Skip to content

Commit 668ce24

Browse files
author
Ryan Bigg
committed
Section 7.4.5: Add the ability to create admin users through the admin backend
1 parent 7a605e7 commit 668ce24

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

ticketee/app/controllers/admin/users_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def user_params
2626
params.require(:user).permit(:name,
2727
:email,
2828
:password,
29-
:password_confirmation)
29+
:password_confirmation,
30+
:admin)
3031
end
3132
end

ticketee/app/models/user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ class User < ActiveRecord::Base
33
# :confirmable, :lockable, :timeoutable and :omniauthable
44
devise :database_authenticatable, :registerable,
55
:recoverable, :rememberable, :trackable, :validatable
6+
7+
def to_s
8+
"#{email} (#{admin? ? "Admin" : "User"})"
9+
end
610
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<%= simple_form_for [:admin, @user] do |f| %>
22
<%= f.input :email %>
33
<%= f.input :password %>
4+
5+
<%= f.input :admin, label: "Is an admin?" %>
46

57
<%= f.button :submit %>
68
<% end %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= link_to "New User", new_admin_user_path, class: "new" %>
22
<ul>
33
<% @users.each do |user| %>
4-
<li><%= link_to user.email, [:admin, user] %></li>
4+
<li><%= link_to user, [:admin, user] %></li>
55
<% end %>
66
</ul>

ticketee/spec/features/admin/creating_users_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@
1717
click_button "Create User"
1818
expect(page).to have_content("User has been created.")
1919
end
20+
21+
scenario "Creating an admin user" do
22+
fill_in "Email", with: "[email protected]"
23+
fill_in "Password", with: "password"
24+
check "Is an admin?"
25+
click_button "Create User"
26+
expect(page).to have_content("User has been created")
27+
expect(page).to have_content("[email protected] (Admin)")
28+
end
2029
end

0 commit comments

Comments
 (0)