Skip to content

Commit

Permalink
Comments are now showed from oldest to newest. Includes test
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsecajavier committed Nov 26, 2012
1 parent e57afac commit b09fd10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/posts_controller.rb
Expand Up @@ -8,7 +8,7 @@ def index

def show
@post = Post.find_by_id(params[:id])
@comments = @post.comments.order("created_at DESC")
@comments = @post.comments.order("created_at")

@comment = @post.comments.build
end
Expand Down
5 changes: 4 additions & 1 deletion spec/controllers/posts_controller_spec.rb
Expand Up @@ -13,12 +13,15 @@
response.should render_template(:index)
end

it "should be presented with a requested post and its comments in the show action" do
it "should be presented with a requested post and its comments (from oldest to newest) in the show action" do
existing_post = create(:post)
4.times { create(:comment, post_id: existing_post.id) }
get :show, id: existing_post.id
assigns[:post].should == existing_post
assigns[:comments].count.should eql(4)
assigns[:comments].map(&:id).should eql(
assigns[:comments].sort { |x, y| x[:id] <=> y[:id] }.map(&:id)
)
response.should render_template(:show)
end

Expand Down

0 comments on commit b09fd10

Please sign in to comment.