shoulda 2.0.6 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/README.rdoc +35 -7
  2. data/Rakefile +5 -3
  3. data/lib/shoulda.rb +7 -15
  4. data/lib/shoulda/action_mailer.rb +1 -1
  5. data/lib/shoulda/action_mailer/assertions.rb +32 -33
  6. data/lib/shoulda/active_record.rb +6 -2
  7. data/lib/shoulda/active_record/assertions.rb +62 -81
  8. data/lib/shoulda/active_record/helpers.rb +40 -0
  9. data/lib/shoulda/active_record/macros.rb +518 -639
  10. data/lib/shoulda/active_record/matchers.rb +42 -0
  11. data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
  12. data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
  13. data/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
  14. data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
  15. data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
  16. data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
  17. data/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
  18. data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
  19. data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
  20. data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
  21. data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
  22. data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
  23. data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
  24. data/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
  25. data/lib/shoulda/assertions.rb +50 -40
  26. data/lib/shoulda/autoload_macros.rb +46 -0
  27. data/lib/shoulda/context.rb +124 -126
  28. data/lib/shoulda/controller.rb +8 -8
  29. data/lib/shoulda/controller/formats/html.rb +158 -160
  30. data/lib/shoulda/controller/formats/xml.rb +132 -134
  31. data/lib/shoulda/controller/helpers.rb +51 -53
  32. data/lib/shoulda/controller/macros.rb +278 -258
  33. data/lib/shoulda/controller/resource_options.rb +211 -214
  34. data/lib/shoulda/helpers.rb +5 -7
  35. data/lib/shoulda/macros.rb +63 -64
  36. data/lib/shoulda/private_helpers.rb +16 -18
  37. data/lib/shoulda/rails.rb +1 -8
  38. data/lib/shoulda/rspec.rb +5 -0
  39. data/lib/shoulda/tasks/list_tests.rake +6 -1
  40. data/lib/shoulda/test_unit.rb +19 -0
  41. data/rails/init.rb +1 -1
  42. data/test/README +2 -2
  43. data/test/fail_macros.rb +16 -16
  44. data/test/functional/posts_controller_test.rb +5 -2
  45. data/test/matchers/allow_mass_assignment_of_matcher_test.rb +68 -0
  46. data/test/matchers/allow_value_matcher_test.rb +41 -0
  47. data/test/matchers/association_matcher_test.rb +258 -0
  48. data/test/matchers/ensure_inclusion_of_matcher_test.rb +80 -0
  49. data/test/matchers/ensure_length_of_matcher_test.rb +158 -0
  50. data/test/matchers/have_db_column_matcher_test.rb +169 -0
  51. data/test/matchers/have_index_matcher_test.rb +74 -0
  52. data/test/matchers/have_named_scope_matcher_test.rb +65 -0
  53. data/test/matchers/have_readonly_attributes_matcher_test.rb +29 -0
  54. data/test/matchers/validate_acceptance_of_matcher_test.rb +44 -0
  55. data/test/matchers/validate_numericality_of_matcher_test.rb +52 -0
  56. data/test/matchers/validate_presence_of_matcher_test.rb +86 -0
  57. data/test/matchers/validate_uniqueness_of_matcher_test.rb +141 -0
  58. data/test/model_builder.rb +61 -0
  59. data/test/other/autoload_macro_test.rb +18 -0
  60. data/test/other/helpers_test.rb +58 -0
  61. data/test/other/private_helpers_test.rb +1 -1
  62. data/test/other/should_test.rb +16 -16
  63. data/test/rails_root/app/controllers/posts_controller.rb +6 -5
  64. data/test/rails_root/app/models/pets/dog.rb +10 -0
  65. data/test/rails_root/app/models/treat.rb +3 -0
  66. data/test/rails_root/app/models/user.rb +2 -2
  67. data/test/rails_root/app/views/layouts/posts.rhtml +2 -0
  68. data/test/rails_root/config/database.yml +1 -1
  69. data/test/rails_root/config/environments/{sqlite3.rb → test.rb} +0 -0
  70. data/test/rails_root/db/migrate/001_create_users.rb +3 -2
  71. data/test/rails_root/db/migrate/011_create_treats.rb +12 -0
  72. data/test/rails_root/log/test.log +0 -0
  73. data/test/rails_root/test/shoulda_macros/custom_macro.rb +6 -0
  74. data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +6 -0
  75. data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +6 -0
  76. data/test/test_helper.rb +3 -1
  77. data/test/unit/address_test.rb +1 -1
  78. data/test/unit/dog_test.rb +5 -2
  79. data/test/unit/post_test.rb +7 -3
  80. data/test/unit/product_test.rb +2 -2
  81. data/test/unit/tag_test.rb +2 -1
  82. data/test/unit/user_test.rb +17 -8
  83. metadata +44 -4
  84. data/test/rails_root/app/models/dog.rb +0 -5
@@ -6,10 +6,10 @@ require 'shoulda/controller/macros'
6
6
  module Test # :nodoc: all
7
7
  module Unit
8
8
  class TestCase
9
- extend ThoughtBot::Shoulda::Controller::Macros
10
- include ThoughtBot::Shoulda::Controller::Helpers
11
- ThoughtBot::Shoulda::Controller::VALID_FORMATS.each do |format|
12
- include "ThoughtBot::Shoulda::Controller::#{format.to_s.upcase}".constantize
9
+ extend Shoulda::Controller::Macros
10
+ include Shoulda::Controller::Helpers
11
+ Shoulda::Controller::VALID_FORMATS.each do |format|
12
+ include "Shoulda::Controller::#{format.to_s.upcase}".constantize
13
13
  end
14
14
  end
15
15
  end
@@ -21,10 +21,10 @@ require 'shoulda/action_mailer/assertions'
21
21
  module ActionController #:nodoc: all
22
22
  module Integration
23
23
  class Session
24
- include ThoughtBot::Shoulda::Assertions
25
- include ThoughtBot::Shoulda::Helpers
26
- include ThoughtBot::Shoulda::ActiveRecord::Assertions
27
- include ThoughtBot::Shoulda::ActionMailer::Assertions
24
+ include Shoulda::Assertions
25
+ include Shoulda::Helpers
26
+ include Shoulda::ActiveRecord::Assertions
27
+ include Shoulda::ActionMailer::Assertions
28
28
  end
29
29
  end
30
30
  end
@@ -1,196 +1,194 @@
1
- module ThoughtBot # :nodoc:
2
- module Shoulda # :nodoc:
3
- module Controller # :nodoc:
4
- module HTML # :nodoc: all
5
- def self.included(other)
6
- other.class_eval do
7
- extend ThoughtBot::Shoulda::Controller::HTML::ClassMethods
8
- end
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
9
7
  end
10
-
11
- module ClassMethods
12
- def controller_name_from_class
13
- self.name.gsub(/Test/, '')
14
- end
8
+ end
15
9
 
16
- def make_show_html_tests(res)
17
- context "on GET to #{controller_name_from_class}#show" do
18
- setup do
19
- record = get_existing_record(res)
20
- parent_params = make_parent_params(res, record)
21
- get :show, parent_params.merge({ res.identifier => record.to_param })
22
- end
10
+ module ClassMethods
11
+ def controller_name_from_class
12
+ self.name.gsub(/Test/, '')
13
+ end
23
14
 
24
- if res.denied.actions.include?(:show)
25
- should_not_assign_to res.object
26
- should_redirect_to res.denied.redirect
27
- should_set_the_flash_to res.denied.flash
28
- else
29
- should_assign_to res.object
30
- should_respond_with :success
31
- should_render_template :show
32
- should_not_set_the_flash
33
- end
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
34
32
  end
35
33
  end
34
+ end
36
35
 
37
- def make_edit_html_tests(res)
38
- context "on GET to #{controller_name_from_class}#edit" do
39
- setup do
40
- @record = get_existing_record(res)
41
- parent_params = make_parent_params(res, @record)
42
- get :edit, parent_params.merge({ res.identifier => @record.to_param })
43
- end
44
-
45
- if res.denied.actions.include?(:edit)
46
- should_not_assign_to res.object
47
- should_redirect_to res.denied.redirect
48
- should_set_the_flash_to res.denied.flash
49
- else
50
- should_assign_to res.object
51
- should_respond_with :success
52
- should_render_template :edit
53
- should_not_set_the_flash
54
- should_render_a_form
55
- should "set @#{res.object} to requested instance" do
56
- assert_equal @record, assigns(res.object)
57
- end
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)
58
56
  end
59
57
  end
60
58
  end
59
+ end
61
60
 
62
- def make_index_html_tests(res)
63
- context "on GET to #{controller_name_from_class}#index" do
64
- setup do
65
- record = get_existing_record(res) rescue nil
66
- parent_params = make_parent_params(res, record)
67
- get(:index, parent_params)
68
- end
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
69
68
 
70
- if res.denied.actions.include?(:index)
71
- should_not_assign_to res.object.to_s.pluralize
72
- should_redirect_to res.denied.redirect
73
- should_set_the_flash_to res.denied.flash
74
- else
75
- should_respond_with :success
76
- should_assign_to res.object.to_s.pluralize
77
- should_render_template :index
78
- should_not_set_the_flash
79
- end
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
80
78
  end
81
79
  end
80
+ end
82
81
 
83
- def make_new_html_tests(res)
84
- context "on GET to #{controller_name_from_class}#new" do
85
- setup do
86
- record = get_existing_record(res) rescue nil
87
- parent_params = make_parent_params(res, record)
88
- get(:new, parent_params)
89
- end
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
90
89
 
91
- if res.denied.actions.include?(:new)
92
- should_not_assign_to res.object
93
- should_redirect_to res.denied.redirect
94
- should_set_the_flash_to res.denied.flash
95
- else
96
- should_respond_with :success
97
- should_assign_to res.object
98
- should_not_set_the_flash
99
- should_render_template :new
100
- should_render_a_form
101
- end
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
102
100
  end
103
101
  end
102
+ end
104
103
 
105
- def make_destroy_html_tests(res)
106
- context "on DELETE to #{controller_name_from_class}#destroy" do
107
- setup do
108
- @record = get_existing_record(res)
109
- parent_params = make_parent_params(res, @record)
110
- delete :destroy, parent_params.merge({ res.identifier => @record.to_param })
111
- end
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
112
115
 
113
- if res.denied.actions.include?(:destroy)
114
- should_redirect_to res.denied.redirect
115
- should_set_the_flash_to res.denied.flash
116
-
117
- should "not destroy record" do
118
- assert_nothing_raised { assert @record.reload }
119
- end
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
120
123
  else
121
- should_set_the_flash_to res.destroy.flash
122
- if res.destroy.redirect.is_a? Symbol
123
- should_respond_with res.destroy.redirect
124
- else
125
- should_redirect_to res.destroy.redirect
126
- end
124
+ should_redirect_to res.destroy.redirect
125
+ end
127
126
 
128
- should "destroy record" do
129
- assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
130
- @record.reload
131
- end
127
+ should "destroy record" do
128
+ assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
129
+ @record.reload
132
130
  end
133
131
  end
134
132
  end
135
133
  end
134
+ end
136
135
 
137
- def make_create_html_tests(res)
138
- context "on POST to #{controller_name_from_class}#create with #{res.create.params.inspect}" do
139
- setup do
140
- record = get_existing_record(res) rescue nil
141
- parent_params = make_parent_params(res, record)
142
- @count = res.klass.count
143
- post :create, parent_params.merge(res.object => res.create.params)
144
- end
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
145
149
 
146
- if res.denied.actions.include?(:create)
147
- should_redirect_to res.denied.redirect
148
- should_set_the_flash_to res.denied.flash
149
- should_not_assign_to res.object
150
-
151
- should "not create new record" do
152
- assert_equal @count, res.klass.count
153
- end
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
154
158
  else
155
- should_assign_to res.object
156
- should_set_the_flash_to res.create.flash
157
- if res.create.redirect.is_a? Symbol
158
- should_respond_with res.create.redirect
159
- else
160
- should_redirect_to res.create.redirect
161
- end
159
+ should_redirect_to res.create.redirect
160
+ end
162
161
 
163
- should "not have errors on @#{res.object}" do
164
- assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
165
- end
166
- end
167
- end
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
168
166
  end
167
+ end
169
168
 
170
- def make_update_html_tests(res)
171
- context "on PUT to #{controller_name_from_class}#update with #{res.create.params.inspect}" do
172
- setup do
173
- @record = get_existing_record(res)
174
- parent_params = make_parent_params(res, @record)
175
- put :update, parent_params.merge(res.identifier => @record.to_param, res.object => res.update.params)
176
- end
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
177
176
 
178
- if res.denied.actions.include?(:update)
179
- should_not_assign_to res.object
180
- should_redirect_to res.denied.redirect
181
- should_set_the_flash_to res.denied.flash
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
182
186
  else
183
- should_assign_to res.object
184
- should_set_the_flash_to(res.update.flash)
185
- if res.update.redirect.is_a? Symbol
186
- should_respond_with res.update.redirect
187
- else
188
- should_redirect_to res.update.redirect
189
- end
190
-
191
- should "not have errors on @#{res.object}" do
192
- assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
193
- end
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:"
194
192
  end
195
193
  end
196
194
  end
@@ -1,170 +1,168 @@
1
- module ThoughtBot # :nodoc:
2
- module Shoulda # :nodoc:
3
- module Controller # :nodoc:
4
- module XML
5
- def self.included(other) #:nodoc:
6
- other.class_eval do
7
- extend ThoughtBot::Shoulda::Controller::XML::ClassMethods
8
- end
1
+ module Shoulda # :nodoc:
2
+ module Controller # :nodoc:
3
+ module XML
4
+ def self.included(other) #:nodoc:
5
+ other.class_eval do
6
+ extend Shoulda::Controller::XML::ClassMethods
9
7
  end
10
-
11
- module ClassMethods
12
- # Macro that creates a test asserting that the controller responded with an XML content-type
13
- # and that the XML contains +<name/>+ as the root element.
14
- def should_respond_with_xml_for(name = nil)
15
- should "have ContentType set to 'application/xml'" do
16
- assert_xml_response
17
- end
18
-
19
- if name
20
- should "return <#{name}/> as the root element" do
21
- body = @response.body.first(100).map {|l| " #{l}"}
22
- assert_select name.to_s.dasherize, 1, "Body:\n#{body}...\nDoes not have <#{name}/> as the root element."
23
- end
24
- end
8
+ end
9
+
10
+ module ClassMethods
11
+ # Macro that creates a test asserting that the controller responded with an XML content-type
12
+ # and that the XML contains +<name/>+ as the root element.
13
+ def should_respond_with_xml_for(name = nil)
14
+ should "have ContentType set to 'application/xml'" do
15
+ assert_xml_response
25
16
  end
26
- alias should_respond_with_xml should_respond_with_xml_for
27
17
 
28
- protected
29
-
30
- def make_show_xml_tests(res) # :nodoc:
31
- context "on GET to #{controller_name_from_class}#show as xml" do
32
- setup do
33
- request_xml
34
- record = get_existing_record(res)
35
- parent_params = make_parent_params(res, record)
36
- get :show, parent_params.merge({ res.identifier => record.to_param })
37
- end
38
-
39
- if res.denied.actions.include?(:show)
40
- should_not_assign_to res.object
41
- should_respond_with 401
42
- else
43
- should_assign_to res.object
44
- should_respond_with :success
45
- should_respond_with_xml_for res.object
46
- end
18
+ if name
19
+ should "return <#{name}/> as the root element" do
20
+ body = @response.body.first(100).map {|l| " #{l}"}
21
+ assert_select name.to_s.dasherize, 1, "Body:\n#{body}...\nDoes not have <#{name}/> as the root element."
47
22
  end
48
23
  end
24
+ end
25
+ alias should_respond_with_xml should_respond_with_xml_for
26
+
27
+ protected
28
+
29
+ def make_show_xml_tests(res) # :nodoc:
30
+ context "on GET to #{controller_name_from_class}#show as xml" do
31
+ setup do
32
+ request_xml
33
+ record = get_existing_record(res)
34
+ parent_params = make_parent_params(res, record)
35
+ get :show, parent_params.merge({ res.identifier => record.to_param })
36
+ end
49
37
 
50
- def make_edit_xml_tests(res) # :nodoc:
51
- # XML doesn't need an :edit action
38
+ if res.denied.actions.include?(:show)
39
+ should_not_assign_to res.object
40
+ should_respond_with 401
41
+ else
42
+ should_assign_to res.object
43
+ should_respond_with :success
44
+ should_respond_with_xml_for res.object
45
+ end
52
46
  end
47
+ end
53
48
 
54
- def make_new_xml_tests(res) # :nodoc:
55
- # XML doesn't need a :new action
56
- end
49
+ def make_edit_xml_tests(res) # :nodoc:
50
+ # XML doesn't need an :edit action
51
+ end
57
52
 
58
- def make_index_xml_tests(res) # :nodoc:
59
- context "on GET to #{controller_name_from_class}#index as xml" do
60
- setup do
61
- request_xml
62
- parent_params = make_parent_params(res)
63
- get(:index, parent_params)
64
- end
53
+ def make_new_xml_tests(res) # :nodoc:
54
+ # XML doesn't need a :new action
55
+ end
65
56
 
66
- if res.denied.actions.include?(:index)
67
- should_not_assign_to res.object.to_s.pluralize
68
- should_respond_with 401
69
- else
70
- should_respond_with :success
71
- should_respond_with_xml_for res.object.to_s.pluralize
72
- should_assign_to res.object.to_s.pluralize
73
- end
57
+ def make_index_xml_tests(res) # :nodoc:
58
+ context "on GET to #{controller_name_from_class}#index as xml" do
59
+ setup do
60
+ request_xml
61
+ parent_params = make_parent_params(res)
62
+ get(:index, parent_params)
63
+ end
64
+
65
+ if res.denied.actions.include?(:index)
66
+ should_not_assign_to res.object.to_s.pluralize
67
+ should_respond_with 401
68
+ else
69
+ should_respond_with :success
70
+ should_respond_with_xml_for res.object.to_s.pluralize
71
+ should_assign_to res.object.to_s.pluralize
74
72
  end
75
73
  end
74
+ end
76
75
 
77
- def make_destroy_xml_tests(res) # :nodoc:
78
- context "on DELETE to #{controller_name_from_class}#destroy as xml" do
79
- setup do
80
- request_xml
81
- @record = get_existing_record(res)
82
- parent_params = make_parent_params(res, @record)
83
- delete :destroy, parent_params.merge({ res.identifier => @record.to_param })
84
- end
76
+ def make_destroy_xml_tests(res) # :nodoc:
77
+ context "on DELETE to #{controller_name_from_class}#destroy as xml" do
78
+ setup do
79
+ request_xml
80
+ @record = get_existing_record(res)
81
+ parent_params = make_parent_params(res, @record)
82
+ delete :destroy, parent_params.merge({ res.identifier => @record.to_param })
83
+ end
84
+
85
+ if res.denied.actions.include?(:destroy)
86
+ should_respond_with 401
85
87
 
86
- if res.denied.actions.include?(:destroy)
87
- should_respond_with 401
88
-
89
- should "not destroy record" do
90
- assert @record.reload
91
- end
92
- else
93
- should "destroy record" do
94
- assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
95
- @record.reload
96
- end
88
+ should "not destroy record" do
89
+ assert @record.reload
90
+ end
91
+ else
92
+ should "destroy record" do
93
+ assert_raises(::ActiveRecord::RecordNotFound, "@#{res.object} was not destroyed.") do
94
+ @record.reload
97
95
  end
98
96
  end
99
97
  end
100
98
  end
99
+ end
101
100
 
102
- def make_create_xml_tests(res) # :nodoc:
103
- context "on POST to #{controller_name_from_class}#create as xml" do
104
- setup do
105
- request_xml
106
- parent_params = make_parent_params(res)
107
- @count = res.klass.count
108
- post :create, parent_params.merge(res.object => res.create.params)
109
- end
101
+ def make_create_xml_tests(res) # :nodoc:
102
+ context "on POST to #{controller_name_from_class}#create as xml" do
103
+ setup do
104
+ request_xml
105
+ parent_params = make_parent_params(res)
106
+ @count = res.klass.count
107
+ post :create, parent_params.merge(res.object => res.create.params)
108
+ end
109
+
110
+ if res.denied.actions.include?(:create)
111
+ should_respond_with 401
112
+ should_not_assign_to res.object
110
113
 
111
- if res.denied.actions.include?(:create)
112
- should_respond_with 401
113
- should_not_assign_to res.object
114
-
115
- should "not create new record" do
116
- assert_equal @count, res.klass.count
117
- end
118
- else
119
- should_assign_to res.object
114
+ should "not create new record" do
115
+ assert_equal @count, res.klass.count
116
+ end
117
+ else
118
+ should_assign_to res.object
120
119
 
121
- should "not have errors on @#{res.object}" do
122
- assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
123
- end
124
- end
125
- end
120
+ should "not have errors on @#{res.object}" do
121
+ assert_equal [], pretty_error_messages(assigns(res.object)), "@#{res.object} has errors:"
122
+ end
123
+ end
126
124
  end
125
+ end
127
126
 
128
- def make_update_xml_tests(res) # :nodoc:
129
- context "on PUT to #{controller_name_from_class}#update as xml" do
130
- setup do
131
- request_xml
132
- @record = get_existing_record(res)
133
- parent_params = make_parent_params(res, @record)
134
- put :update, parent_params.merge(res.identifier => @record.to_param, res.object => res.update.params)
135
- end
127
+ def make_update_xml_tests(res) # :nodoc:
128
+ context "on PUT to #{controller_name_from_class}#update as xml" do
129
+ setup do
130
+ request_xml
131
+ @record = get_existing_record(res)
132
+ parent_params = make_parent_params(res, @record)
133
+ put :update, parent_params.merge(res.identifier => @record.to_param, res.object => res.update.params)
134
+ end
136
135
 
137
- if res.denied.actions.include?(:update)
138
- should_not_assign_to res.object
139
- should_respond_with 401
140
- else
141
- should_assign_to res.object
136
+ if res.denied.actions.include?(:update)
137
+ should_not_assign_to res.object
138
+ should_respond_with 401
139
+ else
140
+ should_assign_to res.object
142
141
 
143
- should "not have errors on @#{res.object}" do
144
- assert_equal [], assigns(res.object).errors.full_messages, "@#{res.object} has errors:"
145
- end
142
+ should "not have errors on @#{res.object}" do
143
+ assert_equal [], assigns(res.object).errors.full_messages, "@#{res.object} has errors:"
146
144
  end
147
145
  end
148
146
  end
149
147
  end
148
+ end
150
149
 
151
- # Sets the next request's format to 'application/xml'
152
- def request_xml
153
- @request.accept = "application/xml"
154
- end
155
-
156
- # Asserts that the controller's response was 'application/xml'
157
- def assert_xml_response
158
- content_type = (@response.headers["Content-Type"] || @response.headers["type"]).to_s
159
- regex = %r{\bapplication/xml\b}
150
+ # Sets the next request's format to 'application/xml'
151
+ def request_xml
152
+ @request.accept = "application/xml"
153
+ end
154
+
155
+ # Asserts that the controller's response was 'application/xml'
156
+ def assert_xml_response
157
+ content_type = (@response.headers["Content-Type"] || @response.headers["type"]).to_s
158
+ regex = %r{\bapplication/xml\b}
160
159
 
161
- msg = "Content Type '#{content_type.inspect}' doesn't match '#{regex.inspect}'\n"
162
- msg += "Body: #{@response.body.first(100).chomp} ..."
160
+ msg = "Content Type '#{content_type.inspect}' doesn't match '#{regex.inspect}'\n"
161
+ msg += "Body: #{@response.body.first(100).chomp} ..."
163
162
 
164
- assert_match regex, content_type, msg
165
- end
166
-
163
+ assert_match regex, content_type, msg
167
164
  end
165
+
168
166
  end
169
167
  end
170
168
  end