Configured object_daddy to help generate test data instead of fixtures. #4004
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2930 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ee9c2d3d88
commit
35333367df
|
@ -22,3 +22,4 @@ config.action_controller.session = {
|
||||||
}
|
}
|
||||||
|
|
||||||
config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"
|
config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"
|
||||||
|
config.gem "nofxx-object_daddy", :lib => "object_daddy", :source => "http://gems.github.com"
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
class CustomField < ActiveRecord::Base
|
||||||
|
generator_for :name, :method => :next_name
|
||||||
|
generator_for :field_format => 'string'
|
||||||
|
|
||||||
|
def self.next_name
|
||||||
|
@last_name ||= 'CustomField0'
|
||||||
|
@last_name.succ!
|
||||||
|
@last_name
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
class CustomValue < ActiveRecord::Base
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
class Enumeration < ActiveRecord::Base
|
||||||
|
generator_for :name, :method => :next_name
|
||||||
|
generator_for :type => 'TimeEntryActivity'
|
||||||
|
|
||||||
|
def self.next_name
|
||||||
|
@last_name ||= 'Enumeration0'
|
||||||
|
@last_name.succ!
|
||||||
|
@last_name
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
class Issue < ActiveRecord::Base
|
||||||
|
generator_for :subject, :method => :next_subject
|
||||||
|
generator_for :author, :method => :next_author
|
||||||
|
|
||||||
|
def self.next_subject
|
||||||
|
@last_subject ||= 'Subject 0'
|
||||||
|
@last_subject.succ!
|
||||||
|
@last_subject
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.next_author
|
||||||
|
User.generate_with_protected!
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class IssueStatus < ActiveRecord::Base
|
||||||
|
generator_for :name, :method => :next_name
|
||||||
|
|
||||||
|
def self.next_name
|
||||||
|
@last_name ||= 'Status 0'
|
||||||
|
@last_name.succ!
|
||||||
|
@last_name
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
class Member < ActiveRecord::Base
|
||||||
|
end
|
|
@ -0,0 +1,17 @@
|
||||||
|
class Project < ActiveRecord::Base
|
||||||
|
generator_for :name, :method => :next_name
|
||||||
|
generator_for :identifier, :method => :next_identifier_from_object_daddy
|
||||||
|
|
||||||
|
def self.next_name
|
||||||
|
@last_name ||= 'Project 0'
|
||||||
|
@last_name.succ!
|
||||||
|
@last_name
|
||||||
|
end
|
||||||
|
|
||||||
|
# Project#next_identifier is defined on Redmine
|
||||||
|
def self.next_identifier_from_object_daddy
|
||||||
|
@last_identifier ||= 'project0'
|
||||||
|
@last_identifier.succ!
|
||||||
|
@last_identifier
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
class Role < ActiveRecord::Base
|
||||||
|
generator_for :name, :method => :next_name
|
||||||
|
|
||||||
|
def self.next_name
|
||||||
|
@last_name ||= 'Role0'
|
||||||
|
@last_name.succ!
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
class TimeEntryActivity < Enumeration
|
||||||
|
generator_for :name, :method => :next_name
|
||||||
|
generator_for :type => 'TimeEntryActivity'
|
||||||
|
|
||||||
|
def self.next_name
|
||||||
|
@last_name ||= 'TimeEntryActivity0'
|
||||||
|
@last_name.succ!
|
||||||
|
@last_name
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
class TimeEntry < ActiveRecord::Base
|
||||||
|
generator_for(:spent_on) { Date.today }
|
||||||
|
generator_for(:hours) { (rand * 10).round(2) } # 0.01 to 9.99
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class Tracker < ActiveRecord::Base
|
||||||
|
generator_for :name, :method => :next_name
|
||||||
|
|
||||||
|
def self.next_name
|
||||||
|
@last_name ||= 'Tracker 0'
|
||||||
|
@last_name.succ!
|
||||||
|
@last_name
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,30 @@
|
||||||
|
class User < ActiveRecord::Base
|
||||||
|
generator_for :login, :method => :next_email
|
||||||
|
generator_for :mail, :method => :next_email
|
||||||
|
generator_for :firstname, :method => :next_firstname
|
||||||
|
generator_for :lastname, :method => :next_lastname
|
||||||
|
|
||||||
|
def self.next_login
|
||||||
|
@gen_login ||= 'user1'
|
||||||
|
@gen_login.succ!
|
||||||
|
@gen_login
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.next_email
|
||||||
|
@last_email ||= 'user1'
|
||||||
|
@last_email.succ!
|
||||||
|
"#{@last_email}@example.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.next_firstname
|
||||||
|
@last_firstname ||= 'Bob'
|
||||||
|
@last_firstname.succ!
|
||||||
|
@last_firstname
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.next_lastname
|
||||||
|
@last_lastname ||= 'Doe'
|
||||||
|
@last_lastname.succ!
|
||||||
|
@last_lastname
|
||||||
|
end
|
||||||
|
end
|
|
@ -27,6 +27,12 @@ class TestingTest < ActiveSupport::TestCase
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "Generating with object_daddy" do
|
||||||
|
assert_difference "IssueStatus.count" do
|
||||||
|
IssueStatus.generate!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "work with shoulda" do
|
should "work with shoulda" do
|
||||||
assert true
|
assert true
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue