From ade06eae7d6f8ff6e5a3d7db2d2f5575b49045db Mon Sep 17 00:00:00 2001 From: toby cabot Date: Thu, 15 Aug 2013 15:15:38 -0400 Subject: [PATCH] fix deprecation warnings about calling scope() with a hash DEPRECATION WARNING: Calling #scope or #default_scope with a hash is deprecated. Please use a lambda containing a scope. E.g. scope :red, -> { where(color: 'red') }. (called from included at ~/surveyor/lib/surveyor/models/answer_methods.rb:13) We use instance_eval because we need the scope lambda to run in the context of the including Class, not the Module in which the code is defined. --- lib/surveyor/models/answer_methods.rb | 2 +- lib/surveyor/models/question_methods.rb | 2 +- lib/surveyor/models/survey_methods.rb | 2 +- lib/surveyor/models/survey_section_methods.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/surveyor/models/answer_methods.rb b/lib/surveyor/models/answer_methods.rb index df9e8ba3..705abb48 100644 --- a/lib/surveyor/models/answer_methods.rb +++ b/lib/surveyor/models/answer_methods.rb @@ -10,7 +10,7 @@ def self.included(base) base.send :has_many, :validations, :dependent => :destroy # Scopes - base.send :default_scope, :order => "#{base.quoted_table_name}.display_order ASC" + base.instance_eval {default_scope ->{order "#{base.quoted_table_name}.display_order ASC"}} # Mustache base.send :include, MustacheContext diff --git a/lib/surveyor/models/question_methods.rb b/lib/surveyor/models/question_methods.rb index afe3bf56..f7f76367 100644 --- a/lib/surveyor/models/question_methods.rb +++ b/lib/surveyor/models/question_methods.rb @@ -12,7 +12,7 @@ def self.included(base) base.send :belongs_to, :correct_answer, :class_name => "Answer", :dependent => :destroy # Scopes - base.send :default_scope, :order => "#{base.quoted_table_name}.display_order ASC" + base.instance_eval {default_scope ->{order "#{base.quoted_table_name}.display_order ASC"}} # Mustache base.send :include, MustacheContext diff --git a/lib/surveyor/models/survey_methods.rb b/lib/surveyor/models/survey_methods.rb index 0ff6f583..46ea6b8b 100644 --- a/lib/surveyor/models/survey_methods.rb +++ b/lib/surveyor/models/survey_methods.rb @@ -12,7 +12,7 @@ def self.included(base) base.send :has_many, :translations, :class_name => "SurveyTranslation" # Scopes - base.send :scope, :with_sections, {:include => :sections} + base.instance_eval {scope :with_sections, ->{includes :sections}} @@validations_already_included ||= nil unless @@validations_already_included diff --git a/lib/surveyor/models/survey_section_methods.rb b/lib/surveyor/models/survey_section_methods.rb index 67ae96b4..3657078b 100644 --- a/lib/surveyor/models/survey_section_methods.rb +++ b/lib/surveyor/models/survey_section_methods.rb @@ -7,7 +7,7 @@ def self.included(base) base.send :belongs_to, :survey # Scopes - base.send :scope, :with_includes, { :include => {:questions => [:answers, :question_group, {:dependency => :dependency_conditions}]}} + base.instance_eval {scope :with_includes, ->{ includes :questions => [:answers, :question_group, {:dependency => :dependency_conditions}]}} @@validations_already_included ||= nil unless @@validations_already_included