Skip to content

Commit

Permalink
fix codefactor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
lassesteffen committed Dec 28, 2018
1 parent 50914b7 commit d36bdb7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def update
def update_role
@user = User.find(params[:id])
@user.update(role: params[:role])
redirect_to users_path
redirect_to users_path
end

private
Expand Down
7 changes: 4 additions & 3 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
module UsersHelper
def last_admin?(user)
user.admin? &&
is_current_user?(user) &&
only_one_admin?
current_user?(user) &&
only_one_admin?
end

def only_one_admin?
User.all.select(&:admin?).size == 1
end

def is_current_user?(user)
def current_user?(user)
user == current_user
end
end
2 changes: 1 addition & 1 deletion app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<td>Name</td>
<td><%= @user.name %></td>
</tr>
<% if @user == current_user %>
<% if current_user?(@user) %>
<tr>
<td><%= User.human_attribute_name('ssh_key') %></td>
<td><%= f.text_area :ssh_key, class: 'form-control', rows: '8', id: 'sshKeyField' %></td>
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
factory :user do
# https://github.com/stympy/faker/blob/master/doc/v1.9.1/internet.md#fakerinternet
email { Faker::Internet.safe_email }
password { Faker::Internet.password(min_length = 10, max_length = 20, mix_case = true, special_chars = true) }
password { Faker::Internet.password(10, 20, true, true) }
password_confirmation { password }
first_name { 'Max' }
last_name { 'Mustermann' }
Expand Down
8 changes: 4 additions & 4 deletions spec/features/users/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
before do
@button_user = page.find(id: "btn-user-#{user.id}")
@button_employee = page.find(id: "btn-employee-#{user.id}")
@button_admin= page.find(id: "btn-admin-#{user.id}")
@button_admin = page.find(id: "btn-admin-#{user.id}")
end

it 'shows that the role is user' do
Expand Down Expand Up @@ -65,7 +65,7 @@
before do
@button_user = page.find(id: "btn-user-#{employee.id}")
@button_employee = page.find(id: "btn-employee-#{employee.id}")
@button_admin= page.find(id: "btn-admin-#{employee.id}")
@button_admin = page.find(id: "btn-admin-#{employee.id}")
end

it 'shows that the role is employee' do
Expand Down Expand Up @@ -111,7 +111,7 @@
before do
@button_user = page.find(id: "btn-user-#{admin.id}")
@button_employee = page.find(id: "btn-employee-#{admin.id}")
@button_admin= page.find(id: "btn-admin-#{admin.id}")
@button_admin = page.find(id: "btn-admin-#{admin.id}")
end

it 'shows that the role is admin' do
Expand Down Expand Up @@ -170,7 +170,7 @@
visit users_path
@button_user = page.find(id: "btn-user-#{admin.id}")
@button_employee = page.find(id: "btn-employee-#{admin.id}")
@button_admin= page.find(id: "btn-admin-#{admin.id}")
@button_admin = page.find(id: "btn-admin-#{admin.id}")
end

it 'disables no button' do
Expand Down
1 change: 0 additions & 1 deletion spec/views/users/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
let(:user) { FactoryBot.create :user }
let(:current_user) { FactoryBot.create :user }


before do
allow(view).to receive(:current_user).and_return(current_user)
assign(:user, user)
Expand Down

0 comments on commit d36bdb7

Please sign in to comment.