diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-22 11:58:05 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-04-22 11:58:05 +0000 |
commit | 95f9246a46de372980a80582d72d46d4e618b3b3 (patch) | |
tree | 6d5ea589c8e7a6c55417f6c13908bd1ba4267524 /test/object_helpers.rb | |
parent | b960470d7817843906d42628d8bb4228ee49b2d9 (diff) | |
download | redmine-95f9246a46de372980a80582d72d46d4e618b3b3.tar.gz redmine-95f9246a46de372980a80582d72d46d4e618b3b3.zip |
Renamed object_daddy_helper and removed exemplars.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9470 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/object_helpers.rb')
-rw-r--r-- | test/object_helpers.rb | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/test/object_helpers.rb b/test/object_helpers.rb new file mode 100644 index 000000000..3cd5e5cd6 --- /dev/null +++ b/test/object_helpers.rb @@ -0,0 +1,124 @@ +module ObjectHelpers + # 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.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.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.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 |