##// END OF EJS Templates
Removed unneeded patch in tests....
Jean-Philippe Lang -
r13299:f1308e64af08
parent child
Show More
@@ -1,292 +1,281
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 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 'rails/test_help'
21 21 require Rails.root.join('test', 'mocks', 'open_id_authentication_mock.rb').to_s
22 22
23 23 require File.expand_path(File.dirname(__FILE__) + '/object_helpers')
24 24 include ObjectHelpers
25 25
26 26 require 'awesome_nested_set/version'
27 27 require 'net/ldap'
28 28
29 29 class ActionView::TestCase
30 30 helper :application
31 31 include ApplicationHelper
32 32 end
33 33
34 34 class ActiveSupport::TestCase
35 35 include ActionDispatch::TestProcess
36 36
37 37 self.use_transactional_fixtures = true
38 38 self.use_instantiated_fixtures = false
39 39
40 40 #ESCAPED_CANT = 'can't'
41 41 #ESCAPED_UCANT = 'Can't'
42 42 # Rails 4.0.2
43 43 ESCAPED_CANT = 'can't'
44 44 ESCAPED_UCANT = 'Can't'
45 45
46 46 def uploaded_test_file(name, mime)
47 47 fixture_file_upload("files/#{name}", mime, true)
48 48 end
49 49
50 50 # Mock out a file
51 51 def self.mock_file
52 52 file = 'a_file.png'
53 53 file.stubs(:size).returns(32)
54 54 file.stubs(:original_filename).returns('a_file.png')
55 55 file.stubs(:content_type).returns('image/png')
56 56 file.stubs(:read).returns(false)
57 57 file
58 58 end
59 59
60 60 def mock_file
61 61 self.class.mock_file
62 62 end
63 63
64 64 def mock_file_with_options(options={})
65 65 file = ''
66 66 file.stubs(:size).returns(32)
67 67 original_filename = options[:original_filename] || nil
68 68 file.stubs(:original_filename).returns(original_filename)
69 69 content_type = options[:content_type] || nil
70 70 file.stubs(:content_type).returns(content_type)
71 71 file.stubs(:read).returns(false)
72 72 file
73 73 end
74 74
75 75 # Use a temporary directory for attachment related tests
76 76 def set_tmp_attachments_directory
77 77 Dir.mkdir "#{Rails.root}/tmp/test" unless File.directory?("#{Rails.root}/tmp/test")
78 78 unless File.directory?("#{Rails.root}/tmp/test/attachments")
79 79 Dir.mkdir "#{Rails.root}/tmp/test/attachments"
80 80 end
81 81 Attachment.storage_path = "#{Rails.root}/tmp/test/attachments"
82 82 end
83 83
84 84 def set_fixtures_attachments_directory
85 85 Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
86 86 end
87 87
88 88 def with_settings(options, &block)
89 89 saved_settings = options.keys.inject({}) do |h, k|
90 90 h[k] = case Setting[k]
91 91 when Symbol, false, true, nil
92 92 Setting[k]
93 93 else
94 94 Setting[k].dup
95 95 end
96 96 h
97 97 end
98 98 options.each {|k, v| Setting[k] = v}
99 99 yield
100 100 ensure
101 101 saved_settings.each {|k, v| Setting[k] = v} if saved_settings
102 102 end
103 103
104 104 # Yields the block with user as the current user
105 105 def with_current_user(user, &block)
106 106 saved_user = User.current
107 107 User.current = user
108 108 yield
109 109 ensure
110 110 User.current = saved_user
111 111 end
112 112
113 113 def with_locale(locale, &block)
114 114 saved_localed = ::I18n.locale
115 115 ::I18n.locale = locale
116 116 yield
117 117 ensure
118 118 ::I18n.locale = saved_localed
119 119 end
120 120
121 121 def self.ldap_configured?
122 122 @test_ldap = Net::LDAP.new(:host => '127.0.0.1', :port => 389)
123 123 return @test_ldap.bind
124 124 rescue Exception => e
125 125 # LDAP is not listening
126 126 return nil
127 127 end
128 128
129 129 def self.convert_installed?
130 130 Redmine::Thumbnail.convert_available?
131 131 end
132 132
133 133 # Returns the path to the test +vendor+ repository
134 134 def self.repository_path(vendor)
135 135 path = Rails.root.join("tmp/test/#{vendor.downcase}_repository").to_s
136 136 # Unlike ruby, JRuby returns Rails.root with backslashes under Windows
137 137 path.tr("\\", "/")
138 138 end
139 139
140 140 # Returns the url of the subversion test repository
141 141 def self.subversion_repository_url
142 142 path = repository_path('subversion')
143 143 path = '/' + path unless path.starts_with?('/')
144 144 "file://#{path}"
145 145 end
146 146
147 147 # Returns true if the +vendor+ test repository is configured
148 148 def self.repository_configured?(vendor)
149 149 File.directory?(repository_path(vendor))
150 150 end
151 151
152 152 def repository_path_hash(arr)
153 153 hs = {}
154 154 hs[:path] = arr.join("/")
155 155 hs[:param] = arr.join("/")
156 156 hs
157 157 end
158 158
159 159 def assert_save(object)
160 160 saved = object.save
161 161 message = "#{object.class} could not be saved"
162 162 errors = object.errors.full_messages.map {|m| "- #{m}"}
163 163 message << ":\n#{errors.join("\n")}" if errors.any?
164 164 assert_equal true, saved, message
165 165 end
166 166
167 167 def assert_select_error(arg)
168 168 assert_select '#errorExplanation', :text => arg
169 169 end
170 170
171 171 def assert_include(expected, s, message=nil)
172 172 assert s.include?(expected), (message || "\"#{expected}\" not found in \"#{s}\"")
173 173 end
174 174
175 175 def assert_not_include(expected, s, message=nil)
176 176 assert !s.include?(expected), (message || "\"#{expected}\" found in \"#{s}\"")
177 177 end
178 178
179 179 def assert_select_in(text, *args, &block)
180 180 d = HTML::Document.new(CGI::unescapeHTML(String.new(text))).root
181 181 assert_select(d, *args, &block)
182 182 end
183 183
184 184 def assert_mail_body_match(expected, mail, message=nil)
185 185 if expected.is_a?(String)
186 186 assert_include expected, mail_body(mail), message
187 187 else
188 188 assert_match expected, mail_body(mail), message
189 189 end
190 190 end
191 191
192 192 def assert_mail_body_no_match(expected, mail, message=nil)
193 193 if expected.is_a?(String)
194 194 assert_not_include expected, mail_body(mail), message
195 195 else
196 196 assert_no_match expected, mail_body(mail), message
197 197 end
198 198 end
199 199
200 200 def mail_body(mail)
201 201 mail.parts.first.body.encoded
202 202 end
203 203
204 204 # awesome_nested_set new node lft and rgt value changed this refactor revision.
205 205 # https://github.com/collectiveidea/awesome_nested_set/commit/199fca9bb938e40200cd90714dc69247ef017c61
206 206 # The reason of behavior change is that "self.class.base_class.unscoped" was added to this line.
207 207 # https://github.com/collectiveidea/awesome_nested_set/commit/199fca9bb9#diff-f61b59a5e6319024e211b0ffdd0e4ef1R273
208 208 # It seems correct behavior because of this line comment.
209 209 # https://github.com/collectiveidea/awesome_nested_set/blame/199fca9bb9/lib/awesome_nested_set/model.rb#L278
210 210 def new_issue_lft
211 211 # ::AwesomeNestedSet::VERSION > "2.1.6" ? Issue.maximum(:rgt) + 1 : 1
212 212 Issue.maximum(:rgt) + 1
213 213 end
214 214 end
215 215
216 216 module Redmine
217 217 class RoutingTest < ActionDispatch::IntegrationTest
218 218 def should_route(arg)
219 219 arg = arg.dup
220 220 request = arg.keys.detect {|key| key.is_a?(String)}
221 221 raise ArgumentError unless request
222 222 options = arg.slice!(request)
223 223
224 224 raise ArgumentError unless request =~ /\A(GET|POST|PUT|PATCH|DELETE)\s+(.+)\z/
225 225 method, path = $1.downcase.to_sym, $2
226 226
227 227 raise ArgumentError unless arg.values.first =~ /\A(.+)#(.+)\z/
228 228 controller, action = $1, $2
229 229
230 230 assert_routing(
231 231 {:method => method, :path => path},
232 232 options.merge(:controller => controller, :action => action)
233 233 )
234 234 end
235 235 end
236 236
237 237 class IntegrationTest < ActionDispatch::IntegrationTest
238 238 def log_user(login, password)
239 239 User.anonymous
240 240 get "/login"
241 241 assert_equal nil, session[:user_id]
242 242 assert_response :success
243 243 assert_template "account/login"
244 244 post "/login", :username => login, :password => password
245 245 assert_equal login, User.find(session[:user_id]).login
246 246 end
247 247
248 248 def credentials(user, password=nil)
249 249 {'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)}
250 250 end
251 251 end
252 252
253 253 module ApiTest
254 254 API_FORMATS = %w(json xml).freeze
255 255
256 256 # Base class for API tests
257 257 class Base < Redmine::IntegrationTest
258 258 def setup
259 259 Setting.rest_api_enabled = '1'
260 260 end
261 261
262 262 def teardown
263 263 Setting.rest_api_enabled = '0'
264 264 end
265 265 end
266 266
267 267 class Routing < Redmine::RoutingTest
268 268 def should_route(arg)
269 269 arg = arg.dup
270 270 request = arg.keys.detect {|key| key.is_a?(String)}
271 271 raise ArgumentError unless request
272 272 options = arg.slice!(request)
273 273
274 274 API_FORMATS.each do |format|
275 275 format_request = request.sub /$/, ".#{format}"
276 276 super options.merge(format_request => arg[request], :format => format)
277 277 end
278 278 end
279 279 end
280 280 end
281 281 end
282
283 # URL helpers do not work with config.threadsafe!
284 # https://github.com/rspec/rspec-rails/issues/476#issuecomment-4705454
285 ActionView::TestCase::TestController.instance_eval do
286 helper Rails.application.routes.url_helpers
287 end
288 ActionView::TestCase::TestController.class_eval do
289 def _routes
290 Rails.application.routes
291 end
292 end
General Comments 0
You need to be logged in to leave comments. Login now