diff --git a/.rubocop.yml b/.rubocop.yml index cd8d1a0..081f3b5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,231 +1,8 @@ -# Relaxed.Ruby.Style +require: + - solidus_dev_support/rubocop -AllCops: - Exclude: - - 'spec/dummy/**/*' - - 'vendor/bundle/**/*' - TargetRubyVersion: 2.1 - -# Sometimes I believe this reads better -# This also causes spacing issues on multi-line fixes -Style/BracesAroundHashParameters: - Enabled: false - -# We use class vars and will have to continue doing so for compatability -Style/ClassVars: - Enabled: false - -# We need these names for backwards compatability -Style/PredicateName: - Enabled: false - -Style/AccessorMethodName: - Enabled: false - -# This has been used for customization -Style/MutableConstant: - Enabled: false - -Style/ClassAndModuleChildren: - Enabled: false - -Style/GuardClause: - Enabled: false - -Style/WordArray: - Enabled: false - -Style/ConditionalAssignment: - Enabled: false - -Performance/Count: - Enabled: false - -Style/RaiseArgs: - Enabled: false - -Style/OpMethod: - Enabled: false - -# We can use good judgement here -Style/RegexpLiteral: - Enabled: false - -# Unicode comments are useful -Style/AsciiComments: - Enabled: false - -Lint/EndAlignment: - Enabled: false - -Style/ElseAlignment: - Enabled: false - -Style/IndentationWidth: - Enabled: false - -Style/AlignParameters: - Enabled: false - -Style/ClosingParenthesisIndentation: - Enabled: false - -Style/MultilineMethodCallIndentation: - Enabled: false - -Style/IndentArray: - Enabled: false - -Style/IndentHash: - Enabled: false - -Style/AlignHash: - Enabled: false - -# From http://relaxed.ruby.style/ - -Style/Alias: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylealias - -Style/BeginBlock: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylebeginblock - -Style/BlockDelimiters: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters - -Style/Documentation: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledocumentation - -Style/DotPosition: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledotposition - -Style/DoubleNegation: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledoublenegation - -Style/EndBlock: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleendblock - -Style/FormatString: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleformatstring - -Style/IfUnlessModifier: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier - -Style/Lambda: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylelambda - -Style/ModuleFunction: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylemodulefunction - -Style/MultilineBlockChain: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain - -Style/NegatedIf: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylenegatedif - -Style/NegatedWhile: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile - -Style/ParallelAssignment: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleparallelassignment - -Style/PercentLiteralDelimiters: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters - -Style/PerlBackrefs: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs - -Style/Semicolon: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesemicolon - -Style/SignalException: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesignalexception - -Style/SingleLineBlockParams: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams - -Style/SingleLineMethods: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods - -Style/SpaceBeforeBlockBraces: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces - -Style/SpaceInsideParens: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens - -Style/SpecialGlobalVars: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars - -Style/StringLiterals: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylestringliterals - -Style/SymbolProc: - Enabled: false - -Style/WhileUntilModifier: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier - -Lint/AmbiguousRegexpLiteral: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral - -Lint/AssignmentInCondition: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition - -Lint/HandleExceptions: - Exclude: - - 'Rakefile' - -Metrics/AbcSize: - Enabled: false - -Metrics/BlockNesting: - Enabled: false - -Metrics/ClassLength: - Enabled: false - -Metrics/ModuleLength: - Enabled: false - -Metrics/CyclomaticComplexity: - Enabled: false - -Metrics/LineLength: - Enabled: false - -Metrics/MethodLength: - Enabled: false - -Metrics/ParameterLists: +RSpec/MultipleMemoizedHelpers: Enabled: false -Metrics/PerceivedComplexity: +RSpec/LetSetup: Enabled: false diff --git a/app/decorators/solidus_payment_method_by_zone/spree/payment_method_decorator.rb b/app/decorators/solidus_payment_method_by_zone/spree/payment_method_decorator.rb index 9c8ab91..a0aee10 100644 --- a/app/decorators/solidus_payment_method_by_zone/spree/payment_method_decorator.rb +++ b/app/decorators/solidus_payment_method_by_zone/spree/payment_method_decorator.rb @@ -1,9 +1,16 @@ # frozen_string_literal: true +<<<<<<< Updated upstream module SolidusPaymentMethodByZone module Spree module PaymentMethodDecorator extend ActiveSupport::Concern +======= +module Spree + module PaymentMethodDecorator + def self.prepended(base) + base.has_and_belongs_to_many :zones, join_table: 'spree_payment_method_zones' +>>>>>>> Stashed changes included do has_and_belongs_to_many :zones, join_table: 'spree_payment_method_zones' diff --git a/app/decorators/solidus_payment_method_by_zone/spree/zone_decorator.rb b/app/decorators/solidus_payment_method_by_zone/spree/zone_decorator.rb index e59b357..cfd8042 100644 --- a/app/decorators/solidus_payment_method_by_zone/spree/zone_decorator.rb +++ b/app/decorators/solidus_payment_method_by_zone/spree/zone_decorator.rb @@ -1,9 +1,17 @@ # frozen_string_literal: true +<<<<<<< Updated upstream module SolidusPaymentMethodByZone module Spree module ZoneDecorator extend ActiveSupport::Concern +======= +module Spree + module ZoneDecorator + def self.prepended(base) + base.has_and_belongs_to_many :payment_methods, join_table: 'spree_payment_method_zones' + end +>>>>>>> Stashed changes included do has_and_belongs_to_many :payment_methods, join_table: 'spree_payment_method_zones' diff --git a/config/routes.rb b/config/routes.rb index 53e2eeb..59d0244 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Spree::Core::Engine.routes.draw do # Add your extension routes here end diff --git a/db/migrate/20190208214252_solidus_payment_method_by_zone_create_payment_method_zones.rb b/db/migrate/20190208214252_solidus_payment_method_by_zone_create_payment_method_zones.rb index 0506b82..6748fa8 100644 --- a/db/migrate/20190208214252_solidus_payment_method_by_zone_create_payment_method_zones.rb +++ b/db/migrate/20190208214252_solidus_payment_method_by_zone_create_payment_method_zones.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SolidusPaymentMethodByZoneCreatePaymentMethodZones < SolidusSupport::Migration[5.0] def change create_table :spree_payment_method_zones do |t| diff --git a/lib/generators/solidus_payment_method_by_zone/install/install_generator.rb b/lib/generators/solidus_payment_method_by_zone/install/install_generator.rb index 357281b..5b682f6 100644 --- a/lib/generators/solidus_payment_method_by_zone/install/install_generator.rb +++ b/lib/generators/solidus_payment_method_by_zone/install/install_generator.rb @@ -1,16 +1,26 @@ +# frozen_string_literal: true + module SolidusPaymentMethodByZone module Generators class InstallGenerator < Rails::Generators::Base class_option :auto_run_migrations, type: :boolean, default: false def add_javascripts - append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_payment_method_by_zone\n" - append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_payment_method_by_zone\n" + append_file 'vendor/assets/javascripts/spree/frontend/all.js', + "//= require spree/frontend/solidus_payment_method_by_zone\n" + append_file 'vendor/assets/javascripts/spree/backend/all.js', + "//= require spree/backend/solidus_payment_method_by_zone\n" end def add_stylesheets - inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_payment_method_by_zone\n", before: /\*\//, verbose: true - inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_payment_method_by_zone\n", before: /\*\//, verbose: true + inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', + " *= require spree/frontend/solidus_payment_method_by_zone\n", + before: %r{\*/}, + verbose: true + inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', + " *= require spree/backend/solidus_payment_method_by_zone\n", + before: %r{\*/}, + verbose: true end def add_migrations @@ -18,11 +28,13 @@ def add_migrations end def run_migrations - run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) + run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?( + ask('Would you like to run the migrations now? [Y/n]') + ) if run_migrations run 'bundle exec rake db:migrate' else - puts 'Skipping rake db:migrate, don\'t forget to run it!' + Rails.logger 'Skipping rake db:migrate, don\'t forget to run it!' end end end diff --git a/lib/solidus_payment_method_by_zone.rb b/lib/solidus_payment_method_by_zone.rb index 897b92f..0cab6f0 100644 --- a/lib/solidus_payment_method_by_zone.rb +++ b/lib/solidus_payment_method_by_zone.rb @@ -1,4 +1,9 @@ +# frozen_string_literal: true + require 'solidus_core' +require 'solidus_backend' require 'solidus_support' require 'deface' + +require 'solidus_payment_method_by_zone/version' require 'solidus_payment_method_by_zone/engine' diff --git a/lib/solidus_payment_method_by_zone/engine.rb b/lib/solidus_payment_method_by_zone/engine.rb index f4165ec..0425a65 100644 --- a/lib/solidus_payment_method_by_zone/engine.rb +++ b/lib/solidus_payment_method_by_zone/engine.rb @@ -1,20 +1,18 @@ +# frozen_string_literal: true + +require 'solidus_payment_method_by_zone' + module SolidusPaymentMethodByZone class Engine < Rails::Engine - require 'spree/core' + include SolidusSupport::EngineExtensions + isolate_namespace ::Spree + engine_name 'solidus_payment_method_by_zone' # use rspec for tests config.generators do |g| g.test_framework :rspec end - - def self.activate - Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c| - Rails.configuration.cache_classes ? require(c) : load(c) - end - end - - config.to_prepare(&method(:activate).to_proc) end end diff --git a/lib/solidus_payment_method_by_zone/factories/state_factory.rb b/lib/solidus_payment_method_by_zone/factories/state_factory.rb index 7598e9b..9f22c84 100644 --- a/lib/solidus_payment_method_by_zone/factories/state_factory.rb +++ b/lib/solidus_payment_method_by_zone/factories/state_factory.rb @@ -1,6 +1,11 @@ # frozen_string_literal: true +<<<<<<< Updated upstream eval(ENV.fetch('FACTORY')).define do +======= + +FactoryBot.define do +>>>>>>> Stashed changes factory :state_ja, class: 'Spree::State' do transient do country_iso { 'MX' } diff --git a/lib/solidus_payment_method_by_zone/version.rb b/lib/solidus_payment_method_by_zone/version.rb index 29da5ab..a24fdef 100644 --- a/lib/solidus_payment_method_by_zone/version.rb +++ b/lib/solidus_payment_method_by_zone/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidusPaymentMethodByZone VERSION = '1.0.1' end diff --git a/solidus_payment_method_by_zone.gemspec b/solidus_payment_method_by_zone.gemspec index be8e6d3..eab2d2e 100644 --- a/solidus_payment_method_by_zone.gemspec +++ b/solidus_payment_method_by_zone.gemspec @@ -19,6 +19,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'solidus_core', '>= 2.2' s.add_runtime_dependency 'deface', '~> 1.0' +<<<<<<< Updated upstream s.add_development_dependency 'capybara' s.add_development_dependency 'poltergeist' s.add_development_dependency 'coffee-rails' @@ -34,4 +35,21 @@ Gem::Specification.new do |s| s.add_development_dependency 'selenium-webdriver' s.add_development_dependency 'solidus_support' s.add_development_dependency 'solidus_dev_support' +======= + s.files = files.grep_v(%r{^(test|spec|features)/}) + s.test_files = files.grep(%r{^(test|spec|features)/}) + s.bindir = 'exe' + s.executables = files.grep(%r{^exe/}) { |f| File.basename(f) } + s.require_paths = ['lib'] + + solidus_version = ['>= 2.6', '< 4'] + + s.add_dependency 'deface', '~> 1.0' + s.add_dependency 'solidus_core', solidus_version + s.add_dependency 'solidus_support', '~> 0.5' + + s.add_development_dependency 'solidus_backend', solidus_version + s.add_development_dependency 'solidus_dev_support', '~> 2.5' + s.add_development_dependency 'solidus_frontend', solidus_version +>>>>>>> Stashed changes end diff --git a/spec/features/admin/payment_methods_spec.rb b/spec/features/admin/payment_methods_spec.rb index 290a91e..f6c8444 100644 --- a/spec/features/admin/payment_methods_spec.rb +++ b/spec/features/admin/payment_methods_spec.rb @@ -5,9 +5,9 @@ describe 'Payment methods admin page', type: :feature, js: true do stub_authorization! - context 'when create new payment method' do - let!(:mexico) { create(:zone, name: 'Mexico') } + let!(:mexico) { create(:zone, name: 'Mexico') } + context 'when create new payment method' do before do visit spree.new_admin_payment_method_path end @@ -22,7 +22,7 @@ check 'Mexico' end click_on('Create') - expect(page).to have_content("successfully created!") + expect(page).to have_content('successfully created!') end end end diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 71b7773..862ccb2 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -7,11 +7,23 @@ let(:usa) { Spree::Country.find_by(iso: 'US') } let(:us_zone) { create(:zone) } let(:mx_zone) { create(:zone) } - let!(:us_payment_method) { create(:check_payment_method, name: 'US method', zones: [us_zone]) } - let!(:mx_payment_method) { create(:check_payment_method, name: 'MX method', zones: [mx_zone]) } + let(:us_payment_method) do + create( + :check_payment_method, + name: 'US method', + zones: [us_zone] + ) + end + let(:mx_payment_method) do + create( + :check_payment_method, + name: 'MX method', + zones: [mx_zone] + ) + end let(:order) { create(:order_with_totals) } - before(:each) do + before do order.line_items << create(:line_item) us_zone.members.create(zoneable: usa) mx_zone.members.create(zoneable: mx) @@ -19,58 +31,58 @@ describe 'available_payment_methods' do it 'includes frontend payment methods' do - payment_method = Spree::PaymentMethod::Check.create!({ - name: 'Fake', - active: true, - available_to_users: true, - available_to_admin: false - }) + payment_method = Spree::PaymentMethod::Check.create!( + { + name: 'Fake', + active: true, + available_to_users: true, + available_to_admin: false + } + ) expect(order.available_payment_methods).to include(payment_method) end it 'must not include payment methods for Mexico in addresses of US' do - expect(order.available_payment_methods).to include(us_payment_method) expect(order.available_payment_methods).not_to include(mx_payment_method) end + end - context 'with mexican address' do - let(:state) { create(:state_ja, country: mx) } - let(:address) { create(:address, city: 'Leon', state: state) } - let!(:order) { create(:order_with_totals, ship_address: address) } + describe 'with mexican address' do + let(:state) { create(:state_ja, country: mx) } + let(:address) { create(:address, city: 'Leon', state: state) } + let!(:order) { create(:order_with_totals, ship_address: address) } - it 'must include mx payment method' do - expect(order.available_payment_methods).not_to include(us_payment_method) - expect(order.available_payment_methods).to include(mx_payment_method) - end + it 'must include mx payment method' do + expect(order.available_payment_methods).to include(mx_payment_method) + end - context 'with address matching more than one zone with same payment method' do - let(:ja_zone) { create(:zone) } + context 'with address matching more than one zone with same payment method' do + let(:ja_zone) { create(:zone) } - before do - ja_zone.members.create(zoneable: state) - mx_payment_method.zones.push(ja_zone) - mx_payment_method.save - end + before do + ja_zone.members.create(zoneable: state) + mx_payment_method.zones.push(ja_zone) + mx_payment_method.save + end - it 'must include unique payment method' do - expect(order.available_payment_methods.count).to eq(1) - end + it 'must include unique payment method' do + expect(order.available_payment_methods.count).to eq(1) + end - it 'must include mx payment method' do - expect(order.available_payment_methods).to include(mx_payment_method) - end + it 'must include mx payment method' do + expect(order.available_payment_methods).to include(mx_payment_method) end end + end - context 'with address not matching zones' do - let(:ar) { create(:country, iso: 'AR') } - let(:caba) { create(:state_ja, country: ar, state_code: 'C') } - let(:address) { create(:address, city: 'Recoleta', state: caba) } - let!(:order) { create(:order_with_totals, ship_address: address) } + context 'with address not matching zones' do + let(:ar) { create(:country, iso: 'AR') } + let(:caba) { create(:state_ja, country: ar, state_code: 'C') } + let(:address) { create(:address, city: 'Recoleta', state: caba) } + let!(:order) { create(:order_with_totals, ship_address: address) } - it 'must not return any payment method' do - expect(order.available_payment_methods.count).to eq(0) - end + it 'must not return any payment method' do + expect(order.available_payment_methods.count).to eq(0) end end end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb new file mode 100644 index 0000000..47feb4f --- /dev/null +++ b/spec/support/capybara.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +Capybara.register_driver :headless_firefox do |app| + Capybara::Selenium::Driver.load_selenium + browser_options = ::Selenium::WebDriver::Firefox::Options.new + browser_options.args << '-headless' + Capybara::Selenium::Driver.new(app, browser: :firefox, options: browser_options) +end + +Capybara.register_driver :headless_chrome do |app| + Capybara::Selenium::Driver.load_selenium + browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts| + opts.args << '--headless' + opts.args << '--disable-gpu' if Gem.win_platform? + # Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary + opts.args << '--disable-site-isolation-trials' + end + Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options) +end + +Capybara.javascript_driver = :headless_firefox diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb new file mode 100644 index 0000000..82d657c --- /dev/null +++ b/spec/support/database_cleaner.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'database_cleaner' + +RSpec.configure do |config| + # Ensure Suite is set to use transactions for speed. + config.before(:suite) do + DatabaseCleaner.strategy = :transaction + DatabaseCleaner.clean_with :truncation + end + + # Before each spec check if it is a Javascript test and switch between using + # database transactions or not where necessary. + config.before do + DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction + DatabaseCleaner.start + end + + # After each spec clean the database. + config.after do + DatabaseCleaner.clean + end +end