shoulda 2.0.6 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +35 -7
- data/Rakefile +5 -3
- data/lib/shoulda.rb +7 -15
- data/lib/shoulda/action_mailer.rb +1 -1
- data/lib/shoulda/action_mailer/assertions.rb +32 -33
- data/lib/shoulda/active_record.rb +6 -2
- data/lib/shoulda/active_record/assertions.rb +62 -81
- data/lib/shoulda/active_record/helpers.rb +40 -0
- data/lib/shoulda/active_record/macros.rb +518 -639
- data/lib/shoulda/active_record/matchers.rb +42 -0
- data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +83 -0
- data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +102 -0
- data/lib/shoulda/active_record/matchers/association_matcher.rb +226 -0
- data/lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb +87 -0
- data/lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb +141 -0
- data/lib/shoulda/active_record/matchers/have_db_column_matcher.rb +169 -0
- data/lib/shoulda/active_record/matchers/have_index_matcher.rb +105 -0
- data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +125 -0
- data/lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb +59 -0
- data/lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb +41 -0
- data/lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb +39 -0
- data/lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb +60 -0
- data/lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb +148 -0
- data/lib/shoulda/active_record/matchers/validation_matcher.rb +56 -0
- data/lib/shoulda/assertions.rb +50 -40
- data/lib/shoulda/autoload_macros.rb +46 -0
- data/lib/shoulda/context.rb +124 -126
- data/lib/shoulda/controller.rb +8 -8
- data/lib/shoulda/controller/formats/html.rb +158 -160
- data/lib/shoulda/controller/formats/xml.rb +132 -134
- data/lib/shoulda/controller/helpers.rb +51 -53
- data/lib/shoulda/controller/macros.rb +278 -258
- data/lib/shoulda/controller/resource_options.rb +211 -214
- data/lib/shoulda/helpers.rb +5 -7
- data/lib/shoulda/macros.rb +63 -64
- data/lib/shoulda/private_helpers.rb +16 -18
- data/lib/shoulda/rails.rb +1 -8
- data/lib/shoulda/rspec.rb +5 -0
- data/lib/shoulda/tasks/list_tests.rake +6 -1
- data/lib/shoulda/test_unit.rb +19 -0
- data/rails/init.rb +1 -1
- data/test/README +2 -2
- data/test/fail_macros.rb +16 -16
- data/test/functional/posts_controller_test.rb +5 -2
- data/test/matchers/allow_mass_assignment_of_matcher_test.rb +68 -0
- data/test/matchers/allow_value_matcher_test.rb +41 -0
- data/test/matchers/association_matcher_test.rb +258 -0
- data/test/matchers/ensure_inclusion_of_matcher_test.rb +80 -0
- data/test/matchers/ensure_length_of_matcher_test.rb +158 -0
- data/test/matchers/have_db_column_matcher_test.rb +169 -0
- data/test/matchers/have_index_matcher_test.rb +74 -0
- data/test/matchers/have_named_scope_matcher_test.rb +65 -0
- data/test/matchers/have_readonly_attributes_matcher_test.rb +29 -0
- data/test/matchers/validate_acceptance_of_matcher_test.rb +44 -0
- data/test/matchers/validate_numericality_of_matcher_test.rb +52 -0
- data/test/matchers/validate_presence_of_matcher_test.rb +86 -0
- data/test/matchers/validate_uniqueness_of_matcher_test.rb +141 -0
- data/test/model_builder.rb +61 -0
- data/test/other/autoload_macro_test.rb +18 -0
- data/test/other/helpers_test.rb +58 -0
- data/test/other/private_helpers_test.rb +1 -1
- data/test/other/should_test.rb +16 -16
- data/test/rails_root/app/controllers/posts_controller.rb +6 -5
- data/test/rails_root/app/models/pets/dog.rb +10 -0
- data/test/rails_root/app/models/treat.rb +3 -0
- data/test/rails_root/app/models/user.rb +2 -2
- data/test/rails_root/app/views/layouts/posts.rhtml +2 -0
- data/test/rails_root/config/database.yml +1 -1
- data/test/rails_root/config/environments/{sqlite3.rb → test.rb} +0 -0
- data/test/rails_root/db/migrate/001_create_users.rb +3 -2
- data/test/rails_root/db/migrate/011_create_treats.rb +12 -0
- data/test/rails_root/log/test.log +0 -0
- data/test/rails_root/test/shoulda_macros/custom_macro.rb +6 -0
- data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +6 -0
- data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +6 -0
- data/test/test_helper.rb +3 -1
- data/test/unit/address_test.rb +1 -1
- data/test/unit/dog_test.rb +5 -2
- data/test/unit/post_test.rb +7 -3
- data/test/unit/product_test.rb +2 -2
- data/test/unit/tag_test.rb +2 -1
- data/test/unit/user_test.rb +17 -8
- metadata +44 -4
- data/test/rails_root/app/models/dog.rb +0 -5
data/lib/shoulda/controller.rb
CHANGED
@@ -6,10 +6,10 @@ require 'shoulda/controller/macros'
|
|
6
6
|
module Test # :nodoc: all
|
7
7
|
module Unit
|
8
8
|
class TestCase
|
9
|
-
extend
|
10
|
-
include
|
11
|
-
|
12
|
-
include "
|
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
|
25
|
-
include
|
26
|
-
include
|
27
|
-
include
|
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
|
2
|
-
module
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
-
|
156
|
-
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
2
|
-
module
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
51
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
49
|
+
def make_edit_xml_tests(res) # :nodoc:
|
50
|
+
# XML doesn't need an :edit action
|
51
|
+
end
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
-
|
144
|
-
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
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
|
-
|
162
|
-
|
160
|
+
msg = "Content Type '#{content_type.inspect}' doesn't match '#{regex.inspect}'\n"
|
161
|
+
msg += "Body: #{@response.body.first(100).chomp} ..."
|
163
162
|
|
164
|
-
|
165
|
-
end
|
166
|
-
|
163
|
+
assert_match regex, content_type, msg
|
167
164
|
end
|
165
|
+
|
168
166
|
end
|
169
167
|
end
|
170
168
|
end
|