Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Make gem compatible with Rails 7 #321

Conversation

gsmendoza
Copy link
Contributor

Main changes

gsmendoza added 10 commits June 14, 2022 15:54
Fixes `Webdrivers::BrowserNotFound: Failed to find Chrome binary` errors
in CircleCI.
Output:

```
solidus_paypal_braintree 15:03:48 $ bundle exec rubocop --autocorrect
Inspecting 76 files
C..............................................CC..C........CCC.......C.....

Offenses:

Gemfile:23:6: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('DB') or ENV.fetch('DB', nil) instead of ENV['DB'].
case ENV['DB']
     ^^^^^^^^^
solidus_paypal_braintree.gemspec:22:3: C: [Corrected] Gemspec/DeprecatedAttributeAssignment: Do not set test_files in gemspec.
  s.test_files = Dir['spec/**/*']
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb:57:14: C: [Correctable] RSpec/ExpectChange: Prefer change(SolidusPaypalBraintree::Source, :count).
          to change { SolidusPaypalBraintree::Source.count }.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb:91:39: C: [Correctable] RSpec/ExpectChange: Prefer change(::Spree::Payment, :count).
        expect{ patch_update }.not_to(change{ ::Spree::Payment.count })
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb:95:39: C: [Correctable] RSpec/ExpectChange: Prefer change(SolidusPaypalBraintree::Source, :count).
        expect{ patch_update }.not_to(change{ SolidusPaypalBraintree::Source.count })
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb:103:37: C: [Correctable] RSpec/ExpectChange: Prefer change(Spree::Address, :count).
          expect { post_create }.to change { Spree::Address.count }.by(1)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb:116:37: C: [Correctable] RSpec/ExpectChange: Prefer change(Spree::Address, :count).
          expect { post_create }.to change { Spree::Address.count }.by(1)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb:126:41: C: [Correctable] RSpec/ExpectChange: Prefer change(Spree::Address, :count).
          expect { post_create }.not_to(change { Spree::Address.count })
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/avs_result_spec.rb:9:25: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
        instance_double('Braintree::Transaction',
                        ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/avs_result_spec.rb:30:25: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
        instance_double('Braintree::Transaction',
                        ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/gateway_spec.rb:423:50: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
      subject { gateway.try_void(instance_double('Spree::Payment', response_code: source.token)) }
                                                 ^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/gateway_spec.rb:426:22: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
        class_double('Braintree::Transaction',
                     ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/gateway_spec.rb:431:34: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
        client = instance_double('Braintree::Gateway')
                                 ^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/gateway_spec.rb:438:27: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
          instance_double('Braintree::Transaction',
                          ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/gateway_spec.rb:476:27: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
          instance_double('Braintree::Transaction',
                          ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/gateway_spec.rb:488:27: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
          instance_double('Braintree::Transaction',
                          ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:7:7: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
      'Braintree::ValidationError',
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:15:7: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
      'Braintree::ErrorResult',
      ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:29:7: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
      'Braintree::Transaction',
      ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:39:7: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
      'Braintree::SuccessfulResult',
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:83:13: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
            'Braintree::Transaction',
            ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:102:13: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
            'Braintree::Transaction',
            ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:120:13: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
            'Braintree::Transaction',
            ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:139:13: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
            'Braintree::Transaction',
            ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:156:13: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
            'Braintree::Transaction',
            ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:189:11: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
          'Braintree::Transaction',
          ^^^^^^^^^^^^^^^^^^^^^^^^
spec/models/solidus_paypal_braintree/response_spec.rb:235:11: C: [Corrected] RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.
          'Braintree::Transaction',
          ^^^^^^^^^^^^^^^^^^^^^^^^
spec/support/capybara.rb:7:30: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a method call.
Capybara.javascript_driver = (ENV.fetch('CAPYBARA_DRIVER', :selenium_chrome)).to_sym
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/support/capybara.rb:7:31: C: [Corrected] Style/FetchEnvVar: Use ENV.fetch('CAPYBARA_DRIVER', :selenium_chrome) instead of ENV['CAPYBARA_DRIVER'] || :selenium_chrome.
Capybara.javascript_driver = (ENV['CAPYBARA_DRIVER'] || :selenium_chrome).to_sym
                              ^^^^^^^^^^^^^^^^^^^^^^

76 files inspected, 29 offenses detected, 23 offenses corrected, 6 more offenses can be corrected with `rubocop -A`
```
For some reason, RuboCop is unable to autocorrect these.

RuboCop output:

```
solidus_paypal_braintree 15:12:20 $ bundle exec rubocop --autocorrect
Inspecting 76 files
................................................C..C........................

Offenses:

spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb:56:36: C: [Correctable] RSpec/ExpectChange: Prefer change(SolidusPaypalBraintree::Source, :count).
        expect { patch_update }.to change { SolidusPaypalBraintree::Source.count }.from(0).to(1)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb:88:39: C: [Correctable] RSpec/ExpectChange: Prefer change(::Spree::Payment, :count).
        expect{ patch_update }.not_to(change{ ::Spree::Payment.count })
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb:92:39: C: [Correctable] RSpec/ExpectChange: Prefer change(SolidusPaypalBraintree::Source, :count).
        expect{ patch_update }.not_to(change{ SolidusPaypalBraintree::Source.count })
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb:103:37: C: [Correctable] RSpec/ExpectChange: Prefer change(Spree::Address, :count).
          expect { post_create }.to change { Spree::Address.count }.by(1)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb:116:37: C: [Correctable] RSpec/ExpectChange: Prefer change(Spree::Address, :count).
          expect { post_create }.to change { Spree::Address.count }.by(1)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb:126:41: C: [Correctable] RSpec/ExpectChange: Prefer change(Spree::Address, :count).
          expect { post_create }.not_to(change { Spree::Address.count })
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

76 files inspected, 6 offenses detected, 6 more offenses can be corrected with `rubocop -A`
```
Remove Bundler workaround. No longer needed.
Will be reenabled once Venmo is enabled on the Braintree sandbox.
Fixes `NameError: uninitialized constant
SolidusPaypalBraintree::Gateway` when running `bundle exec rake`
Fixes `NameError: uninitialized constant
SolidusPaypalBraintree::Spree::PermittedAttributes` when running `bundle
exec rake`.
…idempotent

For historical reasons, the `to_prepare` callback may run twice. The
code it executes must be idempotent.

See
https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoload-on-boot-and-on-each-reload.
SolidusPaypalBraintree::Gateway.allowed_admin_form_preference_types << :preference_select
Spree::PermittedAttributes.source_attributes.concat [:nonce, :payment_type, :paypal_funding_source]
config.to_prepare do
app.config.spree.payment_methods << SolidusPaypalBraintree::Gateway
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This append call is already idempotent since app.config.spree.payment_methods is a Set object

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 George!

@kennyadsl kennyadsl merged commit 806d20b into solidusio:master Jun 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants