Skip to content

Commit

Permalink
replace Relation#all with other methods to quiet deprecation warnings
Browse files Browse the repository at this point in the history
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`). (called from to_hash at /Users/tcabot/Code/surveyor/lib/surveyor/models/dependency_condition_methods.rb:39)
  • Loading branch information
toby cabot committed Aug 15, 2013
1 parent 8ba5e96 commit b59ecfd
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion features/step_definitions/parser_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

Then /^there should be (\d+) question(?:s?) with a correct answer$/ do |x|
Question.count(:conditions => "correct_answer_id NOT NULL").should == x.to_i
Question.all(:conditions => "correct_answer_id NOT NULL").compact.map(&:correct_answer).compact.size.should == x.to_i
Question.where("correct_answer_id NOT NULL").compact.map(&:correct_answer).compact.size.should == x.to_i
end

Then /^there should be (\d+) answer(?:s?) with:$/ do |x, table|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
class AddDisplayTypeToAnswers < ActiveRecord::Migration
def self.up
add_column :answers, :display_type, :string
Answer.all.each{|a| a.update_attributes(:display_type => "hidden_label") if a.hide_label == true}
Answer.find_each{|a| a.update_attributes(:display_type => "hidden_label") if a.hide_label == true}
remove_column :answers, :hide_label
end

def self.down
add_column :answers, :hide_label, :boolean
Answer.all.each{|a| a.update_attributes(:hide_label => true) if a.display_type == "hidden_label"}
Answer.find_each{|a| a.update_attributes(:hide_label => true) if a.display_type == "hidden_label"}
remove_column :answers, :display_type
end
end
2 changes: 1 addition & 1 deletion lib/surveyor/models/dependency_condition_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def operators
# Instance methods
def to_hash(response_set)
# all responses to associated question
responses = question.blank? ? [] : response_set.responses.where("responses.answer_id in (?)", question.answer_ids).all
responses = question.blank? ? [] : response_set.responses.where("responses.answer_id in (?)", question.answer_ids)
if self.operator.match /^count(>|>=|<|<=|==|!=)\d+$/
op, i = self.operator.scan(/^count(>|>=|<|<=|==|!=)(\d+)$/).flatten
# logger.warn({rule_key.to_sym => responses.count.send(op, i.to_i)})
Expand Down
4 changes: 2 additions & 2 deletions lib/surveyor/models/response_set_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def update_from_ui_hash(ui_hash)

def dependencies(question_ids = nil)
question_ids = survey.sections.map(&:questions).flatten.map(&:id) if responses.blank? and question_ids.blank?
deps = Dependency.all(:include => :dependency_conditions,
:conditions => {:dependency_conditions => {:question_id => question_ids || responses.map(&:question_id)}})
deps = Dependency.includes(:dependency_conditions).
where({:dependency_conditions => {:question_id => question_ids || responses.map(&:question_id)}})
# this is a work around for a bug in active_record in rails 2.3 which incorrectly eager-loads associatins when a
# condition clause includes an association limiter
deps.each{|d| d.dependency_conditions.reload}
Expand Down
2 changes: 1 addition & 1 deletion lib/surveyor/surveyor_controller_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.included(base)

# Actions
def new
@surveys_by_access_code = Survey.order("created_at DESC, survey_version DESC").all.group_by(&:access_code)
@surveys_by_access_code = Survey.order("created_at DESC, survey_version DESC").group_by(&:access_code)
redirect_to surveyor_index unless surveyor_index == surveyor.available_surveys_path
end

Expand Down

0 comments on commit b59ecfd

Please sign in to comment.