]> source.dussan.org Git - redmine.git/commitdiff
Merged the Object Daddy exemplars from trunk. r3337, r3340, r3342
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 2 Feb 2010 16:03:05 +0000 (16:03 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Tue, 2 Feb 2010 16:03:05 +0000 (16:03 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/0.9-stable@3359 e93f8b46-1217-0410-a6f0-8f06a7374b81

25 files changed:
test/exemplars/attachment_exemplar.rb [new file with mode: 0644]
test/exemplars/auth_source_exemplar.rb [new file with mode: 0644]
test/exemplars/board_exemplar.rb [new file with mode: 0644]
test/exemplars/change_exemplar.rb [new file with mode: 0644]
test/exemplars/changeset_exemplar.rb [new file with mode: 0644]
test/exemplars/comment_exemplar.rb [new file with mode: 0644]
test/exemplars/custom_value_exemplar.rb
test/exemplars/document_exemplar.rb [new file with mode: 0644]
test/exemplars/enabled_module_exemplar.rb [new file with mode: 0644]
test/exemplars/group_exemplar.rb [new file with mode: 0644]
test/exemplars/issue_category_exemplar.rb [new file with mode: 0644]
test/exemplars/journal_exemplar.rb [new file with mode: 0644]
test/exemplars/member_exemplar.rb
test/exemplars/member_role_exemplar.rb [new file with mode: 0644]
test/exemplars/message_exemplar.rb [new file with mode: 0644]
test/exemplars/news_exemplar.rb [new file with mode: 0644]
test/exemplars/repository_exemplar.rb [new file with mode: 0644]
test/exemplars/subversion_repository_exemplar.rb [new file with mode: 0644]
test/exemplars/time_entry_exemplar.rb
test/exemplars/watcher_exemplar.rb [new file with mode: 0644]
test/exemplars/wiki_content_exemplar.rb [new file with mode: 0644]
test/exemplars/wiki_exemplar.rb [new file with mode: 0644]
test/exemplars/wiki_page_exemplar.rb [new file with mode: 0644]
test/exemplars/wiki_redirect_exemplar.rb [new file with mode: 0644]
test/object_daddy_helpers.rb

diff --git a/test/exemplars/attachment_exemplar.rb b/test/exemplars/attachment_exemplar.rb
new file mode 100644 (file)
index 0000000..e86c4d3
--- /dev/null
@@ -0,0 +1,21 @@
+class Attachment < ActiveRecord::Base
+  generator_for :container, :method => :generate_project
+  generator_for :file, :method => :generate_file
+  generator_for :author, :method => :generate_author
+
+  def self.generate_project
+    Project.generate!
+  end
+
+  def self.generate_author
+    User.generate_with_protected!
+  end
+
+  def self.generate_file
+    @file = 'a_file.png'
+    @file.stubs(:original_filename).returns('a_file.png')
+    @file.stubs(:content_type).returns('image/png')
+    @file.stubs(:read).returns(false)
+    @file
+  end
+end
diff --git a/test/exemplars/auth_source_exemplar.rb b/test/exemplars/auth_source_exemplar.rb
new file mode 100644 (file)
index 0000000..da277e2
--- /dev/null
@@ -0,0 +1,9 @@
+class AuthSource < ActiveRecord::Base
+  generator_for :name, :method => :next_name
+
+  def self.next_name
+    @last_name ||= 'Auth0'
+    @last_name.succ!
+    @last_name
+  end
+end
diff --git a/test/exemplars/board_exemplar.rb b/test/exemplars/board_exemplar.rb
new file mode 100644 (file)
index 0000000..264ea81
--- /dev/null
@@ -0,0 +1,21 @@
+class Board < ActiveRecord::Base
+  generator_for :name, :method => :next_name
+  generator_for :description, :method => :next_description
+  generator_for :project, :method => :generate_project
+
+  def self.next_name
+    @last_name ||= 'A Forum'
+    @last_name.succ!
+    @last_name
+  end
+
+  def self.next_description
+    @last_description ||= 'Some description here'
+    @last_description.succ!
+    @last_description
+  end
+
+  def self.generate_project
+    Project.generate!
+  end
+end
diff --git a/test/exemplars/change_exemplar.rb b/test/exemplars/change_exemplar.rb
new file mode 100644 (file)
index 0000000..97985fb
--- /dev/null
@@ -0,0 +1,15 @@
+class Change < ActiveRecord::Base
+  generator_for :action => 'A'
+  generator_for :path, :method => :next_path
+  generator_for :changeset, :method => :generate_changeset
+
+  def self.next_path
+    @last_path ||= 'test/dir/aaa0001'
+    @last_path.succ!
+    @last_path
+  end
+
+  def self.generate_changeset
+    Changeset.generate!
+  end
+end
diff --git a/test/exemplars/changeset_exemplar.rb b/test/exemplars/changeset_exemplar.rb
new file mode 100644 (file)
index 0000000..a149977
--- /dev/null
@@ -0,0 +1,15 @@
+class Changeset < ActiveRecord::Base
+  generator_for :revision, :method => :next_revision
+  generator_for :committed_on => Date.today
+  generator_for :repository, :method => :generate_repository
+
+  def self.next_revision
+    @last_revision ||= '1'
+    @last_revision.succ!
+    @last_revision
+  end
+
+  def self.generate_repository
+    Repository::Subversion.generate!
+  end
+end
diff --git a/test/exemplars/comment_exemplar.rb b/test/exemplars/comment_exemplar.rb
new file mode 100644 (file)
index 0000000..036e827
--- /dev/null
@@ -0,0 +1,13 @@
+class Comment < ActiveRecord::Base
+  generator_for :commented, :method => :generate_news
+  generator_for :author, :method => :generate_author
+  generator_for :comments => 'What great news this is.'
+
+  def self.generate_news
+    News.generate!
+  end
+
+  def self.generate_author
+    User.generate_with_protected!
+  end
+end
index 4e982614eeafab8a19ca58fc8c18587b5452262e..aeb5412e15e3a54c8bb3f3736bbbd8051d92b48b 100644 (file)
@@ -1,2 +1,7 @@
 class CustomValue < ActiveRecord::Base
+  generator_for :custom_field, :method => :generate_custom_field
+
+  def self.generate_custom_field
+    CustomField.generate!
+  end
 end
diff --git a/test/exemplars/document_exemplar.rb b/test/exemplars/document_exemplar.rb
new file mode 100644 (file)
index 0000000..ae9a4a2
--- /dev/null
@@ -0,0 +1,9 @@
+class Document < ActiveRecord::Base
+  generator_for :title, :method => :next_title
+
+  def self.next_title
+    @last_title ||= 'Document001'
+    @last_title.succ!
+    @last_title
+  end
+end
diff --git a/test/exemplars/enabled_module_exemplar.rb b/test/exemplars/enabled_module_exemplar.rb
new file mode 100644 (file)
index 0000000..85a38b5
--- /dev/null
@@ -0,0 +1,10 @@
+class EnabledModule < ActiveRecord::Base
+  generator_for :name, :method => :next_name
+
+  def self.next_name
+    @last_name ||= 'module_001'
+    @last_name.succ!
+    @last_name
+  end
+
+end
diff --git a/test/exemplars/group_exemplar.rb b/test/exemplars/group_exemplar.rb
new file mode 100644 (file)
index 0000000..5d2cd74
--- /dev/null
@@ -0,0 +1,10 @@
+class Group < Principal
+  generator_for :lastname, :method => :next_lastname
+
+  def self.next_lastname
+    @last_lastname ||= 'Group'
+    @last_lastname.succ!
+    @last_lastname
+  end
+
+end
diff --git a/test/exemplars/issue_category_exemplar.rb b/test/exemplars/issue_category_exemplar.rb
new file mode 100644 (file)
index 0000000..318947c
--- /dev/null
@@ -0,0 +1,9 @@
+class IssueCategory < ActiveRecord::Base
+  generator_for :name, :method => :next_name
+  
+  def self.next_name
+    @last_name ||= 'Category 0001'
+    @last_name.succ!
+    @last_name
+  end
+end
diff --git a/test/exemplars/journal_exemplar.rb b/test/exemplars/journal_exemplar.rb
new file mode 100644 (file)
index 0000000..dbb66f2
--- /dev/null
@@ -0,0 +1,13 @@
+class Journal < ActiveRecord::Base
+  generator_for :journalized, :method => :generate_issue
+  generator_for :user, :method => :generate_user
+
+  def self.generate_issue
+    project = Project.generate!
+    Issue.generate_for_project!(project)
+  end
+
+  def self.generate_user
+    User.generate_with_protected!
+  end
+end
index 999bd448721317836b39c0dba870482f280bd6ee..ecb09bb91925c221c933b24f211bf8669d02e510 100644 (file)
@@ -1,2 +1,12 @@
 class Member < ActiveRecord::Base
+  generator_for :roles, :method => :generate_roles
+  generator_for :principal, :method => :generate_user
+
+  def self.generate_roles
+    [Role.generate!]
+  end
+
+  def self.generate_user
+    User.generate_with_protected!
+  end
 end
diff --git a/test/exemplars/member_role_exemplar.rb b/test/exemplars/member_role_exemplar.rb
new file mode 100644 (file)
index 0000000..0e1e6e7
--- /dev/null
@@ -0,0 +1,12 @@
+class MemberRole < ActiveRecord::Base
+  generator_for :member, :method => :generate_member
+  generator_for :role, :method => :generate_role
+
+  def self.generate_role
+    Role.generate!
+  end
+
+  def self.generate_member
+    Member.generate!
+  end
+end
diff --git a/test/exemplars/message_exemplar.rb b/test/exemplars/message_exemplar.rb
new file mode 100644 (file)
index 0000000..0a310fc
--- /dev/null
@@ -0,0 +1,21 @@
+class Message < ActiveRecord::Base
+  generator_for :subject, :method => :next_subject
+  generator_for :content, :method => :next_content
+  generator_for :board, :method => :generate_board
+
+  def self.next_subject
+    @last_subject ||= 'A Message'
+    @last_subject.succ!
+    @last_subject
+  end
+
+  def self.next_content
+    @last_content ||= 'Some content here'
+    @last_content.succ!
+    @last_content
+  end
+
+  def self.generate_board
+    Board.generate!
+  end
+end
diff --git a/test/exemplars/news_exemplar.rb b/test/exemplars/news_exemplar.rb
new file mode 100644 (file)
index 0000000..c7e22c5
--- /dev/null
@@ -0,0 +1,16 @@
+class News < ActiveRecord::Base
+  generator_for :title, :method => :next_title
+  generator_for :description, :method => :next_description
+
+  def self.next_title
+    @last_title ||= 'A New Item'
+    @last_title.succ!
+    @last_title
+  end
+
+  def self.next_description
+    @last_description ||= 'Some content here'
+    @last_description.succ!
+    @last_description
+  end
+end
diff --git a/test/exemplars/repository_exemplar.rb b/test/exemplars/repository_exemplar.rb
new file mode 100644 (file)
index 0000000..42d11fc
--- /dev/null
@@ -0,0 +1,11 @@
+class Repository < ActiveRecord::Base
+  generator_for :type => 'Subversion'
+  generator_for :url, :method => :next_url
+
+  def self.next_url
+    @last_url ||= 'file:///test/svn'
+    @last_url.succ!
+    @last_url
+  end
+
+end
diff --git a/test/exemplars/subversion_repository_exemplar.rb b/test/exemplars/subversion_repository_exemplar.rb
new file mode 100644 (file)
index 0000000..2d48cb2
--- /dev/null
@@ -0,0 +1,11 @@
+class Repository::Subversion < Repository
+  generator_for :type, :method => 'Subversion'
+  generator_for :url, :method => :next_url
+
+  def self.next_url
+    @last_url ||= 'file:///test/svn'
+    @last_url.succ!
+    @last_url
+  end
+
+end
index 5aa4179f3bb1990e3441a5ab3fdbc33eb3e54afa..b15b9562ded07e95f895d6cc4314dbc17cff8668 100644 (file)
@@ -1,5 +1,10 @@
 class TimeEntry < ActiveRecord::Base
   generator_for(:spent_on) { Date.today }
   generator_for(:hours) { (rand * 10).round(2) } # 0.01 to 9.99
+  generator_for :user, :method => :generate_user
 
+  def self.generate_user
+    User.generate_with_protected!
+  end
+  
 end
diff --git a/test/exemplars/watcher_exemplar.rb b/test/exemplars/watcher_exemplar.rb
new file mode 100644 (file)
index 0000000..4d6c266
--- /dev/null
@@ -0,0 +1,7 @@
+class Watcher < ActiveRecord::Base
+  generator_for :user, :method => :generate_user
+
+  def self.generate_user
+    User.generate_with_protected!
+  end
+end
diff --git a/test/exemplars/wiki_content_exemplar.rb b/test/exemplars/wiki_content_exemplar.rb
new file mode 100644 (file)
index 0000000..79465b0
--- /dev/null
@@ -0,0 +1,8 @@
+class WikiContent < ActiveRecord::Base
+  generator_for :text => 'Some content'
+  generator_for :page, :method => :generate_page
+
+  def self.generate_page
+    WikiPage.generate!
+  end
+end
diff --git a/test/exemplars/wiki_exemplar.rb b/test/exemplars/wiki_exemplar.rb
new file mode 100644 (file)
index 0000000..65b93a2
--- /dev/null
@@ -0,0 +1,8 @@
+class Wiki < ActiveRecord::Base
+  generator_for :start_page => 'Start'
+  generator_for :project, :method => :generate_project
+
+  def self.generate_project
+    Project.generate!
+  end
+end
diff --git a/test/exemplars/wiki_page_exemplar.rb b/test/exemplars/wiki_page_exemplar.rb
new file mode 100644 (file)
index 0000000..d70cc22
--- /dev/null
@@ -0,0 +1,14 @@
+class WikiPage < ActiveRecord::Base
+  generator_for :title, :method => :next_title
+  generator_for :wiki, :method => :generate_wiki
+
+  def self.next_title
+    @last_title ||= 'AWikiPage'
+    @last_title.succ!
+    @last_title
+  end
+
+  def self.generate_wiki
+    Wiki.generate!
+  end
+end
diff --git a/test/exemplars/wiki_redirect_exemplar.rb b/test/exemplars/wiki_redirect_exemplar.rb
new file mode 100644 (file)
index 0000000..0b380ac
--- /dev/null
@@ -0,0 +1,21 @@
+class WikiRedirect < ActiveRecord::Base
+  generator_for :title, :method => :next_title
+  generator_for :redirects_to, :method => :next_redirects_to
+  generator_for :wiki, :method => :generate_wiki
+
+  def self.next_title
+    @last_title ||= 'AWikiPage'
+    @last_title.succ!
+    @last_title
+  end
+
+  def self.next_redirects_to
+    @last_redirect ||= '/a/path/000001'
+    @last_redirect.succ!
+    @last_redirect
+  end
+
+  def self.generate_wiki
+    Wiki.generate!
+  end
+end
index a05e55f83857c5071d7501cc0cfdbb4d28665c56..ce6e00bd7d6215ff9dccce20f91a32ad4dcf8feb 100644 (file)
@@ -1,14 +1,29 @@
 module ObjectDaddyHelpers
+  # TODO: The gem or official version of ObjectDaddy doesn't set
+  # protected attributes so they need to be wrapped.
+  def User.generate_with_protected(attributes={})
+    user = User.spawn_with_protected(attributes)
+    user.save
+    user
+  end
+
   # TODO: The gem or official version of ObjectDaddy doesn't set
   # protected attributes so they need to be wrapped.
   def User.generate_with_protected!(attributes={})
+    user = User.spawn_with_protected(attributes)
+    user.save!
+    user
+  end
+
+  # TODO: The gem or official version of ObjectDaddy doesn't set
+  # protected attributes so they need to be wrapped.
+  def User.spawn_with_protected(attributes={})
     user = User.spawn(attributes) do |user|
       user.login = User.next_login
       attributes.each do |attr,v|
         user.send("#{attr}=", v)
       end
     end
-    user.save!
     user
   end