Skip to content

Commit

Permalink
Fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-gracia committed Oct 4, 2023
1 parent 40fd76f commit 199b6a0
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/controllers/system_admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def edit

def create
@user = User.new(user_params)
@user.roles = []
@user.roles = []
params[:user][:role_ids].each do |role_id|
@user.add_role(Role.find(role_id).name) if role_id.present?
end
Expand All @@ -31,7 +31,7 @@ def create

def update
if @user.update(user_params)
@user.roles = []
@user.roles = []
params[:user][:role_ids].each do |role_id|
@user.add_role(Role.find(role_id).name) if role_id.present?
end
Expand Down
15 changes: 7 additions & 8 deletions app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@
# resource_id :bigint
#
class Role < ApplicationRecord
ROLES_LIST = [:spectator, :servant, :manager, :admin, :super_admin]
ROLES_LIST = %i[spectator servant manager admin super_admin].freeze

has_many_through :users, :users_roles

has_and_belongs_to_many :users, :join_table => :users_roles

belongs_to :resource,
:polymorphic => true,
:optional => true

polymorphic: true,
optional: true

validates :resource_type,
:inclusion => { :in => Rolify.resource_types },
:allow_nil => true
inclusion: { in: Rolify.resource_types },
allow_nil: true

scopify
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class User < ApplicationRecord
rolify
audited
devise :omniauthable, omniauth_providers: %i[azure_activedirectory_v2]
end
end
2 changes: 1 addition & 1 deletion config/initializers/rolify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
# config.use_dynamic_shortcuts

# Configuration to remove roles from database once the last resource is removed. Default is: true
# config.remove_role_if_empty = false
end
10 changes: 5 additions & 5 deletions db/migrate/20231003024901_rolify_create_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ class RolifyCreateRoles < ActiveRecord::Migration[7.0]
def change
create_table(:roles) do |t|
t.string :name
t.references :resource, :polymorphic => true
t.references :resource, polymorphic: true

t.timestamps
end

create_table(:users_roles, :id => false) do |t|
create_table(:users_roles, id: false) do |t|
t.references :user
t.references :role
end
add_index(:roles, [ :name, :resource_type, :resource_id ])
add_index(:users_roles, [ :user_id, :role_id ])

add_index(:roles, %i[name resource_type resource_id])
add_index(:users_roles, %i[user_id role_id])
end
end
2 changes: 1 addition & 1 deletion spec/factories/roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
#
FactoryBot.define do
factory :role do

name { "Admin" }
end
end
4 changes: 2 additions & 2 deletions spec/models/role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# updated_at :datetime not null
# resource_id :bigint
#
require 'rails_helper'
require "rails_helper"

RSpec.describe Role, type: :model do
RSpec.describe Role do
it { is_expected.to have_db_column(:name) }
end

0 comments on commit 199b6a0

Please sign in to comment.