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

Fix setting the wallet's default payment source to the same value #1888

Merged
merged 3 commits into from
May 9, 2017

Conversation

ahoernecke
Copy link
Contributor

…set to the same value

This fixes a bug where if the app tried to set the default payment method to the existing default, the wallet would end up with no default payment method

@@ -95,6 +95,19 @@
end
end

context "with the same payment source already set to default" do
let!(:wallet_credit_card) { subject.add(credit_card) }

Choose a reason for hiding this comment

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

Trailing whitespace detected.

@@ -61,6 +61,11 @@ def default_wallet_payment_source=(wallet_payment_source)
raise Unauthorized, "wallet_payment_source #{wallet_payment_source.id} does not belong to wallet of user #{user.id}"
end

# Do not update the payment source if the passed source is already default
if(default_wallet_payment_source.try(:id) == wallet_payment_source.id)

Choose a reason for hiding this comment

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

Space after keyword if is missing.

…set to the same value

This fixes a bug where if the app tried to set the default payment method to the existing default, the wallet would end up with no default payment method
@@ -61,6 +61,11 @@ def default_wallet_payment_source=(wallet_payment_source)
raise Unauthorized, "wallet_payment_source #{wallet_payment_source.id} does not belong to wallet of user #{user.id}"
end

# Do not update the payment source if the passed source is already default
if default_wallet_payment_source.try(:id) == wallet_payment_source.try(:id)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if both of these return nil?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably better to also not use .try(:id). default_wallet_payment_source == wallet_payment_source

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If both return nil, it should signify that the system is trying to clear the default payment source (wallet_payment_source=>nil) and that the default payment source is already not set (default_wallet_payment_source=>nil). Since we just return for this case, nothing would change, which I would think is what would be wanted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jhawthorn, made the change to not compare against the ids.

Copy link
Contributor

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me. Thanks.

I've spotted a second issue (assigning nil errors), which I'll send a follow up PR to fix.

Copy link
Contributor

@jordan-brough jordan-brough left a comment

Choose a reason for hiding this comment

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

Thanks!

@jhawthorn jhawthorn merged commit 93941eb into solidusio:master May 9, 2017
@jhawthorn jhawthorn changed the title Bug fix: Don't update wallet default payment method if the default is already … Fix setting the wallet's default payment source to the same value May 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Error, flaw or fault
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants