diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 3b14eed..7e99f8e 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,7 +1,12 @@
class UsersController < ApplicationController
- before_filter :authenticate, :only => [:edit, :update]
+ before_filter :authenticate, :only => [:index, :edit, :update]
before_filter :correct_user, :only => [:edit, :update]
+ def index
+ @users = User.all
+ @title = "All users"
+ end
+
def show
@user = User.find(params[:id])
@title = @user.name
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb
index 4f44809..bc8fd78 100644
--- a/app/views/layouts/_header.html.erb
+++ b/app/views/layouts/_header.html.erb
@@ -5,6 +5,7 @@
<%= link_to "Home", root_path %>
<% if signed_in? %>
<%= link_to "Profile", current_user %>
+ <%= link_to "Users", users_path %>
<%= link_to "Settings", edit_user_path(current_user) %>
<% end %>
<%= link_to "Help", help_path %>
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb
new file mode 100644
index 0000000..7346a87
--- /dev/null
+++ b/app/views/users/index.html.erb
@@ -0,0 +1,10 @@
+All users
+
+
+ <% @users.each do |user| %>
+ -
+ <%= gravatar_for user, :size => 30 %>
+ <%= link_to user.name, user %>
+
+ <% end %>
+
\ No newline at end of file
diff --git a/public/stylesheets/custom.css b/public/stylesheets/custom.css
index 115cdfe..1b3f968 100644
--- a/public/stylesheets/custom.css
+++ b/public/stylesheets/custom.css
@@ -182,3 +182,11 @@ div.field, div.actions {
font-size: 12px;
list-style: square;
}
+
+ul.users {
+ margin-top: 1em;
+}
+
+ul.users li {
+ list-style: none;
+}
\ No newline at end of file
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 94b0b08..1171014 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -3,6 +3,42 @@
describe UsersController do
render_views
+ describe "GET 'index'" do
+
+ describe "for non-signed-in users" do
+ it "should deny access" do
+ get :index
+ response.should redirect_to(signin_path)
+ end
+ end
+
+ describe "for signed-in-users" do
+
+ before(:each) do
+ @user = test_sign_in(Factory(:user))
+ Factory(:user, :email => "another@example.com")
+ Factory(:user, :email => "another@example.net")
+ end
+
+ it "should be successful" do
+ get :index
+ response.should be_success
+ end
+
+ it "should have the right title" do
+ get :index
+ response.should have_selector('title', :content => "All users")
+ end
+
+ it "should have an element for each user" do
+ get :index
+ User.all.each do |user|
+ response.should have_selector('li', :content => user.name)
+ end
+ end
+ end
+ end
+
describe "GET 'show'" do
before(:each) do
diff --git a/spec/requests/layout_links_spec.rb b/spec/requests/layout_links_spec.rb
index de121ce..b5be9f7 100644
--- a/spec/requests/layout_links_spec.rb
+++ b/spec/requests/layout_links_spec.rb
@@ -81,5 +81,11 @@
response.should have_selector("a", :href => edit_user_path(@user),
:content => "Settings")
end
+
+ it "should have a users link" do
+ visit root_path
+ response.should have_selector("a", :href => users_path,
+ :content => "Users")
+ end
end
end