Skip to content

Commit

Permalink
Working index page
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed Aug 29, 2010
1 parent 7d06bcb commit 8e52fe8
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<li><%= link_to "Home", root_path %></li>
<% if signed_in? %>
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Users", users_path %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<% end %>
<li><%= link_to "Help", help_path %></li>
Expand Down
10 changes: 10 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>All users</h1>

<ul class="users">
<% @users.each do |user| %>
<li>
<%= gravatar_for user, :size => 30 %>
<%= link_to user.name, user %>
</li>
<% end %>
</ul>
8 changes: 8 additions & 0 deletions public/stylesheets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
36 changes: 36 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => "[email protected]")
Factory(:user, :email => "[email protected]")
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
Expand Down
6 changes: 6 additions & 0 deletions spec/requests/layout_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8e52fe8

Please sign in to comment.