From d1e3e568b9400f9569f2c5b40e550045a5c99080 Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Thu, 3 Sep 2015 17:43:20 +0200 Subject: [PATCH 1/6] Report tab; bootstrap3 compatible, add user detail btn The reported_user_details button will redirect you to admin user_search. This can be useful if the podmin wants to lock, unlock or delete the account which is responsible for the reported post Signed-off-by: Lukas Matt --- app/assets/stylesheets/report.scss | 20 +++----------- app/helpers/report_helper.rb | 19 ++++++++++---- app/views/report/index.html.haml | 42 ++++++++++++++++-------------- config/locales/diaspora/en.yml | 1 + 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/app/assets/stylesheets/report.scss b/app/assets/stylesheets/report.scss index d964b55cd..30e6f32eb 100644 --- a/app/assets/stylesheets/report.scss +++ b/app/assets/stylesheets/report.scss @@ -1,21 +1,9 @@ #reports { padding-top: 2em; - .content { - float: left; - span { - display: block; - } - span.text { - padding-bottom: 1em; - } + .reason { + padding-bottom: 20px; } - .options { - float: right; - } - .clear { - clear: both; - border-bottom: 1px solid #808080; - padding-bottom: 1em; - margin-bottom: 1em; + form input { + margin-right: 5px; } } diff --git a/app/helpers/report_helper.rb b/app/helpers/report_helper.rb index 2170e3665..99533489e 100644 --- a/app/helpers/report_helper.rb +++ b/app/helpers/report_helper.rb @@ -3,15 +3,24 @@ # the COPYRIGHT file. module ReportHelper + def get_reported_guid(id, type) + if type == "post" + Post.where(id: id).first.author.guid + elsif type == "comment" + Comment.where(id: id).first.author.guid + end + end + def report_content(id, type) - if type == 'post' && !(post = Post.find_by_id(id)).nil? - raw t('report.post_label', title: link_to(post_page_title(post), post_path(id))) - elsif type == 'comment' && !(comment = Comment.find_by_id(id)).nil? + if type == "post" && !(post = Post.find_by_id(id)).nil? + raw t("report.post_label", title: link_to(post_page_title(post), post_path(id))) + elsif type == "comment" && !(comment = Comment.find_by_id(id)).nil? # comment_message is not html_safe. To prevent # cross-site-scripting we have to escape html - raw t('report.comment_label', data: link_to(h(comment_message(comment)), post_path(comment.post.id, anchor: comment.guid))) + raw t("report.comment_label", data: link_to( + h(comment_message(comment)), post_path(comment.post.id, anchor: comment.guid))) else - raw t('report.not_found') + raw t("report.not_found") end end end diff --git a/app/views/report/index.html.haml b/app/views/report/index.html.haml index b13031cd7..c8745fcec 100644 --- a/app/views/report/index.html.haml +++ b/app/views/report/index.html.haml @@ -7,26 +7,30 @@ - if current_user.admin? = render partial: "admins/admin_bar" .col-md-9 - %h1 - = t('report.title') #reports + %h1 + = t("report.title") - @reports.each do |r| - - username = User.find_by_id(r.user_id).username - .content - %span.text - = report_content(r.item_id, r.item_type) - %span - = raw t('report.reported_label', person: link_to(username, user_profile_path(username))) - %span - = t('report.reason_label', text: r.text) - .options.text-right - %span - = button_to t('report.review_link'), report_path(r.id, :type => r.item_type), - :class => "btn btn-info btn-small", + .panel.panel-default + - username = User.find_by_id(r.user_id).username + .panel-heading + .reporter.pull-right + = raw t("report.reported_label", person: link_to(username, user_profile_path(username))) + .title + = report_content(r.item_id, r.item_type) + .panel-body + .reason + = t("report.reason_label", text: r.text) + + = button_to t("report.reported_user_details"), + user_search_path(admins_controller_user_search: {guid: get_reported_guid(r.item_id, + r.item_type)}), class: "btn pull-left btn-info btn-small", + method: :post + = button_to t("report.review_link"), report_path(r.id, type: r.item_type), + class: "btn pull-left btn-info btn-small", method: :put - %span - = button_to t('report.delete_link'), report_path(r.id, :type => r.item_type), - :data => { :confirm => t('report.confirm_deletion') }, - :class => "btn btn-danger btn-small", + = button_to t("report.delete_link"), report_path(r.id, type: r.item_type), + data: {confirm: t("report.confirm_deletion")}, + class: "btn pull-right btn-danger btn-small", method: :delete - .clear + diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 30446b96f..7b30fee8f 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -1006,6 +1006,7 @@ en: reason_label: "Reason: %{text}" review_link: "Mark as reviewed" delete_link: "Delete item" + reported_user_details: "Details on reported user" confirm_deletion: "Are you sure to delete the item?" not_found: "The post/comment was not found. It seems that it was deleted by the user!" status: From 95072d6010297ccbfe0edcd7f04b2db1b6f3bd8d Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Thu, 3 Sep 2015 17:43:56 +0200 Subject: [PATCH 2/6] Add get_reported_guid spec for report helper * two new methods in report model reported_author and item * merge deletion methods in report model Signed-off-by: Lukas Matt --- app/assets/stylesheets/report.scss | 1 - app/helpers/report_helper.rb | 23 +++++-------- app/models/report.rb | 55 ++++++++++++++++-------------- app/views/report/index.html.haml | 23 ++++++------- spec/helpers/report_helper_spec.rb | 24 +++++++++---- 5 files changed, 64 insertions(+), 62 deletions(-) diff --git a/app/assets/stylesheets/report.scss b/app/assets/stylesheets/report.scss index 30e6f32eb..4282ad637 100644 --- a/app/assets/stylesheets/report.scss +++ b/app/assets/stylesheets/report.scss @@ -1,5 +1,4 @@ #reports { - padding-top: 2em; .reason { padding-bottom: 20px; } diff --git a/app/helpers/report_helper.rb b/app/helpers/report_helper.rb index 99533489e..5a6f1e0e3 100644 --- a/app/helpers/report_helper.rb +++ b/app/helpers/report_helper.rb @@ -3,22 +3,15 @@ # the COPYRIGHT file. module ReportHelper - def get_reported_guid(id, type) - if type == "post" - Post.where(id: id).first.author.guid - elsif type == "comment" - Comment.where(id: id).first.author.guid - end - end - - def report_content(id, type) - if type == "post" && !(post = Post.find_by_id(id)).nil? - raw t("report.post_label", title: link_to(post_page_title(post), post_path(id))) - elsif type == "comment" && !(comment = Comment.find_by_id(id)).nil? - # comment_message is not html_safe. To prevent - # cross-site-scripting we have to escape html + def report_content(report) + case (item = report.item) + when Post + raw t("report.post_label", title: link_to(post_page_title(item), post_path(item.id))) + when Comment raw t("report.comment_label", data: link_to( - h(comment_message(comment)), post_path(comment.post.id, anchor: comment.guid))) + h(comment_message(item)), + post_path(item.post.id, anchor: item.guid) + )) else raw t("report.not_found") end diff --git a/app/models/report.rb b/app/models/report.rb index 36356c48f..5e056cf02 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,4 +1,6 @@ class Report < ActiveRecord::Base + POST, COMMENT = %w(post comment).map(&:freeze) + validates :user_id, presence: true validates :item_id, presence: true validates :item_type, presence: true, :inclusion => { :in => %w(post comment), @@ -14,6 +16,18 @@ class Report < ActiveRecord::Base after_commit :send_report_notification, :on => :create + def item + if item_type == POST + Post.find_by(id: item_id) + elsif item_type == COMMENT + Comment.find_by(id: item_id) + end + end + + def reported_author + item.author unless item.nil? + end + def entry_does_not_exist if Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id) errors[:base] << 'You cannot report the same post twice.' @@ -27,35 +41,24 @@ class Report < ActiveRecord::Base end def destroy_reported_item - if item_type == 'post' - delete_post - elsif item_type == 'comment' - delete_comment + case item + when Post + if item.author.local? + item.author.owner.retract(item) + else + item.destroy + end + when Comment + if item.author.local? + item.author.owner.retract(comment) + elsif item.parent.author.local? + item.parent.author.owner.retract(comment) + else + item.destroy + end end mark_as_reviewed end - - def delete_post - if post = Post.where(id: item_id).first - if post.author.local? - post.author.owner.retract(post) - else - post.destroy - end - end - end - - def delete_comment - if comment = Comment.where(id: item_id).first - if comment.author.local? - comment.author.owner.retract(comment) - elsif comment.parent.author.local? - comment.parent.author.owner.retract(comment) - else - comment.destroy - end - end - end def mark_as_reviewed Report.where(item_id: item_id, item_type: item_type).update_all(reviewed: true) diff --git a/app/views/report/index.html.haml b/app/views/report/index.html.haml index c8745fcec..6a285874e 100644 --- a/app/views/report/index.html.haml +++ b/app/views/report/index.html.haml @@ -10,27 +10,24 @@ #reports %h1 = t("report.title") - - @reports.each do |r| + - @reports.each do |report| .panel.panel-default - - username = User.find_by_id(r.user_id).username + - username = report.user.username .panel-heading .reporter.pull-right = raw t("report.reported_label", person: link_to(username, user_profile_path(username))) .title - = report_content(r.item_id, r.item_type) + = report_content(report) .panel-body .reason - = t("report.reason_label", text: r.text) + = t("report.reason_label", text: report.text) = button_to t("report.reported_user_details"), - user_search_path(admins_controller_user_search: {guid: get_reported_guid(r.item_id, - r.item_type)}), class: "btn pull-left btn-info btn-small", - method: :post - = button_to t("report.review_link"), report_path(r.id, type: r.item_type), - class: "btn pull-left btn-info btn-small", - method: :put - = button_to t("report.delete_link"), report_path(r.id, type: r.item_type), + user_search_path(admins_controller_user_search: {guid: report.reported_author.guid}), + class: "btn pull-left btn-info btn-small", method: :post + = button_to t("report.review_link"), report_path(report.id, type: report.item_type), + class: "btn pull-left btn-info btn-small", method: :put + = button_to t("report.delete_link"), report_path(report.id, type: report.item_type), data: {confirm: t("report.confirm_deletion")}, - class: "btn pull-right btn-danger btn-small", - method: :delete + class: "btn pull-right btn-danger btn-small", method: :delete diff --git a/spec/helpers/report_helper_spec.rb b/spec/helpers/report_helper_spec.rb index 8cb003c42..6a6b95958 100644 --- a/spec/helpers/report_helper_spec.rb +++ b/spec/helpers/report_helper_spec.rb @@ -1,17 +1,27 @@ -require 'spec_helper' +require "spec_helper" -describe ReportHelper, :type => :helper do +describe ReportHelper, type: :helper do before do - @comment = FactoryGirl.create(:comment) - @post = @comment.post + @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 end describe "#report_content" do it "contains a link to the post" do - expect(helper.report_content(@post, 'post')).to include %Q(href="#{post_path(@post)}") + expect(helper.report_content(@post, "post")).to include %(href="#{post_path(@post)}") end - it "contains an anchor to the comment" do - expect(helper.report_content(@comment, 'comment')).to include %Q(href="#{post_path(@post, anchor: @comment.guid)}") + it "contains an anchor to the comment" do + expect(helper.report_content(@comment, "comment")).to include %(href="#{post_path(@post, anchor: @comment.guid)}") end end end From a6c3f67ba2ff7f1877f0a239f3cc33d5e559aa45 Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Mon, 14 Sep 2015 19:26:02 +0200 Subject: [PATCH 3/6] Check if post or comment exist while rendering It is possible that the item was deleted during the time it was reported and the admin review Signed-off-by: Lukas Matt --- app/controllers/report_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb index 8e0826c1f..14e9001f1 100644 --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -7,7 +7,10 @@ class ReportController < ApplicationController before_action :redirect_unless_moderator, except: [:create] def index - @reports = Report.where(reviewed: false) + @reports ||= [] + Report.where(reviewed: false).each do |report| + @reports << report unless report.item.nil? + end end def update From 6bf47c7ff04b212f45b88229c74fd53fd4600d9b Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Sat, 3 Oct 2015 12:18:06 +0200 Subject: [PATCH 4/6] 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 From 97ee2cd9757539e49b12f7b945f4226b699f6239 Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Sat, 3 Oct 2015 13:34:32 +0200 Subject: [PATCH 5/6] Display all reports and give the ability to review them --- app/controllers/report_controller.rb | 5 +-- app/views/report/index.html.haml | 49 +++++++++++++++++----------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb index 14e9001f1..8e0826c1f 100644 --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -7,10 +7,7 @@ class ReportController < ApplicationController before_action :redirect_unless_moderator, except: [:create] def index - @reports ||= [] - Report.where(reviewed: false).each do |report| - @reports << report unless report.item.nil? - end + @reports = Report.where(reviewed: false) end def update diff --git a/app/views/report/index.html.haml b/app/views/report/index.html.haml index 6a285874e..2df36adf8 100644 --- a/app/views/report/index.html.haml +++ b/app/views/report/index.html.haml @@ -11,23 +11,34 @@ %h1 = t("report.title") - @reports.each do |report| - .panel.panel-default - - username = report.user.username - .panel-heading - .reporter.pull-right - = raw t("report.reported_label", person: link_to(username, user_profile_path(username))) - .title - = report_content(report) - .panel-body - .reason - = t("report.reason_label", text: report.text) - - = button_to t("report.reported_user_details"), - user_search_path(admins_controller_user_search: {guid: report.reported_author.guid}), - class: "btn pull-left btn-info btn-small", method: :post - = button_to t("report.review_link"), report_path(report.id, type: report.item_type), - class: "btn pull-left btn-info btn-small", method: :put - = button_to t("report.delete_link"), report_path(report.id, type: report.item_type), - data: {confirm: t("report.confirm_deletion")}, - class: "btn pull-right btn-danger btn-small", method: :delete + - if report.item + .panel.panel-default + - username = report.user.username + .panel-heading + .reporter.pull-right + = raw t("report.reported_label", person: link_to(username, user_profile_path(username))) + .title + = report_content(report) + .panel-body + .reason + = t("report.reason_label", text: report.text) + = button_to t("report.reported_user_details"), + user_search_path(admins_controller_user_search: {guid: report.reported_author.guid}), + class: "btn pull-left btn-info btn-small", method: :post + = button_to t("report.review_link"), report_path(report.id, type: report.item_type), + class: "btn pull-left btn-info btn-small", method: :put + = button_to t("report.delete_link"), report_path(report.id, type: report.item_type), + data: {confirm: t("report.confirm_deletion")}, + class: "btn pull-right btn-danger btn-small", method: :delete + - else + .panel.panel-default + - username = report.user.username + .panel-heading + .reporter.pull-right + = raw t("report.reported_label", person: link_to(username, user_profile_path(username))) + .title + = report_content(report) + .panel-body + = button_to t("report.review_link"), report_path(report.id, type: report.item_type), + class: "btn pull-left btn-info btn-small", method: :put From 78f9b39e553a114d31f467f2293ffcc1a20827c4 Mon Sep 17 00:00:00 2001 From: Lukas Matt Date: Sat, 3 Oct 2015 16:52:50 +0200 Subject: [PATCH 6/6] Use polymorphic association for the report item * Adopt pronto suggestions Signed-off-by: Lukas Matt --- app/assets/templates/comment_tpl.jst.hbs | 2 +- app/assets/templates/photo_tpl.jst.hbs | 2 +- .../single-post-moderation_tpl.jst.hbs | 2 +- .../templates/stream-element_tpl.jst.hbs | 2 +- app/models/comment.rb | 2 ++ app/models/post.rb | 2 ++ app/models/report.rb | 15 ++------- ...20151003142048_update_report_item_types.rb | 7 ++++ db/schema.rb | 2 +- spec/controllers/report_controller_spec.rb | 32 +++++++++---------- spec/helpers/report_helper_spec.rb | 4 +-- spec/models/report_spec.rb | 10 +++--- 12 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 db/migrate/20151003142048_update_report_item_types.rb diff --git a/app/assets/templates/comment_tpl.jst.hbs b/app/assets/templates/comment_tpl.jst.hbs index 5dc240b49..2f8a9ae14 100644 --- a/app/assets/templates/comment_tpl.jst.hbs +++ b/app/assets/templates/comment_tpl.jst.hbs @@ -13,7 +13,7 @@ {{else}} - + {{/if}} diff --git a/app/assets/templates/photo_tpl.jst.hbs b/app/assets/templates/photo_tpl.jst.hbs index a36e05879..9cf51d51b 100644 --- a/app/assets/templates/photo_tpl.jst.hbs +++ b/app/assets/templates/photo_tpl.jst.hbs @@ -7,7 +7,7 @@ {{else}} - + diff --git a/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs b/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs index 10fc6f0d2..d81f6a14b 100644 --- a/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs +++ b/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs @@ -5,7 +5,7 @@ {{else}} - + diff --git a/app/assets/templates/stream-element_tpl.jst.hbs b/app/assets/templates/stream-element_tpl.jst.hbs index 92ea4e5ee..bb13c0cfa 100644 --- a/app/assets/templates/stream-element_tpl.jst.hbs +++ b/app/assets/templates/stream-element_tpl.jst.hbs @@ -13,7 +13,7 @@ {{else}} - + diff --git a/app/models/comment.rb b/app/models/comment.rb index 9e0eca2c7..b4194e7c8 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -30,6 +30,8 @@ class Comment < ActiveRecord::Base validates :text, :presence => true, :length => {:maximum => 65535} validates :parent, :presence => true #should be in relayable (pending on fixing Message) + has_many :reports, as: :item + scope :including_author, -> { includes(:author => :profile) } scope :for_a_stream, -> { including_author.merge(order('created_at ASC')) } diff --git a/app/models/post.rb b/app/models/post.rb index e59576085..787924f8e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -17,6 +17,8 @@ class Post < ActiveRecord::Base xml_attr :provider_display_name + has_many :reports, as: :item + has_many :mentions, :dependent => :destroy has_many :reshares, :class_name => "Reshare", :foreign_key => :root_guid, :primary_key => :guid diff --git a/app/models/report.rb b/app/models/report.rb index 6463bcf59..0ecaea927 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,10 +1,8 @@ class Report < ActiveRecord::Base - POST, COMMENT = %w(post comment).map(&:freeze) - validates :user_id, presence: true validates :item_id, presence: true - validates :item_type, presence: true, :inclusion => { :in => %w(post comment), - :message => 'Type should match `post` or `comment`!'} + validates :item_type, presence: true, inclusion: { + in: %w(Post Comment), message: "Type should match `Post` or `Comment`!"} validates :text, presence: true validate :entry_does_not_exist, :on => :create @@ -13,17 +11,10 @@ class Report < ActiveRecord::Base belongs_to :user belongs_to :post belongs_to :comment + belongs_to :item, polymorphic: true after_commit :send_report_notification, :on => :create - def item - if item_type == POST - Post.find_by(id: item_id) - elsif item_type == COMMENT - Comment.find_by(id: item_id) - end - end - def reported_author item.author if item end diff --git a/db/migrate/20151003142048_update_report_item_types.rb b/db/migrate/20151003142048_update_report_item_types.rb new file mode 100644 index 000000000..9a318edff --- /dev/null +++ b/db/migrate/20151003142048_update_report_item_types.rb @@ -0,0 +1,7 @@ +class UpdateReportItemTypes < ActiveRecord::Migration + def change + Report.all.each do |report| + report.update_attribute :item_type, report[:item_type].capitalize + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f2afae365..6a526fe46 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150828132451) do +ActiveRecord::Schema.define(version: 20151003142048) do create_table "account_deletions", force: :cascade do |t| t.string "diaspora_handle", limit: 255 diff --git a/spec/controllers/report_controller_spec.rb b/spec/controllers/report_controller_spec.rb index e5d5a49eb..fc64d36dd 100644 --- a/spec/controllers/report_controller_spec.rb +++ b/spec/controllers/report_controller_spec.rb @@ -49,16 +49,16 @@ describe ReportController, type: :controller do context "report offensive post" do it "succeeds" do - put :create, report: {item_id: @message.id, item_type: "post", text: "offensive content"} + put :create, report: {item_id: @message.id, item_type: "Post", text: "offensive content"} expect(response.status).to eq(200) - expect(Report.exists?(item_id: @message.id, item_type: "post")).to be true + expect(Report.exists?(item_id: @message.id, item_type: "Post")).to be true end end context "report offensive comment" do it "succeeds" do - put :create, report: {item_id: @comment.id, item_type: "comment", text: "offensive content"} + put :create, report: {item_id: @comment.id, item_type: "Comment", text: "offensive content"} expect(response.status).to eq(200) - expect(Report.exists?(item_id: @comment.id, item_type: "comment")).to be true + expect(Report.exists?(item_id: @comment.id, item_type: "Comment")).to be true end end end @@ -68,14 +68,14 @@ describe ReportController, type: :controller do it "is behind redirect_unless_admin_or_moderator" do put :update, id: @message.id, type: "post" expect(response).to redirect_to stream_path - expect(Report.where(reviewed: false, item_id: @message.id, item_type: "post")).to be_truthy + expect(Report.where(reviewed: false, item_id: @message.id, item_type: "Post")).to be_truthy end end context "mark comment report as user" do it "is behind redirect_unless_admin_or_moderator" do put :update, id: @comment.id, type: "comment" expect(response).to redirect_to stream_path - expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "comment")).to be_truthy + expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "Comment")).to be_truthy end end @@ -86,7 +86,7 @@ describe ReportController, type: :controller do it "succeeds" do put :update, id: @message.id, type: "post" expect(response.status).to eq(302) - expect(Report.where(reviewed: true, item_id: @message.id, item_type: "post")).to be_truthy + expect(Report.where(reviewed: true, item_id: @message.id, item_type: "Post")).to be_truthy end end context "mark comment report as admin" do @@ -96,7 +96,7 @@ describe ReportController, type: :controller do it "succeeds" do put :update, id: @comment.id, type: "comment" expect(response.status).to eq(302) - expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy + expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "Comment")).to be_truthy end end @@ -108,7 +108,7 @@ describe ReportController, type: :controller do it "succeeds" do put :update, id: @message.id, type: "post" expect(response.status).to eq(302) - expect(Report.where(reviewed: true, item_id: @message.id, item_type: "post")).to be_truthy + expect(Report.where(reviewed: true, item_id: @message.id, item_type: "Post")).to be_truthy end end @@ -119,7 +119,7 @@ describe ReportController, type: :controller do it "succeeds" do put :update, id: @comment.id, type: "comment" expect(response.status).to eq(302) - expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy + expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "Comment")).to be_truthy end end end @@ -129,14 +129,14 @@ describe ReportController, type: :controller do it "is behind redirect_unless_admin_or_moderator" do delete :destroy, id: @message.id, type: "post" expect(response).to redirect_to stream_path - expect(Report.where(reviewed: false, item_id: @message.id, item_type: "post")).to be_truthy + expect(Report.where(reviewed: false, item_id: @message.id, item_type: "Post")).to be_truthy end end context "destroy comment as user" do it "is behind redirect_unless_admin_or_moderator" do delete :destroy, id: @comment.id, type: "comment" expect(response).to redirect_to stream_path - expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "comment")).to be_truthy + expect(Report.where(reviewed: false, item_id: @comment.id, item_type: "Comment")).to be_truthy end end @@ -147,7 +147,7 @@ describe ReportController, type: :controller do it "succeeds" do delete :destroy, id: @message.id, type: "post" expect(response.status).to eq(302) - expect(Report.where(reviewed: true, item_id: @message.id, item_type: "post")).to be_truthy + expect(Report.where(reviewed: true, item_id: @message.id, item_type: "Post")).to be_truthy end end context "destroy comment as admin" do @@ -157,7 +157,7 @@ describe ReportController, type: :controller do it "succeeds" do delete :destroy, id: @comment.id, type: "comment" expect(response.status).to eq(302) - expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy + expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "Comment")).to be_truthy end end @@ -168,7 +168,7 @@ describe ReportController, type: :controller do it "succeeds" do delete :destroy, id: @message.id, type: "post" expect(response.status).to eq(302) - expect(Report.where(reviewed: true, item_id: @message.id, item_type: "post")).to be_truthy + expect(Report.where(reviewed: true, item_id: @message.id, item_type: "Post")).to be_truthy end end context "destroy comment as moderator" do @@ -178,7 +178,7 @@ describe ReportController, type: :controller do it "succeeds" do delete :destroy, id: @comment.id, type: "comment" expect(response.status).to eq(302) - expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "comment")).to be_truthy + expect(Report.where(reviewed: true, item_id: @comment.id, item_type: "Comment")).to be_truthy end end end diff --git a/spec/helpers/report_helper_spec.rb b/spec/helpers/report_helper_spec.rb index 1c3fa3b18..f7d6b2510 100644 --- a/spec/helpers/report_helper_spec.rb +++ b/spec/helpers/report_helper_spec.rb @@ -7,11 +7,11 @@ describe ReportHelper, type: :helper do @comment = @user.comment!(@post, "welcome") @post_report = @user.reports.create( - item_id: @post.id, item_type: "post", + item_id: @post.id, item_type: "Post", text: "offensive content" ) @comment_report = @user.reports.create( - item_id: @comment.id, item_type: "comment", + item_id: @comment.id, item_type: "Comment", text: "offensive content" ) end diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index bdfc17d38..04e4bc85a 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -12,14 +12,12 @@ describe Report, :type => :model do @bob_comment = @user.comment!(@bob_post, "welcome") @valid_post_report = { - :item_id => @bob_post.id, - :item_type => 'post', - :text => 'offensive content' + item_id: @bob_post.id, item_type: "Post", + text: "offensive content" } @valid_comment_report = { - :item_id => @bob_comment.id, - :item_type => 'comment', - :text => 'offensive content' + item_id: @bob_comment.id, item_type: "Comment", + text: "offensive content" } end