group :test do
gem "shoulda", "~> 2.10.3"
- gem "edavis10-object_daddy", :require => "object_daddy"
gem "mocha"
end
def User.add_to_project(user, project, roles)
roles = [roles] unless roles.is_a?(Array)
- Member.generate!(:principal => user, :project => project, :roles => roles)
+ Member.create!(:principal => user, :project => project, :roles => roles)
+ end
+
+ def User.generate!(attributes={})
+ @generated_user_login ||= 'user0'
+ @generated_user_login.succ!
+ user = User.new(attributes)
+ user.login = @generated_user_login if user.login.blank?
+ user.mail = "#{@generated_user_login}@example.com" if user.mail.blank?
+ user.firstname = "Bob" if user.firstname.blank?
+ user.lastname = "Doe" if user.lastname.blank?
+ yield user if block_given?
+ user.save!
+ user
+ end
+
+ def Group.generate!(attributes={})
+ @generated_group_name ||= 'Group 0'
+ @generated_group_name.succ!
+ group = Group.new(attributes)
+ group.lastname = @generated_group_name if group.lastname.blank?
+ yield group if block_given?
+ group.save!
+ group
+ end
+
+ def Project.generate!(attributes={})
+ @generated_project_identifier ||= 'project-0000'
+ @generated_project_identifier.succ!
+ project = Project.new(attributes)
+ project.name = @generated_project_identifier if project.name.blank?
+ project.identifier = @generated_project_identifier if project.identifier.blank?
+ yield project if block_given?
+ project.save!
+ project
+ end
+
+ def Tracker.generate!(attributes={})
+ @generated_tracker_name ||= 'Tracker 0'
+ @generated_tracker_name.succ!
+ tracker = Tracker.new(attributes)
+ tracker.name = @generated_tracker_name if tracker.name.blank?
+ yield tracker if block_given?
+ tracker.save!
+ tracker
+ end
+
+ def Role.generate!(attributes={})
+ @generated_role_name ||= 'Role 0'
+ @generated_role_name.succ!
+ role = Role.new(attributes)
+ role.name = @generated_role_name if role.name.blank?
+ yield role if block_given?
+ role.save!
+ role
+ end
+
+ def Issue.generate!(attributes={})
+ issue = Issue.new(attributes)
+ issue.subject = 'Generated' if issue.subject.blank?
+ issue.author ||= User.find(2)
+ yield issue if block_given?
+ issue.save!
+ issue
+ end
+
+ def Version.generate!(attributes={})
+ @generated_version_name ||= 'Version 0'
+ @generated_version_name.succ!
+ version = Version.new(attributes)
+ version.name = @generated_version_name if version.name.blank?
+ yield version if block_given?
+ version.save!
+ version
+ end
+
+ def AuthSource.generate!(attributes={})
+ @generated_auth_source_name ||= 'Auth 0'
+ @generated_auth_source_name.succ!
+ source = AuthSource.new(attributes)
+ source.name = @generated_auth_source_name if source.name.blank?
+ yield source if block_given?
+ source.save!
+ source
end
# Generate the default Query
def Query.generate_default!(attributes={})
- query = Query.spawn(attributes)
- query.name ||= '_'
+ query = Query.new(attributes)
+ query.name = '_' if query.name.blank?
query.save!
query
end
# Generate an issue for a project, using it's trackers
def Issue.generate_for_project!(project, attributes={})
- issue = Issue.spawn(attributes) do |issue|
+ issue = Issue.new(attributes) do |issue|
issue.project = project
issue.tracker = project.trackers.first unless project.trackers.empty?
+ issue.subject = 'Generated' if issue.subject.blank?
+ issue.author ||= User.find(2)
yield issue if block_given?
end
issue.save!
issue
end
-
end
context "should allow http basic auth using a username and password for #{http_method} #{url}" do
context "with a valid HTTP authentication" do
setup do
- @user = User.generate_with_protected!(:password => 'my_password', :password_confirmation => 'my_password', :admin => true) # Admin so they can access the project
+ @user = User.generate! do |user|
+ user.admin = true
+ user.password = 'my_password'
+ end
send(http_method, url, parameters, credentials(@user.login, 'my_password'))
end
context "with an invalid HTTP authentication" do
setup do
- @user = User.generate_with_protected!
+ @user = User.generate!
send(http_method, url, parameters, credentials(@user.login, 'wrong_password'))
end
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
setup do
- @user = User.generate_with_protected!(:admin => true)
- @token = Token.generate!(:user => @user, :action => 'api')
+ @user = User.generate! do |user|
+ user.admin = true
+ end
+ @token = Token.create!(:user => @user, :action => 'api')
send(http_method, url, parameters, credentials(@token.value, 'X'))
end
context "with an invalid HTTP authentication" do
setup do
- @user = User.generate_with_protected!
- @token = Token.generate!(:user => @user, :action => 'feeds')
+ @user = User.generate!
+ @token = Token.create!(:user => @user, :action => 'feeds')
send(http_method, url, parameters, credentials(@token.value, 'X'))
end
context "should allow key based auth using key=X for #{http_method} #{url}" do
context "with a valid api token" do
setup do
- @user = User.generate_with_protected!(:admin => true)
- @token = Token.generate!(:user => @user, :action => 'api')
+ @user = User.generate! do |user|
+ user.admin = true
+ end
+ @token = Token.create!(:user => @user, :action => 'api')
# Simple url parse to add on ?key= or &key=
request_url = if url.match(/\?/)
url + "&key=#{@token.value}"
context "with an invalid api token" do
setup do
- @user = User.generate_with_protected!
- @token = Token.generate!(:user => @user, :action => 'feeds')
+ @user = User.generate! do |user|
+ user.admin = true
+ end
+ @token = Token.create!(:user => @user, :action => 'feeds')
# Simple url parse to add on ?key= or &key=
request_url = if url.match(/\?/)
url + "&key=#{@token.value}"
context "should allow key based auth using X-Redmine-API-Key header for #{http_method} #{url}" do
setup do
- @user = User.generate_with_protected!(:admin => true)
- @token = Token.generate!(:user => @user, :action => 'api')
+ @user = User.generate! do |user|
+ user.admin = true
+ end
+ @token = Token.create!(:user => @user, :action => 'api')
send(http_method, url, parameters, {'X-Redmine-API-Key' => @token.value.to_s})
end
tracker = Tracker.find(1)
user = User.find(2)
- issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1)
+ issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author_id => 1)
assert_equal [1, 2], issue.new_statuses_allowed_to(user).map(&:id)
issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user)
assert_equal [1, 2, 3, 5], issue.new_statuses_allowed_to(user).map(&:id)
- issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :assigned_to => user)
+ issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author_id => 1, :assigned_to => user)
assert_equal [1, 2, 4, 5], issue.new_statuses_allowed_to(user).map(&:id)
issue = Issue.generate!(:tracker => tracker, :status => status, :project_id => 1, :author => user, :assigned_to => user)
def test_password_should_be_encrypted
Redmine::Configuration.with 'database_cipher_key' => 'secret' do
- r = Repository::Subversion.generate!(:password => 'foo')
+ r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn')
assert_equal 'foo', r.password
assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/)
end
def test_password_should_be_clear_with_blank_key
Redmine::Configuration.with 'database_cipher_key' => '' do
- r = Repository::Subversion.generate!(:password => 'foo')
+ r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn')
assert_equal 'foo', r.password
assert_equal 'foo', r.read_attribute(:password)
end
def test_password_should_be_clear_with_nil_key
Redmine::Configuration.with 'database_cipher_key' => nil do
- r = Repository::Subversion.generate!(:password => 'foo')
+ r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn')
assert_equal 'foo', r.password
assert_equal 'foo', r.read_attribute(:password)
end
def test_blank_password_should_be_clear
Redmine::Configuration.with 'database_cipher_key' => 'secret' do
- r = Repository::Subversion.generate!(:password => '')
+ r = Repository::Subversion.create!(:password => '', :url => 'file:///tmp', :identifier => 'svn')
assert_equal '', r.password
assert_equal '', r.read_attribute(:password)
end
def test_unciphered_password_should_be_readable
Redmine::Configuration.with 'database_cipher_key' => nil do
- r = Repository::Subversion.generate!(:password => 'clear')
+ r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn')
end
Redmine::Configuration.with 'database_cipher_key' => 'secret' do
def test_ciphered_password_with_no_cipher_key_configured_should_be_returned_ciphered
Redmine::Configuration.with 'database_cipher_key' => 'secret' do
- r = Repository::Subversion.generate!(:password => 'clear')
+ r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn')
end
Redmine::Configuration.with 'database_cipher_key' => '' do
def test_encrypt_all
Repository.delete_all
Redmine::Configuration.with 'database_cipher_key' => nil do
- Repository::Subversion.generate!(:password => 'foo')
- Repository::Subversion.generate!(:password => 'bar')
+ Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'foo')
+ Repository::Subversion.create!(:password => 'bar', :url => 'file:///tmp', :identifier => 'bar')
end
Redmine::Configuration.with 'database_cipher_key' => 'secret' do
def test_decrypt_all
Repository.delete_all
Redmine::Configuration.with 'database_cipher_key' => 'secret' do
- Repository::Subversion.generate!(:password => 'foo')
- Repository::Subversion.generate!(:password => 'bar')
+ Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'foo')
+ Repository::Subversion.create!(:password => 'bar', :url => 'file:///tmp', :identifier => 'bar')
assert Repository.decrypt_all(:password)
r = Repository.first(:order => 'id DESC')
context "assigned to a shared version of another project" do
setup do
p = Project.generate!
- p.trackers << @tracker
p.enabled_module_names = [:issue_tracking]
@shared_version = Version.generate!(:sharing => 'system')
p.versions << @shared_version
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 = TimeEntryActivity.create!(:name => "Project", :project => project, :parent => system_activity, :active => false)
assert overridden_activity.save!
assert !project.activities.include?(overridden_activity), "Inactive Project specific Activity not found"
:tracker_id => 1,
:assigned_to_id => 2,
:project_id => @source_project.id)
- source_relation = IssueRelation.generate!(:issue_from => Issue.find(4),
+ source_relation = IssueRelation.create!(:issue_from => Issue.find(4),
:issue_to => second_issue,
:relation_type => "relates")
- source_relation_cross_project = IssueRelation.generate!(:issue_from => Issue.find(1),
+ source_relation_cross_project = IssueRelation.create!(:issue_from => Issue.find(1),
:issue_to => second_issue,
:relation_type => "duplicates")
@role = Role.generate!
@user_with_membership_notification = User.generate!(:mail_notification => 'selected')
- Member.generate!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true)
+ Member.create!(:project => @project, :roles => [@role], :principal => @user_with_membership_notification, :mail_notification => true)
@all_events_user = User.generate!(:mail_notification => 'all')
- Member.generate!(:project => @project, :roles => [@role], :principal => @all_events_user)
+ Member.create!(:project => @project, :roles => [@role], :principal => @all_events_user)
@no_events_user = User.generate!(:mail_notification => 'none')
- Member.generate!(:project => @project, :roles => [@role], :principal => @no_events_user)
+ Member.create!(:project => @project, :roles => [@role], :principal => @no_events_user)
@only_my_events_user = User.generate!(:mail_notification => 'only_my_events')
- Member.generate!(:project => @project, :roles => [@role], :principal => @only_my_events_user)
+ Member.create!(:project => @project, :roles => [@role], :principal => @only_my_events_user)
@only_assigned_user = User.generate!(:mail_notification => 'only_assigned')
- Member.generate!(:project => @project, :roles => [@role], :principal => @only_assigned_user)
+ Member.create!(:project => @project, :roles => [@role], :principal => @only_assigned_user)
@only_owned_user = User.generate!(:mail_notification => 'only_owner')
- Member.generate!(:project => @project, :roles => [@role], :principal => @only_owned_user)
+ Member.create!(:project => @project, :roles => [@role], :principal => @only_owned_user)
end
should "include members with a mail notification" do
end
def test_issue_count_with_archived_issues
- p = Project.generate!( :status => Project::STATUS_ARCHIVED )
+ p = Project.generate! do |project|
+ project.status = Project::STATUS_ARCHIVED
+ end
i = Issue.generate!( :project => p, :tracker => p.trackers.first )
assert !i.visible?
+++ /dev/null
-# Redmine - project management software
-# Copyright (C) 2006-2011 Jean-Philippe Lang
-#
-# 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.
-
-require File.expand_path('../../test_helper', __FILE__)
-
-# Test case that checks that the testing infrastructure is setup correctly.
-class TestingTest < ActiveSupport::TestCase
- def test_working
- assert true
- end
-
- test "Rails 'test' case syntax" do
- assert true
- end
-
- test "Generating with object_daddy" do
- assert_difference "IssueStatus.count" do
- IssueStatus.generate!
- end
- end
-
- should "work with shoulda" do
- assert true
- end
-
- context "works with a context" do
- should "work" do
- assert true
- end
- end
-
-end
def test_destroy_should_nullify_changesets
changeset = Changeset.create!(
- :repository => Repository::Subversion.generate!(
- :project_id => 1
+ :repository => Repository::Subversion.create!(
+ :project_id => 1,
+ :url => 'file:///tmp',
+ :identifier => 'tmp'
),
:revision => '12',
:committed_on => Time.now,
end
should "select the exact matching user first" do
- case_sensitive_user = User.generate_with_protected!(
- :login => 'changed', :password => 'admin',
- :password_confirmation => 'admin')
+ case_sensitive_user = User.generate! do |user|
+ user.password = "admin"
+ end
# bypass validations to make it appear like existing data
case_sensitive_user.update_attribute(:login, 'ADMIN')
should "return the existing api token value" do
user = User.generate_with_protected!
- token = Token.generate!(:action => 'api')
+ token = Token.create!(:action => 'api')
user.api_token = token
assert user.save
should "return nil if the key is found for an inactive user" do
user = User.generate_with_protected!(:status => User::STATUS_LOCKED)
- token = Token.generate!(:action => 'api')
+ token = Token.create!(:action => 'api')
user.api_token = token
user.save
should "return the user if the key is found for an active user" do
user = User.generate_with_protected!(:status => User::STATUS_ACTIVE)
- token = Token.generate!(:action => 'api')
+ token = Token.create!(:action => 'api')
user.api_token = token
user.save
end
def test_own_account_deletable_should_be_true_for_an_admin_if_other_admin_exists
- User.generate_with_protected(:admin => true)
+ User.generate! do |user|
+ user.admin = true
+ end
with_settings :unsubscribe => '1' do
assert_equal true, User.find(1).own_account_deletable?