Migrate AR finder/query methods in specs

Signed-off-by: Alex Coles <alex@alexbcoles.com>
pull/3194/head
Alex Coles 9 years ago
parent a6c54cb25f
commit 424889897a
  1. 6
      spec/controllers/account_controller_spec.rb
  2. 6
      spec/controllers/work_packages/moves_controller_spec.rb
  3. 2
      spec/factories/enumerations_factory.rb
  4. 2
      spec/legacy/functional/enumerations_controller_spec.rb
  5. 8
      spec/legacy/functional/messages_controller_spec.rb
  6. 8
      spec/legacy/functional/project_enumerations_controller_spec.rb
  7. 2
      spec/legacy/functional/projects_controller_spec.rb
  8. 2
      spec/legacy/functional/repositories_controller_spec.rb
  9. 4
      spec/legacy/functional/roles_controller_spec.rb
  10. 2
      spec/legacy/functional/users_controller_spec.rb
  11. 2
      spec/legacy/functional/welcome_controller_spec.rb
  12. 27
      spec/legacy/functional/workflows_controller_spec.rb
  13. 2
      spec/legacy/support/legacy_assertions.rb
  14. 2
      spec/legacy/unit/board_spec.rb
  15. 8
      spec/legacy/unit/changeset_spec.rb
  16. 2
      spec/legacy/unit/enumeration_spec.rb
  17. 8
      spec/legacy/unit/journal_spec.rb
  18. 6
      spec/legacy/unit/lib/redmine/ciphering_spec.rb
  19. 2
      spec/legacy/unit/mail_handler_spec.rb
  20. 26
      spec/legacy/unit/project_spec.rb
  21. 28
      spec/legacy/unit/query_spec.rb
  22. 4
      spec/legacy/unit/repository_git_spec.rb
  23. 4
      spec/legacy/unit/repository_spec.rb
  24. 2
      spec/legacy/unit/repository_subversion_spec.rb
  25. 2
      spec/legacy/unit/search_spec.rb
  26. 6
      spec/legacy/unit/status_spec.rb
  27. 2
      spec/legacy/unit/user_spec.rb
  28. 8
      spec/legacy/unit/version_spec.rb
  29. 4
      spec/legacy/unit/wiki_page_spec.rb
  30. 2
      spec/legacy/unit/wiki_redirect_spec.rb
  31. 2
      spec/support/shared/permissions.rb

@ -310,11 +310,11 @@ describe AccountController, type: :controller do
is_expected.to respond_with :redirect is_expected.to respond_with :redirect
expect(assigns[:user]).not_to be_nil expect(assigns[:user]).not_to be_nil
is_expected.to redirect_to(my_first_login_path) 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 end
it 'set the user status to active' do 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).not_to be_nil
expect(user.status).to eq(User::STATUSES[:active]) expect(user.status).to eq(User::STATUSES[:active])
end end
@ -355,7 +355,7 @@ describe AccountController, type: :controller do
it "doesn't activate the user but sends out a token instead" do it "doesn't activate the user but sends out a token instead" do
expect(User.find_by_login('register')).not_to be_active 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.action).to eq('register')
expect(token.user.mail).to eq('register@example.com') expect(token.user.mail).to eq('register@example.com')
expect(token).not_to be_expired expect(token).not_to be_expired

@ -271,7 +271,7 @@ describe WorkPackages::MovesController, type: :controller do
end end
it 'redirects to the work package copy' do 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)) is_expected.to redirect_to(work_package_path(copy))
end end
end end
@ -284,7 +284,7 @@ describe WorkPackages::MovesController, type: :controller do
new_project_id: target_project.id new_project_id: target_project.id
end 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 it 'did not change the type' do
expect(subject.type_id).to eq(work_package.type_id) expect(subject.type_id).to eq(work_package.type_id)
@ -321,7 +321,7 @@ describe WorkPackages::MovesController, type: :controller do
due_date: due_date due_date: due_date
end 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 it 'copied two work packages' do
expect(subject.count).to eq(2) expect(subject.count).to eq(2)

@ -29,7 +29,7 @@
FactoryGirl.define do FactoryGirl.define do
factory :default_enumeration, class: Enumeration do factory :default_enumeration, class: Enumeration do
initialize_with 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 end
active true active true

@ -56,7 +56,7 @@ describe EnumerationsController, type: :controller do
end end
it 'should destroy enumeration in use with reassignment' do 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 post :destroy, id: 4, reassign_to_id: 6
assert_redirected_to enumerations_path assert_redirected_to enumerations_path
assert_nil Enumeration.find_by(id: 4) assert_nil Enumeration.find_by(id: 4)

@ -56,13 +56,13 @@ describe MessagesController, type: :controller do
message.children << m message.children << m
end end
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_response :success
assert_template 'show' assert_template 'show'
replies = assigns(:replies) replies = assigns(:replies)
assert_not_nil replies assert_not_nil replies
assert !replies.include?(message.children.first(order: 'id')) assert !replies.include?(message.children.order('id').first)
assert replies.include?(message.children.last(order: 'id')) assert replies.include?(message.children.order('id').last)
end end
it 'should show with reply permission' do it 'should show with reply permission' do
@ -137,7 +137,7 @@ describe MessagesController, type: :controller do
it 'should reply' do it 'should reply' do
session[:user_id] = 2 session[:user_id] = 2
post :reply, board_id: 1, id: 1, reply: { content: 'This is a test reply', subject: 'Test reply' } 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_redirected_to topic_path(1, r: reply)
assert Message.find_by(subject: 'Test reply') assert Message.find_by(subject: 'Test reply')
end end

@ -92,14 +92,14 @@ describe ProjectEnumerationsController, type: :controller do
project_activity = TimeEntryActivity.new( project_activity = TimeEntryActivity.new(
name: 'Project Specific', name: 'Project Specific',
parent: TimeEntryActivity.find(:first), parent: TimeEntryActivity.first,
project: Project.find(1), project: Project.find(1),
active: true active: true
) )
assert project_activity.save assert project_activity.save
project_activity_two = TimeEntryActivity.new( project_activity_two = TimeEntryActivity.new(
name: 'Project Specific Two', name: 'Project Specific Two',
parent: TimeEntryActivity.find(:last), parent: TimeEntryActivity.last,
project: Project.find(1), project: Project.find(1),
active: true active: true
) )
@ -181,14 +181,14 @@ describe ProjectEnumerationsController, type: :controller do
session[:user_id] = 2 # manager session[:user_id] = 2 # manager
project_activity = TimeEntryActivity.new( project_activity = TimeEntryActivity.new(
name: 'Project Specific', name: 'Project Specific',
parent: TimeEntryActivity.find(:first), parent: TimeEntryActivity.first,
project: Project.find(1), project: Project.find(1),
active: true active: true
) )
assert project_activity.save assert project_activity.save
project_activity_two = TimeEntryActivity.new( project_activity_two = TimeEntryActivity.new(
name: 'Project Specific Two', name: 'Project Specific Two',
parent: TimeEntryActivity.find(:last), parent: TimeEntryActivity.last,
project: Project.find(1), project: Project.find(1),
active: true active: true
) )

@ -64,7 +64,7 @@ describe ProjectsController, type: :controller do
assert_response :success assert_response :success
assert_template 'common/feed' assert_template 'common/feed'
assert_select 'feed>title', text: 'OpenProject: Latest projects' 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 end
context '#index' do context '#index' do

@ -114,7 +114,7 @@ describe RepositoriesController, type: :controller do
revision: 100, revision: 100,
comments: 'Committed by foo.' 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'] } post :committers, project_id: 1, committers: { '0' => ['foo', '2'], '1' => ['dlopper', '3'] }
assert_redirected_to '/projects/ecookbook/repository/committers' assert_redirected_to '/projects/ecookbook/repository/committers'
assert_equal User.find(2), c.reload.user assert_equal User.find(2), c.reload.user

@ -45,7 +45,7 @@ describe RolesController, type: :controller do
assert_template 'index' assert_template 'index'
assert_not_nil assigns(:roles) 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) }, assert_tag tag: 'a', attributes: { href: edit_role_path(1) },
content: 'Manager' content: 'Manager'
@ -131,7 +131,7 @@ describe RolesController, type: :controller do
assert_template 'report' assert_template 'report'
assert_not_nil assigns(:roles) 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', assert_tag tag: 'input', attributes: { type: 'checkbox',
name: 'permissions[3][]', name: 'permissions[3][]',

@ -166,7 +166,7 @@ describe UsersController, type: :controller do
end end
end end
user = User.first(order: 'id DESC') user = User.order('id DESC').first
assert_redirected_to edit_user_path(user) assert_redirected_to edit_user_path(user)
assert_equal 'John', user.firstname assert_equal 'John', user.firstname

@ -45,7 +45,7 @@ describe WelcomeController, type: :controller do
assert_template 'index' assert_template 'index'
assert_not_nil assigns(:news) assert_not_nil assigns(:news)
assert_not_nil assigns(:projects) 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 end
it 'should browser language' do it 'should browser language' do

@ -44,7 +44,7 @@ describe WorkflowsController, type: :controller do
assert_response :success assert_response :success
assert_template 'index' 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, assert_tag tag: 'a', content: count.to_s,
attributes: { href: '/workflows/edit?role_id=1&amp;type_id=2' } attributes: { href: '/workflows/edit?role_id=1&amp;type_id=2' }
end end
@ -109,9 +109,9 @@ describe WorkflowsController, type: :controller do
} }
assert_redirected_to '/workflows/edit?role_id=2&type_id=1' assert_redirected_to '/workflows/edit?role_id=2&type_id=1'
assert_equal 3, Workflow.count(conditions: { type_id: 1, role_id: 2 }) assert_equal 3, Workflow.where(type_id: 1, role_id: 2).count
assert_not_nil Workflow.find(:first, conditions: { role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 2 }) assert_not_nil Workflow.where(role_id: 2, type_id: 1, old_status_id: 3, new_status_id: 2).first
assert_nil Workflow.find(:first, conditions: { role_id: 2, type_id: 1, old_status_id: 5, new_status_id: 4 }) assert_nil Workflow.where(role_id: 2, type_id: 1, old_status_id: 5, new_status_id: 4).first
end end
it 'should post edit with additional transitions' do 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_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.author
assert !w.assignee 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.author
assert !w.assignee 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.author
assert w.assignee 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.author
assert w.assignee assert w.assignee
end end
it 'should clear workflow' do 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 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 end
it 'should get copy' do it 'should get copy' do
@ -187,7 +187,8 @@ describe WorkflowsController, type: :controller do
# Returns an array of status transitions that can be compared # Returns an array of status transitions that can be compared
def status_transitions(conditions) def status_transitions(conditions)
Workflow.find(:all, conditions: conditions, Workflow.where(conditions)
order: 'type_id, role_id, old_status_id, new_status_id').map { |w| [w.old_status, w.new_status_id] } .order('type_id, role_id, old_status_id, new_status_id')
.map { |w| [w.old_status, w.new_status_id] }
end end
end end

@ -131,7 +131,7 @@ module LegacyAssertionsAndHelpers
end end
def change_user_password(login, new_password) 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 = new_password
user.password_confirmation = new_password user.password_confirmation = new_password
user.save! user.save!

@ -59,6 +59,6 @@ describe Board, type: :model do
end end
end end
end end
assert_equal 0, Message.count(conditions: { board_id: 1 }) assert_equal 0, Message.where(board_id: 1).count
end end
end end

@ -36,7 +36,7 @@ describe Changeset, type: :model do
WorkPackage.all.each(&:recreate_initial_journal!) WorkPackage.all.each(&:recreate_initial_journal!)
ActionMailer::Base.deliveries.clear 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_fix_done_ratio = '90'
Setting.commit_ref_keywords = '*' Setting.commit_ref_keywords = '*'
Setting.commit_fix_keywords = 'fixes , closes' Setting.commit_fix_keywords = 'fixes , closes'
@ -107,7 +107,7 @@ describe Changeset, type: :model do
end end
assert_equal [1], c.work_package_ids.sort 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.work_package_id
assert_equal 1, time.project_id assert_equal 1, time.project_id
assert_equal 2, time.user_id assert_equal 2, time.user_id
@ -119,7 +119,7 @@ describe Changeset, type: :model do
end end
it 'should ref keywords closing with timelog' do 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_ref_keywords = '*'
Setting.commit_fix_keywords = 'fixes , closes' Setting.commit_fix_keywords = 'fixes , closes'
Setting.commit_logtime_enabled = '1' Setting.commit_logtime_enabled = '1'
@ -136,7 +136,7 @@ describe Changeset, type: :model do
assert WorkPackage.find(1).closed? assert WorkPackage.find(1).closed?
assert WorkPackage.find(2).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 assert_equal [1, 2], times.map(&:work_package_id).sort
end end

@ -86,7 +86,7 @@ describe Enumeration, type: :model do
it 'should destroy with reassign' do it 'should destroy with reassign' do
new_priority = FactoryGirl.create :priority new_priority = FactoryGirl.create :priority
Enumeration.find(@low_priority).destroy(new_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 assert_equal @issues.size, new_priority.objects_count
end end

@ -39,12 +39,12 @@ describe Journal, type: :model do
it 'should create should send email notification' do it 'should create should send email notification' do
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
issue = WorkPackage.find(:first) issue = WorkPackage.first
if issue.journals.empty? if issue.journals.empty?
issue.add_journal(User.current, 'This journal represents the creationa of journal version 1') issue.add_journal(User.current, 'This journal represents the creationa of journal version 1')
issue.save issue.save
end end
user = User.find(:first) user = User.first
assert_equal 0, ActionMailer::Base.deliveries.size assert_equal 0, ActionMailer::Base.deliveries.size
issue.reload issue.reload
issue.update_attribute(:subject, 'New subject to trigger automatic journal entry') 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 it 'should create should not send email notification if told not to' do
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
issue = WorkPackage.find(:first) issue = WorkPackage.first
user = User.find(:first) user = User.first
journal = issue.add_journal(user, 'A note') journal = issue.add_journal(user, 'A note')
JournalObserver.instance.send_notification = false JournalObserver.instance.send_notification = false

@ -59,7 +59,7 @@ describe Redmine::Ciphering do
end end
OpenProject::Configuration.with 'database_cipher_key' => 'secret' do 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 assert_equal 'clear', r.password
end end
end end
@ -73,7 +73,7 @@ describe Redmine::Ciphering do
OpenProject::Configuration.with 'database_cipher_key' => 'secret' do OpenProject::Configuration.with 'database_cipher_key' => 'secret' do
assert Repository.encrypt_all(:password) assert Repository.encrypt_all(:password)
r = Repository.first(order: 'id DESC') r = Repository.order('id DESC').first
assert_equal 'bar', r.password assert_equal 'bar', r.password
assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/) assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/)
end end
@ -86,7 +86,7 @@ describe Redmine::Ciphering do
Repository::Subversion.generate!(password: 'bar') Repository::Subversion.generate!(password: 'bar')
assert Repository.decrypt_all(:password) 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.password
assert_equal 'bar', r.read_attribute(:password) assert_equal 'bar', r.read_attribute(:password)
end end

@ -557,7 +557,7 @@ describe MailHandler, type: :model do
) )
end end
user = User.first(order: 'id DESC') user = User.order('id DESC').first
assert_equal 'foo@example.org', user.mail assert_equal 'foo@example.org', user.mail
str1 = "\xc3\x84\xc3\xa4" str1 = "\xc3\x84\xc3\xa4"
str2 = "\xc3\x96\xc3\xb6" str2 = "\xc3\x96\xc3\xb6"

@ -153,7 +153,7 @@ describe Project, type: :model do
# Assign an issue of a project to a version of a child project # Assign an issue of a project to a version of a child project
WorkPackage.find(4).update_attribute :fixed_version_id, 4 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 assert_equal false, @ecookbook.archive
end end
@ecookbook.reload @ecookbook.reload
@ -183,7 +183,7 @@ describe Project, type: :model do
# 2 active members # 2 active members
assert_equal 2, @ecookbook.members.size assert_equal 2, @ecookbook.members.size
# and 1 is locked # 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 # some boards
assert @ecookbook.boards.any? assert @ecookbook.boards.any?
@ -191,9 +191,9 @@ describe Project, type: :model do
# make sure that the project non longer exists # make sure that the project non longer exists
assert_raise(ActiveRecord::RecordNotFound) do Project.find(@ecookbook.id) end assert_raise(ActiveRecord::RecordNotFound) do Project.find(@ecookbook.id) end
# make sure related data was removed # make sure related data was removed
assert_nil Member.first(conditions: { project_id: @ecookbook.id }) assert_equal 0, Member.where(project_id: @ecookbook.id).count
assert_nil Board.first(conditions: { project_id: @ecookbook.id }) assert_equal 0, Board.where(project_id: @ecookbook.id).count
assert_nil WorkPackage.first(conditions: { project_id: @ecookbook.id }) assert_equal 0, WorkPackage.where(project_id: @ecookbook.id).count
end end
it 'should destroying root projects should clear data' do 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, Board.count
assert_equal 0, Message.count assert_equal 0, Message.count
assert_equal 0, News.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, Repository.count
assert_equal 0, Changeset.count assert_equal 0, Changeset.count
assert_equal 0, Change.count assert_equal 0, Change.count
@ -226,7 +226,7 @@ describe Project, type: :model do
assert_equal 0, WikiContent.count 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 projects_types').to_a.size
assert_equal 0, Project.connection.select_all('SELECT * FROM custom_fields_projects').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 end
it 'should move an orphan project to a root project' do 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 it 'should activities should use the system activities' do
project = Project.find(1) 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 end
it 'should activities should use the project specific activities' do 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 it 'should activities should not include the inactive project specific activities' do
project = Project.find(1) 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 overridden_activity.save!
assert !project.activities.include?(overridden_activity), 'Inactive Project specific Activity found' assert !project.activities.include?(overridden_activity), 'Inactive Project specific Activity found'
@ -691,7 +691,7 @@ describe Project, type: :model do
end end
it 'should activities should handle nils' do 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 TimeEntryActivity.delete_all
# No activities # No activities
@ -706,7 +706,7 @@ describe Project, type: :model do
it 'should activities should override system activities with project activities' do it 'should activities should override system activities with project activities' do
project = Project.find(1) project = Project.find(1)
parent_activity = TimeEntryActivity.find(:first) parent_activity = TimeEntryActivity.first
overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: parent_activity) overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: parent_activity)
assert overridden_activity.save! assert overridden_activity.save!
@ -716,7 +716,7 @@ describe Project, type: :model do
it 'should activities should include inactive activities if specified' do it 'should activities should include inactive activities if specified' do
project = Project.find(1) 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 overridden_activity.save!
assert project.activities(true).include?(overridden_activity), 'Inactive Project specific Activity not found' 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 assert_equal @project, issue.project
end 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
assert copied_issue.status assert copied_issue.status
assert_equal 'Closed', copied_issue.status.name assert_equal 'Closed', copied_issue.status.name

@ -55,9 +55,8 @@ describe Query, type: :model do
end end
def find_issues_with_query(query) def find_issues_with_query(query)
WorkPackage.find :all, WorkPackage.includes(:assigned_to, :status, :type, :project, :priority)
include: [:assigned_to, :status, :type, :project, :priority], .where(query.statement)
conditions: query.statement
end end
def assert_find_issues_with_query_is_successful(query) 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'])]) query = Query.new(name: '_', filters: [Queries::WorkPackages::Filter.new(:assigned_to_id, operator: '=', values: ['me'])])
result = query.results.work_packages 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?(i1)
assert result.include?(i2) 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' } c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' }
assert c assert c
assert c.sortable assert c.sortable
issues = WorkPackage.find :all, issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority)
include: [:assigned_to, :status, :type, :project, :priority], .where(q.statement)
conditions: q.statement, .order("#{c.sortable} ASC")
order: "#{c.sortable} ASC"
values = issues.map { |i| i.custom_value_for(c.custom_field).to_s } values = issues.map { |i| i.custom_value_for(c.custom_field).to_s }
assert !values.empty? assert !values.empty?
assert_equal values.sort, values 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' } c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' }
assert c assert c
assert c.sortable assert c.sortable
issues = WorkPackage.find :all, issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority)
include: [:assigned_to, :status, :type, :project, :priority], .where(q.statement)
conditions: q.statement, .order("#{c.sortable} DESC")
order: "#{c.sortable} DESC"
values = issues.map { |i| i.custom_value_for(c.custom_field).to_s } values = issues.map { |i| i.custom_value_for(c.custom_field).to_s }
assert !values.empty? assert !values.empty?
assert_equal values.sort.reverse, values 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' } c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'float' }
assert c assert c
assert c.sortable assert c.sortable
issues = WorkPackage.find :all, issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority)
include: [:assigned_to, :status, :type, :project, :priority], .where(q.statement)
conditions: q.statement, .order("#{c.sortable} ASC")
order: "#{c.sortable} ASC"
values = issues.map { |i| begin; Kernel.Float(i.custom_value_for(c.custom_field).to_s); rescue; nil; end }.compact values = issues.map { |i| begin; Kernel.Float(i.custom_value_for(c.custom_field).to_s); rescue; nil; end }.compact
assert !values.empty? assert !values.empty?
assert_equal values.sort, values assert_equal values.sort, values

@ -88,12 +88,12 @@ describe Repository::Git, type: :model do
it 'should fetch changesets incremental' do it 'should fetch changesets incremental' do
@repository.fetch_changesets @repository.fetch_changesets
# Remove the 3 latest 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 @repository.reload
cs1 = @repository.changesets cs1 = @repository.changesets
assert_equal 13, cs1.count 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 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
# Mon Jul 5 22:34:26 2010 +0200 # Mon Jul 5 22:34:26 2010 +0200
rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26) rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)

@ -79,7 +79,7 @@ describe Repository, type: :model do
Setting.notified_events = ['work_package_added', 'work_package_updated'] Setting.notified_events = ['work_package_added', 'work_package_updated']
# choosing a status to apply to fix issues # 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_fix_done_ratio = '90'
Setting.commit_ref_keywords = 'refs , references, IssueID' Setting.commit_ref_keywords = 'refs , references, IssueID'
Setting.commit_fix_keywords = 'fixes , closes' Setting.commit_fix_keywords = 'fixes , closes'
@ -140,7 +140,7 @@ describe Repository, type: :model do
end end
it 'should manual user mapping' do 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.') c = Changeset.create!(repository: @repository, committer: 'foo', committed_on: Time.now, revision: 100, comments: 'Committed by foo.')
assert_nil c.user assert_nil c.user
@repository.committer_ids = { 'foo' => '2' } @repository.committer_ids = { 'foo' => '2' }

@ -52,7 +52,7 @@ describe Repository::Subversion, type: :model do
it 'should fetch changesets incremental' do it 'should fetch changesets incremental' do
@repository.fetch_changesets @repository.fetch_changesets
# Remove changesets with revision > 5 # 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 @repository.reload
assert_equal 5, @repository.changesets.count assert_equal 5, @repository.changesets.count

@ -134,7 +134,7 @@ describe 'Search' do # FIXME: naming (RSpec-port)
i.add_journal User.current, 'Some notes with Redmine links: #2, r2.' i.add_journal User.current, 'Some notes with Redmine links: #2, r2.'
i.save! 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 r = WorkPackage.search('%notes%').first
assert_equal 1, r.size assert_equal 1, r.size

@ -47,8 +47,8 @@ describe Status, type: :model do
assert_difference 'Status.count', -1 do assert_difference 'Status.count', -1 do
assert status.destroy assert status.destroy
end end
assert_nil Workflow.first(conditions: { old_status_id: status.id }) assert_equal 0, Workflow.where(old_status_id: status.id).count
assert_nil Workflow.first(conditions: { new_status_id: status.id }) assert_equal 0, Workflow.where(new_status_id: status.id).count
end end
it 'should destroy status in use' do it 'should destroy status in use' do
@ -95,7 +95,7 @@ describe Status, type: :model do
it 'should change nothing' do it 'should change nothing' do
Status.update_work_package_done_ratios 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
end end

@ -42,7 +42,7 @@ describe User, type: :model do
specify 'object_daddy creation' do specify 'object_daddy creation' do
User.generate_with_protected!(firstname: 'Testing connection') User.generate_with_protected!(firstname: 'Testing connection')
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 end
it 'should truth' do it 'should truth' do

@ -97,7 +97,7 @@ describe Version, type: :model do
it 'should progress should be 100 with closed assigned issues' do it 'should progress should be 100 with closed assigned issues' do
project = Project.find(1) 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 = Version.new.tap do |v|
v.force_attributes = { project: project, name: 'Progress' } v.force_attributes = { project: project, name: 'Progress' }
end).save! end).save!
@ -128,7 +128,7 @@ describe Version, type: :model do
end).save! end).save!
add_work_package(v) add_work_package(v)
add_work_package(v, done_ratio: 20) 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 (0.0 + 20.0 + 100.0) / 3, v.completed_percent
assert_progress_equal (100.0) / 3, v.closed_percent assert_progress_equal (100.0) / 3, v.closed_percent
end end
@ -141,7 +141,7 @@ describe Version, type: :model do
add_work_package(v, estimated_hours: 10) add_work_package(v, estimated_hours: 10)
add_work_package(v, estimated_hours: 20, done_ratio: 30) 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: 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 (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 assert_progress_equal 25.0 / 95.0 * 100, v.closed_percent
end end
@ -152,7 +152,7 @@ describe Version, type: :model do
v.force_attributes = { project: project, name: 'Progress' } v.force_attributes = { project: project, name: 'Progress' }
end).save! end).save!
add_work_package(v, done_ratio: 20) 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: 10, done_ratio: 30)
add_work_package(v, estimated_hours: 40, done_ratio: 10) 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 assert_progress_equal (25.0 * 0.2 + 25.0 * 1 + 10.0 * 0.3 + 40.0 * 0.1) / 100.0 * 100, v.completed_percent

@ -118,8 +118,8 @@ describe WikiPage, type: :model do
# make sure that page content and its history are deleted # make sure that page content and its history are deleted
assert WikiContent.where(page_id: 1).empty? assert WikiContent.where(page_id: 1).empty?
content_ids.each do |wiki_content_id| content_ids.each do |wiki_content_id|
assert Journal.find :all, conditions: { journable_type: WikiContent, assert Journal.where(journable_type: WikiContent,
journable_id: wiki_content_id } journable_id: wiki_content_id)
end end
end end

@ -80,6 +80,6 @@ describe WikiRedirect, type: :model do
assert WikiRedirect.create(wiki: @wiki, title: 'An_old_page', redirects_to: 'Original_title') assert WikiRedirect.create(wiki: @wiki, title: 'An_old_page', redirects_to: 'Original_title')
@original.destroy @original.destroy
assert !@wiki.redirects.find(:first) assert !@wiki.redirects.first
end end
end end

@ -90,7 +90,7 @@ shared_examples_for 'a controller action with require_login' do
end end
shared_examples_for 'a controller action with require_admin' do 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) } let(:invalid_user) { FactoryGirl.create(:user) }
extend PermissionSpecHelpers extend PermissionSpecHelpers

Loading…
Cancel
Save