Merge branch 'master' into 2-0-stable-jan-8th

This commit is contained in:
luisramos0
2019-01-08 14:29:50 +00:00
42 changed files with 977 additions and 144 deletions

View File

@@ -48,6 +48,16 @@ describe UserRegistrationsController, type: :controller do
expect(json).to eq({"email" => "test@test.com"})
expect(controller.spree_current_user).to be_nil
end
it "sets user.locale from cookie on create" do
original_locale_cookie = cookies[:locale]
cookies[:locale] = "pt"
xhr :post, :create, spree_user: user_params, use_route: :spree
expect(assigns[:user].locale).to eq("pt")
cookies[:locale] = original_locale_cookie
end
end
context "when registration fails" do

View File

@@ -189,9 +189,20 @@ FactoryBot.define do
factory :variant_override, :class => VariantOverride do
price 77.77
on_demand false
count_on_hand 11111
default_stock 2000
resettable false
trait :on_demand do
on_demand true
count_on_hand nil
end
trait :use_producer_stock_settings do
on_demand nil
count_on_hand nil
end
end
factory :inventory_item, :class => InventoryItem do

View File

@@ -140,8 +140,8 @@ feature %q{
fill_in "variant-overrides-#{variant.id}-sku", with: 'NEWSKU'
fill_in "variant-overrides-#{variant.id}-price", with: '777.77'
select_on_demand variant, :no
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123'
check "variant-overrides-#{variant.id}-on_demand"
page.should have_content "Changes to one override remain unsaved."
expect do
@@ -154,14 +154,15 @@ feature %q{
vo.hub_id.should == hub.id
vo.sku.should == "NEWSKU"
vo.price.should == 777.77
expect(vo.on_demand).to eq(false)
vo.count_on_hand.should == 123
vo.on_demand.should == true
end
describe "creating and then updating the new override" do
it "updates the same override instead of creating a duplicate" do
# When I create a new override
fill_in "variant-overrides-#{variant.id}-price", with: '777.77'
select_on_demand variant, :no
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '123'
page.should have_content "Changes to one override remain unsaved."
@@ -186,6 +187,7 @@ feature %q{
vo.variant_id.should == variant.id
vo.hub_id.should == hub.id
vo.price.should == 111.11
expect(vo.on_demand).to eq(false)
vo.count_on_hand.should == 111
end
end
@@ -218,7 +220,7 @@ feature %q{
end
context "with overrides" do
let!(:vo) { create(:variant_override, variant: variant, hub: hub, price: 77.77, count_on_hand: 11111, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) }
let!(:vo) { create(:variant_override, :on_demand, variant: variant, hub: hub, price: 77.77, default_stock: 1000, resettable: true, tag_list: ["tag1","tag2","tag3"]) }
let!(:vo_no_auth) { create(:variant_override, variant: variant, hub: hub2, price: 1, count_on_hand: 2) }
let!(:product2) { create(:simple_product, supplier: producer, variant_unit: 'weight', variant_unit_scale: 1) }
let!(:variant2) { create(:variant, product: product2, unit_value: 8, price: 1.00, on_hand: 12) }
@@ -235,11 +237,15 @@ feature %q{
it "product values are affected by overrides" do
page.should have_input "variant-overrides-#{variant.id}-price", with: '77.77', placeholder: '1.23'
page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '11111', placeholder: '12'
expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "", placeholder: I18n.t("js.variants.on_demand.yes")
expect(page).to have_select "variant-overrides-#{variant.id}-on_demand", selected: I18n.t("js.variant_overrides.on_demand.yes")
expect(page).to have_input "variant-overrides-#{variant2.id}-count_on_hand", with: "40", placeholder: ""
end
it "updates existing overrides" do
fill_in "variant-overrides-#{variant.id}-price", with: '22.22'
select_on_demand variant, :no
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '8888'
page.should have_content "Changes to one override remain unsaved."
@@ -252,13 +258,36 @@ feature %q{
vo.variant_id.should == variant.id
vo.hub_id.should == hub.id
vo.price.should == 22.22
expect(vo.on_demand).to eq(false)
vo.count_on_hand.should == 8888
end
it "updates on_demand settings" do
select_on_demand variant, :no
click_button I18n.t("save_changes")
expect(page).to have_content I18n.t("js.changes_saved")
vo.reload
expect(vo.on_demand).to eq(false)
select_on_demand variant, :yes
click_button I18n.t("save_changes")
expect(page).to have_content I18n.t("js.changes_saved")
vo.reload
expect(vo.on_demand).to eq(true)
select_on_demand variant, :use_producer_settings
click_button I18n.t("save_changes")
expect(page).to have_content I18n.t("js.changes_saved")
vo.reload
expect(vo.on_demand).to be_nil
end
# Any new fields added to the VO model need to be added to this test
it "deletes overrides when values are cleared" do
first("div#columns-dropdown", :text => "COLUMNS").click
first("div#columns-dropdown div.menu div.menu_item", text: "On Demand").click
first("div#columns-dropdown div.menu div.menu_item", text: "Enable Stock Reset?").click
first("div#columns-dropdown div.menu div.menu_item", text: "Tags").click
first("div#columns-dropdown", :text => "COLUMNS").click
@@ -272,6 +301,7 @@ feature %q{
# Clearing values manually
fill_in "variant-overrides-#{variant.id}-price", with: ''
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: ''
select_on_demand variant, :use_producer_settings
fill_in "variant-overrides-#{variant.id}-default_stock", with: ''
within "tr#v_#{variant.id}" do
vo.tag_list.each do |tag|
@@ -297,7 +327,7 @@ feature %q{
first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click
page.should have_content 'Stocks reset to defaults.'
vo.reload
page.should have_input "variant-overrides-#{variant.id}-count_on_hand", with: '1000', placeholder: '12'
expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: "1000", placeholder: ""
vo.count_on_hand.should == 1000
end
@@ -305,7 +335,7 @@ feature %q{
first("div#bulk-actions-dropdown").click
first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click
vo_no_reset.reload
page.should have_input "variant-overrides-#{variant2.id}-count_on_hand", with: '40', placeholder: '12'
expect(page).to have_input "variant-overrides-#{variant2.id}-count_on_hand", with: "40", placeholder: ""
vo_no_reset.count_on_hand.should == 40
end
@@ -315,9 +345,52 @@ feature %q{
first("div#bulk-actions-dropdown div.menu div.menu_item", text: "Reset Stock Levels To Defaults").click
page.should have_content "Save changes first"
end
describe "ensuring that on demand and count on hand settings are compatible" do
it "clears count on hand when not limited stock" do
# It clears count_on_hand when selecting true on_demand.
select_on_demand variant, :no
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200"
select_on_demand variant, :yes
expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: ""
# It clears count_on_hand when selecting nil on_demand.
select_on_demand variant, :no
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "200"
select_on_demand variant, :use_producer_settings
expect(page).to have_input "variant-overrides-#{variant.id}-count_on_hand", with: ""
# It saves the changes.
click_button I18n.t("save_changes")
expect(page).to have_content I18n.t("js.changes_saved")
vo.reload
expect(vo.count_on_hand).to be_nil
expect(vo.on_demand).to be_nil
end
it "provides explanation when attempting to save variant override with incompatible stock settings" do
# Successfully change stock settings.
select_on_demand variant, :no
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: "1111"
click_button I18n.t("save_changes")
expect(page).to have_content I18n.t("js.changes_saved")
# Make stock settings incompatible.
select_on_demand variant, :no
fill_in "variant-overrides-#{variant.id}-count_on_hand", with: ""
# It does not save the changes.
click_button I18n.t("save_changes")
expect(page).to have_content I18n.t("activerecord.errors.models.variant_override.count_on_hand.limited_stock_but_no_count_on_hand")
expect(page).to have_no_content I18n.t("js.changes_saved")
vo.reload
expect(vo.count_on_hand).to eq(1111)
expect(vo.on_demand).to eq(false)
end
end
end
end
end
describe "when manually placing an order" do
@@ -382,4 +455,9 @@ feature %q{
end
end
end
def select_on_demand(variant, value_sym)
option_label = I18n.t(value_sym, scope: "js.variant_overrides.on_demand")
select option_label, from: "variant-overrides-#{variant.id}-on_demand"
end
end

View File

@@ -22,7 +22,7 @@ feature "shopping with variant overrides defined", js: true, retry: 3 do
let(:product1_variant3) { create(:variant, product: product1, price: 44.44, unit_value: 4) }
let(:product3_variant1) { create(:variant, product: product3, price: 55.55, unit_value: 5, on_demand: true) }
let(:product3_variant2) { create(:variant, product: product3, price: 66.66, unit_value: 6, on_demand: true) }
let!(:product1_variant1_override) { create(:variant_override, hub: hub, variant: product1_variant1, price: 55.55, count_on_hand: nil, default_stock: nil, resettable: false) }
let!(:product1_variant1_override) { create(:variant_override, :use_producer_stock_settings, hub: hub, variant: product1_variant1, price: 55.55, count_on_hand: nil, default_stock: nil, resettable: false) }
let!(:product1_variant2_override) { create(:variant_override, hub: hub, variant: product1_variant2, count_on_hand: 0, default_stock: nil, resettable: false) }
let!(:product2_variant1_override) { create(:variant_override, hub: hub, variant: product2_variant1, count_on_hand: 0, default_stock: nil, resettable: false) }
let!(:product1_variant3_override) { create(:variant_override, hub: hub, variant: product1_variant3, count_on_hand: 3, default_stock: nil, resettable: false) }

View File

@@ -24,13 +24,13 @@ describe I18nHelper, type: :helper do
end
it "sets the chosen locale" do
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
expect(I18n.locale).to eq :es
end
it "remembers the chosen locale" do
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
allow(helper).to receive(:params) { {} }
@@ -39,16 +39,16 @@ describe I18nHelper, type: :helper do
end
it "ignores unavailable locales" do
allow(helper).to receive(:params) { {locale: "xx"} }
allow(helper).to receive(:params) { { locale: "xx" } }
helper.set_locale
expect(I18n.locale).to eq :en
end
it "remembers the last chosen locale" do
allow(helper).to receive(:params) { {locale: "en"} }
allow(helper).to receive(:params) { { locale: "en" } }
helper.set_locale
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
allow(helper).to receive(:params) { {} }
@@ -57,7 +57,7 @@ describe I18nHelper, type: :helper do
end
it "remembers the chosen locale after logging in" do
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
# log in
@@ -68,7 +68,7 @@ describe I18nHelper, type: :helper do
end
it "forgets the chosen locale without cookies" do
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
# clean up cookies
@@ -91,14 +91,14 @@ describe I18nHelper, type: :helper do
end
it "sets the chosen locale" do
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
expect(I18n.locale).to eq :es
expect(user.locale).to eq "es"
end
it "remembers the chosen locale" do
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
allow(helper).to receive(:params) { {} }
@@ -107,10 +107,10 @@ describe I18nHelper, type: :helper do
end
it "remembers the last chosen locale" do
allow(helper).to receive(:params) { {locale: "en"} }
allow(helper).to receive(:params) { { locale: "en" } }
helper.set_locale
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
allow(helper).to receive(:params) { {} }
@@ -119,7 +119,7 @@ describe I18nHelper, type: :helper do
end
it "remembers the chosen locale after logging out" do
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
# log out
@@ -130,7 +130,7 @@ describe I18nHelper, type: :helper do
end
it "remembers the chosen locale on another computer" do
allow(helper).to receive(:params) { {locale: "es"} }
allow(helper).to receive(:params) { { locale: "es" } }
helper.set_locale
expect(cookies[:locale]).to eq "es"
@@ -142,4 +142,36 @@ describe I18nHelper, type: :helper do
expect(I18n.locale).to eq :es
end
end
context "#valid_locale" do
around do |example|
original_default_locale = I18n.default_locale
original_available_locales = Rails.application.config.i18n.available_locales
I18n.default_locale = "es"
Rails.application.config.i18n.available_locales = ["es", "pt"]
example.run
I18n.default_locale = original_default_locale
Rails.application.config.i18n.available_locales = original_available_locales
end
let(:user) { build(:user) }
it "returns default locale if given user is nil" do
expect(helper.valid_locale(nil)).to eq I18n.default_locale
end
it "returns default locale if locale of given user is nil" do
expect(helper.valid_locale(user)).to eq I18n.default_locale
end
it "returns default locale if locale of given user is not available" do
user.locale = "cn"
expect(helper.valid_locale(user)).to eq I18n.default_locale
end
it "returns the locale of the given user if available" do
user.locale = "pt"
expect(helper.valid_locale(user)).to eq "pt"
end
end
end

View File

@@ -87,3 +87,115 @@ describe "VariantOverridesCtrl", ->
$httpBackend.flush()
expect(VariantOverrides.updateData).toHaveBeenCalledWith variant_overrides_mock
expect(StatusMessage.display).toHaveBeenCalledWith 'success', 'Stocks reset to defaults.'
describe "suggesting count_on_hand when on_demand is changed", ->
variant = null
beforeEach ->
scope.variantOverrides = {123: {}}
describe "when variant is on demand", ->
beforeEach ->
# Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not
# enforced.
variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: "On demand"}
it "clears count_on_hand when variant override uses producer stock settings", ->
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
scope.updateCountOnHand(variant, 123)
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()
it "clears count_on_hand when variant override forces on demand", ->
scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1}
scope.updateCountOnHand(variant, 123)
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()
it "clears count_on_hand when variant override forces limited stock", ->
scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1}
scope.updateCountOnHand(variant, 123)
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()
describe "when variant has limited stock", ->
beforeEach ->
variant = {id: 2, on_demand: false, count_on_hand: 20, on_hand: 20}
it "clears count_on_hand when variant override uses producer stock settings", ->
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
scope.updateCountOnHand(variant, 123)
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()
it "clears count_on_hand when variant override forces on demand", ->
scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1}
scope.updateCountOnHand(variant, 123)
expect(scope.variantOverrides[123][2].count_on_hand).toBeNull()
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBeNull()
it "sets to producer count_on_hand when variant override forces limited stock", ->
scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1}
scope.updateCountOnHand(variant, 123)
expect(scope.variantOverrides[123][2].count_on_hand).toBe(20)
dirtyVariantOverride = DirtyVariantOverrides.dirtyVariantOverrides[123][2]
expect(dirtyVariantOverride.count_on_hand).toBe(20)
describe "count on hand placeholder", ->
beforeEach ->
scope.variantOverrides = {123: {}}
describe "when variant is on demand", ->
variant = null
beforeEach ->
# Ideally, count_on_hand is blank when the variant is on demand. However, this rule is not
# enforced.
variant = {id: 2, on_demand: true, count_on_hand: 20, on_hand: t("on_demand")}
it "is 'On demand' when variant override uses producer stock settings", ->
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("on_demand"))
it "is 'On demand' when variant override is on demand", ->
scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("js.variants.on_demand.yes"))
it "is blank when variant override is limited stock", ->
scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe('')
describe "when variant is limited stock", ->
variant = null
beforeEach ->
variant = {id: 2, on_demand: false, count_on_hand: 20, on_hand: 20}
it "is variant count on hand when variant override uses producer stock settings", ->
scope.variantOverrides[123][2] = {on_demand: null, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(20)
it "is 'On demand' when variant override is on demand", ->
scope.variantOverrides[123][2] = {on_demand: true, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe(t("js.variants.on_demand.yes"))
it "is blank when variant override is limited stock", ->
scope.variantOverrides[123][2] = {on_demand: false, count_on_hand: 1}
placeholder = scope.countOnHandPlaceholder(variant, 123)
expect(placeholder).toBe('')

View File

@@ -5,7 +5,7 @@ module OpenFoodNetwork
let(:hub) { create(:distributor_enterprise) }
let(:v) { create(:variant, price: 11.11, on_hand: 1, on_demand: true, sku: "VARIANTSKU") }
let(:vo) { create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: 2, on_demand: false, sku: "VOSKU") }
let(:vo_price_only) { create(:variant_override, hub: hub, variant: v, price: 22.22, count_on_hand: nil) }
let(:vo_price_only) { create(:variant_override, :use_producer_stock_settings, hub: hub, variant: v, price: 22.22) }
let(:scoper) { ScopeVariantToHub.new(hub) }
describe "overriding price" do

View File

@@ -17,9 +17,32 @@ describe Spree::UserMailer do
setup_email
end
it "sends an email when given a user" do
Spree::UserMailer.signup_confirmation(user).deliver
ActionMailer::Base.deliveries.count.should == 1
describe '#signup_confirmation' do
it "sends email when given a user" do
Spree::UserMailer.signup_confirmation(user).deliver
expect(ActionMailer::Base.deliveries.count).to eq(1)
end
describe "user locale" do
around do |example|
original_default_locale = I18n.default_locale
I18n.default_locale = 'pt'
example.run
I18n.default_locale = original_default_locale
end
it "sends email in user locale when user locale is defined" do
user.locale = 'es'
Spree::UserMailer.signup_confirmation(user).deliver
expect(ActionMailer::Base.deliveries.first.body).to include "Gracias por unirte"
end
it "sends email in default locale when user locale is not available" do
user.locale = 'cn'
Spree::UserMailer.signup_confirmation(user).deliver
expect(ActionMailer::Base.deliveries.first.body).to include "Obrigada por juntar-se"
end
end
end
# adapted from https://github.com/spree/spree_auth_devise/blob/70737af/spec/mailers/user_mailer_spec.rb

View File

@@ -35,6 +35,82 @@ describe VariantOverride do
end
end
describe "validation" do
describe "ensuring that on_demand and count_on_hand are compatible" do
let(:variant_override) { build(:variant_override, hub: hub, variant: variant,
on_demand: on_demand, count_on_hand: count_on_hand) }
context "when using producer stock settings" do
let(:on_demand) { nil }
context "when count_on_hand is blank" do
let(:count_on_hand) { nil }
it "is valid" do
expect(variant_override.save).to be_truthy
end
end
context "when count_on_hand is set" do
let(:count_on_hand) { 1 }
it "is invalid" do
expect(variant_override.save).to be_falsey
error_message = I18n.t("using_producer_stock_settings_but_count_on_hand_set",
scope: [i18n_scope_for_error, "count_on_hand"])
expect(variant_override.errors[:count_on_hand]).to eq([error_message])
end
end
end
context "when on demand" do
let(:on_demand) { true }
context "when count_on_hand is blank" do
let(:count_on_hand) { nil }
it "is valid" do
expect(variant_override.save).to be_truthy
end
end
context "when count_on_hand is set" do
let(:count_on_hand) { 1 }
it "is invalid" do
expect(variant_override.save).to be_falsey
error_message = I18n.t("on_demand_but_count_on_hand_set",
scope: [i18n_scope_for_error, "count_on_hand"])
expect(variant_override.errors[:count_on_hand]).to eq([error_message])
end
end
end
context "when limited stock" do
let(:on_demand) { false }
context "when count_on_hand is blank" do
let(:count_on_hand) { nil }
it "is invalid" do
expect(variant_override.save).to be_falsey
error_message = I18n.t("limited_stock_but_no_count_on_hand",
scope: [i18n_scope_for_error, "count_on_hand"])
expect(variant_override.errors[:count_on_hand]).to eq([error_message])
end
end
context "when count_on_hand is set" do
let(:count_on_hand) { 1 }
it "is valid" do
expect(variant_override.save).to be_truthy
end
end
end
end
end
describe "callbacks" do
let!(:vo) { create(:variant_override, hub: hub, variant: variant) }
@@ -119,17 +195,42 @@ describe VariantOverride do
end
describe "resetting stock levels" do
it "resets the on hand level to the value in the default_stock field" do
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20, resettable: true)
vo.reset_stock!
expect(vo.reload.count_on_hand).to eq(20)
describe "forcing the on hand level to the value in the default_stock field" do
it "succeeds for variant override that forces limited stock" do
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 20, resettable: true)
vo.reset_stock!
vo.reload
expect(vo.on_demand).to eq(false)
expect(vo.count_on_hand).to eq(20)
end
it "succeeds for variant override that forces unlimited stock" do
vo = create(:variant_override, :on_demand, variant: variant, hub: hub, default_stock: 20, resettable: true)
vo.reset_stock!
vo.reload
expect(vo.on_demand).to eq(false)
expect(vo.count_on_hand).to eq(20)
end
it "succeeds for variant override that uses producer stock settings" do
vo = create(:variant_override, :use_producer_stock_settings, variant: variant, hub: hub, default_stock: 20, resettable: true)
vo.reset_stock!
vo.reload
expect(vo.on_demand).to eq(false)
expect(vo.count_on_hand).to eq(20)
end
end
it "silently logs an error if the variant override doesn't have a default stock level" do
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: nil, resettable: true)
expect(Bugsnag).to receive(:notify)
vo.reset_stock!
expect(vo.reload.count_on_hand).to eq(12)
end
it "doesn't reset the level if the behaviour is disabled" do
vo = create(:variant_override, variant: variant, hub: hub, count_on_hand: 12, default_stock: 10, resettable: false)
vo.reset_stock!
@@ -140,4 +241,8 @@ describe VariantOverride do
context "extends LocalizedNumber" do
it_behaves_like "a model using the LocalizedNumber module", [:price]
end
def i18n_scope_for_error
"activerecord.errors.models.variant_override"
end
end

View File

@@ -6,9 +6,13 @@ require 'rubygems'
# Require pry when we're not inside Travis-CI
require 'pry' unless ENV['CI']
require 'knapsack'
Knapsack.tracker.config({enable_time_offset_warning: false}) unless ENV['CI']
Knapsack::Adapters::RSpecAdapter.bind
# This spec_helper.rb is being used by the custom engines in engines/. The engines are not set up to
# use Knapsack, and this provides the option to disable it when running the tests in CI services.
unless ENV['DISABLE_KNAPSACK']
require 'knapsack'
Knapsack.tracker.config({enable_time_offset_warning: false}) unless ENV['CI']
Knapsack::Adapters::RSpecAdapter.bind
end
ENV["RAILS_ENV"] ||= 'test'
require_relative "../config/environment"