How to use report method of Reportable Package

Best Minitest_ruby code snippet using Reportable.report

manage_moderations_examples.rb

Source:manage_moderations_examples.rb Github

copy

Full Screen

1# frozen_string_literal: true2shared_examples "sorted moderations" do3 let!(:moderations) do4 reportables.first(reportables.length - 1).map do |reportable|5 moderation = create(:moderation, reportable: reportable, report_count: 1, reported_content: reportable.reported_searchable_content_text)6 create(:report, moderation: moderation)7 moderation8 end9 end10 let!(:moderation) { moderations.first }11 let(:moderations_link_text) { "Moderations" }12 before do13 visit participatory_space_path14 click_link moderations_link_text15 end16 it "sorts the most recent first" do17 within ".pagination" do18 click_link "Last"19 end20 all("tbody tr").each_with_index do |row, _index|21 expect(row.find("td:first-child")).to have_content(reportables.first.id)22 end23 end24end25shared_examples "manage moderations" do26 let!(:moderations) do27 reportables.first(reportables.length - 1).map do |reportable|28 moderation = create(:moderation, reportable: reportable, report_count: 1, reported_content: reportable.reported_searchable_content_text)29 create(:report, moderation: moderation)30 moderation31 end32 end33 let!(:moderation) { moderations.first }34 let!(:hidden_moderations) do35 reportables.last(1).map do |reportable|36 moderation = create(:moderation, reportable: reportable, report_count: 3, reported_content: reportable.reported_searchable_content_text, hidden_at: Time.current)37 create_list(:report, 3, moderation: moderation, reason: :spam)38 moderation39 end40 end41 let(:moderations_link_text) { "Moderations" }42 before do43 visit participatory_space_path44 click_link moderations_link_text45 end46 context "when listing moderations" do47 it "only lists moderations for the current organization" do48 external_reportable = create :dummy_resource49 external_moderation = create(:moderation, reportable: external_reportable, report_count: 1, reported_content: external_reportable.reported_searchable_content_text)50 create(:report, moderation: external_moderation)51 visit current_path52 expect(page).to have_no_selector("tr[data-id=\"#{external_moderation.id}\"]")53 end54 it "user can review them" do55 moderations.each do |moderation|56 within "tr[data-id=\"#{moderation.id}\"]" do57 expect(page).to have_css("a[href='#{moderation.reportable.reported_content_url}']")58 expect(page).to have_content "Spam"59 end60 end61 end62 it "user can un-report a resource" do63 within "tr[data-id=\"#{moderation.id}\"]" do64 click_link "Unreport"65 end66 expect(page).to have_admin_callout("Resource successfully unreported")67 end68 it "user can hide a resource" do69 within "tr[data-id=\"#{moderation.id}\"]" do70 click_link "Hide"71 end72 expect(page).to have_admin_callout("Resource successfully hidden")73 expect(page).to have_no_content(moderation.reportable.reported_content_url)74 end75 it "user can sort by report count" do76 moderations.each_with_index { |moderation, index| moderation.update(report_count: index + 1) }77 moderations_ordered_by_report_count_asc = moderations.sort_by(&:report_count)78 within "table" do79 click_link "Count"80 all("tbody tr").each_with_index do |row, index|81 reportable_id = moderations_ordered_by_report_count_asc[index].reportable.id82 expect(row.find("td:first-child")).to have_content(reportable_id)83 end84 end85 end86 it "user can filter by reportable type" do87 reportable_type = moderation.reportable.class.name.demodulize88 within ".filters__section" do89 find(:xpath, "//a[contains(text(), 'Filter')]").hover90 find(:xpath, "//a[contains(text(), 'Type')]").hover91 click_link reportable_type92 end93 expect(page).to have_selector("tbody tr", count: moderations.length)94 end95 it "user can filter by reported content" do96 search = moderation.reportable.id97 within ".filters__section" do98 fill_in("Search Moderation by reportable id or content.", with: search)99 find(:xpath, "//button[@type='submit']").click100 end101 expect(page).to have_selector("tbody tr", count: 1)102 end103 it "user can see moderation details" do104 within "tr[data-id=\"#{moderation.id}\"]" do105 click_link "Expand"106 end107 reported_content_slice = moderation.reportable.reported_searchable_content_text.split("\n").first108 expect(page).to have_content(reported_content_slice)109 end110 context "when the reported content does not exist" do111 it "still renders the page" do112 moderation.reportable.destroy113 visit current_path114 expect(page).to have_no_selector("tr[data-id=\"#{moderation.id}\"]")115 end116 end117 end118 context "when listing hidden resources" do119 it "user can review them" do120 within ".card-title" do121 click_link "Hidden"122 end123 hidden_moderations.each do |moderation|124 within "tr[data-id=\"#{moderation.id}\"]" do125 expect(page).to have_css("a[href='#{moderation.reportable.reported_content_url}']")126 end127 end128 end129 end130end...

Full Screen

Full Screen

reports_controller_test.rb

Source:reports_controller_test.rb Github

copy

Full Screen

1require "test_helper"2class ReportsControllerTest < ActionController::TestCase3 def test_new_report_without_login4 target_user = create(:user)5 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }6 assert_response :redirect7 assert_redirected_to login_path(:referer => new_report_path(:reportable_id => target_user.id, :reportable_type => "User"))8 end9 def test_new_report_after_login10 target_user = create(:user)11 session[:user] = create(:user).id12 # Create an Issue and a report13 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }14 assert_response :success15 assert_difference "Issue.count", 1 do16 details = "Details of a report"17 category = "other"18 post :create,19 :params => {20 :report => {21 :details => details,22 :category => category,23 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }24 }25 }26 end27 assert_response :redirect28 assert_redirected_to user_path(target_user)29 end30 def test_new_report_with_incomplete_details31 # Test creation of a new issue and a new report32 target_user = create(:user)33 # Login34 session[:user] = create(:user).id35 # Create an Issue and a report36 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }37 assert_response :success38 assert_difference "Issue.count", 1 do39 details = "Details of a report"40 category = "other"41 post :create,42 :params => {43 :report => {44 :details => details,45 :category => category,46 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }47 }48 }49 end50 assert_response :redirect51 assert_redirected_to user_path(target_user)52 issue = Issue.last53 assert_equal 1, issue.reports.count54 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }55 assert_response :success56 # Report without details57 assert_no_difference "Issue.count" do58 category = "other"59 post :create,60 :params => {61 :report => {62 :category => category,63 :issue => { :reportable_id => 1, :reportable_type => "User" }64 }65 }66 end67 assert_response :redirect68 assert_equal 1, issue.reports.count69 end70 def test_new_report_with_complete_details71 # Test creation of a new issue and a new report72 target_user = create(:user)73 # Login74 session[:user] = create(:user).id75 # Create an Issue and a report76 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }77 assert_response :success78 assert_difference "Issue.count", 1 do79 details = "Details of a report"80 category = "other"81 post :create,82 :params => {83 :report => {84 :details => details,85 :category => category,86 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }87 }88 }89 end90 assert_response :redirect91 assert_redirected_to user_path(target_user)92 issue = Issue.last93 assert_equal 1, issue.reports.count94 # Create a report for an existing Issue95 get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }96 assert_response :success97 assert_no_difference "Issue.count" do98 details = "Details of another report under the same issue"99 category = "other"100 post :create,101 :params => {102 :report => {103 :details => details,104 :category => category,105 :issue => { :reportable_id => target_user.id, :reportable_type => "User" }106 }107 }108 end109 assert_response :redirect110 assert_equal 2, issue.reports.count111 end112end...

Full Screen

Full Screen

report.rb

Source:report.rb Github

copy

Full Screen

1class Report < ActiveRecord::Base2 set_table_name "#{RAILS_DATABASE_PREFIX}reports"3 include Changeable4 5 acts_as_replicatable6 7 self.extend SearchableModel8 belongs_to :user9 belongs_to :reportable, :polymorphic => true 10 belongs_to :otrunk_report_template11 has_and_belongs_to_many :report_types, :join_table => "#{RAILS_DATABASE_PREFIX}report_types_reports"12 13 @@searchable_attributes = %w{name description}14 class <<self15 def searchable_attributes16 @@searchable_attributes17 end18 end19 20 include OtrunkSystem21 include SdsRunnable22 validates_presence_of :name23 validates_uniqueness_of :name24 def short_name25 self.otrunk_report_template.short_name + '_for_' + self.reportable.short_name26 end27 def self.reportable_serialize_token28 ":"29 end30 def self.serialize_reportable(activity)31 return [activity.class.name.to_s,activity.id].join(reportable_serialize_token)32 end33 34 def reportable_s35 if self.reportable36 return Report.serialize_reportable(self.reportable)37 end38 return nil39 end40 def reportable_from_s(string)41 type,id= string.split(Report.reportable_serialize_token)42 43 if id.to_i > 0 && reportable_types.index(type.constantize)44 self.reportable=type.constantize.find(id.to_i) 45 else46 logger.error("Error: bad reportable: #{string}")47 end48 return self.reportable49 end50 def reportable_s=(rep)51 if rep.is_a? String52 self.reportable_from_s(rep)53 end54 end55 56 protected57 58 def validate59 # validate any report_types which have limit_to_one = true60 self.report_types.select{|rt| rt.limit_to_one}.each do |rep_type|61 reports = self.reportable.reports.select{|rep| (rep != self && rep.report_types.include?(rep_type))}62 if reports.size > 063 errors.add("report_type", "Limited report type (#{rep_type.id}: #{rep_type.name}) already in use in #{reports.collect{|r| "#{r.id}: #{r.name}"}.join(", ")}")64 end65 end66 end67 def reportable_types68 [Activity,ExternalOtrunkActivity]69 end70end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Minitest_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful