##// END OF EJS Templates
Updated some object_daddy exemplars for the Models....
Eric Davis -
r2823:6456f7c4a481
parent child
Show More
@@ -0,0 +1,9
1 class Query < ActiveRecord::Base
2 generator_for :name, :method => :next_name
3
4 def self.next_name
5 @last_name ||= 'Query 0'
6 @last_name.succ!
7 @last_name
8 end
9 end
@@ -1,17 +1,31
1 1 class Project < ActiveRecord::Base
2 2 generator_for :name, :method => :next_name
3 3 generator_for :identifier, :method => :next_identifier_from_object_daddy
4 generator_for :enabled_modules, :method => :all_modules
5 generator_for :trackers, :method => :next_tracker
4 6
5 7 def self.next_name
6 8 @last_name ||= 'Project 0'
7 9 @last_name.succ!
8 10 @last_name
9 11 end
10 12
11 13 # Project#next_identifier is defined on Redmine
12 14 def self.next_identifier_from_object_daddy
13 15 @last_identifier ||= 'project0'
14 16 @last_identifier.succ!
15 17 @last_identifier
16 18 end
19
20 def self.all_modules
21 returning [] do |modules|
22 Redmine::AccessControl.available_project_modules.each do |name|
23 modules << EnabledModule.new(:name => name.to_s)
24 end
25 end
26 end
27
28 def self.next_tracker
29 [Tracker.generate!]
30 end
17 31 end
@@ -1,87 +1,105
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 ENV["RAILS_ENV"] ||= "test"
19 19 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
20 20 require 'test_help'
21 21 require File.expand_path(File.dirname(__FILE__) + '/helper_testcase')
22 22 require File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb')
23 23
24 24 # TODO: The gem or official version of ObjectDaddy doesn't set
25 25 # protected attributes so they need to be wrapped.
26 26 def User.generate_with_protected!(attributes={})
27 27 user = User.spawn(attributes) do |user|
28 28 user.login = User.next_login
29 29 attributes.each do |attr,v|
30 30 user.send("#{attr}=", v)
31 31 end
32 32 end
33 33 user.save!
34 34 user
35 35 end
36 36
37 # Generate the default Query
38 def Query.generate_default!(attributes={})
39 query = Query.spawn(attributes)
40 query.name ||= '_'
41 query.save!
42 query
43 end
44
45 # Generate an issue for a project, using it's trackers
46 def Issue.generate_for_project!(project, attributes={})
47 issue = Issue.spawn(attributes) do |issue|
48 issue.project = project
49 end
50 issue.tracker = project.trackers.first unless project.trackers.empty?
51 issue.save!
52 issue
53 end
54
37 55 class ActiveSupport::TestCase
38 56 # Transactional fixtures accelerate your tests by wrapping each test method
39 57 # in a transaction that's rolled back on completion. This ensures that the
40 58 # test database remains unchanged so your fixtures don't have to be reloaded
41 59 # between every test method. Fewer database queries means faster tests.
42 60 #
43 61 # Read Mike Clark's excellent walkthrough at
44 62 # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
45 63 #
46 64 # Every Active Record database supports transactions except MyISAM tables
47 65 # in MySQL. Turn off transactional fixtures in this case; however, if you
48 66 # don't care one way or the other, switching from MyISAM to InnoDB tables
49 67 # is recommended.
50 68 self.use_transactional_fixtures = true
51 69
52 70 # Instantiated fixtures are slow, but give you @david where otherwise you
53 71 # would need people(:david). If you don't want to migrate your existing
54 72 # test cases which use the @david style and don't mind the speed hit (each
55 73 # instantiated fixtures translates to a database query per test method),
56 74 # then set this back to true.
57 75 self.use_instantiated_fixtures = false
58 76
59 77 # Add more helper methods to be used by all tests here...
60 78
61 79 def log_user(login, password)
62 80 get "/login"
63 81 assert_equal nil, session[:user_id]
64 82 assert_response :success
65 83 assert_template "account/login"
66 84 post "/login", :username => login, :password => password
67 85 assert_equal login, User.find(session[:user_id]).login
68 86 end
69 87
70 88 def uploaded_test_file(name, mime)
71 89 ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime)
72 90 end
73 91
74 92 # Use a temporary directory for attachment related tests
75 93 def set_tmp_attachments_directory
76 94 Dir.mkdir "#{RAILS_ROOT}/tmp/test" unless File.directory?("#{RAILS_ROOT}/tmp/test")
77 95 Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments")
78 96 Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments"
79 97 end
80 98
81 99 def with_settings(options, &block)
82 100 saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h}
83 101 options.each {|k, v| Setting[k] = v}
84 102 yield
85 103 saved_settings.each {|k, v| Setting[k] = v}
86 104 end
87 105 end
General Comments 0
You need to be logged in to leave comments. Login now