mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Make new specs pass
This commit is contained in:
@@ -11,7 +11,7 @@ describe Spree::Address do
|
||||
address2: 'address2',
|
||||
alternative_phone: 'alternative_phone',
|
||||
city: 'city',
|
||||
country: Spree::Country.first,
|
||||
country: state.country,
|
||||
firstname: 'firstname',
|
||||
lastname: 'lastname',
|
||||
company: 'company',
|
||||
@@ -22,22 +22,22 @@ describe Spree::Address do
|
||||
|
||||
cloned = original.clone
|
||||
|
||||
cloned.address1.should == original.address1
|
||||
cloned.address2.should == original.address2
|
||||
cloned.alternative_phone.should == original.alternative_phone
|
||||
cloned.city.should == original.city
|
||||
cloned.country_id.should == original.country_id
|
||||
cloned.firstname.should == original.firstname
|
||||
cloned.lastname.should == original.lastname
|
||||
cloned.company.should == original.company
|
||||
cloned.phone.should == original.phone
|
||||
cloned.state_id.should == original.state_id
|
||||
cloned.state_name.should == original.state_name
|
||||
cloned.zipcode.should == original.zipcode
|
||||
expect(cloned.address1).to eq original.address1
|
||||
expect(cloned.address2).to eq original.address2
|
||||
expect(cloned.alternative_phone).to eq original.alternative_phone
|
||||
expect(cloned.city).to eq original.city
|
||||
expect(cloned.country_id).to eq original.country_id
|
||||
expect(cloned.firstname).to eq original.firstname
|
||||
expect(cloned.lastname).to eq original.lastname
|
||||
expect(cloned.company).to eq original.company
|
||||
expect(cloned.phone).to eq original.phone
|
||||
expect(cloned.state_id).to eq original.state_id
|
||||
expect(cloned.state_name).to eq original.state_name
|
||||
expect(cloned.zipcode).to eq original.zipcode
|
||||
|
||||
cloned.id.should_not == original.id
|
||||
cloned.created_at.should_not == original.created_at
|
||||
cloned.updated_at.should_not == original.updated_at
|
||||
expect(cloned.id).to_not eq original.id
|
||||
expect(cloned.created_at).to_not eq original.created_at
|
||||
expect(cloned.updated_at).to_not eq original.updated_at
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,12 +46,12 @@ describe Spree::Address do
|
||||
|
||||
it "first_name" do
|
||||
address.firstname = "Ryan"
|
||||
address.first_name.should == "Ryan"
|
||||
expect(address.first_name).to eq "Ryan"
|
||||
end
|
||||
|
||||
it "last_name" do
|
||||
address.lastname = "Bigg"
|
||||
address.last_name.should == "Bigg"
|
||||
expect(address.last_name).to eq "Bigg"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -62,81 +62,61 @@ describe Spree::Address do
|
||||
end
|
||||
end
|
||||
|
||||
let(:country) { mock_model(Spree::Country, states: [state], states_required: true) }
|
||||
let(:state) { stub_model(Spree::State, name: 'maryland', abbr: 'md') }
|
||||
let(:address) { build(:address, country: country) }
|
||||
let(:state) { create(:state, name: 'maryland', abbr: 'md') }
|
||||
let(:country) { state.country }
|
||||
let(:address) { create(:address, country: country, state: state) }
|
||||
|
||||
before do
|
||||
country.states.stub find_all_by_name_or_abbr: [state]
|
||||
end
|
||||
|
||||
it "state_name is not nil and country does not have any states" do
|
||||
address.state = nil
|
||||
address.state_name = 'alabama'
|
||||
address.should be_valid
|
||||
country.states_required = true
|
||||
end
|
||||
|
||||
it "errors when state_name is nil" do
|
||||
address.state_name = nil
|
||||
address.state = nil
|
||||
address.should_not be_valid
|
||||
expect(address).to_not be_valid
|
||||
end
|
||||
|
||||
it "full state name is in state_name and country does contain that state" do
|
||||
address.state_name = 'alabama'
|
||||
# called by state_validate to set up state_id.
|
||||
# Perhaps this should be a before_validation instead?
|
||||
address.should be_valid
|
||||
address.state.should_not be_nil
|
||||
address.state_name.should be_nil
|
||||
country.states.stub find_all_by_name_or_abbr: [create(:state, name: 'alabama', abbr: 'al')]
|
||||
address.update state_name: 'alabama'
|
||||
expect(address).to be_valid
|
||||
expect(address.state.name).to eq 'alabama'
|
||||
expect(address.state_name).to eq 'alabama'
|
||||
end
|
||||
|
||||
it "state abbr is in state_name and country does contain that state" do
|
||||
country.states.stub find_all_by_name_or_abbr: [state]
|
||||
address.state_name = state.abbr
|
||||
address.should be_valid
|
||||
address.state_id.should_not be_nil
|
||||
address.state_name.should be_nil
|
||||
end
|
||||
|
||||
it "state is entered but country does not contain that state" do
|
||||
address.state = state
|
||||
address.country = stub_model(Spree::Country)
|
||||
address.valid?
|
||||
address.errors["state"].should == ['is invalid']
|
||||
end
|
||||
|
||||
it "both state and state_name are entered but country does not contain the state" do
|
||||
address.state = state
|
||||
address.state_name = 'maryland'
|
||||
address.country = stub_model(Spree::Country)
|
||||
address.should be_valid
|
||||
address.state_id.should be_nil
|
||||
expect(address).to be_valid
|
||||
expect(address.state.abbr).to eq state.abbr
|
||||
expect(address.state_name).to eq state.name
|
||||
end
|
||||
|
||||
it "both state and state_name are entered and country does contain the state" do
|
||||
country.states.stub find_all_by_name_or_abbr: [state]
|
||||
address.state = state
|
||||
address.state_name = 'maryland'
|
||||
address.should be_valid
|
||||
address.state_name.should be_nil
|
||||
expect(address).to be_valid
|
||||
expect(address.state_name).to eq 'maryland'
|
||||
end
|
||||
|
||||
it "address_requires_state preference is false" do
|
||||
Spree::Config.set address_requires_state: false
|
||||
address.state = nil
|
||||
address.state_name = nil
|
||||
address.should be_valid
|
||||
expect(address).to be_valid
|
||||
end
|
||||
|
||||
it "requires phone" do
|
||||
address.phone = ""
|
||||
address.valid?
|
||||
address.errors["phone"].should == ["can't be blank"]
|
||||
expect(address.errors["phone"]).to eq ["can't be blank"]
|
||||
end
|
||||
|
||||
it "requires zipcode" do
|
||||
address.zipcode = ""
|
||||
address.valid?
|
||||
address.should have(1).error_on(:zipcode)
|
||||
expect(address.errors[:zipcode].first).to eq "can't be blank"
|
||||
end
|
||||
|
||||
context "phone not required" do
|
||||
@@ -145,7 +125,7 @@ describe Spree::Address do
|
||||
it "shows no errors when phone is blank" do
|
||||
address.phone = ""
|
||||
address.valid?
|
||||
address.should have(:no).errors_on(:phone)
|
||||
expect(address.errors[:phone]).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -155,7 +135,7 @@ describe Spree::Address do
|
||||
it "shows no errors when phone is blank" do
|
||||
address.zipcode = ""
|
||||
address.valid?
|
||||
address.should have(:no).errors_on(:zipcode)
|
||||
expect(address.errors[:zipcode]).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -171,59 +151,54 @@ describe Spree::Address do
|
||||
Spree::Config[:default_country_id] = @default_country_id
|
||||
end
|
||||
it "sets up a new record with Spree::Config[:default_country_id]" do
|
||||
Spree::Address.default.country.should == Spree::Country.find(Spree::Config[:default_country_id])
|
||||
expect(Spree::Address.default.country).to eq Spree::Country.find(Spree::Config[:default_country_id])
|
||||
end
|
||||
|
||||
# Regression test for #1142
|
||||
it "uses the first available country if :default_country_id is set to an invalid value" do
|
||||
Spree::Config[:default_country_id] = "0"
|
||||
Spree::Address.default.country.should == Spree::Country.first
|
||||
expect(Spree::Address.default.country).to eq Spree::Country.first
|
||||
end
|
||||
end
|
||||
|
||||
context '#full_name' do
|
||||
context 'both first and last names are present' do
|
||||
let(:address) { stub_model(Spree::Address, firstname: 'Michael', lastname: 'Jackson') }
|
||||
specify { address.full_name.should == 'Michael Jackson' }
|
||||
let(:address) { build(:address, firstname: 'Michael', lastname: 'Jackson') }
|
||||
specify { expect(address.full_name).to eq 'Michael Jackson' }
|
||||
end
|
||||
|
||||
context 'first name is blank' do
|
||||
let(:address) { stub_model(Spree::Address, firstname: nil, lastname: 'Jackson') }
|
||||
specify { address.full_name.should == 'Jackson' }
|
||||
let(:address) { build(:address, firstname: nil, lastname: 'Jackson') }
|
||||
specify { expect(address.full_name).to eq 'Jackson' }
|
||||
end
|
||||
|
||||
context 'last name is blank' do
|
||||
let(:address) { stub_model(Spree::Address, firstname: 'Michael', lastname: nil) }
|
||||
specify { address.full_name.should == 'Michael' }
|
||||
let(:address) { build(:address, firstname: 'Michael', lastname: nil) }
|
||||
specify { expect(address.full_name).to eq 'Michael' }
|
||||
end
|
||||
|
||||
context 'both first and last names are blank' do
|
||||
let(:address) { stub_model(Spree::Address, firstname: nil, lastname: nil) }
|
||||
specify { address.full_name.should == '' }
|
||||
let(:address) { build(:address, firstname: nil, lastname: nil) }
|
||||
specify { expect(address.full_name).to eq '' }
|
||||
end
|
||||
end
|
||||
|
||||
context '#state_text' do
|
||||
context 'state is blank' do
|
||||
let(:address) { stub_model(Spree::Address, state: nil, state_name: 'virginia') }
|
||||
specify { address.state_text.should == 'virginia' }
|
||||
end
|
||||
|
||||
context 'both name and abbr is present' do
|
||||
let(:state) { stub_model(Spree::State, name: 'virginia', abbr: 'va') }
|
||||
let(:address) { stub_model(Spree::Address, state: state) }
|
||||
specify { address.state_text.should == 'va' }
|
||||
let(:state) { build(:state, name: 'virginia', abbr: 'va') }
|
||||
let(:address) { build(:address, state: state) }
|
||||
specify { expect(address.state_text).to eq 'va' }
|
||||
end
|
||||
|
||||
context 'only name is present' do
|
||||
let(:state) { stub_model(Spree::State, name: 'virginia', abbr: nil) }
|
||||
let(:address) { stub_model(Spree::Address, state: state) }
|
||||
specify { address.state_text.should == 'virginia' }
|
||||
let(:state) { build(:state, name: 'virginia', abbr: nil) }
|
||||
let(:address) { build(:address, state: state) }
|
||||
specify { expect(address.state_text).to eq 'virginia' }
|
||||
end
|
||||
end
|
||||
|
||||
context "defines require_phone? helper method" do
|
||||
let(:address) { stub_model(Spree::Address) }
|
||||
specify { address.instance_eval{ require_phone? }.should be_true }
|
||||
let(:address) { build(:address) }
|
||||
specify { expect(address.instance_eval{ require_phone? }).to be_truthy }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -121,20 +121,21 @@ module Spree
|
||||
end
|
||||
|
||||
context "validations" do
|
||||
before { subject.valid? }
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [create(:distributor_enterprise)]) }
|
||||
|
||||
it "validates presence of name" do
|
||||
subject.should have(1).error_on(:name)
|
||||
shipping_method.update name: ''
|
||||
expect(shipping_method.errors[:name].first).to eq "can't be blank"
|
||||
end
|
||||
|
||||
context "shipping category" do
|
||||
it "validates presence of at least one" do
|
||||
subject.should have(1).error_on(:base)
|
||||
shipping_method.update shipping_categories: []
|
||||
expect(shipping_method.reload.errors[:base].first).to eq "You need to select at least one shipping category"
|
||||
end
|
||||
|
||||
context "one associated" do
|
||||
before { subject.shipping_categories.push create(:shipping_category) }
|
||||
it { subject.should have(0).error_on(:base) }
|
||||
it { expect(shipping_method.reload.errors[:base]).to be_empty }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,14 +16,14 @@ describe Spree::ShippingRate do
|
||||
context "when shipment includes VAT" do
|
||||
before { Spree::Config[:shipment_inc_vat] = true }
|
||||
it "displays the correct price" do
|
||||
shipping_rate.display_price.to_s.should == "$11.08" # $10.55 * 1.05 == $11.08
|
||||
expect(shipping_rate.display_price.to_s).to eq "$11.08" # $10.55 * 1.05 == $11.08
|
||||
end
|
||||
end
|
||||
|
||||
context "when shipment does not include VAT" do
|
||||
before { Spree::Config[:shipment_inc_vat] = false }
|
||||
it "displays the correct price" do
|
||||
shipping_rate.display_price.to_s.should == "$10.55"
|
||||
expect(shipping_rate.display_price.to_s).to eq "$10.55"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ describe Spree::ShippingRate do
|
||||
}
|
||||
|
||||
it "displays the price in yen" do
|
||||
shipping_rate.display_price.to_s.should == "¥205"
|
||||
expect(shipping_rate.display_price.to_s).to eq "¥205"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user