diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a8bd2266..47e53d62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,15 +23,12 @@ jobs: fail-fast: true matrix: rails-version: - - "7.0" - "7.1" - "7.2" ruby-version: - - "3.1" + - "3.3" - "3.4" solidus-branch: - - "v4.1" - - "v4.2" - "v4.3" - "v4.4" database: @@ -41,16 +38,7 @@ jobs: exclude: - rails-version: "7.2" solidus-branch: "v4.3" - - rails-version: "7.2" - solidus-branch: "v4.2" - - rails-version: "7.2" - solidus-branch: "v4.1" - - rails-version: "7.1" - solidus-branch: "v4.2" - - rails-version: "7.1" - solidus-branch: "v4.1" - - ruby-version: "3.4" - rails-version: "7.0" + steps: - uses: actions/checkout@v4 - name: Run extension tests diff --git a/.rubocop.yml b/.rubocop.yml index 9b902771..6207a647 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,86 +1,2 @@ require: - solidus_dev_support/rubocop - -AllCops: - NewCops: disable - TargetRubyVersion: '3.0' - Exclude: - - sandbox/**/* - - dummy-app/**/* - - spec/dummy/**/* - - vendor/bundle/**/* - -Layout/FirstArgumentIndentation: - EnforcedStyle: consistent - -Layout/FirstArrayElementIndentation: - EnforcedStyle: consistent - -Layout/FirstHashElementIndentation: - EnforcedStyle: consistent - -Layout/MultilineMethodCallIndentation: - EnforcedStyle: indented - -Naming/VariableNumber: - Enabled: false - -# We use this extensively, the alternatives are not viable or desirable. -RSpec/AnyInstance: - Enabled: false - -# No need to make the code more complex for no real gain. -RSpec/MessageSpies: - Enabled: false - -# Let's consider legitimate to have multiple expectations within an example. -RSpec/MultipleExpectations: - Enabled: false - -# Allow to use subject as is, no big deal. -RSpec/NamedSubject: - Enabled: false - -# Let's set this to some really exagerate value. -RSpec/NestedGroups: - Max: 8 - -# We don't use the FactoryBot mixin -RSpec/FactoryBot/SyntaxMethods: - Enabled: false - -RSpec/VerifiedDoubles: - # Sometimes you really need an "anything" double - IgnoreSymbolicNames: true - -Style/FrozenStringLiteralComment: - Exclude: - - spec/**/* - - db/migrate/**/* - - bin/**/* - -Style/ExplicitBlockArgument: - Exclude: - - lib/solidus_braintree/request_protection.rb - -Rails/SkipsModelValidations: - Exclude: - - db/migrate/**/* - -Rails/ReflectionClassName: - Exclude: - - app/models/solidus_braintree/customer.rb - - app/models/solidus_braintree/source.rb - -RSpec/MultipleMemoizedHelpers: - Exclude: - - spec/models/solidus_braintree/transaction_import_spec.rb - - spec/models/solidus_braintree/response_spec.rb - - spec/models/solidus_braintree/gateway_spec.rb - - spec/controllers/solidus_braintree/client_tokens_controller_spec.rb - - spec/system/frontend/braintree_credit_card_checkout_spec.rb - - spec/system/frontend/paypal_checkout_spec.rb - -Rails/ApplicationRecord: - Exclude: - - db/migrate/* diff --git a/Gemfile b/Gemfile index 897c28ce..1da0073e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,23 +1,23 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -branch = ENV.fetch('SOLIDUS_BRANCH', 'main') -gem 'solidus', github: 'solidusio/solidus', branch: branch +branch = ENV.fetch("SOLIDUS_BRANCH", "main") +gem "solidus", github: "solidusio/solidus", branch: branch -gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', '7.0')}" +gem "rails", "~> #{ENV.fetch("RAILS_VERSION", "7.0")}" # Provides basic authentication functionality for testing parts of your engine -gem 'solidus_auth_devise' +gem "solidus_auth_devise" -case ENV.fetch('DB', nil) -when 'mysql' - gem 'mysql2' -when 'postgresql' - gem 'pg' +case ENV.fetch("DB", nil) +when "mysql" + gem "mysql2" +when "postgresql" + gem "pg" else - gem 'sqlite3' + gem "sqlite3" end gemspec @@ -27,4 +27,4 @@ gemspec # # We use `send` instead of calling `eval_gemfile` to work around an issue with # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658. -send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local' +send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local" diff --git a/Rakefile b/Rakefile index f269e67b..e701ffb1 100644 --- a/Rakefile +++ b/Rakefile @@ -1,15 +1,15 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' -require 'solidus_dev_support/rake_tasks' +require "bundler/gem_tasks" +require "solidus_dev_support/rake_tasks" SolidusDevSupport::RakeTasks.install task :default do - require 'bundler' + require "bundler" Bundler.with_unbundled_env do - sh 'bin/rspec' + sh "bin/rspec" end end -CLOBBER.include('dummy-app') -CLOBBER.include('sandbox') +CLOBBER.include("dummy-app") +CLOBBER.include("sandbox") diff --git a/app/decorators/models/solidus_braintree/spree_user_decorator.rb b/app/decorators/models/solidus_braintree/spree_user_decorator.rb index 0721a3d8..b2990c27 100644 --- a/app/decorators/models/solidus_braintree/spree_user_decorator.rb +++ b/app/decorators/models/solidus_braintree/spree_user_decorator.rb @@ -3,7 +3,7 @@ module SolidusBraintree module SpreeUserDecorator def self.prepended(base) - base.has_one :braintree_customer, class_name: 'SolidusBraintree::Customer', inverse_of: :user + base.has_one :braintree_customer, class_name: "SolidusBraintree::Customer", inverse_of: :user end ::Spree.user_class.prepend self diff --git a/app/helpers/solidus_braintree/braintree_admin_helper.rb b/app/helpers/solidus_braintree/braintree_admin_helper.rb index 5c08a36e..a0cee40d 100644 --- a/app/helpers/solidus_braintree/braintree_admin_helper.rb +++ b/app/helpers/solidus_braintree/braintree_admin_helper.rb @@ -4,7 +4,7 @@ module SolidusBraintree module BraintreeAdminHelper # Returns a link to the Braintree web UI for the given Braintree payment def braintree_transaction_link(payment) - environment = payment.payment_method.preferred_environment == 'sandbox' ? 'sandbox' : 'www' + environment = (payment.payment_method.preferred_environment == "sandbox") ? "sandbox" : "www" merchant_id = payment.payment_method.preferred_merchant_id response_code = payment.response_code @@ -14,9 +14,9 @@ def braintree_transaction_link(payment) link_to( response_code, "https://#{environment}.braintreegateway.com/merchants/#{merchant_id}/transactions/#{response_code}", - title: 'Show payment on Braintree', - target: '_blank', - rel: 'noopener' + title: "Show payment on Braintree", + target: "_blank", + rel: "noopener" ) end end diff --git a/app/models/solidus_braintree/avs_result.rb b/app/models/solidus_braintree/avs_result.rb index 157a188f..ac70f6a3 100644 --- a/app/models/solidus_braintree/avs_result.rb +++ b/app/models/solidus_braintree/avs_result.rb @@ -1,50 +1,50 @@ # frozen_string_literal: true -require 'active_merchant/billing/avs_result' +require "active_merchant/billing/avs_result" module SolidusBraintree class AVSResult < ActiveMerchant::Billing::AVSResult # Mapping took from ActiveMerchant::Billing::BraintreeBlueGateway AVS_MAPPING = { - 'M' => { - 'M' => 'M', - 'N' => 'A', - 'U' => 'B', - 'I' => 'B', - 'A' => 'B' + "M" => { + "M" => "M", + "N" => "A", + "U" => "B", + "I" => "B", + "A" => "B" }, - 'N' => { - 'M' => 'Z', - 'N' => 'C', - 'U' => 'C', - 'I' => 'C', - 'A' => 'C' + "N" => { + "M" => "Z", + "N" => "C", + "U" => "C", + "I" => "C", + "A" => "C" }, - 'U' => { - 'M' => 'P', - 'N' => 'N', - 'U' => 'I', - 'I' => 'I', - 'A' => 'I' + "U" => { + "M" => "P", + "N" => "N", + "U" => "I", + "I" => "I", + "A" => "I" }, - 'I' => { - 'M' => 'P', - 'N' => 'C', - 'U' => 'I', - 'I' => 'I', - 'A' => 'I' + "I" => { + "M" => "P", + "N" => "C", + "U" => "I", + "I" => "I", + "A" => "I" }, - 'A' => { - 'M' => 'P', - 'N' => 'C', - 'U' => 'I', - 'I' => 'I', - 'A' => 'I' + "A" => { + "M" => "P", + "N" => "C", + "U" => "I", + "I" => "I", + "A" => "I" }, - 'B' => { - 'B' => 'B' + "B" => { + "B" => "B" }, - nil => { nil => nil } + nil => {nil => nil} }.freeze class << self diff --git a/app/models/solidus_braintree/base_record.rb b/app/models/solidus_braintree/base_record.rb index 204c1bfe..02b7db76 100644 --- a/app/models/solidus_braintree/base_record.rb +++ b/app/models/solidus_braintree/base_record.rb @@ -2,7 +2,7 @@ module SolidusBraintree def self.table_name_prefix - 'solidus_paypal_braintree_' + "solidus_paypal_braintree_" end class BaseRecord < ::Spree::Base diff --git a/app/models/solidus_braintree/configuration.rb b/app/models/solidus_braintree/configuration.rb index 36dbb533..4586bdcd 100644 --- a/app/models/solidus_braintree/configuration.rb +++ b/app/models/solidus_braintree/configuration.rb @@ -3,30 +3,30 @@ module SolidusBraintree class Configuration < BaseRecord PAYPAL_BUTTON_PREFERENCES = { - color: { availables: %w[gold blue silver white black], default: 'white' }, - shape: { availables: %w[pill rect], default: 'rect' }, - label: { availables: %w[checkout credit pay buynow paypal installment], default: 'checkout' }, - tagline: { availables: %w[true false], default: 'false' }, - layout: { availables: %w[horizontal vertical], default: 'horizontal' }, - messaging: { availables: %w[true false], default: 'false' } + color: {availables: %w[gold blue silver white black], default: "white"}, + shape: {availables: %w[pill rect], default: "rect"}, + label: {availables: %w[checkout credit pay buynow paypal installment], default: "checkout"}, + tagline: {availables: %w[true false], default: "false"}, + layout: {availables: %w[horizontal vertical], default: "horizontal"}, + messaging: {availables: %w[true false], default: "false"} }.freeze include ::Spree::Preferences::Persistable - belongs_to :store, class_name: 'Spree::Store', optional: false + belongs_to :store, class_name: "Spree::Store", optional: false # Preferences for Paypal button PAYPAL_BUTTON_PREFERENCES.each do |name, desc| - preference_name = "paypal_button_#{name}".to_sym - attribute_name = "preferred_#{preference_name}".to_sym + preference_name = :"paypal_button_#{name}" + attribute_name = :"preferred_#{preference_name}" preference preference_name, :string, default: desc[:default] validates attribute_name, inclusion: desc[:availables] end - preference :venmo_button_color, :preference_select, default: 'blue' - preference :venmo_button_width, :preference_select, default: '320' + preference :venmo_button_color, :preference_select, default: "blue" + preference :venmo_button_width, :preference_select, default: "320" def preferred_venmo_button_color_options [["Blue", "blue"], ["White", "white"]] diff --git a/app/models/solidus_braintree/gateway.rb b/app/models/solidus_braintree/gateway.rb index 2e234a5b..f30bc702 100644 --- a/app/models/solidus_braintree/gateway.rb +++ b/app/models/solidus_braintree/gateway.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'solidus_braintree/request_protection' +require "solidus_braintree/request_protection" module SolidusBraintree class Gateway < ::Spree::PaymentMethod @@ -11,9 +11,9 @@ class TokenGenerationDisabledError < StandardError; end # Error message from Braintree that gets returned by a non voidable transaction NON_VOIDABLE_STATUS_ERROR_REGEXP = /can only be voided if status is authorized/ - TOKEN_GENERATION_DISABLED_MESSAGE = 'Token generation is disabled. ' \ - 'To re-enable set the `token_generation_enabled` preference on the ' \ - 'gateway to `true`.' + TOKEN_GENERATION_DISABLED_MESSAGE = "Token generation is disabled. " \ + "To re-enable set the `token_generation_enabled` preference on the " \ + "gateway to `true`." ALLOWED_BRAINTREE_OPTIONS = [ :device_data, @@ -35,9 +35,9 @@ class TokenGenerationDisabledError < StandardError; end preference(:token_generation_enabled, :boolean, default: true) # Preferences for configuration of Braintree credentials - preference(:environment, :string, default: 'sandbox') + preference(:environment, :string, default: "sandbox") preference(:merchant_id, :string, default: nil) - preference(:public_key, :string, default: nil) + preference(:public_key, :string, default: nil) preference(:private_key, :string, default: nil) preference(:http_open_timeout, :integer, default: 60) preference(:http_read_timeout, :integer, default: 60) @@ -45,7 +45,7 @@ class TokenGenerationDisabledError < StandardError; end preference(:paypal_payee_email_map, :hash, default: {}) # Which checkout flow to use (vault/checkout) - preference(:paypal_flow, :string, default: 'vault') + preference(:paypal_flow, :string, default: "vault") # A hash that gets passed to the `style` key when initializing the credit card fields. # See https://developers.braintreepayments.com/guides/hosted-fields/styling/javascript/v3 @@ -301,7 +301,7 @@ def reusable_sources(order) # Whether to store this payment method in the PayPal Vault. This only works when the checkout # flow is "vault", so make sure to call +super+ if you override it. def store_in_vault - preferred_paypal_flow == 'vault' + preferred_paypal_flow == "vault" end def logger @@ -334,26 +334,24 @@ def convert_preference_value(value, type, preference_encryptor = nil) end def transaction_options(source, options, submit_for_settlement: false) - params = options.select do |key, _| - ALLOWED_BRAINTREE_OPTIONS.include?(key) - end + params = options.slice(*ALLOWED_BRAINTREE_OPTIONS) params[:channel] = "Solidus" - params[:options] = { store_in_vault_on_success: store_in_vault } + params[:options] = {store_in_vault_on_success: store_in_vault} if submit_for_settlement params[:options][:submit_for_settlement] = true end - if paypal_email = paypal_payee_email_for(source, options) - params[:options][:paypal] = { payee_email: paypal_email } + if (paypal_email = paypal_payee_email_for(source, options)) + params[:options][:paypal] = {payee_email: paypal_email} end if source.venmo? && venmo_business_profile_id - params[:options][:venmo] = { profile_id: venmo_business_profile_id } + params[:options][:venmo] = {profile_id: venmo_business_profile_id} end - if merchant_account_id = merchant_account_for(source, options) + if (merchant_account_id = merchant_account_for(source, options)) params[:merchant_account_id] = merchant_account_id end diff --git a/app/models/solidus_braintree/response.rb b/app/models/solidus_braintree/response.rb index 55c18e0a..3144388e 100644 --- a/app/models/solidus_braintree/response.rb +++ b/app/models/solidus_braintree/response.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'active_merchant/billing/response' -require_relative 'avs_result' +require "active_merchant/billing/response" +require_relative "avs_result" # Response object that all actions on the gateway should return module SolidusBraintree @@ -57,21 +57,21 @@ def error_message(result) # Human readable error message for transaction responses def transaction_error_message(transaction) case transaction.status - when 'gateway_rejected' + when "gateway_rejected" I18n.t(transaction.gateway_rejection_reason, - scope: 'solidus_braintree.gateway_rejection_reasons', + scope: "solidus_braintree.gateway_rejection_reasons", default: "#{transaction.status.humanize} #{transaction.gateway_rejection_reason.humanize}") - when 'processor_declined' + when "processor_declined" I18n.t(transaction.processor_response_code, - scope: 'solidus_braintree.processor_response_codes', + scope: "solidus_braintree.processor_response_codes", default: "#{transaction.processor_response_text} (#{transaction.processor_response_code})") - when 'settlement_declined' + when "settlement_declined" I18n.t(transaction.processor_settlement_response_code, - scope: 'solidus_braintree.processor_settlement_response_codes', + scope: "solidus_braintree.processor_settlement_response_codes", default: "#{transaction.processor_settlement_response_text} (#{transaction.processor_settlement_response_code})") # rubocop:disable Layout/LineLength else I18n.t(transaction.status, - scope: 'solidus_braintree.transaction_statuses', + scope: "solidus_braintree.transaction_statuses", default: transaction.status.humanize) end end diff --git a/app/models/solidus_braintree/source.rb b/app/models/solidus_braintree/source.rb index c09019d8..acde5357 100644 --- a/app/models/solidus_braintree/source.rb +++ b/app/models/solidus_braintree/source.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'solidus_braintree/request_protection' +require "solidus_braintree/request_protection" module SolidusBraintree class Source < ::Spree::PaymentSource @@ -20,7 +20,7 @@ class Source < ::Spree::PaymentSource }, suffix: :funding belongs_to :user, class_name: ::Spree::UserClassHandle.new, optional: true - belongs_to :payment_method, class_name: 'Spree::PaymentMethod' + belongs_to :payment_method, class_name: "Spree::PaymentMethod" has_many :payments, as: :source, class_name: "Spree::Payment", dependent: :destroy belongs_to :customer, class_name: "SolidusBraintree::Customer", optional: true @@ -100,18 +100,18 @@ def display_number elsif venmo? username else - "XXXX-XXXX-XXXX-#{last_digits.to_s.rjust(4, 'X')}" + "XXXX-XXXX-XXXX-#{last_digits.to_s.rjust(4, "X")}" end end def display_paypal_funding_source I18n.t(paypal_funding_source, - scope: 'solidus_braintree.paypal_funding_sources', + scope: "solidus_braintree.paypal_funding_sources", default: paypal_funding_source) end def display_payment_type - "#{I18n.t('solidus_braintree.payment_type.label')}: #{friendly_payment_type}" + "#{I18n.t("solidus_braintree.payment_type.label")}: #{friendly_payment_type}" end private diff --git a/app/models/solidus_braintree/transaction.rb b/app/models/solidus_braintree/transaction.rb index 17bc3da1..09d5c510 100644 --- a/app/models/solidus_braintree/transaction.rb +++ b/app/models/solidus_braintree/transaction.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_model' +require "active_model" module SolidusBraintree class Transaction @@ -15,7 +15,7 @@ class Transaction validate do unless payment_method.is_a? SolidusBraintree::Gateway - errors.add(:payment_method, 'Must be braintree') + errors.add(:payment_method, "Must be braintree") end if address&.invalid? address.errors.each do |error| diff --git a/app/models/solidus_braintree/transaction_address.rb b/app/models/solidus_braintree/transaction_address.rb index c9261b47..c9f37ab8 100644 --- a/app/models/solidus_braintree/transaction_address.rb +++ b/app/models/solidus_braintree/transaction_address.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'active_model' -require 'solidus_braintree/country_mapper' +require "active_model" +require "solidus_braintree/country_mapper" module SolidusBraintree class TransactionAddress @@ -13,7 +13,7 @@ class TransactionAddress :address_line_1, :address_line_2, :first_name, :last_name validates :address_line_1, :city, :zip, :country_code, presence: true - validates :name, presence: true, unless: ->(address){ address.first_name.present? } + validates :name, presence: true, unless: ->(address) { address.first_name.present? } before_validation do self.country_code = country_code.presence || "us" @@ -28,7 +28,7 @@ def initialize(attributes = {}) attributes[:country_code] = iso_from_name(country_name) end - super(attributes) + super end def spree_country @@ -36,7 +36,7 @@ def spree_country end def spree_state - spree_country && state_code && ( @state ||= spree_country.states.find_by( + spree_country && state_code && (@state ||= spree_country.states.find_by( ::Spree::State.arel_table[:name].matches(state_code).or( ::Spree::State.arel_table[:abbr].matches(state_code) ) diff --git a/app/models/solidus_braintree/transaction_import.rb b/app/models/solidus_braintree/transaction_import.rb index 635df606..096f69d4 100644 --- a/app/models/solidus_braintree/transaction_import.rb +++ b/app/models/solidus_braintree/transaction_import.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_model' +require "active_model" module SolidusBraintree class TransactionImport @@ -61,7 +61,7 @@ def import!(end_state, restart_checkout: false) advance_order(payment, end_state) else raise InvalidImportError, - "Validation failed: #{errors.full_messages.join(', ')}" + "Validation failed: #{errors.full_messages.join(", ")}" end end diff --git a/bin/dummy-app b/bin/dummy-app index 3552eaea..03e0d3d3 100755 --- a/bin/dummy-app +++ b/bin/dummy-app @@ -15,7 +15,7 @@ test "$DB" = "sqlite" && export DB="sqlite3" rm -rf ./dummy-app rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'` -rails _${rails_version}_ new dummy-app \ +bundle exec rails _${rails_version}_ new dummy-app \ --database=${DB:-sqlite3} \ --skip-git \ --skip-keeps \ diff --git a/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb b/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb index 617ba428..5c3247d0 100644 --- a/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +++ b/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb @@ -1,9 +1,9 @@ class CreateSolidusPaypalBraintreeConfigurations < SolidusSupport::Migration[4.2] def change create_table :solidus_paypal_braintree_configurations do |t| - t.boolean :paypal, null: false, default: false + t.boolean :paypal, null: false, default: false t.boolean :apple_pay, null: false, default: false - t.integer :store_id, null: false, index: true, foreign_key: { references: :spree_stores } + t.integer :store_id, null: false, index: true, foreign_key: {references: :spree_stores} t.timestamps null: false end diff --git a/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb b/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb index b994c7f6..58a08e25 100644 --- a/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +++ b/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb @@ -5,8 +5,8 @@ class SolidusPaypalBraintreeSource < ActiveRecord::Base def change reversible do |dir| dir.up do - SolidusPaypalBraintreeSource.where(payment_type: nil). - update_all(payment_type: 'CreditCard') + SolidusPaypalBraintreeSource.where(payment_type: nil) + .update_all(payment_type: "CreditCard") end end change_column_null(:solidus_paypal_braintree_sources, :payment_type, false) diff --git a/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb b/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb index b8666b85..e6d5fa61 100644 --- a/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +++ b/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb @@ -7,19 +7,19 @@ class RenameSolidusPaypalBraintreeSourceType < ActiveRecord::Migration[6.1] def up Spree::Payment.unscoped - .where(source_type: 'SolidusPaypalBraintree::Source').in_batches do |relation| + .where(source_type: "SolidusPaypalBraintree::Source").in_batches do |relation| relation.update_all("source_type = 'SolidusBraintree::Source'") sleep(0.01) end Spree::WalletPaymentSource.unscoped - .where(payment_source_type: 'SolidusPaypalBraintree::Source').in_batches do |relation| + .where(payment_source_type: "SolidusPaypalBraintree::Source").in_batches do |relation| relation.update_all("payment_source_type = 'SolidusBraintree::Source'") sleep(0.01) end Spree::PaymentMethod.unscoped - .where('type = ?', 'SolidusPaypalBraintree::Gateway').in_batches do |relation| + .where("type = ?", "SolidusPaypalBraintree::Gateway").in_batches do |relation| relation.update_all("type = 'SolidusBraintree::Gateway'") sleep(0.01) end diff --git a/lib/controllers/api/solidus_braintree/client_tokens_controller.rb b/lib/controllers/api/solidus_braintree/client_tokens_controller.rb index ca42b71b..229f50ef 100644 --- a/lib/controllers/api/solidus_braintree/client_tokens_controller.rb +++ b/lib/controllers/api/solidus_braintree/client_tokens_controller.rb @@ -9,9 +9,9 @@ class ClientTokensController < ::Spree::Api::BaseController def create token = @gateway.generate_token if token - render json: { client_token: token, payment_method_id: @gateway.id } + render json: {client_token: token, payment_method_id: @gateway.id} else - render json: { error: Gateway::TOKEN_GENERATION_DISABLED_MESSAGE }, status: :unprocessable_entity + render json: {error: Gateway::TOKEN_GENERATION_DISABLED_MESSAGE}, status: :unprocessable_entity end end diff --git a/lib/controllers/backend/solidus_braintree/configurations_controller.rb b/lib/controllers/backend/solidus_braintree/configurations_controller.rb index e2017333..b1fa81e5 100644 --- a/lib/controllers/backend/solidus_braintree/configurations_controller.rb +++ b/lib/controllers/backend/solidus_braintree/configurations_controller.rb @@ -16,9 +16,9 @@ def update params = configurations_params[:configuration_fields] results = SolidusBraintree::Configuration.update(params.keys, params.values) if results.all?(&:valid?) - flash[:success] = t('update_success', scope: 'solidus_braintree.configurations') + flash[:success] = t("update_success", scope: "solidus_braintree.configurations") else - flash[:error] = t('update_error', scope: 'solidus_braintree.configurations') + flash[:error] = t("update_error", scope: "solidus_braintree.configurations") end redirect_to action: :list end @@ -26,8 +26,8 @@ def update private def configurations_params - params.require(:configurations). - permit(configuration_fields: [ + params.require(:configurations) + .permit(configuration_fields: [ :paypal, :apple_pay, :venmo, diff --git a/lib/generators/solidus_braintree/install/install_generator.rb b/lib/generators/solidus_braintree/install/install_generator.rb index ac7f7593..e5d4d327 100644 --- a/lib/generators/solidus_braintree/install/install_generator.rb +++ b/lib/generators/solidus_braintree/install/install_generator.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rails/generators/app_base' +require "rails/generators/app_base" module SolidusBraintree module Generators @@ -9,115 +9,115 @@ class InstallGenerator < Rails::Generators::AppBase class_option :migrate, type: :boolean, default: true class_option :backend, type: :boolean, default: true - class_option :frontend, type: :string, default: 'starter' + class_option :frontend, type: :string, default: "starter" # This is only used to run all-specs during development and CI, regular installation limits # installed specs to frontend, which are the ones related to code copied to the target application. - class_option :specs, type: :string, enum: %w[all frontend], default: 'frontend', hide: true + class_option :specs, type: :string, enum: %w[all frontend], default: "frontend", hide: true - source_root File.expand_path('templates', __dir__) + source_root File.expand_path("templates", __dir__) def normalize_components_options @components = { backend: options[:backend], - starter_frontend: options[:frontend] == 'starter', - classic_frontend: options[:frontend] == 'classic', + starter_frontend: options[:frontend] == "starter", + classic_frontend: options[:frontend] == "classic" } end def add_test_gems gem_group :test do - ['vcr', 'webmock'].each do |gem_name| + ["vcr", "webmock"].each do |gem_name| gem gem_name unless Bundler.locked_gems.dependencies[gem_name] end end - bundle_command 'install' + bundle_command "install" end def setup_initializers legacy_initializer_pathname = - Pathname.new(destination_root).join('config/initializers/solidus_paypal_braintree.rb') + Pathname.new(destination_root).join("config/initializers/solidus_paypal_braintree.rb") if legacy_initializer_pathname.exist? - legacy_initializer_pathname.rename('config/initializers/solidus_braintree.rb') + legacy_initializer_pathname.rename("config/initializers/solidus_braintree.rb") - gsub_file 'config/initializers/solidus_braintree.rb', + gsub_file "config/initializers/solidus_braintree.rb", "SolidusPaypalBraintree.configure do |config|\n", "SolidusBraintree.configure do |config|\n" else - directory 'config/initializers', 'config/initializers' + directory "config/initializers", "config/initializers" end end def run_migrations - rake 'railties:install:migrations FROM=solidus_braintree' - run 'bin/rails db:migrate' if options[:migrate] + rake "railties:install:migrations FROM=solidus_braintree" + run "bin/rails db:migrate" if options[:migrate] end def mount_engine - gsub_file 'config/routes.rb', - "mount SolidusPaypalBraintree::Engine, at: '/solidus_paypal_braintree'\n", '' + gsub_file "config/routes.rb", + "mount SolidusPaypalBraintree::Engine, at: '/solidus_paypal_braintree'\n", "" route "mount SolidusBraintree::Engine, at: '#{solidus_mount_point}solidus_braintree'" end def install_solidus_backend_support support_code_for(:backend) do - gsub_file 'vendor/assets/javascripts/spree/backend/all.js', - "//= require spree/backend/solidus_paypal_braintree\n", '' + gsub_file "vendor/assets/javascripts/spree/backend/all.js", + "//= require spree/backend/solidus_paypal_braintree\n", "" - append_file 'vendor/assets/javascripts/spree/backend/all.js', + append_file "vendor/assets/javascripts/spree/backend/all.js", "//= require spree/backend/solidus_braintree\n" - gsub_file 'vendor/assets/stylesheets/spree/backend/all.css', - " *= require spree/backend/solidus_paypal_braintree\n", '' + gsub_file "vendor/assets/stylesheets/spree/backend/all.css", + " *= require spree/backend/solidus_paypal_braintree\n", "" - inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', + inject_into_file "vendor/assets/stylesheets/spree/backend/all.css", " *= require spree/backend/solidus_braintree\n", before: %r{\*/}, verbose: true end end def install_solidus_starter_frontend_support support_code_for(:starter_frontend) do - directory 'app', 'app' + directory "app", "app" - inject_into_file 'vendor/assets/javascripts/spree/frontend/all.js', + inject_into_file "vendor/assets/javascripts/spree/frontend/all.js", "//= require jquery3\n", - before: '//= require rails-ujs', + before: "//= require rails-ujs", verbose: true - gsub_file 'vendor/assets/javascripts/spree/frontend/all.js', - "//= require spree/frontend/solidus_paypal_braintree\n", '' + gsub_file "vendor/assets/javascripts/spree/frontend/all.js", + "//= require spree/frontend/solidus_paypal_braintree\n", "" - append_file 'app/assets/javascripts/solidus_starter_frontend.js', + append_file "app/assets/javascripts/solidus_starter_frontend.js", "//= require spree/frontend/solidus_braintree\n" - gsub_file 'vendor/assets/stylesheets/spree/frontend/all.css', - " *= require spree/frontend/solidus_paypal_braintree\n", '' + gsub_file "vendor/assets/stylesheets/spree/frontend/all.css", + " *= require spree/frontend/solidus_paypal_braintree\n", "" - inject_into_file 'app/assets/stylesheets/solidus_starter_frontend.css', + inject_into_file "app/assets/stylesheets/solidus_starter_frontend.css", " *= require spree/frontend/solidus_braintree\n", before: %r{\*/}, verbose: true - inject_into_class 'app/controllers/checkouts_controller.rb', - 'CheckoutsController', + inject_into_class "app/controllers/checkouts_controller.rb", + "CheckoutsController", " helper SolidusBraintree::BraintreeCheckoutHelper\n\n", verbose: true - inject_into_class 'app/controllers/carts_controller.rb', - 'CartsController', + inject_into_class "app/controllers/carts_controller.rb", + "CartsController", " helper SolidusBraintree::BraintreeCheckoutHelper\n\n", verbose: true - inject_into_file 'app/views/orders/_payment_info.html.erb', + inject_into_file "app/views/orders/_payment_info.html.erb", "
  • <%= render 'payments/braintree_payment_details', payment: payment %>
  • \n", after: "
  • <%= payment.payment_method.name %>
  • \n", verbose: true spec_paths = case options[:specs] - when 'all' then %w[spec] - when 'frontend' + when "all" then %w[spec] + when "frontend" %w[ spec/solidus_braintree_spec_helper.rb spec/system/frontend @@ -143,7 +143,7 @@ def alert_no_classic_frontend_support The new version of this extension only supports Solidus Starter Frontend. No frontend code has been copied to your application. TEXT - say_status :error, set_color(message.tr("\n", ' '), :red), :red + say_status :error, set_color(message.tr("\n", " "), :red), :red end end @@ -170,7 +170,7 @@ def engine def bundle_command(command, env = {}) # Make `bundle install` less verbose by skipping the "Using ..." messages - super(command, env.reverse_merge('BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES' => 'true')) + super(command, env.reverse_merge("BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES" => "true")) ensure Bundler.reset_paths! end diff --git a/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb b/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb index ac292f9b..161c3de7 100644 --- a/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +++ b/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb @@ -4,10 +4,10 @@ module SolidusBraintree class CheckoutsController < CheckoutsController PERMITTED_PAYMENT_PARAMS = [ :payment_method_id, - { source_attributes: [ + {source_attributes: [ :nonce, :payment_type - ] } + ]} ].freeze def update @@ -21,11 +21,11 @@ def update end def payment_params - params. - require(:order). - require(:payments_attributes). - first. - permit(PERMITTED_PAYMENT_PARAMS) + params + .require(:order) + .require(:payments_attributes) + .first + .permit(PERMITTED_PAYMENT_PARAMS) end end end diff --git a/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb b/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb index e0039a30..fb04c315 100644 --- a/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +++ b/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb @@ -10,10 +10,10 @@ class InvalidImportError < StandardError; end :paypal_funding_source, :phone, :email, - { address_attributes: [ + {address_attributes: [ :country_code, :country_name, :name, :city, :zip, :state_code, :address_line_1, :address_line_2, :first_name, :last_name - ] }, + ]}, :device_data ].freeze @@ -27,11 +27,11 @@ def create import.import!(import_state, restart_checkout: restart_checkout) format.html { redirect_to redirect_url(import) } - format.json { render json: { redirectUrl: redirect_url(import) } } + format.json { render json: {redirectUrl: redirect_url(import)} } else status = 422 format.html { import_error(import) } - format.json { render json: { errors: import.errors, status: status }, status: status } + format.json { render json: {errors: import.errors, status: status}, status: status } end end end @@ -39,12 +39,12 @@ def create private def import_state - params[:state] || 'confirm' + params[:state] || "confirm" end def import_error(import) raise InvalidImportError, - "Import invalid: #{import.errors.full_messages.join(', ')}" + "Import invalid: #{import.errors.full_messages.join(", ")}" end def redirect_url(import) @@ -58,7 +58,7 @@ def redirect_url(import) def transaction_params params.require(:transaction) .permit(PERMITTED_BRAINTREE_TRANSACTION_PARAMS) - .merge({ payment_method: payment_method }) + .merge({payment_method: payment_method}) end def payment_method diff --git a/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb b/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb index c480fa7f..9be84bf7 100644 --- a/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +++ b/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb @@ -20,7 +20,7 @@ def braintree_3ds_options_for(order) locality: bill_address.city, region: bill_address.state&.abbr, postalCode: bill_address.zipcode, - countryCodeAlpha2: bill_address.country&.iso, + countryCodeAlpha2: bill_address.country&.iso }, additionalInformation: { shippingGivenName: ship_address.firstname, @@ -32,7 +32,7 @@ def braintree_3ds_options_for(order) locality: ship_address.city, region: ship_address.state&.abbr, postalCode: ship_address.zipcode, - countryCodeAlpha2: ship_address.country&.iso, + countryCodeAlpha2: ship_address.country&.iso } } } @@ -47,12 +47,12 @@ def venmo_button_style(store) color = configuration.preferred_venmo_button_color width = configuration.preferred_venmo_button_width - { width: width, color: color } + {width: width, color: color} end def venmo_button_asset_url(style, active: false) - prefix = 'solidus_braintree/venmo/venmo_' - active_string = active ? 'active_' : '' + prefix = "solidus_braintree/venmo/venmo_" + active_string = active ? "active_" : "" path = "#{prefix}#{active_string}#{style[:color]}_button_#{style[:width]}x48.svg" asset_path(path) end diff --git a/lib/solidus_braintree.rb b/lib/solidus_braintree.rb index 0d930c56..57d181b3 100644 --- a/lib/solidus_braintree.rb +++ b/lib/solidus_braintree.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'solidus_core' -require 'solidus_support' -require 'braintree' +require "solidus_core" +require "solidus_support" +require "braintree" -require 'solidus_braintree/country_mapper' -require 'solidus_braintree/request_protection' -require 'solidus_braintree/extension_configuration' -require 'solidus_braintree/version' -require 'solidus_braintree/engine' +require "solidus_braintree/country_mapper" +require "solidus_braintree/request_protection" +require "solidus_braintree/extension_configuration" +require "solidus_braintree/version" +require "solidus_braintree/engine" module SolidusBraintree end diff --git a/lib/solidus_braintree/engine.rb b/lib/solidus_braintree/engine.rb index a64ecd53..b04c4f11 100644 --- a/lib/solidus_braintree/engine.rb +++ b/lib/solidus_braintree/engine.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -require 'solidus_core' -require 'solidus_support' +require "solidus_core" +require "solidus_support" module SolidusBraintree class Engine < Rails::Engine include SolidusSupport::EngineExtensions isolate_namespace SolidusBraintree - engine_name 'solidus_braintree' + engine_name "solidus_braintree" ActiveSupport::Inflector.inflections do |inflect| - inflect.acronym 'AVS' + inflect.acronym "AVS" end initializer "register_solidus_braintree_gateway", after: "spree.register.payment_methods" do |app| @@ -25,15 +25,15 @@ class Engine < Rails::Engine end end - initializer 'add_solidus_braintree_response_to_log_entry_permitted_classes' do + initializer "add_solidus_braintree_response_to_log_entry_permitted_classes" do Spree.config do |config| - config.log_entry_permitted_classes << 'SolidusBraintree::Response' + config.log_entry_permitted_classes << "SolidusBraintree::Response" end end config.assets.precompile += [ - 'spree/frontend/solidus_braintree/checkout.js', - 'solidus_braintree_manifest.js' + "spree/frontend/solidus_braintree/checkout.js", + "solidus_braintree_manifest.js" ] paths["app/controllers"] << "lib/controllers/frontend" paths["app/views"] << "lib/views/frontend" @@ -44,11 +44,11 @@ class Engine < Rails::Engine # We support Solidus v1.2, which requires some different markup in the # source form partial. This will take precedence over lib/views/backend. - paths["app/views"] << "lib/views/backend_v1.2" if Spree.solidus_gem_version < Gem::Version.new('1.3') + paths["app/views"] << "lib/views/backend_v1.2" if Spree.solidus_gem_version < Gem::Version.new("1.3") # Solidus v2.4 introduced preference field partials but does not ship a hash field type. # This is solved in Solidus v2.5. - if Spree.solidus_gem_version <= Gem::Version.new('2.5.0') + if Spree.solidus_gem_version <= Gem::Version.new("2.5.0") paths["app/views"] << "lib/views/backend_v2.4" end @@ -57,18 +57,18 @@ class Engine < Rails::Engine initializer "solidus_braintree_admin_menu_item", after: "register_solidus_braintree_gateway" do Spree::Backend::Config.configure do |config| config.menu_items << - if Spree.solidus_gem_version >= Gem::Version.new('4.2') + if Spree.solidus_gem_version >= Gem::Version.new("4.2") config.class::MenuItem.new( label: :braintree, - icon: 'cc-paypal', - url: '/solidus_braintree/configurations/list', + icon: "cc-paypal", + url: "/solidus_braintree/configurations/list", condition: -> { can?(:list, SolidusBraintree::Configuration) } ) else config.class::MenuItem.new( [:braintree], - 'cc-paypal', - url: '/solidus_braintree/configurations/list', + "cc-paypal", + url: "/solidus_braintree/configurations/list", condition: -> { can?(:list, SolidusBraintree::Configuration) } ) end diff --git a/lib/solidus_braintree/extension_configuration.rb b/lib/solidus_braintree/extension_configuration.rb index b4c56098..61aff8bf 100644 --- a/lib/solidus_braintree/extension_configuration.rb +++ b/lib/solidus_braintree/extension_configuration.rb @@ -14,7 +14,7 @@ def configuration @configuration ||= ExtensionConfiguration.new end - alias config configuration + alias_method :config, :configuration def configure yield configuration diff --git a/lib/solidus_braintree/request_protection.rb b/lib/solidus_braintree/request_protection.rb index 135e6a90..d1db4b06 100644 --- a/lib/solidus_braintree/request_protection.rb +++ b/lib/solidus_braintree/request_protection.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'active_merchant/network_connection_retries' +require "active_merchant/network_connection_retries" module SolidusBraintree module RequestProtection @@ -11,7 +11,7 @@ def protected_request(&block) options = { connection_exceptions: { - Braintree::BraintreeError => 'Error while connecting to Braintree gateway' + Braintree::BraintreeError => "Error while connecting to Braintree gateway" }, logger: Rails.logger } diff --git a/lib/solidus_braintree/version.rb b/lib/solidus_braintree/version.rb index cd503759..df97e013 100644 --- a/lib/solidus_braintree/version.rb +++ b/lib/solidus_braintree/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SolidusBraintree - VERSION = '3.3.0' + VERSION = "3.3.0" end diff --git a/lib/solidus_paypal_braintree.rb b/lib/solidus_paypal_braintree.rb index 57d5aee8..a943c969 100644 --- a/lib/solidus_paypal_braintree.rb +++ b/lib/solidus_paypal_braintree.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'solidus_braintree' +require "solidus_braintree" SolidusPaypalBraintree = - ActiveSupport::Deprecation::DeprecatedConstantProxy.new('SolidusPaypalBraintree', 'SolidusBraintree') + ActiveSupport::Deprecation::DeprecatedConstantProxy.new("SolidusPaypalBraintree", "SolidusBraintree") diff --git a/solidus_braintree.gemspec b/solidus_braintree.gemspec index 1aca7154..ce498a39 100644 --- a/solidus_braintree.gemspec +++ b/solidus_braintree.gemspec @@ -1,41 +1,40 @@ # frozen_string_literal: true -require_relative 'lib/solidus_braintree/version' +require_relative "lib/solidus_braintree/version" Gem::Specification.new do |spec| - spec.name = 'solidus_braintree' + spec.name = "solidus_braintree" spec.version = SolidusBraintree::VERSION - spec.authors = ['Stembolt'] - spec.email = 'braintree+gemfile@stembolt.com' + spec.authors = ["Stembolt"] + spec.email = "braintree+gemfile@stembolt.com" - spec.summary = 'Officially supported Braintree extension' - spec.description = 'Uses the javascript API for seamless braintree payments' - spec.homepage = 'https://github.com/solidusio/solidus_braintree' - spec.license = 'BSD-3-Clause' + spec.summary = "Officially supported Braintree extension" + spec.description = "Uses the javascript API for seamless braintree payments" + spec.homepage = "https://github.com/solidusio/solidus_braintree" + spec.license = "BSD-3-Clause" - spec.metadata['homepage_uri'] = spec.homepage - spec.metadata['source_code_uri'] = 'https://github.com/solidusio/solidus_braintree' - spec.metadata['changelog_uri'] = 'https://github.com/solidusio/solidus_braintree/releases' + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/solidusio/solidus_braintree" + spec.metadata["changelog_uri"] = "https://github.com/solidusio/solidus_braintree/releases" - spec.required_ruby_version = Gem::Requirement.new('>= 3.0', '< 4') + spec.required_ruby_version = Gem::Requirement.new(">= 3.0", "< 4") # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") } spec.files = files.grep_v(%r{^(test|spec|features)/}) - spec.test_files = files.grep(%r{^(test|spec|features)/}) spec.bindir = "exe" spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency 'activemerchant', '~> 1.48' - spec.add_dependency 'braintree', '~> 4.2' - spec.add_dependency 'solidus_api', ['>= 3.4.0.dev', '< 5'] - spec.add_dependency 'solidus_backend', ['>= 3.4.0.dev', '< 5'] - spec.add_dependency 'solidus_core', ['>= 3.4.0.dev', '< 5'] - spec.add_dependency 'solidus_support', ['>= 0.8.1', '< 1'] + spec.add_dependency "activemerchant", "~> 1.48" + spec.add_dependency "braintree", "~> 4.2" + spec.add_dependency "solidus_api", [">= 3.4.0.dev", "< 5"] + spec.add_dependency "solidus_backend", [">= 3.4.0.dev", "< 5"] + spec.add_dependency "solidus_core", [">= 3.4.0.dev", "< 5"] + spec.add_dependency "solidus_support", [">= 0.8.1", "< 1"] - spec.add_development_dependency 'rails-controller-testing' - spec.add_development_dependency 'solidus_dev_support', '~> 2.5' + spec.add_development_dependency "rails-controller-testing" + spec.add_development_dependency "solidus_dev_support", "~> 2.5" end diff --git a/spec/controllers/solidus_braintree/checkouts_controller_spec.rb b/spec/controllers/solidus_braintree/checkouts_controller_spec.rb index abbaade4..a3b6b318 100644 --- a/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +++ b/spec/controllers/solidus_braintree/checkouts_controller_spec.rb @@ -1,12 +1,12 @@ -require 'solidus_braintree_spec_helper' -require 'support/solidus_braintree/order_ready_for_payment' +require "solidus_braintree_spec_helper" +require "support/solidus_braintree/order_ready_for_payment" RSpec.describe SolidusBraintree::CheckoutsController, type: :controller do routes { SolidusBraintree::Engine.routes } - include_context 'when order is ready for payment' + include_context "when order is ready for payment" - describe 'PATCH update' do + describe "PATCH update" do subject(:patch_update) { patch :update, params: params } let(:params) do @@ -42,24 +42,24 @@ end context "when a payment is created successfully", vcr: { - cassette_name: 'checkout/update', + cassette_name: "checkout/update", match_requests_on: [:braintree_uri] } do - it 'creates a payment' do - expect { patch_update }. - to change { order.payments.count }. - from(0). - to(1) + it "creates a payment" do + expect { patch_update } + .to change { order.payments.count } + .from(0) + .to(1) end - it 'creates a payment source' do - expect { patch_update }. - to change(SolidusBraintree::Source, :count). - from(0). - to(1) + it "creates a payment source" do + expect { patch_update } + .to change(SolidusBraintree::Source, :count) + .from(0) + .to(1) end - it 'assigns @order' do + it "assigns @order" do patch_update expect(assigns(:order)).to eq order end @@ -84,15 +84,15 @@ end it "renders 'not-ok'" do - expect(patch_update.body).to eq('not-ok') + expect(patch_update.body).to eq("not-ok") end it "does not change the number of payments in the system" do - expect{ patch_update }.not_to(change(::Spree::Payment, :count)) + expect { patch_update }.not_to(change(::Spree::Payment, :count)) end it "does not change the number of sources in the system" do - expect{ patch_update }.not_to(change(SolidusBraintree::Source, :count)) + expect { patch_update }.not_to(change(SolidusBraintree::Source, :count)) end end end diff --git a/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb b/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb index 541eda5f..4e8969c9 100644 --- a/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +++ b/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb @@ -1,9 +1,9 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::ClientTokensController do routes { SolidusBraintree::Engine.routes } - cassette_options = { cassette_name: "braintree/token" } + cassette_options = {cassette_name: "braintree/token"} describe "POST create", vcr: cassette_options do let!(:gateway) { create_gateway } let(:user) { create(:user) } @@ -11,24 +11,24 @@ before { user.generate_spree_api_key! } - context 'without a payment method id' do + context "without a payment method id" do subject(:response) do - post :create, params: { token: user.spree_api_key } + post :create, params: {token: user.spree_api_key} end it "returns a client token", aggregate_failures: true do expect(response).to have_http_status(:success) - expect(response.content_type).to include 'application/json' + expect(response.content_type).to include "application/json" expect(json["client_token"]).to be_present expect(json["client_token"]).to be_a String expect(json["payment_method_id"]).to eq gateway.id end context "when there's two gateway's for different stores" do - let!(:store1) { create(:store, code: 'store_1') } - let!(:store2) { create(:store, code: 'store_2') } - let!(:gateway_for_store1) { create_gateway.tap{ |gw| store1.payment_methods << gw } } - let!(:gateway_for_store2) { create_gateway.tap{ |gw| store2.payment_methods << gw } } + let!(:store1) { create(:store, code: "store_1") } + let!(:store2) { create(:store, code: "store_2") } + let!(:gateway_for_store1) { create_gateway.tap { |gw| store1.payment_methods << gw } } + let!(:gateway_for_store2) { create_gateway.tap { |gw| store2.payment_methods << gw } } it "returns the correct gateway for store1" do allow_any_instance_of(described_class).to receive(:current_store).and_return store1 @@ -42,12 +42,12 @@ end end - context 'with a payment method id' do + context "with a payment method id" do subject(:response) do - post :create, params: { token: user.spree_api_key, payment_method_id: gateway.id } + post :create, params: {token: user.spree_api_key, payment_method_id: gateway.id} end - it 'uses the selected gateway' do + it "uses the selected gateway" do expect(json["payment_method_id"]).to eq gateway.id end end diff --git a/spec/controllers/solidus_braintree/configurations_controller_spec.rb b/spec/controllers/solidus_braintree/configurations_controller_spec.rb index 4c7d17e7..cf224f88 100644 --- a/spec/controllers/solidus_braintree/configurations_controller_spec.rb +++ b/spec/controllers/solidus_braintree/configurations_controller_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::ConfigurationsController, type: :controller do routes { SolidusBraintree::Engine.routes } @@ -13,8 +13,8 @@ it "assigns all store's configurations as @configurations" do subject - expect(assigns(:configurations)). - to eq [store_1.braintree_configuration, store_2.braintree_configuration] + expect(assigns(:configurations)) + .to eq [store_1.braintree_configuration, store_2.braintree_configuration] end it "renders the correct view" do @@ -25,12 +25,12 @@ describe "POST #update" do subject { post :update, params: configurations_params } - let(:paypal_button_color) { 'blue' } + let(:paypal_button_color) { "blue" } let(:configurations_params) do { configurations: { configuration_fields: { - store_1.braintree_configuration.id.to_s => { paypal: true, apple_pay: true }, + store_1.braintree_configuration.id.to_s => {paypal: true, apple_pay: true}, store_2.braintree_configuration.id.to_s => { paypal: true, apple_pay: false, @@ -43,8 +43,8 @@ context "with valid parameters" do it "updates the configuration" do - expect { subject }.to change { store_1.braintree_configuration.reload.paypal }. - from(false).to(true) + expect { subject }.to change { store_1.braintree_configuration.reload.paypal } + .from(false).to(true) end it "displays a success message to the user" do @@ -58,7 +58,7 @@ end context "with invalid parameters" do - let(:paypal_button_color) { 'invalid-color' } + let(:paypal_button_color) { "invalid-color" } it "displays an error message to the user" do subject diff --git a/spec/controllers/solidus_braintree/transactions_controller_spec.rb b/spec/controllers/solidus_braintree/transactions_controller_spec.rb index 54d3ce31..63e35f53 100644 --- a/spec/controllers/solidus_braintree/transactions_controller_spec.rb +++ b/spec/controllers/solidus_braintree/transactions_controller_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::TransactionsController, type: :controller do routes { SolidusBraintree::Engine.routes } @@ -8,7 +8,7 @@ let(:order) do Spree::Order.create!( line_items: [line_item], - email: 'test@example.com', + email: "test@example.com", bill_address: create(:address, country: country), ship_address: create(:address, country: country), user: create(:user) @@ -31,7 +31,7 @@ describe "POST create", vcr: cassette_options do subject(:post_create) { post :create, params: params } - let!(:country) { create :country, iso: 'US' } + let!(:country) { create :country, iso: "US" } let(:params) do { @@ -71,7 +71,7 @@ end context "when the transaction is valid", vcr: { - cassette_name: 'transaction/import/valid', + cassette_name: "transaction/import/valid", match_requests_on: [:braintree_uri] } do it "imports the payment" do @@ -87,7 +87,7 @@ end context "when end state provided is delivery" do - let(:params) { super().merge(state: 'delivery') } + let(:params) { super().merge(state: "delivery") } it "advances the order to delivery" do post_create @@ -130,7 +130,7 @@ context "when format is HTML" do context "when import! leaves the order in confirm" do it "redirects the user to the confirm page" do - expect(post_create).to redirect_to '/checkout/confirm' + expect(post_create).to redirect_to "/checkout/confirm" end end diff --git a/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb b/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb index fb78f994..5ad75480 100644 --- a/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +++ b/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb @@ -1,16 +1,16 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::BraintreeAdminHelper do - describe '#braintree_transaction_link' do + describe "#braintree_transaction_link" do subject { helper.braintree_transaction_link(payment) } let(:payment_method) { create_gateway } let(:payment) do - instance_double(Spree::Payment, payment_method: payment_method, response_code: 'abcde') + instance_double(Spree::Payment, payment_method: payment_method, response_code: "abcde") end let(:merchant_id) { payment_method.preferences[:merchant_id] } - it 'generates a link to Braintree admin' do + it "generates a link to Braintree admin" do expect(subject).to eq "abcde" # rubocop:disable Layout/LineLength end end diff --git a/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb b/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb index c76a5cdd..32e1b5c9 100644 --- a/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +++ b/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::BraintreeCheckoutHelper do let!(:store) { create :store } @@ -8,62 +8,62 @@ store.braintree_configuration.update(braintree_configuration) end - describe '#venmo_button_style' do + describe "#venmo_button_style" do subject { helper.venmo_button_style(store) } - context 'when the venmo button is white and has a width of 280' do - let(:braintree_configuration) { { preferred_venmo_button_width: '280', preferred_venmo_button_color: 'white' } } + context "when the venmo button is white and has a width of 280" do + let(:braintree_configuration) { {preferred_venmo_button_width: "280", preferred_venmo_button_color: "white"} } - it 'returns a hash of the width and color' do - expect(subject).to eq({ width: '280', color: 'white' }) + it "returns a hash of the width and color" do + expect(subject).to eq({width: "280", color: "white"}) end end - context 'when the venmo button is blue and has a width of 375' do - let(:braintree_configuration) { { preferred_venmo_button_width: '375', preferred_venmo_button_color: 'blue' } } + context "when the venmo button is blue and has a width of 375" do + let(:braintree_configuration) { {preferred_venmo_button_width: "375", preferred_venmo_button_color: "blue"} } - it 'returns a hash of the width and color' do - expect(subject).to eq({ width: '375', color: 'blue' }) + it "returns a hash of the width and color" do + expect(subject).to eq({width: "375", color: "blue"}) end end end - describe '#venmo_button_width' do + describe "#venmo_button_width" do subject { helper.venmo_button_asset_url(style, active: active) } - context 'when the given style color is white and width is 280, and the given active is false' do - let(:style) { { width: '280', color: 'white' } } + context "when the given style color is white and width is 280, and the given active is false" do + let(:style) { {width: "280", color: "white"} } let(:active) { false } - it 'returns the correct url' do - expect(subject).to match(%r[\A/assets/solidus_braintree/venmo/venmo_white_button_280x48-.+\.svg]) + it "returns the correct url" do + expect(subject).to match(%r{\A/assets/solidus_braintree/venmo/venmo_white_button_280x48-.+\.svg}) end end - context 'when the given style color is white and width is 280, and the given active is true' do - let(:style) { { width: '280', color: 'white' } } + context "when the given style color is white and width is 280, and the given active is true" do + let(:style) { {width: "280", color: "white"} } let(:active) { true } - it 'returns the correct url' do - expect(subject).to match(%r[\A/assets/solidus_braintree/venmo/venmo_active_white_button_280x48-.+\.svg]) + it "returns the correct url" do + expect(subject).to match(%r{\A/assets/solidus_braintree/venmo/venmo_active_white_button_280x48-.+\.svg}) end end - context 'when the given style color is blue and width is 320, and the given active is false' do - let(:style) { { width: '320', color: 'blue' } } + context "when the given style color is blue and width is 320, and the given active is false" do + let(:style) { {width: "320", color: "blue"} } let(:active) { false } - it 'returns the correct url' do - expect(subject).to match(%r[\A/assets/solidus_braintree/venmo/venmo_blue_button_320x48-.+\.svg]) + it "returns the correct url" do + expect(subject).to match(%r{\A/assets/solidus_braintree/venmo/venmo_blue_button_320x48-.+\.svg}) end end - context 'when the given style color is blue and width is 320, and the given active is true' do - let(:style) { { width: '320', color: 'blue' } } + context "when the given style color is blue and width is 320, and the given active is true" do + let(:style) { {width: "320", color: "blue"} } let(:active) { true } - it 'returns the correct url' do - expect(subject).to match(%r[\A/assets/solidus_braintree/venmo/venmo_active_blue_button_320x48-.+\.svg]) + it "returns the correct url" do + expect(subject).to match(%r{\A/assets/solidus_braintree/venmo/venmo_active_blue_button_320x48-.+\.svg}) end end end diff --git a/spec/models/solidus_braintree/address_spec.rb b/spec/models/solidus_braintree/address_spec.rb index e4d10d60..88cde5cb 100644 --- a/spec/models/solidus_braintree/address_spec.rb +++ b/spec/models/solidus_braintree/address_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::Address do describe "::split_name" do @@ -21,50 +21,50 @@ end end - describe '#to_json' do + describe "#to_json" do subject(:address_json) { JSON.parse(described_class.new(spree_address).to_json) } - let(:german_address) { create(:address, country_iso: 'DE', state: nil) } # Does not require states - let(:us_address) { create(:address, country_iso: 'US') } # Requires states + let(:german_address) { create(:address, country_iso: "DE", state: nil) } # Does not require states + let(:us_address) { create(:address, country_iso: "US") } # Requires states let(:spree_address) { us_address } before do - create(:country, iso: 'DE', states_required: false) - create(:country, iso: 'US', states_required: true) + create(:country, iso: "DE", states_required: false) + create(:country, iso: "US", states_required: true) end - it 'has all the required keys' do + it "has all the required keys" do expect(address_json.keys).to contain_exactly( - 'line1', - 'line2', - 'city', - 'postalCode', - 'countryCode', - 'recipientName', - 'state', - 'phone' + "line1", + "line2", + "city", + "postalCode", + "countryCode", + "recipientName", + "state", + "phone" ) end - context 'with a country that does not require state' do + context "with a country that does not require state" do let(:spree_address) { german_address } - it { is_expected.not_to have_key('state') } + it { is_expected.not_to have_key("state") } end - context 'with states turned off globally' do + context "with states turned off globally" do before do allow(::Spree::Config).to receive(:address_requires_state).and_return(false) end - context 'with a country that requires states' do - it { is_expected.not_to have_key('state') } + context "with a country that requires states" do + it { is_expected.not_to have_key("state") } end - context 'with a country that does not require state' do + context "with a country that does not require state" do let(:spree_address) { german_address } - it { is_expected.not_to have_key('state') } + it { is_expected.not_to have_key("state") } end end end diff --git a/spec/models/solidus_braintree/avs_result_spec.rb b/spec/models/solidus_braintree/avs_result_spec.rb index 14e8b288..b803a047 100644 --- a/spec/models/solidus_braintree/avs_result_spec.rb +++ b/spec/models/solidus_braintree/avs_result_spec.rb @@ -1,10 +1,10 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::AVSResult do - describe 'AVS response message' do - subject { described_class.build(transaction).to_hash['message'] } + describe "AVS response message" do + subject { described_class.build(transaction).to_hash["message"] } - context 'with avs_error_response_code' do + context "with avs_error_response_code" do let(:transaction) do instance_double(Braintree::Transaction, avs_error_response_code: error_code, @@ -12,20 +12,20 @@ avs_postal_code_response_code: nil) end - context 'when error code is S' do - let(:error_code) { 'S' } + context "when error code is S" do + let(:error_code) { "S" } - it { is_expected.to eq 'U.S.-issuing bank does not support AVS.' } + it { is_expected.to eq "U.S.-issuing bank does not support AVS." } end - context 'when error code is E' do - let(:error_code) { 'E' } + context "when error code is E" do + let(:error_code) { "E" } - it { is_expected.to eq 'AVS data is invalid or AVS is not allowed for this card type.' } + it { is_expected.to eq "AVS data is invalid or AVS is not allowed for this card type." } end end - context 'without avs_error_response_code' do + context "without avs_error_response_code" do let(:transaction) do instance_double(Braintree::Transaction, avs_error_response_code: nil, @@ -33,283 +33,283 @@ avs_postal_code_response_code: codes.last) end - context 'when street address result is M and postal code result is N' do - let(:codes) { %w(M N) } + context "when street address result is M and postal code result is N" do + let(:codes) { %w[M N] } - it { is_expected.to eq 'Street address matches, but postal code does not match.' } + it { is_expected.to eq "Street address matches, but postal code does not match." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'M', 'postal_match' => 'N') + expect(described_class.build(transaction).to_hash).to include("street_match" => "M", "postal_match" => "N") } end - context 'when street address result is M and postal code result is U' do - let(:codes) { %w(M U) } + context "when street address result is M and postal code result is U" do + let(:codes) { %w[M U] } - it { is_expected.to eq 'Street address matches, but postal code not verified.' } + it { is_expected.to eq "Street address matches, but postal code not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'M', 'postal_match' => 'U') + expect(described_class.build(transaction).to_hash).to include("street_match" => "M", "postal_match" => "U") } end - context 'when street address result is M and postal code result is I' do - let(:codes) { %w(M I) } + context "when street address result is M and postal code result is I" do + let(:codes) { %w[M I] } - it { is_expected.to eq 'Street address matches, but postal code not verified.' } + it { is_expected.to eq "Street address matches, but postal code not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'M', 'postal_match' => 'I') + expect(described_class.build(transaction).to_hash).to include("street_match" => "M", "postal_match" => "I") } end - context 'when street address result is M and postal code result is A' do - let(:codes) { %w(M A) } + context "when street address result is M and postal code result is A" do + let(:codes) { %w[M A] } - it { is_expected.to eq 'Street address matches, but postal code not verified.' } + it { is_expected.to eq "Street address matches, but postal code not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'M', 'postal_match' => 'A') + expect(described_class.build(transaction).to_hash).to include("street_match" => "M", "postal_match" => "A") } end - context 'when street address result is N and postal code result is N' do - let(:codes) { %w(N N) } + context "when street address result is N and postal code result is N" do + let(:codes) { %w[N N] } - it { is_expected.to eq 'Street address and postal code do not match.' } + it { is_expected.to eq "Street address and postal code do not match." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'N', 'postal_match' => 'N') + expect(described_class.build(transaction).to_hash).to include("street_match" => "N", "postal_match" => "N") } end - context 'when street address result is N and postal code result is U' do - let(:codes) { %w(N U) } + context "when street address result is N and postal code result is U" do + let(:codes) { %w[N U] } - it { is_expected.to eq 'Street address and postal code do not match.' } + it { is_expected.to eq "Street address and postal code do not match." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'N', 'postal_match' => 'U') + expect(described_class.build(transaction).to_hash).to include("street_match" => "N", "postal_match" => "U") } end - context 'when street address result is N and postal code result is I' do - let(:codes) { %w(N I) } + context "when street address result is N and postal code result is I" do + let(:codes) { %w[N I] } - it { is_expected.to eq 'Street address and postal code do not match.' } + it { is_expected.to eq "Street address and postal code do not match." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'N', 'postal_match' => 'I') + expect(described_class.build(transaction).to_hash).to include("street_match" => "N", "postal_match" => "I") } end - context 'when street address result is N and postal code result is A' do - let(:codes) { %w(N A) } + context "when street address result is N and postal code result is A" do + let(:codes) { %w[N A] } - it { is_expected.to eq 'Street address and postal code do not match.' } + it { is_expected.to eq "Street address and postal code do not match." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'N', 'postal_match' => 'A') + expect(described_class.build(transaction).to_hash).to include("street_match" => "N", "postal_match" => "A") } end - context 'when street address result is I and postal code result is N' do - let(:codes) { %w(I N) } + context "when street address result is I and postal code result is N" do + let(:codes) { %w[I N] } - it { is_expected.to eq 'Street address and postal code do not match.' } + it { is_expected.to eq "Street address and postal code do not match." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'I', 'postal_match' => 'N') + expect(described_class.build(transaction).to_hash).to include("street_match" => "I", "postal_match" => "N") } end - context 'when street address result is A and postal code result is N' do - let(:codes) { %w(A N) } + context "when street address result is A and postal code result is N" do + let(:codes) { %w[A N] } - it { is_expected.to eq 'Street address and postal code do not match.' } + it { is_expected.to eq "Street address and postal code do not match." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'A', 'postal_match' => 'N') + expect(described_class.build(transaction).to_hash).to include("street_match" => "A", "postal_match" => "N") } end - context 'when street address result is U and postal code result is U' do - let(:codes) { %w(U U) } + context "when street address result is U and postal code result is U" do + let(:codes) { %w[U U] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'U', 'postal_match' => 'U') + expect(described_class.build(transaction).to_hash).to include("street_match" => "U", "postal_match" => "U") } end - context 'when street address result is U and postal code result is I' do - let(:codes) { %w(U I) } + context "when street address result is U and postal code result is I" do + let(:codes) { %w[U I] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'U', 'postal_match' => 'I') + expect(described_class.build(transaction).to_hash).to include("street_match" => "U", "postal_match" => "I") } end - context 'when street address result is U and postal code result is A' do - let(:codes) { %w(U A) } + context "when street address result is U and postal code result is A" do + let(:codes) { %w[U A] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'U', 'postal_match' => 'A') + expect(described_class.build(transaction).to_hash).to include("street_match" => "U", "postal_match" => "A") } end - context 'when street address result is I and postal code result is U' do - let(:codes) { %w(I U) } + context "when street address result is I and postal code result is U" do + let(:codes) { %w[I U] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'I', 'postal_match' => 'U') + expect(described_class.build(transaction).to_hash).to include("street_match" => "I", "postal_match" => "U") } end - context 'when street address result is I and postal code result is I' do - let(:codes) { %w(I I) } + context "when street address result is I and postal code result is I" do + let(:codes) { %w[I I] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'I', 'postal_match' => 'I') + expect(described_class.build(transaction).to_hash).to include("street_match" => "I", "postal_match" => "I") } end - context 'when street address result is I and postal code result is A' do - let(:codes) { %w(I A) } + context "when street address result is I and postal code result is A" do + let(:codes) { %w[I A] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'I', 'postal_match' => 'A') + expect(described_class.build(transaction).to_hash).to include("street_match" => "I", "postal_match" => "A") } end - context 'when street address result is A and postal code result is U' do - let(:codes) { %w(A U) } + context "when street address result is A and postal code result is U" do + let(:codes) { %w[A U] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'A', 'postal_match' => 'U') + expect(described_class.build(transaction).to_hash).to include("street_match" => "A", "postal_match" => "U") } end - context 'when street address result is A and postal code result is I' do - let(:codes) { %w(A I) } + context "when street address result is A and postal code result is I" do + let(:codes) { %w[A I] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'A', 'postal_match' => 'I') + expect(described_class.build(transaction).to_hash).to include("street_match" => "A", "postal_match" => "I") } end - context 'when street address result is A and postal code result is A' do - let(:codes) { %w(A A) } + context "when street address result is A and postal code result is A" do + let(:codes) { %w[A A] } - it { is_expected.to eq 'Address not verified.' } + it { is_expected.to eq "Address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'A', 'postal_match' => 'A') + expect(described_class.build(transaction).to_hash).to include("street_match" => "A", "postal_match" => "A") } end - context 'when street address result is M and postal code result is M' do - let(:codes) { %w(M M) } + context "when street address result is M and postal code result is M" do + let(:codes) { %w[M M] } - it { is_expected.to eq 'Street address and postal code match.' } + it { is_expected.to eq "Street address and postal code match." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'M', 'postal_match' => 'M') + expect(described_class.build(transaction).to_hash).to include("street_match" => "M", "postal_match" => "M") } end - context 'when street address result is U and postal code result is N' do - let(:codes) { %w(U N) } + context "when street address result is U and postal code result is N" do + let(:codes) { %w[U N] } it { is_expected.to eq "Street address and postal code do not match. For American Express: Card member's name, street address and postal code do not match." } # rubocop:disable Layout/LineLength it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'U', 'postal_match' => 'N') + expect(described_class.build(transaction).to_hash).to include("street_match" => "U", "postal_match" => "N") } end - context 'when street address result is U and postal code result is M' do - let(:codes) { %w(U M) } + context "when street address result is U and postal code result is M" do + let(:codes) { %w[U M] } - it { is_expected.to eq 'Postal code matches, but street address not verified.' } + it { is_expected.to eq "Postal code matches, but street address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'U', 'postal_match' => 'M') + expect(described_class.build(transaction).to_hash).to include("street_match" => "U", "postal_match" => "M") } end - context 'when street address result is I and postal code result is M' do - let(:codes) { %w(I M) } + context "when street address result is I and postal code result is M" do + let(:codes) { %w[I M] } - it { is_expected.to eq 'Postal code matches, but street address not verified.' } + it { is_expected.to eq "Postal code matches, but street address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'I', 'postal_match' => 'M') + expect(described_class.build(transaction).to_hash).to include("street_match" => "I", "postal_match" => "M") } end - context 'when street address result is A and postal code result is M' do - let(:codes) { %w(A M) } + context "when street address result is A and postal code result is M" do + let(:codes) { %w[A M] } - it { is_expected.to eq 'Postal code matches, but street address not verified.' } + it { is_expected.to eq "Postal code matches, but street address not verified." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'A', 'postal_match' => 'M') + expect(described_class.build(transaction).to_hash).to include("street_match" => "A", "postal_match" => "M") } end - context 'when street address result is N and postal code result is M' do - let(:codes) { %w(N M) } + context "when street address result is N and postal code result is M" do + let(:codes) { %w[N M] } - it { is_expected.to eq 'Street address does not match, but 5-digit postal code matches.' } + it { is_expected.to eq "Street address does not match, but 5-digit postal code matches." } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'N', 'postal_match' => 'M') + expect(described_class.build(transaction).to_hash).to include("street_match" => "N", "postal_match" => "M") } end - context 'when street address response code is nil' do - let(:codes) { [nil, 'M'] } + context "when street address response code is nil" do + let(:codes) { [nil, "M"] } it { is_expected.to be_nil } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => nil, 'postal_match' => 'M') + expect(described_class.build(transaction).to_hash).to include("street_match" => nil, "postal_match" => "M") } end - context 'when postal code response code is nil' do - let(:codes) { ['M', nil] } + context "when postal code response code is nil" do + let(:codes) { ["M", nil] } it { is_expected.to be_nil } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => 'M', 'postal_match' => nil) + expect(described_class.build(transaction).to_hash).to include("street_match" => "M", "postal_match" => nil) } end - context 'when postal code and street address response code is nil' do + context "when postal code and street address response code is nil" do let(:codes) { [nil, nil] } it { is_expected.to be_nil } it { - expect(described_class.build(transaction).to_hash).to include('street_match' => nil, 'postal_match' => nil) + expect(described_class.build(transaction).to_hash).to include("street_match" => nil, "postal_match" => nil) } end end diff --git a/spec/models/solidus_braintree/gateway_spec.rb b/spec/models/solidus_braintree/gateway_spec.rb index d648c24c..6acbd6f6 100644 --- a/spec/models/solidus_braintree/gateway_spec.rb +++ b/spec/models/solidus_braintree/gateway_spec.rb @@ -1,6 +1,6 @@ -require 'solidus_braintree_spec_helper' -require 'webmock' -require 'support/solidus_braintree/order_ready_for_payment' +require "solidus_braintree_spec_helper" +require "webmock" +require "support/solidus_braintree/order_ready_for_payment" RSpec.describe SolidusBraintree::Gateway do let(:gateway) do @@ -13,11 +13,11 @@ let(:source) do SolidusBraintree::Source.create!( - nonce: 'fake-valid-nonce', + nonce: "fake-valid-nonce", user: user, payment_type: payment_type, payment_method: gateway, - device_data: 'fake-device-data' + device_data: "fake-device-data" ) end @@ -36,27 +36,27 @@ it "successfully updates the preference" do subject - expect(gateway.preferred_merchant_currency_map).to eq({ "EUR" => "test_merchant_account_id" }) - expect(gateway.preferred_paypal_payee_email_map).to eq({ "CAD" => "bruce+wayne@example.com" }) + expect(gateway.preferred_merchant_currency_map).to eq({"EUR" => "test_merchant_account_id"}) + expect(gateway.preferred_paypal_payee_email_map).to eq({"CAD" => "bruce+wayne@example.com"}) end end context "with invalid user input" do let(:update_params) do - { preferred_merchant_currency_map: '{this_is_not_a_valid_hash}' } + {preferred_merchant_currency_map: "{this_is_not_a_valid_hash}"} end it "raise a JSON parser error" do - expect{ subject }.to raise_error(JSON::ParserError) + expect { subject }.to raise_error(JSON::ParserError) end end end - describe 'making a payment on an order', vcr: { - cassette_name: 'gateway/complete', + describe "making a payment on an order", vcr: { + cassette_name: "gateway/complete", match_requests_on: [:braintree_uri] } do - include_context 'when order is ready for payment' + include_context "when order is ready for payment" before do order.update(number: "ORDER0") @@ -71,7 +71,7 @@ ) end - it 'can complete an order' do + it "can complete an order" do order.payments.reset expect(order.total).to eq 55 @@ -92,15 +92,15 @@ describe "instance methods" do shared_examples "successful response" do - it 'returns a successful billing response', aggregate_failures: true do + it "returns a successful billing response", aggregate_failures: true do expect(subject).to be_a ActiveMerchant::Billing::Response expect(subject).to be_success end end shared_examples "protects against connection errors" do - context 'when a timeout error happens' do - it 'raises ActiveMerchant::ConnectionError' do + context "when a timeout error happens" do + it "raises ActiveMerchant::ConnectionError" do expect_any_instance_of(Braintree::TransactionGateway).to receive(gateway_action) do raise Braintree::BraintreeError end @@ -131,7 +131,7 @@ braintree.testing.settle(sale_id).transaction.id end - let(:currency) { 'USD' } + let(:currency) { "USD" } let(:gateway_options) do { @@ -163,31 +163,31 @@ it { is_expected.to eq "braintree" } end - describe '#gateway_options' do + describe "#gateway_options" do subject(:gateway_options) { gateway.gateway_options } - it 'includes http_open_timeout' do + it "includes http_open_timeout" do expect(subject).to have_key(:http_open_timeout) expect(gateway_options[:http_open_timeout]).to eq(60) end - it 'includes http_read_timeout' do + it "includes http_read_timeout" do expect(subject).to have_key(:http_read_timeout) expect(gateway_options[:http_read_timeout]).to eq(60) end end - describe '#purchase' do + describe "#purchase" do subject(:purchase) { gateway.purchase(1000, source, gateway_options) } - context 'with successful purchase', vcr: { - cassette_name: 'gateway/purchase', + context "with successful purchase", vcr: { + cassette_name: "gateway/purchase", match_requests_on: [:braintree_uri] } do include_examples "successful response" - it 'submits the transaction for settlement', aggregate_failures: true do - expect(purchase.message).to eq 'submitted_for_settlement' + it "submits the transaction for settlement", aggregate_failures: true do + expect(purchase.message).to eq "submitted_for_settlement" expect(purchase.authorization).to be_present end end @@ -204,37 +204,37 @@ let(:gateway_action) { :sale } end - context 'with successful authorization', vcr: { - cassette_name: 'gateway/authorize', + context "with successful authorization", vcr: { + cassette_name: "gateway/authorize", match_requests_on: [:braintree_uri] } do include_examples "successful response" it 'passes "Solidus" as the channel parameter in the request' do - expect_any_instance_of(Braintree::TransactionGateway). - to receive(:sale). - with(hash_including({ channel: "Solidus" })).and_call_original + expect_any_instance_of(Braintree::TransactionGateway) + .to receive(:sale) + .with(hash_including({channel: "Solidus"})).and_call_original authorize end - it 'authorizes the transaction', aggregate_failures: true do - expect(authorize.message).to eq 'authorized' + it "authorizes the transaction", aggregate_failures: true do + expect(authorize.message).to eq "authorized" expect(authorize.authorization).to be_present end - context 'with available device data' do - it 'passes the device data as a parameter in the request' do - expect_any_instance_of(Braintree::TransactionGateway). - to receive(:sale). - with(hash_including({ device_data: "fake-device-data" })).and_call_original + context "with available device data" do + it "passes the device data as a parameter in the request" do + expect_any_instance_of(Braintree::TransactionGateway) + .to receive(:sale) + .with(hash_including({device_data: "fake-device-data"})).and_call_original authorize end end - context 'without device_data' do + context "without device_data" do let(:source) do SolidusBraintree::Source.create!( - nonce: 'fake-valid-nonce', + nonce: "fake-valid-nonce", user: user, payment_type: payment_type, payment_method: gateway @@ -245,41 +245,41 @@ allow_any_instance_of(Braintree::TransactionGateway).to receive(:sale).and_call_original end - it 'does not pass any device data in the request' do + it "does not pass any device data in the request" do expect_any_instance_of(Braintree::TransactionGateway) - .not_to receive(:sale).with(hash_including({ device_data: "" })) + .not_to receive(:sale).with(hash_including({device_data: ""})) authorize end end end - context 'with different merchant account for currency', vcr: { - cassette_name: 'gateway/authorize/merchant_account/EUR', + context "with different merchant account for currency", vcr: { + cassette_name: "gateway/authorize/merchant_account/EUR", match_requests_on: [:braintree_uri] } do - let(:currency) { 'EUR' } + let(:currency) { "EUR" } - it 'settles with the correct currency' do + it "settles with the correct currency" do transaction = braintree.transaction.find(authorize.authorization) - expect(transaction.merchant_account_id).to eq 'stembolt_EUR' + expect(transaction.merchant_account_id).to eq "stembolt_EUR" end end - context 'with different paypal payee email for currency', vcr: { - cassette_name: 'gateway/authorize/paypal/EUR', + context "with different paypal payee email for currency", vcr: { + cassette_name: "gateway/authorize/paypal/EUR", match_requests_on: [:braintree_uri] } do - let(:currency) { 'EUR' } + let(:currency) { "EUR" } - it 'uses the correct payee email' do - expect_any_instance_of(Braintree::TransactionGateway). - to receive(:sale). - with(hash_including({ + it "uses the correct payee email" do + expect_any_instance_of(Braintree::TransactionGateway) + .to receive(:sale) + .with(hash_including({ options: { store_in_vault_on_success: true, paypal: { - payee_email: ENV.fetch('BRAINTREE_PAYPAL_PAYEE_EMAIL') + payee_email: ENV.fetch("BRAINTREE_PAYPAL_PAYEE_EMAIL") } } })).and_call_original @@ -287,13 +287,13 @@ end context "with PayPal transaction", vcr: { - cassette_name: 'gateway/authorize/paypal/address', + cassette_name: "gateway/authorize/paypal/address", match_requests_on: [:braintree_uri] } do - it 'includes the shipping address in the request' do - expect_any_instance_of(Braintree::TransactionGateway). - to receive(:sale). - with(hash_including({ + it "includes the shipping address in the request" do + expect_any_instance_of(Braintree::TransactionGateway) + .to receive(:sale) + .with(hash_including({ shipping: { first_name: "Bruce", last_name: "Wayne", @@ -310,14 +310,14 @@ end context "with CreditCard transaction", vcr: { - cassette_name: 'gateway/authorize/credit_card/address', + cassette_name: "gateway/authorize/credit_card/address", match_requests_on: [:braintree_uri] } do let(:payment_type) { SolidusBraintree::Source::CREDIT_CARD } - it 'includes the billing address in the request' do - expect_any_instance_of(Braintree::TransactionGateway).to receive(:sale). - with(hash_including({ + it "includes the billing address in the request" do + expect_any_instance_of(Braintree::TransactionGateway).to receive(:sale) + .with(hash_including({ billing: { first_name: "Dick", last_name: "Grayson", @@ -336,19 +336,19 @@ describe "#capture" do subject(:capture) { gateway.capture(1000, authorized_id, {}) } - context 'with successful capture', vcr: { - cassette_name: 'gateway/capture', + context "with successful capture", vcr: { + cassette_name: "gateway/capture", match_requests_on: [:braintree_uri] } do include_examples "successful response" - it 'submits the transaction for settlement' do + it "submits the transaction for settlement" do expect(capture.message).to eq "submitted_for_settlement" end end - context 'with authorized transaction', vcr: { - cassette_name: 'gateway/authorized_transaction', + context "with authorized transaction", vcr: { + cassette_name: "gateway/authorized_transaction", match_requests_on: [:braintree_uri] } do include_examples "protects against connection errors" do @@ -360,19 +360,19 @@ describe "#credit" do subject(:credit) { gateway.credit(2000, source, settled_id, {}) } - context 'with successful credit', vcr: { - cassette_name: 'gateway/credit', + context "with successful credit", vcr: { + cassette_name: "gateway/credit", match_requests_on: [:braintree_uri] } do include_examples "successful response" - it 'credits the transaction' do - expect(credit.message).to eq 'submitted_for_settlement' + it "credits the transaction" do + expect(credit.message).to eq "submitted_for_settlement" end end - context 'with settled transaction', vcr: { - cassette_name: 'gateway/settled_transaction', + context "with settled transaction", vcr: { + cassette_name: "gateway/settled_transaction", match_requests_on: [:braintree_uri] } do include_examples "protects against connection errors" do @@ -384,19 +384,19 @@ describe "#void" do subject(:void) { gateway.void(authorized_id, source, {}) } - context 'when successfully voided', vcr: { - cassette_name: 'gateway/void', + context "when successfully voided", vcr: { + cassette_name: "gateway/void", match_requests_on: [:braintree_uri] } do include_examples "successful response" - it 'voids the transaction' do - expect(void.message).to eq 'voided' + it "voids the transaction" do + expect(void.message).to eq "voided" end end - context 'with authorized transaction', vcr: { - cassette_name: 'gateway/authorized_transaction', + context "with authorized transaction", vcr: { + cassette_name: "gateway/authorized_transaction", match_requests_on: [:braintree_uri] } do include_examples "protects against connection errors" do @@ -406,7 +406,7 @@ end describe "#cancel", vcr: { - cassette_name: 'gateway/cancel', + cassette_name: "gateway/cancel", match_requests_on: [:braintree_uri] } do subject(:cancel) { gateway.cancel(transaction_id) } @@ -415,43 +415,43 @@ context "when the transaction is found" do context "when it is voidable", vcr: { - cassette_name: 'gateway/cancel/void', + cassette_name: "gateway/cancel/void", match_requests_on: [:braintree_uri] } do let(:transaction_id) { authorized_id } include_examples "successful response" - it 'voids the transaction' do - expect(cancel.message).to eq 'voided' + it "voids the transaction" do + expect(cancel.message).to eq "voided" end end context "when it is not voidable", vcr: { - cassette_name: 'gateway/cancel/refunds', + cassette_name: "gateway/cancel/refunds", match_requests_on: [:braintree_uri] } do let(:transaction_id) { settled_id } include_examples "successful response" - it 'refunds the transaction' do - expect(cancel.message).to eq 'submitted_for_settlement' + it "refunds the transaction" do + expect(cancel.message).to eq "submitted_for_settlement" end end end context "when the transaction is not found", vcr: { - cassette_name: 'gateway/cancel/missing', + cassette_name: "gateway/cancel/missing", match_requests_on: [:braintree_uri] } do - it 'raises an error' do - expect{ cancel }.to raise_error ActiveMerchant::ConnectionError + it "raises an error" do + expect { cancel }.to raise_error ActiveMerchant::ConnectionError end end end - describe '#try_void' do + describe "#try_void" do subject { gateway.try_void(instance_double(Spree::Payment, response_code: source.token)) } let(:transaction_request) do @@ -465,22 +465,22 @@ allow(gateway).to receive(:braintree) { client } end - context 'with voidable payment' do + context "with voidable payment" do let(:transaction_response) do instance_double(Braintree::Transaction, status: Braintree::Transaction::Status::Authorized) end - it 'voids the payment' do + it "voids the payment" do expect(gateway).to receive(:void) subject end - context 'with error response mentioning an unvoidable transaction' do + context "with error response mentioning an unvoidable transaction" do before do allow(gateway).to receive(:void) do raise ActiveMerchant::ConnectionError.new( - 'Transaction can only be voided if status is authorized', + "Transaction can only be voided if status is authorized", double ) end @@ -489,11 +489,11 @@ it { is_expected.to be(false) } end - context 'with other error response' do + context "with other error response" do before do allow(gateway).to receive(:void) do raise ActiveMerchant::ConnectionError.new( - 'Server unreachable', + "Server unreachable", double ) end @@ -503,19 +503,19 @@ end end - context 'with voidable paypal payment' do + context "with voidable paypal payment" do let(:transaction_response) do instance_double(Braintree::Transaction, status: Braintree::Transaction::Status::SettlementPending) end - it 'voids the payment' do + it "voids the payment" do expect(gateway).to receive(:void) subject end end - context 'with non-voidable payment' do + context "with non-voidable payment" do let(:transaction_response) do instance_double(Braintree::Transaction, status: Braintree::Transaction::Status::Settled) @@ -540,14 +540,14 @@ match_requests_on: [:braintree_uri] } context "with no existing customer profile", vcr: cassette_options do - it 'creates and returns a new customer profile', aggregate_failures: true do + it "creates and returns a new customer profile", aggregate_failures: true do expect(profile).to be_a SolidusBraintree::Customer expect(profile.sources).to eq [source] expect(profile.braintree_customer_id).to be_present end it "sets a token on the payment source" do - expect{ subject }.to change(source, :token) + expect { subject }.to change(source, :token) end end @@ -576,7 +576,7 @@ end end - describe '#customer_profile_params' do + describe "#customer_profile_params" do subject(:params) { gateway.send(:customer_profile_params, payment) } let(:payment) do @@ -586,16 +586,16 @@ }) end - context 'when payment does not belong to an order' do + context "when payment does not belong to an order" do before { allow(payment).to receive(:order).and_return(nil) } - it 'has the email param as nil' do + it "has the email param as nil" do expect(subject[:email]).to be_nil end end - context 'when payment belongs to an order' do - it 'has no email param' do + context "when payment belongs to an order" do + it "has no email param" do expect(subject[:email]).to eq(payment.order.email) end end @@ -614,13 +614,13 @@ end cassette_options = { - cassette_name: 'gateway/customer', + cassette_name: "gateway/customer", match_requests_on: [:braintree_uri] } context "with customer", vcr: cassette_options do - it 'saves the customer email correctly' do - allow(payment.order).to receive(:email).and_return('braintree@customers.com') + it "saves the customer email correctly" do + allow(payment.order).to receive(:email).and_return("braintree@customers.com") expect(subject.email).to eq(payment.order.email) end end @@ -747,23 +747,23 @@ end end - describe '.generate_token' do + describe ".generate_token" do subject do # dont VCR ignore generate token request, use the existing cassette allow(VCR.request_ignorer.hooks).to receive(:[]).with(:ignore_request).and_return([]) gateway.generate_token end - context 'with connection enabled', vcr: { - cassette_name: 'braintree/generate_token', + context "with connection enabled", vcr: { + cassette_name: "braintree/generate_token", match_requests_on: [:braintree_uri] } do it { is_expected.to be_a(String).and be_present } end - context 'when token generation is disabled' do + context "when token generation is disabled" do let(:gateway) do - gateway = described_class.create!(name: 'braintree') + gateway = described_class.create!(name: "braintree") gateway.preferred_token_generation_enabled = false gateway end diff --git a/spec/models/solidus_braintree/response_spec.rb b/spec/models/solidus_braintree/response_spec.rb index d4de2d56..bded2e8b 100644 --- a/spec/models/solidus_braintree/response_spec.rb +++ b/spec/models/solidus_braintree/response_spec.rb @@ -1,11 +1,11 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::Response do let(:failed_transaction) { nil } let(:error) do instance_double( Braintree::ValidationError, - code: '12345', + code: "12345", message: "Cannot refund a transaction unless it is settled." ) end @@ -16,7 +16,7 @@ success?: false, errors: [error], transaction: failed_transaction, - params: { some: 'error' } + params: {some: "error"} ) end @@ -27,12 +27,12 @@ let(:successful_result) do transaction = instance_double( Braintree::Transaction, - status: 'ok', - id: 'abcdef', + status: "ok", + id: "abcdef", avs_error_response_code: nil, - avs_street_address_response_code: 'M', - avs_postal_code_response_code: 'M', - cvv_response_code: 'I' + avs_street_address_response_code: "M", + avs_postal_code_response_code: "M", + cvv_response_code: "I" ) instance_double( @@ -46,18 +46,18 @@ described_class.build(successful_result) end - describe '.new' do - it 'is private' do + describe ".new" do + it "is private" do expect { described_class.new }.to raise_error(/private method/) end end - describe '.build' do + describe ".build" do it { expect(error_response).to be_a ActiveMerchant::Billing::Response } it { expect(successful_response).to be_a ActiveMerchant::Billing::Response } end - describe '#success?' do + describe "#success?" do it { expect(error_response.success?).to be false } it { expect(successful_response.success?).to be true } end @@ -81,7 +81,7 @@ let(:failed_transaction) do instance_double( Braintree::Transaction, - id: 'abcdef', + id: "abcdef", status: "settlement_declined", processor_settlement_response_code: "4001", processor_settlement_response_text: "Settlement Declined", @@ -100,7 +100,7 @@ let(:failed_transaction) do instance_double( Braintree::Transaction, - id: 'abcdef', + id: "abcdef", status: "gateway_rejected", gateway_rejection_reason: "cvv", avs_error_response_code: nil, @@ -118,10 +118,10 @@ let(:failed_transaction) do instance_double( Braintree::Transaction, - id: 'abcdef', + id: "abcdef", status: "processor_declined", - processor_response_code: '2001', - processor_response_text: 'Insufficient Funds', + processor_response_code: "2001", + processor_response_text: "Insufficient Funds", avs_error_response_code: nil, avs_street_address_response_code: nil, avs_postal_code_response_code: nil, @@ -132,12 +132,12 @@ it { is_expected.to eq "Insufficient Funds (2001)" } end - context 'with other transaction status' do + context "with other transaction status" do let(:error) { nil } let(:failed_transaction) do instance_double( Braintree::Transaction, - id: 'abcdef', + id: "abcdef", status: "authorization_expired", avs_error_response_code: nil, avs_street_address_response_code: nil, @@ -146,15 +146,15 @@ ) end - it { is_expected.to eq 'Payment authorization has expired.' } + it { is_expected.to eq "Payment authorization has expired." } end - context 'with other transaction status that is not translated' do + context "with other transaction status that is not translated" do let(:error) { nil } let(:failed_transaction) do instance_double( Braintree::Transaction, - id: 'abcdef', + id: "abcdef", status: "something_bad_happened", avs_error_response_code: nil, avs_street_address_response_code: nil, @@ -163,116 +163,116 @@ ) end - it { is_expected.to eq 'Something bad happened' } + it { is_expected.to eq "Something bad happened" } end end end - describe '#avs_result' do - context 'with a successful result' do + describe "#avs_result" do + context "with a successful result" do subject { described_class.build(successful_result).avs_result } - it 'includes AVS response code' do - expect(subject['code']).to eq 'M' + it "includes AVS response code" do + expect(subject["code"]).to eq "M" end - it 'includes AVS response message' do - expect(subject['message']).to eq 'Street address and postal code match.' + it "includes AVS response message" do + expect(subject["message"]).to eq "Street address and postal code match." end end - context 'with an error result' do + context "with an error result" do subject { described_class.build(error_result).avs_result } let(:failed_transaction) do instance_double( Braintree::Transaction, - id: 'abcdef', - avs_error_response_code: 'E', + id: "abcdef", + avs_error_response_code: "E", avs_street_address_response_code: nil, avs_postal_code_response_code: nil, cvv_response_code: nil ) end - it 'includes AVS response code' do - expect(subject['code']).to eq 'E' + it "includes AVS response code" do + expect(subject["code"]).to eq "E" end - it 'includes AVS response message' do - expect(subject['message']).to eq 'AVS data is invalid or AVS is not allowed for this card type.' + it "includes AVS response message" do + expect(subject["message"]).to eq "AVS data is invalid or AVS is not allowed for this card type." end - context 'without transaction' do + context "without transaction" do let(:failed_transaction) { nil } - it 'includes no AVS response' do - expect(subject['message']).to be_nil - expect(subject['code']).to be_nil + it "includes no AVS response" do + expect(subject["message"]).to be_nil + expect(subject["code"]).to be_nil end end end end - describe '#cvv_result' do - context 'with a successful result' do + describe "#cvv_result" do + context "with a successful result" do subject { described_class.build(successful_result).cvv_result } - it 'does not include CVV response code' do - expect(subject['code']).to be_nil + it "does not include CVV response code" do + expect(subject["code"]).to be_nil end - it 'does not include CVV response message' do - expect(subject['message']).to be_nil + it "does not include CVV response message" do + expect(subject["message"]).to be_nil end end - context 'with an error result' do + context "with an error result" do subject { described_class.build(error_result).cvv_result } let(:failed_transaction) do instance_double( Braintree::Transaction, - id: 'abcdef', + id: "abcdef", avs_error_response_code: nil, avs_street_address_response_code: nil, avs_postal_code_response_code: nil, - cvv_response_code: 'N' + cvv_response_code: "N" ) end - it 'includes CVV response code' do - expect(subject['code']).to eq 'N' + it "includes CVV response code" do + expect(subject["code"]).to eq "N" end - it 'includes CVV response message' do - expect(subject['message']).to eq 'CVV does not match' + it "includes CVV response message" do + expect(subject["message"]).to eq "CVV does not match" end - context 'without transaction' do + context "without transaction" do let(:failed_transaction) { nil } - it 'includes no CVV response' do - expect(subject['message']).to be_nil - expect(subject['code']).to be_nil + it "includes no CVV response" do + expect(subject["message"]).to be_nil + expect(subject["code"]).to be_nil end end end end - describe '#params' do + describe "#params" do context "with an error response" do subject { error_response.params } - it 'includes request params' do - expect(subject).to eq({ 'some' => 'error' }) + it "includes request params" do + expect(subject).to eq({"some" => "error"}) end end end - describe '#authorization' do - it 'is whatever the b.t. transaction id was' do - expect(successful_response.authorization).to eq 'abcdef' + describe "#authorization" do + it "is whatever the b.t. transaction id was" do + expect(successful_response.authorization).to eq "abcdef" end it { expect(error_response.authorization).to be_nil } diff --git a/spec/models/solidus_braintree/source_spec.rb b/spec/models/solidus_braintree/source_spec.rb index 2414c608..d276918d 100644 --- a/spec/models/solidus_braintree/source_spec.rb +++ b/spec/models/solidus_braintree/source_spec.rb @@ -1,29 +1,29 @@ -require 'solidus_braintree_spec_helper' -require 'support/solidus_braintree/order_ready_for_payment' +require "solidus_braintree_spec_helper" +require "support/solidus_braintree/order_ready_for_payment" RSpec.describe SolidusBraintree::Source, type: :model do - include_context 'when order is ready for payment' + include_context "when order is ready for payment" - it 'is invalid without a payment_type set' do + it "is invalid without a payment_type set" do expect(described_class.new).to be_invalid end - it 'is invalid with payment_type set to unknown type' do - expect(described_class.new(payment_type: 'AndroidPay')).to be_invalid + it "is invalid with payment_type set to unknown type" do + expect(described_class.new(payment_type: "AndroidPay")).to be_invalid end - describe 'attributes' do - context 'with paypal_funding_source' do + describe "attributes" do + context "with paypal_funding_source" do subject { build(:solidus_braintree_source, :paypal) } - it 'can be nil' do + it "can be nil" do subject.paypal_funding_source = nil expect(subject).to be_valid end - it 'makes empty strings nil' do - subject.paypal_funding_source = '' + it "makes empty strings nil" do + subject.paypal_funding_source = "" result = subject.save @@ -31,19 +31,19 @@ expect(subject.paypal_funding_source).to be_nil end - it 'gets correctly mapped as an enum' do - subject.paypal_funding_source = 'applepay' + it "gets correctly mapped as an enum" do + subject.paypal_funding_source = "applepay" result = subject.save expect(result).to be(true) - expect(subject.paypal_funding_source).to eq('applepay') + expect(subject.paypal_funding_source).to eq("applepay") expect(subject.applepay_funding?).to be(true) end it "doesn't become nil when the payment_type is a PAYPAL" do subject.payment_type = described_class::PAYPAL - subject.paypal_funding_source = 'venmo' + subject.paypal_funding_source = "venmo" result = subject.save @@ -51,9 +51,9 @@ expect(subject.venmo_funding?).to be(true) end - it 'becomes nil when the payment_type is a CREDIT CARD' do + it "becomes nil when the payment_type is a CREDIT CARD" do subject.payment_type = described_class::CREDIT_CARD - subject.paypal_funding_source = 'venmo' + subject.paypal_funding_source = "venmo" result = subject.save @@ -61,9 +61,9 @@ expect(subject.paypal_funding_source).to be_nil end - it 'becomes nil when the payment_type is APPLE PAY' do + it "becomes nil when the payment_type is APPLE PAY" do subject.payment_type = described_class::APPLE_PAY - subject.paypal_funding_source = 'venmo' + subject.paypal_funding_source = "venmo" result = subject.save @@ -73,14 +73,14 @@ end end - describe '#payment_method' do - it 'uses spree_payment_method' do + describe "#payment_method" do + it "uses spree_payment_method" do expect(described_class.new.build_payment_method).to be_a Spree::PaymentMethod end end - describe '#imported' do - it 'is always false' do + describe "#imported" do + it "is always false" do expect(described_class.new.imported).not_to be_truthy end end @@ -113,7 +113,7 @@ end end - describe '#can_void?' do + describe "#can_void?" do subject { payment_source.can_void?(payment) } let(:payment_source) { described_class.new } @@ -133,17 +133,17 @@ end end - context 'when transaction id is not present' do + context "when transaction id is not present" do let(:payment) { build(:payment, response_code: nil) } it { is_expected.to be(false) } end - context 'when transaction has voidable status' do + context "when transaction has voidable status" do it { is_expected.to be(true) } end - context 'when transaction has non voidable status' do + context "when transaction has non voidable status" do let(:transaction_response) do double(:response, status: Braintree::Transaction::Status::Settled) end @@ -151,7 +151,7 @@ it { is_expected.to be(false) } end - context 'when transaction is not found at Braintreee' do + context "when transaction is not found at Braintreee" do before do allow(transaction_request).to \ receive(:find).and_raise(Braintree::NotFoundError) @@ -277,7 +277,7 @@ end end - shared_context 'with unknown source token' do + shared_context "with unknown source token" do let(:braintree_payment_method) { double } before do @@ -290,7 +290,7 @@ end end - shared_context 'with nil source token' do + shared_context "with nil source token" do let(:braintree_payment_method) { double } before do @@ -310,7 +310,7 @@ let(:payment_source) { described_class.create!(payment_type: "CreditCard", payment_method: method) } let(:braintree_client) { method.braintree } - context 'when token is known at braintree', vcr: { + context "when token is known at braintree", vcr: { cassette_name: "source/last4", match_requests_on: [:braintree_uri] } do @@ -331,14 +331,14 @@ end end - context 'when the source token is not known at Braintree' do - include_context 'with unknown source token' + context "when the source token is not known at Braintree" do + include_context "with unknown source token" it { is_expected.to be_nil } end - context 'when the source token is nil' do - include_context 'with nil source token' + context "when the source token is nil" do + include_context "with nil source token" it { is_expected.to be_nil } end @@ -352,10 +352,10 @@ context "when last_digits is a number" do before do - allow(payment_source).to receive(:last_digits).and_return('1234') + allow(payment_source).to receive(:last_digits).and_return("1234") end - it { is_expected.to eq 'XXXX-XXXX-XXXX-1234' } + it { is_expected.to eq "XXXX-XXXX-XXXX-1234" } end context "when last_digits is nil" do @@ -363,27 +363,27 @@ allow(payment_source).to receive(:last_digits).and_return(nil) end - it { is_expected.to eq 'XXXX-XXXX-XXXX-XXXX' } + it { is_expected.to eq "XXXX-XXXX-XXXX-XXXX" } end context "when is a PayPal source" do let(:type) { "PayPalAccount" } before do - allow(payment_source).to receive(:email).and_return('user@example.com') + allow(payment_source).to receive(:email).and_return("user@example.com") end - it { is_expected.to eq 'user@example.com' } + it { is_expected.to eq "user@example.com" } end context "when is a Venmo source" do let(:type) { "VenmoAccount" } before do - allow(payment_source).to receive(:username).and_return('venmojoe') + allow(payment_source).to receive(:username).and_return("venmojoe") end - it { is_expected.to eq('venmojoe') } + it { is_expected.to eq("venmojoe") } end end @@ -414,39 +414,39 @@ end end - context 'when the source token is not known at Braintree' do - include_context 'with unknown source token' + context "when the source token is not known at Braintree" do + include_context "with unknown source token" it { is_expected.to be_nil } end - context 'when the source token is nil' do - include_context 'with nil source token' + context "when the source token is nil" do + include_context "with nil source token" it { is_expected.to be_nil } end end - describe '#display_paypal_funding_source' do + describe "#display_paypal_funding_source" do let(:payment_source) { described_class.new } - context 'when the EN locale exists' do - it 'translates the funding source' do - payment_source.paypal_funding_source = 'card' + context "when the EN locale exists" do + it "translates the funding source" do + payment_source.paypal_funding_source = "card" result = payment_source.display_paypal_funding_source - expect(result).to eq('Credit or debit card') + expect(result).to eq("Credit or debit card") end end context "when the locale doesn't exist" do - it 'returns the paypal_funding_source as the default' do - allow(payment_source).to receive(:paypal_funding_source).and_return('non-existent') + it "returns the paypal_funding_source as the default" do + allow(payment_source).to receive(:paypal_funding_source).and_return("non-existent") result = payment_source.display_paypal_funding_source - expect(result).to eq('non-existent') + expect(result).to eq("non-existent") end end end @@ -478,60 +478,60 @@ end end - context 'when the source token is not known at Braintree' do - include_context 'with unknown source token' + context "when the source token is not known at Braintree" do + include_context "with unknown source token" it { is_expected.to be_nil } end - context 'when the source token is nil' do - include_context 'with nil source token' + context "when the source token is nil" do + include_context "with nil source token" it { is_expected.to be_nil } end end - describe '#display_payment_type' do + describe "#display_payment_type" do subject { described_class.new(payment_type: type).display_payment_type } - context 'when type is CreditCard' do - let(:type) { 'CreditCard' } + context "when type is CreditCard" do + let(:type) { "CreditCard" } it 'returns "Payment Type: Credit Card' do - expect(subject).to eq('Payment Type: Credit Card') + expect(subject).to eq("Payment Type: Credit Card") end end - context 'when type is PayPalAccount' do - let(:type) { 'PayPalAccount' } + context "when type is PayPalAccount" do + let(:type) { "PayPalAccount" } it 'returns "Payment Type: PayPal' do - expect(subject).to eq('Payment Type: PayPal') + expect(subject).to eq("Payment Type: PayPal") end end - context 'when type is VenmoAccount' do - let(:type) { 'VenmoAccount' } + context "when type is VenmoAccount" do + let(:type) { "VenmoAccount" } it 'returns "Payment Type: Venmo' do - expect(subject).to eq('Payment Type: Venmo') + expect(subject).to eq("Payment Type: Venmo") end end end - describe '#reusable?' do + describe "#reusable?" do subject { payment_source.reusable? } let(:payment_source) { described_class.new(token: token, nonce: nonce) } - let(:nonce) { 'nonce67890' } + let(:nonce) { "nonce67890" } - context 'when source token is present' do - let(:token) { 'token12345' } + context "when source token is present" do + let(:token) { "token12345" } it { is_expected.to be_truthy } end - context 'when source token is nil' do + context "when source token is nil" do let(:token) { nil } it { is_expected.to be_falsy } diff --git a/spec/models/solidus_braintree/transaction_address_spec.rb b/spec/models/solidus_braintree/transaction_address_spec.rb index 2b8e8eeb..f42220f2 100644 --- a/spec/models/solidus_braintree/transaction_address_spec.rb +++ b/spec/models/solidus_braintree/transaction_address_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::TransactionAddress do describe "#valid?" do @@ -17,7 +17,7 @@ } end - let(:country) { create :country, iso: 'US', states_required: true } + let(:country) { create :country, iso: "US", states_required: true } before do create :state, abbr: "WA", country: country @@ -25,8 +25,8 @@ it { is_expected.to be true } - context 'without country matches' do - let(:valid_attributes) { super().merge({ country_code: 'CA' }) } + context "without country matches" do + let(:valid_attributes) { super().merge({country_code: "CA"}) } it { is_expected.to be false } end @@ -61,7 +61,7 @@ it { is_expected.to be false } context "when country does not requires states" do - let(:country) { create :country, iso: 'US', states_required: false } + let(:country) { create :country, iso: "US", states_required: false } it { is_expected.to be true } end @@ -79,7 +79,7 @@ end context "with a one word name" do - let(:valid_attributes) { super().merge({ name: "Bruce" }) } + let(:valid_attributes) { super().merge({name: "Bruce"}) } it { is_expected.to be true } end @@ -89,7 +89,7 @@ subject { described_class.new(attrs) } context "when an ISO code is provided" do - let(:attrs) { { country_code: "US" } } + let(:attrs) { {country_code: "US"} } it "uses the ISO code provided" do expect(subject.country_code).to eq "US" @@ -102,7 +102,7 @@ create :country, name: "canada", iso: "CA" end - let(:attrs) { { country_name: "Canada" } } + let(:attrs) { {country_name: "Canada"} } it "looks up the ISO code by the country name" do expect(subject.country_code).to eq "CA" @@ -110,7 +110,7 @@ end context "without valid country name" do - let(:attrs) { { country_name: "Neverland" } } + let(:attrs) { {country_name: "Neverland"} } it "leaves the country code blank" do expect(subject.country_code).to be_nil @@ -119,113 +119,113 @@ end end - describe '#spree_country' do + describe "#spree_country" do subject { described_class.new(country_code: country_code).spree_country } before do - create :country, name: 'United States', iso: 'US' + create :country, name: "United States", iso: "US" end - ['us', 'US'].each do |code| + ["us", "US"].each do |code| let(:country_code) { code } - it 'looks up by iso' do - expect(subject.name).to eq 'United States' + it "looks up by iso" do + expect(subject.name).to eq "United States" end end - context 'when country does not exist' do - let(:country_code) { 'NA' } + context "when country does not exist" do + let(:country_code) { "NA" } it { is_expected.to be_nil } end end - describe '#spree_state' do - subject { described_class.new(country_code: 'US', state_code: state_code).spree_state } + describe "#spree_state" do + subject { described_class.new(country_code: "US", state_code: state_code).spree_state } - let(:state_code) { 'newy' } + let(:state_code) { "newy" } it { is_expected.to be_nil } - context 'when state exists' do + context "when state exists" do before do - us = create :country, iso: 'US' - create :state, abbr: 'NY', name: 'New York', country: us + us = create :country, iso: "US" + create :state, abbr: "NY", name: "New York", country: us end - ['ny', ' ny', 'ny ', 'New York', 'new york', 'NY'].each do |code| + ["ny", " ny", "ny ", "New York", "new york", "NY"].each do |code| let(:state_code) { code } - it 'looks up the right state' do + it "looks up the right state" do expect(subject.abbr).to eq "NY" end end - context 'with no matching state' do - let(:state_code) { 'AL' } + context "with no matching state" do + let(:state_code) { "AL" } it { is_expected.to be_nil } end end end - describe '#should_match_state_model' do - subject { described_class.new(country_code: 'US').should_match_state_model? } + describe "#should_match_state_model" do + subject { described_class.new(country_code: "US").should_match_state_model? } it { is_expected.to be_falsey } - context 'when country does not require states' do - before { create :country, iso: 'US', states_required: false } + context "when country does not require states" do + before { create :country, iso: "US", states_required: false } it { is_expected.to be false } end - context 'when country requires states' do - before { create :country, iso: 'US', states_required: true } + context "when country requires states" do + before { create :country, iso: "US", states_required: true } it { is_expected.to be true } end end - describe '#to_spree_address' do + describe "#to_spree_address" do subject { described_class.new(address_params).to_spree_address } let(:address_params) do { - country_code: 'US', - state_code: 'NY', + country_code: "US", + state_code: "NY", name: "Alfred" } end - let!(:us) { create :country, iso: 'US' } + let!(:us) { create :country, iso: "US" } it { is_expected.to be_a Spree::Address } - context 'when country exists with states' do + context "when country exists with states" do before do - create :state, country: us, abbr: 'NY', name: 'New York' + create :state, country: us, abbr: "NY", name: "New York" end - it 'uses state model' do - expect(subject.state.name).to eq 'New York' + it "uses state model" do + expect(subject.state.name).to eq "New York" end end - context 'when country exist with no states' do - it 'uses state_name' do + context "when country exist with no states" do + it "uses state_name" do expect(subject.state).to be_nil - expect(subject.state_text).to eq 'NY' + expect(subject.state_text).to eq "NY" end end unless SolidusSupport.combined_first_and_last_name_in_address? - context 'when using first_name and last_name' do - let(:address_params) { super().merge({ first_name: "Bruce", last_name: "Wayne" }) } + context "when using first_name and last_name" do + let(:address_params) { super().merge({first_name: "Bruce", last_name: "Wayne"}) } - it 'displays a deprecation warning' do - expect(Spree::Deprecation).to receive(:warn). - with("first_name and last_name are deprecated. Use name instead.", any_args) + it "displays a deprecation warning" do + expect(Spree::Deprecation).to receive(:warn) + .with("first_name and last_name are deprecated. Use name instead.", any_args) subject end diff --git a/spec/models/solidus_braintree/transaction_import_spec.rb b/spec/models/solidus_braintree/transaction_import_spec.rb index 6e715cc3..744fd170 100644 --- a/spec/models/solidus_braintree/transaction_import_spec.rb +++ b/spec/models/solidus_braintree/transaction_import_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::TransactionImport do let(:order) { Spree::Order.new } @@ -7,7 +7,7 @@ let(:transaction_address) { nil } let(:transaction) do SolidusBraintree::Transaction.new( - nonce: 'abcd1234', + nonce: "abcd1234", payment_type: "ApplePayCard", address: transaction_address, payment_method: braintree_gateway, @@ -47,51 +47,51 @@ it "sets useful error messages" do transaction_import.valid? - expect(transaction_import.errors.full_messages). - to eq ["Address is invalid", "Address Zip can't be blank"] + expect(transaction_import.errors.full_messages) + .to eq ["Address is invalid", "Address Zip can't be blank"] end end end - describe '#source' do + describe "#source" do subject { described_class.new(order, transaction).source } it { is_expected.to be_a SolidusBraintree::Source } - it 'takes the nonce from the transaction' do - expect(subject.nonce).to eq 'abcd1234' + it "takes the nonce from the transaction" do + expect(subject.nonce).to eq "abcd1234" end - it 'takes the payment type from the transaction' do - expect(subject.payment_type).to eq 'ApplePayCard' + it "takes the payment type from the transaction" do + expect(subject.payment_type).to eq "ApplePayCard" end - it 'takes the payment method from the transaction' do + it "takes the payment method from the transaction" do expect(subject.payment_method).to eq braintree_gateway end - it 'takes the paypal funding source from the transaction' do - transaction.paypal_funding_source = 'paypal' + it "takes the paypal funding source from the transaction" do + transaction.paypal_funding_source = "paypal" - expect(subject.paypal_funding_source).to eq('paypal') + expect(subject.paypal_funding_source).to eq("paypal") end - context 'when order has a user' do + context "when order has a user" do let(:user) { Spree.user_class.new } let(:order) { Spree::Order.new user: user } - it 'associates user to the source' do + it "associates user to the source" do expect(subject.user).to eq user end end end - describe '#user' do + describe "#user" do subject { described_class.new(order, transaction).user } it { is_expected.to be_nil } - context 'when order has a user' do + context "when order has a user" do let(:user) { Spree.user_class.new } let(:order) { Spree::Order.new user: user } @@ -99,7 +99,7 @@ end end - describe '#import!' do + describe "#import!" do subject { described_class.new(order, transaction).import!(end_state) } let(:store) { create :store } @@ -112,24 +112,24 @@ store: store, line_items: [line_item], ship_address: address, - currency: 'USD', + currency: "USD", total: 10, - email: 'test@example.com' + email: "test@example.com" ) } let(:payment_method) { create_gateway } let(:transaction_address) { nil } - let(:end_state) { 'confirm' } + let(:end_state) { "confirm" } let(:transaction) do SolidusBraintree::Transaction.new( - nonce: 'fake-valid-nonce', + nonce: "fake-valid-nonce", payment_method: payment_method, address: transaction_address, payment_type: SolidusBraintree::Source::PAYPAL, - phone: '123-456-7890', - email: 'user@example.com' + phone: "123-456-7890", + email: "user@example.com" ) end @@ -138,28 +138,28 @@ create :shipping_method, cost: 5 # ensure payments have the same number so VCR matches the request body - allow_any_instance_of(Spree::Payment). - to receive(:generate_identifier). - and_return("ABCD1234") + allow_any_instance_of(Spree::Payment) + .to receive(:generate_identifier) + .and_return("ABCD1234") end context "with passing validation", vcr: { - cassette_name: 'transaction/import/valid', + cassette_name: "transaction/import/valid", match_requests_on: [:braintree_uri] } do context "when order end state is confirm" do - it 'advances order to confirm state' do + it "advances order to confirm state" do subject - expect(order.state).to eq 'confirm' + expect(order.state).to eq "confirm" end - it 'has a payment for the cost of line items + shipment' do + it "has a payment for the cost of line items + shipment" do subject expect(order.payments.first.amount).to eq 15 end - it 'is complete and capturable', aggregate_failures: true, vcr: { - cassette_name: 'transaction/import/valid/capture', + it "is complete and capturable", aggregate_failures: true, vcr: { + cassette_name: "transaction/import/valid/capture", match_requests_on: [:braintree_uri] } do subject @@ -175,11 +175,11 @@ end context "when order end state is delivery" do - let(:end_state) { 'delivery' } + let(:end_state) { "delivery" } it "advances the order to delivery" do subject - expect(order.state).to eq 'delivery' + expect(order.state).to eq "delivery" end it "has a payment for the cost of line items" do @@ -188,66 +188,67 @@ end end - context 'when transaction has address' do - let!(:new_york) { create :state, country: country, abbr: 'NY' } + context "when transaction has address" do + let!(:new_york) { create :state, country: country, abbr: "NY" } let(:transaction_address) do SolidusBraintree::TransactionAddress.new( - country_code: 'US', - name: 'Thaddeus Venture', - city: 'New York', - state_code: 'NY', - address_line_1: '350 5th Ave', - zip: '10118' + country_code: "US", + name: "Thaddeus Venture", + city: "New York", + state_code: "NY", + address_line_1: "350 5th Ave", + zip: "10118" ) end - it 'uses the new address', aggregate_failures: true do + it "uses the new address", aggregate_failures: true do subject - expect(order.shipping_address.address1).to eq '350 5th Ave' + expect(order.shipping_address.address1).to eq "350 5th Ave" expect(order.shipping_address.country).to eq country expect(order.shipping_address.state).to eq new_york end - context 'when transaction has paypal funding source' do - it 'saves it to the payment source' do - transaction.paypal_funding_source = 'paypal' + context "when transaction has paypal funding source" do + it "saves it to the payment source" do + transaction.paypal_funding_source = "paypal" subject source = SolidusBraintree::Source.last - expect(source.paypal_funding_source).to eq('paypal') + expect(source.paypal_funding_source).to eq("paypal") end end - context 'with a tax category' do + context "with a tax category" do before do - zone = Spree::Zone.create name: 'nyc tax' + zone = Spree::Zone.create name: "nyc tax" zone.members << Spree::ZoneMember.new(zoneable: new_york) create :tax_rate, zone: zone end - it 'includes the tax in the payment' do + it "includes the tax in the payment" do subject expect(order.payments.first.amount).to eq 16 end end - context 'with a less expensive tax category' do + context "with a less expensive tax category" do before do - original_zone = Spree::Zone.create name: 'first address tax' + original_zone = Spree::Zone.create name: "first address tax" original_zone.members << Spree::ZoneMember.new(zoneable: address.state) original_tax_rate = create :tax_rate, zone: original_zone, amount: 0.2 # new address is NY - ny_zone = Spree::Zone.create name: 'nyc tax' + ny_zone = Spree::Zone.create name: "nyc tax" ny_zone.members << Spree::ZoneMember.new(zoneable: new_york) create :tax_rate, tax_categories: [original_tax_rate.tax_categories.first], zone: ny_zone, amount: 0.1 end - it 'includes the lower tax in the payment' do + it "includes the lower tax in the payment" do # so shipments and shipment cost is calculated before transaction import - order.next!; order.next! + order.next! + order.next! # precondition expect(order.additional_tax_total).to eq 2 expect(order.total).to eq 17 @@ -263,11 +264,11 @@ context "when validation fails" do let(:transaction_address) do SolidusBraintree::TransactionAddress.new( - country_code: 'US', - name: 'Thaddeus Venture', - city: 'New York', - state_code: 'NY', - address_line_1: '350 5th Ave' + country_code: "US", + name: "Thaddeus Venture", + city: "New York", + state_code: "NY", + address_line_1: "350 5th Ave" ) end @@ -279,7 +280,7 @@ end context "with checkout flow", vcr: { - cassette_name: 'transaction/import/valid', + cassette_name: "transaction/import/valid", match_requests_on: [:braintree_uri] } do it "is not restarted by default" do diff --git a/spec/models/solidus_braintree/transaction_spec.rb b/spec/models/solidus_braintree/transaction_spec.rb index a0791bd9..b1cf52b3 100644 --- a/spec/models/solidus_braintree/transaction_spec.rb +++ b/spec/models/solidus_braintree/transaction_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe SolidusBraintree::Transaction do describe "#valid?" do @@ -6,9 +6,9 @@ let(:valid_attributes) do { - nonce: 'abcde-fghjkl-lmnop', + nonce: "abcde-fghjkl-lmnop", payment_method: SolidusBraintree::Gateway.new, - payment_type: 'ApplePayCard', + payment_type: "ApplePayCard", email: "test@example.com" } end @@ -33,31 +33,31 @@ it { is_expected.to be true } - context 'without nonce' do + context "without nonce" do let(:valid_attributes) { super().except(:nonce) } it { is_expected.to be false } end - context 'without gateway' do + context "without gateway" do let(:valid_attributes) { super().except(:payment_method) } it { is_expected.to be false } end - context 'with bad gateway' do + context "with bad gateway" do let(:valid_attributes) { super().merge(payment_method: Spree::PaymentMethod.new) } it { is_expected.to be false } end - context 'without payment_type' do + context "without payment_type" do let(:valid_attributes) { super().except(:payment_type) } it { is_expected.to be false } end - context 'without email' do + context "without email" do let(:valid_attributes) { super().except(:email) } it { is_expected.to be false } @@ -78,8 +78,8 @@ it "sets useful error messages" do transaction.valid? - expect(transaction.errors.full_messages). - to eq ["Address Zip can't be blank"] + expect(transaction.errors.full_messages) + .to eq ["Address Zip can't be blank"] end end end diff --git a/spec/models/spree/store_spec.rb b/spec/models/spree/store_spec.rb index 130f5bbc..7107c43a 100644 --- a/spec/models/spree/store_spec.rb +++ b/spec/models/spree/store_spec.rb @@ -1,9 +1,9 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe Spree::Store do - describe 'before_create :build_default_configuration' do - context 'when a braintree_configuration record already exists' do - it 'does not overwrite it' do + describe "before_create :build_default_configuration" do + context "when a braintree_configuration record already exists" do + it "does not overwrite it" do store = build(:store) custom_braintree_configuration = store.build_braintree_configuration store.save! diff --git a/spec/requests/spree/api/orders_controller_spec.rb b/spec/requests/spree/api/orders_controller_spec.rb index ba1defb6..a47f8a2a 100644 --- a/spec/requests/spree/api/orders_controller_spec.rb +++ b/spec/requests/spree/api/orders_controller_spec.rb @@ -1,21 +1,21 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe Spree::Api::OrdersController, type: :request do stub_authorization! - describe 'get show' do + describe "get show" do let(:gateway) { create_gateway } let(:order) { create(:order_with_line_items) } let(:source) do SolidusBraintree::Source.new( - nonce: 'fake-valid-nonce', + nonce: "fake-valid-nonce", user: order.user, payment_type: SolidusBraintree::Source::PAYPAL, payment_method: gateway ) end - context 'when using braintree as the payment' do + context "when using braintree as the payment" do before do allow_any_instance_of(Spree::Payment).to receive(:create_payment_profile).and_return(true) diff --git a/spec/solidus_braintree_spec_helper.rb b/spec/solidus_braintree_spec_helper.rb index 509a54eb..2263e3a7 100644 --- a/spec/solidus_braintree_spec_helper.rb +++ b/spec/solidus_braintree_spec_helper.rb @@ -1,9 +1,9 @@ -require 'solidus_starter_frontend_spec_helper' +require "solidus_starter_frontend_spec_helper" -require 'support/solidus_braintree/capybara' -require 'support/solidus_braintree/factories' -require 'support/solidus_braintree/gateway_helpers' -require 'support/solidus_braintree/order_walkthrough' -require 'support/solidus_braintree/vcr' +require "support/solidus_braintree/capybara" +require "support/solidus_braintree/factories" +require "support/solidus_braintree/gateway_helpers" +require "support/solidus_braintree/order_walkthrough" +require "support/solidus_braintree/vcr" Braintree::Configuration.logger = Rails.logger diff --git a/spec/support/solidus_braintree/capybara.rb b/spec/support/solidus_braintree/capybara.rb index d67eb732..d0e4d010 100644 --- a/spec/support/solidus_braintree/capybara.rb +++ b/spec/support/solidus_braintree/capybara.rb @@ -4,4 +4,4 @@ end end -Capybara.javascript_driver = (ENV['CAPYBARA_JS_DRIVER'] || :selenium_chrome_headless).to_sym +Capybara.javascript_driver = (ENV["CAPYBARA_JS_DRIVER"] || :selenium_chrome_headless).to_sym diff --git a/spec/support/solidus_braintree/factories.rb b/spec/support/solidus_braintree/factories.rb index 23993cf7..a96fff46 100644 --- a/spec/support/solidus_braintree/factories.rb +++ b/spec/support/solidus_braintree/factories.rb @@ -8,7 +8,7 @@ # require 'solidus_braintree/factories' factory :solidus_braintree_payment_method, class: SolidusBraintree::Gateway do - name { 'Solidus Braintree Gateway' } + name { "Solidus Braintree Gateway" } active { true } end @@ -38,7 +38,7 @@ # body in our VCR settings VCR can not match the request anymore and # therefore cannot replay existing cassettes. - zipcode { '21088-0255' } + zipcode { "21088-0255" } end if SolidusSupport.combined_first_and_last_name_in_address? diff --git a/spec/support/solidus_braintree/gateway_helpers.rb b/spec/support/solidus_braintree/gateway_helpers.rb index e5a8a97f..ba591201 100644 --- a/spec/support/solidus_braintree/gateway_helpers.rb +++ b/spec/support/solidus_braintree/gateway_helpers.rb @@ -4,15 +4,15 @@ def new_gateway(opts = {}) SolidusBraintree::Gateway.new({ name: "Braintree", preferences: { - environment: 'sandbox', - public_key: ENV.fetch('BRAINTREE_PUBLIC_KEY', 'dummy_public_key'), - private_key: ENV.fetch('BRAINTREE_PRIVATE_KEY', 'dummy_private_key'), - merchant_id: ENV.fetch('BRAINTREE_MERCHANT_ID', 'dummy_merchant_id'), + environment: "sandbox", + public_key: ENV.fetch("BRAINTREE_PUBLIC_KEY", "dummy_public_key"), + private_key: ENV.fetch("BRAINTREE_PRIVATE_KEY", "dummy_private_key"), + merchant_id: ENV.fetch("BRAINTREE_MERCHANT_ID", "dummy_merchant_id"), merchant_currency_map: { - 'EUR' => 'stembolt_EUR' + "EUR" => "stembolt_EUR" }, paypal_payee_email_map: { - 'EUR' => ENV.fetch('BRAINTREE_PAYPAL_PAYEE_EMAIL', 'paypal+europe@example.com') + "EUR" => ENV.fetch("BRAINTREE_PAYPAL_PAYEE_EMAIL", "paypal+europe@example.com") } } }.merge(opts)) diff --git a/spec/support/solidus_braintree/order_ready_for_payment.rb b/spec/support/solidus_braintree/order_ready_for_payment.rb index c6ebb101..6cf3e558 100644 --- a/spec/support/solidus_braintree/order_ready_for_payment.rb +++ b/spec/support/solidus_braintree/order_ready_for_payment.rb @@ -1,4 +1,4 @@ -RSpec.shared_context 'when order is ready for payment' do +RSpec.shared_context "when order is ready for payment" do let!(:country) { create :country } let(:user) { create :user } @@ -22,7 +22,7 @@ let(:order) do order = Spree::Order.create!( line_items: create_list(:line_item, 1, price: 50), - email: 'test@example.com', + email: "test@example.com", bill_address: address, ship_address: address, user: user diff --git a/spec/support/solidus_braintree/order_walkthrough.rb b/spec/support/solidus_braintree/order_walkthrough.rb index 184f39be..d25f3966 100644 --- a/spec/support/solidus_braintree/order_walkthrough.rb +++ b/spec/support/solidus_braintree/order_walkthrough.rb @@ -30,11 +30,11 @@ def up_to(state, user: nil) order.next! states_to_process = if state == :complete - states - else - end_state_position = states.index(state.to_sym) - states[..end_state_position] - end + states + else + end_state_position = states.index(state.to_sym) + states[..end_state_position] + end states_to_process.each do |state_to_process| send(state_to_process, order) @@ -68,7 +68,7 @@ def payment(order) credit_card = ::FactoryBot.create(:credit_card, user: order.user) order.payments.create!(payment_method: credit_card.payment_method, amount: order.total, source: credit_card) # TODO: maybe look at some way of making this payment_state change automatic - order.payment_state = 'paid' + order.payment_state = "paid" order.next! end diff --git a/spec/support/solidus_braintree/vcr.rb b/spec/support/solidus_braintree/vcr.rb index 6e92847d..7ba0d726 100644 --- a/spec/support/solidus_braintree/vcr.rb +++ b/spec/support/solidus_braintree/vcr.rb @@ -1,5 +1,5 @@ -require 'vcr' -require 'webmock' +require "vcr" +require "webmock" VCR.configure do |c| c.cassette_library_dir = "spec/fixtures/cassettes" @@ -10,7 +10,7 @@ } c.allow_http_connections_when_no_cassette = false c.ignore_localhost = true - c.ignore_hosts 'chromedriver.storage.googleapis.com' + c.ignore_hosts "chromedriver.storage.googleapis.com" # client token used for the fronted JS lib cannot be mocked: # it contains a cryptographically signed string containing the merchant id @@ -26,7 +26,7 @@ uri_match_pattern = %r{\Ahttps://api\.sandbox\.braintreegateway\.com/merchants/\w+(/.*)\z} - if match = uri.match(uri_match_pattern) + if (match = uri.match(uri_match_pattern)) match.captures.first end end diff --git a/spec/support/solidus_braintree/with_prepended_view_fixtures.rb b/spec/support/solidus_braintree/with_prepended_view_fixtures.rb index 727d9079..0a9fa4f5 100644 --- a/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +++ b/spec/support/solidus_braintree/with_prepended_view_fixtures.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -RSpec.shared_context 'with prepended view fixtures' do - let(:view_fixtures_path) { 'spec/fixtures/views' } +RSpec.shared_context "with prepended view fixtures" do + let(:view_fixtures_path) { "spec/fixtures/views" } before do ApplicationController.prepend_view_path view_fixtures_path diff --git a/spec/system/backend/configuration_spec.rb b/spec/system/backend/configuration_spec.rb index fdfa543c..3e023989 100644 --- a/spec/system/backend/configuration_spec.rb +++ b/spec/system/backend/configuration_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe "viewing the configuration interface", type: :feature do stub_authorization! @@ -13,11 +13,11 @@ it "doesn't raise any errors due to unavailable preference field partial" do Rails.application.config.spree.payment_methods << SolidusBraintree::Gateway Spree::PaymentMethod.create!( - type: 'SolidusBraintree::Gateway', - name: 'Braintree Payments' + type: "SolidusBraintree::Gateway", + name: "Braintree Payments" ) - visit '/admin/payment_methods' + visit "/admin/payment_methods" page.find('a[title="Edit"]').click - expect(page).to have_field 'Name', with: 'Braintree Payments' + expect(page).to have_field "Name", with: "Braintree Payments" end end diff --git a/spec/system/backend/new_payment_spec.rb b/spec/system/backend/new_payment_spec.rb index 2010e193..4403b254 100644 --- a/spec/system/backend/new_payment_spec.rb +++ b/spec/system/backend/new_payment_spec.rb @@ -1,9 +1,9 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.shared_context "with backend checkout setup" do let(:braintree) { new_gateway(active: true) } let!(:gateway) { create :payment_method } - let(:order) { create(:completed_order_with_totals, number: 'R9999999') } + let(:order) { create(:completed_order_with_totals, number: "R9999999") } let(:pending_case_insensitive) { /pending/i } let(:expiration) { "02/#{Date.current.year.next}" } @@ -25,18 +25,18 @@ end end -RSpec.describe 'creating a new payment', type: :feature, js: true do +RSpec.describe "creating a new payment", type: :feature, js: true do stub_authorization! context "with valid credit card data", vcr: { - cassette_name: 'admin/valid_credit_card', + cassette_name: "admin/valid_credit_card", match_requests_on: [:braintree_uri] } do include_context "with backend checkout setup" it "checks out successfully" do visit "/admin/orders/#{order.number}/payments/new" - choose('Braintree') + choose("Braintree") expect(page).to have_selector("#payment_method_#{braintree.id}", visible: :visible) expect(page).to have_selector("iframe#braintree-hosted-field-number") @@ -52,15 +52,15 @@ click_button("Update") - within('table#payments') do - expect(page).to have_content('Braintree') + within("table#payments") do + expect(page).to have_content("Braintree") expect(page).to have_content(pending_case_insensitive) end click_icon(:capture) - expect(page).not_to have_content('Cannot perform requested operation') - expect(page).to have_content('Payment Updated') + expect(page).not_to have_content("Cannot perform requested operation") + expect(page).to have_content("Payment Updated") end end @@ -70,7 +70,7 @@ # Attempt to submit an invalid form once before do visit "/admin/orders/#{order.number}/payments/new" - choose('Braintree') + choose("Braintree") within_frame("braintree-hosted-field-number") do fill_in("credit-card-number", with: "1111111111111111") @@ -121,15 +121,15 @@ end click_button("Update") - within('table#payments') do - expect(page).to have_content('Braintree') + within("table#payments") do + expect(page).to have_content("Braintree") expect(page).to have_content(pending_case_insensitive) end click_icon(:capture) - expect(page).not_to have_content('Cannot perform requested operation') - expect(page).to have_content('Payment Updated') + expect(page).not_to have_content("Cannot perform requested operation") + expect(page).to have_content("Payment Updated") end end end diff --git a/spec/system/frontend/braintree_credit_card_checkout_spec.rb b/spec/system/frontend/braintree_credit_card_checkout_spec.rb index 06035424..995c9bbc 100644 --- a/spec/system/frontend/braintree_credit_card_checkout_spec.rb +++ b/spec/system/frontend/braintree_credit_card_checkout_spec.rb @@ -1,4 +1,4 @@ -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.shared_context "with frontend checkout setup" do let(:braintree) { new_gateway(active: true) } @@ -19,16 +19,16 @@ ) braintree.update( - preferred_credit_card_fields_style: { input: { 'font-size': '30px' } }, - preferred_placeholder_text: { number: "Enter Your Card Number" } + preferred_credit_card_fields_style: {input: {"font-size": "30px"}}, + preferred_placeholder_text: {number: "Enter Your Card Number"} ) end - order = if Spree.solidus_gem_version >= Gem::Version.new('2.6.0') - SolidusBraintree::OrderWalkthrough.up_to(:delivery) - else - OrderWalkthrough.up_to(:delivery) - end + order = if Spree.solidus_gem_version >= Gem::Version.new("2.6.0") + SolidusBraintree::OrderWalkthrough.up_to(:delivery) + else + OrderWalkthrough.up_to(:delivery) + end user = create(:user) order.user = user @@ -51,8 +51,8 @@ end end -RSpec.describe 'entering credit card details', type: :feature, js: true do - context 'when page loads' do +RSpec.describe "entering credit card details", type: :feature, js: true do + context "when page loads" do include_context "with frontend checkout setup" it "selectors display correctly" do @@ -63,19 +63,19 @@ it "credit card field style variable is set" do within_frame("braintree-hosted-field-number") do - expect(find("#credit-card-number").style("font-size")).to eq({ "font-size" => "30px" }) + expect(find("#credit-card-number").style("font-size")).to eq({"font-size" => "30px"}) end end it "sets the placeholder text correctly" do within_frame("braintree-hosted-field-number") do - expect(find("#credit-card-number")['placeholder']).to eq("Enter Your Card Number") + expect(find("#credit-card-number")["placeholder"]).to eq("Enter Your Card Number") end end end context "with valid credit card data", vcr: { - cassette_name: 'checkout/valid_credit_card', + cassette_name: "checkout/valid_credit_card", match_requests_on: [:braintree_uri] } do include_context "with frontend checkout setup" @@ -101,32 +101,32 @@ expect(page).to have_content(/confirm/i) end - check('accept_terms_and_conditions') + check("accept_terms_and_conditions") click_button("Place Order") expect(page).to have_content("Your order has been processed successfully") end - context 'with 3D secure enabled' do + context "with 3D secure enabled" do let(:three_d_secure_enabled) { true } - it 'checks out successfully' do + it "checks out successfully" do authenticate_3ds within(".confirm-step") do expect(page).to have_content(/confirm/i) end - check('accept_terms_and_conditions') + check("accept_terms_and_conditions") click_button("Place Order") expect(page).to have_content("Your order has been processed successfully") end - context 'with 3ds authentication error' do + context "with 3ds authentication error" do let(:card_number) { "4000000000001125" } - it 'shows a 3ds authentication error' do + it "shows a 3ds authentication error" do authenticate_3ds expect(page).to have_content( "3D Secure authentication failed. Please try again using a different payment method." @@ -150,7 +150,7 @@ end # Same error should be produced when submitting an empty form again - context "when user tries to resubmit an empty form", vcr: { cassette_name: "checkout/invalid_credit_card" } do + context "when user tries to resubmit an empty form", vcr: {cassette_name: "checkout/invalid_credit_card"} do it "displays an alert with a meaningful error message" do expect(page).to have_selector("[type='submit']:enabled") @@ -180,7 +180,7 @@ expect(page).to have_content(/confirm/i) end - check('accept_terms_and_conditions') + check("accept_terms_and_conditions") click_button("Place Order") expect(page).to have_content("Your order has been processed successfully") diff --git a/spec/system/frontend/paypal_checkout_spec.rb b/spec/system/frontend/paypal_checkout_spec.rb index 3f37c707..121f877d 100644 --- a/spec/system/frontend/paypal_checkout_spec.rb +++ b/spec/system/frontend/paypal_checkout_spec.rb @@ -1,8 +1,8 @@ -require 'solidus_braintree_spec_helper' -require 'support/solidus_braintree/with_prepended_view_fixtures' +require "solidus_braintree_spec_helper" +require "support/solidus_braintree/with_prepended_view_fixtures" RSpec.describe "Checkout", type: :feature, js: true do - include_context 'with prepended view fixtures' + include_context "with prepended view fixtures" Capybara.default_max_wait_time = 60 @@ -11,7 +11,7 @@ # s.braintree_configuration.update!(braintree_preferences) # end # end - let(:braintree_preferences) { { paypal: true }.merge(paypal_options) } + let(:braintree_preferences) { {paypal: true}.merge(paypal_options) } let(:paypal_options) { {} } let!(:country) { create(:country, states_required: true) } @@ -48,12 +48,12 @@ end end - context 'when using custom paypal button style' do - let(:paypal_options) { { preferred_paypal_button_color: 'blue' } } + context "when using custom paypal button style" do + let(:paypal_options) { {preferred_paypal_button_color: "blue"} } - it 'displays required PayPal button style' do - within_frame find('#paypal-button iframe') do - expect(page).to have_selector('.paypal-button-color-blue') + it "displays required PayPal button style" do + within_frame find("#paypal-button iframe") do + expect(page).to have_selector(".paypal-button-color-blue") end end end @@ -96,13 +96,13 @@ # this greatly increases the test time, so it is left out since CI runs # these with poltergeist. def move_through_paypal_popup - expect(page).to have_css('#paypal-button .paypal-button') + expect(page).to have_css("#paypal-button .paypal-button") sleep 2 # the PayPal button is not immediately ready popup = page.window_opened_by do - within_frame find('#paypal-button iframe') do - find('div.paypal-button').click + within_frame find("#paypal-button iframe") do + find("div.paypal-button").click end end page.switch_to_window(popup) @@ -110,15 +110,15 @@ def move_through_paypal_popup # We don't control this popup window. # So javascript errors are not our errors. begin - expect(page).not_to have_selector('body.loading') + expect(page).not_to have_selector("body.loading") fill_in("login_email", with: "stembolt_buyer@stembolttest.com") click_on "Next" fill_in("login_password", with: "test1234") - expect(page).not_to have_selector('body.loading') + expect(page).not_to have_selector("body.loading") click_button("btnLogin") - expect(page).not_to have_selector('body.loading') + expect(page).not_to have_selector("body.loading") click_button("Continue") click_button("Agree & Continue") rescue Selenium::WebDriver::Error::JavascriptError => e diff --git a/spec/system/frontend/venmo_checkout_spec.rb b/spec/system/frontend/venmo_checkout_spec.rb index 8e66ad55..621e3b09 100644 --- a/spec/system/frontend/venmo_checkout_spec.rb +++ b/spec/system/frontend/venmo_checkout_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'solidus_braintree_spec_helper' +require "solidus_braintree_spec_helper" RSpec.describe "Checkout", type: :feature, js: true do - let(:braintree_preferences) { { venmo: true }.merge(preferences) } + let(:braintree_preferences) { {venmo: true}.merge(preferences) } let(:preferences) { {} } let(:user) { create(:user) } let!(:payment_method) { create_gateway } @@ -16,67 +16,67 @@ go_to_payment_checkout_page end - context 'with Venmo checkout' do - context 'when Venmo is disabled' do - let(:preferences) { { venmo: false } } + context "with Venmo checkout" do + context "when Venmo is disabled" do + let(:preferences) { {venmo: false} } - it 'does not load the Venmo payment button' do - expect(page).not_to have_selector('#venmo-button') + it "does not load the Venmo payment button" do + expect(page).not_to have_selector("#venmo-button") end end - context 'when Venmo is enabled' do - it 'loads the Venmo payment button' do - expect(page).to have_selector('#venmo-button') + context "when Venmo is enabled" do + it "loads the Venmo payment button" do + expect(page).to have_selector("#venmo-button") end end context "when Venmo's button style is customized" do context 'when venmo_button_color is "blue" and venmo_button_width is "280"' do - let(:preferences) { { preferred_venmo_button_color: 'blue', preferred_venmo_button_width: '280' } } + let(:preferences) { {preferred_venmo_button_color: "blue", preferred_venmo_button_width: "280"} } - it 'has the correct style' do - venmo_button.assert_matches_style(width: '280px', 'background-image': /venmo_blue_button_280x48/) + it "has the correct style" do + venmo_button.assert_matches_style(width: "280px", "background-image": /venmo_blue_button_280x48/) venmo_button.hover - venmo_button.assert_matches_style('background-image': /venmo_active_blue_button_280x48/) + venmo_button.assert_matches_style("background-image": /venmo_active_blue_button_280x48/) end end context 'when venmo_button_color is "white" and venmo_button_width is "375"' do - let(:preferences) { { preferred_venmo_button_color: 'white', preferred_venmo_button_width: '375' } } + let(:preferences) { {preferred_venmo_button_color: "white", preferred_venmo_button_width: "375"} } - it 'has the correct style' do - venmo_button.assert_matches_style(width: '375px', 'background-image': /venmo_white_button_375x48/) + it "has the correct style" do + venmo_button.assert_matches_style(width: "375px", "background-image": /venmo_white_button_375x48/) venmo_button.hover - venmo_button.assert_matches_style('background-image': /venmo_active_white_button_375x48/) + venmo_button.assert_matches_style("background-image": /venmo_active_white_button_375x48/) end end end - context 'when the Venmo button is clicked' do + context "when the Venmo button is clicked" do before { venmo_button.click } - it 'opens the QR modal which shows an error when closed' do + it "opens the QR modal which shows an error when closed" do within_frame(venmo_frame) do - expect(page).to have_selector('#venmo-qr-code-view') + expect(page).to have_selector("#venmo-qr-code-view") - click_button('close-icon') + click_button("close-icon") - expect(page).not_to have_selector('#venmo-qr-code-view') + expect(page).not_to have_selector("#venmo-qr-code-view") end - expect(page).to have_content('Venmo authorization was canceled by closing the Venmo Desktop modal.') + expect(page).to have_content("Venmo authorization was canceled by closing the Venmo Desktop modal.") end end # TODO: Reenable these specs once Venmo is enabled on the Braintree sandbox. - xcontext 'with Venmo transactions', vcr: { cassette_name: 'checkout/valid_venmo_transaction' } do + xcontext "with Venmo transactions", vcr: {cassette_name: "checkout/valid_venmo_transaction"} do before do fake_venmo_successful_tokenization end - context 'with CreditCard disabled' do - it 'can checkout with Venmo' do + context "with CreditCard disabled" do + it "can checkout with Venmo" do next_checkout_step finalize_checkout @@ -85,10 +85,10 @@ end # To test that the hosted-fields inputs do not conflict with Venmo's - context 'with CreditCard enabled' do - let(:preferences) { { credit_card: true } } + context "with CreditCard enabled" do + let(:preferences) { {credit_card: true} } - it 'can checkout with Venmo' do + it "can checkout with Venmo" do disable_hosted_fields_inputs disable_hosted_fields_form_listener @@ -104,22 +104,22 @@ it "meet's Braintree's acceptance criteria during checkout", aggregate_failures: true do next_checkout_step - expect(page).to have_content('Payment Type: Venmo') + expect(page).to have_content("Payment Type: Venmo") finalize_checkout - expect(page).to have_content('Venmo Account: venmojoe') + expect(page).to have_content("Venmo Account: venmojoe") end # the VCR must be based on this test, so it includes HTTP requests of the second order - it 'saves the used Venmo source in the wallet and can be reused' do + it "saves the used Venmo source in the wallet and can be reused" do next_checkout_step finalize_checkout - go_to_payment_checkout_page(order_number: 'R300000002') + go_to_payment_checkout_page(order_number: "R300000002") expect(Spree::User.first.wallet.wallet_payment_sources).not_to be_empty - expect(page).to have_selector('#existing_cards') - expect(page).to have_content('venmojoe') + expect(page).to have_selector("#existing_cards") + expect(page).to have_content("venmojoe") next_checkout_step finalize_checkout @@ -131,12 +131,12 @@ private - def go_to_payment_checkout_page(order_number: 'R300000001' ) - order = if Spree.solidus_gem_version >= Gem::Version.new('2.6.0') - SolidusBraintree::OrderWalkthrough.up_to(:address) - else - OrderWalkthrough.up_to(:address) - end + def go_to_payment_checkout_page(order_number: "R300000001") + order = if Spree.solidus_gem_version >= Gem::Version.new("2.6.0") + SolidusBraintree::OrderWalkthrough.up_to(:address) + else + OrderWalkthrough.up_to(:address) + end order.update!(user: user, number: order_number) # constant order number for VCRs @@ -153,19 +153,19 @@ def go_to_payment_checkout_page(order_number: 'R300000001' ) end def next_checkout_step - click_button('Save and Continue') + click_button("Save and Continue") end def finalize_checkout - click_button('Place Order') + click_button("Place Order") end def venmo_button - find_button('venmo-button', disabled: false) + find_button("venmo-button", disabled: false) end def venmo_frame - find('#venmo-desktop-iframe') + find("#venmo-desktop-iframe") end def fake_venmo_successful_tokenization