<commit_before>require 'spec_helper'

describe "States" do
  before(:each) do
    visit spree.admin_path
    click_link "Configuration"
  end

  context "admin visiting states listing" do
    before(:each) do
      Factory(:zone)
    end

    it "should correctly display the states" do
      click_link "States"
      find('table#listing_states tbody tr:nth-child(1) td:nth-child(1)').text.should == Spree::State.limit(1).order('name asc').to_a.first.name.downcase.capitalize
    end
  end

  context "creating and editing states" do
    it "should allow an admin to edit existing states", :js => true do
      click_link "States"
      select "Canada", :from => "country"
      click_link "new_state_link"
      fill_in "state_name", :with => "Calgary"
      fill_in "Abbreviation", :with => "CL"
      click_button "Create"
      page.should have_content("successfully created!")
      page.should have_content("Calgary")
    end

    it "should show validation errors", :js => true do
      click_link "States"
      select "Canada", :from => "country"
      click_link "new_state_link"
      fill_in "state_name", :with => ""
      fill_in "Abbreviation", :with => ""
      click_button "Create"
      page.should have_content("Name can't be blank")
    end
  end
end<commit_msg>Clean up states spec so that a country + state are created for testing purposes<commit_after>require 'spec_helper'

describe "States" do
  let!(:country) { Factory.create(:country) }

  before(:each) do
    Spree::Config[:default_country_id] = country.id

    visit spree.admin_path
    click_link "Configuration"
  end

  context "admin visiting states listing" do
    let!(:state) { Factory.create(:state, :country => country) }

    it "should correctly display the states" do
      click_link "States"
      page.should have_content(state.name)
    end
  end

  context "creating and editing states" do
    it "should allow an admin to edit existing states", :js => true do
      click_link "States"
      select country.name, :from => "country"
      click_link "new_state_link"
      fill_in "state_name", :with => "Calgary"
      fill_in "Abbreviation", :with => "CL"
      click_button "Create"
      page.should have_content("successfully created!")
      page.should have_content("Calgary")
    end

    it "should show validation errors", :js => true do
      click_link "States"
      select country.name, :from => "country"
      click_link "new_state_link"
      fill_in "state_name", :with => ""
      fill_in "Abbreviation", :with => ""
      click_button "Create"
      page.should have_content("Name can't be blank")
    end
  end
end
{'fraction_non_alphanumeric': 0.11077389984825493, 'fraction_numerical': 0.0011380880121396055, 'mean_word_length': 3.253225806451613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '131608', 'n_tokens_mistral': 827, 'n_tokens_neox': 796, 'n_words': 238}