Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a store credit reasons Admin UI #2798

Merged
merged 9 commits into from
Jan 18, 2019
Merged

Add a store credit reasons Admin UI #2798

merged 9 commits into from
Jan 18, 2019

Conversation

jtapia
Copy link
Contributor

@jtapia jtapia commented Jul 11, 2018

Issue

What it does?

  • Add migration to rename spree_store_credit_update_reasons to spree_store_credit_reasons
  • Add store credit reason controller
  • Add store credit reason model
  • Add store credit reason views
  • Update store credits controller to use store credit reason
  • Add store credit routes and locales
  • Update store credit model to use store credit reason
  • Update store credit event model to use store credit reason
  • Update store credit db seed
  • Update factories to use store credit reason
  • Update tests to use store credit reason

Preview

screen shot 2018-07-10 at 8 00 42 pm

screen shot 2018-07-10 at 8 10 16 pm

screen shot 2018-07-10 at 11 51 27 pm

screen shot 2018-07-10 at 11 51 47 pm

screen shot 2018-07-10 at 8 13 13 pm

screen shot 2018-07-10 at 8 14 19 pm

screen shot 2018-07-10 at 8 14 38 pm

@@ -0,0 +1,18 @@
class RenameSpreeStoreCreditUpdateReasonsTable < ActiveRecord::Migration[5.1]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing magic comment # frozen_string_literal: true.

@@ -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) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/ExtraSpacing: Unnecessary spacing detected.

@@ -16,7 +16,7 @@

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) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/ExtraSpacing: Unnecessary spacing detected.

@jtapia jtapia changed the title Chore/store credit reasons Store credit reasons Jul 11, 2018
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good change, I have just a doubt that the StoreCreditUpdateReason resource meant to represent the reason of the update and not the reason of the store credit itself. Could it make sense?

I left some comment about code but I'm a bit concerned about backward compatibility. Can you please give it a thought as well?

attr_accessor :action, :action_amount, :action_originator, :action_authorization_code, :update_reason
belongs_to :store_credit_reason, class_name: 'Spree::StoreCreditReason', inverse_of: :store_credits

attr_accessor :action, :action_amount, :action_originator, :action_authorization_code, :store_credit_reason
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think store_credit_reason here is needed anymore


validates_presence_of :update_reason, if: :action_requires_reason?
validates_presence_of :store_credit_reason_id, if: :action_requires_reason?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use store_credit_reason here

Copy link
Contributor Author

@jtapia jtapia Jul 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, done

def load_update_reasons
@update_reasons = Spree::StoreCreditUpdateReason.all.order(:name)
def load_reasons
@store_credit_reasons = Spree::StoreCreditReason.all.order(:name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should use the active scope here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

subject { event.valid? }

context "adjustment event" do
context "has an update reason" do
context "has an store credit reason" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has an -> has a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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 an store credit reason" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't have an -> doesn't have a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

end
end
end

context "invalidate event" do
context "has an update reason" do
context "has an store credit reason" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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 an store credit reason" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

end
end
end

context "event doesn't require an update reason" do
context "event doesn't require an store credit reason" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jtapia jtapia closed this Jul 23, 2018
@jtapia jtapia reopened this Jul 23, 2018
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kennyadsl
Copy link
Member

Hey @jtapia, can you please rebase? I'd like to push merging this with the Core Team this week. Thanks!

@jtapia
Copy link
Contributor Author

jtapia commented Jan 12, 2019

@kennyadsl done

Copy link
Contributor

@ericsaupe ericsaupe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

Copy link
Contributor

@jacobherrington jacobherrington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jtapia! 🍰

@kennyadsl kennyadsl merged commit cf96b03 into solidusio:master Jan 18, 2019
@kennyadsl kennyadsl changed the title Store credit reasons Add a store credit reasons Admin UI Jan 18, 2019
kennyadsl added a commit to nebulab/solidus that referenced this pull request Jan 22, 2019
We already converted the rest of the factories attributes to dynamic
into solidusio#2831 but after merging that PR, we merged solidusio#2798 which was pretty
old and was still using the old "way".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_backend Changes to the solidus_backend gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants