Best Minitest_ruby code snippet using Reportable.options
news_item.rb
Source:news_item.rb
...76 end77 78 79 def self.report(*args)80 options = args.extract_options!81 82 if options[:type] and type = NewsItemType.cached_by_name(options[:type])83 options.merge!(:news_item_type_id => type.id)84 options.delete(:type)85 86 if options[:actionable]87 options.merge!({:actionable_type => options[:actionable].class.name, :actionable_id => options[:actionable].id})88 options.delete(:actionable)89 end90 91 if options[:reportable]92 options.merge!({:reportable_type => options[:reportable].class.name, :reportable_id => options[:reportable].id})93 options.delete(:reportable)94 end95 96 NewsItem.create(options)97 end98 end99 100 def self.grouped_activity(user_ids, options = {})101 # Speed and clean this method up with the caching system102 activity_types = NewsItemType.find(:all, :conditions => ['kind = ?', 'about a user']).collect{|type| type.id}103 104 options[:order] = 'max_id DESC'105 106 union([{:select => '*, max(id) AS max_id', 107 :conditions => ["news_item_type_id IN (?) AND reportable_type = 'Video' AND user_id IN (?) AND hidden = false", activity_types, user_ids], :group => 'reportable_id'}, 108 {:select => '*, id AS max_id', 109 :conditions => ["news_item_type_id IN (?) AND (reportable_type != 'Video' OR reportable_type IS NULL) AND user_id IN (?) AND hidden = false", activity_types, user_ids]}], 110 options)111 end112 113 def self.ungrouped_activity(user_ids, options = {})114 # Speed and clean this method up with the caching system115 activity_types = NewsItemType.find(:all, :conditions => ['kind = ?', 'about a user']).collect{|type| type.id}116 117 find(:all, :select => '*, id AS max_id', :conditions => ['news_item_type_id IN (?) AND user_id IN (?) AND hidden = false', activity_types, user_ids], :order => 'id DESC', :offset => options[:offset], :limit => options[:limit])118 end119 120 121 def render(link_user = true, absolute = false, format = '')122 prefix = absolute ? 'http://www.gawkk.com' : ''123 124 html = self.news_item_type.template125 html = html.gsub(/\{channel\}/, "<a href=\"#{prefix}/#{self.reportable.user.slug}/#{self.reportable.slug}#{format}\">#{channel_name(self.reportable.name)}</a>") if self.reportable and self.reportable.class == Channel126 html = html.gsub(/\{channel.listing\}/, "<div style=\"height:54px;margin:5px 0px;width:105px;\"><div style=\"font-size:8pt;float:right;height:40px;line-height:9pt;padding-top:14px;text-align:center;\"><a href=\"#{prefix}/#{self.reportable.user.slug}/#{self.reportable.slug}#{format}\">View<br/>Channel</a></div><a href=\"#{prefix}/#{self.reportable.user.slug}/#{self.reportable.slug}#{format}\"><img src=\"#{prefix}/images/#{self.reportable.user.thumbnail.blank? ? 'profile-pic.jpg' : self.reportable.user.thumbnail}\" style=\"border:1px solid #E5E5E5;float:left;height:52px;width:52px;\"/></a></div>") if self.reportable and self.reportable.class == Channel127 html = html.gsub(/\{friend\}/, "<a href=\"#{prefix}/#{self.reportable.slug}/profile#{format}\">#{self.reportable.username}</a>") if self.reportable and self.reportable.class == User128 html = html.gsub(/\{friend.listing\}/, "<div style=\"height:54px;margin:5px 0px;width:95px;\"><div style=\"font-size:8pt;float:right;height:40px;line-height:9pt;padding-top:14px;text-align:center;\"><a href=\"#{prefix}/#{self.reportable.slug}/profile#{format}\">View<br/>Profile</a></div><a href=\"#{prefix}/#{self.reportable.slug}/profile#{format}\"><img src=\"#{prefix}/images/#{self.reportable.thumbnail.blank? ? 'profile-pic.jpg' : self.reportable.thumbnail}\" style=\"border:1px solid #E5E5E5;float:left;height:52px;width:52px;\"/></a></div>") if self.reportable and self.reportable.class == User129 html = html.gsub(/\{message\}/, self.message)130 if link_user131 html = html.gsub(/\{user\}/, "<a href=\"#{prefix}/#{self.user.slug}/profile#{format}\">#{self.user.username}</a>")...
application_helper.rb
Source:application_helper.rb
1require 'redcarpet'2require 'redcarpet/render_strip'3module ApplicationHelper4 def render_markdown_content(content, options = {})5 return unless content6 options.reverse_merge!({7 target: nil,8 stripdown: false9 })10 if options[:truncate_length].present?11 content = truncate(content, length: options[:truncate_length])12 end13 if options[:target]14 html_render = Redcarpet::Markdown.new(15 Redcarpet::Render::HTML.new(16 hard_wrap: true,17 link_attributes: { target: options[:target] }18 ),19 autolink: true,20 fenced_code_blocks: true,21 highlight: true,22 space_after_headers: true,23 strikethrough: true,24 tables: true,25 underline: true,26 quote: true,27 )28 html_render.render(content).html_safe29 elsif options[:stripdown]30 content.gsub!(/\!\[([^\]]+)\]?\((https|http)?:\/\/[\S]+\)/, '')31 stripdown = Redcarpet::Markdown.new(Redcarpet::Render::StripDown)32 stripdown.render(content).html_safe33 else34 MarkItZero::Markdown.to_html(content).html_safe35 end36 end37 def report_link(reportable, report_parent = nil, options = {})38 options.reverse_merge!( remote: true, class: 'report-link')39 link_to 'Report', new_report_content_path(40 reportable_id: reportable.id,41 reportable_type: reportable.class.name,42 report_parent_type: report_parent&.class&.name,43 report_parent_id: report_parent&.id44 ), options45 end46 def reportable_url(reportable, report_parent = nil, options = {})47 options.reverse_merge!({ anchor: nil })48 @url ||=49 case reportable.class.name.to_s50 when 'Post'51 post_url(reportable, options)52 when 'Reply'53 return '' unless report_parent.present?54 reportable_url(report_parent, nil, anchor: "#reply_content_#{reportable.id}")55 when 'UserPublication'56 user_publication_url(reportable, options)57 else58 '#'59 end60 end61 def report_source(reportable)62 case reportable.class.name.to_s63 when 'Reply'64 reportable.content65 when 'Post' || 'UserPublication'66 reportable.title67 else68 ''69 end70 end71 def render_error(errors, options = {})72 if errors.present?73 capture do74 content_tag :div, class: "error-help-block" do75 errors.is_a?(Array) ? simple_format(errors.join(", ")) : simple_format(errors)76 end77 end78 end79 end80 def remotipart_render(template, options = {})81 if remotipart_submitted?82 "#{render(template, options)}"83 else84 render(template, options)85 end86 end87end...
moderations_helper.rb
Source:moderations_helper.rb
...3 module Admin4 # This module includes helpers to show moderation in admin5 module ModerationsHelper6 # Public: Renders an extract of the content reported in a text format.7 def reported_content_excerpt_for(reportable, options = {})8 I18n.with_locale(options.fetch(:locale, I18n.locale)) do9 reportable_content = reportable.reported_attributes.map do |attribute_name|10 attribute_value = reportable.attributes.with_indifferent_access[attribute_name]11 next translated_attribute(attribute_value) if attribute_value.is_a? Hash12 attribute_value13 end14 reportable_content.filter(&:present?).join(". ").truncate(options.fetch(:limit, 100))15 end16 end17 # Public: Finds the type and name of the participatory space the given18 # `reportable` object is associated to.19 #20 # Returns a String, or `nil` if the space is not found.21 def participatory_space_title_for(reportable, options = {})22 space = reportable.try(:participatory_space)23 return unless space24 I18n.with_locale(options.fetch(:locale, I18n.locale)) do25 title = translated_attribute(space.try(:title) || space.try(:name))26 type = space.class.model_name.human27 [type, title].compact.join(": ").truncate(options.fetch(:limit, 100))28 end29 end30 end31 end32end...
options
Using AI Code Generation
1 @options = { :one => 1, :two => 2 }2 @options = { :one => 1, :two => 2 }3 @options = { :one => 1, :two => 2 }4 @options = { :one => 1, :two => 2 }5 @options = { :one => 1, :two => 2 }6 @options = { :one => 1, :two => 2 }
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!