Skip to content

Commit

Permalink
Merge pull request #14954 from saraycp/test_data_decisions
Browse files Browse the repository at this point in the history
Add test data for decisions
  • Loading branch information
danidoni committed Sep 26, 2023
2 parents 6601f3a + 940de2c commit 70d6aa7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/lib/tasks/dev.rake
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ namespace :dev do
# Create some Reports
Rake::Task['dev:reports:data'].invoke

# Create some Decisions on existing Reports
Rake::Task['dev:reports:decisions'].invoke

# Create notifications by running the `dev:notifications:data` task two times
Rake::Task['dev:notifications:data'].invoke(2)

Expand Down
23 changes: 23 additions & 0 deletions src/api/lib/tasks/dev/reports.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,28 @@ namespace :dev do
Report.create!(reportable: reportable, user: iggy, reason: 'Watch your language, please')
end
end

# Run `rake dev:reports:decisions` (always after running `rake dev:reports:data`)
desc 'Create decisions related to existing reports'
task decisions: :development_environment do
require 'factory_bot'
include FactoryBot::Syntax::Methods

puts 'Taking decisions regarding some reports'

admin = User.get_default_admin

Report.find_each do |report|
# Reports with even id will be 'cleared' (0). Those with odd id will be 'favor' (1).
decision = Decision.create!(reason: "Just because! #{report.id}", moderator: admin, kind: (report.id % 2))
decision.reports << report
end

# The same decision applies to more than one report about the same object/reportable.
reportable = Decision.first.reports.first.reportable
another_user = User.find_by(login: 'Requestor') || create(:confirmed_user, login: 'Requestor')
another_report = Report.create!(reportable: reportable, user: another_user, reason: 'Behave properly, please!')
Decision.first.reports << another_report
end
end
end

0 comments on commit 70d6aa7

Please sign in to comment.