<commit_before>RSpec.describe "Vendor", type: :system do
  before do
    sign_in(@user)
  end
  let(:url_prefix) { "/#{@organization.to_param}" }

  context "When a user views the index page" do
    before(:each) do
      @second = create(:vendor, business_name: "Bcd")
      @first = create(:vendor, business_name: "Abc")
      @third = create(:vendor, business_name: "Cde")
      visit url_prefix + "/vendors"
    end
    it "should have the vendor names in alphabetical order" do
      expect(page).to have_xpath("//table//tr", count: 4)
      expect(page.find(:xpath, "//table/tbody/tr[1]/td[1]")).to have_content(@first.business_name)
      expect(page.find(:xpath, "//table/tbody/tr[3]/td[1]")).to have_content(@third.business_name)
    end
  end

  it "can create a new vendor instance as a user" do
    visit url_prefix + "/vendors/new"
    vendor_traits = attributes_for(:vendor)
    fill_in "Contact Name", with: vendor_traits[:contact_name]
    fill_in "Business Name", with: vendor_traits[:business_name]
    fill_in "Phone", with: vendor_traits[:phone]

    expect do
      click_button "Save"
    end.to change { Vendor.count }.by(1)

    expect(page.find(".alert")).to have_content "added"
  end

  it "can add a new vendor instance with empty attributes as a user" do
    visit url_prefix + "/vendors/new"
    click_button "Save"

    expect(page.find(".alert")).to have_content "didn't work"
  end

  it "can update the contact info for a vendor as a user" do
    vendor = create(:vendor)
    new_email = "<EMAIL>"
    visit url_prefix + "/vendors/#{vendor.id}/edit"
    fill_in "Phone", with: ""
    fill_in "E-mail", with: new_email
    click_button "Save"

    expect(page.find(".alert")).to have_content "updated"
    expect(page).to have_content(vendor.contact_name)
    expect(page).to have_content(new_email)
  end

  it "can update a vendor with empty attributes as a user" do
    vendor = create(:vendor)
    visit url_prefix + "/vendors/#{vendor.id}/edit"
    fill_in "Business Name", with: ""
    fill_in "Contact Name", with: ""
    click_button "Save"

    expect(page.find(".alert")).to have_content "didn't work"
  end

  context "When vendor have purchases associated with them already" do
    before(:each) do
      @vendor = create(:vendor)
      create(:purchase, :with_items, created_at: 1.day.ago, item_quantity: 10, amount_spent: 1, vendor: @vendor)
      create(:purchase, :with_items, created_at: 1.week.ago, item_quantity: 15, amount_spent: 1, vendor: @vendor)
    end

    it "can have existing vendors show in the #index with some summary stats" do
      visit url_prefix + "/vendors"
      expect(page).to have_xpath("//table/tbody/tr/td", text: @vendor.business_name)
      expect(page).to have_xpath("//table/tbody/tr/td", text: "25")
    end

    it "can have a single vendor show semi-detailed stats about purchases" do
      visit url_prefix + "/vendors/#{@vendor.to_param}"
      expect(page).to have_xpath("//table/tbody/tr", count: 3)
      expect(page).to have_xpath("//table/tr/td", text: "10")
    end
  end
end<commit_msg>Fix additional testing error with table nesting<commit_after>RSpec.describe "Vendor", type: :system do
  before do
    sign_in(@user)
  end
  let(:url_prefix) { "/#{@organization.to_param}" }

  context "When a user views the index page" do
    before(:each) do
      @second = create(:vendor, business_name: "Bcd")
      @first = create(:vendor, business_name: "Abc")
      @third = create(:vendor, business_name: "Cde")
      visit url_prefix + "/vendors"
    end
    it "should have the vendor names in alphabetical order" do
      expect(page).to have_xpath("//table//tr", count: 4)
      expect(page.find(:xpath, "//table/tbody/tr[1]/td[1]")).to have_content(@first.business_name)
      expect(page.find(:xpath, "//table/tbody/tr[3]/td[1]")).to have_content(@third.business_name)
    end
  end

  it "can create a new vendor instance as a user" do
    visit url_prefix + "/vendors/new"
    vendor_traits = attributes_for(:vendor)
    fill_in "Contact Name", with: vendor_traits[:contact_name]
    fill_in "Business Name", with: vendor_traits[:business_name]
    fill_in "Phone", with: vendor_traits[:phone]

    expect do
      click_button "Save"
    end.to change { Vendor.count }.by(1)

    expect(page.find(".alert")).to have_content "added"
  end

  it "can add a new vendor instance with empty attributes as a user" do
    visit url_prefix + "/vendors/new"
    click_button "Save"

    expect(page.find(".alert")).to have_content "didn't work"
  end

  it "can update the contact info for a vendor as a user" do
    vendor = create(:vendor)
    new_email = "<EMAIL>"
    visit url_prefix + "/vendors/#{vendor.id}/edit"
    fill_in "Phone", with: ""
    fill_in "E-mail", with: new_email
    click_button "Save"

    expect(page.find(".alert")).to have_content "updated"
    expect(page).to have_content(vendor.contact_name)
    expect(page).to have_content(new_email)
  end

  it "can update a vendor with empty attributes as a user" do
    vendor = create(:vendor)
    visit url_prefix + "/vendors/#{vendor.id}/edit"
    fill_in "Business Name", with: ""
    fill_in "Contact Name", with: ""
    click_button "Save"

    expect(page.find(".alert")).to have_content "didn't work"
  end

  context "When vendor have purchases associated with them already" do
    before(:each) do
      @vendor = create(:vendor)
      create(:purchase, :with_items, created_at: 1.day.ago, item_quantity: 10, amount_spent: 1, vendor: @vendor)
      create(:purchase, :with_items, created_at: 1.week.ago, item_quantity: 15, amount_spent: 1, vendor: @vendor)
    end

    it "can have existing vendors show in the #index with some summary stats" do
      visit url_prefix + "/vendors"
      expect(page).to have_xpath("//table/tbody/tr/td", text: @vendor.business_name)
      expect(page).to have_xpath("//table/tbody/tr/td", text: "25")
    end

    it "can have a single vendor show semi-detailed stats about purchases" do
      visit url_prefix + "/vendors/#{@vendor.to_param}"
      expect(page).to have_xpath("//table/tbody/tr", count: 3)
      expect(page).to have_xpath("//table/tbody/tr/td", text: "10")
    end
  end
end
{'fraction_non_alphanumeric': 0.1340755082284608, 'fraction_numerical': 0.006131010003226848, 'mean_word_length': 3.511644832605531, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6625721', 'n_tokens_mistral': 2096, 'n_tokens_neox': 2016, 'n_words': 569}