diff --git a/.rubocop.yml b/.rubocop.yml index 0dcb27aa..10629c3b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,7 @@ +require: + - rubocop-performance + - rubocop-rails + # Relaxed.Ruby.Style AllCops: @@ -5,7 +9,12 @@ AllCops: - 'spec/dummy/**/*' - 'app/overrides/*' - 'bin/**' - TargetRubyVersion: 2.2 + TargetRubyVersion: 2.3 + + +Rails/Output: + Exclude: + - 'db/default/users.rb' # Sometimes I believe this reads better # This also causes spacing issues on multi-line fixes @@ -48,9 +57,6 @@ Style/WordArray: Style/ConditionalAssignment: Enabled: false -Performance/Count: - Enabled: false - Style/RaiseArgs: Enabled: false diff --git a/db/default/users.rb b/db/default/users.rb index beeaf725..ea228e06 100644 --- a/db/default/users.rb +++ b/db/default/users.rb @@ -46,7 +46,7 @@ def create_admin_user load 'spree/user.rb' - if Spree::User.find_by_email(email) + if Spree::User.find_by(email: email) puts "\nWARNING: There is already a user with the email: #{email}, so no account changes were made. If you wish to create an additional admin user, please run rake spree_auth:admin:create again with a different email.\n\n" else admin = Spree::User.new(attributes) diff --git a/lib/controllers/frontend/spree/checkout_controller_decorator.rb b/lib/controllers/frontend/spree/checkout_controller_decorator.rb index e68a5d27..4435fc72 100644 --- a/lib/controllers/frontend/spree/checkout_controller_decorator.rb +++ b/lib/controllers/frontend/spree/checkout_controller_decorator.rb @@ -3,7 +3,7 @@ module Spree module CheckoutControllerDecorator def self.prepended(base) - base.before_action :check_registration, except: [:registration, :update_registration] + base.before_action :check_registration, except: [:registration, :update_registration] base.before_action :check_authorization # This action builds some associations on the order, ex. addresses, which we @@ -16,7 +16,7 @@ def registration end def update_registration - if params[:order][:email] =~ Devise.email_regexp && current_order.update_attributes(email: params[:order][:email]) + if params[:order][:email] =~ Devise.email_regexp && current_order.update(email: params[:order][:email]) redirect_to spree.checkout_path else flash[:registration_error] = t(:email_is_invalid, scope: [:errors, :messages]) @@ -59,7 +59,7 @@ def already_registered? end def guest_authenticated? - current_order.try!(:email).present? && + current_order&.email.present? && Spree::Config[:allow_guest_checkout] end diff --git a/lib/controllers/frontend/spree/users_controller.rb b/lib/controllers/frontend/spree/users_controller.rb index 6f1b97bc..058694b2 100644 --- a/lib/controllers/frontend/spree/users_controller.rb +++ b/lib/controllers/frontend/spree/users_controller.rb @@ -26,7 +26,7 @@ def create end def update - if @user.update_attributes(user_params) + if @user.update(user_params) spree_current_user.reload if params[:user][:password].present? @@ -48,7 +48,7 @@ def user_params end def load_object - @user ||= Spree::User.find_by(id: spree_current_user && spree_current_user.id) + @user ||= Spree::User.find_by(id: spree_current_user&.id) authorize! params[:action].to_sym, @user end diff --git a/lib/spree/authentication_helpers.rb b/lib/spree/authentication_helpers.rb index 8a2bcb85..d62a20c4 100644 --- a/lib/spree/authentication_helpers.rb +++ b/lib/spree/authentication_helpers.rb @@ -19,17 +19,9 @@ def spree_current_user end if SolidusSupport.frontend_available? - def spree_login_path - spree.login_path - end - - def spree_signup_path - spree.signup_path - end - - def spree_logout_path - spree.logout_path - end + delegate :login_path, :signup_path, :logout_path, + to: :spree, + prefix: :spree end end end diff --git a/solidus_auth_devise.gemspec b/solidus_auth_devise.gemspec index 3ae5809d..6bcbd2c7 100644 --- a/solidus_auth_devise.gemspec +++ b/solidus_auth_devise.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.author = 'Solidus Team' s.email = 'contact@solidus.io' - s.required_ruby_version = ">= 2.2" + s.required_ruby_version = ">= 2.3" s.license = 'BSD-3' s.files = `git ls-files`.split("\n") @@ -42,7 +42,9 @@ Gem::Specification.new do |s| s.add_development_dependency "gem-release", "~> 2.0" s.add_development_dependency "poltergeist", "~> 1.5" s.add_development_dependency "rspec-rails", "~> 3.3" - s.add_development_dependency "rubocop", "0.68" + s.add_development_dependency "rubocop", "~> 0.71" + s.add_development_dependency "rubocop-performance", "~> 1.4" + s.add_development_dependency "rubocop-rails", "~> 2.2" s.add_development_dependency "sass-rails" s.add_development_dependency "shoulda-matchers", "~> 3.1" s.add_development_dependency "simplecov", "~> 0.14" diff --git a/spec/controllers/spree/checkout_controller_spec.rb b/spec/controllers/spree/checkout_controller_spec.rb index c835e1ff..f0a1bec6 100644 --- a/spec/controllers/spree/checkout_controller_spec.rb +++ b/spec/controllers/spree/checkout_controller_spec.rb @@ -81,8 +81,7 @@ context '#update' do context 'when in the confirm state' do before do - order.update_column(:email, 'spree@example.com') - order.update_column(:state, 'confirm') + order.update(email: 'spree@example.com', state: 'confirm') # So that the order can transition to complete successfully allow(order).to receive(:payment_required?) { false } diff --git a/spec/controllers/spree/user_registrations_controller_spec.rb b/spec/controllers/spree/user_registrations_controller_spec.rb index 9413bbcd..b258b22a 100644 --- a/spec/controllers/spree/user_registrations_controller_spec.rb +++ b/spec/controllers/spree/user_registrations_controller_spec.rb @@ -57,7 +57,7 @@ it 'assigns orders with the correct token and no user present' do order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil) subject - user = Spree::User.find_by_email('foobar@example.com') + user = Spree::User.find_by(email: 'foobar@example.com') order.reload expect(order.user_id).to eq user.id diff --git a/spec/factories/confirmed_user.rb b/spec/factories/confirmed_user.rb index 03b4342d..190152b9 100644 --- a/spec/factories/confirmed_user.rb +++ b/spec/factories/confirmed_user.rb @@ -2,8 +2,8 @@ FactoryBot.define do factory :confirmed_user, parent: :user do - confirmed_at { Time.now } - confirmation_sent_at { Time.now } + confirmed_at { Time.zone.now } + confirmation_sent_at { Time.zone.now } confirmation_token { "12345" } end end diff --git a/spec/features/checkout_spec.rb b/spec/features/checkout_spec.rb index 125a4616..6a888f5d 100644 --- a/spec/features/checkout_spec.rb +++ b/spec/features/checkout_spec.rb @@ -17,7 +17,7 @@ background do @product = create(:product, name: 'RoR Mug') - @product.master.stock_items.first.update_column(:count_on_hand, 1) + @product.master.stock_items.first.set_count_on_hand(1) # Bypass gateway error on checkout | ..or stub a gateway Spree::Config[:allow_checkout_on_gateway_error] = true @@ -177,7 +177,7 @@ click_button 'Place Order' expect(page).to have_text 'Your order has been processed successfully' - expect(Spree::Order.first.user).to eq Spree::User.find_by_email('email@person.com') + expect(Spree::Order.first.user).to eq Spree::User.find_by(email: 'email@person.com') end end end