Commit 499768ff authored by jplang's avatar jplang

Removed object_daddy dependency.

git-svn-id: https://svn.redmine.org/redmine/trunk@9469 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 53efeba0
......@@ -71,7 +71,6 @@ end
group :test do
gem "shoulda", "~> 2.10.3"
gem "edavis10-object_daddy", :require => "object_daddy"
gem "mocha"
end
......
......@@ -15,26 +15,110 @@ module ObjectDaddyHelpers
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
......@@ -243,7 +243,10 @@ class ActiveSupport::TestCase
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
......@@ -256,7 +259,7 @@ class ActiveSupport::TestCase
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
......@@ -297,8 +300,10 @@ class ActiveSupport::TestCase
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
......@@ -312,8 +317,8 @@ class ActiveSupport::TestCase
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
......@@ -341,8 +346,10 @@ class ActiveSupport::TestCase
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}"
......@@ -362,8 +369,10 @@ class ActiveSupport::TestCase
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}"
......@@ -383,8 +392,10 @@ class ActiveSupport::TestCase
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
......
......@@ -373,13 +373,13 @@ class IssueTest < ActiveSupport::TestCase
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)
......
......@@ -21,7 +21,7 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
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
......@@ -29,7 +29,7 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
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
......@@ -37,7 +37,7 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
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
......@@ -45,7 +45,7 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
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
......@@ -53,7 +53,7 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
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
......@@ -64,7 +64,7 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
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
......@@ -79,8 +79,8 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
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
......@@ -94,8 +94,8 @@ class Redmine::CipheringTest < ActiveSupport::TestCase
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')
......
......@@ -160,7 +160,6 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase
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
......
......@@ -742,7 +742,7 @@ class ProjectTest < ActiveSupport::TestCase
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"
......@@ -822,10 +822,10 @@ class ProjectTest < ActiveSupport::TestCase
: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")
......@@ -1104,22 +1104,22 @@ class ProjectTest < ActiveSupport::TestCase
@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
......
......@@ -670,7 +670,9 @@ class QueryTest < ActiveSupport::TestCase
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?
......
# 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
......@@ -337,8 +337,10 @@ class UserTest < ActiveSupport::TestCase
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,
......@@ -378,9 +380,9 @@ class UserTest < ActiveSupport::TestCase
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')
......@@ -628,7 +630,7 @@ class UserTest < ActiveSupport::TestCase
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
......@@ -643,7 +645,7 @@ class UserTest < ActiveSupport::TestCase
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
......@@ -652,7 +654,7 @@ class UserTest < ActiveSupport::TestCase
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
......@@ -823,7 +825,9 @@ class UserTest < ActiveSupport::TestCase
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?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment