-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from solidusio/ml/existing_card_id_deprecation
New cop to warn about `existing_card_id` usage
- Loading branch information
Showing
11 changed files
with
134 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
rubocop-solidus (0.1.4) | ||
rubocop-solidus (0.2.0) | ||
rubocop | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module Cop | ||
module Solidus | ||
# This cop finds existing_card_id occurrences and suggest using wallet_payment_source_id instead. | ||
# | ||
# @example | ||
# | ||
# # bad | ||
# { | ||
# name: payment_method.name, | ||
# existing_card_id: payment_source.id | ||
# } | ||
# | ||
# # good | ||
# { | ||
# name: payment_method.name, | ||
# wallet_payment_source_id: payment_source.wallet.wallet_payment_sources.first.id | ||
# } | ||
# | ||
class ExistingCardIdDeprecated < Base | ||
include TargetSolidusVersion | ||
minimum_solidus_version 2.2 | ||
|
||
MSG = 'Use `wallet_payment_source_id` instead of `existing_card_id`.' | ||
|
||
def_node_matcher :existing_card_id?, <<~PATTERN | ||
(send ... :existing_card_id) | ||
PATTERN | ||
|
||
def on_send(node) | ||
return unless existing_card_id?(node) | ||
|
||
add_offense(node, severity: :warning) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module RuboCop | ||
module Solidus | ||
VERSION = '0.1.4' | ||
VERSION = '0.2.0' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### New features | ||
|
||
* [#60](https://github.com/solidusio/rubocop-solidus/issues/60): Create new cop to check existing_card_id. ([@MassimilianoLattanzio][]) | ||
|
||
### Bug fixes | ||
|
||
* [#60](https://github.com/solidusio/rubocop-solidus/issues/60): Fix overridden add_offense method. ([@MassimilianoLattanzio][]) | ||
|
||
[@MassimilianoLattanzio]: https://github.com/MassimilianoLattanzio |
16 changes: 16 additions & 0 deletions
16
spec/rubocop/cop/solidus/existing_card_id_deprecated_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Cop::Solidus::ExistingCardIdDeprecated, :config do | ||
it 'registers an offense when using `existing_card_id`' do | ||
expect_offense(<<~RUBY, severity: :warning) | ||
existing_card_id | ||
^^^^^^^^^^^^^^^^ Use `wallet_payment_source_id` instead of `existing_card_id`. | ||
RUBY | ||
end | ||
|
||
it 'does not register an offense when using `wallet_payment_source_id`' do | ||
expect_no_offenses(<<~RUBY) | ||
wallet_payment_source_id | ||
RUBY | ||
end | ||
end |