Updated some object_daddy exemplars for the Models.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2937 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2009-10-20 00:36:51 +00:00
parent 61c09b6442
commit 6456f7c4a4
3 changed files with 42 additions and 1 deletions

View File

@ -1,7 +1,9 @@
class Project < ActiveRecord::Base
generator_for :name, :method => :next_name
generator_for :identifier, :method => :next_identifier_from_object_daddy
generator_for :enabled_modules, :method => :all_modules
generator_for :trackers, :method => :next_tracker
def self.next_name
@last_name ||= 'Project 0'
@last_name.succ!
@ -14,4 +16,16 @@ class Project < ActiveRecord::Base
@last_identifier.succ!
@last_identifier
end
def self.all_modules
returning [] do |modules|
Redmine::AccessControl.available_project_modules.each do |name|
modules << EnabledModule.new(:name => name.to_s)
end
end
end
def self.next_tracker
[Tracker.generate!]
end
end

View File

@ -0,0 +1,9 @@
class Query < ActiveRecord::Base
generator_for :name, :method => :next_name
def self.next_name
@last_name ||= 'Query 0'
@last_name.succ!
@last_name
end
end

View File

@ -34,6 +34,24 @@ def User.generate_with_protected!(attributes={})
user
end
# Generate the default Query
def Query.generate_default!(attributes={})
query = Query.spawn(attributes)
query.name ||= '_'
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.project = project
end
issue.tracker = project.trackers.first unless project.trackers.empty?
issue.save!
issue
end
class ActiveSupport::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the