From 2221710bdf2cb289101642d6aec5e7ff579c8e03 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sat, 2 Feb 2019 09:27:42 +0500 Subject: [PATCH] Fix code style --- .rubocop.yml | 4 ++++ app/models/account.rb | 4 +++- app/models/role.rb | 3 ++- spec/models/account_spec.rb | 5 +++-- spec/models/role_spec.rb | 1 + 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index f5f620c..b57bdad 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -53,6 +53,10 @@ Rails/LexicallyScopedActionFilter: Exclude: - 'app/controllers/application_controller.rb' +Rails/SkipsModelValidations: + Whitelist: + - update_all + Style/AndOr: EnforcedStyle: conditionals diff --git a/app/models/account.rb b/app/models/account.rb index 2014b52..b7d2733 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -14,7 +14,8 @@ class Account < ApplicationRecord has_many :account_roles, -> { where deleted_at: nil }, - dependent: :restrict_with_exception + inverse_of: :account, + dependent: :restrict_with_exception has_many :roles, through: :account_roles @@ -69,6 +70,7 @@ class Account < ApplicationRecord def remove_role(role_name, resource = nil) role = self.class.role_class.find_by name: role_name, resource: resource return if role.nil? + account_roles.where(role: role).update_all(deleted_at: Time.zone.now) end diff --git a/app/models/role.rb b/app/models/role.rb index c71ed6a..4f9d55a 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -7,7 +7,8 @@ class Role < ApplicationRecord has_many :account_roles, -> { where deleted_at: nil }, - dependent: :restrict_with_exception + inverse_of: :role, + dependent: :restrict_with_exception has_many :accounts, through: :account_roles diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 10db0d4..9e8487d 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -16,6 +16,7 @@ RSpec.describe Account do it do is_expected.to \ have_many(:account_roles) + .inverse_of(:account) .dependent(:restrict_with_exception) end @@ -178,11 +179,11 @@ RSpec.describe Account do end specify do - expect { result }.not_to change { Role.count } + expect { result }.not_to(change { Role.count }) end specify do - expect { result }.not_to change { AccountRole.count } + expect { result }.not_to(change { AccountRole.count }) end specify do diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index 3f33662..bfad00d 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -8,6 +8,7 @@ RSpec.describe Role do it do is_expected.to \ have_many(:account_roles) + .inverse_of(:role) .dependent(:restrict_with_exception) end