jcnetdev-shoulda 4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/CONTRIBUTION_GUIDELINES.rdoc +12 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.rdoc +123 -0
  4. data/Rakefile +32 -0
  5. data/bin/convert_to_should_syntax +40 -0
  6. data/init.rb +1 -0
  7. data/lib/shoulda.rb +43 -0
  8. data/lib/shoulda/active_record_helpers.rb +670 -0
  9. data/lib/shoulda/color.rb +77 -0
  10. data/lib/shoulda/controller_tests/controller_tests.rb +467 -0
  11. data/lib/shoulda/controller_tests/formats/html.rb +201 -0
  12. data/lib/shoulda/controller_tests/formats/xml.rb +170 -0
  13. data/lib/shoulda/gem/proc_extensions.rb +14 -0
  14. data/lib/shoulda/gem/shoulda.rb +246 -0
  15. data/lib/shoulda/general.rb +118 -0
  16. data/lib/shoulda/private_helpers.rb +22 -0
  17. data/rails/init.rb +1 -0
  18. data/shoulda.gemspec +109 -0
  19. data/tasks/list_tests.rake +23 -0
  20. data/tasks/yaml_to_shoulda.rake +28 -0
  21. data/test/README +36 -0
  22. data/test/fixtures/addresses.yml +3 -0
  23. data/test/fixtures/posts.yml +5 -0
  24. data/test/fixtures/taggings.yml +0 -0
  25. data/test/fixtures/tags.yml +9 -0
  26. data/test/fixtures/users.yml +6 -0
  27. data/test/functional/posts_controller_test.rb +43 -0
  28. data/test/functional/users_controller_test.rb +36 -0
  29. data/test/other/context_test.rb +115 -0
  30. data/test/other/helpers_test.rb +80 -0
  31. data/test/other/private_helpers_test.rb +26 -0
  32. data/test/rails_root/app/controllers/application.rb +25 -0
  33. data/test/rails_root/app/controllers/posts_controller.rb +78 -0
  34. data/test/rails_root/app/controllers/users_controller.rb +81 -0
  35. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  36. data/test/rails_root/app/helpers/posts_helper.rb +2 -0
  37. data/test/rails_root/app/helpers/users_helper.rb +2 -0
  38. data/test/rails_root/app/models/address.rb +4 -0
  39. data/test/rails_root/app/models/dog.rb +4 -0
  40. data/test/rails_root/app/models/flea.rb +3 -0
  41. data/test/rails_root/app/models/post.rb +11 -0
  42. data/test/rails_root/app/models/tag.rb +8 -0
  43. data/test/rails_root/app/models/tagging.rb +4 -0
  44. data/test/rails_root/app/models/user.rb +17 -0
  45. data/test/rails_root/app/views/layouts/posts.rhtml +17 -0
  46. data/test/rails_root/app/views/layouts/users.rhtml +17 -0
  47. data/test/rails_root/app/views/posts/edit.rhtml +27 -0
  48. data/test/rails_root/app/views/posts/index.rhtml +25 -0
  49. data/test/rails_root/app/views/posts/new.rhtml +26 -0
  50. data/test/rails_root/app/views/posts/show.rhtml +18 -0
  51. data/test/rails_root/app/views/users/edit.rhtml +22 -0
  52. data/test/rails_root/app/views/users/index.rhtml +22 -0
  53. data/test/rails_root/app/views/users/new.rhtml +21 -0
  54. data/test/rails_root/app/views/users/show.rhtml +13 -0
  55. data/test/rails_root/config/boot.rb +109 -0
  56. data/test/rails_root/config/database.yml +4 -0
  57. data/test/rails_root/config/environment.rb +18 -0
  58. data/test/rails_root/config/environments/sqlite3.rb +0 -0
  59. data/test/rails_root/config/initializers/new_rails_defaults.rb +15 -0
  60. data/test/rails_root/config/routes.rb +6 -0
  61. data/test/rails_root/db/migrate/001_create_users.rb +17 -0
  62. data/test/rails_root/db/migrate/002_create_posts.rb +13 -0
  63. data/test/rails_root/db/migrate/003_create_taggings.rb +12 -0
  64. data/test/rails_root/db/migrate/004_create_tags.rb +11 -0
  65. data/test/rails_root/db/migrate/005_create_dogs.rb +11 -0
  66. data/test/rails_root/db/migrate/006_create_addresses.rb +13 -0
  67. data/test/rails_root/db/migrate/007_create_fleas.rb +11 -0
  68. data/test/rails_root/db/migrate/008_create_dogs_fleas.rb +12 -0
  69. data/test/rails_root/db/migrate/009_add_ssn_to_users.rb +9 -0
  70. data/test/rails_root/db/schema.rb +0 -0
  71. data/test/rails_root/log/.keep +0 -0
  72. data/test/rails_root/public/.htaccess +40 -0
  73. data/test/rails_root/public/404.html +30 -0
  74. data/test/rails_root/public/422.html +30 -0
  75. data/test/rails_root/public/500.html +30 -0
  76. data/test/rails_root/script/console +3 -0
  77. data/test/rails_root/script/generate +3 -0
  78. data/test/rails_root/vendor/plugins/.keep +0 -0
  79. data/test/test_helper.rb +35 -0
  80. data/test/unit/address_test.rb +7 -0
  81. data/test/unit/dog_test.rb +7 -0
  82. data/test/unit/flea_test.rb +7 -0
  83. data/test/unit/post_test.rb +14 -0
  84. data/test/unit/tag_test.rb +12 -0
  85. data/test/unit/tagging_test.rb +8 -0
  86. data/test/unit/user_test.rb +32 -0
  87. metadata +148 -0
@@ -0,0 +1,77 @@
1
+ require 'test/unit/ui/console/testrunner'
2
+
3
+ # Completely stolen from redgreen gem
4
+ #
5
+ # Adds colored output to your tests. Specify <tt>color: true</tt> in
6
+ # your <tt>~/.shoulda.conf</tt> file to enable.
7
+ #
8
+ # *Bug*: for some reason, this adds another line of output to the end of
9
+ # every rake task, as though there was another (empty) set of tests.
10
+ # A fix would be most welcome.
11
+ #
12
+ module ThoughtBot::Shoulda::Color
13
+ COLORS = { :clear => 0, :red => 31, :green => 32, :yellow => 33 } # :nodoc:
14
+ def self.method_missing(color_name, *args) # :nodoc:
15
+ color(color_name) + args.first + color(:clear)
16
+ end
17
+ def self.color(color) # :nodoc:
18
+ "\e[#{COLORS[color.to_sym]}m"
19
+ end
20
+ end
21
+
22
+ module Test # :nodoc:
23
+ module Unit # :nodoc:
24
+ class TestResult # :nodoc:
25
+ alias :old_to_s :to_s
26
+ def to_s
27
+ if old_to_s =~ /\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors/
28
+ ThoughtBot::Shoulda::Color.send($1.to_i != 0 || $2.to_i != 0 ? :red : :green, $&)
29
+ end
30
+ end
31
+ end
32
+
33
+ class AutoRunner # :nodoc:
34
+ alias :old_initialize :initialize
35
+ def initialize(standalone)
36
+ old_initialize(standalone)
37
+ @runner = proc do |r|
38
+ Test::Unit::UI::Console::RedGreenTestRunner
39
+ end
40
+ end
41
+ end
42
+
43
+ class Failure # :nodoc:
44
+ alias :old_long_display :long_display
45
+ def long_display
46
+ # old_long_display.sub('Failure', ThoughtBot::Shoulda::Color.red('Failure'))
47
+ ThoughtBot::Shoulda::Color.red(old_long_display)
48
+ end
49
+ end
50
+
51
+ class Error # :nodoc:
52
+ alias :old_long_display :long_display
53
+ def long_display
54
+ # old_long_display.sub('Error', ThoughtBot::Shoulda::Color.yellow('Error'))
55
+ ThoughtBot::Shoulda::Color.yellow(old_long_display)
56
+ end
57
+ end
58
+
59
+ module UI # :nodoc:
60
+ module Console # :nodoc:
61
+ class RedGreenTestRunner < Test::Unit::UI::Console::TestRunner # :nodoc:
62
+ def output_single(something, level=NORMAL)
63
+ return unless (output?(level))
64
+ something = case something
65
+ when '.' then ThoughtBot::Shoulda::Color.green('.')
66
+ when 'F' then ThoughtBot::Shoulda::Color.red("F")
67
+ when 'E' then ThoughtBot::Shoulda::Color.yellow("E")
68
+ else something
69
+ end
70
+ @io.write(something)
71
+ @io.flush
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,467 @@
1
+ module ThoughtBot # :nodoc:
2
+ module Shoulda # :nodoc:
3
+ module Controller
4
+ def self.included(other) # :nodoc:
5
+ other.class_eval do
6
+ extend ThoughtBot::Shoulda::Controller::ClassMethods
7
+ include ThoughtBot::Shoulda::Controller::InstanceMethods
8
+ ThoughtBot::Shoulda::Controller::ClassMethods::VALID_FORMATS.each do |format|
9
+ include "ThoughtBot::Shoulda::Controller::#{format.to_s.upcase}".constantize
10
+ end
11
+ end
12
+ end
13
+
14
+ # = Macro test helpers for your controllers
15
+ #
16
+ # By using the macro helpers you can quickly and easily create concise and easy to read test suites.
17
+ #
18
+ # This code segment:
19
+ # context "on GET to :show for first record" do
20
+ # setup do
21
+ # get :show, :id => 1
22
+ # end
23
+ #
24
+ # should_assign_to :user
25
+ # should_respond_with :success
26
+ # should_render_template :show
27
+ # should_not_set_the_flash
28
+ #
29
+ # should "do something else really cool" do
30
+ # assert_equal 1, assigns(:user).id
31
+ # end
32
+ # end
33
+ #
34
+ # Would produce 5 tests for the +show+ action
35
+ #
36
+ # Furthermore, the should_be_restful helper will create an entire set of tests which will verify that your
37
+ # controller responds restfully to a variety of requested formats.
38
+ module ClassMethods
39
+ # Formats tested by #should_be_restful. Defaults to [:html, :xml]
40
+ VALID_FORMATS = Dir.glob(File.join(File.dirname(__FILE__), 'formats', '*.rb')).map { |f| File.basename(f, '.rb') }.map(&:to_sym) # :doc:
41
+ VALID_FORMATS.each {|f| require "shoulda/controller_tests/formats/#{f}.rb"}
42
+
43
+ # Actions tested by #should_be_restful
44
+ VALID_ACTIONS = [:index, :show, :new, :edit, :create, :update, :destroy] # :doc:
45
+
46
+ # A ResourceOptions object is passed into should_be_restful in order to configure the tests for your controller.
47
+ #
48
+ # Example:
49
+ # class UsersControllerTest < Test::Unit::TestCase
50
+ # load_all_fixtures
51
+ #
52
+ # def setup
53
+ # ...normal setup code...
54
+ # @user = User.find(:first)
55
+ # end
56
+ #
57
+ # should_be_restful do |resource|
58
+ # resource.identifier = :id
59
+ # resource.klass = User
60
+ # resource.object = :user
61
+ # resource.parent = []
62
+ # resource.actions = [:index, :show, :new, :edit, :update, :create, :destroy]
63
+ # resource.formats = [:html, :xml]
64
+ #
65
+ # resource.create.params = { :name => "bob", :email => 'bob@bob.com', :age => 13}
66
+ # resource.update.params = { :name => "sue" }
67
+ #
68
+ # resource.create.redirect = "user_url(@user)"
69
+ # resource.update.redirect = "user_url(@user)"
70
+ # resource.destroy.redirect = "users_url"
71
+ #
72
+ # resource.create.flash = /created/i
73
+ # resource.update.flash = /updated/i
74
+ # resource.destroy.flash = /removed/i
75
+ # end
76
+ # end
77
+ #
78
+ # Whenever possible, the resource attributes will be set to sensible defaults.
79
+ #
80
+ class ResourceOptions
81
+ # Configuration options for the create, update, destroy actions under should_be_restful
82
+ class ActionOptions
83
+ # String evaled to get the target of the redirection.
84
+ # All of the instance variables set by the controller will be available to the
85
+ # evaled code.
86
+ #
87
+ # Example:
88
+ # resource.create.redirect = "user_url(@user.company, @user)"
89
+ #
90
+ # Defaults to a generated url based on the name of the controller, the action, and the resource.parents list.
91
+ attr_accessor :redirect
92
+
93
+ # String or Regexp describing a value expected in the flash. Will match against any flash key.
94
+ #
95
+ # Defaults:
96
+ # destroy:: /removed/
97
+ # create:: /created/
98
+ # update:: /updated/
99
+ attr_accessor :flash
100
+
101
+ # Hash describing the params that should be sent in with this action.
102
+ attr_accessor :params
103
+ end
104
+
105
+ # Configuration options for the denied actions under should_be_restful
106
+ #
107
+ # Example:
108
+ # context "The public" do
109
+ # setup do
110
+ # @request.session[:logged_in] = false
111
+ # end
112
+ #
113
+ # should_be_restful do |resource|
114
+ # resource.parent = :user
115
+ #
116
+ # resource.denied.actions = [:index, :show, :edit, :new, :create, :update, :destroy]
117
+ # resource.denied.flash = /get outta here/i
118
+ # resource.denied.redirect = 'new_session_url'
119
+ # end
120
+ # end
121
+ #
122
+ class DeniedOptions
123
+ # String evaled to get the target of the redirection.
124
+ # All of the instance variables set by the controller will be available to the
125
+ # evaled code.
126
+ #
127
+ # Example:
128
+ # resource.create.redirect = "user_url(@user.company, @user)"
129
+ attr_accessor :redirect
130
+
131
+ # String or Regexp describing a value expected in the flash. Will match against any flash key.
132
+ #
133
+ # Example:
134
+ # resource.create.flash = /created/
135
+ attr_accessor :flash
136
+
137
+ # Actions that should be denied (only used by resource.denied). <i>Note that these actions will
138
+ # only be tested if they are also listed in +resource.actions+</i>
139
+ # The special value of :all will deny all of the REST actions.
140
+ attr_accessor :actions
141
+ end
142
+
143
+ # Name of key in params that references the primary key.
144
+ # Will almost always be :id (default), unless you are using a plugin or have patched rails.
145
+ attr_accessor :identifier
146
+
147
+ # Name of the ActiveRecord class this resource is responsible for. Automatically determined from
148
+ # test class if not explicitly set. UserTest => "User"
149
+ attr_accessor :klass
150
+
151
+ # Name of the instantiated ActiveRecord object that should be used by some of the tests.
152
+ # Defaults to the underscored name of the AR class. CompanyManager => :company_manager
153
+ attr_accessor :object
154
+
155
+ # Name of the parent AR objects. Can be set as parent= or parents=, and can take either
156
+ # the name of the parent resource (if there's only one), or an array of names (if there's
157
+ # more than one).
158
+ #
159
+ # Example:
160
+ # # in the routes...
161
+ # map.resources :companies do
162
+ # map.resources :people do
163
+ # map.resources :limbs
164
+ # end
165
+ # end
166
+ #
167
+ # # in the tests...
168
+ # class PeopleControllerTest < Test::Unit::TestCase
169
+ # should_be_restful do |resource|
170
+ # resource.parent = :companies
171
+ # end
172
+ # end
173
+ #
174
+ # class LimbsControllerTest < Test::Unit::TestCase
175
+ # should_be_restful do |resource|
176
+ # resource.parents = [:companies, :people]
177
+ # end
178
+ # end
179
+ attr_accessor :parent
180
+ alias parents parent
181
+ alias parents= parent=
182
+
183
+ # Actions that should be tested. Must be a subset of VALID_ACTIONS (default).
184
+ # Tests for each actionw will only be generated if the action is listed here.
185
+ # The special value of :all will test all of the REST actions.
186
+ #
187
+ # Example (for a read-only controller):
188
+ # resource.actions = [:show, :index]
189
+ attr_accessor :actions
190
+
191
+ # Formats that should be tested. Must be a subset of VALID_FORMATS (default).
192
+ # Each action will be tested against the formats listed here. The special value
193
+ # of :all will test all of the supported formats.
194
+ #
195
+ # Example:
196
+ # resource.actions = [:html, :xml]
197
+ attr_accessor :formats
198
+
199
+ # ActionOptions object specifying options for the create action.
200
+ attr_accessor :create
201
+
202
+ # ActionOptions object specifying options for the update action.
203
+ attr_accessor :update
204
+
205
+ # ActionOptions object specifying options for the desrtoy action.
206
+ attr_accessor :destroy
207
+
208
+ # DeniedOptions object specifying which actions should return deny a request, and what should happen in that case.
209
+ attr_accessor :denied
210
+
211
+ def initialize # :nodoc:
212
+ @create = ActionOptions.new
213
+ @update = ActionOptions.new
214
+ @destroy = ActionOptions.new
215
+ @denied = DeniedOptions.new
216
+
217
+ @create.flash ||= /created/i
218
+ @update.flash ||= /updated/i
219
+ @destroy.flash ||= /removed/i
220
+ @denied.flash ||= /denied/i
221
+
222
+ @create.params ||= {}
223
+ @update.params ||= {}
224
+
225
+ @actions = VALID_ACTIONS
226
+ @formats = VALID_FORMATS
227
+ @denied.actions = []
228
+ end
229
+
230
+ def normalize!(target) # :nodoc:
231
+ @denied.actions = VALID_ACTIONS if @denied.actions == :all
232
+ @actions = VALID_ACTIONS if @actions == :all
233
+ @formats = VALID_FORMATS if @formats == :all
234
+
235
+ @denied.actions = @denied.actions.map(&:to_sym)
236
+ @actions = @actions.map(&:to_sym)
237
+ @formats = @formats.map(&:to_sym)
238
+
239
+ ensure_valid_members(@actions, VALID_ACTIONS, 'actions')
240
+ ensure_valid_members(@denied.actions, VALID_ACTIONS, 'denied.actions')
241
+ ensure_valid_members(@formats, VALID_FORMATS, 'formats')
242
+
243
+ @identifier ||= :id
244
+ @klass ||= target.name.gsub(/ControllerTest$/, '').singularize.constantize
245
+ @object ||= @klass.name.tableize.singularize
246
+ @parent ||= []
247
+ @parent = [@parent] unless @parent.is_a? Array
248
+
249
+ collection_helper = [@parent, @object.to_s.pluralize, 'url'].flatten.join('_')
250
+ collection_args = @parent.map {|n| "@#{object}.#{n}"}.join(', ')
251
+ @destroy.redirect ||= "#{collection_helper}(#{collection_args})"
252
+
253
+ member_helper = [@parent, @object, 'url'].flatten.join('_')
254
+ member_args = [@parent.map {|n| "@#{object}.#{n}"}, "@#{object}"].flatten.join(', ')
255
+ @create.redirect ||= "#{member_helper}(#{member_args})"
256
+ @update.redirect ||= "#{member_helper}(#{member_args})"
257
+ @denied.redirect ||= "new_session_url"
258
+ end
259
+
260
+ private
261
+
262
+ def ensure_valid_members(ary, valid_members, name) # :nodoc:
263
+ invalid = ary - valid_members
264
+ raise ArgumentError, "Unsupported #{name}: #{invalid.inspect}" unless invalid.empty?
265
+ end
266
+ end
267
+
268
+ # :section: should_be_restful
269
+ # Generates a full suite of tests for a restful controller.
270
+ #
271
+ # The following definition will generate tests for the +index+, +show+, +new+,
272
+ # +edit+, +create+, +update+ and +destroy+ actions, in both +html+ and +xml+ formats:
273
+ #
274
+ # should_be_restful do |resource|
275
+ # resource.parent = :user
276
+ #
277
+ # resource.create.params = { :title => "first post", :body => 'blah blah blah'}
278
+ # resource.update.params = { :title => "changed" }
279
+ # end
280
+ #
281
+ # This generates about 40 tests, all of the format:
282
+ # "on GET to :show should assign @user."
283
+ # "on GET to :show should not set the flash."
284
+ # "on GET to :show should render 'show' template."
285
+ # "on GET to :show should respond with success."
286
+ # "on GET to :show as xml should assign @user."
287
+ # "on GET to :show as xml should have ContentType set to 'application/xml'."
288
+ # "on GET to :show as xml should respond with success."
289
+ # "on GET to :show as xml should return <user/> as the root element."
290
+ # The +resource+ parameter passed into the block is a ResourceOptions object, and
291
+ # is used to configure the tests for the details of your resources.
292
+ #
293
+ def should_be_restful(&blk) # :yields: resource
294
+ resource = ResourceOptions.new
295
+ blk.call(resource)
296
+ resource.normalize!(self)
297
+
298
+ resource.formats.each do |format|
299
+ resource.actions.each do |action|
300
+ if self.respond_to? :"make_#{action}_#{format}_tests"
301
+ self.send(:"make_#{action}_#{format}_tests", resource)
302
+ else
303
+ should "test #{action} #{format}" do
304
+ flunk "Test for #{action} as #{format} not implemented"
305
+ end
306
+ end
307
+ end
308
+ end
309
+ end
310
+
311
+ # :section: Test macros
312
+
313
+ # Macro that creates a test asserting that the flash contains the given value.
314
+ # val can be a String, a Regex, or nil (indicating that the flash should not be set)
315
+ #
316
+ # Example:
317
+ #
318
+ # should_set_the_flash_to "Thank you for placing this order."
319
+ # should_set_the_flash_to /created/i
320
+ # should_set_the_flash_to nil
321
+ def should_set_the_flash_to(val)
322
+ if val
323
+ should "have #{val.inspect} in the flash" do
324
+ assert_contains flash.values, val, ", Flash: #{flash.inspect}"
325
+ end
326
+ else
327
+ should "not set the flash" do
328
+ assert_equal({}, flash, "Flash was set to:\n#{flash.inspect}")
329
+ end
330
+ end
331
+ end
332
+
333
+ # Macro that creates a test asserting that the flash is empty. Same as
334
+ # @should_set_the_flash_to nil@
335
+ def should_not_set_the_flash
336
+ should_set_the_flash_to nil
337
+ end
338
+
339
+ # Macro that creates a test asserting that the controller assigned to @name
340
+ #
341
+ # Example:
342
+ #
343
+ # should_assign_to :user
344
+ def should_assign_to(name)
345
+ should "assign @#{name}" do
346
+ assert assigns(name.to_sym), "The action isn't assigning to @#{name}"
347
+ end
348
+ end
349
+
350
+ # Macro that creates a test asserting that the controller did not assign to @name
351
+ #
352
+ # Example:
353
+ #
354
+ # should_not_assign_to :user
355
+ def should_not_assign_to(name)
356
+ should "not assign to @#{name}" do
357
+ assert !assigns(name.to_sym), "@#{name} was visible"
358
+ end
359
+ end
360
+
361
+ # Macro that creates a test asserting that the controller responded with a 'response' status code.
362
+ # Example:
363
+ #
364
+ # should_respond_with :success
365
+ def should_respond_with(response)
366
+ should "respond with #{response}" do
367
+ assert_response response
368
+ end
369
+ end
370
+
371
+ # Macro that creates a test asserting that the controller rendered the given template.
372
+ # Example:
373
+ #
374
+ # should_render_template :new
375
+ def should_render_template(template)
376
+ should "render template #{template.inspect}" do
377
+ assert_template template.to_s
378
+ end
379
+ end
380
+
381
+ # Macro that creates a test asserting that the controller returned a redirect to the given path.
382
+ # The given string is evaled to produce the resulting redirect path. All of the instance variables
383
+ # set by the controller are available to the evaled string.
384
+ # Example:
385
+ #
386
+ # should_redirect_to '"/"'
387
+ # should_redirect_to "users_url(@user)"
388
+ def should_redirect_to(url)
389
+ should "redirect to #{url.inspect}" do
390
+ instantiate_variables_from_assigns do
391
+ assert_redirected_to eval(url, self.send(:binding), __FILE__, __LINE__)
392
+ end
393
+ end
394
+ end
395
+
396
+ # Macro that creates a test asserting that the rendered view contains a <form> element.
397
+ def should_render_a_form
398
+ should "display a form" do
399
+ assert_select "form", true, "The template doesn't contain a <form> element"
400
+ end
401
+ end
402
+ end
403
+
404
+ module InstanceMethods # :nodoc:
405
+
406
+ private # :enddoc:
407
+
408
+ SPECIAL_INSTANCE_VARIABLES = %w{
409
+ _cookies
410
+ _flash
411
+ _headers
412
+ _params
413
+ _request
414
+ _response
415
+ _session
416
+ action_name
417
+ before_filter_chain_aborted
418
+ cookies
419
+ flash
420
+ headers
421
+ ignore_missing_templates
422
+ logger
423
+ params
424
+ request
425
+ request_origin
426
+ response
427
+ session
428
+ template
429
+ template_class
430
+ template_root
431
+ url
432
+ variables_added
433
+ }.map(&:to_s)
434
+
435
+ def instantiate_variables_from_assigns(*names, &blk)
436
+ old = {}
437
+ names = (@response.template.assigns.keys - SPECIAL_INSTANCE_VARIABLES) if names.empty?
438
+ names.each do |name|
439
+ old[name] = instance_variable_get("@#{name}")
440
+ instance_variable_set("@#{name}", assigns(name.to_sym))
441
+ end
442
+ blk.call
443
+ names.each do |name|
444
+ instance_variable_set("@#{name}", old[name])
445
+ end
446
+ end
447
+
448
+ def get_existing_record(res) # :nodoc:
449
+ returning(instance_variable_get("@#{res.object}")) do |record|
450
+ assert(record, "This test requires you to set @#{res.object} in your setup block")
451
+ end
452
+ end
453
+
454
+ def make_parent_params(resource, record = nil, parent_names = nil) # :nodoc:
455
+ parent_names ||= resource.parents.reverse
456
+ return {} if parent_names == [] # Base case
457
+ parent_name = parent_names.shift
458
+ parent = record ? record.send(parent_name) : parent_name.to_s.classify.constantize.find(:first)
459
+
460
+ { :"#{parent_name}_id" => parent.to_param }.merge(make_parent_params(resource, parent, parent_names))
461
+ end
462
+
463
+ end
464
+ end
465
+ end
466
+ end
467
+