From 424889897a545ea1f6313cb16874cae34dcab2b6 Mon Sep 17 00:00:00 2001 From: Alex Coles Date: Sat, 27 Jun 2015 19:06:36 +0200 Subject: [PATCH] Migrate AR finder/query methods in specs Signed-off-by: Alex Coles --- spec/controllers/account_controller_spec.rb | 6 ++-- .../work_packages/moves_controller_spec.rb | 6 ++-- spec/factories/enumerations_factory.rb | 2 +- .../enumerations_controller_spec.rb | 2 +- .../functional/messages_controller_spec.rb | 8 +++--- .../project_enumerations_controller_spec.rb | 8 +++--- .../functional/projects_controller_spec.rb | 2 +- .../repositories_controller_spec.rb | 2 +- .../functional/roles_controller_spec.rb | 4 +-- .../functional/users_controller_spec.rb | 2 +- .../functional/welcome_controller_spec.rb | 2 +- .../functional/workflows_controller_spec.rb | 27 +++++++++--------- spec/legacy/support/legacy_assertions.rb | 2 +- spec/legacy/unit/board_spec.rb | 2 +- spec/legacy/unit/changeset_spec.rb | 8 +++--- spec/legacy/unit/enumeration_spec.rb | 2 +- spec/legacy/unit/journal_spec.rb | 8 +++--- .../legacy/unit/lib/redmine/ciphering_spec.rb | 6 ++-- spec/legacy/unit/mail_handler_spec.rb | 2 +- spec/legacy/unit/project_spec.rb | 26 ++++++++--------- spec/legacy/unit/query_spec.rb | 28 ++++++++----------- spec/legacy/unit/repository_git_spec.rb | 4 +-- spec/legacy/unit/repository_spec.rb | 4 +-- .../legacy/unit/repository_subversion_spec.rb | 2 +- spec/legacy/unit/search_spec.rb | 2 +- spec/legacy/unit/status_spec.rb | 6 ++-- spec/legacy/unit/user_spec.rb | 2 +- spec/legacy/unit/version_spec.rb | 8 +++--- spec/legacy/unit/wiki_page_spec.rb | 4 +-- spec/legacy/unit/wiki_redirect_spec.rb | 2 +- spec/support/shared/permissions.rb | 2 +- 31 files changed, 94 insertions(+), 97 deletions(-) diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb index bfd06dce9c..aea6b1c4a9 100644 --- a/spec/controllers/account_controller_spec.rb +++ b/spec/controllers/account_controller_spec.rb @@ -310,11 +310,11 @@ describe AccountController, type: :controller do is_expected.to respond_with :redirect expect(assigns[:user]).not_to be_nil is_expected.to redirect_to(my_first_login_path) - expect(User.last(conditions: { login: 'register' })).not_to be_nil + expect(User.where(login: 'register').last).not_to be_nil end it 'set the user status to active' do - user = User.last(conditions: { login: 'register' }) + user = User.where(login: 'register').last expect(user).not_to be_nil expect(user.status).to eq(User::STATUSES[:active]) end @@ -355,7 +355,7 @@ describe AccountController, type: :controller do it "doesn't activate the user but sends out a token instead" do expect(User.find_by_login('register')).not_to be_active - token = Token.find(:first) + token = Token.first expect(token.action).to eq('register') expect(token.user.mail).to eq('register@example.com') expect(token).not_to be_expired diff --git a/spec/controllers/work_packages/moves_controller_spec.rb b/spec/controllers/work_packages/moves_controller_spec.rb index 0583b2415a..30d6d8fb18 100644 --- a/spec/controllers/work_packages/moves_controller_spec.rb +++ b/spec/controllers/work_packages/moves_controller_spec.rb @@ -271,7 +271,7 @@ describe WorkPackages::MovesController, type: :controller do end it 'redirects to the work package copy' do - copy = WorkPackage.first(order: 'id desc') + copy = WorkPackage.order('id desc').first is_expected.to redirect_to(work_package_path(copy)) end end @@ -284,7 +284,7 @@ describe WorkPackages::MovesController, type: :controller do new_project_id: target_project.id end - subject { WorkPackage.first(order: 'id desc', conditions: { project_id: project.id }) } + subject { WorkPackage.order('id desc').where(project_id: project.id).first } it 'did not change the type' do expect(subject.type_id).to eq(work_package.type_id) @@ -321,7 +321,7 @@ describe WorkPackages::MovesController, type: :controller do due_date: due_date end - subject { WorkPackage.all(limit: 2, order: 'id desc', conditions: { project_id: target_project.id }) } + subject { WorkPackage.limit(2).order('id desc').where(project_id: target_project.id) } it 'copied two work packages' do expect(subject.count).to eq(2) diff --git a/spec/factories/enumerations_factory.rb b/spec/factories/enumerations_factory.rb index aa4333fdc9..a4763eab50 100644 --- a/spec/factories/enumerations_factory.rb +++ b/spec/factories/enumerations_factory.rb @@ -29,7 +29,7 @@ FactoryGirl.define do factory :default_enumeration, class: Enumeration do initialize_with do - Enumeration.find(:first, conditions: { type: 'Enumeration', is_default: true }) || Enumeration.new + Enumeration.where(type: 'Enumeration', is_default: true).first || Enumeration.new end active true diff --git a/spec/legacy/functional/enumerations_controller_spec.rb b/spec/legacy/functional/enumerations_controller_spec.rb index 354980d8a1..a99e62c244 100644 --- a/spec/legacy/functional/enumerations_controller_spec.rb +++ b/spec/legacy/functional/enumerations_controller_spec.rb @@ -56,7 +56,7 @@ describe EnumerationsController, type: :controller do end it 'should destroy enumeration in use with reassignment' do - issue = WorkPackage.find(:first, conditions: { priority_id: 4 }) + issue = WorkPackage.find_by(priority_id: 4) post :destroy, id: 4, reassign_to_id: 6 assert_redirected_to enumerations_path assert_nil Enumeration.find_by(id: 4) diff --git a/spec/legacy/functional/messages_controller_spec.rb b/spec/legacy/functional/messages_controller_spec.rb index 17a4285b0d..713963ada1 100644 --- a/spec/legacy/functional/messages_controller_spec.rb +++ b/spec/legacy/functional/messages_controller_spec.rb @@ -56,13 +56,13 @@ describe MessagesController, type: :controller do message.children << m end end - get :show, board_id: 1, id: 1, per_page: 100, r: message.children.last(order: 'id').id + get :show, board_id: 1, id: 1, per_page: 100, r: message.children.order('id').last.id assert_response :success assert_template 'show' replies = assigns(:replies) assert_not_nil replies - assert !replies.include?(message.children.first(order: 'id')) - assert replies.include?(message.children.last(order: 'id')) + assert !replies.include?(message.children.order('id').first) + assert replies.include?(message.children.order('id').last) end it 'should show with reply permission' do @@ -137,7 +137,7 @@ describe MessagesController, type: :controller do it 'should reply' do session[:user_id] = 2 post :reply, board_id: 1, id: 1, reply: { content: 'This is a test reply', subject: 'Test reply' } - reply = Message.find(:first, order: 'id DESC') + reply = Message.order('id DESC').first assert_redirected_to topic_path(1, r: reply) assert Message.find_by(subject: 'Test reply') end diff --git a/spec/legacy/functional/project_enumerations_controller_spec.rb b/spec/legacy/functional/project_enumerations_controller_spec.rb index c38080bf89..e501f217ab 100644 --- a/spec/legacy/functional/project_enumerations_controller_spec.rb +++ b/spec/legacy/functional/project_enumerations_controller_spec.rb @@ -92,14 +92,14 @@ describe ProjectEnumerationsController, type: :controller do project_activity = TimeEntryActivity.new( name: 'Project Specific', - parent: TimeEntryActivity.find(:first), + parent: TimeEntryActivity.first, project: Project.find(1), active: true ) assert project_activity.save project_activity_two = TimeEntryActivity.new( name: 'Project Specific Two', - parent: TimeEntryActivity.find(:last), + parent: TimeEntryActivity.last, project: Project.find(1), active: true ) @@ -181,14 +181,14 @@ describe ProjectEnumerationsController, type: :controller do session[:user_id] = 2 # manager project_activity = TimeEntryActivity.new( name: 'Project Specific', - parent: TimeEntryActivity.find(:first), + parent: TimeEntryActivity.first, project: Project.find(1), active: true ) assert project_activity.save project_activity_two = TimeEntryActivity.new( name: 'Project Specific Two', - parent: TimeEntryActivity.find(:last), + parent: TimeEntryActivity.last, project: Project.find(1), active: true ) diff --git a/spec/legacy/functional/projects_controller_spec.rb b/spec/legacy/functional/projects_controller_spec.rb index 41d279d4c0..102abebbe4 100644 --- a/spec/legacy/functional/projects_controller_spec.rb +++ b/spec/legacy/functional/projects_controller_spec.rb @@ -64,7 +64,7 @@ describe ProjectsController, type: :controller do assert_response :success assert_template 'common/feed' assert_select 'feed>title', text: 'OpenProject: Latest projects' - assert_select 'feed>entry', count: Project.count(conditions: Project.visible_by(User.current)) + assert_select 'feed>entry', count: Project.where(Project.visible_by(User.current)).count end context '#index' do diff --git a/spec/legacy/functional/repositories_controller_spec.rb b/spec/legacy/functional/repositories_controller_spec.rb index 6d4a99be7a..b6a6cee2a6 100644 --- a/spec/legacy/functional/repositories_controller_spec.rb +++ b/spec/legacy/functional/repositories_controller_spec.rb @@ -114,7 +114,7 @@ describe RepositoriesController, type: :controller do revision: 100, comments: 'Committed by foo.' ) - assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do + assert_no_difference 'Changeset.where(user_id: 3).count' do post :committers, project_id: 1, committers: { '0' => ['foo', '2'], '1' => ['dlopper', '3'] } assert_redirected_to '/projects/ecookbook/repository/committers' assert_equal User.find(2), c.reload.user diff --git a/spec/legacy/functional/roles_controller_spec.rb b/spec/legacy/functional/roles_controller_spec.rb index c09dc76de3..13cc3a9235 100644 --- a/spec/legacy/functional/roles_controller_spec.rb +++ b/spec/legacy/functional/roles_controller_spec.rb @@ -45,7 +45,7 @@ describe RolesController, type: :controller do assert_template 'index' assert_not_nil assigns(:roles) - assert_equal Role.find(:all, order: 'builtin, position'), assigns(:roles) + assert_equal Role.order('builtin, position').to_a, assigns(:roles) assert_tag tag: 'a', attributes: { href: edit_role_path(1) }, content: 'Manager' @@ -131,7 +131,7 @@ describe RolesController, type: :controller do assert_template 'report' assert_not_nil assigns(:roles) - assert_equal Role.find(:all, order: 'builtin, position'), assigns(:roles) + assert_equal Role.order('builtin, position'), assigns(:roles) assert_tag tag: 'input', attributes: { type: 'checkbox', name: 'permissions[3][]', diff --git a/spec/legacy/functional/users_controller_spec.rb b/spec/legacy/functional/users_controller_spec.rb index 067d31e8a7..5ac0aca13a 100644 --- a/spec/legacy/functional/users_controller_spec.rb +++ b/spec/legacy/functional/users_controller_spec.rb @@ -166,7 +166,7 @@ describe UsersController, type: :controller do end end - user = User.first(order: 'id DESC') + user = User.order('id DESC').first assert_redirected_to edit_user_path(user) assert_equal 'John', user.firstname diff --git a/spec/legacy/functional/welcome_controller_spec.rb b/spec/legacy/functional/welcome_controller_spec.rb index b0a24840c8..b1f832673e 100644 --- a/spec/legacy/functional/welcome_controller_spec.rb +++ b/spec/legacy/functional/welcome_controller_spec.rb @@ -45,7 +45,7 @@ describe WelcomeController, type: :controller do assert_template 'index' assert_not_nil assigns(:news) assert_not_nil assigns(:projects) - assert !assigns(:projects).include?(Project.find(:first, conditions: { is_public: false })) + assert !assigns(:projects).include?(Project.where(is_public: false).first) end it 'should browser language' do diff --git a/spec/legacy/functional/workflows_controller_spec.rb b/spec/legacy/functional/workflows_controller_spec.rb index 4837a9ac2a..1c662d3241 100644 --- a/spec/legacy/functional/workflows_controller_spec.rb +++ b/spec/legacy/functional/workflows_controller_spec.rb @@ -44,7 +44,7 @@ describe WorkflowsController, type: :controller do assert_response :success assert_template 'index' - count = Workflow.count(:all, conditions: 'role_id = 1 AND type_id = 2') + count = Workflow.where('role_id = 1 AND type_id = 2').count assert_tag tag: 'a', content: count.to_s, attributes: { href: '/workflows/edit?role_id=1&type_id=2' } end @@ -109,9 +109,9 @@ describe WorkflowsController, type: :controller do } assert_redirected_to '/workflows/edit?role_id=2&type_id=1' - assert_equal 3, Workflow.count(conditions: { type_id: 1, role_id: 2 }) - assert_not_nil Workflow.find(:first, conditions: { role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 2 }) - assert_nil Workflow.find(:first, conditions: { role_id: 2, type_id: 1, old_status_id: 5, new_status_id: 4 }) + assert_equal 3, Workflow.where(type_id: 1, role_id: 2).count + assert_not_nil Workflow.where(role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 2).first + assert_nil Workflow.where(role_id: 2, type_id: 1, old_status_id: 5, new_status_id: 4).first end it 'should post edit with additional transitions' do @@ -122,27 +122,27 @@ describe WorkflowsController, type: :controller do } assert_redirected_to '/workflows/edit?role_id=2&type_id=1' - assert_equal 4, Workflow.count(conditions: { type_id: 1, role_id: 2 }) + assert_equal 4, Workflow.where(type_id: 1, role_id: 2).count - w = Workflow.find(:first, conditions: { role_id: 2, type_id: 1, old_status_id: 4, new_status_id: 5 }) + w = Workflow.where(role_id: 2, type_id: 1, old_status_id: 4, new_status_id: 5).first assert !w.author assert !w.assignee - w = Workflow.find(:first, conditions: { role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 1 }) + w = Workflow.where(role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 1).first assert w.author assert !w.assignee - w = Workflow.find(:first, conditions: { role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 2 }) + w = Workflow.where(role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 2).first assert !w.author assert w.assignee - w = Workflow.find(:first, conditions: { role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 4 }) + w = Workflow.where(role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 4).first assert w.author assert w.assignee end it 'should clear workflow' do - assert Workflow.count(conditions: { type_id: 1, role_id: 2 }) > 0 + assert Workflow.where(type_id: 1, role_id: 2).count > 0 post :edit, role_id: 2, type_id: 1 - assert_equal 0, Workflow.count(conditions: { type_id: 1, role_id: 2 }) + assert_equal 0, Workflow.where(type_id: 1, role_id: 2).count end it 'should get copy' do @@ -187,7 +187,8 @@ describe WorkflowsController, type: :controller do # Returns an array of status transitions that can be compared def status_transitions(conditions) - Workflow.find(:all, conditions: conditions, - order: 'type_id, role_id, old_status_id, new_status_id').map { |w| [w.old_status, w.new_status_id] } + Workflow.where(conditions) + .order('type_id, role_id, old_status_id, new_status_id') + .map { |w| [w.old_status, w.new_status_id] } end end diff --git a/spec/legacy/support/legacy_assertions.rb b/spec/legacy/support/legacy_assertions.rb index 08984c2fc3..0979c5ce41 100644 --- a/spec/legacy/support/legacy_assertions.rb +++ b/spec/legacy/support/legacy_assertions.rb @@ -131,7 +131,7 @@ module LegacyAssertionsAndHelpers end def change_user_password(login, new_password) - user = User.first(conditions: { login: login }) + user = User.find_by_login(login) user.password = new_password user.password_confirmation = new_password user.save! diff --git a/spec/legacy/unit/board_spec.rb b/spec/legacy/unit/board_spec.rb index 6436d41c48..554b4a5b21 100644 --- a/spec/legacy/unit/board_spec.rb +++ b/spec/legacy/unit/board_spec.rb @@ -59,6 +59,6 @@ describe Board, type: :model do end end end - assert_equal 0, Message.count(conditions: { board_id: 1 }) + assert_equal 0, Message.where(board_id: 1).count end end diff --git a/spec/legacy/unit/changeset_spec.rb b/spec/legacy/unit/changeset_spec.rb index 044fd0b715..3d99225698 100644 --- a/spec/legacy/unit/changeset_spec.rb +++ b/spec/legacy/unit/changeset_spec.rb @@ -36,7 +36,7 @@ describe Changeset, type: :model do WorkPackage.all.each(&:recreate_initial_journal!) ActionMailer::Base.deliveries.clear - Setting.commit_fix_status_id = Status.find(:first, conditions: ['is_closed = ?', true]).id + Setting.commit_fix_status_id = Status.where(['is_closed = ?', true]).first.id Setting.commit_fix_done_ratio = '90' Setting.commit_ref_keywords = '*' Setting.commit_fix_keywords = 'fixes , closes' @@ -107,7 +107,7 @@ describe Changeset, type: :model do end assert_equal [1], c.work_package_ids.sort - time = TimeEntry.first(order: 'id desc') + time = TimeEntry.order('id DESC').first assert_equal 1, time.work_package_id assert_equal 1, time.project_id assert_equal 2, time.user_id @@ -119,7 +119,7 @@ describe Changeset, type: :model do end it 'should ref keywords closing with timelog' do - Setting.commit_fix_status_id = Status.find(:first, conditions: ['is_closed = ?', true]).id + Setting.commit_fix_status_id = Status.where(['is_closed = ?', true]).first.id Setting.commit_ref_keywords = '*' Setting.commit_fix_keywords = 'fixes , closes' Setting.commit_logtime_enabled = '1' @@ -136,7 +136,7 @@ describe Changeset, type: :model do assert WorkPackage.find(1).closed? assert WorkPackage.find(2).closed? - times = TimeEntry.all(order: 'id desc', limit: 2) + times = TimeEntry.order('id desc').limit(2) assert_equal [1, 2], times.map(&:work_package_id).sort end diff --git a/spec/legacy/unit/enumeration_spec.rb b/spec/legacy/unit/enumeration_spec.rb index ab88427787..83654fa29a 100644 --- a/spec/legacy/unit/enumeration_spec.rb +++ b/spec/legacy/unit/enumeration_spec.rb @@ -86,7 +86,7 @@ describe Enumeration, type: :model do it 'should destroy with reassign' do new_priority = FactoryGirl.create :priority Enumeration.find(@low_priority).destroy(new_priority) - assert_nil WorkPackage.find(:first, conditions: { priority_id: @low_priority.id }) + assert_nil WorkPackage.find_by(priority_id: @low_priority.id) assert_equal @issues.size, new_priority.objects_count end diff --git a/spec/legacy/unit/journal_spec.rb b/spec/legacy/unit/journal_spec.rb index dcbcf01f59..25efc49624 100644 --- a/spec/legacy/unit/journal_spec.rb +++ b/spec/legacy/unit/journal_spec.rb @@ -39,12 +39,12 @@ describe Journal, type: :model do it 'should create should send email notification' do ActionMailer::Base.deliveries.clear - issue = WorkPackage.find(:first) + issue = WorkPackage.first if issue.journals.empty? issue.add_journal(User.current, 'This journal represents the creationa of journal version 1') issue.save end - user = User.find(:first) + user = User.first assert_equal 0, ActionMailer::Base.deliveries.size issue.reload issue.update_attribute(:subject, 'New subject to trigger automatic journal entry') @@ -53,8 +53,8 @@ describe Journal, type: :model do it 'should create should not send email notification if told not to' do ActionMailer::Base.deliveries.clear - issue = WorkPackage.find(:first) - user = User.find(:first) + issue = WorkPackage.first + user = User.first journal = issue.add_journal(user, 'A note') JournalObserver.instance.send_notification = false diff --git a/spec/legacy/unit/lib/redmine/ciphering_spec.rb b/spec/legacy/unit/lib/redmine/ciphering_spec.rb index 6f10bde2f0..7275b57dad 100644 --- a/spec/legacy/unit/lib/redmine/ciphering_spec.rb +++ b/spec/legacy/unit/lib/redmine/ciphering_spec.rb @@ -59,7 +59,7 @@ describe Redmine::Ciphering do end OpenProject::Configuration.with 'database_cipher_key' => 'secret' do - r = Repository.first(order: 'id DESC') + r = Repository.order('id DESC').first assert_equal 'clear', r.password end end @@ -73,7 +73,7 @@ describe Redmine::Ciphering do OpenProject::Configuration.with 'database_cipher_key' => 'secret' do assert Repository.encrypt_all(:password) - r = Repository.first(order: 'id DESC') + r = Repository.order('id DESC').first assert_equal 'bar', r.password assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/) end @@ -86,7 +86,7 @@ describe Redmine::Ciphering do Repository::Subversion.generate!(password: 'bar') assert Repository.decrypt_all(:password) - r = Repository.first(order: 'id DESC') + r = Repository.order('id DESC').first assert_equal 'bar', r.password assert_equal 'bar', r.read_attribute(:password) end diff --git a/spec/legacy/unit/mail_handler_spec.rb b/spec/legacy/unit/mail_handler_spec.rb index 695c44f1b6..92b0d4b79e 100644 --- a/spec/legacy/unit/mail_handler_spec.rb +++ b/spec/legacy/unit/mail_handler_spec.rb @@ -557,7 +557,7 @@ describe MailHandler, type: :model do ) end - user = User.first(order: 'id DESC') + user = User.order('id DESC').first assert_equal 'foo@example.org', user.mail str1 = "\xc3\x84\xc3\xa4" str2 = "\xc3\x96\xc3\xb6" diff --git a/spec/legacy/unit/project_spec.rb b/spec/legacy/unit/project_spec.rb index dcb28a84ae..f4ac99999b 100644 --- a/spec/legacy/unit/project_spec.rb +++ b/spec/legacy/unit/project_spec.rb @@ -153,7 +153,7 @@ describe Project, type: :model do # Assign an issue of a project to a version of a child project WorkPackage.find(4).update_attribute :fixed_version_id, 4 - assert_no_difference "Project.count(:all, :conditions => 'status = #{Project::STATUS_ARCHIVED}')" do + assert_no_difference "Project.where('status = #{Project::STATUS_ARCHIVED}').count" do assert_equal false, @ecookbook.archive end @ecookbook.reload @@ -183,7 +183,7 @@ describe Project, type: :model do # 2 active members assert_equal 2, @ecookbook.members.size # and 1 is locked - assert_equal 3, Member.find(:all, conditions: ['project_id = ?', @ecookbook.id]).size + assert_equal 3, Member.where(['project_id = ?', @ecookbook.id]).size # some boards assert @ecookbook.boards.any? @@ -191,9 +191,9 @@ describe Project, type: :model do # make sure that the project non longer exists assert_raise(ActiveRecord::RecordNotFound) do Project.find(@ecookbook.id) end # make sure related data was removed - assert_nil Member.first(conditions: { project_id: @ecookbook.id }) - assert_nil Board.first(conditions: { project_id: @ecookbook.id }) - assert_nil WorkPackage.first(conditions: { project_id: @ecookbook.id }) + assert_equal 0, Member.where(project_id: @ecookbook.id).count + assert_equal 0, Board.where(project_id: @ecookbook.id).count + assert_equal 0, WorkPackage.where(project_id: @ecookbook.id).count end it 'should destroying root projects should clear data' do @@ -213,7 +213,7 @@ describe Project, type: :model do assert_equal 0, Board.count assert_equal 0, Message.count assert_equal 0, News.count - assert_equal 0, Query.count(conditions: 'project_id IS NOT NULL') + assert_equal 0, Query.where('project_id IS NOT NULL').count assert_equal 0, Repository.count assert_equal 0, Changeset.count assert_equal 0, Change.count @@ -226,7 +226,7 @@ describe Project, type: :model do assert_equal 0, WikiContent.count assert_equal 0, Project.connection.select_all('SELECT * FROM projects_types').to_a.size assert_equal 0, Project.connection.select_all('SELECT * FROM custom_fields_projects').to_a.size - assert_equal 0, CustomValue.count(conditions: { customized_type: ['Project', 'Issue', 'TimeEntry', 'Version'] }) + assert_equal 0, CustomValue.where(customized_type: ['Project', 'Issue', 'TimeEntry', 'Version']).count end it 'should move an orphan project to a root project' do @@ -663,7 +663,7 @@ describe Project, type: :model do it 'should activities should use the system activities' do project = Project.find(1) - assert_equal project.activities, TimeEntryActivity.find(:all, conditions: { active: true }) + assert_equal project.activities, TimeEntryActivity.where(active: true).to_a end it 'should activities should use the project specific activities' do @@ -676,7 +676,7 @@ describe Project, type: :model do it 'should activities should not include the inactive project specific activities' do project = Project.find(1) - overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: TimeEntryActivity.find(:first), active: false) + overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: TimeEntryActivity.first, active: false) assert overridden_activity.save! assert !project.activities.include?(overridden_activity), 'Inactive Project specific Activity found' @@ -691,7 +691,7 @@ describe Project, type: :model do end it 'should activities should handle nils' do - overridden_activity = TimeEntryActivity.new(name: 'Project', project: Project.find(1), parent: TimeEntryActivity.find(:first)) + overridden_activity = TimeEntryActivity.new(name: 'Project', project: Project.find(1), parent: TimeEntryActivity.first) TimeEntryActivity.delete_all # No activities @@ -706,7 +706,7 @@ describe Project, type: :model do it 'should activities should override system activities with project activities' do project = Project.find(1) - parent_activity = TimeEntryActivity.find(:first) + parent_activity = TimeEntryActivity.first overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: parent_activity) assert overridden_activity.save! @@ -716,7 +716,7 @@ describe Project, type: :model do it 'should activities should include inactive activities if specified' do project = Project.find(1) - overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: TimeEntryActivity.find(:first), active: false) + overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: TimeEntryActivity.first, active: false) assert overridden_activity.save! assert project.activities(true).include?(overridden_activity), 'Inactive Project specific Activity not found' @@ -776,7 +776,7 @@ describe Project, type: :model do assert_equal @project, issue.project end - copied_issue = @project.work_packages.first(conditions: { subject: 'copy issue status' }) + copied_issue = @project.work_packages.find_by(subject: 'copy issue status') assert copied_issue assert copied_issue.status assert_equal 'Closed', copied_issue.status.name diff --git a/spec/legacy/unit/query_spec.rb b/spec/legacy/unit/query_spec.rb index 6fc2c80c62..bcc83f9159 100644 --- a/spec/legacy/unit/query_spec.rb +++ b/spec/legacy/unit/query_spec.rb @@ -55,9 +55,8 @@ describe Query, type: :model do end def find_issues_with_query(query) - WorkPackage.find :all, - include: [:assigned_to, :status, :type, :project, :priority], - conditions: query.statement + WorkPackage.includes(:assigned_to, :status, :type, :project, :priority) + .where(query.statement) end def assert_find_issues_with_query_is_successful(query) @@ -222,7 +221,7 @@ describe Query, type: :model do query = Query.new(name: '_', filters: [Queries::WorkPackages::Filter.new(:assigned_to_id, operator: '=', values: ['me'])]) result = query.results.work_packages - assert_equal WorkPackage.visible.all(conditions: { assigned_to_id: ([2] + user.reload.group_ids) }).sort_by(&:id), result.sort_by(&:id) + assert_equal WorkPackage.visible.where(assigned_to_id: ([2] + user.reload.group_ids)).sort_by(&:id), result.sort_by(&:id) assert result.include?(i1) assert result.include?(i2) @@ -315,10 +314,9 @@ describe Query, type: :model do c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' } assert c assert c.sortable - issues = WorkPackage.find :all, - include: [:assigned_to, :status, :type, :project, :priority], - conditions: q.statement, - order: "#{c.sortable} ASC" + issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority) + .where(q.statement) + .order("#{c.sortable} ASC") values = issues.map { |i| i.custom_value_for(c.custom_field).to_s } assert !values.empty? assert_equal values.sort, values @@ -329,10 +327,9 @@ describe Query, type: :model do c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' } assert c assert c.sortable - issues = WorkPackage.find :all, - include: [:assigned_to, :status, :type, :project, :priority], - conditions: q.statement, - order: "#{c.sortable} DESC" + issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority) + .where(q.statement) + .order("#{c.sortable} DESC") values = issues.map { |i| i.custom_value_for(c.custom_field).to_s } assert !values.empty? assert_equal values.sort.reverse, values @@ -343,10 +340,9 @@ describe Query, type: :model do c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'float' } assert c assert c.sortable - issues = WorkPackage.find :all, - include: [:assigned_to, :status, :type, :project, :priority], - conditions: q.statement, - order: "#{c.sortable} ASC" + issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority) + .where(q.statement) + .order("#{c.sortable} ASC") values = issues.map { |i| begin; Kernel.Float(i.custom_value_for(c.custom_field).to_s); rescue; nil; end }.compact assert !values.empty? assert_equal values.sort, values diff --git a/spec/legacy/unit/repository_git_spec.rb b/spec/legacy/unit/repository_git_spec.rb index 9ef3d4cde8..89911c55a0 100644 --- a/spec/legacy/unit/repository_git_spec.rb +++ b/spec/legacy/unit/repository_git_spec.rb @@ -88,12 +88,12 @@ describe Repository::Git, type: :model do it 'should fetch changesets incremental' do @repository.fetch_changesets # Remove the 3 latest changesets - @repository.changesets.find(:all, order: 'committed_on DESC', limit: 8).each(&:destroy) + @repository.changesets.order('committed_on DESC').limit(8).each(&:destroy) @repository.reload cs1 = @repository.changesets assert_equal 13, cs1.count - rev_a_commit = @repository.changesets.find(:first, order: 'committed_on DESC') + rev_a_commit = @repository.changesets.order('committed_on DESC').first assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision # Mon Jul 5 22:34:26 2010 +0200 rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26) diff --git a/spec/legacy/unit/repository_spec.rb b/spec/legacy/unit/repository_spec.rb index a04d43b77c..1364067cab 100644 --- a/spec/legacy/unit/repository_spec.rb +++ b/spec/legacy/unit/repository_spec.rb @@ -79,7 +79,7 @@ describe Repository, type: :model do Setting.notified_events = ['work_package_added', 'work_package_updated'] # choosing a status to apply to fix issues - Setting.commit_fix_status_id = Status.find(:first, conditions: ['is_closed = ?', true]).id + Setting.commit_fix_status_id = Status.where(['is_closed = ?', true]).first.id Setting.commit_fix_done_ratio = '90' Setting.commit_ref_keywords = 'refs , references, IssueID' Setting.commit_fix_keywords = 'fixes , closes' @@ -140,7 +140,7 @@ describe Repository, type: :model do end it 'should manual user mapping' do - assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do + assert_no_difference "Changeset.where('user_id <> 2').count" do c = Changeset.create!(repository: @repository, committer: 'foo', committed_on: Time.now, revision: 100, comments: 'Committed by foo.') assert_nil c.user @repository.committer_ids = { 'foo' => '2' } diff --git a/spec/legacy/unit/repository_subversion_spec.rb b/spec/legacy/unit/repository_subversion_spec.rb index f14bfd6c04..b61a182bcb 100644 --- a/spec/legacy/unit/repository_subversion_spec.rb +++ b/spec/legacy/unit/repository_subversion_spec.rb @@ -52,7 +52,7 @@ describe Repository::Subversion, type: :model do it 'should fetch changesets incremental' do @repository.fetch_changesets # Remove changesets with revision > 5 - @repository.changesets.find(:all).each do |c| c.destroy if c.revision.to_i > 5 end + @repository.changesets.all.each do |c| c.destroy if c.revision.to_i > 5 end @repository.reload assert_equal 5, @repository.changesets.count diff --git a/spec/legacy/unit/search_spec.rb b/spec/legacy/unit/search_spec.rb index 1e591399bf..86e9368e8b 100644 --- a/spec/legacy/unit/search_spec.rb +++ b/spec/legacy/unit/search_spec.rb @@ -134,7 +134,7 @@ describe 'Search' do # FIXME: naming (RSpec-port) i.add_journal User.current, 'Some notes with Redmine links: #2, r2.' i.save! - assert_equal 2, i.journals.count(:all, conditions: "notes LIKE '%notes%'") + assert_equal 2, i.journals.where("notes LIKE '%notes%'").count r = WorkPackage.search('%notes%').first assert_equal 1, r.size diff --git a/spec/legacy/unit/status_spec.rb b/spec/legacy/unit/status_spec.rb index 3aaea8fa6c..1e6a0d7519 100644 --- a/spec/legacy/unit/status_spec.rb +++ b/spec/legacy/unit/status_spec.rb @@ -47,8 +47,8 @@ describe Status, type: :model do assert_difference 'Status.count', -1 do assert status.destroy end - assert_nil Workflow.first(conditions: { old_status_id: status.id }) - assert_nil Workflow.first(conditions: { new_status_id: status.id }) + assert_equal 0, Workflow.where(old_status_id: status.id).count + assert_equal 0, Workflow.where(new_status_id: status.id).count end it 'should destroy status in use' do @@ -95,7 +95,7 @@ describe Status, type: :model do it 'should change nothing' do Status.update_work_package_done_ratios - assert_equal 0, WorkPackage.count(conditions: { done_ratio: 50 }) + assert_equal 0, WorkPackage.where(done_ratio: 50).count end end diff --git a/spec/legacy/unit/user_spec.rb b/spec/legacy/unit/user_spec.rb index 3ee8f37c25..0f87ad4dab 100644 --- a/spec/legacy/unit/user_spec.rb +++ b/spec/legacy/unit/user_spec.rb @@ -42,7 +42,7 @@ describe User, type: :model do specify 'object_daddy creation' do User.generate_with_protected!(firstname: 'Testing connection') User.generate_with_protected!(firstname: 'Testing connection') - assert_equal 2, User.count(:all, conditions: { firstname: 'Testing connection' }) + assert_equal 2, User.where(firstname: 'Testing connection').count end it 'should truth' do diff --git a/spec/legacy/unit/version_spec.rb b/spec/legacy/unit/version_spec.rb index 4b88c1d14e..2d3b18b53b 100644 --- a/spec/legacy/unit/version_spec.rb +++ b/spec/legacy/unit/version_spec.rb @@ -97,7 +97,7 @@ describe Version, type: :model do it 'should progress should be 100 with closed assigned issues' do project = Project.find(1) - status = Status.find(:first, conditions: { is_closed: true }) + status = Status.where(is_closed: true).first (v = Version.new.tap do |v| v.force_attributes = { project: project, name: 'Progress' } end).save! @@ -128,7 +128,7 @@ describe Version, type: :model do end).save! add_work_package(v) add_work_package(v, done_ratio: 20) - add_work_package(v, status: Status.find(:first, conditions: { is_closed: true })) + add_work_package(v, status: Status.where(is_closed: true).first) assert_progress_equal (0.0 + 20.0 + 100.0) / 3, v.completed_percent assert_progress_equal (100.0) / 3, v.closed_percent end @@ -141,7 +141,7 @@ describe Version, type: :model do add_work_package(v, estimated_hours: 10) add_work_package(v, estimated_hours: 20, done_ratio: 30) add_work_package(v, estimated_hours: 40, done_ratio: 10) - add_work_package(v, estimated_hours: 25, status: Status.find(:first, conditions: { is_closed: true })) + add_work_package(v, estimated_hours: 25, status: Status.where(is_closed: true).first) assert_progress_equal (10.0 * 0 + 20.0 * 0.3 + 40 * 0.1 + 25.0 * 1) / 95.0 * 100, v.completed_percent assert_progress_equal 25.0 / 95.0 * 100, v.closed_percent end @@ -152,7 +152,7 @@ describe Version, type: :model do v.force_attributes = { project: project, name: 'Progress' } end).save! add_work_package(v, done_ratio: 20) - add_work_package(v, status: Status.find(:first, conditions: { is_closed: true })) + add_work_package(v, status: Status.where(is_closed: true).first) add_work_package(v, estimated_hours: 10, done_ratio: 30) add_work_package(v, estimated_hours: 40, done_ratio: 10) assert_progress_equal (25.0 * 0.2 + 25.0 * 1 + 10.0 * 0.3 + 40.0 * 0.1) / 100.0 * 100, v.completed_percent diff --git a/spec/legacy/unit/wiki_page_spec.rb b/spec/legacy/unit/wiki_page_spec.rb index 7717beb25b..a57e11b7ed 100644 --- a/spec/legacy/unit/wiki_page_spec.rb +++ b/spec/legacy/unit/wiki_page_spec.rb @@ -118,8 +118,8 @@ describe WikiPage, type: :model do # make sure that page content and its history are deleted assert WikiContent.where(page_id: 1).empty? content_ids.each do |wiki_content_id| - assert Journal.find :all, conditions: { journable_type: WikiContent, - journable_id: wiki_content_id } + assert Journal.where(journable_type: WikiContent, + journable_id: wiki_content_id) end end diff --git a/spec/legacy/unit/wiki_redirect_spec.rb b/spec/legacy/unit/wiki_redirect_spec.rb index 15f07cf658..baa54184b5 100644 --- a/spec/legacy/unit/wiki_redirect_spec.rb +++ b/spec/legacy/unit/wiki_redirect_spec.rb @@ -80,6 +80,6 @@ describe WikiRedirect, type: :model do assert WikiRedirect.create(wiki: @wiki, title: 'An_old_page', redirects_to: 'Original_title') @original.destroy - assert !@wiki.redirects.find(:first) + assert !@wiki.redirects.first end end diff --git a/spec/support/shared/permissions.rb b/spec/support/shared/permissions.rb index 2a1aa84605..48be037312 100644 --- a/spec/support/shared/permissions.rb +++ b/spec/support/shared/permissions.rb @@ -90,7 +90,7 @@ shared_examples_for 'a controller action with require_login' do end shared_examples_for 'a controller action with require_admin' do - let(:valid_user) { User.first(conditions: { admin: true }) || FactoryGirl.create(:admin) } + let(:valid_user) { User.where(admin: true).first || FactoryGirl.create(:admin) } let(:invalid_user) { FactoryGirl.create(:user) } extend PermissionSpecHelpers