Skip to content

Commit

Permalink
Set role correctly. (#188)
Browse files Browse the repository at this point in the history
Fixes #187
  • Loading branch information
oneiros authored Nov 2, 2023
1 parent 3d7cc15 commit b69d7d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create
@user = User.new(user_params)

if User.none?
@user.admin = true
@user.role = "admin"
end

if @user.save
Expand Down
21 changes: 21 additions & 0 deletions test/integration/users_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "test_helper"

class UsersTest < ActionDispatch::IntegrationTest
test "when no users exist an unauthenticated user can create an admin" do
User.delete_all

assert_difference "User.count" do
post users_path, params: { user: FactoryBot.attributes_for(:user) }

assert_redirected_to root_path
end

assert User.last.admin?
end

test "when users exists an unauthenticated user cannot create any users" do
post users_path, params: { user: FactoryBot.attributes_for(:user) }

assert_redirected_to login_path
end
end

0 comments on commit b69d7d6

Please sign in to comment.