Decouple legacy specs from ObjectDaddy

pull/3421/head
Stefan Botzenhart 9 years ago committed by Alex Coles
parent d2edc0d0bf
commit 5d9513183e
  1. 20
      spec/legacy/integration/api_spec/disabled_rest_api_spec.rb
  2. 2
      spec/legacy/integration/layout_spec.rb
  3. 30
      spec/legacy/support/legacy_assertions.rb
  4. 62
      spec/legacy/support/object_daddy_helpers.rb
  5. 4
      spec/legacy/unit/journal_spec.rb
  6. 16
      spec/legacy/unit/lib/redmine/ciphering_spec.rb
  7. 9
      spec/legacy/unit/mail_handler_spec.rb
  8. 16
      spec/legacy/unit/principal_spec.rb
  9. 107
      spec/legacy/unit/project_spec.rb
  10. 40
      spec/legacy/unit/query_spec.rb
  11. 8
      spec/legacy/unit/time_entry_spec.rb
  12. 34
      spec/legacy/unit/user_spec.rb
  13. 4
      spec/legacy/unit/version_spec.rb
  14. 2
      spec/legacy/unit/wiki_spec.rb
  15. 12
      spec/legacy_spec_helper.rb

@ -46,8 +46,8 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
context 'in :xml format' do
context 'with a valid api token' do
before do
@user = User.generate_with_protected!
@token = Token.generate!(user: @user, action: 'api')
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
get "/api/v2/projects.xml?key=#{@token.value}"
end
@ -60,7 +60,7 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
context 'with a valid HTTP authentication' do
before do
@user = User.generate_with_protected!(password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
@user = FactoryGirl.create(:user, password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'adminADMIN!')
get '/api/v2/projects.xml', nil, authorization: @authorization
end
@ -74,8 +74,8 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
context 'with a valid HTTP authentication using the API token' do
before do
@user = User.generate_with_protected!
@token = Token.generate!(user: @user, action: 'api')
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'X')
get '/api/v2/projects.xml', nil, authorization: @authorization
end
@ -91,8 +91,8 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
context 'in :json format' do
context 'with a valid api token' do
before do
@user = User.generate_with_protected!
@token = Token.generate!(user: @user, action: 'api')
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
get "/api/v2/projects.json?key=#{@token.value}"
end
@ -105,7 +105,7 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
context 'with a valid HTTP authentication' do
before do
@user = User.generate_with_protected!(password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
@user = FactoryGirl.create(:user, password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@user.login, 'adminADMIN!')
get '/api/v2/projects.json', nil, authorization: @authorization
end
@ -119,8 +119,8 @@ describe 'ApiTest: DisabledRestApiTest', type: :request do
context 'with a valid HTTP authentication using the API token' do
before do
@user = User.generate_with_protected!
@token = Token.generate!(user: @user, action: 'api')
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
@authorization = ActionController::HttpAuthentication::Basic.encode_credentials(@token.value, 'DoesNotMatter')
get '/api/v2/projects.json', nil, authorization: @authorization
end

@ -56,7 +56,7 @@ describe 'Layout' do
end
specify 'page titles should be properly escaped' do
project = Project.generate(name: 'C&A', is_public: true)
project = FactoryGirl.create(:project, name: 'C&A', is_public: true)
with_settings app_title: '<3' do
get "/projects/#{project.to_param}"

@ -168,8 +168,8 @@ module LegacyAssertionsAndHelpers
if block_given?
instance_eval &block
else
@old_value = model.generate!
@new_value = model.generate!
@old_value = FactoryGirl.create(model.to_sym)
@new_value = FactoryGirl.create(model.to_sym)
end
end
@ -317,7 +317,7 @@ module LegacyAssertionsAndHelpers
context "should allow http basic auth using a username and password for #{http_method} #{url}" do
context 'with a valid HTTP authentication' do
before do
@user = User.generate_with_protected!(password: 'adminADMIN!', password_confirmation: 'adminADMIN!', admin: true) # Admin so they can access the project
@user = FactoryGirl.create(:user, password: 'adminADMIN!', password_confirmation: 'adminADMIN!', admin: true) # Admin so they can access the project
send(http_method, url, parameters, credentials(@user.login, 'adminADMIN!'))
end
@ -330,7 +330,7 @@ module LegacyAssertionsAndHelpers
context 'with an invalid HTTP authentication' do
before do
@user = User.generate_with_protected!
@user = FactoryGirl.create(:user)
send(http_method, url, parameters, credentials(@user.login, 'wrong_password'))
end
@ -377,8 +377,8 @@ module LegacyAssertionsAndHelpers
context "should allow http basic auth with a key for #{http_method} #{url}" do
context 'with a valid HTTP authentication using the API token' do
before do
@user = User.generate_with_protected!(admin: true)
@token = Token.generate!(user: @user, action: 'api')
@user = FactoryGirl.create(:user, admin: true)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
send(http_method, url, parameters, credentials(@token.value, 'X'))
end
@ -392,8 +392,8 @@ module LegacyAssertionsAndHelpers
context 'with an invalid HTTP authentication' do
before do
@user = User.generate_with_protected!
@token = Token.generate!(user: @user, action: 'feeds')
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'feeds')
send(http_method, url, parameters, credentials(@token.value, 'X'))
end
@ -421,8 +421,8 @@ module LegacyAssertionsAndHelpers
context "should allow key based auth using key=X for #{http_method} #{url}" do
context 'with a valid api token' do
before do
@user = User.generate_with_protected!(admin: true)
@token = Token.generate!(user: @user, action: 'api')
@user = FactoryGirl.create(:user, admin: true)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
# Simple url parse to add on ?key= or &key=
request_url = if url.match(/\?/)
url + "&key=#{@token.value}"
@ -441,8 +441,8 @@ module LegacyAssertionsAndHelpers
context 'with an invalid api token' do
before do
@user = User.generate_with_protected!
@token = Token.generate!(user: @user, action: 'feeds')
@user = FactoryGirl.create(:user)
@token = FactoryGirl.create(:token, user: @user, action: 'feeds')
# Simple url parse to add on ?key= or &key=
request_url = if url.match(/\?/)
url + "&key=#{@token.value}"
@ -461,9 +461,9 @@ module LegacyAssertionsAndHelpers
context "should allow key based auth using X-OpenProject-API-Key header for #{http_method} #{url}" do
before do
@user = User.generate_with_protected!(admin: true)
@token = Token.generate!(user: @user, action: 'api')
send(http_method, url, {}, 'X-OpenProject-API-Key' => @token.value.to_s)
@user = FactoryGirl.create(:user, admin: true)
@token = FactoryGirl.create(:token, user: @user, action: 'api')
send(http_method, url, {}, {'X-OpenProject-API-Key' => @token.value.to_s})
end
it { should respond_with success_code }
it { should_respond_with_content_type_based_on_url(url) }

@ -1,62 +0,0 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
module ObjectDaddyHelpers
# TODO: Remove these three once everyone has ported their code to use the
# new object_daddy version with protected attribute support
def User.generate_with_protected(attributes = {})
User.generate(attributes)
end
def User.generate_with_protected!(attributes = {})
User.generate!(attributes)
end
def User.spawn_with_protected(attributes = {})
User.spawn(attributes)
end
def User.add_to_project(user, project, roles)
roles = [roles] unless roles.is_a?(Array)
member = Member.generate { |m|
m.principal = user
m.project = project
m.role_ids = roles.map(&:id)
}
member.save!
end
# Generate the default Query
def Query.generate_default!(attributes = {})
query = Query.spawn(attributes)
query.name ||= '_'
query.save!
query
end
end

@ -64,12 +64,12 @@ describe Journal, type: :model do
specify 'creating the initial journal should track the changes from creation' do
Journal.delete_all
@project = Project.generate!
@project = FactoryGirl.create(:project)
issue = WorkPackage.new do |i|
i.project = @project
i.subject = 'Test initial journal'
i.type = @project.types.first
i.author = User.generate!
i.author = FactoryGirl.create(:user)
i.description = 'Some content'
end

@ -31,7 +31,7 @@ require 'legacy_spec_helper'
describe Redmine::Ciphering do
it 'should password should be encrypted' do
OpenProject::Configuration.with 'database_cipher_key' => 'secret' do
r = Repository::Subversion.generate!(password: 'foo')
r = FactoryGirl.create(:repository_subversion, password: 'foo')
assert_equal 'foo', r.password
assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/)
end
@ -39,7 +39,7 @@ describe Redmine::Ciphering do
it 'should password should be clear with blank key' do
OpenProject::Configuration.with 'database_cipher_key' => '' do
r = Repository::Subversion.generate!(password: 'foo')
r = FactoryGirl.create(:repository_subversion, password: 'foo')
assert_equal 'foo', r.password
assert_equal 'foo', r.read_attribute(:password)
end
@ -47,7 +47,7 @@ describe Redmine::Ciphering do
it 'should password should be clear with nil key' do
OpenProject::Configuration.with 'database_cipher_key' => nil do
r = Repository::Subversion.generate!(password: 'foo')
r = FactoryGirl.create(:repository_subversion, password: 'foo')
assert_equal 'foo', r.password
assert_equal 'foo', r.read_attribute(:password)
end
@ -55,7 +55,7 @@ describe Redmine::Ciphering do
it 'should unciphered password should be readable' do
OpenProject::Configuration.with 'database_cipher_key' => nil do
r = Repository::Subversion.generate!(password: 'clear')
r = FactoryGirl.create(:repository_subversion, password: 'clear')
end
OpenProject::Configuration.with 'database_cipher_key' => 'secret' do
@ -67,8 +67,8 @@ describe Redmine::Ciphering do
it 'should encrypt all' do
Repository.delete_all
OpenProject::Configuration.with 'database_cipher_key' => nil do
Repository::Subversion.generate!(password: 'foo')
Repository::Subversion.generate!(password: 'bar')
FactoryGirl.create(:repository_subversion, password: 'foo')
FactoryGirl.create(:repository_subversion, password: 'bar')
end
OpenProject::Configuration.with 'database_cipher_key' => 'secret' do
@ -82,8 +82,8 @@ describe Redmine::Ciphering do
it 'should decrypt all' do
Repository.delete_all
OpenProject::Configuration.with 'database_cipher_key' => 'secret' do
Repository::Subversion.generate!(password: 'foo')
Repository::Subversion.generate!(password: 'bar')
FactoryGirl.create(:repository_subversion, password: 'foo')
FactoryGirl.create(:repository_subversion, password: 'bar')
assert Repository.decrypt_all(:password)
r = Repository.order('id DESC').first

@ -169,8 +169,9 @@ describe MailHandler, type: :model do
end
it 'should add work package should match assignee on display name' do # added from redmine - not sure if it is ok here
user = User.generate!(firstname: 'Foo', lastname: 'Bar')
User.add_to_project(user, Project.find(2), Role.generate!(name: 'Superhero'))
user = FactoryGirl.create(:user, firstname: 'Foo', lastname: 'Bar')
role = FactoryGirl.create(:role, name: 'Superhero')
FactoryGirl.create(:member, user: user, project: Project.find(2), role_ids: [role.id] )
issue = submit_email('ticket_on_given_project.eml') do |email|
email.sub!(/^Assigned to.*$/, 'Assigned to: Foo Bar')
end
@ -353,9 +354,7 @@ describe MailHandler, type: :model do
specify 'reply to issue update (Journal) by message_id' do
Journal.delete_all
issue = WorkPackage.find(2)
j = FactoryGirl.create :work_package_journal,
id: 3,
journable_id: issue.id
j = FactoryGirl.create :work_package_journal, id: 3, journable_id: issue.id
journal = submit_email('ticket_reply_by_message_id.eml')
assert journal.data.is_a?(Journal::WorkPackageJournal), "Email was a #{journal.data.class}"
assert_equal User.find_by_login('jsmith'), journal.user

@ -31,17 +31,17 @@ require 'legacy_spec_helper'
describe Principal, type: :model do
context '#like' do
before do
Principal.generate!(login: 'login')
Principal.generate!(login: 'login2')
FactoryGirl.create(:principal, login: 'login')
FactoryGirl.create(:principal, login: 'login2')
Principal.generate!(firstname: 'firstname')
Principal.generate!(firstname: 'firstname2')
FactoryGirl.create(:principal, firstname: 'firstname')
FactoryGirl.create(:principal, firstname: 'firstname2')
Principal.generate!(lastname: 'lastname')
Principal.generate!(lastname: 'lastname2')
FactoryGirl.create(:principal, lastname: 'lastname')
FactoryGirl.create(:principal, lastname: 'lastname2')
Principal.generate!(mail: 'mail@example.com')
Principal.generate!(mail: 'mail2@example.com')
FactoryGirl.create(:principal, mail: 'mail@example.com')
FactoryGirl.create(:principal, mail: 'mail2@example.com')
end
it 'should search login' do

@ -446,14 +446,14 @@ describe Project, type: :model do
end
it 'should short description returns shortened description' do
@project = Project.generate!
@project = FactoryGirl.create(:project)
@project.description = ('Abcd ' * 5 + "\n") * 11
@project.summary = ''
assert_equal (('Abcd ' * 5 + "\n") * 10)[0..-2] + '...', @project.short_description
end
it 'should short description returns summary' do
@project = Project.generate!
@project = FactoryGirl.create(:project)
@project.description = ('Abcd ' * 5 + "\n") * 11
@project.summary = 'In short'
assert_equal 'In short', @project.short_description
@ -462,9 +462,9 @@ describe Project, type: :model do
context '#rolled_up_versions' do
before do
@project = Project.generate!
@parent_version_1 = Version.generate!(project: @project)
@parent_version_2 = Version.generate!(project: @project)
@project = FactoryGirl.create(:project)
@parent_version_1 = FactoryGirl.create(:version, project: @project)
@parent_version_2 = FactoryGirl.create(:version, project: @project)
end
it 'should include the versions for the current project' do
@ -472,9 +472,9 @@ describe Project, type: :model do
end
it 'should include versions for a subproject' do
@subproject = Project.generate!
@subproject = FactoryGirl.create(:project)
@subproject.set_parent!(@project)
@subproject_version = Version.generate!(project: @subproject)
@subproject_version = FactoryGirl.create(:version, project: @subproject)
assert_same_elements [
@parent_version_1,
@ -484,11 +484,11 @@ describe Project, type: :model do
end
it 'should include versions for a sub-subproject' do
@subproject = Project.generate!
@subproject = FactoryGirl.create(:project)
@subproject.set_parent!(@project)
@sub_subproject = Project.generate!
@sub_subproject = FactoryGirl.create(:project)
@sub_subproject.set_parent!(@subproject)
@sub_subproject_version = Version.generate!(project: @sub_subproject)
@sub_subproject_version = FactoryGirl.create(:version, project: @sub_subproject)
@project.reload
@ -500,9 +500,9 @@ describe Project, type: :model do
end
it 'should only check active projects' do
@subproject = Project.generate!
@subproject = FactoryGirl.create(:project)
@subproject.set_parent!(@project)
@subproject_version = Version.generate!(project: @subproject)
@subproject_version = FactoryGirl.create(:version, project: @subproject)
assert @subproject.archive
@project.reload
@ -726,7 +726,7 @@ describe Project, type: :model do
project = Project.find(1)
system_activity = TimeEntryActivity.find_by(name: 'Design')
assert system_activity.active?
overridden_activity = TimeEntryActivity.generate!(project: project, parent: system_activity, active: false)
overridden_activity = FactoryGirl.create(:time_entry_activity, project: project, parent: system_activity, active: false)
assert overridden_activity.save!
assert !project.activities.include?(overridden_activity), 'Inactive Project specific Activity not found'
@ -760,11 +760,14 @@ describe Project, type: :model do
end
it 'should copy work units' do
@source_project.work_packages << WorkPackage.generate!(status: Status.find_by(name: 'Closed'),
subject: 'copy issue status',
type_id: 1,
assigned_to_id: 2,
project_id: @source_project.id)
work_package = FactoryGirl.create( :work_package,
status: Status.find_by_name('Closed'),
subject: 'copy issue status',
type_id: 1,
assigned_to_id: 2,
project_id: @source_project.id)
@source_project.work_packages << work_package
assert @project.valid?
assert @project.work_packages.empty?
assert @project.copy(@source_project)
@ -784,7 +787,7 @@ describe Project, type: :model do
it 'should change the new issues to use the copied version' do
User.current = User.find(1)
assigned_version = Version.generate!(name: 'Assigned Issues', status: 'open')
assigned_version = FactoryGirl.create(:version, name: 'Assigned Issues', status: 'open')
@source_project.versions << assigned_version
assert_equal 3, @source_project.versions.size
FactoryGirl.create(:work_package, project: @source_project,
@ -805,7 +808,7 @@ describe Project, type: :model do
it 'should change the new issues to use the copied closed version' do
User.current = User.find(1)
assigned_version = Version.generate!(name: 'Assigned Issues', status: 'open')
assigned_version = FactoryGirl.create(:version, name: 'Assigned Issues', status: 'open')
@source_project.versions << assigned_version
assert_equal 3, @source_project.versions.size
FactoryGirl.create(:work_package, project: @source_project,
@ -828,15 +831,15 @@ describe Project, type: :model do
it 'should copy issue relations' do
Setting.cross_project_work_package_relations = '1'
second_issue = WorkPackage.generate!(status_id: 5,
second_issue = FactoryGirl.create(:work_package, status_id: 5,
subject: 'copy issue relation',
type_id: 1,
assigned_to_id: 2,
project_id: @source_project.id)
source_relation = Relation.generate!(from: WorkPackage.find(4),
source_relation = FactoryGirl.create(:relation, from: WorkPackage.find(4),
to: second_issue,
relation_type: 'relates')
source_relation_cross_project = Relation.generate!(from: WorkPackage.find(1),
source_relation_cross_project = FactoryGirl.create(:relation, from: WorkPackage.find(1),
to: second_issue,
relation_type: 'duplicates')
@ -908,8 +911,8 @@ describe Project, type: :model do
end
it 'should copy versions' do
@source_project.versions << Version.generate!
@source_project.versions << Version.generate!
@source_project.versions << FactoryGirl.create(:version)
@source_project.versions << FactoryGirl.create(:version)
assert @project.versions.empty?
assert @project.copy(@source_project)
@ -998,8 +1001,8 @@ describe Project, type: :model do
context '#start_date' do
before do
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
@project = Project.generate!(identifier: 'test0')
@project.types << ::Type.generate!
@project = FactoryGirl.create(:project, identifier: 'test0')
@project.types << FactoryGirl.create(:type)
end
it 'should be nil if there are no issues on the project' do
@ -1020,8 +1023,8 @@ describe Project, type: :model do
context '#due_date' do
before do
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
@project = Project.generate!(identifier: 'test0')
@project.types << ::Type.generate!
@project = FactoryGirl.create(:project, identifier: 'test0')
@project.types << FactoryGirl.create(:type)
end
it 'should be nil if there are no issues on the project' do
@ -1040,8 +1043,8 @@ describe Project, type: :model do
it "should be the latest due date of it's versions" do
future = 7.days.from_now.to_date
@project.versions << Version.generate!(effective_date: future)
@project.versions << Version.generate!(effective_date: Date.today)
@project.versions << FactoryGirl.create(:version, effective_date: future)
@project.versions << FactoryGirl.create(:version, effective_date: Date.today)
assert_equal future, @project.due_date
end
@ -1050,7 +1053,7 @@ describe Project, type: :model do
future = 7.days.from_now.to_date
far_future = 14.days.from_now.to_date
FactoryGirl.create(:work_package, project: @project, due_date: far_future)
@project.versions << Version.generate!(effective_date: future)
@project.versions << FactoryGirl.create(:version, effective_date: future)
assert_equal far_future, @project.due_date
end
@ -1059,8 +1062,8 @@ describe Project, type: :model do
context 'Project#completed_percent' do
before do
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
@project = Project.generate!(identifier: 'test0')
@project.types << ::Type.generate!
@project = FactoryGirl.create(:project, identifier: 'test0')
@project.types << FactoryGirl.create(:type)
end
context 'no versions' do
@ -1071,26 +1074,26 @@ describe Project, type: :model do
context 'with versions' do
it 'should return 0 if the versions have no issues' do
Version.generate!(project: @project)
Version.generate!(project: @project)
FactoryGirl.create(:version, project: @project)
FactoryGirl.create(:version, project: @project)
assert_equal 0, @project.completed_percent
end
it 'should return 100 if the version has only closed issues' do
v1 = Version.generate!(project: @project)
FactoryGirl.create(:work_package, project: @project, status: Status.find_by(name: 'Closed'), fixed_version: v1)
v2 = Version.generate!(project: @project)
FactoryGirl.create(:work_package, project: @project, status: Status.find_by(name: 'Closed'), fixed_version: v2)
v1 = FactoryGirl.create(:version, project: @project)
FactoryGirl.create(:work_package, project: @project, status: Status.find_by_name('Closed'), fixed_version: v1)
v2 = FactoryGirl.create(:version, project: @project)
FactoryGirl.create(:work_package, project: @project, status: Status.find_by_name('Closed'), fixed_version: v2)
assert_equal 100, @project.completed_percent
end
it 'should return the averaged completed percent of the versions (not weighted)' do
v1 = Version.generate!(project: @project)
FactoryGirl.create(:work_package, project: @project, status: Status.find_by(name: 'New'), estimated_hours: 10, done_ratio: 50, fixed_version: v1)
v2 = Version.generate!(project: @project)
FactoryGirl.create(:work_package, project: @project, status: Status.find_by(name: 'New'), estimated_hours: 10, done_ratio: 50, fixed_version: v2)
v1 = FactoryGirl.create(:version, project: @project)
FactoryGirl.create(:work_package, project: @project, status: Status.find_by_name('New'), estimated_hours: 10, done_ratio: 50, fixed_version: v1)
v2 = FactoryGirl.create(:version, project: @project)
FactoryGirl.create(:work_package, project: @project, status: Status.find_by_name('New'), estimated_hours: 10, done_ratio: 50, fixed_version: v2)
assert_equal 50, @project.completed_percent
end
@ -1099,35 +1102,35 @@ describe Project, type: :model do
context '#notified_users' do
before do
@project = Project.generate!
@role = Role.generate!
@project = FactoryGirl.create(:project)
@role = FactoryGirl.create(:role)
@user_with_membership_notification = User.generate!(mail_notification: 'selected')
@user_with_membership_notification = FactoryGirl.create(:user, mail_notification: 'selected')
Member.create!(project: @project, principal: @user_with_membership_notification, mail_notification: true) do |member|
member.role_ids = [@role.id]
end
@all_events_user = User.generate!(mail_notification: 'all')
@all_events_user = FactoryGirl.create(:user, mail_notification: 'all')
Member.create!(project: @project, principal: @all_events_user) do |member|
member.role_ids = [@role.id]
end
@no_events_user = User.generate!(mail_notification: 'none')
@no_events_user = FactoryGirl.create(:user, mail_notification: 'none')
Member.create!(project: @project, principal: @no_events_user) do |member|
member.role_ids = [@role.id]
end
@only_my_events_user = User.generate!(mail_notification: 'only_my_events')
@only_my_events_user = FactoryGirl.create(:user, mail_notification: 'only_my_events')
Member.create!(project: @project, principal: @only_my_events_user) do |member|
member.role_ids = [@role.id]
end
@only_assigned_user = User.generate!(mail_notification: 'only_assigned')
@only_assigned_user = FactoryGirl.create(:user, mail_notification: 'only_assigned')
Member.create!(project: @project, principal: @only_assigned_user) do |member|
member.role_ids = [@role.id]
end
@only_owned_user = User.generate!(mail_notification: 'only_owner')
@only_owned_user = FactoryGirl.create(:user, mail_notification: 'only_owner')
Member.create!(project: @project, principal: @only_owned_user) do |member|
member.role_ids = [@role.id]
end

@ -448,8 +448,8 @@ describe Query, type: :model do
it 'should have a list of the groups as values' do
Group.destroy_all # No fixtures
group1 = Group.generate!.reload
group2 = Group.generate!.reload
group1 = FactoryGirl.create(:group).reload
group2 = FactoryGirl.create(:group).reload
expected_group_list = [
[group1.name, group1.id.to_s],
@ -581,19 +581,19 @@ describe Query, type: :model do
context "with 'member_of_group' filter" do
before do
Group.destroy_all # No fixtures
@user_in_group = User.generate!
@second_user_in_group = User.generate!
@user_in_group2 = User.generate!
@user_not_in_group = User.generate!
@user_in_group = FactoryGirl.create(:user)
@second_user_in_group = FactoryGirl.create(:user)
@user_in_group2 = FactoryGirl.create(:user)
@user_not_in_group = FactoryGirl.create(:user)
@group = Group.generate!.reload
@group = FactoryGirl.create(:group).reload
@group.users << @user_in_group
@group.users << @second_user_in_group
@group2 = Group.generate!.reload
@group2 = FactoryGirl.create(:group).reload
@group2.users << @user_in_group2
@empty_group = Group.generate!.reload
@empty_group = FactoryGirl.create(:group).reload
end
it 'should search assigned to for users in the group' do
@ -646,17 +646,17 @@ describe Query, type: :model do
Member.delete_all
Role.delete_all
@manager_role = Role.generate!(name: 'Manager')
@developer_role = Role.generate!(name: 'Developer')
@empty_role = Role.generate!(name: 'Empty')
@project = Project.generate!
@manager = User.generate!
@developer = User.generate!
@boss = User.generate!
User.add_to_project(@manager, @project, @manager_role)
User.add_to_project(@developer, @project, @developer_role)
User.add_to_project(@boss, @project, [@manager_role, @developer_role])
@manager_role = FactoryGirl.create(:role, name: 'Manager')
@developer_role = FactoryGirl.create(:role, name: 'Developer')
@empty_role = FactoryGirl.create(:role, name: 'Empty')
@project = FactoryGirl.create(:project)
@manager = FactoryGirl.create(:user)
@developer = FactoryGirl.create(:user)
@boss = FactoryGirl.create(:user)
FactoryGirl.create(:member, user: @manager, project: @project, role_ids: [@manager_role.id])
FactoryGirl.create(:member, user: @developer, project: @project, role_ids: [@developer_role.id])
FactoryGirl.create(:member, user: @boss, project: @project, role_ids: [@manager_role, @developer_role].map(&:id))
end
it 'should search assigned to for users with the Role' do

@ -99,9 +99,9 @@ describe TimeEntry, type: :model do
context '#earliest_date_for_project' do
before do
User.current = nil
@public_project = Project.generate!(is_public: true)
@public_project = FactoryGirl.create(:project, is_public: true)
@issue = FactoryGirl.create(:work_package, project: @public_project)
TimeEntry.generate!(spent_on: '2010-01-01',
FactoryGirl.create(:time_entry, spent_on: '2010-01-01',
work_package: @issue,
project: @public_project)
end
@ -122,9 +122,9 @@ describe TimeEntry, type: :model do
context '#latest_date_for_project' do
before do
User.current = nil
@public_project = Project.generate!(is_public: true)
@public_project = FactoryGirl.create(:project, is_public: true)
@issue = FactoryGirl.create(:work_package, project: @public_project)
TimeEntry.generate!(spent_on: '2010-01-01',
FactoryGirl.create(:time_entry, spent_on: '2010-01-01',
work_package: @issue,
project: @public_project)
end

@ -40,8 +40,8 @@ describe User, type: :model do
end
specify 'object_daddy creation' do
User.generate_with_protected!(firstname: 'Testing connection')
User.generate_with_protected!(firstname: 'Testing connection')
FactoryGirl.create(:user, firstname: 'Testing connection')
FactoryGirl.create(:user, firstname: 'Testing connection')
assert_equal 2, User.where(firstname: 'Testing connection').count
end
@ -79,11 +79,11 @@ describe User, type: :model do
context 'User#before_create' do
it 'should set the mail_notification to the default Setting' do
@user1 = User.generate_with_protected!
@user1 = FactoryGirl.create(:user, mail_notification: nil)
assert_equal 'only_my_events', @user1.mail_notification
with_settings default_notification_option: 'all' do
@user2 = User.generate_with_protected!
@user2 = FactoryGirl.create(:user)
assert_equal 'all', @user2.mail_notification
end
end
@ -156,7 +156,7 @@ describe User, type: :model do
end
it 'should select the exact matching user first' do
case_sensitive_user = User.generate_with_protected!(login: 'changed', password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
case_sensitive_user = FactoryGirl.create(:user, login: 'changed', password: 'adminADMIN!', password_confirmation: 'adminADMIN!')
# bypass validations to make it appear like existing data
case_sensitive_user.update_attribute(:login, 'ADMIN')
@ -283,7 +283,7 @@ describe User, type: :model do
context 'User#api_key' do
it "should generate a new one if the user doesn't have one" do
user = User.generate_with_protected!(api_token: nil)
user = FactoryGirl.create(:user, api_token: nil)
assert_nil user.api_token
key = user.api_key
@ -293,8 +293,8 @@ describe User, type: :model do
end
it 'should return the existing api token value' do
user = User.generate_with_protected!
token = Token.generate!(action: 'api')
user = FactoryGirl.create(:user)
token = FactoryGirl.create(:token, action: 'api')
user.api_token = token
assert user.save
@ -308,8 +308,8 @@ describe User, type: :model do
end
it 'should return nil if the key is found for an inactive user' do
user = User.generate_with_protected!(status: User::STATUSES[:locked])
token = Token.generate!(action: 'api')
user = FactoryGirl.create(:user, status: User::STATUSES[:locked])
token = FactoryGirl.create(:token, action: 'api')
user.api_token = token
user.save
@ -317,8 +317,8 @@ describe User, type: :model do
end
it 'should return the user if the key is found for an active user' do
user = User.generate_with_protected!(status: User::STATUSES[:active])
token = Token.generate!(action: 'api')
user = FactoryGirl.create(:user, status: User::STATUSES[:active])
token = FactoryGirl.create(:token, action: 'api')
user.api_token = token
user.save
@ -345,7 +345,7 @@ describe User, type: :model do
end
it 'should projects by role for user with no role' do
user = User.generate!
user = FactoryGirl.create(:user)
assert_equal({}, user.projects_by_role)
end
@ -482,8 +482,8 @@ describe User, type: :model do
context 'Issues' do
before do
@project = Project.find(1)
@author = User.generate_with_protected!
@assignee = User.generate_with_protected!
@author = FactoryGirl.create(:user)
@assignee = FactoryGirl.create(:user)
@issue = FactoryGirl.create(:work_package, project: @project, assigned_to: @assignee, author: @author)
end
@ -498,7 +498,7 @@ describe User, type: :model do
end
it "should be false for a user with :only_my_events and isn't an author, creator, or assignee" do
@user = User.generate_with_protected!(mail_notification: 'only_my_events')
@user = FactoryGirl.create(:user, mail_notification: 'only_my_events')
(Member.new.tap do |m|
m.force_attributes = { user: @user, project: @project, role_ids: [1] }
end).save!
@ -546,7 +546,7 @@ describe User, type: :model do
end
it 'should be false for a user with :selected and is not the author or assignee' do
@user = User.generate_with_protected!(mail_notification: 'selected')
@user = FactoryGirl.create(:user, mail_notification: 'selected')
(Member.new.tap do |m|
m.force_attributes = { user: @user, project: @project, role_ids: [1] }
end).save!

@ -162,8 +162,8 @@ describe Version, type: :model do
context '#behind_schedule?' do
before do
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
@project = Project.generate!(identifier: 'test0')
@project.types << Type.generate!
@project = FactoryGirl.create(:project, identifier: 'test0')
@project.types << FactoryGirl.create(:type)
(@version = Version.new.tap do |v|
v.force_attributes = { project: @project, effective_date: nil, name: 'test' }

@ -59,7 +59,7 @@ describe Wiki, type: :model do
page = WikiPage.find(10)
assert_equal page, wiki.find_page('Этика_менеджмента')
page = WikiPage.generate!(wiki: wiki, title: '2009\\02\\09')
page = FactoryGirl.create(:wiki_page, wiki: wiki, title: '2009\\02\\09')
assert_equal page, wiki.find_page('2009\\02\\09')
end

@ -29,7 +29,13 @@
ENV['RAILS_ENV'] = 'test'
require 'simplecov'
if ENV['COVERAGE']
require 'bundler'
Bundler.setup(:default, :test)
require 'simplecov'
SimpleCov.start 'rails'
end
require File.expand_path('../../config/environment', __FILE__)
@ -42,10 +48,6 @@ require_relative './support/shared/with_mock_request'
require_relative './legacy/support/legacy_assertions'
require_relative './support/repository_helpers'
require_relative './legacy/support/object_daddy_helpers'
include ObjectDaddyHelpers
require 'rspec/rails'
require 'shoulda/matchers'
require 'rspec/example_disabler'

Loading…
Cancel
Save