Skip to content

Commit

Permalink
Merge pull request #163 from nebulab/kennyadsl/move-rubocop-performan…
Browse files Browse the repository at this point in the history
…ce-cops

Extension maintenance
  • Loading branch information
spaghetticode committed Aug 2, 2019
2 parents 9ba6d17 + b5df88c commit 7a2703e
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 30 deletions.
14 changes: 10 additions & 4 deletions .rubocop.yml
@@ -1,11 +1,20 @@
require:
- rubocop-performance
- rubocop-rails

# Relaxed.Ruby.Style

AllCops:
Exclude:
- '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
Expand Down Expand Up @@ -48,9 +57,6 @@ Style/WordArray:
Style/ConditionalAssignment:
Enabled: false

Performance/Count:
Enabled: false

Style/RaiseArgs:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion db/default/users.rb
Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand All @@ -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])
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/controllers/frontend/spree/users_controller.rb
Expand Up @@ -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?
Expand All @@ -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

Expand Down
14 changes: 3 additions & 11 deletions lib/spree/authentication_helpers.rb
Expand Up @@ -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
6 changes: 4 additions & 2 deletions solidus_auth_devise.gemspec
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions spec/controllers/spree/checkout_controller_spec.rb
Expand Up @@ -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 }
Expand Down
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/confirmed_user.rb
Expand Up @@ -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
4 changes: 2 additions & 2 deletions spec/features/checkout_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7a2703e

Please sign in to comment.