diff --git a/app/models/abstract_course.rb b/app/models/abstract_course.rb index c8e7ebeef58..5de5c820dc7 100644 --- a/app/models/abstract_course.rb +++ b/app/models/abstract_course.rb @@ -43,7 +43,7 @@ class AbstractCourse < ActiveRecord::Base save! end - scope :active, where("abstract_courses.workflow_state<>'deleted'") + scope :active, -> { where("abstract_courses.workflow_state<>'deleted'") } include StickySisFields are_sis_sticky :name, :short_name, :enrollment_term_id diff --git a/app/models/access_token.rb b/app/models/access_token.rb index 1d7e87fe732..439a5110de7 100644 --- a/app/models/access_token.rb +++ b/app/models/access_token.rb @@ -14,7 +14,7 @@ class AccessToken < ActiveRecord::Base # on the scope defined in the auth process (scope has not # yet been implemented) - scope :active, lambda { where("expires_at IS NULL OR expires_at>?", Time.zone.now) } + scope :active, -> { where("expires_at IS NULL OR expires_at>?", Time.zone.now) } TOKEN_SIZE = 64 OAUTH2_SCOPE_NAMESPACE = '/auth/' diff --git a/app/models/account.rb b/app/models/account.rb index 9d5bf55f3cc..a68869a4727 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -1362,12 +1362,10 @@ class Account < ActiveRecord::Base :closed end - scope :root_accounts, where(:root_account_id => nil) - scope :processing_sis_batch, where("accounts.current_sis_batch_id IS NOT NULL").order(:updated_at) - scope :name_like, lambda { |name| - where(wildcard('accounts.name', name)) - } - scope :active, where("accounts.workflow_state<>'deleted'") + scope :root_accounts, -> { where(:root_account_id => nil) } + scope :processing_sis_batch, -> { where("accounts.current_sis_batch_id IS NOT NULL").order(:updated_at) } + scope :name_like, lambda { |name| where(wildcard('accounts.name', name)) } + scope :active, -> { where("accounts.workflow_state<>'deleted'") } def canvas_network_enabled? false diff --git a/app/models/account_report.rb b/app/models/account_report.rb index fe7c62aef3b..bbf7e2008b8 100644 --- a/app/models/account_report.rb +++ b/app/models/account_report.rb @@ -35,13 +35,8 @@ class AccountReport < ActiveRecord::Base state :deleted end - scope :last_complete_of_type, lambda { |type, limit = 1| - last_of_type(type, limit).where(:progress => '100') - } - - scope :last_of_type, lambda { |type, limit = 1| - where(:report_type => type).order("updated_at DESC").limit(limit) - } + scope :last_complete_of_type, lambda { |type, limit = 1| last_of_type(type, limit).where(:progress => '100') } + scope :last_of_type, lambda { |type, limit = 1| where(:report_type => type).order("updated_at DESC").limit(limit) } def context self.account diff --git a/app/models/appointment_group.rb b/app/models/appointment_group.rb index 27dc35e8861..c8f5f9c38d5 100644 --- a/app/models/appointment_group.rb +++ b/app/models/appointment_group.rb @@ -227,8 +227,8 @@ class AppointmentGroup < ActiveRecord::Base ) COND } - scope :current, lambda { where("end_at>=?", Time.zone.now.midnight) } - scope :current_or_undated, lambda { where("end_at>=? OR end_at IS NULL", Time.zone.now.midnight) } + scope :current, -> { where("end_at>=?", Time.zone.now.midnight) } + scope :current_or_undated, -> { where("end_at>=? OR end_at IS NULL", Time.zone.now.midnight) } scope :intersecting, lambda { |start_date, end_date| where("start_at?", end_date, start_date) } set_policy do diff --git a/app/models/assessment_question.rb b/app/models/assessment_question.rb index 43cc270a2f6..db5529f776a 100644 --- a/app/models/assessment_question.rb +++ b/app/models/assessment_question.rb @@ -263,5 +263,5 @@ class AssessmentQuestion < ActiveRecord::Base dup end - scope :active, where("assessment_questions.workflow_state<>'deleted'") + scope :active, -> { where("assessment_questions.workflow_state<>'deleted'") } end diff --git a/app/models/assessment_question_bank.rb b/app/models/assessment_question_bank.rb index 3eae6258d55..4b0eefa18eb 100644 --- a/app/models/assessment_question_bank.rb +++ b/app/models/assessment_question_bank.rb @@ -140,5 +140,5 @@ class AssessmentQuestionBank < ActiveRecord::Base quiz_groups.destroy_all end - scope :active, where("assessment_question_banks.workflow_state<>'deleted'") + scope :active, -> { where("assessment_question_banks.workflow_state<>'deleted'") } end diff --git a/app/models/asset_user_access.rb b/app/models/asset_user_access.rb index 6a41ed661c2..e1ac3aa0161 100644 --- a/app/models/asset_user_access.rb +++ b/app/models/asset_user_access.rb @@ -37,8 +37,8 @@ class AssetUserAccess < ActiveRecord::Base scope :for_context, lambda { |context| where(:context_id => context, :context_type => context.class.to_s) } scope :for_user, lambda { |user| where(:user_id => user) } - scope :participations, where(:action_level => 'participate') - scope :most_recent, order('updated_at DESC') + scope :participations, -> { where(:action_level => 'participate') } + scope :most_recent, -> { order('updated_at DESC') } def category self.asset_category diff --git a/app/models/assignment.rb b/app/models/assignment.rb index 8ce3fccbb56..3c947708521 100644 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -1502,21 +1502,21 @@ class Assignment < ActiveRecord::Base 0.5 end - scope :include_submitted_count, select( + scope :include_submitted_count, -> { select( "assignments.*, (SELECT COUNT(*) FROM submissions WHERE assignments.id = submissions.assignment_id - AND submissions.submission_type IS NOT NULL) AS submitted_count") + AND submissions.submission_type IS NOT NULL) AS submitted_count") } - scope :include_graded_count, select( + scope :include_graded_count, -> { select( "assignments.*, (SELECT COUNT(*) FROM submissions WHERE assignments.id = submissions.assignment_id - AND submissions.grade IS NOT NULL) AS graded_count") + AND submissions.grade IS NOT NULL) AS graded_count") } - scope :include_quiz_and_topic, includes(:quiz, :discussion_topic) + scope :include_quiz_and_topic, -> { includes(:quiz, :discussion_topic) } - scope :no_graded_quizzes_or_topics, where("submission_types NOT IN ('online_quiz', 'discussion_topic')") + scope :no_graded_quizzes_or_topics, -> { where("submission_types NOT IN ('online_quiz', 'discussion_topic')") } - scope :with_submissions, includes(:submissions) + scope :with_submissions, -> { includes(:submissions) } scope :for_context_codes, lambda { |codes| where(:context_code => codes) } scope :for_course, lambda { |course_id| where(:context_type => 'Course', :context_id => course_id) } @@ -1524,11 +1524,11 @@ class Assignment < ActiveRecord::Base scope :due_before, lambda { |date| where("assignments.due_at?", date) } - scope :undated, where(:due_at => nil) + scope :undated, -> { where(:due_at => nil) } - scope :only_graded, where("submission_types<>'not_graded'") + scope :only_graded, -> { where("submission_types<>'not_graded'") } - scope :with_just_calendar_attributes, lambda { + scope :with_just_calendar_attributes, -> { select(((Assignment.column_names & CalendarEvent.column_names) + ['due_at', 'assignment_group_id', 'could_be_locked', 'unlock_at', 'lock_at', 'submission_types', '(freeze_on_copy AND copied) AS frozen'] - ['cloned_item_id', 'migration_id']).join(", ")) } @@ -1560,7 +1560,7 @@ class Assignment < ActiveRecord::Base # query as ambigious for the "due_at" field if combined with another table # (e.g. assignment overrides) with similar fields (like id,lock_at,etc), # throwing an error. - scope :api_needed_fields, select(API_NEEDED_FIELDS.map{ |f| "assignments." + f.to_s}) + scope :api_needed_fields, -> { select(API_NEEDED_FIELDS.map{ |f| "assignments." + f.to_s}) } # This should only be used in the course drop down to show assignments needing a submission scope :need_submitting_info, lambda { |user_id, limit| @@ -1595,22 +1595,22 @@ class Assignment < ActiveRecord::Base end } - scope :expecting_submission, where("submission_types NOT IN ('', 'none', 'not_graded', 'on_paper') AND submission_types IS NOT NULL") + scope :expecting_submission, -> { where("submission_types NOT IN ('', 'none', 'not_graded', 'on_paper') AND submission_types IS NOT NULL") } - scope :gradeable, where("assignments.submission_types<>'not_graded'") + scope :gradeable, -> { where("assignments.submission_types<>'not_graded'") } - scope :active, where("assignments.workflow_state<>'deleted'") + scope :active, -> { where("assignments.workflow_state<>'deleted'") } scope :before, lambda { |date| where("assignments.created_at { where("(assignments.unlock_at IS NULL OR assignments.unlock_at<:now) AND (assignments.lock_at IS NULL OR assignments.lock_at>:now)", :now => Time.zone.now) } - scope :order_by_base_due_at, order("assignments.due_at") + scope :order_by_base_due_at, -> { order("assignments.due_at") } - scope :unpublished, where(:workflow_state => 'unpublished') - scope :published, where(:workflow_state => 'published') + scope :unpublished, -> { where(:workflow_state => 'unpublished') } + scope :published, -> { where(:workflow_state => 'published') } def overdue? due_at && due_at <= Time.now diff --git a/app/models/assignment_group.rb b/app/models/assignment_group.rb index e8aeec75907..2ae6bf241d0 100644 --- a/app/models/assignment_group.rb +++ b/app/models/assignment_group.rb @@ -146,8 +146,8 @@ class AssignmentGroup < ActiveRecord::Base self.assignments.map{|a| a.points_possible || 0}.sum end - scope :include_active_assignments, includes(:active_assignments) - scope :active, where("assignment_groups.workflow_state<>'deleted'") + scope :include_active_assignments, -> { includes(:active_assignments) } + scope :active, -> { where("assignment_groups.workflow_state<>'deleted'") } scope :before, lambda { |date| where("assignment_groups.created_at codes).order(:position) } scope :for_course, lambda { |course| where(:context_id => course, :context_type => 'Course') } diff --git a/app/models/assignment_override.rb b/app/models/assignment_override.rb index a037d0c1fc0..b4ff1df2209 100644 --- a/app/models/assignment_override.rb +++ b/app/models/assignment_override.rb @@ -107,7 +107,7 @@ class AssignmentOverride < ActiveRecord::Base end end - scope :active, where(:workflow_state => 'active') + scope :active, -> { where(:workflow_state => 'active') } before_validation :default_values def default_values diff --git a/app/models/attachment.rb b/app/models/attachment.rb index c8b1b9d2517..f66698c8593 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -1253,11 +1253,11 @@ class Attachment < ActiveRecord::Base state :unattached_temporary end - scope :visible, where(['attachments.file_state in (?, ?)', 'available', 'public']) - scope :not_deleted, where("attachments.file_state<>'deleted'") + scope :visible, -> { where(['attachments.file_state in (?, ?)', 'available', 'public']) } + scope :not_deleted, -> { where("attachments.file_state<>'deleted'") } - scope :not_hidden, where("attachments.file_state<>'hidden'") - scope :not_locked, lambda { + scope :not_hidden, -> { where("attachments.file_state<>'hidden'") } + scope :not_locked, -> { where("(attachments.locked IS NULL OR attachments.locked=?) AND ((attachments.lock_at IS NULL) OR (attachments.lock_at>? OR (attachments.unlock_at IS NOT NULL AND attachments.unlock_at 'pending_upload') - scope :active, where(:file_state => 'available') - scope :thumbnailable?, where(:content_type => Technoweenie::AttachmentFu.content_types) - scope :by_display_name, lambda { order(display_name_order_by_clause('attachments')) } - scope :by_position_then_display_name, lambda { order("attachments.position, #{display_name_order_by_clause('attachments')}") } + scope :scribdable?, -> { where("scribd_mime_type_id IS NOT NULL") } + scope :recyclable, -> { where("attachments.scribd_attempts { where("attachments.workflow_state='processing' AND attachments.updated_at { where(:workflow_state => 'pending_upload') } + scope :active, -> { where(:file_state => 'available') } + scope :thumbnailable?, -> { where(:content_type => Technoweenie::AttachmentFu.content_types) } + scope :by_display_name, -> { order(display_name_order_by_clause('attachments')) } + scope :by_position_then_display_name, -> { order("attachments.position, #{display_name_order_by_clause('attachments')}") } def self.serialization_excludes; [:uuid, :namespace]; end def set_serialization_options if self.scribd_doc diff --git a/app/models/calendar_event.rb b/app/models/calendar_event.rb index 3f74c6a591f..f113ea5c119 100644 --- a/app/models/calendar_event.rb +++ b/app/models/calendar_event.rb @@ -115,11 +115,11 @@ class CalendarEvent < ActiveRecord::Base effective_context_code && ActiveRecord::Base.find_by_asset_string(effective_context_code) || context end - scope :order_by_start_at, order(:start_at) + scope :order_by_start_at, -> { order(:start_at) } - scope :active, where("calendar_events.workflow_state<>'deleted'") - scope :are_locked, where(:workflow_state => 'locked') - scope :are_unlocked, where("calendar_events.workflow_state NOT IN ('deleted', 'locked')") + scope :active, -> { where("calendar_events.workflow_state<>'deleted'") } + scope :are_locked, -> { where(:workflow_state => 'locked') } + scope :are_unlocked, -> { where("calendar_events.workflow_state NOT IN ('deleted', 'locked')") } # controllers/apis/etc. should generally use for_user_and_context_codes instead scope :for_context_codes, lambda { |codes| where(:context_code => codes) } @@ -161,10 +161,10 @@ class CalendarEvent < ActiveRecord::Base SQL } - scope :undated, where(:start_at => nil, :end_at => nil) + scope :undated, -> { where(:start_at => nil, :end_at => nil) } scope :between, lambda { |start, ending| where(:start_at => start..ending) } - scope :current, lambda { where("calendar_events.end_at>=?", Time.zone.now.midnight) } + scope :current, -> { where("calendar_events.end_at>=?", Time.zone.now.midnight) } scope :updated_after, lambda { |*args| if args.first where("calendar_events.updated_at IS NULL OR calendar_events.updated_at>?", args.first) @@ -173,8 +173,8 @@ class CalendarEvent < ActiveRecord::Base end } - scope :events_without_child_events, where("NOT EXISTS (SELECT 1 FROM calendar_events children WHERE children.parent_calendar_event_id = calendar_events.id AND children.workflow_state<>'deleted')") - scope :events_with_child_events, where("EXISTS (SELECT 1 FROM calendar_events children WHERE children.parent_calendar_event_id = calendar_events.id AND children.workflow_state<>'deleted')") + scope :events_without_child_events, -> { where("NOT EXISTS (SELECT 1 FROM calendar_events children WHERE children.parent_calendar_event_id = calendar_events.id AND children.workflow_state<>'deleted')") } + scope :events_with_child_events, -> { where("EXISTS (SELECT 1 FROM calendar_events children WHERE children.parent_calendar_event_id = calendar_events.id AND children.workflow_state<>'deleted')") } def validate_context! @validate_context = true diff --git a/app/models/collaboration.rb b/app/models/collaboration.rb index 405700b68b3..82a1cd6e1f8 100644 --- a/app/models/collaboration.rb +++ b/app/models/collaboration.rb @@ -88,7 +88,7 @@ class Collaboration < ActiveRecord::Base can :read and can :update and can :delete end - scope :active, where("collaborations.workflow_state<>'deleted'") + scope :active, -> { where("collaborations.workflow_state<>'deleted'") } scope :after, lambda { |date| where("collaborations.updated_at>?", date) } diff --git a/app/models/communication_channel.rb b/app/models/communication_channel.rb index a767861489f..0ad1071a126 100644 --- a/app/models/communication_channel.rb +++ b/app/models/communication_channel.rb @@ -235,11 +235,11 @@ class CommunicationChannel < ActiveRecord::Base where("#{by_path_condition("communication_channels.path")}=#{by_path_condition("?")}", path) } - scope :email, where(:path_type => TYPE_EMAIL) - scope :sms, where(:path_type => TYPE_SMS) + scope :email, -> { where(:path_type => TYPE_EMAIL) } + scope :sms, -> { where(:path_type => TYPE_SMS) } - scope :active, where(:workflow_state => 'active') - scope :unretired, where("communication_channels.workflow_state<>'retired'") + scope :active, -> { where(:workflow_state => 'active') } + scope :unretired, -> { where("communication_channels.workflow_state<>'retired'") } scope :for_notification_frequency, lambda { |notification, frequency| includes(:notification_policies).where(:notification_policies => { :notification_id => notification, :frequency => frequency }) @@ -262,10 +262,10 @@ class CommunicationChannel < ActiveRecord::Base all end - scope :include_policies, includes(:notification_policies) + scope :include_policies, -> { includes(:notification_policies) } scope :in_state, lambda { |state| where(:workflow_state => state.to_s) } - scope :of_type, lambda {|type| where(:path_type => type) } + scope :of_type, lambda { |type| where(:path_type => type) } def can_notify? self.notification_policies.any? { |np| np.frequency == 'never' } ? false : true diff --git a/app/models/content_export.rb b/app/models/content_export.rb index 2bcb0cca254..89d402abe39 100644 --- a/app/models/content_export.rb +++ b/app/models/content_export.rb @@ -210,12 +210,12 @@ class ContentExport < ActiveRecord::Base self.job_progress.try(:update_completion!, val) end - scope :active, where("workflow_state<>'deleted'") - scope :not_for_copy, where("export_type<>?", COURSE_COPY) - scope :common_cartridge, where(:export_type => COMMON_CARTRIDGE) - scope :qti, where(:export_type => QTI) - scope :course_copy, where(:export_type => COURSE_COPY) - scope :running, where(:workflow_state => ['created', 'exporting']) + scope :active, -> { where("workflow_state<>'deleted'") } + scope :not_for_copy, -> { where("export_type<>?", COURSE_COPY) } + scope :common_cartridge, -> { where(:export_type => COMMON_CARTRIDGE) } + scope :qti, -> { where(:export_type => QTI) } + scope :course_copy, -> { where(:export_type => COURSE_COPY) } + scope :running, -> { where(:workflow_state => ['created', 'exporting']) } private diff --git a/app/models/content_migration.rb b/app/models/content_migration.rb index 66cd6f4db65..8bc54748df3 100644 --- a/app/models/content_migration.rb +++ b/app/models/content_migration.rb @@ -465,10 +465,10 @@ class ContentMigration < ActiveRecord::Base scope :for_context, lambda { |context| where(:context_id => context, :context_type => context.class.to_s) } - scope :successful, where(:workflow_state => 'imported') - scope :running, where(:workflow_state => ['exporting', 'importing']) - scope :waiting, where(:workflow_state => 'exported') - scope :failed, where(:workflow_state => ['failed', 'pre_process_error']) + scope :successful, -> { where(:workflow_state => 'imported') } + scope :running, -> { where(:workflow_state => ['exporting', 'importing']) } + scope :waiting, -> { where(:workflow_state => 'exported') } + scope :failed, -> { where(:workflow_state => ['failed', 'pre_process_error']) } def complete? %w[imported failed pre_process_error].include?(workflow_state) diff --git a/app/models/content_tag.rb b/app/models/content_tag.rb index 799c440bdf0..f1d3e160514 100644 --- a/app/models/content_tag.rb +++ b/app/models/content_tag.rb @@ -84,8 +84,8 @@ class ContentTag < ActiveRecord::Base alias_method :published?, :active? - scope :active, where(:workflow_state => 'active') - scope :not_deleted, where("content_tags.workflow_state<>'deleted'") + scope :active, -> { where(:workflow_state => 'active') } + scope :not_deleted, -> { where("content_tags.workflow_state<>'deleted'") } attr_accessor :skip_touch def touch_context_module @@ -414,8 +414,8 @@ class ContentTag < ActiveRecord::Base where(:context_type => context.class.to_s, :context_id => context) end } - scope :learning_outcome_alignments, where(:tag_type => 'learning_outcome') - scope :learning_outcome_links, where(:tag_type => 'learning_outcome_association', :associated_asset_type => 'LearningOutcomeGroup', :content_type => 'LearningOutcome') + scope :learning_outcome_alignments, -> { where(:tag_type => 'learning_outcome') } + scope :learning_outcome_links, -> { where(:tag_type => 'learning_outcome_association', :associated_asset_type => 'LearningOutcomeGroup', :content_type => 'LearningOutcome') } # only intended for learning outcome links def self.outcome_title_order_by_clause diff --git a/app/models/context_external_tool.rb b/app/models/context_external_tool.rb index d79fe4044c6..dc8bb941274 100644 --- a/app/models/context_external_tool.rb +++ b/app/models/context_external_tool.rb @@ -547,7 +547,7 @@ class ContextExternalTool < ActiveRecord::Base tool end - scope :active, where("context_external_tools.workflow_state<>'deleted'") + scope :active, -> { where("context_external_tools.workflow_state<>'deleted'") } def self.find_all_for(context, type) tools = [] diff --git a/app/models/context_module.rb b/app/models/context_module.rb index b61fdb2ff1d..57d058c2010 100644 --- a/app/models/context_module.rb +++ b/app/models/context_module.rb @@ -140,9 +140,9 @@ class ContextModule < ActiveRecord::Base state :deleted end - scope :active, where(:workflow_state => 'active') - scope :unpublished, where(:workflow_state => 'unpublished') - scope :not_deleted, where("context_modules.workflow_state<>'deleted'") + scope :active, -> { where(:workflow_state => 'active') } + scope :unpublished, -> { where(:workflow_state => 'unpublished') } + scope :not_deleted, -> { where("context_modules.workflow_state<>'deleted'") } alias_method :published?, :active? diff --git a/app/models/conversation_batch.rb b/app/models/conversation_batch.rb index 3972a3e03f1..27246dabf74 100644 --- a/app/models/conversation_batch.rb +++ b/app/models/conversation_batch.rb @@ -19,7 +19,7 @@ class ConversationBatch < ActiveRecord::Base validates_presence_of :user_id, :workflow_state, :root_conversation_message_id - scope :in_progress, where(:workflow_state => ['created', 'sending']) + scope :in_progress, -> { where(:workflow_state => ['created', 'sending']) } attr_accessible attr_accessor :mode diff --git a/app/models/conversation_message.rb b/app/models/conversation_message.rb index 40623afac43..a1f867d7b4b 100644 --- a/app/models/conversation_message.rb +++ b/app/models/conversation_message.rb @@ -51,9 +51,9 @@ class ConversationMessage < ActiveRecord::Base after_create :generate_user_note! - scope :human, where("NOT generated") - scope :with_attachments, where("attachment_ids<>'' OR has_attachments") # TODO: simplify post-migration - scope :with_media_comments, where("media_comment_id IS NOT NULL OR has_media_objects") # TODO: simplify post-migration + scope :human, -> { where("NOT generated") } + scope :with_attachments, -> { where("attachment_ids<>'' OR has_attachments") } # TODO: simplify post-migration + scope :with_media_comments, -> { where("media_comment_id IS NOT NULL OR has_media_objects") } # TODO: simplify post-migration scope :by_user, lambda { |user_or_id| where(:author_id => user_or_id) } def self.preload_latest(conversation_participants, author=nil) diff --git a/app/models/conversation_message_participant.rb b/app/models/conversation_message_participant.rb index e3c0d219818..d89cb0d2427 100644 --- a/app/models/conversation_message_participant.rb +++ b/app/models/conversation_message_participant.rb @@ -31,8 +31,8 @@ class ConversationMessageParticipant < ActiveRecord::Base EXPORTABLE_ATTRIBUTES = [:id, :conversation_message_id, :conversation_participant_id, :tags, :user_id, :workflow_state] EXPORTABLE_ASSOCIATIONS = [:conversation_message, :user, :conversation_participant] - scope :active, where("(conversation_message_participants.workflow_state <> 'deleted' OR conversation_message_participants.workflow_state IS NULL)") - scope :deleted, where("conversation_message_participants.workflow_state = 'deleted'") + scope :active, -> { where("(conversation_message_participants.workflow_state <> 'deleted' OR conversation_message_participants.workflow_state IS NULL)") } + scope :deleted, -> { where(workflow_state: 'deleted') } scope :for_conversation_and_message, lambda { |conversation_id, message_id| joins("INNER JOIN conversation_participants ON conversation_participants.id = conversation_participant_id"). diff --git a/app/models/conversation_participant.rb b/app/models/conversation_participant.rb index b719733ab99..08a6cab0475 100644 --- a/app/models/conversation_participant.rb +++ b/app/models/conversation_participant.rb @@ -36,12 +36,12 @@ class ConversationParticipant < ActiveRecord::Base after_destroy :destroy_conversation_message_participants - scope :visible, where("last_message_at IS NOT NULL") - scope :default, where(:workflow_state => ['read', 'unread']) - scope :unread, where(:workflow_state => 'unread') - scope :archived, where(:workflow_state => 'archived') - scope :starred, where(:label => 'starred') - scope :sent, where("visible_last_authored_at IS NOT NULL").order("visible_last_authored_at DESC, conversation_id DESC") + scope :visible, -> { where("last_message_at IS NOT NULL") } + scope :default, -> { where(:workflow_state => ['read', 'unread']) } + scope :unread, -> { where(:workflow_state => 'unread') } + scope :archived, -> { where(:workflow_state => 'archived') } + scope :starred, -> { where(:label => 'starred') } + scope :sent, -> { where("visible_last_authored_at IS NOT NULL").order("visible_last_authored_at DESC, conversation_id DESC") } scope :for_masquerading_user, lambda { |user| # site admins can see everything return scoped if user.account_users.map(&:account_id).include?(Account.site_admin.id) diff --git a/app/models/course.rb b/app/models/course.rb index 50b25901e0b..9b1ad94e1e8 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -490,14 +490,14 @@ class Course < ActiveRecord::Base accounts end - scope :recently_started, lambda { where(:start_at => 1.month.ago..Time.zone.now).order("start_at DESC").limit(10) } - scope :recently_ended, lambda { where(:conclude_at => 1.month.ago..Time.zone.now).order("start_at DESC").limit(10) } - scope :recently_created, lambda { where("created_at>?", 1.month.ago).order("created_at DESC").limit(50).includes(:teachers) } + scope :recently_started, -> { where(:start_at => 1.month.ago..Time.zone.now).order("start_at DESC").limit(10) } + scope :recently_ended, -> { where(:conclude_at => 1.month.ago..Time.zone.now).order("start_at DESC").limit(10) } + scope :recently_created, -> { where("created_at>?", 1.month.ago).order("created_at DESC").limit(50).includes(:teachers) } scope :for_term, lambda {|term| term ? where(:enrollment_term_id => term) : scoped } - scope :active_first, lambda { order("CASE WHEN courses.workflow_state='available' THEN 0 ELSE 1 END, #{best_unicode_collation_key('name')}") } + scope :active_first, -> { order("CASE WHEN courses.workflow_state='available' THEN 0 ELSE 1 END, #{best_unicode_collation_key('name')}") } scope :name_like, lambda { |name| where(wildcard('courses.name', 'courses.sis_source_id', 'courses.course_code', name)) } scope :needs_account, lambda { |account, limit| where(:account_id => nil, :root_account_id => account).limit(limit) } - scope :active, where("courses.workflow_state<>'deleted'") + scope :active, -> { where("courses.workflow_state<>'deleted'") } scope :least_recently_updated, lambda { |limit| order(:updated_at).limit(limit) } scope :manageable_by_user, lambda { |*args| # args[0] should be user_id, args[1], if true, will include completed @@ -514,19 +514,19 @@ class Course < ActiveRecord::Base WHERE courses.workflow_state <> 'deleted') as course_users ON course_users.course_id = courses.id") } - scope :not_deleted, where("workflow_state<>'deleted'") + scope :not_deleted, -> { where("workflow_state<>'deleted'") } - scope :with_enrollments, lambda { + scope :with_enrollments, -> { where("EXISTS (?)", Enrollment.active.where("enrollments.course_id=courses.id")) } - scope :without_enrollments, lambda { + scope :without_enrollments, -> { where("NOT EXISTS (?)", Enrollment.active.where("enrollments.course_id=courses.id")) } - scope :completed, lambda { + scope :completed, -> { joins(:enrollment_term). where("courses.workflow_state='completed' OR courses.conclude_at { joins(:enrollment_term). where("courses.workflow_state<>'completed' AND (courses.conclude_at IS NULL OR courses.conclude_at>=?) AND @@ -537,13 +537,13 @@ class Course < ActiveRecord::Base none : where("EXISTS (?)", Enrollment.active.where("enrollments.course_id=courses.id AND enrollments.type='TeacherEnrollment' AND enrollments.user_id IN (?)", teacher_ids)) } - scope :by_associated_accounts, lambda{ |account_ids| + scope :by_associated_accounts, lambda { |account_ids| account_ids.empty? ? none : where("EXISTS (?)", CourseAccountAssociation.where("course_account_associations.course_id=courses.id AND course_account_associations.account_id IN (?)", account_ids)) } - scope :deleted, where(:workflow_state => 'deleted') + scope :deleted, -> { where(:workflow_state => 'deleted') } set_broadcast_policy do |p| p.dispatch :grade_weight_changed diff --git a/app/models/course_section.rb b/app/models/course_section.rb index 0f323243c24..945d1ad1bfa 100644 --- a/app/models/course_section.rb +++ b/app/models/course_section.rb @@ -246,7 +246,7 @@ class CourseSection < ActiveRecord::Base save! end - scope :active, where("course_sections.workflow_state<>'deleted'") + scope :active, -> { where("course_sections.workflow_state<>'deleted'") } scope :sis_sections, lambda { |account, *source_ids| where(:root_account_id => account, :sis_source_id => source_ids).order(:sis_source_id) } diff --git a/app/models/custom_gradebook_column.rb b/app/models/custom_gradebook_column.rb index 277c1879134..85250ef314e 100644 --- a/app/models/custom_gradebook_column.rb +++ b/app/models/custom_gradebook_column.rb @@ -38,8 +38,8 @@ class CustomGradebookColumn < ActiveRecord::Base state :deleted end - scope :active, where(workflow_state: "active") - scope :not_deleted, where("workflow_state != 'deleted'") + scope :active, -> { where(workflow_state: "active") } + scope :not_deleted, -> { where("workflow_state != 'deleted'") } set_policy do given { |user, session| diff --git a/app/models/delayed_message.rb b/app/models/delayed_message.rb index c8f0db3b3fa..7954198f8e5 100644 --- a/app/models/delayed_message.rb +++ b/app/models/delayed_message.rb @@ -74,11 +74,11 @@ class DelayedMessage < ActiveRecord::Base scope :in_state, lambda { |state| where(:workflow_state => state.to_s) } - scope :to_summarize, lambda { + scope :to_summarize, -> { where("delayed_messages.workflow_state='pending' and delayed_messages.send_at<=?", Time.now.utc) } - scope :next_to_summarize, lambda { + scope :next_to_summarize, -> { where(:workflow_state => 'pending').order(:send_at).limit(1) } diff --git a/app/models/discussion_entry.rb b/app/models/discussion_entry.rb index 137a70f7c8e..3d334ebf6d7 100644 --- a/app/models/discussion_entry.rb +++ b/app/models/discussion_entry.rb @@ -238,8 +238,8 @@ class DiscussionEntry < ActiveRecord::Base end end - scope :active, where("discussion_entries.workflow_state<>'deleted'") - scope :deleted, where(:workflow_state => 'deleted') + scope :active, -> { where("discussion_entries.workflow_state<>'deleted'") } + scope :deleted, -> { where(:workflow_state => 'deleted') } def user_name self.user.name rescue t :default_user_name, "User Name" @@ -308,9 +308,9 @@ class DiscussionEntry < ActiveRecord::Base scope :for_user, lambda { |user| where(:user_id => user).order("discussion_entries.created_at") } scope :for_users, lambda { |users| where(:user_id => users) } scope :after, lambda { |date| where("created_at>?", date) } - scope :top_level_for_topics, lambda {|topics| where(:root_entry_id => nil, :discussion_topic_id => topics) } + scope :top_level_for_topics, lambda { |topics| where(:root_entry_id => nil, :discussion_topic_id => topics) } scope :all_for_topics, lambda { |topics| where(:discussion_topic_id => topics) } - scope :newest_first, order("discussion_entries.created_at DESC, discussion_entries.id DESC") + scope :newest_first, -> { order("discussion_entries.created_at DESC, discussion_entries.id DESC") } def to_atom(opts={}) author_name = self.user.present? ? self.user.name : t('atom_no_author', "No Author") diff --git a/app/models/discussion_entry_participant.rb b/app/models/discussion_entry_participant.rb index 4555a576675..91bd699f030 100644 --- a/app/models/discussion_entry_participant.rb +++ b/app/models/discussion_entry_participant.rb @@ -45,7 +45,7 @@ class DiscussionEntryParticipant < ActiveRecord::Base state :read end - scope :read, where(:workflow_state => 'read') + scope :read, -> { where(:workflow_state => 'read') } scope :existing_participants, ->(user, entry_id) { select([:id, :discussion_entry_id]). where(user_id: user, discussion_entry_id: entry_id) diff --git a/app/models/discussion_topic.rb b/app/models/discussion_topic.rb index 59f3415c277..5061f87655d 100644 --- a/app/models/discussion_topic.rb +++ b/app/models/discussion_topic.rb @@ -462,17 +462,17 @@ class DiscussionTopic < ActiveRecord::Base topic_participant end - scope :recent, lambda { where("discussion_topics.last_reply_at>?", 2.weeks.ago).order("discussion_topics.last_reply_at DESC") } - scope :only_discussion_topics, where(:type => nil) - scope :for_subtopic_refreshing, where("discussion_topics.subtopics_refreshed_at IS NOT NULL AND discussion_topics.subtopics_refreshed_at'deleted'") - scope :for_context_codes, lambda {|codes| where(:context_code => codes) } + scope :recent, -> { where("discussion_topics.last_reply_at>?", 2.weeks.ago).order("discussion_topics.last_reply_at DESC") } + scope :only_discussion_topics, -> { where(:type => nil) } + scope :for_subtopic_refreshing, -> { where("discussion_topics.subtopics_refreshed_at IS NOT NULL AND discussion_topics.subtopics_refreshed_at { where("discussion_topics.workflow_state<>'deleted'") } + scope :for_context_codes, lambda { |codes| where(:context_code => codes) } scope :before, lambda { |date| where("discussion_topics.created_at { order("discussion_topics.position ASC, discussion_topics.created_at DESC, discussion_topics.id DESC") } + scope :by_position_legacy, -> { order("discussion_topics.position DESC, discussion_topics.created_at DESC, discussion_topics.id DESC") } + scope :by_last_reply_at, -> { order("discussion_topics.last_reply_at DESC, discussion_topics.created_at DESC, discussion_topics.id DESC") } alias_attribute :available_from, :delayed_post_at alias_attribute :unlock_at, :delayed_post_at diff --git a/app/models/enrollment.rb b/app/models/enrollment.rb index b371836d005..0f4cee5f994 100644 --- a/app/models/enrollment.rb +++ b/app/models/enrollment.rb @@ -148,40 +148,40 @@ class Enrollment < ActiveRecord::Base } end - scope :active, where("enrollments.workflow_state<>'deleted'") + scope :active, -> { where("enrollments.workflow_state<>'deleted'") } - scope :admin, - select(:course_id). + scope :admin, -> { + select(:course_id). joins(:course). where("enrollments.type IN ('TeacherEnrollment','TaEnrollment', 'DesignerEnrollment') - AND (courses.workflow_state='claimed' OR (enrollments.workflow_state='active' AND courses.workflow_state='available'))") + AND (courses.workflow_state='claimed' OR (enrollments.workflow_state='active' AND courses.workflow_state='available'))") } - scope :of_admin_type, where(:type => ['TeacherEnrollment','TaEnrollment', 'DesignerEnrollment']) + scope :of_admin_type, -> { where(:type => ['TeacherEnrollment','TaEnrollment', 'DesignerEnrollment']) } - scope :of_instructor_type, where(:type => ['TeacherEnrollment', 'TaEnrollment']) + scope :of_instructor_type, -> { where(:type => ['TeacherEnrollment', 'TaEnrollment']) } - scope :of_content_admins, where(:type => ['TeacherEnrollment', 'DesignerEnrollment']) + scope :of_content_admins, -> { where(:type => ['TeacherEnrollment', 'DesignerEnrollment']) } - scope :student, - select(:course_id). + scope :student, -> { + select(:course_id). joins(:course). - where(:type => 'StudentEnrollment', :workflow_state => 'active', :courses => { :workflow_state => 'available' }) + where(:type => 'StudentEnrollment', :workflow_state => 'active', :courses => { :workflow_state => 'available' }) } - scope :student_in_claimed_or_available, - select(:course_id). + scope :student_in_claimed_or_available, -> { + select(:course_id). joins(:course). - where(:type => 'StudentEnrollment', :workflow_state => 'active', :courses => { :workflow_state => ['available', 'claimed'] }) + where(:type => 'StudentEnrollment', :workflow_state => 'active', :courses => { :workflow_state => ['available', 'claimed'] }) } - scope :all_student, - includes(:course). + scope :all_student, -> { + includes(:course). where("(enrollments.type = 'StudentEnrollment' AND enrollments.workflow_state IN ('invited', 'active', 'completed') AND courses.workflow_state IN ('available', 'completed')) OR (enrollments.type = 'StudentViewEnrollment' AND enrollments.workflow_state = 'active' - AND courses.workflow_state != 'deleted')") + AND courses.workflow_state != 'deleted')") } - scope :future, lambda { + scope :future, -> { joins(:course). where("(courses.start_at>? AND courses.workflow_state='available' @@ -191,16 +191,15 @@ class Enrollment < ActiveRecord::Base courses.workflow_state IN ('created', 'claimed') AND enrollments.type IN ('TeacherEnrollment','TaEnrollment', 'DesignerEnrollment') AND enrollments.workflow_state IN ('invited', 'active', 'creation_pending') - )", Time.now.utc, true) - } + )", Time.now.utc, true) } - scope :past, - joins(:course). + scope :past, -> { + joins(:course). where("(courses.workflow_state='completed' AND enrollments.workflow_state NOT IN ('invited', 'deleted')) - OR enrollments.workflow_state IN ('rejected', 'completed')") + OR enrollments.workflow_state IN ('rejected', 'completed')") } - scope :not_fake, where("enrollments.type<>'StudentViewEnrollment'") + scope :not_fake, -> { where("enrollments.type<>'StudentViewEnrollment'") } def self.readable_types @@ -883,7 +882,7 @@ class Enrollment < ActiveRecord::Base can :read_services end - scope :before, lambda{ |date| + scope :before, lambda { |date| where("enrollments.created_at 'invited') - scope :accepted, where("enrollments.workflow_state<>'invited'") - scope :active_or_pending, where(:workflow_state => ['invited', 'creation_pending', 'active']) - scope :currently_online, joins(:pseudonyms).where("pseudonyms.last_request_at>?", 5.minutes.ago) + scope :invited, -> { where(:workflow_state => 'invited') } + scope :accepted, -> { where("enrollments.workflow_state<>'invited'") } + scope :active_or_pending, -> { where(:workflow_state => ['invited', 'creation_pending', 'active']) } + scope :currently_online, -> { joins(:pseudonyms).where("pseudonyms.last_request_at>?", 5.minutes.ago) } # this returns enrollments for creation_pending users; should always be used in conjunction with the invited scope scope :for_email, lambda { |email| joins(:user => :communication_channels). diff --git a/app/models/enrollment_term.rb b/app/models/enrollment_term.rb index 4d41e430a56..60a9b103690 100644 --- a/app/models/enrollment_term.rb +++ b/app/models/enrollment_term.rb @@ -140,5 +140,5 @@ class EnrollmentTerm < ActiveRecord::Base save! end - scope :active, where("enrollment_terms.workflow_state<>'deleted'") + scope :active, -> { where("enrollment_terms.workflow_state<>'deleted'") } end diff --git a/app/models/eportfolio.rb b/app/models/eportfolio.rb index c771d398cef..b5ca4a5728d 100644 --- a/app/models/eportfolio.rb +++ b/app/models/eportfolio.rb @@ -43,7 +43,7 @@ class Eportfolio < ActiveRecord::Base self.save end - scope :active, where("eportfolios.workflow_state<>'deleted'") + scope :active, -> { where("eportfolios.workflow_state<>'deleted'") } before_create :assign_uuid def assign_uuid diff --git a/app/models/external_feed.rb b/app/models/external_feed.rb index 53fff060b15..ab9e51be214 100644 --- a/app/models/external_feed.rb +++ b/app/models/external_feed.rb @@ -52,7 +52,7 @@ class ExternalFeed < ActiveRecord::Base write_attribute(:header_match, str.to_s.strip.presence) end - scope :to_be_polled, lambda { + scope :to_be_polled, -> { where("external_feeds.consecutive_failures<5 AND external_feeds.refresh_at'deleted'") - scope :not_hidden, where("folders.workflow_state<>'hidden'") - scope :not_locked, lambda { where("(folders.locked IS NULL OR folders.locked=?) AND ((folders.lock_at IS NULL) OR + scope :active, -> { where("folders.workflow_state<>'deleted'") } + scope :not_hidden, -> { where("folders.workflow_state<>'hidden'") } + scope :not_locked, -> { where("(folders.locked IS NULL OR folders.locked=?) AND ((folders.lock_at IS NULL) OR (folders.lock_at>? OR (folders.unlock_at IS NOT NULL AND folders.unlock_at { order(:position) } + scope :by_name, -> { order(name_order_by_clause('folders')) } def display_name name diff --git a/app/models/grading_standard.rb b/app/models/grading_standard.rb index 27d7c834e14..75d19199edc 100644 --- a/app/models/grading_standard.rb +++ b/app/models/grading_standard.rb @@ -59,8 +59,8 @@ class GradingStandard < ActiveRecord::Base state :deleted end - scope :active, where("grading_standards.workflow_state<>'deleted'") - scope :sorted, lambda { order("usage_count >= 3 DESC").order(nulls(:last, best_unicode_collation_key('title'))) } + scope :active, -> { where("grading_standards.workflow_state<>'deleted'") } + scope :sorted, -> { order("usage_count >= 3 DESC").order(nulls(:last, best_unicode_collation_key('title'))) } VERSION = 2 diff --git a/app/models/group.rb b/app/models/group.rb index b49065669e5..13b896f47ab 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -251,9 +251,9 @@ class Group < ActiveRecord::Base Bookmarker = BookmarkedCollection::SimpleBookmarker.new(Group, :name, :id) - scope :active, where("groups.workflow_state<>'deleted'") - scope :by_name, lambda { order(Bookmarker.order_by) } - scope :uncategorized, where("groups.group_category_id IS NULL") + scope :active, -> { where("groups.workflow_state<>'deleted'") } + scope :by_name, -> { order(Bookmarker.order_by) } + scope :uncategorized, -> { where("groups.group_category_id IS NULL") } def full_name res = before_label(self.name) + " " diff --git a/app/models/group_category.rb b/app/models/group_category.rb index 9d213448536..9679afd81a7 100644 --- a/app/models/group_category.rb +++ b/app/models/group_category.rb @@ -80,7 +80,7 @@ class GroupCategory < ActiveRecord::Base end end - scope :active, where(:deleted_at => nil) + scope :active, -> { where(:deleted_at => nil) } scope :other_than, lambda { |cat| where("group_categories.id<>?", cat.id || 0) } diff --git a/app/models/group_membership.rb b/app/models/group_membership.rb index 1b6d761028e..fa73957f97e 100644 --- a/app/models/group_membership.rb +++ b/app/models/group_membership.rb @@ -45,10 +45,10 @@ class GroupMembership < ActiveRecord::Base has_a_broadcast_policy - scope :include_user, includes(:user) + scope :include_user, -> { includes(:user) } - scope :active, where("group_memberships.workflow_state<>'deleted'") - scope :moderators, where(:moderator => true) + scope :active, -> { where("group_memberships.workflow_state<>'deleted'") } + scope :moderators, -> { where(:moderator => true) } alias_method :context, :group diff --git a/app/models/inbox_item.rb b/app/models/inbox_item.rb index c8ffab5d1b6..bcd61eebea9 100644 --- a/app/models/inbox_item.rb +++ b/app/models/inbox_item.rb @@ -44,8 +44,8 @@ class InboxItem < ActiveRecord::Base attr_accessible :user_id, :asset, :subject, :body_teaser, :sender_id # Named scopes - scope :active, where("workflow_state NOT IN ('deleted', 'retired', 'retired_unread')") - scope :unread, where(:workflow_state => 'unread') + scope :active, -> { where("workflow_state NOT IN ('deleted', 'retired', 'retired_unread')") } + scope :unread, -> { where(:workflow_state => 'unread') } # State machine workflow do diff --git a/app/models/learning_outcome.rb b/app/models/learning_outcome.rb index 6bd713d5911..d205f9c218c 100644 --- a/app/models/learning_outcome.rb +++ b/app/models/learning_outcome.rb @@ -207,13 +207,13 @@ class LearningOutcome < ActiveRecord::Base end scope :for_context_codes, lambda { |codes| where(:context_code => codes) } - scope :active, where("learning_outcomes.workflow_state<>'deleted'") + scope :active, -> { where("learning_outcomes.workflow_state<>'deleted'") } scope :has_result_for, lambda { |user| joins(:learning_outcome_results). where("learning_outcomes.id=learning_outcome_results.learning_outcome_id AND learning_outcome_results.user_id=?", user). order(best_unicode_collation_key('short_description')) } - scope :global, where(:context_id => nil) + scope :global, -> { where(:context_id => nil) } end diff --git a/app/models/learning_outcome_group.rb b/app/models/learning_outcome_group.rb index 39364840cfe..f0cc82bd724 100644 --- a/app/models/learning_outcome_group.rb +++ b/app/models/learning_outcome_group.rb @@ -228,11 +228,11 @@ class LearningOutcomeGroup < ActiveRecord::Base end end - scope :active, where("learning_outcome_groups.workflow_state<>'deleted'") + scope :active, -> { where("learning_outcome_groups.workflow_state<>'deleted'") } - scope :global, where(:context_id => nil) + scope :global, -> { where(:context_id => nil) } - scope :root, where(:learning_outcome_group_id => nil) + scope :root, -> { where(:learning_outcome_group_id => nil) } def self.for_context(context) context ? context.learning_outcome_groups : LearningOutcomeGroup.global diff --git a/app/models/media_object.rb b/app/models/media_object.rb index d0b509304ab..ac6f0b238f1 100644 --- a/app/models/media_object.rb +++ b/app/models/media_object.rb @@ -336,7 +336,7 @@ class MediaObject < ActiveRecord::Base save! end - scope :active, where("media_objects.workflow_state<>'deleted'") + scope :active, -> { where("media_objects.workflow_state<>'deleted'") } scope :by_media_id, lambda { |media_id| where("media_objects.media_id=? OR media_objects.old_media_id=?", media_id, media_id) } diff --git a/app/models/message.rb b/app/models/message.rb index 3e4f1268ffc..63a075d1c71 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -140,15 +140,15 @@ class Message < ActiveRecord::Base scope :after, lambda { |date| where("messages.created_at>?", date) } - scope :to_dispatch, lambda { + scope :to_dispatch, -> { where("messages.workflow_state='staged' AND messages.dispatch_at<=? AND 'messages.to'<>'dashboard'", Time.now.utc) } - scope :to_email, where(:path_type => ['email', 'sms']) + scope :to_email, -> { where(:path_type => ['email', 'sms']) } - scope :to_facebook, where(:path_type => 'facebook', :workflow_state => 'sent').order("sent_at DESC").limit(25) + scope :to_facebook, -> { where(:path_type => 'facebook', :workflow_state => 'sent').order("sent_at DESC").limit(25) } - scope :not_to_email, where("messages.path_type NOT IN ('email', 'sms')") + scope :not_to_email, -> { where("messages.path_type NOT IN ('email', 'sms')") } scope :by_name, lambda { |notification_name| where(:notification_name => notification_name) } @@ -158,13 +158,13 @@ class Message < ActiveRecord::Base # messages that can be moved to the 'cancelled' state. dashboard messages # can be closed by calling 'cancel', but aren't included - scope :cancellable, where(:workflow_state => ['created', 'staged', 'sending']) + scope :cancellable, -> { where(:workflow_state => ['created', 'staged', 'sending']) } # For finding a very particular message: # Message.for(context).by_name(name).directed_to(to).for_user(user), or # messages.for(context).by_name(name).directed_to(to).for_user(user) # Where user can be a User or id, name needs to be the Notification name. - scope :staged, lambda { where("messages.workflow_state='staged' AND messages.dispatch_at>?", Time.now.utc) } + scope :staged, -> { where("messages.workflow_state='staged' AND messages.dispatch_at>?", Time.now.utc) } scope :in_state, lambda { |state| where(:workflow_state => Array(state).map(&:to_s)) } diff --git a/app/models/migration_issue.rb b/app/models/migration_issue.rb index 52981fd0e51..b19d882cb00 100644 --- a/app/models/migration_issue.rb +++ b/app/models/migration_issue.rb @@ -17,8 +17,8 @@ class MigrationIssue < ActiveRecord::Base state :resolved end - scope :active, where(:workflow_state => 'active') - scope :by_created_at, order(:created_at) + scope :active, -> { where(:workflow_state => 'active') } + scope :by_created_at, -> { order(:created_at) } set_policy do given { |user| Account.site_admin.grants_right?(user, :view_error_reports) } diff --git a/app/models/notification.rb b/app/models/notification.rb index 86e96012684..a5fe4d82a6b 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -52,7 +52,7 @@ class Notification < ActiveRecord::Base attr_accessible :name, :subject, :main_link, :delay_for, :category - scope :to_show_in_feed, where("messages.category='TestImmediately' OR messages.notification_name IN (?)", TYPES_TO_SHOW_IN_FEED) + scope :to_show_in_feed, -> { where("messages.category='TestImmediately' OR messages.notification_name IN (?)", TYPES_TO_SHOW_IN_FEED) } validates_uniqueness_of :name diff --git a/app/models/pseudonym.rb b/app/models/pseudonym.rb index 0aa58053e00..75b38c2c487 100644 --- a/app/models/pseudonym.rb +++ b/app/models/pseudonym.rb @@ -381,7 +381,7 @@ class Pseudonym < ActiveRecord::Base nil end - scope :active, where(workflow_state: 'active') + scope :active, -> { where(workflow_state: 'active') } def self.serialization_excludes; [:crypted_password, :password_salt, :reset_password_token, :persistence_token, :single_access_token, :perishable_token, :sis_ssha]; end diff --git a/app/models/quizzes/quiz.rb b/app/models/quizzes/quiz.rb index 3f83a22a0e8..03f3627fb1f 100644 --- a/app/models/quizzes/quiz.rb +++ b/app/models/quizzes/quiz.rb @@ -1062,11 +1062,11 @@ class Quizzes::Quiz < ActiveRecord::Base can :read and can :submit end - scope :include_assignment, includes(:assignment) + scope :include_assignment, -> { includes(:assignment) } scope :before, lambda { |date| where("quizzes.created_at'deleted'") - scope :not_for_assignment, where(:assignment_id => nil) - scope :available, where("quizzes.workflow_state = 'available'") + scope :active, -> { where("quizzes.workflow_state<>'deleted'") } + scope :not_for_assignment, -> { where(:assignment_id => nil) } + scope :available, -> { where("quizzes.workflow_state = 'available'") } def teachers context.teacher_enrollments.map(&:user) diff --git a/app/models/quizzes/quiz_question.rb b/app/models/quizzes/quiz_question.rb index d63bc31b544..b99867e7a74 100644 --- a/app/models/quizzes/quiz_question.rb +++ b/app/models/quizzes/quiz_question.rb @@ -43,7 +43,7 @@ class Quizzes::QuizQuestion < ActiveRecord::Base state :deleted end - scope :active, where("workflow_state='active' OR workflow_state IS NULL") + scope :active, -> { where("workflow_state='active' OR workflow_state IS NULL") } def infer_defaults if !self.position && self.quiz diff --git a/app/models/quizzes/quiz_submission.rb b/app/models/quizzes/quiz_submission.rb index 711fdef1749..95825c7aba7 100644 --- a/app/models/quizzes/quiz_submission.rb +++ b/app/models/quizzes/quiz_submission.rb @@ -641,9 +641,9 @@ class Quizzes::QuizSubmission < ActiveRecord::Base date ? where("quiz_submissions.updated_at>?", date) : scoped } scope :for_user_ids, lambda { |user_ids| where(:user_id => user_ids) } - scope :logged_out, where("temporary_user_code is not null") - scope :not_settings_only, where("quiz_submissions.workflow_state<>'settings_only'") - scope :completed, where(:workflow_state => %w(complete pending_review)) + scope :logged_out, -> { where("temporary_user_code is not null") } + scope :not_settings_only, -> { where("quiz_submissions.workflow_state<>'settings_only'") } + scope :completed, -> { where(:workflow_state => %w(complete pending_review)) } has_a_broadcast_policy diff --git a/app/models/report_snapshot.rb b/app/models/report_snapshot.rb index 66a364aded0..5aa96bf234f 100644 --- a/app/models/report_snapshot.rb +++ b/app/models/report_snapshot.rb @@ -74,10 +74,10 @@ class ReportSnapshot < ActiveRecord::Base write_attribute(:data, data.to_json) end - scope :detailed, where(:report_type => 'counts_detailed') - scope :progressive, where(:report_type => 'counts_progressive_detailed') - scope :overview, where(:report_type => 'counts_overview') - scope :progressive_overview, where(:report_type => 'counts_progressive_overview') + scope :detailed, -> { where(:report_type => 'counts_detailed') } + scope :progressive, -> { where(:report_type => 'counts_progressive_detailed') } + scope :overview, -> { where(:report_type => 'counts_overview') } + scope :progressive_overview, -> { where(:report_type => 'counts_progressive_overview') } def push_to_instructure_if_collection_enabled begin diff --git a/app/models/role.rb b/app/models/role.rb index 6351d911a75..642cffd5534 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -75,12 +75,12 @@ class Role < ActiveRecord::Base save! end - scope :not_deleted, where("roles.workflow_state<>'deleted'") - scope :deleted, where(:workflow_state => 'deleted') - scope :active, where(:workflow_state => 'active') - scope :inactive, where(:workflow_state => 'inactive') - scope :for_courses, where("roles.base_role_type<>?", AccountUser::BASE_ROLE_NAME) - scope :for_accounts, where(:base_role_type => AccountUser::BASE_ROLE_NAME) + scope :not_deleted, -> { where("roles.workflow_state<>'deleted'") } + scope :deleted, -> { where(:workflow_state => 'deleted') } + scope :active, -> { where(:workflow_state => 'active') } + scope :inactive, -> { where(:workflow_state => 'inactive') } + scope :for_courses, -> { where("roles.base_role_type<>?", AccountUser::BASE_ROLE_NAME) } + scope :for_accounts, -> { where(:base_role_type => AccountUser::BASE_ROLE_NAME) } def self.is_base_role?(role_name) RoleOverride.base_role_types.include?(role_name) diff --git a/app/models/rubric.rb b/app/models/rubric.rb index e9bd598694d..1e877097178 100644 --- a/app/models/rubric.rb +++ b/app/models/rubric.rb @@ -45,10 +45,10 @@ class Rubric < ActiveRecord::Base serialize :data simply_versioned - scope :publicly_reusable, lambda { where(:reusable => true).order(best_unicode_collation_key('title')) } + scope :publicly_reusable, -> { where(:reusable => true).order(best_unicode_collation_key('title')) } scope :matching, lambda { |search| where(wildcard('rubrics.title', search)).order("rubrics.association_count DESC") } scope :before, lambda { |date| where("rubrics.created_at'deleted'") + scope :active, -> { where("workflow_state<>'deleted'") } set_policy do given {|user, session| self.context.grants_right?(user, session, :manage_rubrics)} diff --git a/app/models/rubric_association.rb b/app/models/rubric_association.rb index 07d29bfb6dc..d96fdbf928a 100644 --- a/app/models/rubric_association.rb +++ b/app/models/rubric_association.rb @@ -82,11 +82,11 @@ class RubricAssociation < ActiveRecord::Base } end - scope :bookmarked, where(:bookmarked => true) + scope :bookmarked, -> { where(:bookmarked => true) } scope :for_purpose, lambda { |purpose| where(:purpose => purpose) } - scope :for_grading, where(:purpose => 'grading') + scope :for_grading, -> { where(:purpose => 'grading') } scope :for_context_codes, lambda { |codes| where(:context_code => codes) } - scope :include_rubric, includes(:rubric) + scope :include_rubric, -> { includes(:rubric) } scope :before, lambda { |date| where("rubric_associations.created_at 'created').order(:created_at) - scope :importing, where(:workflow_state => 'importing') + scope :needs_processing, -> { where(:workflow_state => 'created').order(:created_at) } + scope :importing, -> { where(:workflow_state => 'importing') } def self.process_all_for_account(account) loop do diff --git a/app/models/submission.rb b/app/models/submission.rb index 2671aeec47b..ef3d01ba35b 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -65,12 +65,12 @@ class Submission < ActiveRecord::Base include CustomValidations validates_as_url :url - scope :with_comments, includes(:submission_comments) + scope :with_comments, -> { includes(:submission_comments) } scope :after, lambda { |date| where("submissions.created_at>?", date) } scope :before, lambda { |date| where("submissions.created_at?", date) } - scope :with_point_data, where("submissions.score IS NOT NULL OR submissions.grade IS NOT NULL") + scope :with_point_data, -> { where("submissions.score IS NOT NULL OR submissions.grade IS NOT NULL") } scope :for_context_codes, lambda { |context_codes| where(:context_code => context_codes) } @@ -104,7 +104,7 @@ class Submission < ActiveRecord::Base conditions end - scope :needs_grading, where(needs_grading_conditions) + scope :needs_grading, -> { where(needs_grading_conditions) } sanitize_field :body, CanvasSanitize::SANITIZE @@ -753,23 +753,23 @@ class Submission < ActiveRecord::Base state :graded end - scope :graded, where("submissions.grade IS NOT NULL") + scope :graded, -> { where("submissions.grade IS NOT NULL") } - scope :ungraded, where(:grade => nil).includes(:assignment) + scope :ungraded, -> { where(:grade => nil).includes(:assignment) } scope :in_workflow_state, lambda { |provided_state| where(:workflow_state => provided_state) } - scope :having_submission, where("submissions.submission_type IS NOT NULL") - scope :without_submission, where(submission_type: nil, workflow_state: "unsubmitted") + scope :having_submission, -> { where("submissions.submission_type IS NOT NULL") } + scope :without_submission, -> { where(submission_type: nil, workflow_state: "unsubmitted") } - scope :include_user, includes(:user) + scope :include_user, -> { includes(:user) } - scope :include_assessment_requests, includes(:assessment_requests, :assigned_assessments) - scope :include_versions, includes(:versions) - scope :include_submission_comments, includes(:submission_comments) - scope :speed_grader_includes, includes(:versions, :submission_comments, :attachments, :rubric_assessment) + scope :include_assessment_requests, -> { includes(:assessment_requests, :assigned_assessments) } + scope :include_versions, -> { includes(:versions) } + scope :include_submission_comments, -> { includes(:submission_comments) } + scope :speed_grader_includes, -> { includes(:versions, :submission_comments, :attachments, :rubric_assessment) } scope :for_user, lambda { |user| where(:user_id => user) } - scope :needing_screenshot, where("submissions.submission_type='online_url' AND submissions.attachment_id IS NULL AND submissions.process_attempts<3").order(:updated_at) + scope :needing_screenshot, -> { where("submissions.submission_type='online_url' AND submissions.attachment_id IS NULL AND submissions.process_attempts<3").order(:updated_at) } def needs_regrading? graded? && !grade_matches_current_submission? diff --git a/app/models/submission_comment.rb b/app/models/submission_comment.rb index e54ea3946d6..eadb33bcf77 100644 --- a/app/models/submission_comment.rb +++ b/app/models/submission_comment.rb @@ -223,7 +223,7 @@ class SubmissionComment < ActiveRecord::Base context.root_account.service_enabled?(:avatars) ? [:avatar_path] : [] end - scope :visible, where(:hidden => false) + scope :visible, -> { where(:hidden => false) } scope :after, lambda { |date| where("submission_comments.created_at>?", date) } scope :for_context, lambda { |context| where(:context_id => context, :context_type => context.class.to_s) } diff --git a/app/models/user.rb b/app/models/user.rb index a3571b0d609..270dcd67854 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -186,13 +186,13 @@ class User < ActiveRecord::Base end scope :of_account, lambda { |account| where("EXISTS (?)", account.user_account_associations.where("user_account_associations.user_id=users.id")).shard(account.shard) } - scope :recently_logged_in, lambda { + scope :recently_logged_in, -> { includes(:pseudonyms). where("pseudonyms.current_login_at>?", 1.month.ago). order("pseudonyms.current_login_at DESC"). limit(25) } - scope :include_pseudonym, includes(:pseudonym) + scope :include_pseudonym, -> { includes(:pseudonym) } scope :restrict_to_sections, lambda { |sections| if sections.empty? scoped @@ -203,9 +203,9 @@ class User < ActiveRecord::Base scope :name_like, lambda { |name| where("#{wildcard('users.name', 'users.short_name', name)} OR EXISTS (?)", Pseudonym.where(wildcard('pseudonyms.sis_user_id', 'pseudonyms.unique_id', name)).where("pseudonyms.user_id=users.id").active) } - scope :active, where("users.workflow_state<>'deleted'") + scope :active, -> { where("users.workflow_state<>'deleted'") } - scope :has_current_student_enrollments, where("EXISTS (SELECT * FROM enrollments JOIN courses ON courses.id=enrollments.course_id AND courses.workflow_state='available' WHERE enrollments.user_id=users.id AND enrollments.workflow_state IN ('active','invited') AND enrollments.type='StudentEnrollment')") + scope :has_current_student_enrollments, -> { where("EXISTS (SELECT * FROM enrollments JOIN courses ON courses.id=enrollments.course_id AND courses.workflow_state='available' WHERE enrollments.user_id=users.id AND enrollments.workflow_state IN ('active','invited') AND enrollments.type='StudentEnrollment')") } def self.order_by_sortable_name(options = {}) order_clause = clause = sortable_name_order_by_clause diff --git a/app/models/user_note.rb b/app/models/user_note.rb index d9f1246ecfe..b5d2b715487 100644 --- a/app/models/user_note.rb +++ b/app/models/user_note.rb @@ -37,8 +37,8 @@ class UserNote < ActiveRecord::Base state :deleted end - scope :active, where("workflow_state<>'deleted'") - scope :desc_by_date, order('created_at DESC') + scope :active, -> { where("workflow_state<>'deleted'") } + scope :desc_by_date, -> { order('created_at DESC') } set_policy do given { |user| self.creator == user } diff --git a/app/models/user_service.rb b/app/models/user_service.rb index 1c450e87e6d..341ca67b47c 100644 --- a/app/models/user_service.rb +++ b/app/models/user_service.rb @@ -79,13 +79,13 @@ class UserService < ActiveRecord::Base scope :of_type, lambda { |type| where(:type => type.to_s) } - scope :to_be_polled, lambda { where("refresh_at<", Time.now.utc).order(:refresh_at).limit(1) } + scope :to_be_polled, -> { where("refresh_at<", Time.now.utc).order(:refresh_at).limit(1) } scope :for_user, lambda { |user| where(:user_id => user) } scope :for_service, lambda { |service| service = service.service if service.is_a?(UserService) where(:service => service.to_s) } - scope :visible, where("visible") + scope :visible, -> { where("visible") } def service_name self.service.titleize rescue "" diff --git a/app/models/web_conference.rb b/app/models/web_conference.rb index 029951d0652..0e952f37aec 100644 --- a/app/models/web_conference.rb +++ b/app/models/web_conference.rb @@ -48,7 +48,7 @@ class WebConference < ActiveRecord::Base scope :for_context_codes, lambda { |context_codes| where(:context_code => context_codes) } - scope :with_config, lambda { where(conference_type: WebConference.conference_types.map{|ct| ct['conference_type']}) } + scope :with_config, -> { where(conference_type: WebConference.conference_types.map{|ct| ct['conference_type']}) } serialize :settings def settings @@ -418,7 +418,7 @@ class WebConference < ActiveRecord::Base end end - scope :active, scoped + scope :active, -> { scoped } def as_json(options={}) url = options.delete(:url) diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index ec2749360db..c993e492538 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -217,21 +217,21 @@ class WikiPage < ActiveRecord::Base self.versions.map(&:model) end - scope :active, where(:workflow_state => 'active') + scope :active, -> { where(:workflow_state => 'active') } - scope :deleted_last, order("workflow_state='deleted'") + scope :deleted_last, -> { order("workflow_state='deleted'") } - scope :not_deleted, where("wiki_pages.workflow_state<>'deleted'") + scope :not_deleted, -> { where("wiki_pages.workflow_state<>'deleted'") } - scope :published, where("wiki_pages.workflow_state='active' AND (wiki_pages.hide_from_students=? OR wiki_pages.hide_from_students IS NULL)", false) - scope :unpublished, where("wiki_pages.workflow_state='unpublished' OR (wiki_pages.hide_from_students=? AND wiki_pages.workflow_state<>'deleted')", true) + scope :published, -> { where("wiki_pages.workflow_state='active' AND (wiki_pages.hide_from_students=? OR wiki_pages.hide_from_students IS NULL)", false) } + scope :unpublished, -> { where("wiki_pages.workflow_state='unpublished' OR (wiki_pages.hide_from_students=? AND wiki_pages.workflow_state<>'deleted')", true) } # needed for ensure_unique_url def not_deleted !deleted? end - scope :order_by_id, order(:id) + scope :order_by_id, -> { order(:id) } def locked_for?(user, opts={}) return false unless self.could_be_locked diff --git a/config/initializers/active_record.rb b/config/initializers/active_record.rb index 1f0defe5c1a..3c74193bd4a 100644 --- a/config/initializers/active_record.rb +++ b/config/initializers/active_record.rb @@ -886,9 +886,9 @@ class ActiveRecord::Base if Rails.version < '4' if CANVAS_RAILS2 - named_scope :none, lambda { where("?", false) } + named_scope :none, -> { where("?", false) } else - scope :none, lambda { {:conditions => ["?", false]} } + scope :none, -> { {:conditions => ["?", false]} } end end end