From 6bf47c7ff04b212f45b88229c74fd53fd4600d9b Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Sat, 3 Oct 2015 12:18:06 +0200 Subject: [PATCH] Fix spec files and report model * Adopt pronto suggestions --- app/helpers/report_helper.rb | 2 +- app/models/report.rb | 6 +++--- spec/helpers/report_helper_spec.rb | 22 ++++++++++++---------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/helpers/report_helper.rb b/app/helpers/report_helper.rb index 5a6f1e0e3..9eb017843 100644 --- a/app/helpers/report_helper.rb +++ b/app/helpers/report_helper.rb @@ -10,7 +10,7 @@ module ReportHelper when Comment raw t("report.comment_label", data: link_to( h(comment_message(item)), - post_path(item.post.id, anchor: item.guid) + post_path(item.post.id, anchor: item.author.guid) )) else raw t("report.not_found") diff --git a/app/models/report.rb b/app/models/report.rb index 5e056cf02..6463bcf59 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -25,7 +25,7 @@ class Report < ActiveRecord::Base end def reported_author - item.author unless item.nil? + item.author if item end def entry_does_not_exist @@ -50,9 +50,9 @@ class Report < ActiveRecord::Base end when Comment if item.author.local? - item.author.owner.retract(comment) + item.author.owner.retract(item) elsif item.parent.author.local? - item.parent.author.owner.retract(comment) + item.parent.author.owner.retract(item) else item.destroy end diff --git a/spec/helpers/report_helper_spec.rb b/spec/helpers/report_helper_spec.rb index 6a6b95958..1c3fa3b18 100644 --- a/spec/helpers/report_helper_spec.rb +++ b/spec/helpers/report_helper_spec.rb @@ -5,23 +5,25 @@ describe ReportHelper, type: :helper do @user = bob @post = @user.post(:status_message, text: "hello", to: @user.aspects.first.id) @comment = @user.comment!(@post, "welcome") - end - describe "#get_reported_guid" do - it "returns user guid from post" do - expect(helper.get_reported_guid(@post, "post")) == @user.guid - end - it "returns user guid from comment" do - expect(helper.get_reported_guid(@comment, "comment")) == @user.guid - end + @post_report = @user.reports.create( + item_id: @post.id, item_type: "post", + text: "offensive content" + ) + @comment_report = @user.reports.create( + item_id: @comment.id, item_type: "comment", + text: "offensive content" + ) end describe "#report_content" do it "contains a link to the post" do - expect(helper.report_content(@post, "post")).to include %(href="#{post_path(@post)}") + expect(helper.report_content(@post_report)) + .to include %(href="#{post_path(@post)}") end it "contains an anchor to the comment" do - expect(helper.report_content(@comment, "comment")).to include %(href="#{post_path(@post, anchor: @comment.guid)}") + expect(helper.report_content(@comment_report)) + .to include %(href="#{post_path(@post, anchor: @comment.author.guid)}") end end end