diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2009-10-18 22:25:00 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2009-10-18 22:25:00 +0000 |
commit | 35333367dff6a3415bfc00904ac88d42024217f6 (patch) | |
tree | 1af169d09b9737df103a89d42ac292c0dea5bb10 | |
parent | ee9c2d3d880ecbb1437dfe62c76ca46dd6cba429 (diff) | |
download | redmine-35333367dff6a3415bfc00904ac88d42024217f6.tar.gz redmine-35333367dff6a3415bfc00904ac88d42024217f6.zip |
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
-rw-r--r-- | config/environments/test.rb | 1 | ||||
-rw-r--r-- | test/exemplars/custom_field_exemplar.rb | 10 | ||||
-rw-r--r-- | test/exemplars/custom_value_exemplar.rb | 2 | ||||
-rw-r--r-- | test/exemplars/enumeration_exemplar.rb | 10 | ||||
-rw-r--r-- | test/exemplars/issue_exemplar.rb | 15 | ||||
-rw-r--r-- | test/exemplars/issue_status_exemplar.rb | 9 | ||||
-rw-r--r-- | test/exemplars/member_exemplar.rb | 2 | ||||
-rw-r--r-- | test/exemplars/project_exemplar.rb | 17 | ||||
-rw-r--r-- | test/exemplars/role_exemplar.rb | 8 | ||||
-rw-r--r-- | test/exemplars/time_entry_activity.rb | 10 | ||||
-rw-r--r-- | test/exemplars/time_entry_exemplar.rb | 5 | ||||
-rw-r--r-- | test/exemplars/tracker_exemplar.rb | 9 | ||||
-rw-r--r-- | test/exemplars/user_exemplar.rb | 30 | ||||
-rw-r--r-- | test/unit/testing_test.rb | 6 |
14 files changed, 134 insertions, 0 deletions
diff --git a/config/environments/test.rb b/config/environments/test.rb index 2d2f76713..efaf9a9fb 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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 index 000000000..b9577bb93 --- /dev/null +++ b/test/exemplars/custom_field_exemplar.rb @@ -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 index 000000000..4e982614e --- /dev/null +++ b/test/exemplars/custom_value_exemplar.rb @@ -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 index 000000000..6665a6d5d --- /dev/null +++ b/test/exemplars/enumeration_exemplar.rb @@ -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 index 000000000..48a92ee4a --- /dev/null +++ b/test/exemplars/issue_exemplar.rb @@ -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 index 000000000..9d3ccdc1b --- /dev/null +++ b/test/exemplars/issue_status_exemplar.rb @@ -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 index 000000000..999bd4487 --- /dev/null +++ b/test/exemplars/member_exemplar.rb @@ -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 index 000000000..a0edd1fde --- /dev/null +++ b/test/exemplars/project_exemplar.rb @@ -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 index 000000000..9f17e1382 --- /dev/null +++ b/test/exemplars/role_exemplar.rb @@ -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 index 000000000..8473c2f81 --- /dev/null +++ b/test/exemplars/time_entry_activity.rb @@ -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 index 000000000..5aa4179f3 --- /dev/null +++ b/test/exemplars/time_entry_exemplar.rb @@ -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 index 000000000..94523f79b --- /dev/null +++ b/test/exemplars/tracker_exemplar.rb @@ -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 index 000000000..d88f5fe7d --- /dev/null +++ b/test/exemplars/user_exemplar.rb @@ -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 diff --git a/test/unit/testing_test.rb b/test/unit/testing_test.rb index 82eb9ed56..7c78288e5 100644 --- a/test/unit/testing_test.rb +++ b/test/unit/testing_test.rb @@ -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 |