replace deprecated find(:all, ...) finders

pull/6827/head
Jan Sandbrink 9 years ago
parent 10d39a64a1
commit 1b3fb0b84b
  1. 2
      app/controllers/work_package_boxes_controller.rb
  2. 4
      app/helpers/rb_common_helper.rb
  3. 4
      app/models/sprint.rb
  4. 4
      features/step_definitions/_given_steps.rb
  5. 16
      features/step_definitions/_then_steps.rb
  6. 2
      features/step_definitions/_when_steps.rb
  7. 4
      lib/open_project/backlogs/patches/version_patch.rb
  8. 5
      spec/models/version_spec.rb

@ -85,7 +85,7 @@ class WorkPackageBoxesController < WorkPackagesController
private
def load_journals
@journals = @work_package.journals.find(:all, include: [:user], order: "#{Journal.table_name}.created_at ASC")
@journals = @work_package.journals.includes(:user).order("#{Journal.table_name}.created_at ASC")
@journals.reverse! if User.current.wants_comments_in_reverse_order?
end
end

@ -225,9 +225,7 @@ module RbCommonHelper
backlogs_ids = Setting.plugin_openproject_backlogs['story_types']
backlogs_ids << Setting.plugin_openproject_backlogs['task_type']
Type.find(:all,
conditions: { id: backlogs_ids },
order: 'position ASC')
Type.where(id: backlogs_ids).order('position ASC')
end
end

@ -149,10 +149,10 @@ class Sprint < Version
conditions = '1 = 1'
end
Version.find(:all, conditions: conditions).each(&:burndown)
Version.where(conditions).each(&:burndown)
end
def impediments(project)
Impediment.find(:all, conditions: { fixed_version_id: self, project_id: project })
Impediment.where(fixed_version_id: self, project_id: project)
end
end

@ -93,7 +93,7 @@ Given /^I want to edit the sprint named (.+)$/ do |name|
end
Given /^I want to indicate that the impediment blocks (.+)$/ do |blocks_csv|
blocks_csv = Story.find(:all, conditions: { subject: blocks_csv.split(', ') }).map(&:id).join(',')
blocks_csv = Story.where(subject: blocks_csv.split(', ')).pluck(:id).join(',')
@impediment_params[:blocks] = blocks_csv
end
@ -238,7 +238,7 @@ Given /^the [pP]roject(?: "([^\"]*)")? has the following impediments:$/ do |proj
as_admin do
table.hashes.each do |impediment|
sprint = Sprint.find(:first, conditions: { name: impediment['sprint'] })
blocks = Story.find(:all, conditions: { subject: impediment['blocks'].split(', ') }).map(&:id)
blocks = Story.where(subject: impediment['blocks'].split(', ')).pluck(:id)
params = initialize_impediment_params(project, sprint)
params['subject'] = impediment['subject']
params['blocks_ids'] = blocks.join(',')

@ -78,7 +78,7 @@ Then /^the velocity of "(.+?)" should be "(.+?)"$/ do |backlog_name, velocity|
end
Then /^show me the list of sprints$/ do
sprints = Sprint.find(:all, conditions: ['project_id=?', @project.id])
sprints = Sprint.where(project_id: @project.id)
puts "\n"
puts "\t| #{'id'.ljust(3)} | #{'name'.ljust(18)} | #{'start_date'.ljust(18)} | #{'effective_date'.ljust(18)} | #{'updated_on'.ljust(20)}"
@ -89,9 +89,9 @@ Then /^show me the list of sprints$/ do
end
Then /^show me the list of stories$/ do
stories = Story.find(:all, conditions: "project_id=#{@project.id}", order: 'position ASC')
stories = Story.where(project_id: @project.id).order('position ASC')
subject_max = (stories.map(&:subject) << 'subject').sort { |a, b| a.length <=> b.length }.last.length
sprints = @project.versions.find(:all)
sprints = @project.versions
sprint_max = (sprints.map(&:name) << 'sprint').sort { |a, b| a.length <=> b.length }.last.length
puts "\n"
@ -105,10 +105,10 @@ end
Then /^(.+) should be the higher (story|item|task) of (.+)$/ do |higher_subject, type, lower_subject|
work_package_class = (type == 'task') ? Task : Story
higher = work_package_class.find(:all, conditions: { subject: higher_subject })
higher = work_package_class.where(subject: higher_subject)
higher.length.should == 1
lower = work_package_class.find(:all, conditions: { subject: lower_subject })
lower = work_package_class.where(subject: lower_subject)
lower.length.should == 1
if type == 'task'
@ -165,7 +165,7 @@ Then /^the server should return (\d+) updated (.+)$/ do |count, object_type|
end
Then /^the sprint named (.+) should have (\d+) impediments? named (.+)$/ do |sprint_name, count, impediment_subject|
sprints = Sprint.find(:all, conditions: { name: sprint_name })
sprints = Sprint.where(name: sprint_name)
sprints.length.should == 1
sprints.first.impediments.map { |i| i.subject == impediment_subject }.length.should == count.to_i
@ -193,10 +193,10 @@ Then /^the status of the story should be set as (.+)$/ do |status|
end
Then /^the story named (.+) should have 1 task named (.+)$/ do |story_subject, task_subject|
stories = Story.find(:all, conditions: { subject: story_subject })
stories = Story.where(subject: story_subject)
stories.length.should == 1
tasks = Task.find(:all, conditions: { parent_id: stories.first.id, subject: task_subject })
tasks = Task.where(parent_id: stories.first.id, subject: task_subject)
tasks.length.should == 1
end

@ -78,7 +78,7 @@ When /^I move the story named (.+) (up|down) to the (\d+)(?:st|nd|rd|th) positio
attributes[:prev] = if position == 1
''
else
stories = Story.find(:all, conditions: ['fixed_version_id=? AND type_id IN (?)', sprint.id, Story.types], order: 'position ASC')
stories = Story.where(['fixed_version_id=? AND type_id IN (?)', sprint.id, Story.types]).order('position ASC')
raise "You indicated an invalid position (#{position}) in a sprint with #{stories.length} stories" if 0 > position or position > stories.length
stories[position - (direction == 'up' ? 2 : 1)].id
end

@ -58,9 +58,9 @@ module OpenProject::Backlogs::Patches::VersionPatch
# Add work_packages w/o position to the top of the list and add
# work_packages, that have a position, at the end
stories_wo_position = fixed_issues.find(:all, conditions: { project_id: project, type_id: Story.types, position: nil }, order: 'id')
stories_wo_position = fixed_issues.where(project_id: project, type_id: Story.types, position: nil).order('id')
stories_w_position = fixed_issues.find(:all, conditions: ['project_id = ? AND type_id IN (?) AND position IS NOT NULL', project, Story.types], order: 'COALESCE(position, 0), id')
stories_w_position = fixed_issues.where(['project_id = ? AND type_id IN (?) AND position IS NOT NULL', project, Story.types]).order('COALESCE(position, 0), id')
(stories_w_position + stories_wo_position).each_with_index do |story, index|
story.send(:update_attribute_silently, 'position', index + 1)

@ -151,7 +151,10 @@ describe Version, type: :model do
version.rebuild_positions(project)
work_packages = version.fixed_issues.find(:all, conditions: { project_id: project }, order: 'COALESCE(position, 0) ASC, id ASC')
work_packages = version
.fixed_issues
.where(project_id: project)
.order('COALESCE(position, 0) ASC, id ASC')
expect(work_packages.map(&:position)).to eq([nil, nil, 1, 2, 3, 4, 5])
expect(work_packages.map(&:subject)).to eq([t3, o9, e1, s2, s5, s3, s4].map(&:subject))

Loading…
Cancel
Save