Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Comment order in posts/show #155

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  app/controllers/posts_controller.rb
@@ -18,6 +18,7 @@ def index
# GET /posts/1.json
def show
@post = Post.find(params[:id])
+ @comments = @post.comments
respond_to do |format|
format.html # show.html.haml
View
2  app/models/comment.rb
@@ -3,6 +3,8 @@ class Comment < ActiveRecord::Base
belongs_to :author, :class_name => 'Member'
belongs_to :post
+ default_scope order("created_at asc")
+
after_create do
recipient = self.post.author.id
sender = self.author.id
View
6 app/views/posts/show.html.haml
@@ -12,10 +12,10 @@
%a{:name => "comments"}
-- if @post.comments.length > 0
+- if @comments
%h2
- =pluralize(@post.comments.length, "comment")
- - @post.comments.each do |c|
+ =pluralize(@comments.length, "comment")
+ - @comments.each do |c|
= render :partial => "comments/single", :locals => { :comment => c }
- else
View
21 spec/views/posts/show.html.haml_spec.rb
@@ -46,6 +46,7 @@
@post = assign(:post,
FactoryGirl.create(:html_post, :author => @author))
@comment = FactoryGirl.create(:comment, :post => @post)
+ @comments = @post.comments
render
end
@@ -62,6 +63,26 @@
end
end
+ context "when there is more than one comment" do
+ before(:each) do
+ @post = assign(:post,
+ FactoryGirl.create(:html_post, :author => @author))
+ @comment1 = FactoryGirl.create(:comment, :post => @post, :body => "F1rst!!!",
+ :created_at => Date.new(2010, 5, 17))
+ @comment3 = FactoryGirl.create(:comment, :post => @post, :body => "Th1rd!!!",
+ :created_at => Date.new(2012, 5, 17))
+ @comment4 = FactoryGirl.create(:comment, :post => @post, :body => "F0urth!!!")
+ @comment2 = FactoryGirl.create(:comment, :post => @post, :body => "S3c0nd!!1!",
+ :created_at => Date.new(2011, 5, 17))
+ @comments = @post.comments
+ render
+ end
+
+ it "shows the oldest comments first" do
+ rendered.should contain /#{@comment1.body}.*#{@comment2.body}.*#{@comment3.body}.*#{@comment4.body}/m
+ end
+ end
+
context "forum post" do
it "shows forum name" do
@post = assign(:post,
Something went wrong with that request. Please try again.