]> source.dussan.org Git - redmine.git/commitdiff
Configured object_daddy to help generate test data instead of fixtures. #4004
authorEric Davis <edavis@littlestreamsoftware.com>
Sun, 18 Oct 2009 22:25:00 +0000 (22:25 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Sun, 18 Oct 2009 22:25:00 +0000 (22:25 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2930 e93f8b46-1217-0410-a6f0-8f06a7374b81

14 files changed:
config/environments/test.rb
test/exemplars/custom_field_exemplar.rb [new file with mode: 0644]
test/exemplars/custom_value_exemplar.rb [new file with mode: 0644]
test/exemplars/enumeration_exemplar.rb [new file with mode: 0644]
test/exemplars/issue_exemplar.rb [new file with mode: 0644]
test/exemplars/issue_status_exemplar.rb [new file with mode: 0644]
test/exemplars/member_exemplar.rb [new file with mode: 0644]
test/exemplars/project_exemplar.rb [new file with mode: 0644]
test/exemplars/role_exemplar.rb [new file with mode: 0644]
test/exemplars/time_entry_activity.rb [new file with mode: 0644]
test/exemplars/time_entry_exemplar.rb [new file with mode: 0644]
test/exemplars/tracker_exemplar.rb [new file with mode: 0644]
test/exemplars/user_exemplar.rb [new file with mode: 0644]
test/unit/testing_test.rb

index 2d2f7671364145f26555df1ef3ca2c706ae3569f..efaf9a9fb3ad4ec2df173f24810735fa3adf5ead 100644 (file)
@@ -22,3 +22,4 @@ config.action_controller.session = {
 }
 
 config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"
+config.gem "nofxx-object_daddy", :lib => "object_daddy", :source => "http://gems.github.com"
diff --git a/test/exemplars/custom_field_exemplar.rb b/test/exemplars/custom_field_exemplar.rb
new file mode 100644 (file)
index 0000000..b9577bb
--- /dev/null
@@ -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
diff --git a/test/exemplars/custom_value_exemplar.rb b/test/exemplars/custom_value_exemplar.rb
new file mode 100644 (file)
index 0000000..4e98261
--- /dev/null
@@ -0,0 +1,2 @@
+class CustomValue < ActiveRecord::Base
+end
diff --git a/test/exemplars/enumeration_exemplar.rb b/test/exemplars/enumeration_exemplar.rb
new file mode 100644 (file)
index 0000000..6665a6d
--- /dev/null
@@ -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
diff --git a/test/exemplars/issue_exemplar.rb b/test/exemplars/issue_exemplar.rb
new file mode 100644 (file)
index 0000000..48a92ee
--- /dev/null
@@ -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
diff --git a/test/exemplars/issue_status_exemplar.rb b/test/exemplars/issue_status_exemplar.rb
new file mode 100644 (file)
index 0000000..9d3ccdc
--- /dev/null
@@ -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
diff --git a/test/exemplars/member_exemplar.rb b/test/exemplars/member_exemplar.rb
new file mode 100644 (file)
index 0000000..999bd44
--- /dev/null
@@ -0,0 +1,2 @@
+class Member < ActiveRecord::Base
+end
diff --git a/test/exemplars/project_exemplar.rb b/test/exemplars/project_exemplar.rb
new file mode 100644 (file)
index 0000000..a0edd1f
--- /dev/null
@@ -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
diff --git a/test/exemplars/role_exemplar.rb b/test/exemplars/role_exemplar.rb
new file mode 100644 (file)
index 0000000..9f17e13
--- /dev/null
@@ -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
diff --git a/test/exemplars/time_entry_activity.rb b/test/exemplars/time_entry_activity.rb
new file mode 100644 (file)
index 0000000..8473c2f
--- /dev/null
@@ -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
diff --git a/test/exemplars/time_entry_exemplar.rb b/test/exemplars/time_entry_exemplar.rb
new file mode 100644 (file)
index 0000000..5aa4179
--- /dev/null
@@ -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
diff --git a/test/exemplars/tracker_exemplar.rb b/test/exemplars/tracker_exemplar.rb
new file mode 100644 (file)
index 0000000..94523f7
--- /dev/null
@@ -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
diff --git a/test/exemplars/user_exemplar.rb b/test/exemplars/user_exemplar.rb
new file mode 100644 (file)
index 0000000..d88f5fe
--- /dev/null
@@ -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
index 82eb9ed56ab6f18fbaf156b4e3be03b178ce8eb3..7c78288e54fa1fa3f9b90e3578f7186f8c1091fa 100644 (file)
@@ -27,6 +27,12 @@ class TestingTest < ActiveSupport::TestCase
     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