Skip to content

Commit

Permalink
Update tests to use store credit reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Tapia committed Jan 12, 2019
1 parent 739c2c5 commit ad1ec79
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require 'spec_helper'

shared_examples "update reason loader" do
it "sets the update_reasons variable to a list of categories sorted by category name " do
expect(assigns(:update_reasons)).to eq [update_reason]
it "sets the store_credit_reasons variable to a list of categories sorted by category name " do
expect(assigns(:store_credit_reasons)).to eq [store_credit_reason]
end
end

Expand All @@ -16,11 +16,11 @@

let!(:b_credit_category) { create(:store_credit_category, name: "B category") }
let!(:a_credit_category) { create(:store_credit_category, name: "A category") }
let!(:update_reason) { create(:store_credit_update_reason) }
let!(:store_credit_reason) { create(:store_credit_reason) }

describe "#show" do
let!(:store_credit) { create(:store_credit, user: user, category: a_credit_category) }
let!(:event) { create(:store_credit_auth_event, store_credit: store_credit, created_at: 5.days.ago) }
let!(:event) { create(:store_credit_auth_event, store_credit: store_credit, created_at: 5.days.ago) }

before { get :show, params: { user_id: user.id, id: store_credit.id } }

Expand Down Expand Up @@ -173,12 +173,12 @@
describe "#update_amount" do
let(:original_amount) { 100.0 }
let!(:store_credit) { create(:store_credit, user: user, amount: original_amount) }
let!(:update_reason) { create(:store_credit_update_reason) }
let!(:store_credit_reason) { create(:store_credit_reason) }
let(:parameters) do
{
user_id: user.id,
id: store_credit.id,
update_reason_id: update_reason.id,
store_credit_reason_id: store_credit_reason.id,
store_credit: {
amount: updated_amount
}
Expand Down Expand Up @@ -271,7 +271,7 @@
{
user_id: user.id,
id: store_credit.id,
update_reason_id: update_reason.id
store_credit_reason_id: store_credit_reason.id
}
end

Expand Down
4 changes: 2 additions & 2 deletions backend/spec/features/admin/store_credits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

describe "updating store credit" do
let(:updated_amount) { "99.0" }
let!(:update_reason) { create(:store_credit_update_reason) }
let!(:store_credit_reason) { create(:store_credit_reason) }

before do
visit spree.admin_path
Expand All @@ -74,7 +74,7 @@
click_link "Change amount"
expect(page).to have_content 'Editing store credit amount'
page.fill_in 'store_credit_amount', with: updated_amount
page.select update_reason.name, from: 'update_reason_id'
page.select store_credit_reason.name, from: 'store_credit_reason_id'
click_button "Update"
expect(page.find('#sc-detail-table')).to have_content "$99.00"
expect(store_credit.reload.amount.to_f).to eq updated_amount.to_f
Expand Down
4 changes: 2 additions & 2 deletions backend/spec/helpers/admin/store_credit_events_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@
end

context "originator is not specifically handled" do
let(:originator) { create(:store_credit_update_reason) }
let(:originator) { create(:store_credit) }

it "raises an error" do
expect { subject }.to raise_error(RuntimeError, "Unexpected originator type Spree::StoreCreditUpdateReason")
expect { subject }.to raise_error(RuntimeError, "Unexpected originator type Spree::StoreCredit")
end
end
end
Expand Down
24 changes: 12 additions & 12 deletions core/spec/models/spree/store_credit_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,56 @@
end
end

describe "update reason validation" do
describe "update store credit reason validation" do
subject { event.valid? }

context "adjustment event" do
context "has an update reason" do
context "has a store credit reason" do
let(:event) { build(:store_credit_adjustment_event) }

it "returns true" do
expect(subject).to eq true
end
end

context "doesn't have an update reason" do
let(:event) { build(:store_credit_adjustment_event, update_reason: nil) }
context "doesn't have a store credit reason" do
let(:event) { build(:store_credit_adjustment_event, store_credit_reason: nil) }

it "returns false" do
expect(subject).to eq false
end

it "adds an error message indicating the update reason is missing" do
it "adds an error message indicating the store credit reason is missing" do
subject
expect(event.errors.full_messages).to match ["Update reason can't be blank"]
expect(event.errors.full_messages).to match ["Store credit reason can't be blank"]
end
end
end

context "invalidate event" do
context "has an update reason" do
context "has a store credit reason" do
let(:event) { build(:store_credit_invalidate_event) }

it "returns true" do
expect(subject).to eq true
end
end

context "doesn't have an update reason" do
let(:event) { build(:store_credit_invalidate_event, update_reason: nil) }
context "doesn't have a store credit reason" do
let(:event) { build(:store_credit_invalidate_event, store_credit_reason: nil) }

it "returns false" do
expect(subject).to eq false
end

it "adds an error message indicating the update reason is missing" do
it "adds an error message indicating the store credit reason is missing" do
subject
expect(event.errors.full_messages).to match ["Update reason can't be blank"]
expect(event.errors.full_messages).to match ["Store credit reason can't be blank"]
end
end
end

context "event doesn't require an update reason" do
context "event doesn't require a store credit reason" do
let(:event) { build(:store_credit_auth_event) }

it "returns true" do
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/store_credit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@

describe "#update_amount" do
let(:invalidation_user) { create(:user) }
let(:invalidation_reason) { create(:store_credit_update_reason) }
let(:invalidation_reason) { create(:store_credit_reason) }

subject { store_credit.update_amount(amount, invalidation_reason, invalidation_user) }

Expand Down Expand Up @@ -852,7 +852,7 @@

describe "#invalidate" do
let(:invalidation_user) { create(:user) }
let(:invalidation_reason) { create(:store_credit_update_reason) }
let(:invalidation_reason) { create(:store_credit_reason) }

before do
store_credit.save!
Expand Down

0 comments on commit ad1ec79

Please sign in to comment.