Skip to content

Commit

Permalink
Showing microposts
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed Aug 30, 2010
1 parent 600aaa5 commit 673eb05
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def index

def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(:page => params[:page])
@title = @user.name
end

Expand Down
8 changes: 8 additions & 0 deletions app/views/microposts/_micropost.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<tr>
<td class="micropost">
<span class="content"><%= micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
</td>
</tr>
7 changes: 7 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
<%= gravatar_for @user %>
<%= @user.name %>
</h1>
<% if @user.microposts.any? %>
<table class="microposts" summary="User microposts">
<%= render @microposts %>
</table>
<%= will_paginate @microposts %>
<% end %>
</td>
<td class="sidebar round">
<strong>Name</strong> <%= @user.name %><br />
<strong>URL</strong> <%= link_to user_path(@user), @user %>
<strong>Microposts</strong> <%= @user.microposts.count %>
</td>
</tr>
</table>
Expand Down
7 changes: 6 additions & 1 deletion lib/tasks/sample_data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ namespace :db do
:password => password,
:password_confirmation => password)
end

User.all(:limit => 6).each do |user|
50.times do
user.microposts.create!(:content => Faker::Lorem.sentence(5))
end
end
end

end
59 changes: 58 additions & 1 deletion public/stylesheets/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,61 @@ ul.users {

ul.users li {
list-style: none;
}
}

/* Micropost styling */

h1.micropost {
margin-bottom: 0.3em;
}

table.microposts {
margin-top: 1em;
}

table.microposts tr {
height: 70px;
}

table.microposts tr td.gravatar {
border-top: 1px solid #ccc;
vertical-align: top;
width: 50px;
}

table.microposts tr td.micropost {
border-top: 1px solid #ccc;
vertical-align: top;
padding-top: 10px;
}

table.microposts tr td.micropost span.timestamp {
display: block;
font-size: 85%;
color: #666;
}

div.user_info img {
padding-right: 0.1em;
}

div.user_info a {
text-decoration: none;
}

div.user_info span.user_name {
position: absolute;
}

div.user_info span.microposts {
font-size: 80%;
}

form.new_micropost {
margin-bottom: 2em;
}

form.new_micropost textarea {
height: 4em;
margin-bottom: 0;
}
21 changes: 21 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@
response.should have_selector('td>a', :content => user_path(@user),
:href => user_path(@user))
end

it "should show the user's microposts" do
mp1 = Factory(:micropost, :user => @user, :content => "Foo bar")
mp2 = Factory(:micropost, :user => @user, :content => "Baz quux")
get :show, :id => @user
response.should have_selector('span.content', :content => mp1.content)
response.should have_selector('span.content', :content => mp2.content)
end

it "should paginate microposts" do
35.times { Factory(:micropost, :user => @user, :content => "foo") }
get :show, :id => @user
response.should have_selector('div.pagination')
end

it "should display the micropost count" do
10.times { Factory(:micropost, :user => @user, :content => "foo") }
get :show, :id => @user
response.should have_selector('td.sidebar',
:content => @user.microposts.count.to_s)
end
end

describe "GET 'new'" do
Expand Down

0 comments on commit 673eb05

Please sign in to comment.