From 259c1e1731fafdb855028fb6b2cb3f88596ea8fd Mon Sep 17 00:00:00 2001 From: Cesy Avon Date: Thu, 2 Jun 2016 14:10:18 +0000 Subject: [PATCH 1/2] Fix #476 show edited and posted date on posts and comments --- app/views/comments/_single.html.haml | 7 +- app/views/posts/_single.html.haml | 7 +- spec/views/posts/_single.html.haml_spec.rb | 75 ++++++++++++++++++++-- 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/app/views/comments/_single.html.haml b/app/views/comments/_single.html.haml index af6c328e5..895002b1e 100644 --- a/app/views/comments/_single.html.haml +++ b/app/views/comments/_single.html.haml @@ -5,10 +5,13 @@ = render :partial => "members/avatar", :locals => { :member => comment.author } .col-md-11 .comment-meta - = (comment.created_at == comment.updated_at) ? 'Posted by' : 'Edited by' + Posted by = link_to comment.author.login_name, member_path(comment.author) on - = (comment.created_at == comment.updated_at) ? comment.created_at : comment.updated_at + = comment.created_at + - if comment.updated_at > comment.created_at + and edited at + = comment.updated_at .comment-body :growstuff_markdown diff --git a/app/views/posts/_single.html.haml b/app/views/posts/_single.html.haml index 44750ceac..3ba1e6194 100644 --- a/app/views/posts/_single.html.haml +++ b/app/views/posts/_single.html.haml @@ -9,13 +9,16 @@ .post-meta %p - = (post.created_at == post.updated_at) ? 'Posted by' : 'Edited by' + Posted by = link_to post.author.login_name, member_path(post.author) - if post.forum in = link_to post.forum, post.forum on - = (post.created_at == post.updated_at) ? post.created_at : post.updated_at + = post.created_at + - if post.updated_at > post.created_at + and edited at + = post.updated_at .post-body :growstuff_markdown diff --git a/spec/views/posts/_single.html.haml_spec.rb b/spec/views/posts/_single.html.haml_spec.rb index 75a57b99c..b3a9c0dd9 100644 --- a/spec/views/posts/_single.html.haml_spec.rb +++ b/spec/views/posts/_single.html.haml_spec.rb @@ -129,8 +129,75 @@ describe "posts/_single" do end end + + context "when post has been edited" do + before(:each) do + @member = FactoryGirl.create(:member) + sign_in @member + controller.stub(:current_user) { @member } + @post = FactoryGirl.create(:post, :author => @member) + @post.update(body: "I am updated") + render_post + end + + it "shows edited at" do + rendered.should have_content "edited at" + end + + it "shows the updated time" do + rendered.should have_content @post.updated_at + end + end + + context "when comment has been edited" do + before(:each) do + @member = FactoryGirl.create(:member) + sign_in @member + controller.stub(:current_user) { @member } + @post = FactoryGirl.create(:post, :author => @member) + @comment = FactoryGirl.create(:comment, :post => @post) + @comment.update(body: "I've been updated") + render :partial => "comments/single", :locals => { :comment => @comment } + end + + it "shows edited at time" do + rendered.should have_content "edited at" + end + + it "shows updated time" do + rendered.should have_content @comment.updated_at + end + end + + context "when post has not been edited" do + before(:each) do + @member = FactoryGirl.create(:member) + sign_in @member + controller.stub(:current_user) { @member } + @post = FactoryGirl.create(:post, :author => @member) + @post.update(updated_at: @post.created_at) + render_post + end + + it "does not show edited at" do + rendered.should_not have_content "edited at #{@post.updated_at}" + end + end + + context "when comment has not been edited" do + before(:each) do + @member = FactoryGirl.create(:member) + sign_in @member + controller.stub(:current_user) { @member } + @post = FactoryGirl.create(:post, :author => @member) + @comment = FactoryGirl.create(:comment, :post => @post) + @comment.update(updated_at: @comment.created_at) + render :partial => "comments/single", :locals => { :comment => @comment } + end + + it "does not show edited at" do + rendered.should_not have_content "edited at #{@comment.updated_at}" + end + end + end - - - - From fc38e1edeab0d53d6e443b31e1e252999e71a8f4 Mon Sep 17 00:00:00 2001 From: Cesy Avon Date: Thu, 2 Jun 2016 14:27:04 +0000 Subject: [PATCH 2/2] Issue #476 test update --- spec/features/comments/commenting_a_comment_spec.rb | 2 +- spec/features/posts/posting_a_post_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/comments/commenting_a_comment_spec.rb b/spec/features/comments/commenting_a_comment_spec.rb index b39d28618..49183c274 100644 --- a/spec/features/comments/commenting_a_comment_spec.rb +++ b/spec/features/comments/commenting_a_comment_spec.rb @@ -27,7 +27,7 @@ feature 'Commenting on a post' do fill_in "comment_body", with: "Testing edit for comment" click_button "Post comment" expect(page).to have_content "Comment was successfully updated" - expect(page).to have_content "Edited by" + expect(page).to have_content "edited at" end end end \ No newline at end of file diff --git a/spec/features/posts/posting_a_post_spec.rb b/spec/features/posts/posting_a_post_spec.rb index a1f32942e..ac31b6fec 100644 --- a/spec/features/posts/posting_a_post_spec.rb +++ b/spec/features/posts/posting_a_post_spec.rb @@ -27,7 +27,7 @@ feature 'Post a post' do fill_in "post_subject", with: "Testing Edit" click_button "Post" expect(page).to have_content "Post was successfully updated" - expect(page).to have_content "Edited by" + expect(page).to have_content "edited at" end end -end \ No newline at end of file +end