How to use re method of Reportable Package

Best Minitest_ruby code snippet using Reportable.re

detail.rb

Source:detail.rb Github

copy

Full Screen

1class Reports::Detail < Reports::Excel2 def initialize(opts = {})3 super(opts)4 @runnables = opts[:runnables] || ExternalActivity.published5 @report_learners = opts[:report_learners] || report_learners_for_runnables(@runnables)6 @url_helpers = opts[:url_helpers]7 @hide_names = opts[:hide_names] || false8 # stud.id, class, school, user.id, username, student name, teachers, completed, %completed, last_run9 @common_columns = common_header(@hide_names) + [10 Reports::ColumnDefinition.new(:title => "# Completed", :width => 10, :left_border => :thin),11 Reports::ColumnDefinition.new(:title => "% Completed", :width => 10),12 Reports::ColumnDefinition.new(:title => "# Correct", :width => 10),13 Reports::ColumnDefinition.new(:title => "Last run", :width => 20),14 Reports::ColumnDefinition.new(:title => "Remote Endpoint", :width => 100)15 ]16 @reportable_embeddables = {} # keys will be runnables, and value will be an array of reportables for that runnable, in the correct order17 end18 def sorted_learners()19 @report_learners.sort_by {|l| [l.school_name, l.class_name, l.student_name, l.runnable_name]}20 end21 def setup_sheet_for_runnable(runnable, idx)22 # Spreadsheet was dying on ":" and "/" chars. Others?23 sheet_name = runnable.name.gsub /[^a-zA-z0-9 ]/,"_"24 # Add index number, as Spreadsheet is failing when two sheets have the same name.25 sheet_name = "#{idx + 1}. #{sheet_name[0..30]}"26 sheet_name "#{idx + 1}. Unknown" unless sheet_name && sheet_name.size > 027 @runnable_sheet[runnable] = @book.create_worksheet :name => sheet_name28 sheet_defs = @common_columns.clone29 answer_defs = []30 header_defs = [] # top level header31 expected_answers = []32 # save the original assignable so we can refer to it later33 assignable = runnable34 if runnable.is_a?(::ExternalActivity)35 if runnable.template36 runnable = runnable.template37 else38 # we can't report on external activities that don't have templates39 return40 end41 end42 # This needs to account for varying types of runnables...43 containers = get_containers(runnable)44 # offset the reportables counter by 245 reportable_header_counter = sheet_defs.size46 header_defs << Reports::ColumnDefinition.new(:title => sheet_name, :heading_row => 0, :col_index => reportable_header_counter)47 containers.each do |a|48 header_defs << Reports::ColumnDefinition.new(:title => a.name, :width=> 30, :heading_row => 0, :col_index => reportable_header_counter)49 reportable_header_counter += 2 # (two columns per container header)50 end51 reportable_header_counter -= 152 # Iterate containers53 containers.each do |a|54 sheet_defs << Reports::ColumnDefinition.new(:title => "#{a.name}\nAssessments Completed", :width => 4, :left_border => :thin)55 sheet_defs << Reports::ColumnDefinition.new(:title => "% Completed", :width => 4)56 reportable_header_counter = setup_sheet_runnables(a, reportable_header_counter, header_defs, answer_defs, expected_answers)57 end #containers58 col_defs = sheet_defs + answer_defs + header_defs59 write_sheet_headers(@runnable_sheet[assignable], col_defs)60 # Add row with expected answers.61 expected_answers.map! { |a| a.nil? ? "" : a }62 row = @runnable_sheet[assignable].row(@runnable_sheet[assignable].last_row_index + 1)63 row.concat(expected_answers)64 end65 def setup_sheet_runnables(container, reportable_header_counter, header_defs, answer_defs, expected_answers)66 reportables = container.reportable_elements.map {|re| re[:embeddable]}67 first = true68 question_counter = 069 # Iterate Reportables70 reportables.each do |r|71 question_counter += 172 reportable_header_counter += 173 header_defs << Reports::ColumnDefinition.new(:title => container.name, :heading_row => 0, :col_index => reportable_header_counter)74 title = clean_text((r.respond_to?(:prompt) ? r.prompt : r.name))75 title = "#{question_counter}: #{title}"76 answer_defs << Reports::ColumnDefinition.new(:title => title, :width => 25, :left_border => (first ? :thin : :none))77 expected_answers[reportable_header_counter] = get_expected_answer(r)78 if r.is_a?(Embeddable::ImageQuestion)79 reportable_header_counter += 180 answer_defs << Reports::ColumnDefinition.new(:title => 'note', :width => 25, :left_border => :none)81 end82 if r.is_required?83 reportable_header_counter += 184 answer_defs << Reports::ColumnDefinition.new(:title => 'submitted', :width => 10, :left_border => :none)85 end86 first = false87 end # reportables88 return reportable_header_counter89 end90 def run_report91 @book = Reports::Book.new(verbose: @verbose)92 @runnable_sheet = {}93 @runnables = @runnables.to_a94 @runnables.sort!{|a,b| a.name <=> b.name}95 print "Creating #{@runnables.size} worksheets for report" if @verbose96 @runnables.each_with_index do |runnable, idx|97 setup_sheet_for_runnable(runnable, idx)98 end # runnables99 puts " done." if @verbose100 student_learners = sorted_learners.group_by {|l| [l.student_id,l.class_id] }101 print "Filling in student data" if @verbose102 iterate_with_status(student_learners.keys) do |student_class|103 student_id = student_class[0]104 student_learners[student_class].each do |l|105 next unless (runnable = @runnables.detect{|r| l.runnable_type == r.class.to_s && r.id == l.runnable_id})106 # sheets are indexed from the actual runnable107 sheet = @runnable_sheet[runnable]108 if runnable.is_a?(::ExternalActivity)109 if runnable.template110 runnable = runnable.template111 else112 # we can't report on external activities that don't have templates113 next114 end115 end116 correctable = runnable.reportable_elements.select {|r| r[:embeddable].respond_to? :correctable? }117 # <=================================================>118 total_assessments = l.num_answerables119 assess_completed = l.num_submitted120 # <=================================================>121 total_by_container = get_containers(runnable).inject(0) { |a,b| a + b.reportable_elements.size}122 assess_percent = percent(assess_completed, total_assessments)123 last_run = l.last_run || 'never'124 row = sheet.row(sheet.last_row_index + 1)125 assess_completed = "#{assess_completed}/#{total_assessments}(#{total_by_container})"126 assess_correct = "#{l.num_correct}/#{correctable.size}"127 remote_endpoint = @url_helpers.remote_endpoint_url(l.learner)128 row[0, 3] = report_learner_info_cells([l], @hide_names) + [assess_completed, assess_percent, assess_correct, last_run, remote_endpoint]129 all_answers = []130 get_containers(runnable).each do |container|131 # <=================================================>132 reportables = container.reportable_elements.map { |re| re[:embeddable] }133 answers = reportables.map { |r| l.answers["#{r.class.to_s}|#{r.id}"] || default_answer_for(r) }134 #Bellow is bad, it gets the answers in the wrong order!135 #answers = @report_utils[l.offering].saveables(:learner => l, :embeddables => reportables )136 # s[:submitted] may be nil, as this hash key was added much later. Previously there was no notion137 # of submitted question, they were only answered or not. In theory we could add DB migration that138 # would update this hash (see answers attribute in Report::Learner), but that would be non-trivial139 # and migration itself would be very time consuming (I've done some experiments in console).140 submitted_answers = answers.select { |s| s[:submitted].nil? ? s[:answered] : s[:submitted] }141 correct_answers = answers.select { |s| s[:is_correct] }142 # <=================================================>143 # TODO: weed out answers with no length, or which are empty144 row.concat [submitted_answers.size, percent(submitted_answers.size, reportables.size)]145 all_answers += answers.collect { |ans|146 res = nil147 if ans[:answer].kind_of?(Hash) && ans[:answer][:type] == "Dataservice::Blob"148 blob = ans[:answer]149 if blob[:id] && blob[:token]150 url = "#{@blobs_url}/#{blob[:id]}/#{blob[:token]}.#{blob[:file_extension]}"151 res = [Reports::Link.new(url: url, text: url), (ans[:answer][:note] || "")]152 else153 res = ["not answered", ""]154 end155 else156 answer_value = ans[:answer].kind_of?(Enumerable) ? ans[:answer].map { |a| a[:answer] }.join(', ') : ans[:answer]157 # guard against invalid or missing answers (can happen eg when Saveable::ExternalLinkUrl has no "url" param set )158 if answer_value.nil?159 answer_value = "";160 end161 # Limit length of the answer to 5000 characters, so we don't break Excel.162 answer_value = answer_value.to_s.truncate(5000)163 case ans[:is_correct]164 when true then res = ["(correct) #{answer_value}"]165 when nil then res = [answer_value]166 when false then res = ["(wrong) #{answer_value}"]167 end168 end169 res << (ans[:submitted] ? "yes" : "no") if ans[:question_required]170 res171 }.flatten172 end173 row.concat all_answers174 end175 end176 return @book177 end178 def default_answer_for(embeddable)179 if embeddable.is_a?(Embeddable::ImageQuestion)180 return {:answered => false, :answer => {:type => "Dataservice::Blob"}, :submitted => false, :question_required => embeddable.is_required }181 end182 return {:answered => false, :answer => "not answered", :submitted => false, :question_required => embeddable.is_required }183 end184 def get_expected_answer(reportable)185 ans = reportable.respond_to?(:correct_answer) ? reportable.correct_answer : ""186 ans.blank? ? "" : "expected: #{ans}"187 end188end...

Full Screen

Full Screen

reported_mailer.rb

Source:reported_mailer.rb Github

copy

Full Screen

1# frozen_string_literal: true2module Decidim3 # A custom mailer for sending notifications to an admin when a report is created..4 class ReportedMailer < Decidim::ApplicationMailer5 helper Decidim::ResourceHelper6 helper Decidim::TranslationsHelper7 helper_method :reported_content_url, :report_url, :manage_moderations_url, :author_profile_url, :reported_content_cell8 def report(user, report)9 with_user(user) do10 @report = report11 @reportable = @report.moderation.reportable12 @participatory_space = @report.moderation.participatory_space13 @organization = user.organization14 @user = user15 @author = @reportable.try(:creator_identity) || @reportable.try(:author)16 @original_language = original_language(@reportable)17 subject = I18n.t("report.subject", scope: "decidim.reported_mailer")18 mail(to: user.email, subject: subject)19 end20 end21 def hide(user, report)22 with_user(user) do23 @report = report24 @participatory_space = @report.moderation.participatory_space25 @organization = user.organization26 @user = user27 subject = I18n.t("hide.subject", scope: "decidim.reported_mailer")28 mail(to: user.email, subject: subject)29 end30 end31 # See comment for reported_content_cell32 def current_organization33 @organization34 end35 private36 def reported_content_url37 @reported_content_url ||= @report.moderation.reportable.reported_content_url38 end39 def report_url40 @report_url ||= EngineRouter.admin_proxy(@participatory_space).moderation_report_url(host: @organization.host, moderation_id: @report.moderation.id, id: @report.id)41 end42 def manage_moderations_url43 @manage_moderations_url ||= EngineRouter.admin_proxy(@participatory_space).moderations_url(host: @organization.host)44 end45 def author_profile_url46 @author_profile_url ||= @author.is_a?(Decidim::UserBaseEntity) && !@author.deleted? ? decidim.profile_url(@author.nickname, host: @organization.host) : nil47 end48 def original_language(reportable)49 return reportable.content_original_language if reportable.respond_to?(:content_original_language)50 @organization.default_locale51 end52 # This is needed to be able to use a cell in an ActionMailer, which is not supported out of the box by cells-rails.53 # We're are passing the current object as if it was a controller.54 # We also need to define a 'current_organization' method, which is expected by Decidim::ViewModel.55 # A similar approach is used in Decidim::NewsletterMailer56 def reported_content_cell57 @reported_content_cell ||= ::Decidim::ViewModel.cell(58 "decidim/reported_content",59 @reportable,60 context: {61 controller: self62 }63 )64 end65 end66end...

Full Screen

Full Screen

re

Using AI Code Generation

copy

Full Screen

1 def initialize(a, b, c)2 re("a = %s, b = %s, c = %s", a, b, c)3t = Test.new(1, 2, 3)4 def initialize(a, b, c)5 Reportable.re("a = %s, b = %s, c = %s", a, b, c)6t = Test.new(1, 2, 3)7 def initialize(a, b, c)8 re("a = %s, b = %s, c = %s", a, b, c)9t = Test.new(1, 2, 3)

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