mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Run transpec in spec/models
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
describe AdjustmentMetadata do
|
||||
it "is valid when build from factory" do
|
||||
adjustment = create(:adjustment)
|
||||
adjustment.should be_valid
|
||||
expect(adjustment).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,11 +2,11 @@ require 'spec_helper'
|
||||
|
||||
describe EnterpriseFee do
|
||||
describe "associations" do
|
||||
it { should belong_to(:enterprise) }
|
||||
it { is_expected.to belong_to(:enterprise) }
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it { should validate_presence_of(:name) }
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
end
|
||||
|
||||
describe "callbacks" do
|
||||
|
||||
@@ -7,38 +7,38 @@ describe EnterpriseGroup do
|
||||
e.name = 'Test Group'
|
||||
e.description = 'A valid test group.'
|
||||
e.address = build(:address)
|
||||
e.should be_valid
|
||||
expect(e).to be_valid
|
||||
end
|
||||
|
||||
it "is valid when built from factory" do
|
||||
e = build(:enterprise_group)
|
||||
e.should be_valid
|
||||
expect(e).to be_valid
|
||||
end
|
||||
|
||||
it "replace empty permalink and pass" do
|
||||
e = build(:enterprise_group, permalink: '')
|
||||
e.should be_valid
|
||||
e.permalink.should == e.name.parameterize
|
||||
expect(e).to be_valid
|
||||
expect(e.permalink).to eq(e.name.parameterize)
|
||||
end
|
||||
|
||||
it "restores permalink and pass" do
|
||||
e = create(:enterprise_group, permalink: 'p')
|
||||
e.permalink = ''
|
||||
e.should be_valid
|
||||
e.permalink.should == 'p'
|
||||
expect(e).to be_valid
|
||||
expect(e.permalink).to eq('p')
|
||||
end
|
||||
|
||||
it "requires a name" do
|
||||
e = build(:enterprise_group, name: '')
|
||||
e.should_not be_valid
|
||||
expect(e).not_to be_valid
|
||||
end
|
||||
|
||||
it "requires a description" do
|
||||
e = build(:enterprise_group, description: '')
|
||||
end
|
||||
|
||||
it { should have_attached_file :promo_image }
|
||||
it { should have_attached_file :logo }
|
||||
it { is_expected.to have_attached_file :promo_image }
|
||||
it { is_expected.to have_attached_file :logo }
|
||||
end
|
||||
|
||||
describe "relations" do
|
||||
@@ -46,7 +46,7 @@ describe EnterpriseGroup do
|
||||
e = create(:supplier_enterprise)
|
||||
eg = create(:enterprise_group)
|
||||
eg.enterprises << e
|
||||
eg.reload.enterprises.should == [e]
|
||||
expect(eg.reload.enterprises).to eq([e])
|
||||
end
|
||||
|
||||
# it "can have an image" do
|
||||
@@ -63,14 +63,14 @@ describe EnterpriseGroup do
|
||||
eg2 = create(:enterprise_group, position: 3)
|
||||
eg3 = create(:enterprise_group, position: 2)
|
||||
|
||||
EnterpriseGroup.by_position.should == [eg1, eg3, eg2]
|
||||
expect(EnterpriseGroup.by_position).to eq([eg1, eg3, eg2])
|
||||
end
|
||||
|
||||
it "finds enterprise groups on the front page" do
|
||||
eg1 = create(:enterprise_group, on_front_page: true)
|
||||
eg2 = create(:enterprise_group, on_front_page: false)
|
||||
|
||||
EnterpriseGroup.on_front_page.should == [eg1]
|
||||
expect(EnterpriseGroup.on_front_page).to eq([eg1])
|
||||
end
|
||||
|
||||
it "finds a user's enterprise groups" do
|
||||
@@ -79,7 +79,7 @@ describe EnterpriseGroup do
|
||||
eg1 = create(:enterprise_group, owner: user)
|
||||
eg2 = create(:enterprise_group)
|
||||
|
||||
EnterpriseGroup.managed_by(user).should == [eg1]
|
||||
expect(EnterpriseGroup.managed_by(user)).to eq([eg1])
|
||||
end
|
||||
|
||||
describe "finding a permalink" do
|
||||
|
||||
@@ -11,22 +11,22 @@ describe EnterpriseRelationship do
|
||||
er2 = create(:enterprise_relationship, parent: e1, child: e2)
|
||||
er3 = create(:enterprise_relationship, parent: e2, child: e1)
|
||||
|
||||
EnterpriseRelationship.by_name.should == [er3, er1, er2]
|
||||
expect(EnterpriseRelationship.by_name).to eq([er3, er1, er2])
|
||||
end
|
||||
|
||||
describe "finding relationships involving some enterprises" do
|
||||
let!(:er) { create(:enterprise_relationship, parent: e1, child: e2) }
|
||||
|
||||
it "returns relationships where an enterprise is the parent" do
|
||||
EnterpriseRelationship.involving_enterprises([e1]).should == [er]
|
||||
expect(EnterpriseRelationship.involving_enterprises([e1])).to eq([er])
|
||||
end
|
||||
|
||||
it "returns relationships where an enterprise is the child" do
|
||||
EnterpriseRelationship.involving_enterprises([e2]).should == [er]
|
||||
expect(EnterpriseRelationship.involving_enterprises([e2])).to eq([er])
|
||||
end
|
||||
|
||||
it "does not return other relationships" do
|
||||
EnterpriseRelationship.involving_enterprises([e3]).should == []
|
||||
expect(EnterpriseRelationship.involving_enterprises([e3])).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,13 +35,13 @@ describe EnterpriseRelationship do
|
||||
it "creates a new permission for each item in the list" do
|
||||
er = EnterpriseRelationship.create! parent: e1, child: e2, permissions_list: ['one', 'two']
|
||||
er.reload
|
||||
er.permissions.map(&:name).should match_array ['one', 'two']
|
||||
expect(er.permissions.map(&:name)).to match_array ['one', 'two']
|
||||
end
|
||||
|
||||
it "does nothing when the list is nil" do
|
||||
er = EnterpriseRelationship.create! parent: e1, child: e2, permissions_list: nil
|
||||
er.reload
|
||||
er.permissions.should be_empty
|
||||
expect(er.permissions).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,30 +51,30 @@ describe EnterpriseRelationship do
|
||||
er.permissions_list = ['four']
|
||||
er.save!
|
||||
er.reload
|
||||
er.permissions.map(&:name).should include 'four'
|
||||
expect(er.permissions.map(&:name)).to include 'four'
|
||||
end
|
||||
|
||||
it "does not duplicate existing permissions" do
|
||||
er.permissions_list = ["one", "two", "three"]
|
||||
er.save!
|
||||
er.reload
|
||||
er.permissions.map(&:name).count.should == 3
|
||||
er.permissions.map(&:name).should match_array ["one", "two", "three"]
|
||||
expect(er.permissions.map(&:name).count).to eq(3)
|
||||
expect(er.permissions.map(&:name)).to match_array ["one", "two", "three"]
|
||||
end
|
||||
|
||||
it "removes permissions that are not in the list" do
|
||||
er.permissions_list = ['one', 'three']
|
||||
er.save!
|
||||
er.reload
|
||||
er.permissions.map(&:name).should include 'one', 'three'
|
||||
er.permissions.map(&:name).should_not include 'two'
|
||||
expect(er.permissions.map(&:name)).to include 'one', 'three'
|
||||
expect(er.permissions.map(&:name)).not_to include 'two'
|
||||
end
|
||||
|
||||
it "does removes all permissions when the list provided is nil" do
|
||||
er.permissions_list = nil
|
||||
er.save!
|
||||
er.reload
|
||||
er.permissions.should be_empty
|
||||
expect(er.permissions).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -85,11 +85,11 @@ describe EnterpriseRelationship do
|
||||
let!(:er3) { create(:enterprise_relationship, parent: e1, child: e3) }
|
||||
|
||||
it "finds relationships that grant permissions to some enterprises" do
|
||||
EnterpriseRelationship.permitting([e1, e2]).should match_array [er1, er2]
|
||||
expect(EnterpriseRelationship.permitting([e1, e2])).to match_array [er1, er2]
|
||||
end
|
||||
|
||||
it "finds relationships that are granted by particular enterprises" do
|
||||
EnterpriseRelationship.permitted_by([e1, e2]).should match_array [er1, er3]
|
||||
expect(EnterpriseRelationship.permitted_by([e1, e2])).to match_array [er1, er3]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -101,7 +101,7 @@ describe EnterpriseRelationship do
|
||||
er3 = create(:enterprise_relationship, parent: e3, child: e1,
|
||||
permissions_list: ['three', 'four'])
|
||||
|
||||
EnterpriseRelationship.with_permission('two').should match_array [er1, er2]
|
||||
expect(EnterpriseRelationship.with_permission('two')).to match_array [er1, er2]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -112,30 +112,31 @@ describe EnterpriseRelationship do
|
||||
let(:er_reverse) { create(:enterprise_relationship, parent: e2, child: e1) }
|
||||
|
||||
it "includes self where appropriate" do
|
||||
EnterpriseRelationship.relatives[e2.id][:distributors].should include e2.id
|
||||
EnterpriseRelationship.relatives[e2.id][:producers].should_not include e2.id
|
||||
expect(EnterpriseRelationship.relatives[e2.id][:distributors]).to include e2.id
|
||||
expect(EnterpriseRelationship.relatives[e2.id][:producers]).not_to include e2.id
|
||||
end
|
||||
|
||||
it "categorises enterprises into distributors and producers" do
|
||||
e2.update_attribute :is_primary_producer, true
|
||||
EnterpriseRelationship.relatives.should ==
|
||||
expect(EnterpriseRelationship.relatives).to eq(
|
||||
{e1.id => {distributors: Set.new([e2.id]), producers: Set.new([e1.id, e2.id])},
|
||||
e2.id => {distributors: Set.new([e2.id]), producers: Set.new([e2.id, e1.id])}}
|
||||
)
|
||||
end
|
||||
|
||||
it "finds inactive enterprises by default" do
|
||||
e1.update_attribute :sells, 'unspecified'
|
||||
EnterpriseRelationship.relatives[e2.id][:producers].should == Set.new([e1.id])
|
||||
expect(EnterpriseRelationship.relatives[e2.id][:producers]).to eq(Set.new([e1.id]))
|
||||
end
|
||||
|
||||
it "does not find inactive enterprises when requested" do
|
||||
e1.update_attribute :sells, 'unspecified'
|
||||
EnterpriseRelationship.relatives(true)[e2.id][:producers].should be_empty
|
||||
expect(EnterpriseRelationship.relatives(true)[e2.id][:producers]).to be_empty
|
||||
end
|
||||
|
||||
it "does not show duplicates" do
|
||||
er_reverse
|
||||
EnterpriseRelationship.relatives[e2.id][:producers].should == Set.new([e1.id])
|
||||
expect(EnterpriseRelationship.relatives[e2.id][:producers]).to eq(Set.new([e1.id]))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ describe Enterprise do
|
||||
end
|
||||
|
||||
describe "associations" do
|
||||
it { should belong_to(:owner) }
|
||||
it { should have_many(:supplied_products) }
|
||||
it { should have_many(:distributed_orders) }
|
||||
it { should belong_to(:address) }
|
||||
it { is_expected.to belong_to(:owner) }
|
||||
it { is_expected.to have_many(:supplied_products) }
|
||||
it { is_expected.to have_many(:distributed_orders) }
|
||||
it { is_expected.to belong_to(:address) }
|
||||
|
||||
it "destroys enterprise roles upon its own demise" do
|
||||
e = create(:enterprise)
|
||||
@@ -29,7 +29,7 @@ describe Enterprise do
|
||||
|
||||
role = e.enterprise_roles.first
|
||||
e.destroy
|
||||
EnterpriseRole.where(id: role.id).should be_empty
|
||||
expect(EnterpriseRole.where(id: role.id)).to be_empty
|
||||
end
|
||||
|
||||
xit "destroys supplied products upon destroy" do
|
||||
@@ -38,7 +38,7 @@ describe Enterprise do
|
||||
|
||||
s.destroy
|
||||
|
||||
Spree::Product.where(id: p.id).should be_empty
|
||||
expect(Spree::Product.where(id: p.id)).to be_empty
|
||||
end
|
||||
|
||||
it "destroys relationships upon destroy" do
|
||||
@@ -49,7 +49,7 @@ describe Enterprise do
|
||||
|
||||
e.destroy
|
||||
|
||||
EnterpriseRelationship.where(id: [er1, er2]).should be_empty
|
||||
expect(EnterpriseRelationship.where(id: [er1, er2])).to be_empty
|
||||
end
|
||||
|
||||
describe "relationships to other enterprises" do
|
||||
@@ -61,7 +61,7 @@ describe Enterprise do
|
||||
let!(:er2) { create(:enterprise_relationship, parent_id: e.id, child_id: c.id) }
|
||||
|
||||
it "finds relatives" do
|
||||
e.relatives.should match_array [p, c]
|
||||
expect(e.relatives).to match_array [p, c]
|
||||
end
|
||||
|
||||
it "finds relatives_including_self" do
|
||||
@@ -69,14 +69,14 @@ describe Enterprise do
|
||||
end
|
||||
|
||||
it "scopes relatives to visible distributors" do
|
||||
e.should_receive(:relatives_including_self).and_return(relatives = [])
|
||||
relatives.should_receive(:is_distributor).and_return relatives
|
||||
expect(e).to receive(:relatives_including_self).and_return(relatives = [])
|
||||
expect(relatives).to receive(:is_distributor).and_return relatives
|
||||
e.distributors
|
||||
end
|
||||
|
||||
it "scopes relatives to visible producers" do
|
||||
e.should_receive(:relatives_including_self).and_return(relatives = [])
|
||||
relatives.should_receive(:is_primary_producer).and_return relatives
|
||||
expect(e).to receive(:relatives_including_self).and_return(relatives = [])
|
||||
expect(relatives).to receive(:is_primary_producer).and_return relatives
|
||||
e.suppliers
|
||||
end
|
||||
end
|
||||
@@ -112,9 +112,9 @@ describe Enterprise do
|
||||
|
||||
describe "validations" do
|
||||
subject { FactoryBot.create(:distributor_enterprise) }
|
||||
it { should validate_presence_of(:name) }
|
||||
it { should validate_uniqueness_of(:permalink) }
|
||||
it { should ensure_length_of(:description).is_at_most(255) }
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
it { is_expected.to validate_uniqueness_of(:permalink) }
|
||||
it { is_expected.to ensure_length_of(:description).is_at_most(255) }
|
||||
|
||||
it "requires an owner" do
|
||||
expect{
|
||||
@@ -140,11 +140,11 @@ describe Enterprise do
|
||||
end
|
||||
|
||||
it "does not prohibit the saving of an enterprise with no name clash" do
|
||||
enterprise.should be_valid
|
||||
expect(enterprise).to be_valid
|
||||
end
|
||||
|
||||
it "sets the enterprise contact to the owner by default" do
|
||||
enterprise.contact.should eq enterprise.owner
|
||||
expect(enterprise.contact).to eq enterprise.owner
|
||||
end
|
||||
end
|
||||
|
||||
@@ -187,10 +187,10 @@ describe Enterprise do
|
||||
describe "delegations" do
|
||||
#subject { FactoryBot.create(:distributor_enterprise, :address => FactoryBot.create(:address)) }
|
||||
|
||||
it { should delegate(:latitude).to(:address) }
|
||||
it { should delegate(:longitude).to(:address) }
|
||||
it { should delegate(:city).to(:address) }
|
||||
it { should delegate(:state_name).to(:address) }
|
||||
it { is_expected.to delegate(:latitude).to(:address) }
|
||||
it { is_expected.to delegate(:longitude).to(:address) }
|
||||
it { is_expected.to delegate(:city).to(:address) }
|
||||
it { is_expected.to delegate(:state_name).to(:address) }
|
||||
end
|
||||
|
||||
describe "callbacks" do
|
||||
@@ -208,7 +208,7 @@ describe Enterprise do
|
||||
it 'find visible enterprises' do
|
||||
d1 = create(:distributor_enterprise, visible: false)
|
||||
s1 = create(:supplier_enterprise)
|
||||
Enterprise.visible.should == [s1]
|
||||
expect(Enterprise.visible).to eq([s1])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -229,24 +229,24 @@ describe Enterprise do
|
||||
|
||||
it "does not show enterprises with no payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
Enterprise.ready_for_checkout.should_not include e
|
||||
expect(Enterprise.ready_for_checkout).not_to include e
|
||||
end
|
||||
|
||||
it "does not show enterprises with no shipping methods" do
|
||||
create(:payment_method, distributors: [e])
|
||||
Enterprise.ready_for_checkout.should_not include e
|
||||
expect(Enterprise.ready_for_checkout).not_to include e
|
||||
end
|
||||
|
||||
it "does not show enterprises with unavailable payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e], active: false)
|
||||
Enterprise.ready_for_checkout.should_not include e
|
||||
expect(Enterprise.ready_for_checkout).not_to include e
|
||||
end
|
||||
|
||||
it "shows enterprises with available payment and shipping methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e])
|
||||
Enterprise.ready_for_checkout.should include e
|
||||
expect(Enterprise.ready_for_checkout).to include e
|
||||
end
|
||||
end
|
||||
|
||||
@@ -255,24 +255,24 @@ describe Enterprise do
|
||||
|
||||
it "shows enterprises with no payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
Enterprise.not_ready_for_checkout.should include e
|
||||
expect(Enterprise.not_ready_for_checkout).to include e
|
||||
end
|
||||
|
||||
it "shows enterprises with no shipping methods" do
|
||||
create(:payment_method, distributors: [e])
|
||||
Enterprise.not_ready_for_checkout.should include e
|
||||
expect(Enterprise.not_ready_for_checkout).to include e
|
||||
end
|
||||
|
||||
it "shows enterprises with unavailable payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e], active: false)
|
||||
Enterprise.not_ready_for_checkout.should include e
|
||||
expect(Enterprise.not_ready_for_checkout).to include e
|
||||
end
|
||||
|
||||
it "does not show enterprises with available payment and shipping methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e])
|
||||
Enterprise.not_ready_for_checkout.should_not include e
|
||||
expect(Enterprise.not_ready_for_checkout).not_to include e
|
||||
end
|
||||
end
|
||||
|
||||
@@ -281,24 +281,24 @@ describe Enterprise do
|
||||
|
||||
it "returns false for enterprises with no payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
e.reload.should_not be_ready_for_checkout
|
||||
expect(e.reload).not_to be_ready_for_checkout
|
||||
end
|
||||
|
||||
it "returns false for enterprises with no shipping methods" do
|
||||
create(:payment_method, distributors: [e])
|
||||
e.reload.should_not be_ready_for_checkout
|
||||
expect(e.reload).not_to be_ready_for_checkout
|
||||
end
|
||||
|
||||
it "returns false for enterprises with unavailable payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e], active: false)
|
||||
e.reload.should_not be_ready_for_checkout
|
||||
expect(e.reload).not_to be_ready_for_checkout
|
||||
end
|
||||
|
||||
it "returns true for enterprises with available payment and shipping methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e])
|
||||
e.reload.should be_ready_for_checkout
|
||||
expect(e.reload).to be_ready_for_checkout
|
||||
end
|
||||
end
|
||||
|
||||
@@ -308,7 +308,7 @@ describe Enterprise do
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product)
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master])
|
||||
Enterprise.distributors_with_active_order_cycles.should == [d]
|
||||
expect(Enterprise.distributors_with_active_order_cycles).to eq([d])
|
||||
end
|
||||
|
||||
it "should not find inactive distributors by order cycles" do
|
||||
@@ -316,7 +316,7 @@ describe Enterprise do
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product)
|
||||
create(:simple_order_cycle, :orders_open_at => 10.days.from_now, orders_close_at: 17.days.from_now, suppliers: [s], distributors: [d], variants: [p.master])
|
||||
Enterprise.distributors_with_active_order_cycles.should_not include d
|
||||
expect(Enterprise.distributors_with_active_order_cycles).not_to include d
|
||||
end
|
||||
end
|
||||
|
||||
@@ -325,7 +325,7 @@ describe Enterprise do
|
||||
s = create(:supplier_enterprise)
|
||||
p = create(:simple_product, supplier: s)
|
||||
|
||||
Enterprise.supplying_variant_in([p.master]).should == [s]
|
||||
expect(Enterprise.supplying_variant_in([p.master])).to eq([s])
|
||||
end
|
||||
|
||||
it "finds producers by supply of variant" do
|
||||
@@ -333,7 +333,7 @@ describe Enterprise do
|
||||
p = create(:simple_product, supplier: s)
|
||||
v = create(:variant, product: p)
|
||||
|
||||
Enterprise.supplying_variant_in([v]).should == [s]
|
||||
expect(Enterprise.supplying_variant_in([v])).to eq([s])
|
||||
end
|
||||
|
||||
it "returns multiple enterprises when given multiple variants" do
|
||||
@@ -342,7 +342,7 @@ describe Enterprise do
|
||||
p1 = create(:simple_product, supplier: s1)
|
||||
p2 = create(:simple_product, supplier: s2)
|
||||
|
||||
Enterprise.supplying_variant_in([p1.master, p2.master]).should match_array [s1, s2]
|
||||
expect(Enterprise.supplying_variant_in([p1.master, p2.master])).to match_array [s1, s2]
|
||||
end
|
||||
|
||||
it "does not return duplicates" do
|
||||
@@ -350,7 +350,7 @@ describe Enterprise do
|
||||
p1 = create(:simple_product, supplier: s)
|
||||
p2 = create(:simple_product, supplier: s)
|
||||
|
||||
Enterprise.supplying_variant_in([p1.master, p2.master]).should == [s]
|
||||
expect(Enterprise.supplying_variant_in([p1.master, p2.master])).to eq([s])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -360,13 +360,13 @@ describe Enterprise do
|
||||
|
||||
it "returns enterprises distributing via an order cycle" do
|
||||
order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.master])
|
||||
Enterprise.distributing_products(product).should == [distributor]
|
||||
expect(Enterprise.distributing_products(product)).to eq([distributor])
|
||||
end
|
||||
|
||||
it "does not return duplicate enterprises" do
|
||||
another_product = create(:product)
|
||||
order_cycle = create(:simple_order_cycle, distributors: [distributor], variants: [product.master, another_product.master])
|
||||
Enterprise.distributing_products([product, another_product]).should == [distributor]
|
||||
expect(Enterprise.distributing_products([product, another_product])).to eq([distributor])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -379,8 +379,8 @@ describe Enterprise do
|
||||
e1.enterprise_roles.build(user: user).save
|
||||
|
||||
enterprises = Enterprise.managed_by user
|
||||
enterprises.count.should == 1
|
||||
enterprises.should include e1
|
||||
expect(enterprises.count).to eq(1)
|
||||
expect(enterprises).to include e1
|
||||
end
|
||||
|
||||
it "shows all enterprises for admin user" do
|
||||
@@ -389,9 +389,9 @@ describe Enterprise do
|
||||
e2 = create(:enterprise)
|
||||
|
||||
enterprises = Enterprise.managed_by user
|
||||
enterprises.count.should == 2
|
||||
enterprises.should include e1
|
||||
enterprises.should include e2
|
||||
expect(enterprises.count).to eq(2)
|
||||
expect(enterprises).to include e1
|
||||
expect(enterprises).to include e2
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -459,11 +459,11 @@ describe Enterprise do
|
||||
|
||||
def should_have_enterprise_relationship(opts={})
|
||||
er = EnterpriseRelationship.where(parent_id: opts[:from], child_id: opts[:to]).last
|
||||
er.should_not be_nil
|
||||
expect(er).not_to be_nil
|
||||
if opts[:with] == :all_permissions
|
||||
er.permissions.map(&:name).should match_array ['add_to_order_cycle', 'manage_products', 'edit_profile', 'create_variant_overrides']
|
||||
expect(er.permissions.map(&:name)).to match_array ['add_to_order_cycle', 'manage_products', 'edit_profile', 'create_variant_overrides']
|
||||
elsif opts.key? :with
|
||||
er.permissions.map(&:name).should match_array opts[:with].map(&:to_s)
|
||||
expect(er.permissions.map(&:name)).to match_array opts[:with].map(&:to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -476,7 +476,7 @@ describe Enterprise do
|
||||
variant = product.variants.first
|
||||
create(:simple_order_cycle, distributors: [distributor], variants: [variant])
|
||||
|
||||
distributor.distributed_variants.should match_array [product.master, variant]
|
||||
expect(distributor.distributed_variants).to match_array [product.master, variant]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -489,13 +489,13 @@ describe Enterprise do
|
||||
let(:product2) { create(:simple_product, primary_taxon: taxon1, taxons: [taxon1, taxon2]) }
|
||||
|
||||
it "gets all taxons of all distributed products" do
|
||||
Spree::Product.stub(:in_distributor).and_return [product1, product2]
|
||||
distributor.distributed_taxons.should match_array [taxon1, taxon2]
|
||||
allow(Spree::Product).to receive(:in_distributor).and_return [product1, product2]
|
||||
expect(distributor.distributed_taxons).to match_array [taxon1, taxon2]
|
||||
end
|
||||
|
||||
it "gets all taxons of all supplied products" do
|
||||
Spree::Product.stub(:in_supplier).and_return [product1, product2]
|
||||
supplier.supplied_taxons.should match_array [taxon1, taxon2]
|
||||
allow(Spree::Product).to receive(:in_supplier).and_return [product1, product2]
|
||||
expect(supplier.supplied_taxons).to match_array [taxon1, taxon2]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -508,9 +508,9 @@ describe Enterprise do
|
||||
}
|
||||
|
||||
it "strips http from url fields" do
|
||||
distributor.website.should == "www.google.com"
|
||||
distributor.facebook.should == "www.facebook.com/roger"
|
||||
distributor.linkedin.should == "linkedin.com"
|
||||
expect(distributor.website).to eq("www.google.com")
|
||||
expect(distributor.facebook).to eq("www.facebook.com/roger")
|
||||
expect(distributor.linkedin).to eq("linkedin.com")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -520,9 +520,9 @@ describe Enterprise do
|
||||
it "sets producer properties" do
|
||||
supplier.set_producer_property 'Organic Certified', 'NASAA 12345'
|
||||
|
||||
supplier.producer_properties.count.should == 1
|
||||
supplier.producer_properties.first.value.should == 'NASAA 12345'
|
||||
supplier.producer_properties.first.property.presentation.should == 'Organic Certified'
|
||||
expect(supplier.producer_properties.count).to eq(1)
|
||||
expect(supplier.producer_properties.first.value).to eq('NASAA 12345')
|
||||
expect(supplier.producer_properties.first.property.presentation).to eq('Organic Certified')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -535,15 +535,15 @@ describe Enterprise do
|
||||
let(:non_producer_sell_none) { build(:enterprise, is_primary_producer: false, sells: "none") }
|
||||
|
||||
it "should output enterprise categories" do
|
||||
producer_sell_all.is_primary_producer.should == true
|
||||
producer_sell_all.sells.should == "any"
|
||||
expect(producer_sell_all.is_primary_producer).to eq(true)
|
||||
expect(producer_sell_all.sells).to eq("any")
|
||||
|
||||
producer_sell_all.category.should == :producer_hub
|
||||
producer_sell_own.category.should == :producer_shop
|
||||
producer_sell_none.category.should == :producer
|
||||
non_producer_sell_all.category.should == :hub
|
||||
non_producer_sell_own.category.should == :hub
|
||||
non_producer_sell_none.category.should == :hub_profile
|
||||
expect(producer_sell_all.category).to eq(:producer_hub)
|
||||
expect(producer_sell_own.category).to eq(:producer_shop)
|
||||
expect(producer_sell_none.category).to eq(:producer)
|
||||
expect(non_producer_sell_all.category).to eq(:hub)
|
||||
expect(non_producer_sell_own.category).to eq(:hub)
|
||||
expect(non_producer_sell_none.category).to eq(:hub_profile)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -551,7 +551,7 @@ describe Enterprise do
|
||||
let(:enterprise) { build(:enterprise, name: "Name To Turn Into A Permalink") }
|
||||
it "assigns permalink when initialized" do
|
||||
allow(Enterprise).to receive(:find_available_permalink).and_return("available_permalink")
|
||||
Enterprise.should_receive(:find_available_permalink).with("Name To Turn Into A Permalink")
|
||||
expect(Enterprise).to receive(:find_available_permalink).with("Name To Turn Into A Permalink")
|
||||
expect(
|
||||
lambda { enterprise.send(:initialize_permalink) }
|
||||
).to change{
|
||||
|
||||
@@ -2,14 +2,14 @@ require 'spec_helper'
|
||||
|
||||
describe Exchange do
|
||||
it "should be valid when built from factory" do
|
||||
build(:exchange).should be_valid
|
||||
expect(build(:exchange)).to be_valid
|
||||
end
|
||||
|
||||
[:order_cycle, :sender, :receiver].each do |attr|
|
||||
it "should not be valid without #{attr}" do
|
||||
e = build(:exchange)
|
||||
e.send("#{attr}=", nil)
|
||||
e.should_not be_valid
|
||||
expect(e).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,18 +18,18 @@ describe Exchange do
|
||||
|
||||
e2 = build(:exchange,
|
||||
:order_cycle => e1.order_cycle, :sender => e1.sender, :receiver => e1.receiver, :incoming => e1.incoming)
|
||||
e2.should_not be_valid
|
||||
expect(e2).not_to be_valid
|
||||
|
||||
e2.incoming = !e2.incoming
|
||||
e2.should be_valid
|
||||
expect(e2).to be_valid
|
||||
e2.incoming = !e2.incoming
|
||||
|
||||
e2.receiver = create(:enterprise)
|
||||
e2.should be_valid
|
||||
expect(e2).to be_valid
|
||||
|
||||
e2.sender = e2.receiver
|
||||
e2.receiver = e1.receiver
|
||||
e2.should be_valid
|
||||
expect(e2).to be_valid
|
||||
end
|
||||
|
||||
it "has exchange variants" do
|
||||
@@ -37,7 +37,7 @@ describe Exchange do
|
||||
p = create(:product)
|
||||
|
||||
e.exchange_variants.create(:variant => p.master)
|
||||
e.variants.count.should == 1
|
||||
expect(e.variants.count).to eq(1)
|
||||
end
|
||||
|
||||
it "has exchange fees" do
|
||||
@@ -45,7 +45,7 @@ describe Exchange do
|
||||
f = create(:enterprise_fee)
|
||||
|
||||
e.exchange_fees.create(:enterprise_fee => f)
|
||||
e.enterprise_fees.count.should == 1
|
||||
expect(e.enterprise_fees.count).to eq(1)
|
||||
end
|
||||
|
||||
describe "exchange directionality" do
|
||||
@@ -58,21 +58,21 @@ describe Exchange do
|
||||
|
||||
describe "reporting whether it is an incoming exchange" do
|
||||
it "returns true for incoming exchanges" do
|
||||
incoming_exchange.should be_incoming
|
||||
expect(incoming_exchange).to be_incoming
|
||||
end
|
||||
|
||||
it "returns false for outgoing exchanges" do
|
||||
outgoing_exchange.should_not be_incoming
|
||||
expect(outgoing_exchange).not_to be_incoming
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding the exchange participant (the enterprise other than the coordinator)" do
|
||||
it "returns the sender for incoming exchanges" do
|
||||
incoming_exchange.participant.should == supplier
|
||||
expect(incoming_exchange.participant).to eq(supplier)
|
||||
end
|
||||
|
||||
it "returns the receiver for outgoing exchanges" do
|
||||
outgoing_exchange.participant.should == distributor
|
||||
expect(outgoing_exchange.participant).to eq(distributor)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -80,14 +80,14 @@ describe Exchange do
|
||||
describe "reporting its role" do
|
||||
it "returns 'supplier' when it is an incoming exchange" do
|
||||
e = Exchange.new
|
||||
e.stub(:incoming?) { true }
|
||||
e.role.should == 'supplier'
|
||||
allow(e).to receive(:incoming?) { true }
|
||||
expect(e.role).to eq('supplier')
|
||||
end
|
||||
|
||||
it "returns 'distributor' when it is an outgoing exchange" do
|
||||
e = Exchange.new
|
||||
e.stub(:incoming?) { false }
|
||||
e.role.should == 'distributor'
|
||||
allow(e).to receive(:incoming?) { false }
|
||||
expect(e.role).to eq('distributor')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -126,32 +126,32 @@ describe Exchange do
|
||||
exchange.sender.users << user
|
||||
exchange.receiver.users << user
|
||||
|
||||
Exchange.managed_by(user).should == [exchange]
|
||||
expect(Exchange.managed_by(user)).to eq([exchange])
|
||||
end
|
||||
|
||||
it "does not return exchanges where the user manages only the sender" do
|
||||
exchange = create(:exchange, order_cycle: oc)
|
||||
exchange.sender.users << user
|
||||
|
||||
Exchange.managed_by(user).should be_empty
|
||||
expect(Exchange.managed_by(user)).to be_empty
|
||||
end
|
||||
|
||||
it "does not return exchanges where the user manages only the receiver" do
|
||||
exchange = create(:exchange, order_cycle: oc)
|
||||
exchange.receiver.users << user
|
||||
|
||||
Exchange.managed_by(user).should be_empty
|
||||
expect(Exchange.managed_by(user)).to be_empty
|
||||
end
|
||||
|
||||
it "does not return exchanges where the user manages neither enterprise" do
|
||||
exchange = create(:exchange, order_cycle: oc)
|
||||
Exchange.managed_by(user).should be_empty
|
||||
expect(Exchange.managed_by(user)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it "finds exchanges in a particular order cycle" do
|
||||
ex = create(:exchange, order_cycle: oc)
|
||||
Exchange.in_order_cycle(oc).should == [ex]
|
||||
expect(Exchange.in_order_cycle(oc)).to eq([ex])
|
||||
end
|
||||
|
||||
describe "finding exchanges by direction" do
|
||||
@@ -159,44 +159,44 @@ describe Exchange do
|
||||
let!(:outgoing_exchange) { oc.exchanges.create! sender: coordinator, receiver: distributor, incoming: false }
|
||||
|
||||
it "finds incoming exchanges" do
|
||||
Exchange.incoming.should == [incoming_exchange]
|
||||
expect(Exchange.incoming).to eq([incoming_exchange])
|
||||
end
|
||||
|
||||
it "finds outgoing exchanges" do
|
||||
Exchange.outgoing.should == [outgoing_exchange]
|
||||
expect(Exchange.outgoing).to eq([outgoing_exchange])
|
||||
end
|
||||
|
||||
it "correctly determines direction of exchanges between the same enterprise" do
|
||||
incoming_exchange.update_attributes sender: coordinator, incoming: true
|
||||
outgoing_exchange.update_attributes receiver: coordinator, incoming: false
|
||||
Exchange.incoming.should == [incoming_exchange]
|
||||
Exchange.outgoing.should == [outgoing_exchange]
|
||||
expect(Exchange.incoming).to eq([incoming_exchange])
|
||||
expect(Exchange.outgoing).to eq([outgoing_exchange])
|
||||
end
|
||||
|
||||
it "finds exchanges coming from an enterprise" do
|
||||
Exchange.from_enterprise(supplier).should == [incoming_exchange]
|
||||
Exchange.from_enterprise(coordinator).should == [outgoing_exchange]
|
||||
expect(Exchange.from_enterprise(supplier)).to eq([incoming_exchange])
|
||||
expect(Exchange.from_enterprise(coordinator)).to eq([outgoing_exchange])
|
||||
end
|
||||
|
||||
it "finds exchanges going to an enterprise" do
|
||||
Exchange.to_enterprise(coordinator).should == [incoming_exchange]
|
||||
Exchange.to_enterprise(distributor).should == [outgoing_exchange]
|
||||
expect(Exchange.to_enterprise(coordinator)).to eq([incoming_exchange])
|
||||
expect(Exchange.to_enterprise(distributor)).to eq([outgoing_exchange])
|
||||
end
|
||||
|
||||
it "finds exchanges coming from any of a number of enterprises" do
|
||||
Exchange.from_enterprises([coordinator]).should == [outgoing_exchange]
|
||||
Exchange.from_enterprises([supplier, coordinator]).should match_array [incoming_exchange, outgoing_exchange]
|
||||
expect(Exchange.from_enterprises([coordinator])).to eq([outgoing_exchange])
|
||||
expect(Exchange.from_enterprises([supplier, coordinator])).to match_array [incoming_exchange, outgoing_exchange]
|
||||
end
|
||||
|
||||
it "finds exchanges going to any of a number of enterprises" do
|
||||
Exchange.to_enterprises([coordinator]).should == [incoming_exchange]
|
||||
Exchange.to_enterprises([coordinator, distributor]).should match_array [incoming_exchange, outgoing_exchange]
|
||||
expect(Exchange.to_enterprises([coordinator])).to eq([incoming_exchange])
|
||||
expect(Exchange.to_enterprises([coordinator, distributor])).to match_array [incoming_exchange, outgoing_exchange]
|
||||
end
|
||||
|
||||
it "finds exchanges involving any of a number of enterprises" do
|
||||
Exchange.involving([supplier]).should == [incoming_exchange]
|
||||
Exchange.involving([coordinator]).should match_array [incoming_exchange, outgoing_exchange]
|
||||
Exchange.involving([distributor]).should == [outgoing_exchange]
|
||||
expect(Exchange.involving([supplier])).to eq([incoming_exchange])
|
||||
expect(Exchange.involving([coordinator])).to match_array [incoming_exchange, outgoing_exchange]
|
||||
expect(Exchange.involving([distributor])).to eq([outgoing_exchange])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -205,14 +205,14 @@ describe Exchange do
|
||||
d = create(:distributor_enterprise)
|
||||
ex = create(:exchange, order_cycle: oc, incoming: true)
|
||||
|
||||
oc.exchanges.supplying_to(d).should == [ex]
|
||||
expect(oc.exchanges.supplying_to(d)).to eq([ex])
|
||||
end
|
||||
|
||||
it "returns outgoing exchanges to the distributor" do
|
||||
d = create(:distributor_enterprise)
|
||||
ex = create(:exchange, order_cycle: oc, receiver: d, incoming: false)
|
||||
|
||||
oc.exchanges.supplying_to(d).should == [ex]
|
||||
expect(oc.exchanges.supplying_to(d)).to eq([ex])
|
||||
end
|
||||
|
||||
it "does not return outgoing exchanges to a different distributor" do
|
||||
@@ -220,7 +220,7 @@ describe Exchange do
|
||||
d2 = create(:distributor_enterprise)
|
||||
ex = create(:exchange, order_cycle: oc, receiver: d1, incoming: false)
|
||||
|
||||
oc.exchanges.supplying_to(d2).should be_empty
|
||||
expect(oc.exchanges.supplying_to(d2)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -229,7 +229,7 @@ describe Exchange do
|
||||
ex = create(:exchange)
|
||||
ex.variants << v
|
||||
|
||||
Exchange.with_variant(v).should == [ex]
|
||||
expect(Exchange.with_variant(v)).to eq([ex])
|
||||
end
|
||||
|
||||
it "finds exchanges with any of a number of variants, without returning duplicates" do
|
||||
@@ -240,7 +240,7 @@ describe Exchange do
|
||||
ex.variants << v1
|
||||
ex.variants << v2
|
||||
|
||||
Exchange.with_any_variant([v1, v2, v3]).should == [ex]
|
||||
expect(Exchange.with_any_variant([v1, v2, v3])).to eq([ex])
|
||||
end
|
||||
|
||||
it "finds exchanges with a particular product's master variant" do
|
||||
@@ -249,7 +249,7 @@ describe Exchange do
|
||||
ex.variants << p.master
|
||||
p.reload
|
||||
|
||||
Exchange.with_product(p).should == [ex]
|
||||
expect(Exchange.with_product(p)).to eq([ex])
|
||||
end
|
||||
|
||||
it "finds exchanges with a particular product's non-master variant" do
|
||||
@@ -259,7 +259,7 @@ describe Exchange do
|
||||
ex.variants << v
|
||||
p.reload
|
||||
|
||||
Exchange.with_product(p).should == [ex]
|
||||
expect(Exchange.with_product(p)).to eq([ex])
|
||||
end
|
||||
|
||||
describe "sorting exchanges by primary enterprise name" do
|
||||
@@ -272,7 +272,7 @@ describe Exchange do
|
||||
let!(:ex3) { create(:exchange, sender: e3, incoming: true) }
|
||||
|
||||
it "sorts" do
|
||||
Exchange.by_enterprise_name.should == [ex2, ex3, ex1]
|
||||
expect(Exchange.by_enterprise_name).to eq([ex2, ex3, ex1])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -285,7 +285,7 @@ describe Exchange do
|
||||
ex1.update_attribute(:tag_list, "wholesale")
|
||||
ex2 = ex1.clone! new_oc
|
||||
|
||||
ex1.eql?(ex2).should be true
|
||||
expect(ex1.eql?(ex2)).to be true
|
||||
expect(ex2.reload.tag_list).to eq ["wholesale"]
|
||||
end
|
||||
|
||||
@@ -294,13 +294,13 @@ describe Exchange do
|
||||
let(:exchange) do
|
||||
exchange = oc.exchanges.last
|
||||
exchange.save!
|
||||
exchange.stub(:variant_ids) { [1835, 1834] } # Test id ordering
|
||||
exchange.stub(:enterprise_fee_ids) { [1493, 1492] } # Test id ordering
|
||||
allow(exchange).to receive(:variant_ids) { [1835, 1834] } # Test id ordering
|
||||
allow(exchange).to receive(:enterprise_fee_ids) { [1493, 1492] } # Test id ordering
|
||||
exchange
|
||||
end
|
||||
|
||||
it "converts to a hash" do
|
||||
exchange.to_h.should ==
|
||||
expect(exchange.to_h).to eq(
|
||||
{'id' => exchange.id, 'order_cycle_id' => oc.id,
|
||||
'sender_id' => exchange.sender_id, 'receiver_id' => exchange.receiver_id,
|
||||
'incoming' => exchange.incoming,
|
||||
@@ -309,16 +309,18 @@ describe Exchange do
|
||||
'pickup_time' => exchange.pickup_time, 'pickup_instructions' => exchange.pickup_instructions,
|
||||
'receival_instructions' => exchange.receival_instructions,
|
||||
'created_at' => exchange.created_at, 'updated_at' => exchange.updated_at}
|
||||
)
|
||||
end
|
||||
|
||||
it "converts to a hash of core attributes only" do
|
||||
exchange.to_h(true).should ==
|
||||
expect(exchange.to_h(true)).to eq(
|
||||
{'sender_id' => exchange.sender_id, 'receiver_id' => exchange.receiver_id,
|
||||
'incoming' => exchange.incoming,
|
||||
'variant_ids' => exchange.variant_ids.sort,
|
||||
'enterprise_fee_ids' => exchange.enterprise_fee_ids.sort,
|
||||
'pickup_time' => exchange.pickup_time, 'pickup_instructions' => exchange.pickup_instructions,
|
||||
'receival_instructions' => exchange.receival_instructions}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -327,17 +329,17 @@ describe Exchange do
|
||||
e1 = Exchange.new
|
||||
e2 = Exchange.new
|
||||
|
||||
e1.stub(:to_h) { {'sender_id' => 456} }
|
||||
e2.stub(:to_h) { {'sender_id' => 456} }
|
||||
allow(e1).to receive(:to_h) { {'sender_id' => 456} }
|
||||
allow(e2).to receive(:to_h) { {'sender_id' => 456} }
|
||||
|
||||
e1.eql?(e2).should be true
|
||||
expect(e1.eql?(e2)).to be true
|
||||
end
|
||||
|
||||
it "compares other objects using super" do
|
||||
exchange = Exchange.new
|
||||
exchange_fee = ExchangeFee.new
|
||||
|
||||
exchange.eql?(exchange_fee).should be false
|
||||
expect(exchange.eql?(exchange_fee)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ describe ModelSet do
|
||||
|
||||
expect { ms.save }.to change(EnterpriseRelationshipPermission, :count).by(2)
|
||||
|
||||
EnterpriseRelationshipPermission.where(name: ['s1', 's2']).count.should == 2
|
||||
expect(EnterpriseRelationshipPermission.where(name: ['s1', 's2']).count).to eq(2)
|
||||
end
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ describe ModelSet do
|
||||
|
||||
expect { ms.save }.to change(EnterpriseGroup, :count).by(0)
|
||||
|
||||
EnterpriseGroup.where(name: ['e1zz', 'e2yy']).count.should == 2
|
||||
expect(EnterpriseGroup.where(name: ['e1zz', 'e2yy']).count).to eq(2)
|
||||
end
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ describe ModelSet do
|
||||
|
||||
expect { ms.save }.to change(Enterprise, :count).by(-1)
|
||||
|
||||
Enterprise.where(id: e1.id).should be_empty
|
||||
Enterprise.where(id: e2.id).should be_present
|
||||
expect(Enterprise.where(id: e1.id)).to be_empty
|
||||
expect(Enterprise.where(id: e2.id)).to be_present
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ describe OrderCycle do
|
||||
include OpenFoodNetwork::EmailHelper
|
||||
|
||||
it "should be valid when built from factory" do
|
||||
build(:simple_order_cycle).should be_valid
|
||||
expect(build(:simple_order_cycle)).to be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without a name" do
|
||||
oc = build(:simple_order_cycle)
|
||||
oc.name = ''
|
||||
oc.should_not be_valid
|
||||
expect(oc).not_to be_valid
|
||||
end
|
||||
|
||||
it 'should not be valid when open date is after close date' do
|
||||
@@ -46,7 +46,7 @@ describe OrderCycle do
|
||||
create(:exchange, order_cycle: oc)
|
||||
create(:exchange, order_cycle: oc)
|
||||
|
||||
oc.exchanges.count.should == 3
|
||||
expect(oc.exchanges.count).to eq(3)
|
||||
end
|
||||
|
||||
it "finds order cycles in various stages of their lifecycle" do
|
||||
@@ -57,13 +57,13 @@ describe OrderCycle do
|
||||
oc_undated_open = create(:simple_order_cycle, orders_open_at: 1.week.ago, orders_close_at: nil)
|
||||
oc_undated_close = create(:simple_order_cycle, orders_open_at: nil, orders_close_at: 1.week.from_now)
|
||||
|
||||
OrderCycle.active.should == [oc_active]
|
||||
OrderCycle.inactive.should match_array [oc_not_yet_open, oc_already_closed]
|
||||
OrderCycle.upcoming.should == [oc_not_yet_open]
|
||||
OrderCycle.closed.should == [oc_already_closed]
|
||||
OrderCycle.undated.should == [oc_undated, oc_undated_open, oc_undated_close]
|
||||
OrderCycle.not_closed.should == [oc_active, oc_not_yet_open, oc_undated, oc_undated_open, oc_undated_close]
|
||||
OrderCycle.dated.should == [oc_active, oc_not_yet_open, oc_already_closed]
|
||||
expect(OrderCycle.active).to eq([oc_active])
|
||||
expect(OrderCycle.inactive).to match_array [oc_not_yet_open, oc_already_closed]
|
||||
expect(OrderCycle.upcoming).to eq([oc_not_yet_open])
|
||||
expect(OrderCycle.closed).to eq([oc_already_closed])
|
||||
expect(OrderCycle.undated).to eq([oc_undated, oc_undated_open, oc_undated_close])
|
||||
expect(OrderCycle.not_closed).to eq([oc_active, oc_not_yet_open, oc_undated, oc_undated_open, oc_undated_close])
|
||||
expect(OrderCycle.dated).to eq([oc_active, oc_not_yet_open, oc_already_closed])
|
||||
end
|
||||
|
||||
it "finds order cycles accessible by a user" do
|
||||
@@ -77,8 +77,8 @@ describe OrderCycle do
|
||||
oc_received = create(:simple_order_cycle, distributors: [e2])
|
||||
oc_not_accessible = create(:simple_order_cycle, coordinator: e1)
|
||||
|
||||
OrderCycle.accessible_by(user).should include(oc_coordinated, oc_sent, oc_received)
|
||||
OrderCycle.accessible_by(user).should_not include(oc_not_accessible)
|
||||
expect(OrderCycle.accessible_by(user)).to include(oc_coordinated, oc_sent, oc_received)
|
||||
expect(OrderCycle.accessible_by(user)).not_to include(oc_not_accessible)
|
||||
end
|
||||
|
||||
it "finds the most recently closed order cycles" do
|
||||
@@ -86,7 +86,7 @@ describe OrderCycle do
|
||||
oc2 = create(:simple_order_cycle, orders_close_at: 1.hour.ago)
|
||||
oc3 = create(:simple_order_cycle, orders_close_at: 1.hour.from_now)
|
||||
|
||||
OrderCycle.most_recently_closed.should == [oc2, oc1]
|
||||
expect(OrderCycle.most_recently_closed).to eq([oc2, oc1])
|
||||
end
|
||||
|
||||
it "finds the soonest opening order cycles" do
|
||||
@@ -94,7 +94,7 @@ describe OrderCycle do
|
||||
oc2 = create(:simple_order_cycle, orders_open_at: 2.hours.from_now)
|
||||
oc3 = create(:simple_order_cycle, orders_open_at: 1.hour.ago)
|
||||
|
||||
OrderCycle.soonest_opening.should == [oc2, oc1]
|
||||
expect(OrderCycle.soonest_opening).to eq([oc2, oc1])
|
||||
end
|
||||
|
||||
it "finds the soonest closing order cycles" do
|
||||
@@ -102,7 +102,7 @@ describe OrderCycle do
|
||||
oc2 = create(:simple_order_cycle, orders_close_at: 2.hour.from_now)
|
||||
oc3 = create(:simple_order_cycle, orders_close_at: 1.hour.from_now)
|
||||
|
||||
OrderCycle.soonest_closing.should == [oc3, oc2]
|
||||
expect(OrderCycle.soonest_closing).to eq([oc3, oc2])
|
||||
end
|
||||
|
||||
describe "finding order cycles with a particular distributor" do
|
||||
@@ -111,17 +111,17 @@ describe OrderCycle do
|
||||
|
||||
it "returns order cycles with that distributor" do
|
||||
oc = create(:simple_order_cycle, coordinator: c, distributors: [d])
|
||||
OrderCycle.with_distributor(d).should == [oc]
|
||||
expect(OrderCycle.with_distributor(d)).to eq([oc])
|
||||
end
|
||||
|
||||
it "does not return order cycles with that enterprise as supplier" do
|
||||
oc = create(:simple_order_cycle, coordinator: c, suppliers: [d])
|
||||
OrderCycle.with_distributor(d).should == []
|
||||
expect(OrderCycle.with_distributor(d)).to eq([])
|
||||
end
|
||||
|
||||
it "does not return order cycles without that distributor" do
|
||||
oc = create(:simple_order_cycle, coordinator: c)
|
||||
OrderCycle.with_distributor(d).should == []
|
||||
expect(OrderCycle.with_distributor(d)).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -133,7 +133,7 @@ describe OrderCycle do
|
||||
e2 = create(:exchange, incoming: true,
|
||||
order_cycle: oc, receiver: oc.coordinator, sender: create(:enterprise))
|
||||
|
||||
oc.suppliers.should match_array [e1.sender, e2.sender]
|
||||
expect(oc.suppliers).to match_array [e1.sender, e2.sender]
|
||||
end
|
||||
|
||||
it "reports its distributors" do
|
||||
@@ -144,7 +144,7 @@ describe OrderCycle do
|
||||
e2 = create(:exchange, incoming: false,
|
||||
order_cycle: oc, sender: oc.coordinator, receiver: create(:enterprise))
|
||||
|
||||
oc.distributors.should match_array [e1.receiver, e2.receiver]
|
||||
expect(oc.distributors).to match_array [e1.receiver, e2.receiver]
|
||||
end
|
||||
|
||||
it "checks for existance of distributors" do
|
||||
@@ -153,8 +153,8 @@ describe OrderCycle do
|
||||
d2 = create(:distributor_enterprise)
|
||||
create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: d1, incoming: false)
|
||||
|
||||
oc.should have_distributor(d1)
|
||||
oc.should_not have_distributor(d2)
|
||||
expect(oc).to have_distributor(d1)
|
||||
expect(oc).not_to have_distributor(d2)
|
||||
end
|
||||
|
||||
it "checks for variants" do
|
||||
@@ -162,8 +162,8 @@ describe OrderCycle do
|
||||
p2 = create(:simple_product)
|
||||
oc = create(:simple_order_cycle, suppliers: [p1.supplier], variants: [p1.master])
|
||||
|
||||
oc.should have_variant(p1.master)
|
||||
oc.should_not have_variant(p2.master)
|
||||
expect(oc).to have_variant(p1.master)
|
||||
expect(oc).not_to have_variant(p2.master)
|
||||
end
|
||||
|
||||
describe "product exchanges" do
|
||||
@@ -202,39 +202,39 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
it "reports on the variants exchanged" do
|
||||
oc.variants.should match_array [p0.master, p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden]
|
||||
expect(oc.variants).to match_array [p0.master, p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden]
|
||||
end
|
||||
|
||||
it "returns the correct count of variants" do
|
||||
oc.variants.count.should == 6
|
||||
expect(oc.variants.count).to eq(6)
|
||||
end
|
||||
|
||||
it "reports on the variants supplied" do
|
||||
oc.supplied_variants.should match_array [p0.master]
|
||||
expect(oc.supplied_variants).to match_array [p0.master]
|
||||
end
|
||||
|
||||
it "reports on the variants distributed" do
|
||||
oc.distributed_variants.should match_array [p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden]
|
||||
expect(oc.distributed_variants).to match_array [p1.master, p2.master, p2_v, p1_v_visible, p1_v_hidden]
|
||||
end
|
||||
|
||||
it "reports on the products distributed by a particular distributor" do
|
||||
oc.products_distributed_by(d2).should == [p1]
|
||||
expect(oc.products_distributed_by(d2)).to eq([p1])
|
||||
end
|
||||
|
||||
it "reports on the products exchanged" do
|
||||
oc.products.should match_array [p0, p1, p2]
|
||||
expect(oc.products).to match_array [p0, p1, p2]
|
||||
end
|
||||
|
||||
context "listing variant distributed by a particular distributor" do
|
||||
context "when default settings are in play" do
|
||||
it "returns an empty list when no distributor is given" do
|
||||
oc.variants_distributed_by(nil).should == []
|
||||
expect(oc.variants_distributed_by(nil)).to eq([])
|
||||
end
|
||||
|
||||
it "returns all variants in the outgoing exchange for the distributor provided" do
|
||||
oc.variants_distributed_by(d2).should include p1.master, p1_v_visible
|
||||
oc.variants_distributed_by(d2).should_not include p1_v_hidden, p1_v_deleted
|
||||
oc.variants_distributed_by(d1).should include p2_v
|
||||
expect(oc.variants_distributed_by(d2)).to include p1.master, p1_v_visible
|
||||
expect(oc.variants_distributed_by(d2)).not_to include p1_v_hidden, p1_v_deleted
|
||||
expect(oc.variants_distributed_by(d1)).to include p2_v
|
||||
end
|
||||
end
|
||||
|
||||
@@ -244,11 +244,11 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
it "returns an empty list when no distributor is given" do
|
||||
oc.variants_distributed_by(nil).should == []
|
||||
expect(oc.variants_distributed_by(nil)).to eq([])
|
||||
end
|
||||
|
||||
it "returns only variants in the exchange that are also in the distributor's inventory" do
|
||||
oc.variants_distributed_by(d1).should_not include p2_v
|
||||
expect(oc.variants_distributed_by(d1)).not_to include p2_v
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -267,23 +267,23 @@ describe OrderCycle do
|
||||
end
|
||||
|
||||
it "finds the exchange for a distributor" do
|
||||
@oc.exchange_for_distributor(@d1).should == @e1
|
||||
@oc.exchange_for_distributor(@d2).should == @e2
|
||||
expect(@oc.exchange_for_distributor(@d1)).to eq(@e1)
|
||||
expect(@oc.exchange_for_distributor(@d2)).to eq(@e2)
|
||||
end
|
||||
|
||||
describe "finding pickup time for a distributor" do
|
||||
it "looks up the pickup time on the exchange when present" do
|
||||
@oc.pickup_time_for(@d1).should == '5pm Tuesday'
|
||||
expect(@oc.pickup_time_for(@d1)).to eq('5pm Tuesday')
|
||||
end
|
||||
|
||||
it "returns the distributor's default collection time otherwise" do
|
||||
@oc.pickup_time_for(@d2).should == '2-8pm Friday'
|
||||
expect(@oc.pickup_time_for(@d2)).to eq('2-8pm Friday')
|
||||
end
|
||||
end
|
||||
|
||||
describe "finding pickup instructions for a distributor" do
|
||||
it "returns the pickup instructions" do
|
||||
@oc.pickup_instructions_for(@d1).should == "Come get it!"
|
||||
expect(@oc.pickup_instructions_for(@d1)).to eq("Come get it!")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -293,60 +293,60 @@ describe OrderCycle do
|
||||
|
||||
it "reports status when an order cycle is upcoming" do
|
||||
Timecop.freeze(oc.orders_open_at - 1.second) do
|
||||
oc.should_not be_undated
|
||||
oc.should be_dated
|
||||
oc.should be_upcoming
|
||||
oc.should_not be_open
|
||||
oc.should_not be_closed
|
||||
expect(oc).not_to be_undated
|
||||
expect(oc).to be_dated
|
||||
expect(oc).to be_upcoming
|
||||
expect(oc).not_to be_open
|
||||
expect(oc).not_to be_closed
|
||||
end
|
||||
end
|
||||
|
||||
it "reports status when an order cycle is open" do
|
||||
oc.should_not be_undated
|
||||
oc.should be_dated
|
||||
oc.should_not be_upcoming
|
||||
oc.should be_open
|
||||
oc.should_not be_closed
|
||||
expect(oc).not_to be_undated
|
||||
expect(oc).to be_dated
|
||||
expect(oc).not_to be_upcoming
|
||||
expect(oc).to be_open
|
||||
expect(oc).not_to be_closed
|
||||
end
|
||||
|
||||
it "reports status when an order cycle has closed" do
|
||||
Timecop.freeze(oc.orders_close_at + 1.second) do
|
||||
oc.should_not be_undated
|
||||
oc.should be_dated
|
||||
oc.should_not be_upcoming
|
||||
oc.should_not be_open
|
||||
oc.should be_closed
|
||||
expect(oc).not_to be_undated
|
||||
expect(oc).to be_dated
|
||||
expect(oc).not_to be_upcoming
|
||||
expect(oc).not_to be_open
|
||||
expect(oc).to be_closed
|
||||
end
|
||||
end
|
||||
|
||||
it "reports status when an order cycle is undated" do
|
||||
oc.update_attributes!(orders_open_at: nil, orders_close_at: nil)
|
||||
|
||||
oc.should be_undated
|
||||
oc.should_not be_dated
|
||||
oc.should_not be_upcoming
|
||||
oc.should_not be_open
|
||||
oc.should_not be_closed
|
||||
expect(oc).to be_undated
|
||||
expect(oc).not_to be_dated
|
||||
expect(oc).not_to be_upcoming
|
||||
expect(oc).not_to be_open
|
||||
expect(oc).not_to be_closed
|
||||
end
|
||||
|
||||
it "reports status when an order cycle is partially dated - opening time only" do
|
||||
oc.update_attributes!(orders_close_at: nil)
|
||||
|
||||
oc.should be_undated
|
||||
oc.should_not be_dated
|
||||
oc.should_not be_upcoming
|
||||
oc.should_not be_open
|
||||
oc.should_not be_closed
|
||||
expect(oc).to be_undated
|
||||
expect(oc).not_to be_dated
|
||||
expect(oc).not_to be_upcoming
|
||||
expect(oc).not_to be_open
|
||||
expect(oc).not_to be_closed
|
||||
end
|
||||
|
||||
it "reports status when an order cycle is partially dated - closing time only" do
|
||||
oc.update_attributes!(orders_open_at: nil)
|
||||
|
||||
oc.should be_undated
|
||||
oc.should_not be_dated
|
||||
oc.should_not be_upcoming
|
||||
oc.should_not be_open
|
||||
oc.should_not be_closed
|
||||
expect(oc).to be_undated
|
||||
expect(oc).not_to be_dated
|
||||
expect(oc).not_to be_upcoming
|
||||
expect(oc).not_to be_open
|
||||
expect(oc).not_to be_closed
|
||||
end
|
||||
end
|
||||
|
||||
@@ -358,16 +358,16 @@ describe OrderCycle do
|
||||
oc.clone!
|
||||
|
||||
occ = OrderCycle.last
|
||||
occ.name.should == "COPY OF #{oc.name}"
|
||||
occ.orders_open_at.should be_nil
|
||||
occ.orders_close_at.should be_nil
|
||||
occ.coordinator.should_not be_nil
|
||||
occ.preferred_product_selection_from_coordinator_inventory_only.should be true
|
||||
occ.coordinator.should == oc.coordinator
|
||||
expect(occ.name).to eq("COPY OF #{oc.name}")
|
||||
expect(occ.orders_open_at).to be_nil
|
||||
expect(occ.orders_close_at).to be_nil
|
||||
expect(occ.coordinator).not_to be_nil
|
||||
expect(occ.preferred_product_selection_from_coordinator_inventory_only).to be true
|
||||
expect(occ.coordinator).to eq(oc.coordinator)
|
||||
|
||||
occ.coordinator_fee_ids.should_not be_empty
|
||||
occ.coordinator_fee_ids.should == oc.coordinator_fee_ids
|
||||
occ.preferred_product_selection_from_coordinator_inventory_only.should == oc.preferred_product_selection_from_coordinator_inventory_only
|
||||
expect(occ.coordinator_fee_ids).not_to be_empty
|
||||
expect(occ.coordinator_fee_ids).to eq(oc.coordinator_fee_ids)
|
||||
expect(occ.preferred_product_selection_from_coordinator_inventory_only).to eq(oc.preferred_product_selection_from_coordinator_inventory_only)
|
||||
|
||||
# to_h gives us a unique hash for each exchange
|
||||
# check that the clone has no additional exchanges
|
||||
@@ -383,12 +383,12 @@ describe OrderCycle do
|
||||
it "should give the most recently closed order cycle for a distributor" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.ago, orders_close_at: 9.days.ago)
|
||||
OrderCycle.most_recently_closed_for(distributor).should == oc
|
||||
expect(OrderCycle.most_recently_closed_for(distributor)).to eq(oc)
|
||||
end
|
||||
|
||||
it "should return nil when there have been none" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
OrderCycle.most_recently_closed_for(distributor).should == nil
|
||||
expect(OrderCycle.most_recently_closed_for(distributor)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -396,12 +396,12 @@ describe OrderCycle do
|
||||
it "should give the soonest opening order cycle for a distributor" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 10.days.from_now, orders_close_at: 11.days.from_now)
|
||||
OrderCycle.first_opening_for(distributor).should == oc
|
||||
expect(OrderCycle.first_opening_for(distributor)).to eq(oc)
|
||||
end
|
||||
|
||||
it "should return no order cycle when none are impending" do
|
||||
distributor = create(:distributor_enterprise)
|
||||
OrderCycle.first_opening_for(distributor).should == nil
|
||||
expect(OrderCycle.first_opening_for(distributor)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -410,7 +410,7 @@ describe OrderCycle do
|
||||
distributor = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, name: 'oc 1', distributors: [distributor], orders_open_at: 1.days.ago, orders_close_at: 11.days.from_now)
|
||||
oc2 = create(:simple_order_cycle, name: 'oc 2', distributors: [distributor], orders_open_at: 2.days.ago, orders_close_at: 12.days.from_now)
|
||||
OrderCycle.first_closing_for(distributor).should == oc
|
||||
expect(OrderCycle.first_closing_for(distributor)).to eq(oc)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -425,11 +425,11 @@ describe OrderCycle do
|
||||
let!(:oc3) { create(:simple_order_cycle, orders_close_at: time3, distributors: [e2]) }
|
||||
|
||||
it "returns the closing time, indexed by enterprise id" do
|
||||
OrderCycle.earliest_closing_times[e1.id].should == time1
|
||||
expect(OrderCycle.earliest_closing_times[e1.id]).to eq(time1)
|
||||
end
|
||||
|
||||
it "returns the earliest closing time" do
|
||||
OrderCycle.earliest_closing_times[e2.id].should == time2
|
||||
expect(OrderCycle.earliest_closing_times[e2.id]).to eq(time2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ describe OrderUpdater do
|
||||
let(:order_updater) { described_class.new(Spree::OrderUpdater.new(order)) }
|
||||
|
||||
it "is failed if no valid payments" do
|
||||
order.stub_chain(:payments, :valid, :empty?).and_return(true)
|
||||
allow(order).to receive_message_chain(:payments, :valid, :empty?).and_return(true)
|
||||
|
||||
order_updater.update_payment_state
|
||||
order.payment_state.should == 'failed'
|
||||
expect(order.payment_state).to eq('failed')
|
||||
end
|
||||
|
||||
context "payment total is greater than order total" do
|
||||
@@ -63,8 +63,8 @@ describe OrderUpdater do
|
||||
it "is credit_owed" do
|
||||
order.payment_total = 30
|
||||
order.total = 30
|
||||
order.stub_chain(:payments, :valid, :empty?).and_return(false)
|
||||
order.stub_chain(:payments, :completed, :empty?).and_return(false)
|
||||
allow(order).to receive_message_chain(:payments, :valid, :empty?).and_return(false)
|
||||
allow(order).to receive_message_chain(:payments, :completed, :empty?).and_return(false)
|
||||
expect {
|
||||
order_updater.update_payment_state
|
||||
}.to change { order.payment_state }.to 'credit_owed'
|
||||
@@ -75,8 +75,8 @@ describe OrderUpdater do
|
||||
it "is void" do
|
||||
order.payment_total = 0
|
||||
order.total = 30
|
||||
order.stub_chain(:payments, :valid, :empty?).and_return(false)
|
||||
order.stub_chain(:payments, :completed, :empty?).and_return(false)
|
||||
allow(order).to receive_message_chain(:payments, :valid, :empty?).and_return(false)
|
||||
allow(order).to receive_message_chain(:payments, :completed, :empty?).and_return(false)
|
||||
expect {
|
||||
order_updater.update_payment_state
|
||||
}.to change { order.payment_state }.to 'void'
|
||||
|
||||
@@ -22,10 +22,10 @@ module Spree
|
||||
user.enterprise_roles.create! enterprise: enterprise_any
|
||||
end
|
||||
|
||||
it { subject.can_manage_products?(user).should be true }
|
||||
it { subject.can_manage_enterprises?(user).should be true }
|
||||
it { subject.can_manage_orders?(user).should be true }
|
||||
it { subject.can_manage_order_cycles?(user).should be true }
|
||||
it { expect(subject.can_manage_products?(user)).to be true }
|
||||
it { expect(subject.can_manage_enterprises?(user)).to be true }
|
||||
it { expect(subject.can_manage_orders?(user)).to be true }
|
||||
it { expect(subject.can_manage_order_cycles?(user)).to be true }
|
||||
end
|
||||
|
||||
context "as manager of an enterprise who sell 'own'" do
|
||||
@@ -33,10 +33,10 @@ module Spree
|
||||
user.enterprise_roles.create! enterprise: enterprise_own
|
||||
end
|
||||
|
||||
it { subject.can_manage_products?(user).should be true }
|
||||
it { subject.can_manage_enterprises?(user).should be true }
|
||||
it { subject.can_manage_orders?(user).should be true }
|
||||
it { subject.can_manage_order_cycles?(user).should be true }
|
||||
it { expect(subject.can_manage_products?(user)).to be true }
|
||||
it { expect(subject.can_manage_enterprises?(user)).to be true }
|
||||
it { expect(subject.can_manage_orders?(user)).to be true }
|
||||
it { expect(subject.can_manage_order_cycles?(user)).to be true }
|
||||
end
|
||||
|
||||
context "as manager of an enterprise who sells 'none'" do
|
||||
@@ -44,10 +44,10 @@ module Spree
|
||||
user.enterprise_roles.create! enterprise: enterprise_none
|
||||
end
|
||||
|
||||
it { subject.can_manage_products?(user).should be false }
|
||||
it { subject.can_manage_enterprises?(user).should be true }
|
||||
it { subject.can_manage_orders?(user).should be false }
|
||||
it { subject.can_manage_order_cycles?(user).should be false }
|
||||
it { expect(subject.can_manage_products?(user)).to be false }
|
||||
it { expect(subject.can_manage_enterprises?(user)).to be true }
|
||||
it { expect(subject.can_manage_orders?(user)).to be false }
|
||||
it { expect(subject.can_manage_order_cycles?(user)).to be false }
|
||||
end
|
||||
|
||||
context "as manager of a producer enterprise who sells 'any'" do
|
||||
@@ -55,10 +55,10 @@ module Spree
|
||||
user.enterprise_roles.create! enterprise: enterprise_any_producer
|
||||
end
|
||||
|
||||
it { subject.can_manage_products?(user).should be true }
|
||||
it { subject.can_manage_enterprises?(user).should be true }
|
||||
it { subject.can_manage_orders?(user).should be true }
|
||||
it { subject.can_manage_order_cycles?(user).should be true }
|
||||
it { expect(subject.can_manage_products?(user)).to be true }
|
||||
it { expect(subject.can_manage_enterprises?(user)).to be true }
|
||||
it { expect(subject.can_manage_orders?(user)).to be true }
|
||||
it { expect(subject.can_manage_order_cycles?(user)).to be true }
|
||||
end
|
||||
|
||||
context "as manager of a producer enterprise who sell 'own'" do
|
||||
@@ -66,10 +66,10 @@ module Spree
|
||||
user.enterprise_roles.create! enterprise: enterprise_own_producer
|
||||
end
|
||||
|
||||
it { subject.can_manage_products?(user).should be true }
|
||||
it { subject.can_manage_enterprises?(user).should be true }
|
||||
it { subject.can_manage_orders?(user).should be true }
|
||||
it { subject.can_manage_order_cycles?(user).should be true }
|
||||
it { expect(subject.can_manage_products?(user)).to be true }
|
||||
it { expect(subject.can_manage_enterprises?(user)).to be true }
|
||||
it { expect(subject.can_manage_orders?(user)).to be true }
|
||||
it { expect(subject.can_manage_order_cycles?(user)).to be true }
|
||||
end
|
||||
|
||||
context "as manager of a producer enterprise who sells 'none'" do
|
||||
@@ -84,10 +84,10 @@ module Spree
|
||||
enterprise_none_producer.save!
|
||||
end
|
||||
|
||||
it { subject.can_manage_products?(user).should be true }
|
||||
it { subject.can_manage_enterprises?(user).should be true }
|
||||
it { subject.can_manage_orders?(user).should be false }
|
||||
it { subject.can_manage_order_cycles?(user).should be false }
|
||||
it { expect(subject.can_manage_products?(user)).to be true }
|
||||
it { expect(subject.can_manage_enterprises?(user)).to be true }
|
||||
it { expect(subject.can_manage_orders?(user)).to be false }
|
||||
it { expect(subject.can_manage_order_cycles?(user)).to be false }
|
||||
end
|
||||
|
||||
context "as a profile" do
|
||||
@@ -97,21 +97,21 @@ module Spree
|
||||
enterprise_none_producer.save!
|
||||
end
|
||||
|
||||
it { subject.can_manage_products?(user).should be false }
|
||||
it { subject.can_manage_enterprises?(user).should be true }
|
||||
it { subject.can_manage_orders?(user).should be false }
|
||||
it { subject.can_manage_order_cycles?(user).should be false }
|
||||
it { expect(subject.can_manage_products?(user)).to be false }
|
||||
it { expect(subject.can_manage_enterprises?(user)).to be true }
|
||||
it { expect(subject.can_manage_orders?(user)).to be false }
|
||||
it { expect(subject.can_manage_order_cycles?(user)).to be false }
|
||||
end
|
||||
end
|
||||
|
||||
context "as a new user with no enterprises" do
|
||||
it { subject.can_manage_products?(user).should be false }
|
||||
it { subject.can_manage_enterprises?(user).should be false }
|
||||
it { subject.can_manage_orders?(user).should be false }
|
||||
it { subject.can_manage_order_cycles?(user).should be false }
|
||||
it { expect(subject.can_manage_products?(user)).to be false }
|
||||
it { expect(subject.can_manage_enterprises?(user)).to be false }
|
||||
it { expect(subject.can_manage_orders?(user)).to be false }
|
||||
it { expect(subject.can_manage_order_cycles?(user)).to be false }
|
||||
|
||||
it "can create enterprises straight off the bat" do
|
||||
subject.is_new_user?(user).should be true
|
||||
expect(subject.is_new_user?(user)).to be true
|
||||
expect(user).to have_ability :create, for: Enterprise
|
||||
end
|
||||
end
|
||||
@@ -149,82 +149,82 @@ module Spree
|
||||
let(:order) { create(:order) }
|
||||
|
||||
it "should be able to read/write their enterprises' products and variants" do
|
||||
should have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p1)
|
||||
should have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p1.master)
|
||||
is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p1)
|
||||
is_expected.to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p1.master)
|
||||
end
|
||||
|
||||
it "should be able to read/write related enterprises' products and variants with manage_products permission" do
|
||||
er_ps
|
||||
should have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p_related)
|
||||
should have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p_related.master)
|
||||
is_expected.to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p_related)
|
||||
is_expected.to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy, :delete], for: p_related.master)
|
||||
end
|
||||
|
||||
it "should not be able to read/write other enterprises' products and variants" do
|
||||
should_not have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p2)
|
||||
should_not have_ability([:admin, :index, :read, :edit, :update, :search, :destroy], for: p2.master)
|
||||
is_expected.not_to have_ability([:admin, :read, :update, :bulk_update, :clone, :destroy], for: p2)
|
||||
is_expected.not_to have_ability([:admin, :index, :read, :edit, :update, :search, :destroy], for: p2.master)
|
||||
end
|
||||
|
||||
it "should not be able to access admin actions on orders" do
|
||||
should_not have_ability([:admin], for: Spree::Order)
|
||||
is_expected.not_to have_ability([:admin], for: Spree::Order)
|
||||
end
|
||||
|
||||
it "should be able to create a new product" do
|
||||
should have_ability(:create, for: Spree::Product)
|
||||
is_expected.to have_ability(:create, for: Spree::Product)
|
||||
end
|
||||
|
||||
it "should be able to read/write their enterprises' product variants" do
|
||||
should have_ability([:create], for: Spree::Variant)
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy, :delete], for: p1.master)
|
||||
is_expected.to have_ability([:create], for: Spree::Variant)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy, :delete], for: p1.master)
|
||||
end
|
||||
|
||||
it "should not be able to read/write other enterprises' product variants" do
|
||||
should_not have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: p2.master)
|
||||
is_expected.not_to have_ability([:admin, :index, :read, :create, :edit, :search, :update, :destroy], for: p2.master)
|
||||
end
|
||||
|
||||
it "should be able to read/write their enterprises' product properties" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: Spree::ProductProperty)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: Spree::ProductProperty)
|
||||
end
|
||||
|
||||
it "should be able to read/write their enterprises' product images" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :update, :destroy], for: Spree::Image)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :destroy], for: Spree::Image)
|
||||
end
|
||||
|
||||
it "should be able to read Taxons (in order to create classifications)" do
|
||||
should have_ability([:admin, :index, :read, :search], for: Spree::Taxon)
|
||||
is_expected.to have_ability([:admin, :index, :read, :search], for: Spree::Taxon)
|
||||
end
|
||||
|
||||
it "should be able to read/write Classifications on a product" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit], for: Spree::Classification)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit], for: Spree::Classification)
|
||||
end
|
||||
|
||||
it "should be able to read/write their enterprises' producer properties" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: ProducerProperty)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update_positions, :destroy], for: ProducerProperty)
|
||||
end
|
||||
|
||||
it "should be able to read and create enterprise relationships" do
|
||||
should have_ability([:admin, :index, :create], for: EnterpriseRelationship)
|
||||
is_expected.to have_ability([:admin, :index, :create], for: EnterpriseRelationship)
|
||||
end
|
||||
|
||||
it "should be able to destroy enterprise relationships for its enterprises" do
|
||||
should have_ability(:destroy, for: er1)
|
||||
is_expected.to have_ability(:destroy, for: er1)
|
||||
end
|
||||
|
||||
it "should not be able to destroy enterprise relationships for other enterprises" do
|
||||
should_not have_ability(:destroy, for: er2)
|
||||
is_expected.not_to have_ability(:destroy, for: er2)
|
||||
end
|
||||
|
||||
it "should be able to read some reports" do
|
||||
should have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management], for: Spree::Admin::ReportsController)
|
||||
is_expected.to have_ability([:admin, :index, :customers, :bulk_coop, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management], for: Spree::Admin::ReportsController)
|
||||
end
|
||||
|
||||
include_examples "allows access to Enterprise Fee Summary only if feature flag enabled"
|
||||
|
||||
it "should not be able to read other reports" do
|
||||
should_not have_ability([:sales_total, :group_buys, :payments, :orders_and_distributors, :users_and_enterprises, :xero_invoices], for: Spree::Admin::ReportsController)
|
||||
is_expected.not_to have_ability([:sales_total, :group_buys, :payments, :orders_and_distributors, :users_and_enterprises, :xero_invoices], for: Spree::Admin::ReportsController)
|
||||
end
|
||||
|
||||
it "should not be able to access customer actions" do
|
||||
should_not have_ability([:admin, :index, :update], for: Customer)
|
||||
is_expected.not_to have_ability([:admin, :index, :update], for: Customer)
|
||||
end
|
||||
|
||||
describe "order_cycles abilities" do
|
||||
@@ -232,19 +232,19 @@ module Spree
|
||||
let!(:order_cycle) { create(:simple_order_cycle) }
|
||||
|
||||
it "should not be able to access read/update order_cycle actions" do
|
||||
should_not have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
|
||||
is_expected.not_to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
|
||||
end
|
||||
|
||||
it "should not be able to access bulk_update, clone order cycle actions" do
|
||||
should_not have_ability([:bulk_update, :clone], for: order_cycle)
|
||||
is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle)
|
||||
end
|
||||
|
||||
it "cannot request permitted enterprises for an order cycle" do
|
||||
should_not have_ability([:for_order_cycle], for: Enterprise)
|
||||
is_expected.not_to have_ability([:for_order_cycle], for: Enterprise)
|
||||
end
|
||||
|
||||
it "cannot request permitted enterprise fees for an order cycle" do
|
||||
should_not have_ability([:for_order_cycle], for: EnterpriseFee)
|
||||
is_expected.not_to have_ability([:for_order_cycle], for: EnterpriseFee)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -253,19 +253,19 @@ module Spree
|
||||
let!(:exchange){ create(:exchange, incoming: true, order_cycle: order_cycle, receiver: order_cycle.coordinator, sender: s1) }
|
||||
|
||||
it "should be able to access read/update order cycle actions" do
|
||||
should have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
|
||||
is_expected.to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
|
||||
end
|
||||
|
||||
it "should not be able to access bulk/update, clone order cycle actions" do
|
||||
should_not have_ability([:bulk_update, :clone], for: order_cycle)
|
||||
is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle)
|
||||
end
|
||||
|
||||
it "can request permitted enterprises for an order cycle" do
|
||||
should have_ability([:for_order_cycle], for: Enterprise)
|
||||
is_expected.to have_ability([:for_order_cycle], for: Enterprise)
|
||||
end
|
||||
|
||||
it "can request permitted enterprise fees for an order cycle" do
|
||||
should have_ability([:for_order_cycle], for: EnterpriseFee)
|
||||
is_expected.to have_ability([:for_order_cycle], for: EnterpriseFee)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -301,19 +301,19 @@ module Spree
|
||||
let!(:er_pd) { create(:enterprise_relationship, parent: d_related, child: d1, permissions_list: [:edit_profile]) }
|
||||
|
||||
it "should be able to edit enterprises it manages" do
|
||||
should have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :bulk_update, :resend_confirmation], for: d1)
|
||||
is_expected.to have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :bulk_update, :resend_confirmation], for: d1)
|
||||
end
|
||||
|
||||
it "should be able to edit enterprises it has permission to" do
|
||||
should have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :bulk_update, :resend_confirmation], for: d_related)
|
||||
is_expected.to have_ability([:read, :edit, :update, :remove_logo, :remove_promo_image, :bulk_update, :resend_confirmation], for: d_related)
|
||||
end
|
||||
|
||||
it "should be able to manage shipping methods, payment methods and enterprise fees for enterprises it manages" do
|
||||
should have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d1)
|
||||
is_expected.to have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d1)
|
||||
end
|
||||
|
||||
it "should not be able to manage shipping methods, payment methods and enterprise fees for enterprises it has edit profile permission to" do
|
||||
should_not have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d_related)
|
||||
is_expected.not_to have_ability([:manage_shipping_methods, :manage_payment_methods, :manage_enterprise_fees], for: d_related)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -326,98 +326,98 @@ module Spree
|
||||
let!(:er1) { create(:enterprise_relationship, parent: s1, child: d1, permissions_list: [:create_variant_overrides]) }
|
||||
|
||||
it "should be able to access variant overrides page" do
|
||||
should have_ability([:admin, :index, :bulk_update, :bulk_reset], for: VariantOverride)
|
||||
is_expected.to have_ability([:admin, :index, :bulk_update, :bulk_reset], for: VariantOverride)
|
||||
end
|
||||
|
||||
it "should be able to read/write their own variant overrides" do
|
||||
should have_ability([:admin, :index, :read, :update], for: vo1)
|
||||
is_expected.to have_ability([:admin, :index, :read, :update], for: vo1)
|
||||
end
|
||||
|
||||
it "should not be able to read/write variant overrides when producer of product hasn't granted permission" do
|
||||
should_not have_ability([:admin, :index, :read, :update], for: vo2)
|
||||
is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo2)
|
||||
end
|
||||
|
||||
it "should not be able to read/write variant overrides when we can't add hub to order cycle" do
|
||||
should_not have_ability([:admin, :index, :read, :update], for: vo3)
|
||||
is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo3)
|
||||
end
|
||||
|
||||
it "should not be able to read/write other enterprises' variant overrides" do
|
||||
should_not have_ability([:admin, :index, :read, :update], for: vo4)
|
||||
is_expected.not_to have_ability([:admin, :index, :read, :update], for: vo4)
|
||||
end
|
||||
end
|
||||
|
||||
it "should be able to read/write their enterprises' orders" do
|
||||
should have_ability([:admin, :index, :read, :edit], for: o1)
|
||||
is_expected.to have_ability([:admin, :index, :read, :edit], for: o1)
|
||||
end
|
||||
|
||||
it "should not be able to read/write other enterprises' orders" do
|
||||
should_not have_ability([:admin, :index, :read, :edit], for: o2)
|
||||
is_expected.not_to have_ability([:admin, :index, :read, :edit], for: o2)
|
||||
end
|
||||
|
||||
it "should be able to read/write orders that are in the process of being created" do
|
||||
should have_ability([:admin, :index, :read, :edit], for: o3)
|
||||
is_expected.to have_ability([:admin, :index, :read, :edit], for: o3)
|
||||
end
|
||||
|
||||
it "should be able to create and search on nil (required for creating an order)" do
|
||||
should have_ability([:create, :search], for: nil)
|
||||
is_expected.to have_ability([:create, :search], for: nil)
|
||||
end
|
||||
|
||||
it "should be able to create a new order" do
|
||||
should have_ability([:admin, :index, :read, :create, :update], for: Spree::Order)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :update], for: Spree::Order)
|
||||
end
|
||||
|
||||
it "should be able to create a new line item" do
|
||||
should have_ability([:admin, :create], for: Spree::LineItem)
|
||||
is_expected.to have_ability([:admin, :create], for: Spree::LineItem)
|
||||
end
|
||||
|
||||
it "should be able to read/write Payments on a product" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Payment)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Payment)
|
||||
end
|
||||
|
||||
it "should be able to read/write Shipments on a product" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Shipment)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Shipment)
|
||||
end
|
||||
|
||||
it "should be able to read/write Adjustments on a product" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Adjustment)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::Adjustment)
|
||||
end
|
||||
|
||||
it "should be able to read/write ReturnAuthorizations on a product" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::ReturnAuthorization)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :update, :fire], for: Spree::ReturnAuthorization)
|
||||
end
|
||||
|
||||
it "should be able to read/write PaymentMethods" do
|
||||
should have_ability([:admin, :index, :create, :update, :destroy], for: Spree::PaymentMethod)
|
||||
is_expected.to have_ability([:admin, :index, :create, :update, :destroy], for: Spree::PaymentMethod)
|
||||
end
|
||||
|
||||
it "should be able to read/write ShippingMethods" do
|
||||
should have_ability([:admin, :index, :create, :update, :destroy], for: Spree::ShippingMethod)
|
||||
is_expected.to have_ability([:admin, :index, :create, :update, :destroy], for: Spree::ShippingMethod)
|
||||
end
|
||||
|
||||
it "should be able to read and create enterprise relationships" do
|
||||
should have_ability([:admin, :index, :create], for: EnterpriseRelationship)
|
||||
is_expected.to have_ability([:admin, :index, :create], for: EnterpriseRelationship)
|
||||
end
|
||||
|
||||
it "should be able to destroy enterprise relationships for its enterprises" do
|
||||
should have_ability(:destroy, for: er2)
|
||||
is_expected.to have_ability(:destroy, for: er2)
|
||||
end
|
||||
|
||||
it "should not be able to destroy enterprise relationships for other enterprises" do
|
||||
should_not have_ability(:destroy, for: er1)
|
||||
is_expected.not_to have_ability(:destroy, for: er1)
|
||||
end
|
||||
|
||||
it "should be able to read some reports" do
|
||||
should have_ability([:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :xero_invoices], for: Spree::Admin::ReportsController)
|
||||
is_expected.to have_ability([:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory, :order_cycle_management, :xero_invoices], for: Spree::Admin::ReportsController)
|
||||
end
|
||||
|
||||
include_examples "allows access to Enterprise Fee Summary only if feature flag enabled"
|
||||
|
||||
it "should not be able to read other reports" do
|
||||
should_not have_ability([:sales_total, :users_and_enterprises], for: Spree::Admin::ReportsController)
|
||||
is_expected.not_to have_ability([:sales_total, :users_and_enterprises], for: Spree::Admin::ReportsController)
|
||||
end
|
||||
|
||||
it "should be able to access customer actions" do
|
||||
should have_ability([:admin, :index, :update], for: Customer)
|
||||
is_expected.to have_ability([:admin, :index, :update], for: Customer)
|
||||
end
|
||||
|
||||
context "for a given order_cycle" do
|
||||
@@ -425,20 +425,20 @@ module Spree
|
||||
let!(:exchange){ create(:exchange, incoming: false, order_cycle: order_cycle, receiver: d1, sender: order_cycle.coordinator) }
|
||||
|
||||
it "should be able to access read and update order cycle actions" do
|
||||
should have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
|
||||
is_expected.to have_ability([:admin, :index, :read, :edit, :update], for: order_cycle)
|
||||
end
|
||||
|
||||
it "should not be able to access bulk_update, clone order cycle actions" do
|
||||
should_not have_ability([:bulk_update, :clone], for: order_cycle)
|
||||
is_expected.not_to have_ability([:bulk_update, :clone], for: order_cycle)
|
||||
end
|
||||
end
|
||||
|
||||
it "can request permitted enterprises for an order cycle" do
|
||||
should have_ability([:for_order_cycle], for: Enterprise)
|
||||
is_expected.to have_ability([:for_order_cycle], for: Enterprise)
|
||||
end
|
||||
|
||||
it "can request permitted enterprise fees for an order cycle" do
|
||||
should have_ability([:for_order_cycle], for: EnterpriseFee)
|
||||
is_expected.to have_ability([:for_order_cycle], for: EnterpriseFee)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -454,23 +454,23 @@ module Spree
|
||||
let(:oc2) { create(:simple_order_cycle) }
|
||||
|
||||
it "should be able to read/write OrderCycles they are the co-ordinator of" do
|
||||
should have_ability([:admin, :index, :read, :edit, :update, :bulk_update, :clone, :destroy], for: oc1)
|
||||
is_expected.to have_ability([:admin, :index, :read, :edit, :update, :bulk_update, :clone, :destroy], for: oc1)
|
||||
end
|
||||
|
||||
it "should not be able to read/write OrderCycles they are not the co-ordinator of" do
|
||||
should_not have_ability([:admin, :index, :read, :create, :edit, :update, :bulk_update, :clone, :destroy], for: oc2)
|
||||
is_expected.not_to have_ability([:admin, :index, :read, :create, :edit, :update, :bulk_update, :clone, :destroy], for: oc2)
|
||||
end
|
||||
|
||||
it "should be able to create OrderCycles" do
|
||||
should have_ability([:create], for: OrderCycle)
|
||||
is_expected.to have_ability([:create], for: OrderCycle)
|
||||
end
|
||||
|
||||
it "should be able to read/write EnterpriseFees" do
|
||||
should have_ability([:admin, :index, :read, :create, :edit, :bulk_update, :destroy, :for_order_cycle], for: EnterpriseFee)
|
||||
is_expected.to have_ability([:admin, :index, :read, :create, :edit, :bulk_update, :destroy, :for_order_cycle], for: EnterpriseFee)
|
||||
end
|
||||
|
||||
it "should be able to add enterprises to order cycles" do
|
||||
should have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise)
|
||||
is_expected.to have_ability([:admin, :index, :for_order_cycle, :create], for: Enterprise)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -483,28 +483,28 @@ module Spree
|
||||
end
|
||||
|
||||
it 'should have the ability to view the admin account page' do
|
||||
should have_ability([:admin, :show], for: :account)
|
||||
is_expected.to have_ability([:admin, :show], for: :account)
|
||||
end
|
||||
|
||||
it 'should have the ability to read and edit enterprises that I manage' do
|
||||
should have_ability([:read, :edit, :update, :bulk_update], for: s1)
|
||||
is_expected.to have_ability([:read, :edit, :update, :bulk_update], for: s1)
|
||||
end
|
||||
|
||||
it 'should not have the ability to read and edit enterprises that I do not manage' do
|
||||
should_not have_ability([:read, :edit, :update, :bulk_update], for: s2)
|
||||
is_expected.not_to have_ability([:read, :edit, :update, :bulk_update], for: s2)
|
||||
end
|
||||
|
||||
it 'should not have the ability to welcome and register enterprises that I do not own' do
|
||||
should_not have_ability([:welcome, :register], for: s1)
|
||||
is_expected.not_to have_ability([:welcome, :register], for: s1)
|
||||
end
|
||||
|
||||
it 'should have the ability administrate and create enterpises' do
|
||||
should have_ability([:admin, :index, :create], for: Enterprise)
|
||||
is_expected.to have_ability([:admin, :index, :create], for: Enterprise)
|
||||
end
|
||||
|
||||
it "should have the ability to search for users which share management of its enterprises" do
|
||||
should have_ability([:admin, :known_users, :customers], for: :search)
|
||||
should_not have_ability([:users], for: :search)
|
||||
is_expected.to have_ability([:admin, :known_users, :customers], for: :search)
|
||||
is_expected.not_to have_ability([:users], for: :search)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -512,11 +512,11 @@ module Spree
|
||||
let(:user) { s1.owner }
|
||||
|
||||
it 'should have the ability to welcome and register enterprises that I own' do
|
||||
should have_ability([:welcome, :register], for: s1)
|
||||
is_expected.to have_ability([:welcome, :register], for: s1)
|
||||
end
|
||||
|
||||
it 'should have the ability to view the admin account page' do
|
||||
should have_ability([:admin, :show], for: :account)
|
||||
is_expected.to have_ability([:admin, :show], for: :account)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ module Spree
|
||||
describe Adjustment do
|
||||
it "has metadata" do
|
||||
adjustment = create(:adjustment, metadata: create(:adjustment_metadata))
|
||||
adjustment.metadata.should be
|
||||
expect(adjustment.metadata).to be
|
||||
end
|
||||
|
||||
describe "querying included tax" do
|
||||
@@ -13,23 +13,23 @@ module Spree
|
||||
|
||||
describe "finding adjustments with and without tax included" do
|
||||
it "finds adjustments with tax" do
|
||||
Adjustment.with_tax.should include adjustment_with_tax
|
||||
Adjustment.with_tax.should_not include adjustment_without_tax
|
||||
expect(Adjustment.with_tax).to include adjustment_with_tax
|
||||
expect(Adjustment.with_tax).not_to include adjustment_without_tax
|
||||
end
|
||||
|
||||
it "finds adjustments without tax" do
|
||||
Adjustment.without_tax.should include adjustment_without_tax
|
||||
Adjustment.without_tax.should_not include adjustment_with_tax
|
||||
expect(Adjustment.without_tax).to include adjustment_without_tax
|
||||
expect(Adjustment.without_tax).not_to include adjustment_with_tax
|
||||
end
|
||||
end
|
||||
|
||||
describe "checking if an adjustment includes tax" do
|
||||
it "returns true when it has > 0 tax" do
|
||||
adjustment_with_tax.should have_tax
|
||||
expect(adjustment_with_tax).to have_tax
|
||||
end
|
||||
|
||||
it "returns false when it has 0 tax" do
|
||||
adjustment_without_tax.should_not have_tax
|
||||
expect(adjustment_without_tax).not_to have_tax
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -48,8 +48,8 @@ module Spree
|
||||
end
|
||||
|
||||
it "has 100% tax included" do
|
||||
adjustment.amount.should be > 0
|
||||
adjustment.included_tax.should == adjustment.amount
|
||||
expect(adjustment.amount).to be > 0
|
||||
expect(adjustment.included_tax).to eq(adjustment.amount)
|
||||
end
|
||||
|
||||
it "does not crash when order data has been updated previously" do
|
||||
@@ -151,7 +151,7 @@ module Spree
|
||||
# The fee is $50, tax is 10%, and the fee is inclusive of tax
|
||||
# Therefore, the included tax should be 0.1/1.1 * 50 = $4.55
|
||||
|
||||
adjustment.included_tax.should == 4.55
|
||||
expect(adjustment.included_tax).to eq(4.55)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -163,8 +163,8 @@ module Spree
|
||||
end
|
||||
|
||||
it "records the tax on TaxRate adjustment on the order" do
|
||||
adjustment.included_tax.should == 0
|
||||
order.adjustments.tax.first.amount.should == 5.0
|
||||
expect(adjustment.included_tax).to eq(0)
|
||||
expect(order.adjustments.tax.first.amount).to eq(5.0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -176,7 +176,7 @@ module Spree
|
||||
end
|
||||
|
||||
it "records no tax as charged" do
|
||||
adjustment.included_tax.should == 0
|
||||
expect(adjustment.included_tax).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -186,7 +186,7 @@ module Spree
|
||||
|
||||
describe "when the tax rate includes the tax in the price" do
|
||||
it "records the tax on the enterprise fee adjustments" do
|
||||
adjustment.included_tax.should == 4.55
|
||||
expect(adjustment.included_tax).to eq(4.55)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -198,8 +198,8 @@ module Spree
|
||||
end
|
||||
|
||||
it "records the tax on TaxRate adjustment on the order" do
|
||||
adjustment.included_tax.should == 0
|
||||
order.adjustments.tax.first.amount.should == 5.0
|
||||
expect(adjustment.included_tax).to eq(0)
|
||||
expect(order.adjustments.tax.first.amount).to eq(5.0)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -224,8 +224,8 @@ module Spree
|
||||
# EnterpriseFee tax category is nil and inheritance only applies to per item fees
|
||||
# so tax on the enterprise_fee adjustment will be 0
|
||||
# Tax on line item is: 0.2/1.2 x $10 = $1.67
|
||||
adjustment.included_tax.should == 0.0
|
||||
line_item.adjustments.first.included_tax.should == 1.67
|
||||
expect(adjustment.included_tax).to eq(0.0)
|
||||
expect(line_item.adjustments.first.included_tax).to eq(1.67)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -240,8 +240,8 @@ module Spree
|
||||
# EnterpriseFee tax category is nil and inheritance only applies to per item fees
|
||||
# so total tax on the order is only that which applies to the line_item itself
|
||||
# ie. $10 x 0.2 = $2.0
|
||||
adjustment.included_tax.should == 0
|
||||
order.adjustments.tax.first.amount.should == 2.0
|
||||
expect(adjustment.included_tax).to eq(0)
|
||||
expect(order.adjustments.tax.first.amount).to eq(2.0)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -254,8 +254,8 @@ module Spree
|
||||
# Applying product tax rate of 0.2 to enterprise fee of $50
|
||||
# gives tax on fee of 0.2/1.2 x $50 = $8.33
|
||||
# Tax on line item is: 0.2/1.2 x $10 = $1.67
|
||||
adjustment.included_tax.should == 8.33
|
||||
line_item.adjustments.first.included_tax.should == 1.67
|
||||
expect(adjustment.included_tax).to eq(8.33)
|
||||
expect(line_item.adjustments.first.included_tax).to eq(1.67)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -270,8 +270,8 @@ module Spree
|
||||
# EnterpriseFee inherits tax_category from product so total tax on
|
||||
# the order is that which applies to the line item itself, plus the
|
||||
# same rate applied to the fee of $50. ie. ($10 + $50) x 0.2 = $12.0
|
||||
adjustment.included_tax.should == 0
|
||||
order.adjustments.tax.first.amount.should == 12.0
|
||||
expect(adjustment.included_tax).to eq(0)
|
||||
expect(order.adjustments.tax.first.amount).to eq(12.0)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -283,7 +283,7 @@ module Spree
|
||||
|
||||
it "sets it, rounding to two decimal places" do
|
||||
adjustment.set_included_tax! 0.25
|
||||
adjustment.included_tax.should == 10.00
|
||||
expect(adjustment.included_tax).to eq(10.00)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,10 +4,10 @@ describe Spree::Calculator::FlatPercentItemTotal do
|
||||
let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new }
|
||||
let(:line_item) { build(:line_item, price: 10, quantity: 1) }
|
||||
|
||||
before { calculator.stub preferred_flat_percent: 10 }
|
||||
before { allow(calculator).to receive_messages preferred_flat_percent: 10 }
|
||||
|
||||
it "computes amount correctly for a single line item" do
|
||||
calculator.compute(line_item).should == 1.0
|
||||
expect(calculator.compute(line_item)).to eq(1.0)
|
||||
end
|
||||
|
||||
context "extends LocalizedNumber" do
|
||||
@@ -18,6 +18,6 @@ describe Spree::Calculator::FlatPercentItemTotal do
|
||||
order = double(:order, line_items: [line_item] )
|
||||
package = double(:package, order: order)
|
||||
|
||||
calculator.compute(package).should == 1.0
|
||||
expect(calculator.compute(package)).to eq(1.0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
describe Spree::Calculator::FlatRate do
|
||||
let(:calculator) { Spree::Calculator::FlatRate.new }
|
||||
|
||||
before { calculator.stub :preferred_amount => 10 }
|
||||
before { allow(calculator).to receive_messages :preferred_amount => 10 }
|
||||
|
||||
context "extends LocalizedNumber" do
|
||||
it_behaves_like "a model using the LocalizedNumber module", [:preferred_amount]
|
||||
|
||||
@@ -6,8 +6,8 @@ describe Spree::Calculator::PerItem do
|
||||
let(:line_item) { build(:line_item, quantity: 5) }
|
||||
|
||||
it "correctly calculates on a single line item object" do
|
||||
calculator.stub(calculable: shipping_calculable)
|
||||
calculator.compute(line_item).to_f.should == 50 # 5 x 10
|
||||
allow(calculator).to receive_messages(calculable: shipping_calculable)
|
||||
expect(calculator.compute(line_item).to_f).to eq(50) # 5 x 10
|
||||
end
|
||||
|
||||
context "extends LocalizedNumber" do
|
||||
|
||||
@@ -8,8 +8,8 @@ module Spree
|
||||
|
||||
it "won't destroy if classification is the primary taxon" do
|
||||
product.primary_taxon = taxon
|
||||
classification.destroy.should be false
|
||||
classification.errors.messages[:base].should == ["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"]
|
||||
expect(classification.destroy).to be false
|
||||
expect(classification.errors.messages[:base]).to eq(["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"])
|
||||
end
|
||||
|
||||
describe "callbacks" do
|
||||
|
||||
@@ -7,11 +7,11 @@ module Spree
|
||||
let(:formatted) { {mini: ["48x48>", "png"]} }
|
||||
|
||||
it "converts style names to symbols" do
|
||||
Image.format_styles(name_str).should == {:mini => "48x48>"}
|
||||
expect(Image.format_styles(name_str)).to eq({:mini => "48x48>"})
|
||||
end
|
||||
|
||||
it "converts formats to symbols" do
|
||||
Image.format_styles(formatted).should == {:mini => ["48x48>", :png]}
|
||||
expect(Image.format_styles(formatted)).to eq({:mini => ["48x48>", :png]})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ module Spree
|
||||
let(:oc_order) { create :order_with_totals_and_distribution }
|
||||
|
||||
it "finds line items for products supplied by a particular enterprise" do
|
||||
LineItem.supplied_by(s1).should == [li1]
|
||||
LineItem.supplied_by(s2).should == [li2]
|
||||
expect(LineItem.supplied_by(s1)).to eq([li1])
|
||||
expect(LineItem.supplied_by(s2)).to eq([li2])
|
||||
end
|
||||
|
||||
it "finds line items for products supplied by one of a number of enterprises" do
|
||||
LineItem.supplied_by_any([s1]).should == [li1]
|
||||
LineItem.supplied_by_any([s2]).should == [li2]
|
||||
LineItem.supplied_by_any([s1, s2]).should match_array [li1, li2]
|
||||
expect(LineItem.supplied_by_any([s1])).to eq([li1])
|
||||
expect(LineItem.supplied_by_any([s2])).to eq([li2])
|
||||
expect(LineItem.supplied_by_any([s1, s2])).to match_array [li1, li2]
|
||||
end
|
||||
|
||||
describe "finding line items with and without tax" do
|
||||
@@ -46,11 +46,11 @@ module Spree
|
||||
before { li1; li2 }
|
||||
|
||||
it "finds line items with tax" do
|
||||
LineItem.with_tax.should == [li1]
|
||||
expect(LineItem.with_tax).to eq([li1])
|
||||
end
|
||||
|
||||
it "finds line items without tax" do
|
||||
LineItem.without_tax.should == [li2]
|
||||
expect(LineItem.without_tax).to eq([li2])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -225,10 +225,10 @@ module Spree
|
||||
it "does not return fractional cents" do
|
||||
li = LineItem.new
|
||||
|
||||
li.stub(:price) { 55.55 }
|
||||
li.stub_chain(:order, :adjustments, :where, :sum) { 11.11 }
|
||||
li.stub(:quantity) { 2 }
|
||||
li.price_with_adjustments.should == 61.11
|
||||
allow(li).to receive(:price) { 55.55 }
|
||||
allow(li).to receive_message_chain(:order, :adjustments, :where, :sum) { 11.11 }
|
||||
allow(li).to receive(:quantity) { 2 }
|
||||
expect(li.price_with_adjustments).to eq(61.11)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -236,10 +236,10 @@ module Spree
|
||||
it "returns a value consistent with price_with_adjustments" do
|
||||
li = LineItem.new
|
||||
|
||||
li.stub(:price) { 55.55 }
|
||||
li.stub_chain(:order, :adjustments, :where, :sum) { 11.11 }
|
||||
li.stub(:quantity) { 2 }
|
||||
li.amount_with_adjustments.should == 122.22
|
||||
allow(li).to receive(:price) { 55.55 }
|
||||
allow(li).to receive_message_chain(:order, :adjustments, :where, :sum) { 11.11 }
|
||||
allow(li).to receive(:quantity) { 2 }
|
||||
expect(li.amount_with_adjustments).to eq(122.22)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -407,45 +407,45 @@ module Spree
|
||||
|
||||
context "when display_name is blank" do
|
||||
before do
|
||||
li.stub(:unit_to_display) { 'unit_to_display' }
|
||||
li.stub(:display_name) { '' }
|
||||
allow(li).to receive(:unit_to_display) { 'unit_to_display' }
|
||||
allow(li).to receive(:display_name) { '' }
|
||||
end
|
||||
|
||||
it "returns unit_to_display" do
|
||||
li.full_name.should == 'unit_to_display'
|
||||
expect(li.full_name).to eq('unit_to_display')
|
||||
end
|
||||
end
|
||||
|
||||
context "when unit_to_display contains display_name" do
|
||||
before do
|
||||
li.stub(:unit_to_display) { '1kg Jar' }
|
||||
li.stub(:display_name) { '1kg' }
|
||||
allow(li).to receive(:unit_to_display) { '1kg Jar' }
|
||||
allow(li).to receive(:display_name) { '1kg' }
|
||||
end
|
||||
|
||||
it "returns unit_to_display" do
|
||||
li.full_name.should == '1kg Jar'
|
||||
expect(li.full_name).to eq('1kg Jar')
|
||||
end
|
||||
end
|
||||
|
||||
context "when display_name contains unit_to_display" do
|
||||
before do
|
||||
li.stub(:unit_to_display) { '10kg' }
|
||||
li.stub(:display_name) { '10kg Box' }
|
||||
allow(li).to receive(:unit_to_display) { '10kg' }
|
||||
allow(li).to receive(:display_name) { '10kg Box' }
|
||||
end
|
||||
|
||||
it "returns display_name" do
|
||||
li.full_name.should == '10kg Box'
|
||||
expect(li.full_name).to eq('10kg Box')
|
||||
end
|
||||
end
|
||||
|
||||
context "otherwise" do
|
||||
before do
|
||||
li.stub(:unit_to_display) { '1 Loaf' }
|
||||
li.stub(:display_name) { 'Spelt Sourdough' }
|
||||
allow(li).to receive(:unit_to_display) { '1 Loaf' }
|
||||
allow(li).to receive(:display_name) { 'Spelt Sourdough' }
|
||||
end
|
||||
|
||||
it "returns unit_to_display" do
|
||||
li.full_name.should == 'Spelt Sourdough (1 Loaf)'
|
||||
expect(li.full_name).to eq('Spelt Sourdough (1 Loaf)')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -459,7 +459,7 @@ module Spree
|
||||
before { allow(li).to receive(:full_name) { p.name + " - something" } }
|
||||
|
||||
it "does not show the product name twice" do
|
||||
li.product_and_full_name.should == 'product - something'
|
||||
expect(li.product_and_full_name).to eq('product - something')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -467,7 +467,7 @@ module Spree
|
||||
before { allow(li).to receive(:full_name) { "display_name (unit)" } }
|
||||
|
||||
it "prepends the product name to the full name" do
|
||||
li.product_and_full_name.should == 'product - display_name (unit)'
|
||||
expect(li.product_and_full_name).to eq('product - display_name (unit)')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -475,15 +475,15 @@ module Spree
|
||||
describe "getting name for display" do
|
||||
it "returns product name" do
|
||||
li = create(:line_item, product: create(:product))
|
||||
li.name_to_display.should == li.product.name
|
||||
expect(li.name_to_display).to eq(li.product.name)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting unit for display" do
|
||||
it "returns options_text" do
|
||||
li = create(:line_item)
|
||||
li.stub(:options_text).and_return "ponies"
|
||||
li.unit_to_display.should == "ponies"
|
||||
allow(li).to receive(:options_text).and_return "ponies"
|
||||
expect(li.unit_to_display).to eq("ponies")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -503,10 +503,10 @@ module Spree
|
||||
li.update_attribute(:final_weight_volume, 10)
|
||||
}.to change(Spree::OptionValue, :count).by(1)
|
||||
|
||||
li.option_values.should_not include ov_orig
|
||||
li.option_values.should_not include ov_var
|
||||
expect(li.option_values).not_to include ov_orig
|
||||
expect(li.option_values).not_to include ov_var
|
||||
ov = li.option_values.last
|
||||
ov.name.should == "10g foo"
|
||||
expect(ov.name).to eq("10g foo")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -526,8 +526,8 @@ module Spree
|
||||
li.update_attribute(:final_weight_volume, 10)
|
||||
}.to change(Spree::OptionValue, :count).by(0)
|
||||
|
||||
li.option_values.should_not include ov_orig
|
||||
li.option_values.should include ov_new
|
||||
expect(li.option_values).not_to include ov_orig
|
||||
expect(li.option_values).to include ov_new
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ describe Spree::Order do
|
||||
subject.add_variant(p.master, 1, 3)
|
||||
|
||||
li = Spree::LineItem.last
|
||||
li.max_quantity.should == 3
|
||||
expect(li.max_quantity).to eq(3)
|
||||
end
|
||||
|
||||
it "does nothing when the line item is not found" do
|
||||
@@ -27,45 +27,45 @@ describe Spree::Order do
|
||||
let(:order) { build(:order) }
|
||||
|
||||
it "clears all enterprise fee adjustments on the order" do
|
||||
EnterpriseFee.should_receive(:clear_all_adjustments_on_order).with(subject)
|
||||
expect(EnterpriseFee).to receive(:clear_all_adjustments_on_order).with(subject)
|
||||
subject.update_distribution_charge!
|
||||
end
|
||||
|
||||
it "skips order cycle per-order adjustments for orders that don't have an order cycle" do
|
||||
EnterpriseFee.stub(:clear_all_adjustments_on_order)
|
||||
subject.stub(:line_items) { [] }
|
||||
allow(EnterpriseFee).to receive(:clear_all_adjustments_on_order)
|
||||
allow(subject).to receive(:line_items) { [] }
|
||||
|
||||
subject.stub(:order_cycle) { nil }
|
||||
allow(subject).to receive(:order_cycle) { nil }
|
||||
|
||||
subject.update_distribution_charge!
|
||||
end
|
||||
|
||||
it "ensures the correct adjustment(s) are created for order cycles" do
|
||||
EnterpriseFee.stub(:clear_all_adjustments_on_order)
|
||||
allow(EnterpriseFee).to receive(:clear_all_adjustments_on_order)
|
||||
line_item = double(:line_item)
|
||||
subject.stub(:line_items) { [line_item] }
|
||||
subject.stub(:provided_by_order_cycle?) { true }
|
||||
allow(subject).to receive(:line_items) { [line_item] }
|
||||
allow(subject).to receive(:provided_by_order_cycle?) { true }
|
||||
|
||||
order_cycle = double(:order_cycle)
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.
|
||||
should_receive(:create_line_item_adjustments_for).
|
||||
expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).
|
||||
to receive(:create_line_item_adjustments_for).
|
||||
with(line_item)
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.stub(:create_order_adjustments_for)
|
||||
subject.stub(:order_cycle) { order_cycle }
|
||||
allow_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:create_order_adjustments_for)
|
||||
allow(subject).to receive(:order_cycle) { order_cycle }
|
||||
|
||||
subject.update_distribution_charge!
|
||||
end
|
||||
|
||||
it "ensures the correct per-order adjustment(s) are created for order cycles" do
|
||||
EnterpriseFee.stub(:clear_all_adjustments_on_order)
|
||||
subject.stub(:line_items) { [] }
|
||||
allow(EnterpriseFee).to receive(:clear_all_adjustments_on_order)
|
||||
allow(subject).to receive(:line_items) { [] }
|
||||
|
||||
order_cycle = double(:order_cycle)
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.
|
||||
should_receive(:create_order_adjustments_for).
|
||||
expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).
|
||||
to receive(:create_order_adjustments_for).
|
||||
with(subject)
|
||||
|
||||
subject.stub(:order_cycle) { order_cycle }
|
||||
allow(subject).to receive(:order_cycle) { order_cycle }
|
||||
|
||||
subject.update_distribution_charge!
|
||||
end
|
||||
@@ -76,26 +76,26 @@ describe Spree::Order do
|
||||
v = double(:variant)
|
||||
line_item = double(:line_item, variant: v)
|
||||
order_cycle = double(:order_cycle, variants: [v])
|
||||
subject.stub(:order_cycle) { order_cycle }
|
||||
allow(subject).to receive(:order_cycle) { order_cycle }
|
||||
|
||||
subject.send(:provided_by_order_cycle?, line_item).should be true
|
||||
expect(subject.send(:provided_by_order_cycle?, line_item)).to be true
|
||||
end
|
||||
|
||||
it "returns false otherwise" do
|
||||
v = double(:variant)
|
||||
line_item = double(:line_item, variant: v)
|
||||
order_cycle = double(:order_cycle, variants: [])
|
||||
subject.stub(:order_cycle) { order_cycle }
|
||||
allow(subject).to receive(:order_cycle) { order_cycle }
|
||||
|
||||
subject.send(:provided_by_order_cycle?, line_item).should be false
|
||||
expect(subject.send(:provided_by_order_cycle?, line_item)).to be false
|
||||
end
|
||||
|
||||
it "returns false when there is no order cycle" do
|
||||
v = double(:variant)
|
||||
line_item = double(:line_item, variant: v)
|
||||
subject.stub(:order_cycle) { nil }
|
||||
allow(subject).to receive(:order_cycle) { nil }
|
||||
|
||||
subject.send(:provided_by_order_cycle?, line_item).should be false
|
||||
expect(subject.send(:provided_by_order_cycle?, line_item)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -108,7 +108,7 @@ describe Spree::Order do
|
||||
ef.calculator.set_preference :amount, 123.45
|
||||
a = ef.create_adjustment("adjustment", o, o, true)
|
||||
|
||||
o.admin_and_handling_total.should == 123.45
|
||||
expect(o.admin_and_handling_total).to eq(123.45)
|
||||
end
|
||||
|
||||
it "does not include ineligible adjustments" do
|
||||
@@ -118,7 +118,7 @@ describe Spree::Order do
|
||||
|
||||
a.update_column :eligible, false
|
||||
|
||||
o.admin_and_handling_total.should == 0
|
||||
expect(o.admin_and_handling_total).to eq(0)
|
||||
end
|
||||
|
||||
it "does not include adjustments that do not originate from enterprise fees" do
|
||||
@@ -126,7 +126,7 @@ describe Spree::Order do
|
||||
sm.calculator.set_preference :amount, 123.45
|
||||
sm.create_adjustment("adjustment", o, o, true)
|
||||
|
||||
o.admin_and_handling_total.should == 0
|
||||
expect(o.admin_and_handling_total).to eq(0)
|
||||
end
|
||||
|
||||
it "does not include adjustments whose source is a line item" do
|
||||
@@ -134,7 +134,7 @@ describe Spree::Order do
|
||||
ef.calculator.set_preference :amount, 123.45
|
||||
ef.create_adjustment("adjustment", li.order, li, true)
|
||||
|
||||
o.admin_and_handling_total.should == 0
|
||||
expect(o.admin_and_handling_total).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -142,7 +142,7 @@ describe Spree::Order do
|
||||
let(:order) { create(:order) }
|
||||
|
||||
it "cannot be shipped" do
|
||||
order.ready_to_ship?.should == false
|
||||
expect(order.ready_to_ship?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -156,7 +156,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "cannot be shipped" do
|
||||
order.ready_to_ship?.should == false
|
||||
expect(order.ready_to_ship?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -169,7 +169,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "cannot be shipped" do
|
||||
order.ready_to_ship?.should == false
|
||||
expect(order.ready_to_ship?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -183,7 +183,7 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "can be shipped" do
|
||||
order.ready_to_ship?.should == true
|
||||
expect(order.ready_to_ship?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -200,13 +200,13 @@ describe Spree::Order do
|
||||
let!(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method, order: order) }
|
||||
|
||||
it "returns the shipping tax" do
|
||||
order.shipping_tax.should == 10
|
||||
expect(order.shipping_tax).to eq(10)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the order has not been shipped' do
|
||||
it "returns zero when the order has not been shipped" do
|
||||
order.shipping_tax.should == 0
|
||||
expect(order.shipping_tax).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -219,7 +219,7 @@ describe Spree::Order do
|
||||
let!(:adjustment2) { create(:adjustment, adjustable: order, originator: enterprise_fee2, label: "EF 2", amount: 123, included_tax: 2.00) }
|
||||
|
||||
it "returns a sum of the tax included in all enterprise fees" do
|
||||
order.reload.enterprise_fee_tax.should == 12
|
||||
expect(order.reload.enterprise_fee_tax).to eq(12)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -322,7 +322,7 @@ describe Spree::Order do
|
||||
it "sets the distributor when no order cycle is set" do
|
||||
d = create(:distributor_enterprise)
|
||||
subject.set_distributor! d
|
||||
subject.distributor.should == d
|
||||
expect(subject.distributor).to eq(d)
|
||||
end
|
||||
|
||||
it "keeps the order cycle when it is available at the new distributor" do
|
||||
@@ -333,8 +333,8 @@ describe Spree::Order do
|
||||
subject.order_cycle = oc
|
||||
subject.set_distributor! d
|
||||
|
||||
subject.distributor.should == d
|
||||
subject.order_cycle.should == oc
|
||||
expect(subject.distributor).to eq(d)
|
||||
expect(subject.order_cycle).to eq(oc)
|
||||
end
|
||||
|
||||
it "clears the order cycle if it is not available at that distributor" do
|
||||
@@ -344,8 +344,8 @@ describe Spree::Order do
|
||||
subject.order_cycle = oc
|
||||
subject.set_distributor! d
|
||||
|
||||
subject.distributor.should == d
|
||||
subject.order_cycle.should be_nil
|
||||
expect(subject.distributor).to eq(d)
|
||||
expect(subject.order_cycle).to be_nil
|
||||
end
|
||||
|
||||
it "clears the distributor when setting to nil" do
|
||||
@@ -353,7 +353,7 @@ describe Spree::Order do
|
||||
subject.set_distributor! d
|
||||
subject.set_distributor! nil
|
||||
|
||||
subject.distributor.should be_nil
|
||||
expect(subject.distributor).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -370,7 +370,7 @@ describe Spree::Order do
|
||||
|
||||
it "removes the variant's line item" do
|
||||
order.remove_variant v1
|
||||
order.line_items(:reload).map(&:variant).should == [v2]
|
||||
expect(order.line_items(:reload).map(&:variant)).to eq([v2])
|
||||
end
|
||||
|
||||
it "does nothing when there is no matching line item" do
|
||||
@@ -400,18 +400,18 @@ describe Spree::Order do
|
||||
let(:oc) { create(:simple_order_cycle) }
|
||||
|
||||
it "empties the cart when changing the order cycle" do
|
||||
subject.should_receive(:empty!)
|
||||
expect(subject).to receive(:empty!)
|
||||
subject.set_order_cycle! oc
|
||||
end
|
||||
|
||||
it "doesn't empty the cart if the order cycle is not different" do
|
||||
subject.should_not_receive(:empty!)
|
||||
expect(subject).not_to receive(:empty!)
|
||||
subject.set_order_cycle! subject.order_cycle
|
||||
end
|
||||
|
||||
it "sets the order cycle when no distributor is set" do
|
||||
subject.set_order_cycle! oc
|
||||
subject.order_cycle.should == oc
|
||||
expect(subject.order_cycle).to eq(oc)
|
||||
end
|
||||
|
||||
it "keeps the distributor when it is available in the new order cycle" do
|
||||
@@ -421,8 +421,8 @@ describe Spree::Order do
|
||||
subject.distributor = d
|
||||
subject.set_order_cycle! oc
|
||||
|
||||
subject.order_cycle.should == oc
|
||||
subject.distributor.should == d
|
||||
expect(subject.order_cycle).to eq(oc)
|
||||
expect(subject.distributor).to eq(d)
|
||||
end
|
||||
|
||||
it "clears the distributor if it is not available at that order cycle" do
|
||||
@@ -431,8 +431,8 @@ describe Spree::Order do
|
||||
subject.distributor = d
|
||||
subject.set_order_cycle! oc
|
||||
|
||||
subject.order_cycle.should == oc
|
||||
subject.distributor.should be_nil
|
||||
expect(subject.order_cycle).to eq(oc)
|
||||
expect(subject.distributor).to be_nil
|
||||
end
|
||||
|
||||
it "clears the order cycle when setting to nil" do
|
||||
@@ -442,8 +442,8 @@ describe Spree::Order do
|
||||
|
||||
subject.set_order_cycle! nil
|
||||
|
||||
subject.order_cycle.should be_nil
|
||||
subject.distributor.should == d
|
||||
expect(subject.order_cycle).to be_nil
|
||||
expect(subject.distributor).to eq(d)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -467,9 +467,9 @@ describe Spree::Order do
|
||||
new_order_cycle = create(:simple_order_cycle, distributors: [new_distributor], variants: [variant1, variant2])
|
||||
|
||||
subject.distributor = new_distributor
|
||||
subject.should_not be_valid
|
||||
expect(subject).not_to be_valid
|
||||
subject.order_cycle = new_order_cycle
|
||||
subject.should be_valid
|
||||
expect(subject).to be_valid
|
||||
end
|
||||
|
||||
it "does not allow the change when not all variants in the order are provided by the new distributor" do
|
||||
@@ -477,8 +477,8 @@ describe Spree::Order do
|
||||
create(:simple_order_cycle, distributors: [new_distributor], variants: [variant1])
|
||||
|
||||
subject.distributor = new_distributor
|
||||
subject.should_not be_valid
|
||||
subject.errors.messages.should == {:base => ["Distributor or order cycle cannot supply the products in your cart"]}
|
||||
expect(subject).not_to be_valid
|
||||
expect(subject.errors.messages).to eq({:base => ["Distributor or order cycle cannot supply the products in your cart"]})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -491,7 +491,7 @@ describe Spree::Order do
|
||||
it "finds only orders not in specified state" do
|
||||
o = FactoryBot.create(:completed_order_with_totals, distributor: create(:distributor_enterprise))
|
||||
o.cancel!
|
||||
Spree::Order.not_state(:canceled).should_not include o
|
||||
expect(Spree::Order.not_state(:canceled)).not_to include o
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,24 +7,24 @@ module Spree
|
||||
pm2 = create(:payment_method, name: 'AA')
|
||||
pm3 = create(:payment_method, name: 'BB')
|
||||
|
||||
PaymentMethod.by_name.should == [pm2, pm3, pm1]
|
||||
expect(PaymentMethod.by_name).to eq([pm2, pm3, pm1])
|
||||
end
|
||||
|
||||
it "raises errors when required fields are missing" do
|
||||
pm = PaymentMethod.new()
|
||||
pm.save
|
||||
pm.errors.to_a.should == ["Name can't be blank", "At least one hub must be selected"]
|
||||
expect(pm.errors.to_a).to eq(["Name can't be blank", "At least one hub must be selected"])
|
||||
end
|
||||
|
||||
it "generates a clean name for known Payment Method types" do
|
||||
Spree::PaymentMethod::Check.clean_name.should == "Cash/EFT/etc. (payments for which automatic validation is not required)"
|
||||
Spree::Gateway::Migs.clean_name.should == "MasterCard Internet Gateway Service (MIGS)"
|
||||
Spree::Gateway::Pin.clean_name.should == "Pin Payments"
|
||||
Spree::Gateway::PayPalExpress.clean_name.should == "PayPal Express"
|
||||
Spree::Gateway::StripeConnect.clean_name.should == "Stripe"
|
||||
expect(Spree::PaymentMethod::Check.clean_name).to eq("Cash/EFT/etc. (payments for which automatic validation is not required)")
|
||||
expect(Spree::Gateway::Migs.clean_name).to eq("MasterCard Internet Gateway Service (MIGS)")
|
||||
expect(Spree::Gateway::Pin.clean_name).to eq("Pin Payments")
|
||||
expect(Spree::Gateway::PayPalExpress.clean_name).to eq("PayPal Express")
|
||||
expect(Spree::Gateway::StripeConnect.clean_name).to eq("Stripe")
|
||||
|
||||
# Testing else condition
|
||||
Spree::Gateway::BogusSimple.clean_name.should == "BogusSimple"
|
||||
expect(Spree::Gateway::BogusSimple.clean_name).to eq("BogusSimple")
|
||||
end
|
||||
|
||||
it "computes the amount of fees" do
|
||||
|
||||
@@ -7,17 +7,17 @@ module Spree
|
||||
let(:payment) { create(:payment, source: create(:credit_card)) }
|
||||
|
||||
it "can capture and void" do
|
||||
payment.actions.should match_array %w(capture void)
|
||||
expect(payment.actions).to match_array %w(capture void)
|
||||
end
|
||||
|
||||
describe "when a payment has been taken" do
|
||||
before do
|
||||
payment.stub(:state) { 'completed' }
|
||||
payment.stub(:order) { double(:order, payment_state: 'credit_owed') }
|
||||
allow(payment).to receive(:state) { 'completed' }
|
||||
allow(payment).to receive(:order) { double(:order, payment_state: 'credit_owed') }
|
||||
end
|
||||
|
||||
it "can void and credit" do
|
||||
payment.actions.should match_array %w(void credit)
|
||||
expect(payment.actions).to match_array %w(void credit)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -28,18 +28,18 @@ module Spree
|
||||
let(:payment) { create(:payment, source: create(:credit_card), payment_method: pin) }
|
||||
|
||||
it "does not void" do
|
||||
payment.actions.should_not include 'void'
|
||||
expect(payment.actions).not_to include 'void'
|
||||
end
|
||||
|
||||
describe "when a payment has been taken" do
|
||||
before do
|
||||
payment.stub(:state) { 'completed' }
|
||||
payment.stub(:order) { double(:order, payment_state: 'credit_owed') }
|
||||
allow(payment).to receive(:state) { 'completed' }
|
||||
allow(payment).to receive(:order) { double(:order, payment_state: 'credit_owed') }
|
||||
end
|
||||
|
||||
it "can refund instead of crediting" do
|
||||
payment.actions.should_not include 'credit'
|
||||
payment.actions.should include 'refund'
|
||||
expect(payment.actions).not_to include 'credit'
|
||||
expect(payment.actions).to include 'refund'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -51,76 +51,76 @@ module Spree
|
||||
let(:failure) { double(:success? => false) }
|
||||
|
||||
it "always checks the environment" do
|
||||
payment.payment_method.stub(:refund) { success }
|
||||
payment.should_receive(:check_environment)
|
||||
allow(payment.payment_method).to receive(:refund) { success }
|
||||
expect(payment).to receive(:check_environment)
|
||||
payment.refund!
|
||||
end
|
||||
|
||||
describe "calculating refund amount" do
|
||||
it "returns the parameter amount when given" do
|
||||
payment.send(:calculate_refund_amount, 123).should === 123.0
|
||||
expect(payment.send(:calculate_refund_amount, 123)).to be === 123.0
|
||||
end
|
||||
|
||||
it "refunds up to the value of the payment when the outstanding balance is larger" do
|
||||
payment.stub(:credit_allowed) { 123 }
|
||||
payment.stub(:order) { double(:order, outstanding_balance: 1000) }
|
||||
payment.send(:calculate_refund_amount).should == 123
|
||||
allow(payment).to receive(:credit_allowed) { 123 }
|
||||
allow(payment).to receive(:order) { double(:order, outstanding_balance: 1000) }
|
||||
expect(payment.send(:calculate_refund_amount)).to eq(123)
|
||||
end
|
||||
|
||||
it "refunds up to the outstanding balance of the order when the payment is larger" do
|
||||
payment.stub(:credit_allowed) { 1000 }
|
||||
payment.stub(:order) { double(:order, outstanding_balance: 123) }
|
||||
payment.send(:calculate_refund_amount).should == 123
|
||||
allow(payment).to receive(:credit_allowed) { 1000 }
|
||||
allow(payment).to receive(:order) { double(:order, outstanding_balance: 123) }
|
||||
expect(payment.send(:calculate_refund_amount)).to eq(123)
|
||||
end
|
||||
end
|
||||
|
||||
describe "performing refunds" do
|
||||
before do
|
||||
payment.stub(:calculate_refund_amount) { 123 }
|
||||
payment.payment_method.should_receive(:refund).and_return(success)
|
||||
allow(payment).to receive(:calculate_refund_amount) { 123 }
|
||||
expect(payment.payment_method).to receive(:refund).and_return(success)
|
||||
end
|
||||
|
||||
it "performs the refund without payment profiles" do
|
||||
payment.payment_method.stub(:payment_profiles_supported?) { false }
|
||||
allow(payment.payment_method).to receive(:payment_profiles_supported?) { false }
|
||||
payment.refund!
|
||||
end
|
||||
|
||||
it "performs the refund with payment profiles" do
|
||||
payment.payment_method.stub(:payment_profiles_supported?) { true }
|
||||
allow(payment.payment_method).to receive(:payment_profiles_supported?) { true }
|
||||
payment.refund!
|
||||
end
|
||||
end
|
||||
|
||||
it "records the response" do
|
||||
payment.stub(:calculate_refund_amount) { 123 }
|
||||
payment.payment_method.stub(:refund).and_return(success)
|
||||
payment.should_receive(:record_response).with(success)
|
||||
allow(payment).to receive(:calculate_refund_amount) { 123 }
|
||||
allow(payment.payment_method).to receive(:refund).and_return(success)
|
||||
expect(payment).to receive(:record_response).with(success)
|
||||
payment.refund!
|
||||
end
|
||||
|
||||
it "records a payment on success" do
|
||||
payment.stub(:calculate_refund_amount) { 123 }
|
||||
payment.payment_method.stub(:refund).and_return(success)
|
||||
payment.stub(:record_response)
|
||||
allow(payment).to receive(:calculate_refund_amount) { 123 }
|
||||
allow(payment.payment_method).to receive(:refund).and_return(success)
|
||||
allow(payment).to receive(:record_response)
|
||||
|
||||
expect do
|
||||
payment.refund!
|
||||
end.to change(Payment, :count).by(1)
|
||||
|
||||
p = Payment.last
|
||||
p.order.should == payment.order
|
||||
p.source.should == payment
|
||||
p.payment_method.should == payment.payment_method
|
||||
p.amount.should == -123
|
||||
p.response_code.should == success.authorization
|
||||
p.state.should == 'completed'
|
||||
expect(p.order).to eq(payment.order)
|
||||
expect(p.source).to eq(payment)
|
||||
expect(p.payment_method).to eq(payment.payment_method)
|
||||
expect(p.amount).to eq(-123)
|
||||
expect(p.response_code).to eq(success.authorization)
|
||||
expect(p.state).to eq('completed')
|
||||
end
|
||||
|
||||
it "logs the error on failure" do
|
||||
payment.stub(:calculate_refund_amount) { 123 }
|
||||
payment.payment_method.stub(:refund).and_return(failure)
|
||||
payment.stub(:record_response)
|
||||
payment.should_receive(:gateway_error).with(failure)
|
||||
allow(payment).to receive(:calculate_refund_amount) { 123 }
|
||||
allow(payment.payment_method).to receive(:refund).and_return(failure)
|
||||
allow(payment).to receive(:record_response)
|
||||
expect(payment).to receive(:gateway_error).with(failure)
|
||||
payment.refund!
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,40 +16,40 @@ module Spree
|
||||
describe "getting preferences" do
|
||||
it "returns regular preferences" do
|
||||
c.name = 'foo'
|
||||
c.get_preference(:name).should == 'foo'
|
||||
expect(c.get_preference(:name)).to eq('foo')
|
||||
end
|
||||
|
||||
it "returns file preferences" do
|
||||
c.get_preference(:logo).should be_a Paperclip::Attachment
|
||||
expect(c.get_preference(:logo)).to be_a Paperclip::Attachment
|
||||
end
|
||||
|
||||
it "returns regular preferences via []" do
|
||||
c.name = 'foo'
|
||||
c[:name].should == 'foo'
|
||||
expect(c[:name]).to eq('foo')
|
||||
end
|
||||
|
||||
it "returns file preferences via []" do
|
||||
c[:logo].should be_a Paperclip::Attachment
|
||||
expect(c[:logo]).to be_a Paperclip::Attachment
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting preference types" do
|
||||
it "returns regular preference types" do
|
||||
c.preference_type(:name).should == :string
|
||||
expect(c.preference_type(:name)).to eq(:string)
|
||||
end
|
||||
|
||||
it "returns file preference types" do
|
||||
c.preference_type(:logo).should == :file
|
||||
expect(c.preference_type(:logo)).to eq(:file)
|
||||
end
|
||||
end
|
||||
|
||||
describe "respond_to?" do
|
||||
it "responds to preference getters" do
|
||||
c.respond_to?(:name).should be true
|
||||
expect(c.respond_to?(:name)).to be true
|
||||
end
|
||||
|
||||
it "responds to preference setters" do
|
||||
c.respond_to?(:name=).should be true
|
||||
expect(c.respond_to?(:name=)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,21 +4,21 @@ module Spree
|
||||
describe Product do
|
||||
|
||||
describe "associations" do
|
||||
it { should belong_to(:supplier) }
|
||||
it { should belong_to(:primary_taxon) }
|
||||
it { is_expected.to belong_to(:supplier) }
|
||||
it { is_expected.to belong_to(:primary_taxon) }
|
||||
end
|
||||
|
||||
describe "validations and defaults" do
|
||||
it "is valid when built from factory" do
|
||||
build(:product).should be_valid
|
||||
expect(build(:product)).to be_valid
|
||||
end
|
||||
|
||||
it "requires a primary taxon" do
|
||||
build(:simple_product, taxons: [], primary_taxon: nil).should_not be_valid
|
||||
expect(build(:simple_product, taxons: [], primary_taxon: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
it "requires a supplier" do
|
||||
build(:simple_product, supplier: nil).should_not be_valid
|
||||
expect(build(:simple_product, supplier: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
it "does not save when master is invalid" do
|
||||
@@ -32,7 +32,7 @@ module Spree
|
||||
it "defaults available_on to now" do
|
||||
Timecop.freeze do
|
||||
product = Product.new
|
||||
product.available_on.should == Time.zone.now
|
||||
expect(product.available_on).to eq(Time.zone.now)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ module Spree
|
||||
context "when a tax category is required" do
|
||||
it "is invalid when a tax category is not provided" do
|
||||
with_products_require_tax_category(true) do
|
||||
build(:product, tax_category_id: nil).should_not be_valid
|
||||
expect(build(:product, tax_category_id: nil)).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -48,7 +48,7 @@ module Spree
|
||||
context "when a tax category is not required" do
|
||||
it "is valid when a tax category is not provided" do
|
||||
with_products_require_tax_category(false) do
|
||||
build(:product, tax_category_id: nil).should be_valid
|
||||
expect(build(:product, tax_category_id: nil)).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -63,7 +63,7 @@ module Spree
|
||||
|
||||
it "requires a unit" do
|
||||
product.variant_unit = nil
|
||||
product.should_not be_valid
|
||||
expect(product).not_to be_valid
|
||||
end
|
||||
|
||||
%w(weight volume).each do |unit|
|
||||
@@ -72,14 +72,14 @@ module Spree
|
||||
product.variant_unit = unit
|
||||
product.variant_unit_scale = 1
|
||||
product.variant_unit_name = nil
|
||||
product.should be_valid
|
||||
expect(product).to be_valid
|
||||
end
|
||||
|
||||
it "is invalid when unit scale is not set" do
|
||||
product.variant_unit = unit
|
||||
product.variant_unit_scale = nil
|
||||
product.variant_unit_name = nil
|
||||
product.should_not be_valid
|
||||
expect(product).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -118,14 +118,14 @@ module Spree
|
||||
product.variant_unit = 'items'
|
||||
product.variant_unit_name = 'loaf'
|
||||
product.variant_unit_scale = nil
|
||||
product.should be_valid
|
||||
expect(product).to be_valid
|
||||
end
|
||||
|
||||
it "is invalid when unit name is not set" do
|
||||
product.variant_unit = 'items'
|
||||
product.variant_unit_name = nil
|
||||
product.variant_unit_scale = nil
|
||||
product.should_not be_valid
|
||||
expect(product).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -146,7 +146,7 @@ module Spree
|
||||
product.variant_unit_scale = nil
|
||||
product.variant_unit_name = nil
|
||||
|
||||
product.should_not be_valid
|
||||
expect(product).not_to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -211,7 +211,7 @@ module Spree
|
||||
s2 = create(:supplier_enterprise)
|
||||
p1 = create(:product, supplier: s1)
|
||||
p2 = create(:product, supplier: s2)
|
||||
Product.in_supplier(s1).should == [p1]
|
||||
expect(Product.in_supplier(s1)).to eq([p1])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -224,7 +224,7 @@ module Spree
|
||||
p2 = create(:product)
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.master])
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master])
|
||||
Product.in_distributor(d1).should == [p1]
|
||||
expect(Product.in_distributor(d1)).to eq([p1])
|
||||
end
|
||||
|
||||
it "shows products in order cycle distribution by variant" do
|
||||
@@ -237,7 +237,7 @@ module Spree
|
||||
v2 = create(:variant, product: p2)
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [v1])
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [v2])
|
||||
Product.in_distributor(d1).should == [p1]
|
||||
expect(Product.in_distributor(d1)).to eq([p1])
|
||||
end
|
||||
|
||||
it "doesn't show products listed in the incoming exchange only" do
|
||||
@@ -249,7 +249,7 @@ module Spree
|
||||
ex = oc.exchanges.incoming.first
|
||||
ex.variants << p.master
|
||||
|
||||
Product.in_distributor(d).should be_empty
|
||||
expect(Product.in_distributor(d)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -259,7 +259,7 @@ module Spree
|
||||
s2 = create(:supplier_enterprise)
|
||||
p1 = create(:product, supplier: s1)
|
||||
p2 = create(:product, supplier: s2)
|
||||
Product.in_supplier_or_distributor(s1).should == [p1]
|
||||
expect(Product.in_supplier_or_distributor(s1)).to eq([p1])
|
||||
end
|
||||
|
||||
it "shows products in order cycle distribution" do
|
||||
@@ -270,7 +270,7 @@ module Spree
|
||||
p2 = create(:product)
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.master])
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master])
|
||||
Product.in_supplier_or_distributor(d1).should == [p1]
|
||||
expect(Product.in_supplier_or_distributor(d1)).to eq([p1])
|
||||
end
|
||||
|
||||
it "shows products in all three without duplicates" do
|
||||
@@ -278,7 +278,7 @@ module Spree
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product, supplier: s)
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master])
|
||||
[s, d].each { |e| Product.in_supplier_or_distributor(e).should == [p] }
|
||||
[s, d].each { |e| expect(Product.in_supplier_or_distributor(e)).to eq([p]) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -291,7 +291,7 @@ module Spree
|
||||
p2 = create(:product)
|
||||
oc1 = create(:simple_order_cycle, suppliers: [s], distributors: [d1], variants: [p1.master])
|
||||
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master])
|
||||
Product.in_order_cycle(oc1).should == [p1]
|
||||
expect(Product.in_order_cycle(oc1)).to eq([p1])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -305,7 +305,7 @@ module Spree
|
||||
p3 = create(:product)
|
||||
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master], orders_open_at: 8.days.ago, orders_close_at: 1.day.ago)
|
||||
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d3], variants: [p3.master], orders_close_at: Date.tomorrow)
|
||||
Product.in_an_active_order_cycle.should == [p3]
|
||||
expect(Product.in_an_active_order_cycle).to eq([p3])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -323,17 +323,17 @@ module Spree
|
||||
@e1.enterprise_roles.build(user: user).save
|
||||
|
||||
product = Product.managed_by user
|
||||
product.count.should == 1
|
||||
product.should include @p1
|
||||
expect(product.count).to eq(1)
|
||||
expect(product).to include @p1
|
||||
end
|
||||
|
||||
it "shows all products for admin user" do
|
||||
user = create(:admin_user)
|
||||
|
||||
product = Product.managed_by user
|
||||
product.count.should == 2
|
||||
product.should include @p1
|
||||
product.should include @p2
|
||||
expect(product.count).to eq(2)
|
||||
expect(product).to include @p1
|
||||
expect(product).to include @p2
|
||||
end
|
||||
end
|
||||
|
||||
@@ -380,7 +380,7 @@ module Spree
|
||||
product.set_property 'Organic Certified', 'NASAA 12345'
|
||||
property = product.properties.last
|
||||
|
||||
product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}]
|
||||
expect(product.properties_including_inherited).to eq([{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}])
|
||||
end
|
||||
|
||||
it "returns producer properties as a hash" do
|
||||
@@ -390,7 +390,7 @@ module Spree
|
||||
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
|
||||
property = supplier.properties.last
|
||||
|
||||
product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}]
|
||||
expect(product.properties_including_inherited).to eq([{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}])
|
||||
end
|
||||
|
||||
it "overrides producer properties with product properties" do
|
||||
@@ -401,7 +401,7 @@ module Spree
|
||||
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
|
||||
property = product.properties.last
|
||||
|
||||
product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}]
|
||||
expect(product.properties_including_inherited).to eq([{id: property.id, name: "Organic Certified", value: 'NASAA 12345'}])
|
||||
end
|
||||
|
||||
context "when product has an inherit_properties value set to true" do
|
||||
@@ -412,7 +412,7 @@ module Spree
|
||||
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
|
||||
property = supplier.properties.last
|
||||
|
||||
product.properties_including_inherited.should == [{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}]
|
||||
expect(product.properties_including_inherited).to eq([{id: property.id, name: "Organic Certified", value: 'NASAA 54321'}])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -423,7 +423,7 @@ module Spree
|
||||
it "does not inherit producer properties" do
|
||||
supplier.set_producer_property 'Organic Certified', 'NASAA 54321'
|
||||
|
||||
product.properties_including_inherited.should == []
|
||||
expect(product.properties_including_inherited).to eq([])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -439,10 +439,11 @@ module Spree
|
||||
product.product_properties.create!({property_id: pc.id, value: '3', position: 3}, {without_protection: true})
|
||||
supplier.producer_properties.create!({property_id: pb.id, value: '2', position: 2}, {without_protection: true})
|
||||
|
||||
product.properties_including_inherited.should ==
|
||||
expect(product.properties_including_inherited).to eq(
|
||||
[{id: pa.id, name: "A", value: '1'},
|
||||
{id: pb.id, name: "B", value: '2'},
|
||||
{id: pc.id, name: "C", value: '3'}]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -455,8 +456,8 @@ module Spree
|
||||
oc1 = create(:simple_order_cycle, :distributors => [d1], :variants => [p1.master])
|
||||
oc2 = create(:simple_order_cycle, :distributors => [d2], :variants => [p2.master])
|
||||
|
||||
p1.should be_in_distributor d1
|
||||
p1.should_not be_in_distributor d2
|
||||
expect(p1).to be_in_distributor d1
|
||||
expect(p1).not_to be_in_distributor d2
|
||||
end
|
||||
|
||||
it "queries its membership of a particular order cycle" do
|
||||
@@ -467,8 +468,8 @@ module Spree
|
||||
oc1 = create(:simple_order_cycle, :distributors => [d1], :variants => [p1.master])
|
||||
oc2 = create(:simple_order_cycle, :distributors => [d2], :variants => [p2.master])
|
||||
|
||||
p1.should be_in_order_cycle oc1
|
||||
p1.should_not be_in_order_cycle oc2
|
||||
expect(p1).to be_in_order_cycle oc1
|
||||
expect(p1).not_to be_in_order_cycle oc2
|
||||
end
|
||||
end
|
||||
|
||||
@@ -484,11 +485,11 @@ module Spree
|
||||
|
||||
it "removes the old option type and assigns the new one" do
|
||||
p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001)
|
||||
p.option_types.should == [ot_volume]
|
||||
expect(p.option_types).to eq([ot_volume])
|
||||
end
|
||||
|
||||
it "does not remove and re-add the option type if it is not changed" do
|
||||
p.option_types.should_receive(:delete).never
|
||||
expect(p.option_types).to receive(:delete).never
|
||||
p.update_attributes!(name: 'foo')
|
||||
end
|
||||
|
||||
@@ -497,14 +498,14 @@ module Spree
|
||||
v = create(:variant, unit_value: 1, product: p)
|
||||
p.reload
|
||||
|
||||
v.option_values.map(&:name).include?("1L").should == false
|
||||
v.option_values.map(&:name).include?("1g").should == true
|
||||
expect(v.option_values.map(&:name).include?("1L")).to eq(false)
|
||||
expect(v.option_values.map(&:name).include?("1g")).to eq(true)
|
||||
expect {
|
||||
p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001)
|
||||
}.to change(p.master.option_values(true), :count).by(0)
|
||||
v.reload
|
||||
v.option_values.map(&:name).include?("1L").should == true
|
||||
v.option_values.map(&:name).include?("1g").should == false
|
||||
expect(v.option_values.map(&:name).include?("1L")).to eq(true)
|
||||
expect(v.option_values.map(&:name).include?("1g")).to eq(false)
|
||||
end
|
||||
|
||||
it "removes the related option values from its master variant and replaces them" do
|
||||
@@ -512,14 +513,14 @@ module Spree
|
||||
p.master.update_attributes!(unit_value: 1)
|
||||
p.reload
|
||||
|
||||
p.master.option_values.map(&:name).include?("1L").should == false
|
||||
p.master.option_values.map(&:name).include?("1g").should == true
|
||||
expect(p.master.option_values.map(&:name).include?("1L")).to eq(false)
|
||||
expect(p.master.option_values.map(&:name).include?("1g")).to eq(true)
|
||||
expect {
|
||||
p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001)
|
||||
}.to change(p.master.option_values(true), :count).by(0)
|
||||
p.reload
|
||||
p.master.option_values.map(&:name).include?("1L").should == true
|
||||
p.master.option_values.map(&:name).include?("1g").should == false
|
||||
expect(p.master.option_values.map(&:name).include?("1L")).to eq(true)
|
||||
expect(p.master.option_values.map(&:name).include?("1g")).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -529,7 +530,7 @@ module Spree
|
||||
ot3 = create(:option_type, name: 'unit_items', presentation: 'Items')
|
||||
ot4 = create(:option_type, name: 'foo_unit_bar', presentation: 'Foo')
|
||||
|
||||
Spree::Product.all_variant_unit_option_types.should match_array [ot1, ot2, ot3]
|
||||
expect(Spree::Product.all_variant_unit_option_types).to match_array [ot1, ot2, ot3]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -553,11 +554,11 @@ module Spree
|
||||
p.option_type_ids = p.option_type_ids.reject { |id| id == ot.id }
|
||||
|
||||
# Then the associated option values should have been removed from the variants
|
||||
v1.option_values(true).should_not include ov1
|
||||
v2.option_values(true).should_not include ov2
|
||||
expect(v1.option_values(true)).not_to include ov1
|
||||
expect(v2.option_values(true)).not_to include ov2
|
||||
|
||||
# And the option values themselves should still exist
|
||||
Spree::OptionValue.where(id: [ov1.id, ov2.id]).count.should == 2
|
||||
expect(Spree::OptionValue.where(id: [ov1.id, ov2.id]).count).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -566,7 +567,7 @@ module Spree
|
||||
it "considers products that are on_demand as being in stock" do
|
||||
product = create(:simple_product, on_demand: true)
|
||||
product.master.update_attribute(:on_hand, 0)
|
||||
product.has_stock?.should == true
|
||||
expect(product.has_stock?).to eq(true)
|
||||
end
|
||||
|
||||
describe "finding products in stock for a particular distribution" do
|
||||
@@ -577,7 +578,7 @@ module Spree
|
||||
oc = create(:simple_order_cycle, distributors: [d])
|
||||
oc.exchanges.outgoing.first.variants << p.variants.first
|
||||
|
||||
p.should have_stock_for_distribution(oc, d)
|
||||
expect(p).to have_stock_for_distribution(oc, d)
|
||||
end
|
||||
|
||||
it "returns products with in-stock variants" do
|
||||
@@ -588,7 +589,7 @@ module Spree
|
||||
oc = create(:simple_order_cycle, distributors: [d])
|
||||
oc.exchanges.outgoing.first.variants << v
|
||||
|
||||
p.should have_stock_for_distribution(oc, d)
|
||||
expect(p).to have_stock_for_distribution(oc, d)
|
||||
end
|
||||
|
||||
it "returns products with on-demand variants" do
|
||||
@@ -599,7 +600,7 @@ module Spree
|
||||
oc = create(:simple_order_cycle, distributors: [d])
|
||||
oc.exchanges.outgoing.first.variants << v
|
||||
|
||||
p.should have_stock_for_distribution(oc, d)
|
||||
expect(p).to have_stock_for_distribution(oc, d)
|
||||
end
|
||||
|
||||
it "does not return products that have stock not in the distribution" do
|
||||
@@ -608,7 +609,7 @@ module Spree
|
||||
d = create(:distributor_enterprise)
|
||||
oc = create(:simple_order_cycle, distributors: [d])
|
||||
|
||||
p.should_not have_stock_for_distribution(oc, d)
|
||||
expect(p).not_to have_stock_for_distribution(oc, d)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -619,7 +620,7 @@ module Spree
|
||||
let(:product) { create(:simple_product) }
|
||||
|
||||
it "returns the first taxon as the primary taxon" do
|
||||
product.taxons.should == [product.primary_taxon]
|
||||
expect(product.taxons).to eq([product.primary_taxon])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -633,13 +634,13 @@ module Spree
|
||||
it "removes the master variant from all order cycles" do
|
||||
e.variants << p.master
|
||||
p.destroy
|
||||
e.variants(true).should be_empty
|
||||
expect(e.variants(true)).to be_empty
|
||||
end
|
||||
|
||||
it "removes all other variants from order cycles" do
|
||||
e.variants << v
|
||||
p.destroy
|
||||
e.variants(true).should be_empty
|
||||
expect(e.variants(true)).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
module Spree
|
||||
describe ShippingMethod do
|
||||
it "is valid when built from factory" do
|
||||
create(:shipping_method).should be_valid
|
||||
expect(create(:shipping_method)).to be_valid
|
||||
end
|
||||
|
||||
it "can have distributors" do
|
||||
@@ -15,7 +15,7 @@ module Spree
|
||||
sm.distributors << d1
|
||||
sm.distributors << d2
|
||||
|
||||
sm.reload.distributors.should match_array [d1, d2]
|
||||
expect(sm.reload.distributors).to match_array [d1, d2]
|
||||
end
|
||||
|
||||
describe "scope" do
|
||||
@@ -42,7 +42,7 @@ module Spree
|
||||
sm1 = create(:shipping_method, distributors: [d1])
|
||||
sm2 = create(:shipping_method, distributors: [d2])
|
||||
|
||||
ShippingMethod.for_distributor(d1).should == [sm1]
|
||||
expect(ShippingMethod.for_distributor(d1)).to eq([sm1])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,7 +51,7 @@ module Spree
|
||||
sm2 = create(:shipping_method, name: 'AA')
|
||||
sm3 = create(:shipping_method, name: 'BB')
|
||||
|
||||
ShippingMethod.by_name.should == [sm2, sm3, sm1]
|
||||
expect(ShippingMethod.by_name).to eq([sm2, sm3, sm1])
|
||||
end
|
||||
|
||||
describe "finding services offered by all distributors" do
|
||||
@@ -65,19 +65,19 @@ module Spree
|
||||
let!(:d3_delivery) { create(:shipping_method, require_ship_address: true, distributors: [d3]) }
|
||||
|
||||
it "reports when the services are available" do
|
||||
ShippingMethod.services[d1.id].should == {pickup: true, delivery: true}
|
||||
expect(ShippingMethod.services[d1.id]).to eq({pickup: true, delivery: true})
|
||||
end
|
||||
|
||||
it "reports when only pickup is available" do
|
||||
ShippingMethod.services[d2.id].should == {pickup: true, delivery: false}
|
||||
expect(ShippingMethod.services[d2.id]).to eq({pickup: true, delivery: false})
|
||||
end
|
||||
|
||||
it "reports when only delivery is available" do
|
||||
ShippingMethod.services[d3.id].should == {pickup: false, delivery: true}
|
||||
expect(ShippingMethod.services[d3.id]).to eq({pickup: false, delivery: true})
|
||||
end
|
||||
|
||||
it "returns no entry when no service is available" do
|
||||
ShippingMethod.services[d4.id].should be_nil
|
||||
expect(ShippingMethod.services[d4.id]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ module Spree
|
||||
let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) }
|
||||
|
||||
it "selects all tax rates" do
|
||||
TaxRate.match(order).should == [tax_rate]
|
||||
expect(TaxRate.match(order)).to eq([tax_rate])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ module Spree
|
||||
let(:hub) { create(:distributor_enterprise, charges_sales_tax: false) }
|
||||
|
||||
it "selects no tax rates" do
|
||||
TaxRate.match(order).should be_empty
|
||||
expect(TaxRate.match(order)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ module Spree
|
||||
let!(:order) { create(:order, distributor: nil, bill_address: create(:address)) }
|
||||
|
||||
it "selects all tax rates" do
|
||||
TaxRate.match(order).should == [tax_rate]
|
||||
expect(TaxRate.match(order)).to eq([tax_rate])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -35,26 +35,26 @@ module Spree
|
||||
|
||||
it "sets included_in_price to true" do
|
||||
tax_rate.send(:with_tax_included_in_price) do
|
||||
tax_rate.included_in_price.should be true
|
||||
expect(tax_rate.included_in_price).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it "sets the included_in_price value accessible to the calculator to true" do
|
||||
tax_rate.send(:with_tax_included_in_price) do
|
||||
tax_rate.calculator.calculable.included_in_price.should be true
|
||||
expect(tax_rate.calculator.calculable.included_in_price).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it "passes through the return value of the block" do
|
||||
tax_rate.send(:with_tax_included_in_price) do
|
||||
expect(tax_rate.send(:with_tax_included_in_price) do
|
||||
'asdf'
|
||||
end.should == 'asdf'
|
||||
end).to eq('asdf')
|
||||
end
|
||||
|
||||
it "restores both values to their original afterwards" do
|
||||
tax_rate.send(:with_tax_included_in_price) {}
|
||||
tax_rate.included_in_price.should be false
|
||||
tax_rate.calculator.calculable.included_in_price.should be false
|
||||
expect(tax_rate.included_in_price).to be false
|
||||
expect(tax_rate.calculator.calculable.included_in_price).to be false
|
||||
end
|
||||
|
||||
it "restores both values when an exception is raised" do
|
||||
@@ -62,8 +62,8 @@ module Spree
|
||||
tax_rate.send(:with_tax_included_in_price) { raise Exception.new 'oops' }
|
||||
end.to raise_error 'oops'
|
||||
|
||||
tax_rate.included_in_price.should be false
|
||||
tax_rate.calculator.calculable.included_in_price.should be false
|
||||
expect(tax_rate.included_in_price).to be false
|
||||
expect(tax_rate.calculator.calculable.included_in_price).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ module Spree
|
||||
let!(:p1) { create(:simple_product, supplier: e, taxons: [t1, t2]) }
|
||||
|
||||
it "finds taxons" do
|
||||
Taxon.supplied_taxons.should == {e.id => Set.new(p1.taxons.map(&:id))}
|
||||
expect(Taxon.supplied_taxons).to eq({e.id => Set.new(p1.taxons.map(&:id))})
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ describe Spree.user_class do
|
||||
include OpenFoodNetwork::EmailHelper
|
||||
|
||||
describe "associations" do
|
||||
it { should have_many(:owned_enterprises) }
|
||||
it { is_expected.to have_many(:owned_enterprises) }
|
||||
|
||||
describe "addresses" do
|
||||
let(:user) { create(:user, bill_address: create(:address)) }
|
||||
@@ -68,7 +68,7 @@ describe Spree.user_class do
|
||||
e = create(:enterprise)
|
||||
c = create(:customer, user: u, enterprise: e)
|
||||
|
||||
u.customer_of(e).should == c
|
||||
expect(u.customer_of(e)).to eq(c)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ module Spree
|
||||
let!(:oc2) { create(:simple_order_cycle, distributors: [d2], variants: [p2.master]) }
|
||||
|
||||
it "shows variants in an order cycle distribution" do
|
||||
Variant.in_distributor(d1).should == [p1.master]
|
||||
expect(Variant.in_distributor(d1)).to eq([p1.master])
|
||||
end
|
||||
|
||||
it "doesn't show duplicates" do
|
||||
oc_dup = create(:simple_order_cycle, distributors: [d1], variants: [p1.master])
|
||||
Variant.in_distributor(d1).should == [p1.master]
|
||||
expect(Variant.in_distributor(d1)).to eq([p1.master])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,14 +40,14 @@ module Spree
|
||||
let!(:oc2) { create(:simple_order_cycle, distributors: [d2], variants: [p2.master]) }
|
||||
|
||||
it "shows variants in an order cycle" do
|
||||
Variant.in_order_cycle(oc1).should == [p1.master]
|
||||
expect(Variant.in_order_cycle(oc1)).to eq([p1.master])
|
||||
end
|
||||
|
||||
it "doesn't show duplicates" do
|
||||
ex = create(:exchange, order_cycle: oc1, sender: oc1.coordinator, receiver: d2)
|
||||
ex.variants << p1.master
|
||||
|
||||
Variant.in_order_cycle(oc1).should == [p1.master]
|
||||
expect(Variant.in_order_cycle(oc1)).to eq([p1.master])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -76,17 +76,17 @@ module Spree
|
||||
}
|
||||
|
||||
it "returns variants in the order cycle and distributor" do
|
||||
p1.variants.for_distribution(oc, d1).should == [v1]
|
||||
p2.variants.for_distribution(oc, d2).should == [v2]
|
||||
expect(p1.variants.for_distribution(oc, d1)).to eq([v1])
|
||||
expect(p2.variants.for_distribution(oc, d2)).to eq([v2])
|
||||
end
|
||||
|
||||
it "does not return variants in the order cycle but not the distributor" do
|
||||
p1.variants.for_distribution(oc, d2).should be_empty
|
||||
p2.variants.for_distribution(oc, d1).should be_empty
|
||||
expect(p1.variants.for_distribution(oc, d2)).to be_empty
|
||||
expect(p2.variants.for_distribution(oc, d1)).to be_empty
|
||||
end
|
||||
|
||||
it "does not return variants not in the order cycle" do
|
||||
p_external.variants.for_distribution(oc, d1).should be_empty
|
||||
expect(p_external.variants.for_distribution(oc, d1)).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -201,8 +201,9 @@ module Spree
|
||||
let!(:v3) { create(:variant) }
|
||||
|
||||
it "indexes variants by id" do
|
||||
Variant.where(id: [v1, v2, v3]).indexed.should ==
|
||||
expect(Variant.where(id: [v1, v2, v3]).indexed).to eq(
|
||||
{v1.id => v1, v2.id => v2, v3.id => v3}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -215,7 +216,7 @@ module Spree
|
||||
before { allow(v).to receive(:full_name) { p.name + " - something" } }
|
||||
|
||||
it "does not show the product name twice" do
|
||||
v.product_and_full_name.should == 'product - something'
|
||||
expect(v.product_and_full_name).to eq('product - something')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -223,7 +224,7 @@ module Spree
|
||||
before { allow(v).to receive(:full_name) { "display_name (unit)" } }
|
||||
|
||||
it "prepends the product name to the full name" do
|
||||
v.product_and_full_name.should == 'product - display_name (unit)'
|
||||
expect(v.product_and_full_name).to eq('product - display_name (unit)')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -234,8 +235,8 @@ module Spree
|
||||
order_cycle = double(:order_cycle)
|
||||
|
||||
variant = Variant.new price: 100
|
||||
variant.should_receive(:fees_for).with(distributor, order_cycle) { 23 }
|
||||
variant.price_with_fees(distributor, order_cycle).should == 123
|
||||
expect(variant).to receive(:fees_for).with(distributor, order_cycle) { 23 }
|
||||
expect(variant.price_with_fees(distributor, order_cycle)).to eq(123)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -246,9 +247,9 @@ module Spree
|
||||
order_cycle = double(:order_cycle)
|
||||
variant = Variant.new
|
||||
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.should_receive(:fees_for).with(variant) { 23 }
|
||||
expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_for).with(variant) { 23 }
|
||||
|
||||
variant.fees_for(distributor, order_cycle).should == 23
|
||||
expect(variant.fees_for(distributor, order_cycle)).to eq(23)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -260,9 +261,9 @@ module Spree
|
||||
variant = Variant.new
|
||||
fees = double(:fees)
|
||||
|
||||
OpenFoodNetwork::EnterpriseFeeCalculator.any_instance.should_receive(:fees_by_type_for).with(variant) { fees }
|
||||
expect_any_instance_of(OpenFoodNetwork::EnterpriseFeeCalculator).to receive(:fees_by_type_for).with(variant) { fees }
|
||||
|
||||
variant.fees_by_type_for(distributor, order_cycle).should == fees
|
||||
expect(variant.fees_by_type_for(distributor, order_cycle)).to eq(fees)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -281,16 +282,16 @@ module Spree
|
||||
it "is valid when unit value is set and unit description is not" do
|
||||
variant.unit_value = 1
|
||||
variant.unit_description = nil
|
||||
variant.should be_valid
|
||||
expect(variant).to be_valid
|
||||
end
|
||||
|
||||
it "is invalid when unit value is not set" do
|
||||
variant.unit_value = nil
|
||||
variant.should_not be_valid
|
||||
expect(variant).not_to be_valid
|
||||
end
|
||||
|
||||
it "has a valid master variant" do
|
||||
product.master.should be_valid
|
||||
expect(product.master).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -304,23 +305,23 @@ module Spree
|
||||
it "is valid with only unit value set" do
|
||||
variant.unit_value = 1
|
||||
variant.unit_description = nil
|
||||
variant.should be_valid
|
||||
expect(variant).to be_valid
|
||||
end
|
||||
|
||||
it "is valid with only unit description set" do
|
||||
variant.unit_value = nil
|
||||
variant.unit_description = 'Medium'
|
||||
variant.should be_valid
|
||||
expect(variant).to be_valid
|
||||
end
|
||||
|
||||
it "is invalid when neither unit value nor unit description are set" do
|
||||
variant.unit_value = nil
|
||||
variant.unit_description = nil
|
||||
variant.should_not be_valid
|
||||
expect(variant).not_to be_valid
|
||||
end
|
||||
|
||||
it "has a valid master variant" do
|
||||
product.master.should be_valid
|
||||
expect(product.master).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -330,67 +331,67 @@ module Spree
|
||||
let(:v) { Variant.new }
|
||||
|
||||
before do
|
||||
v.stub(:display_name) { 'display_name' }
|
||||
v.stub(:unit_to_display) { 'unit_to_display' }
|
||||
allow(v).to receive(:display_name) { 'display_name' }
|
||||
allow(v).to receive(:unit_to_display) { 'unit_to_display' }
|
||||
end
|
||||
|
||||
it "returns unit_to_display when display_name is blank" do
|
||||
v.stub(:display_name) { '' }
|
||||
v.full_name.should == 'unit_to_display'
|
||||
allow(v).to receive(:display_name) { '' }
|
||||
expect(v.full_name).to eq('unit_to_display')
|
||||
end
|
||||
|
||||
it "returns display_name when it contains unit_to_display" do
|
||||
v.stub(:display_name) { 'DiSpLaY_name' }
|
||||
v.stub(:unit_to_display) { 'name' }
|
||||
v.full_name.should == 'DiSpLaY_name'
|
||||
allow(v).to receive(:display_name) { 'DiSpLaY_name' }
|
||||
allow(v).to receive(:unit_to_display) { 'name' }
|
||||
expect(v.full_name).to eq('DiSpLaY_name')
|
||||
end
|
||||
|
||||
it "returns unit_to_display when it contains display_name" do
|
||||
v.stub(:display_name) { '_to_' }
|
||||
v.stub(:unit_to_display) { 'unit_TO_display' }
|
||||
v.full_name.should == 'unit_TO_display'
|
||||
allow(v).to receive(:display_name) { '_to_' }
|
||||
allow(v).to receive(:unit_to_display) { 'unit_TO_display' }
|
||||
expect(v.full_name).to eq('unit_TO_display')
|
||||
end
|
||||
|
||||
it "returns a combination otherwise" do
|
||||
v.stub(:display_name) { 'display_name' }
|
||||
v.stub(:unit_to_display) { 'unit_to_display' }
|
||||
v.full_name.should == 'display_name (unit_to_display)'
|
||||
allow(v).to receive(:display_name) { 'display_name' }
|
||||
allow(v).to receive(:unit_to_display) { 'unit_to_display' }
|
||||
expect(v.full_name).to eq('display_name (unit_to_display)')
|
||||
end
|
||||
|
||||
it "is resilient to regex chars" do
|
||||
v = Variant.new display_name: ")))"
|
||||
v.stub(:unit_to_display) { ")))" }
|
||||
v.full_name.should == ")))"
|
||||
allow(v).to receive(:unit_to_display) { ")))" }
|
||||
expect(v.full_name).to eq(")))")
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting name for display" do
|
||||
it "returns display_name if present" do
|
||||
v = create(:variant, display_name: "foo")
|
||||
v.name_to_display.should == "foo"
|
||||
expect(v.name_to_display).to eq("foo")
|
||||
end
|
||||
|
||||
it "returns product name if display_name is empty" do
|
||||
v = create(:variant, product: create(:product))
|
||||
v.name_to_display.should == v.product.name
|
||||
expect(v.name_to_display).to eq(v.product.name)
|
||||
v1 = create(:variant, display_name: "", product: create(:product))
|
||||
v1.name_to_display.should == v1.product.name
|
||||
expect(v1.name_to_display).to eq(v1.product.name)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting unit for display" do
|
||||
it "returns display_as if present" do
|
||||
v = create(:variant, display_as: "foo")
|
||||
v.unit_to_display.should == "foo"
|
||||
expect(v.unit_to_display).to eq("foo")
|
||||
end
|
||||
|
||||
it "returns options_text if display_as is blank" do
|
||||
v = create(:variant)
|
||||
v1 = create(:variant, display_as: "")
|
||||
v.stub(:options_text).and_return "ponies"
|
||||
v1.stub(:options_text).and_return "ponies"
|
||||
v.unit_to_display.should == "ponies"
|
||||
v1.unit_to_display.should == "ponies"
|
||||
allow(v).to receive(:options_text).and_return "ponies"
|
||||
allow(v1).to receive(:options_text).and_return "ponies"
|
||||
expect(v.unit_to_display).to eq("ponies")
|
||||
expect(v1.unit_to_display).to eq("ponies")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -402,7 +403,7 @@ module Spree
|
||||
p.update_attributes! variant_unit: 'weight', variant_unit_scale: 1
|
||||
v.update_attributes! unit_value: 10, unit_description: 'foo'
|
||||
|
||||
v.reload.weight.should == 0.01
|
||||
expect(v.reload.weight).to eq(0.01)
|
||||
end
|
||||
|
||||
it "does nothing when unit is not weight" do
|
||||
@@ -412,7 +413,7 @@ module Spree
|
||||
p.update_attributes! variant_unit: 'volume', variant_unit_scale: 1
|
||||
v.update_attributes! unit_value: 10, unit_description: 'foo'
|
||||
|
||||
v.reload.weight.should == 123
|
||||
expect(v.reload.weight).to eq(123)
|
||||
end
|
||||
|
||||
it "does nothing when unit_value is not set" do
|
||||
@@ -423,9 +424,9 @@ module Spree
|
||||
|
||||
# Although invalid, this calls the before_validation callback, which would
|
||||
# error if not handling unit_value == nil case
|
||||
v.update_attributes(unit_value: nil, unit_description: 'foo').should be false
|
||||
expect(v.update_attributes(unit_value: nil, unit_description: 'foo')).to be false
|
||||
|
||||
v.reload.weight.should == 123
|
||||
expect(v.reload.weight).to eq(123)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -440,7 +441,7 @@ module Spree
|
||||
v.update_attributes!(unit_value: 10, unit_description: 'foo')
|
||||
}.to change(Spree::OptionValue, :count).by(1)
|
||||
|
||||
v.option_values.should_not include ov_orig
|
||||
expect(v.option_values).not_to include ov_orig
|
||||
end
|
||||
end
|
||||
|
||||
@@ -459,8 +460,8 @@ module Spree
|
||||
v.update_attributes!(unit_value: 10, unit_description: 'foo')
|
||||
}.to change(Spree::OptionValue, :count).by(0)
|
||||
|
||||
v.option_values.should_not include ov_orig
|
||||
v.option_values.should include ov_new
|
||||
expect(v.option_values).not_to include ov_orig
|
||||
expect(v.option_values).to include ov_new
|
||||
end
|
||||
end
|
||||
|
||||
@@ -469,10 +470,10 @@ module Spree
|
||||
let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: '') }
|
||||
|
||||
it "requests the name of the new option_value from OptionValueName" do
|
||||
OpenFoodNetwork::OptionValueNamer.any_instance.should_receive(:name).exactly(1).times.and_call_original
|
||||
expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original
|
||||
v.update_attributes(unit_value: 10, unit_description: 'foo')
|
||||
ov = v.option_values.last
|
||||
ov.name.should == "10g foo"
|
||||
expect(ov.name).to eq("10g foo")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -481,10 +482,10 @@ module Spree
|
||||
let!(:v) { create(:variant, product: p, unit_value: 5, unit_description: 'bar', display_as: 'FOOS!') }
|
||||
|
||||
it "does not request the name of the new option_value from OptionValueName" do
|
||||
OpenFoodNetwork::OptionValueNamer.any_instance.should_not_receive(:name)
|
||||
expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).not_to receive(:name)
|
||||
v.update_attributes!(unit_value: 10, unit_description: 'foo')
|
||||
ov = v.option_values.last
|
||||
ov.name.should == "FOOS!"
|
||||
expect(ov.name).to eq("FOOS!")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -522,7 +523,7 @@ module Spree
|
||||
e = create(:exchange, variants: [v])
|
||||
|
||||
v.destroy
|
||||
e.reload.variant_ids.should be_empty
|
||||
expect(e.reload.variant_ids).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user