ratnikov-shoulda 2.0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. data/CONTRIBUTION_GUIDELINES.rdoc +12 -0
  2. data/MIT-LICENSE +22 -0
  3. data/README.rdoc +146 -0
  4. data/Rakefile +72 -0
  5. data/bin/convert_to_should_syntax +42 -0
  6. data/lib/shoulda/action_mailer/assertions.rb +38 -0
  7. data/lib/shoulda/action_mailer.rb +10 -0
  8. data/lib/shoulda/active_record/assertions.rb +90 -0
  9. data/lib/shoulda/active_record/macros.rb +748 -0
  10. data/lib/shoulda/active_record.rb +12 -0
  11. data/lib/shoulda/assertions.rb +47 -0
  12. data/lib/shoulda/context.rb +326 -0
  13. data/lib/shoulda/controller/formats/html.rb +199 -0
  14. data/lib/shoulda/controller/formats/xml.rb +168 -0
  15. data/lib/shoulda/controller/helpers.rb +62 -0
  16. data/lib/shoulda/controller/macros.rb +336 -0
  17. data/lib/shoulda/controller/resource_options.rb +233 -0
  18. data/lib/shoulda/controller.rb +30 -0
  19. data/lib/shoulda/helpers.rb +8 -0
  20. data/lib/shoulda/macros.rb +73 -0
  21. data/lib/shoulda/private_helpers.rb +20 -0
  22. data/lib/shoulda/proc_extensions.rb +14 -0
  23. data/lib/shoulda/rails.rb +19 -0
  24. data/lib/shoulda/tasks/list_tests.rake +24 -0
  25. data/lib/shoulda/tasks/yaml_to_shoulda.rake +28 -0
  26. data/lib/shoulda/tasks.rb +3 -0
  27. data/lib/shoulda.rb +21 -0
  28. data/rails/init.rb +1 -0
  29. data/test/README +36 -0
  30. data/test/fail_macros.rb +34 -0
  31. data/test/fixtures/addresses.yml +3 -0
  32. data/test/fixtures/friendships.yml +0 -0
  33. data/test/fixtures/posts.yml +5 -0
  34. data/test/fixtures/products.yml +0 -0
  35. data/test/fixtures/taggings.yml +0 -0
  36. data/test/fixtures/tags.yml +9 -0
  37. data/test/fixtures/users.yml +6 -0
  38. data/test/functional/posts_controller_test.rb +108 -0
  39. data/test/functional/users_controller_test.rb +38 -0
  40. data/test/other/context_test.rb +161 -0
  41. data/test/other/convert_to_should_syntax_test.rb +63 -0
  42. data/test/other/helpers_test.rb +183 -0
  43. data/test/other/private_helpers_test.rb +34 -0
  44. data/test/other/should_test.rb +266 -0
  45. data/test/rails_root/app/controllers/application.rb +25 -0
  46. data/test/rails_root/app/controllers/posts_controller.rb +86 -0
  47. data/test/rails_root/app/controllers/users_controller.rb +84 -0
  48. data/test/rails_root/app/helpers/application_helper.rb +3 -0
  49. data/test/rails_root/app/helpers/posts_helper.rb +2 -0
  50. data/test/rails_root/app/helpers/users_helper.rb +2 -0
  51. data/test/rails_root/app/models/address.rb +7 -0
  52. data/test/rails_root/app/models/flea.rb +3 -0
  53. data/test/rails_root/app/models/friendship.rb +4 -0
  54. data/test/rails_root/app/models/post.rb +12 -0
  55. data/test/rails_root/app/models/product.rb +12 -0
  56. data/test/rails_root/app/models/tag.rb +8 -0
  57. data/test/rails_root/app/models/tagging.rb +4 -0
  58. data/test/rails_root/app/models/user.rb +28 -0
  59. data/test/rails_root/app/views/layouts/posts.rhtml +19 -0
  60. data/test/rails_root/app/views/layouts/users.rhtml +17 -0
  61. data/test/rails_root/app/views/layouts/wide.html.erb +1 -0
  62. data/test/rails_root/app/views/posts/edit.rhtml +27 -0
  63. data/test/rails_root/app/views/posts/index.rhtml +25 -0
  64. data/test/rails_root/app/views/posts/new.rhtml +26 -0
  65. data/test/rails_root/app/views/posts/show.rhtml +18 -0
  66. data/test/rails_root/app/views/users/edit.rhtml +22 -0
  67. data/test/rails_root/app/views/users/index.rhtml +22 -0
  68. data/test/rails_root/app/views/users/new.rhtml +21 -0
  69. data/test/rails_root/app/views/users/show.rhtml +13 -0
  70. data/test/rails_root/config/boot.rb +109 -0
  71. data/test/rails_root/config/database.yml +4 -0
  72. data/test/rails_root/config/environment.rb +14 -0
  73. data/test/rails_root/config/environments/sqlite3.rb +0 -0
  74. data/test/rails_root/config/initializers/new_rails_defaults.rb +15 -0
  75. data/test/rails_root/config/initializers/shoulda.rb +8 -0
  76. data/test/rails_root/config/routes.rb +6 -0
  77. data/test/rails_root/db/migrate/001_create_users.rb +19 -0
  78. data/test/rails_root/db/migrate/002_create_posts.rb +13 -0
  79. data/test/rails_root/db/migrate/003_create_taggings.rb +12 -0
  80. data/test/rails_root/db/migrate/004_create_tags.rb +11 -0
  81. data/test/rails_root/db/migrate/005_create_dogs.rb +12 -0
  82. data/test/rails_root/db/migrate/006_create_addresses.rb +14 -0
  83. data/test/rails_root/db/migrate/007_create_fleas.rb +11 -0
  84. data/test/rails_root/db/migrate/008_create_dogs_fleas.rb +12 -0
  85. data/test/rails_root/db/migrate/009_create_products.rb +17 -0
  86. data/test/rails_root/db/migrate/010_create_friendships.rb +14 -0
  87. data/test/rails_root/db/schema.rb +0 -0
  88. data/test/rails_root/public/404.html +30 -0
  89. data/test/rails_root/public/422.html +30 -0
  90. data/test/rails_root/public/500.html +30 -0
  91. data/test/rails_root/script/console +3 -0
  92. data/test/rails_root/script/generate +3 -0
  93. data/test/test_helper.rb +33 -0
  94. data/test/unit/address_test.rb +10 -0
  95. data/test/unit/dog_test.rb +10 -0
  96. data/test/unit/flea_test.rb +6 -0
  97. data/test/unit/friendship_test.rb +6 -0
  98. data/test/unit/post_test.rb +19 -0
  99. data/test/unit/product_test.rb +27 -0
  100. data/test/unit/tag_test.rb +14 -0
  101. data/test/unit/tagging_test.rb +6 -0
  102. data/test/unit/user_test.rb +60 -0
  103. metadata +189 -0
@@ -0,0 +1,12 @@
1
+ require 'shoulda'
2
+ require 'shoulda/active_record/assertions'
3
+ require 'shoulda/active_record/macros'
4
+
5
+ module Test # :nodoc: all
6
+ module Unit
7
+ class TestCase
8
+ include Shoulda::ActiveRecord::Assertions
9
+ extend Shoulda::ActiveRecord::Macros
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ module Shoulda # :nodoc:
2
+ module Assertions
3
+ # Asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered.
4
+ #
5
+ # assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes
6
+ def assert_same_elements(a1, a2, msg = nil)
7
+ [:select, :inject, :size].each do |m|
8
+ [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") }
9
+ end
10
+
11
+ assert a1h = a1.inject({}) { |h,e| h[e] = a1.select { |i| i == e }.size; h }
12
+ assert a2h = a2.inject({}) { |h,e| h[e] = a2.select { |i| i == e }.size; h }
13
+
14
+ assert_equal(a1h, a2h, msg)
15
+ end
16
+
17
+ # Asserts that the given collection contains item x. If x is a regular expression, ensure that
18
+ # at least one element from the collection matches x. +extra_msg+ is appended to the error message if the assertion fails.
19
+ #
20
+ # assert_contains(['a', '1'], /\d/) => passes
21
+ # assert_contains(['a', '1'], 'a') => passes
22
+ # assert_contains(['a', '1'], /not there/) => fails
23
+ def assert_contains(collection, x, extra_msg = "")
24
+ collection = [collection] unless collection.is_a?(Array)
25
+ msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}"
26
+ case x
27
+ when Regexp
28
+ assert(collection.detect { |e| e =~ x }, msg)
29
+ else
30
+ assert(collection.include?(x), msg)
31
+ end
32
+ end
33
+
34
+ # Asserts that the given collection does not contain item x. If x is a regular expression, ensure that
35
+ # none of the elements from the collection match x.
36
+ def assert_does_not_contain(collection, x, extra_msg = "")
37
+ collection = [collection] unless collection.is_a?(Array)
38
+ msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg
39
+ case x
40
+ when Regexp
41
+ assert(!collection.detect { |e| e =~ x }, msg)
42
+ else
43
+ assert(!collection.include?(x), msg)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,326 @@
1
+ module Shoulda
2
+ class << self
3
+ attr_accessor :contexts
4
+ def contexts # :nodoc:
5
+ @contexts ||= []
6
+ end
7
+
8
+ def current_context # :nodoc:
9
+ self.contexts.last
10
+ end
11
+
12
+ def add_context(context) # :nodoc:
13
+ self.contexts.push(context)
14
+ end
15
+
16
+ def remove_context # :nodoc:
17
+ self.contexts.pop
18
+ end
19
+ end
20
+
21
+ module ClassMethods
22
+ # == Should statements
23
+ #
24
+ # Should statements are just syntactic sugar over normal Test::Unit test methods. A should block
25
+ # contains all the normal code and assertions you're used to seeing, with the added benefit that
26
+ # they can be wrapped inside context blocks (see below).
27
+ #
28
+ # === Example:
29
+ #
30
+ # class UserTest < Test::Unit::TestCase
31
+ #
32
+ # def setup
33
+ # @user = User.new("John", "Doe")
34
+ # end
35
+ #
36
+ # should "return its full name"
37
+ # assert_equal 'John Doe', @user.full_name
38
+ # end
39
+ #
40
+ # end
41
+ #
42
+ # ...will produce the following test:
43
+ # * <tt>"test: User should return its full name. "</tt>
44
+ #
45
+ # Note: The part before <tt>should</tt> in the test name is gleamed from the name of the Test::Unit class.
46
+ #
47
+ # Should statements can also take a Proc as a <tt>:before </tt>option. This proc runs after any
48
+ # parent context's setups but before the current context's setup.
49
+ #
50
+ # === Example:
51
+ #
52
+ # context "Some context" do
53
+ # setup { puts("I run after the :before proc") }
54
+ #
55
+ # should "run a :before proc", :before => lambda { puts("I run before the setup") } do
56
+ # assert true
57
+ # end
58
+ # end
59
+
60
+ def should(name, options = {}, &blk)
61
+ if Shoulda.current_context
62
+ block_given? ? Shoulda.current_context.should(name, options, &blk) : Should.current_context.should_eventually(name)
63
+ else
64
+ context_name = self.name.gsub(/Test/, "")
65
+ context = Shoulda::Context.new(context_name, self) do
66
+ block_given? ? should(name, options, &blk) : should_eventually(name)
67
+ end
68
+ context.build
69
+ end
70
+ end
71
+
72
+ # == Before statements
73
+ #
74
+ # Before statements are should statements that run before the current
75
+ # context's setup. These are especially useful when setting expectations.
76
+ #
77
+ # === Example:
78
+ #
79
+ # class UserControllerTest < Test::Unit::TestCase
80
+ # context "the index action" do
81
+ # setup do
82
+ # @users = [Factory(:user)]
83
+ # User.stubs(:find).returns(@users)
84
+ # end
85
+ #
86
+ # context "on GET" do
87
+ # setup { get :index }
88
+ #
89
+ # should_respond_with :success
90
+ #
91
+ # # runs before "get :index"
92
+ # before_should "find all users" do
93
+ # User.expects(:find).with(:all).returns(@users)
94
+ # end
95
+ # end
96
+ # end
97
+ # end
98
+ def before_should(name, &blk)
99
+ should(name, :before => blk) { assert true }
100
+ end
101
+
102
+ # Just like should, but never runs, and instead prints an 'X' in the Test::Unit output.
103
+ def should_eventually(name, options = {}, &blk)
104
+ context_name = self.name.gsub(/Test/, "")
105
+ context = Shoulda::Context.new(context_name, self) do
106
+ should_eventually(name, &blk)
107
+ end
108
+ context.build
109
+ end
110
+
111
+ # == Contexts
112
+ #
113
+ # A context block groups should statements under a common set of setup/teardown methods.
114
+ # Context blocks can be arbitrarily nested, and can do wonders for improving the maintainability
115
+ # and readability of your test code.
116
+ #
117
+ # A context block can contain setup, should, should_eventually, and teardown blocks.
118
+ #
119
+ # class UserTest < Test::Unit::TestCase
120
+ # context "A User instance" do
121
+ # setup do
122
+ # @user = User.find(:first)
123
+ # end
124
+ #
125
+ # should "return its full name"
126
+ # assert_equal 'John Doe', @user.full_name
127
+ # end
128
+ # end
129
+ # end
130
+ #
131
+ # This code will produce the method <tt>"test: A User instance should return its full name. "</tt>.
132
+ #
133
+ # Contexts may be nested. Nested contexts run their setup blocks from out to in before each
134
+ # should statement. They then run their teardown blocks from in to out after each should statement.
135
+ #
136
+ # class UserTest < Test::Unit::TestCase
137
+ # context "A User instance" do
138
+ # setup do
139
+ # @user = User.find(:first)
140
+ # end
141
+ #
142
+ # should "return its full name"
143
+ # assert_equal 'John Doe', @user.full_name
144
+ # end
145
+ #
146
+ # context "with a profile" do
147
+ # setup do
148
+ # @user.profile = Profile.find(:first)
149
+ # end
150
+ #
151
+ # should "return true when sent :has_profile?"
152
+ # assert @user.has_profile?
153
+ # end
154
+ # end
155
+ # end
156
+ # end
157
+ #
158
+ # This code will produce the following methods
159
+ # * <tt>"test: A User instance should return its full name. "</tt>
160
+ # * <tt>"test: A User instance with a profile should return true when sent :has_profile?. "</tt>
161
+ #
162
+ # <b>Just like should statements, a context block can exist next to normal <tt>def test_the_old_way; end</tt>
163
+ # tests</b>. This means you do not have to fully commit to the context/should syntax in a test file.
164
+
165
+ def context(name, &blk)
166
+ if Shoulda.current_context
167
+ Shoulda.current_context.context(name, &blk)
168
+ else
169
+ context = Shoulda::Context.new(name, self, &blk)
170
+ context.build
171
+ end
172
+ end
173
+ end
174
+
175
+ class Context # :nodoc:
176
+
177
+ attr_accessor :name # my name
178
+ attr_accessor :parent # may be another context, or the original test::unit class.
179
+ attr_accessor :subcontexts # array of contexts nested under myself
180
+ attr_accessor :setup_blocks # blocks given via setup methods
181
+ attr_accessor :evaluate_blocks # blocks given via eveluate methods that are run after setup
182
+ attr_accessor :teardown_blocks # blocks given via teardown methods
183
+ attr_accessor :shoulds # array of hashes representing the should statements
184
+ attr_accessor :should_eventuallys # array of hashes representing the should eventually statements
185
+
186
+ def initialize(name, parent, &blk)
187
+ Shoulda.add_context(self)
188
+ self.name = name
189
+ self.parent = parent
190
+ self.setup_blocks = []
191
+ self.evaluate_blocks = []
192
+ self.teardown_blocks = []
193
+ self.shoulds = []
194
+ self.should_eventuallys = []
195
+ self.subcontexts = []
196
+
197
+ merge_block(&blk)
198
+ Shoulda.remove_context
199
+ end
200
+
201
+ def merge_block(&blk)
202
+ blk.bind(self).call
203
+ end
204
+
205
+ def context(name, &blk)
206
+ self.subcontexts << Context.new(name, self, &blk)
207
+ end
208
+
209
+ def setup(&blk)
210
+ self.setup_blocks << blk
211
+ end
212
+
213
+ def evaluate(&blk)
214
+ self.evaluate_blocks << blk
215
+ end
216
+
217
+ def teardown(&blk)
218
+ self.teardown_blocks << blk
219
+ end
220
+
221
+ def should(name, options = {}, &blk)
222
+ if block_given?
223
+ self.shoulds << { :name => name, :before => options[:before], :block => blk }
224
+ else
225
+ self.should_eventuallys << { :name => name }
226
+ end
227
+ end
228
+
229
+ def should_eventually(name, &blk)
230
+ self.should_eventuallys << { :name => name, :block => blk }
231
+ end
232
+
233
+ def full_name
234
+ parent_name = parent.full_name if am_subcontext?
235
+ return [parent_name, name].join(" ").strip
236
+ end
237
+
238
+ def am_subcontext?
239
+ parent.is_a?(self.class) # my parent is the same class as myself.
240
+ end
241
+
242
+ def test_unit_class
243
+ am_subcontext? ? parent.test_unit_class : parent
244
+ end
245
+
246
+ def create_test_from_should_hash(should)
247
+ test_name = ["test:", full_name, "should", "#{should[:name]}. "].flatten.join(' ').to_sym
248
+
249
+ if test_unit_class.instance_methods.include?(test_name.to_s)
250
+ warn " * WARNING: '#{test_name}' is already defined"
251
+ end
252
+
253
+ context = self
254
+ test_unit_class.send(:define_method, test_name) do
255
+ begin
256
+ context.run_parent_setup_blocks(self)
257
+ should[:before].bind(self).call if should[:before]
258
+ context.run_current_setup_blocks(self)
259
+ context.run_all_evaluate_blocks(self)
260
+ should[:block].bind(self).call
261
+ ensure
262
+ context.run_all_teardown_blocks(self)
263
+ end
264
+ end
265
+ end
266
+
267
+ def run_all_setup_blocks(binding)
268
+ run_parent_setup_blocks(binding)
269
+ run_current_setup_blocks(binding)
270
+ end
271
+
272
+ def run_parent_setup_blocks(binding)
273
+ self.parent.run_all_setup_blocks(binding) if am_subcontext?
274
+ end
275
+
276
+ def run_current_setup_blocks(binding)
277
+ setup_blocks.each do |setup_block|
278
+ setup_block.bind(binding).call
279
+ end
280
+ end
281
+
282
+ def run_all_evaluate_blocks(binding)
283
+ run_parent_evaluate_blocks(binding)
284
+ run_current_evaluate_blocks(binding)
285
+ end
286
+
287
+ def run_parent_evaluate_blocks(binding)
288
+ self.parent.run_all_evaluate_blocks(binding) if am_subcontext?
289
+ end
290
+
291
+ def run_current_evaluate_blocks(binding)
292
+ evaluate_blocks.each do |evaluate_block|
293
+ evaluate_block.bind(binding).call
294
+ end
295
+ end
296
+
297
+ def run_all_teardown_blocks(binding)
298
+ teardown_blocks.reverse.each do |teardown_block|
299
+ teardown_block.bind(binding).call
300
+ end
301
+ self.parent.run_all_teardown_blocks(binding) if am_subcontext?
302
+ end
303
+
304
+ def print_should_eventuallys
305
+ should_eventuallys.each do |should|
306
+ test_name = [full_name, "should", "#{should[:name]}. "].flatten.join(' ')
307
+ puts " * DEFERRED: " + test_name
308
+ end
309
+ end
310
+
311
+ def build
312
+ shoulds.each do |should|
313
+ create_test_from_should_hash(should)
314
+ end
315
+
316
+ subcontexts.each { |context| context.build }
317
+
318
+ print_should_eventuallys
319
+ end
320
+
321
+ def method_missing(method, *args, &blk)
322
+ test_unit_class.send(method, *args, &blk)
323
+ end
324
+
325
+ end
326
+ end
@@ -0,0 +1,199 @@
1
+ module Shoulda # :nodoc:
2
+ module Controller # :nodoc:
3
+ module HTML # :nodoc: all
4
+ def self.included(other)
5
+ other.class_eval do
6
+ extend Shoulda::Controller::HTML::ClassMethods
7
+ end
8
+ end
9
+
10
+ module ClassMethods
11
+ def controller_name_from_class
12
+ self.name.gsub(/Test/, '')
13
+ end
14
+
15
+ def make_show_html_tests(res)
16
+ context "on GET to #{controller_name_from_class}#show" do
17
+ setup do
18
+ record = get_existing_record(res)
19
+ parent_params = make_parent_params(res, record)
20
+ get :show, parent_params.merge({ res.identifier => record.to_param })
21
+ end
22
+
23
+ if res.denied.actions.include?(:show)
24
+ should_not_assign_to res.object
25
+ should_redirect_to res.denied.redirect
26
+ should_set_the_flash_to res.denied.flash
27
+ else
28
+ should_assign_to res.object
29
+ should_respond_with :success
30
+ should_render_template :show
31
+ should_not_set_the_flash
32
+ end
33
+ end
34
+ end
35
+
36
+ def make_edit_html_tests(res)
37
+ context "on GET to #{controller_name_from_class}#edit" do
38
+ setup do
39
+ @record = get_existing_record(res)
40
+ parent_params = make_parent_params(res, @record)
41
+ get :edit, parent_params.merge({ res.identifier => @record.to_param })
42
+ end
43
+
44
+ if res.denied.actions.include?(:edit)
45
+ should_not_assign_to res.object
46
+ should_redirect_to res.denied.redirect
47
+ should_set_the_flash_to res.denied.flash
48
+ else
49
+ should_assign_to res.object
50
+ should_respond_with :success
51
+ should_render_template :edit
52
+ should_not_set_the_flash
53
+ should_render_a_form
54
+ should "set @#{res.object} to requested instance" do
55
+ assert_equal @record, assigns(res.object)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def make_index_html_tests(res)
62
+ context "on GET to #{controller_name_from_class}#index" do
63
+ setup do
64
+ record = get_existing_record(res) rescue nil
65
+ parent_params = make_parent_params(res, record)
66
+ get(:index, parent_params)
67
+ end
68
+
69
+ if res.denied.actions.include?(:index)
70
+ should_not_assign_to res.object.to_s.pluralize
71
+ should_redirect_to res.denied.redirect
72
+ should_set_the_flash_to res.denied.flash
73
+ else
74
+ should_respond_with :success
75
+ should_assign_to res.object.to_s.pluralize
76
+ should_render_template :index
77
+ should_not_set_the_flash
78
+ end
79
+ end
80
+ end
81
+
82
+ def make_new_html_tests(res)
83
+ context "on GET to #{controller_name_from_class}#new" do
84
+ setup do
85
+ record = get_existing_record(res) rescue nil
86
+ parent_params = make_parent_params(res, record)
87
+ get(:new, parent_params)
88
+ end
89
+
90
+ if res.denied.actions.include?(:new)
91
+ should_not_assign_to res.object
92
+ should_redirect_to res.denied.redirect
93
+ should_set_the_flash_to res.denied.flash
94
+ else
95
+ should_respond_with :success
96
+ should_assign_to res.object
97
+ should_not_set_the_flash
98
+ should_render_template :new
99
+ should_render_a_form
100
+ end
101
+ end
102
+ end
103
+
104
+ def make_destroy_html_tests(res)
105
+ context "on DELETE to #{controller_name_from_class}#destroy" do
106
+ setup do
107
+ @record = get_existing_record(res)
108
+ parent_params = make_parent_params(res, @record)
109
+ delete :destroy, parent_params.merge({ res.identifier => @record.to_param })
110
+ end
111
+
112
+ if res.denied.actions.include?(:destroy)
113
+ should_redirect_to res.denied.redirect
114
+ should_set_the_flash_to res.denied.flash
115
+
116
+ should "not destroy record" do
117
+ assert_nothing_raised { assert @record.reload }
118
+ end
119
+ else
120
+ should_set_the_flash_to res.destroy.flash
121
+ if res.destroy.redirect.is_a? Symbol
122
+ should_respond_with res.destroy.redirect
123
+ else
124
+ should_redirect_to res.destroy.redirect
125
+ end
126
+
127
+ should "destroy record" do
128
+ assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
129
+ @record.reload
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ def make_create_html_tests(res)
137
+ context "on POST to #{controller_name_from_class}#create with #{res.create.params.inspect}" do
138
+ setup do
139
+ record = get_existing_record(res) rescue nil
140
+ parent_params = make_parent_params(res, record)
141
+ @count = res.klass.count
142
+ post :create, parent_params.merge(res.object => res.create.params)
143
+ end
144
+
145
+ if res.denied.actions.include?(:create)
146
+ should_redirect_to res.denied.redirect
147
+ should_set_the_flash_to res.denied.flash
148
+ should_not_assign_to res.object
149
+
150
+ should "not create new record" do
151
+ assert_equal @count, res.klass.count
152
+ end
153
+ else
154
+ should_assign_to res.object
155
+ should_set_the_flash_to res.create.flash
156
+ if res.create.redirect.is_a? Symbol
157
+ should_respond_with res.create.redirect
158
+ else
159
+ should_redirect_to res.create.redirect
160
+ end
161
+
162
+ should "not have errors on @#{res.object}" do
163
+ assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ def make_update_html_tests(res)
170
+ context "on PUT to #{controller_name_from_class}#update with #{res.create.params.inspect}" do
171
+ setup do
172
+ @record = get_existing_record(res)
173
+ parent_params = make_parent_params(res, @record)
174
+ put :update, parent_params.merge(res.identifier => @record.to_param, res.object => res.update.params)
175
+ end
176
+
177
+ if res.denied.actions.include?(:update)
178
+ should_not_assign_to res.object
179
+ should_redirect_to res.denied.redirect
180
+ should_set_the_flash_to res.denied.flash
181
+ else
182
+ should_assign_to res.object
183
+ should_set_the_flash_to(res.update.flash)
184
+ if res.update.redirect.is_a? Symbol
185
+ should_respond_with res.update.redirect
186
+ else
187
+ should_redirect_to res.update.redirect
188
+ end
189
+
190
+ should "not have errors on @#{res.object}" do
191
+ assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end