@@ -0,0 +1,33 | |||
|
1 | module ObjectDaddyHelpers | |
|
2 | # TODO: The gem or official version of ObjectDaddy doesn't set | |
|
3 | # protected attributes so they need to be wrapped. | |
|
4 | def User.generate_with_protected!(attributes={}) | |
|
5 | user = User.spawn(attributes) do |user| | |
|
6 | user.login = User.next_login | |
|
7 | attributes.each do |attr,v| | |
|
8 | user.send("#{attr}=", v) | |
|
9 | end | |
|
10 | end | |
|
11 | user.save! | |
|
12 | user | |
|
13 | end | |
|
14 | ||
|
15 | # Generate the default Query | |
|
16 | def Query.generate_default!(attributes={}) | |
|
17 | query = Query.spawn(attributes) | |
|
18 | query.name ||= '_' | |
|
19 | query.save! | |
|
20 | query | |
|
21 | end | |
|
22 | ||
|
23 | # Generate an issue for a project, using it's trackers | |
|
24 | def Issue.generate_for_project!(project, attributes={}) | |
|
25 | issue = Issue.spawn(attributes) do |issue| | |
|
26 | issue.project = project | |
|
27 | end | |
|
28 | issue.tracker = project.trackers.first unless project.trackers.empty? | |
|
29 | issue.save! | |
|
30 | issue | |
|
31 | end | |
|
32 | ||
|
33 | end |
@@ -1,105 +1,77 | |||
|
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 | # TODO: The gem or official version of ObjectDaddy doesn't set | |
|
25 | # protected attributes so they need to be wrapped. | |
|
26 | def User.generate_with_protected!(attributes={}) | |
|
27 | user = User.spawn(attributes) do |user| | |
|
28 | user.login = User.next_login | |
|
29 | attributes.each do |attr,v| | |
|
30 | user.send("#{attr}=", v) | |
|
31 | end | |
|
32 | end | |
|
33 | user.save! | |
|
34 | user | |
|
35 | end | |
|
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 | |
|
24 | require File.expand_path(File.dirname(__FILE__) + '/object_daddy_helpers') | |
|
25 | include ObjectDaddyHelpers | |
|
54 | 26 | |
|
55 | 27 | class ActiveSupport::TestCase |
|
56 | 28 | # Transactional fixtures accelerate your tests by wrapping each test method |
|
57 | 29 | # in a transaction that's rolled back on completion. This ensures that the |
|
58 | 30 | # test database remains unchanged so your fixtures don't have to be reloaded |
|
59 | 31 | # between every test method. Fewer database queries means faster tests. |
|
60 | 32 | # |
|
61 | 33 | # Read Mike Clark's excellent walkthrough at |
|
62 | 34 | # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting |
|
63 | 35 | # |
|
64 | 36 | # Every Active Record database supports transactions except MyISAM tables |
|
65 | 37 | # in MySQL. Turn off transactional fixtures in this case; however, if you |
|
66 | 38 | # don't care one way or the other, switching from MyISAM to InnoDB tables |
|
67 | 39 | # is recommended. |
|
68 | 40 | self.use_transactional_fixtures = true |
|
69 | 41 | |
|
70 | 42 | # Instantiated fixtures are slow, but give you @david where otherwise you |
|
71 | 43 | # would need people(:david). If you don't want to migrate your existing |
|
72 | 44 | # test cases which use the @david style and don't mind the speed hit (each |
|
73 | 45 | # instantiated fixtures translates to a database query per test method), |
|
74 | 46 | # then set this back to true. |
|
75 | 47 | self.use_instantiated_fixtures = false |
|
76 | 48 | |
|
77 | 49 | # Add more helper methods to be used by all tests here... |
|
78 | 50 | |
|
79 | 51 | def log_user(login, password) |
|
80 | 52 | get "/login" |
|
81 | 53 | assert_equal nil, session[:user_id] |
|
82 | 54 | assert_response :success |
|
83 | 55 | assert_template "account/login" |
|
84 | 56 | post "/login", :username => login, :password => password |
|
85 | 57 | assert_equal login, User.find(session[:user_id]).login |
|
86 | 58 | end |
|
87 | 59 | |
|
88 | 60 | def uploaded_test_file(name, mime) |
|
89 | 61 | ActionController::TestUploadedFile.new(ActiveSupport::TestCase.fixture_path + "/files/#{name}", mime) |
|
90 | 62 | end |
|
91 | 63 | |
|
92 | 64 | # Use a temporary directory for attachment related tests |
|
93 | 65 | def set_tmp_attachments_directory |
|
94 | 66 | Dir.mkdir "#{RAILS_ROOT}/tmp/test" unless File.directory?("#{RAILS_ROOT}/tmp/test") |
|
95 | 67 | Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments") |
|
96 | 68 | Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments" |
|
97 | 69 | end |
|
98 | 70 | |
|
99 | 71 | def with_settings(options, &block) |
|
100 | 72 | saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h} |
|
101 | 73 | options.each {|k, v| Setting[k] = v} |
|
102 | 74 | yield |
|
103 | 75 | saved_settings.each {|k, v| Setting[k] = v} |
|
104 | 76 | end |
|
105 | 77 | end |
General Comments 0
You need to be logged in to leave comments.
Login now