-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix view for orders api (Fixes Issue #2512) #2513
Fix view for orders api (Fixes Issue #2512) #2513
Conversation
832bce7
to
78396ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a test for this? Also, the partial name for credit cards should be _credit_card.json.jbuilder
at this point if I'm not mistaken.
Yeah I can add a test for this. As far as the naming convention, I followed convention on how Spree admin chooses to display payment sources. If we want to move away from that convention I will change the views mimic that payment source rather than the method |
Sorry, I thought we changed the partial name with deprecating the So, keep the partial name, but do add a spec. ❤️ |
78396ab
to
f941499
Compare
Let me know if the specs added are sufficient |
|
||
it 'renders the payment source view for gateway' do | ||
subject | ||
expect(response).to render_template partial: "spree/api/payments/source_views/_#{payment.payment_method.partial_name}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are sufficient, but should be more explicit. Either render_template('spree/api/payments/source_views/_gateway.html.erb
), or test directly for the right thing being rendered as JSON.
f941499
to
ce50561
Compare
Made changes as requested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -25,11 +25,10 @@ json.payments(order.payments) do |payment| | |||
json.payment_method { json.(payment.payment_method, :id, :name) } | |||
json.source do | |||
if payment.source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible that payment.source
is a Spree::Payment
.
See: https://github.com/solidusio/solidus/blob/v2.4/backend/app/views/spree/admin/payments/show.html.erb#L16
We will need to account for that situation here as well:
json.source do
##
# payment.source could be a Spree::Payment. If it is then we need to call
# source twice.
# @see https://github.com/solidusio/solidus/blob/v2.4/backend/app/views/spree/admin/payments/show.html.erb#L16
#
payment_source = payment.source.is_a?(Spree::Payment) ? payment.source.source : payment.source
if payment_source
json.partial!(
"spree/api/payments/source_views/#{payment.payment_method.partial_name}",
payment_source: payment_source
)
else
json.nil!
end
end
When I get a chance I'll add this to the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some files could not be reviewed due to errors:
.rubocop.yml: Lint/EndAlignment has the wrong namespace - should be Layout
.rubocop.yml: Lint/EndAlignment has the wrong namespace - should be Layout Error: The `Style/TrailingCommaInLiteral` cop no longer exists. Please use `Style/TrailingCommaInArrayLiteral` and/or `Style/TrailingCommaInHashLiteral` instead. (obsolete configuration found in .rubocop.yml, please update it)
What is the status of this? |
There's a red CircleCI build on this right now. Do you know the source of the errors? |
I just pushed something new so it may have to do with that. I'll take a look |
Refactor _big.json.jbuilder so that it dynamically loads the payment source view based on that source's payment method. Add payment views for each payment method which will be used to render a payment source as json.
34c41db
to
89cb4d9
Compare
Look like I just needed to rebase my branch on master |
Refactor _big.json.jbuilder so that it dynamically loads the payment
source view based on that source's payment method.
Add payment views for each payment method which will be used to render a
payment source as json.
Fixes #2512.