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