shoulda 2.10.1 → 2.10.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTION_GUIDELINES.rdoc +4 -6
- data/README.rdoc +14 -12
- data/lib/shoulda.rb +1 -1
- data/lib/shoulda/action_controller.rb +0 -2
- data/lib/shoulda/action_controller/macros.rb +38 -75
- data/lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb +4 -0
- data/lib/shoulda/action_controller/matchers/set_session_matcher.rb +1 -1
- data/lib/shoulda/action_view/macros.rb +6 -1
- data/lib/shoulda/active_record/assertions.rb +4 -4
- data/lib/shoulda/active_record/helpers.rb +0 -13
- data/lib/shoulda/active_record/macros.rb +50 -127
- data/lib/shoulda/active_record/matchers.rb +2 -1
- data/lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb +1 -1
- data/lib/shoulda/active_record/matchers/allow_value_matcher.rb +5 -5
- data/lib/shoulda/active_record/matchers/association_matcher.rb +3 -3
- data/lib/shoulda/active_record/matchers/{have_index_matcher.rb → have_db_index_matcher.rb} +15 -8
- data/lib/shoulda/active_record/matchers/have_named_scope_matcher.rb +3 -0
- data/lib/shoulda/active_record/matchers/validate_format_of_matcher.rb +67 -0
- data/lib/shoulda/active_record/matchers/validation_matcher.rb +1 -0
- data/lib/shoulda/assertions.rb +18 -6
- data/lib/shoulda/context.rb +99 -1
- data/lib/shoulda/macros.rb +83 -23
- data/lib/shoulda/private_helpers.rb +1 -8
- data/lib/shoulda/test_unit.rb +3 -0
- data/test/fail_macros.rb +6 -1
- data/test/functional/posts_controller_test.rb +17 -21
- data/test/functional/users_controller_test.rb +1 -1
- data/test/matchers/active_record/allow_mass_assignment_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/allow_value_matcher_test.rb +24 -1
- data/test/matchers/active_record/association_matcher_test.rb +8 -3
- data/test/matchers/active_record/ensure_inclusion_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/ensure_length_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/have_db_column_matcher_test.rb +1 -1
- data/test/matchers/active_record/{have_index_matcher_test.rb → have_db_index_matcher_test.rb} +24 -7
- data/test/matchers/active_record/have_named_scope_matcher_test.rb +1 -1
- data/test/matchers/active_record/have_readonly_attributes_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_acceptance_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_format_of_matcher_test.rb +39 -0
- data/test/matchers/active_record/validate_numericality_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_presence_of_matcher_test.rb +1 -1
- data/test/matchers/active_record/validate_uniqueness_of_matcher_test.rb +1 -1
- data/test/matchers/controller/assign_to_matcher_test.rb +1 -1
- data/test/matchers/controller/filter_param_matcher_test.rb +1 -1
- data/test/matchers/controller/render_with_layout_matcher_test.rb +1 -1
- data/test/matchers/controller/respond_with_content_type_matcher_test.rb +12 -7
- data/test/matchers/controller/respond_with_matcher_test.rb +1 -1
- data/test/matchers/controller/route_matcher_test.rb +1 -1
- data/test/matchers/controller/set_session_matcher_test.rb +9 -2
- data/test/matchers/controller/set_the_flash_matcher.rb +1 -1
- data/test/model_builder.rb +1 -1
- data/test/other/autoload_macro_test.rb +1 -1
- data/test/other/context_test.rb +45 -1
- data/test/other/convert_to_should_syntax_test.rb +3 -3
- data/test/other/helpers_test.rb +102 -3
- data/test/other/private_helpers_test.rb +6 -8
- data/test/other/should_test.rb +8 -3
- data/test/rails_root/app/controllers/{application.rb → application_controller.rb} +0 -0
- data/test/rails_root/app/controllers/posts_controller.rb +1 -0
- data/test/rails_root/app/models/pets/cat.rb +7 -0
- data/test/rails_root/app/models/profile.rb +2 -0
- data/test/rails_root/app/models/registration.rb +2 -0
- data/test/rails_root/app/models/user.rb +3 -0
- data/test/rails_root/config/boot.rb +6 -5
- data/test/rails_root/config/environment.rb +5 -1
- data/test/rails_root/db/migrate/20090506203502_create_profiles.rb +12 -0
- data/test/rails_root/db/migrate/20090506203536_create_registrations.rb +14 -0
- data/test/rails_root/db/migrate/20090513104502_create_cats.rb +12 -0
- data/test/rails_root/test/shoulda_macros/custom_macro.rb +1 -1
- data/test/rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +1 -1
- data/test/rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +1 -1
- data/test/rspec_test.rb +1 -1
- data/test/test_helper.rb +3 -10
- data/test/unit/address_test.rb +2 -2
- data/test/unit/cat_test.rb +7 -0
- data/test/unit/dog_test.rb +2 -3
- data/test/unit/flea_test.rb +1 -1
- data/test/unit/post_test.rb +2 -2
- data/test/unit/product_test.rb +2 -6
- data/test/unit/tag_test.rb +2 -2
- data/test/unit/tagging_test.rb +1 -1
- data/test/unit/user_test.rb +18 -8
- metadata +15 -9
- data/lib/shoulda/action_controller/helpers.rb +0 -47
- data/test/rails_root/log/sqlite3.log +0 -0
- data/test/rails_root/log/test.log +0 -0
@@ -7,14 +7,7 @@ module Shoulda # :nodoc:
|
|
7
7
|
opts = (args.last.is_a?(Hash) ? args.pop : {})
|
8
8
|
wanted.each {|w| ret << opts.delete(w)}
|
9
9
|
raise ArgumentError, "Unsupported options given: #{opts.keys.join(', ')}" unless opts.keys.empty?
|
10
|
-
return
|
11
|
-
end
|
12
|
-
|
13
|
-
# Returns the model class constant, as determined by the test class name.
|
14
|
-
#
|
15
|
-
# class TestUser; model_class; end => User
|
16
|
-
def model_class
|
17
|
-
self.name.gsub(/Test$/, '').constantize
|
10
|
+
return wanted.size == 1 ? ret.first : ret
|
18
11
|
end
|
19
12
|
end
|
20
13
|
end
|
data/lib/shoulda/test_unit.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
1
3
|
require 'shoulda/context'
|
2
4
|
require 'shoulda/proc_extensions'
|
3
5
|
require 'shoulda/assertions'
|
@@ -9,6 +11,7 @@ require 'shoulda/rails' if defined? RAILS_ROOT
|
|
9
11
|
module Test # :nodoc: all
|
10
12
|
module Unit
|
11
13
|
class TestCase
|
14
|
+
include Shoulda::InstanceMethods
|
12
15
|
extend Shoulda::ClassMethods
|
13
16
|
include Shoulda::Assertions
|
14
17
|
extend Shoulda::Macros
|
data/test/fail_macros.rb
CHANGED
@@ -13,7 +13,12 @@ module Shoulda
|
|
13
13
|
# end
|
14
14
|
def should_fail(&block)
|
15
15
|
context "should fail when trying to run:" do
|
16
|
-
|
16
|
+
if defined?(Test::Unit::AssertionFailedError)
|
17
|
+
failures = [Test::Unit::AssertionFailedError]
|
18
|
+
elsif defined?(MiniTest::Assertion)
|
19
|
+
failures = [MiniTest::Assertion]
|
20
|
+
end
|
21
|
+
Shoulda.expected_exceptions = failures
|
17
22
|
yield block
|
18
23
|
Shoulda.expected_exceptions = nil
|
19
24
|
end
|
@@ -4,7 +4,7 @@ require 'posts_controller'
|
|
4
4
|
# Re-raise errors caught by the controller.
|
5
5
|
class PostsController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
|
-
class PostsControllerTest <
|
7
|
+
class PostsControllerTest < ActionController::TestCase
|
8
8
|
fixtures :all
|
9
9
|
|
10
10
|
def setup
|
@@ -43,14 +43,12 @@ class PostsControllerTest < Test::Unit::TestCase
|
|
43
43
|
get :index, :user_id => users(:first)
|
44
44
|
end
|
45
45
|
should_respond_with :success
|
46
|
-
should_assign_to :user, :class => User
|
46
|
+
should_assign_to :user, :class => User
|
47
|
+
should_render_template :index
|
47
48
|
should_assign_to(:user) { users(:first) }
|
48
49
|
should_fail do
|
49
50
|
should_assign_to :user, :class => Post
|
50
51
|
end
|
51
|
-
should_fail do
|
52
|
-
should_assign_to :user, :equals => 'posts(:first)'
|
53
|
-
end
|
54
52
|
should_fail do
|
55
53
|
should_assign_to(:user) { posts(:first) }
|
56
54
|
end
|
@@ -69,20 +67,11 @@ class PostsControllerTest < Test::Unit::TestCase
|
|
69
67
|
should_respond_with_content_type 'application/rss+xml'
|
70
68
|
should_respond_with_content_type :rss
|
71
69
|
should_respond_with_content_type /rss/
|
72
|
-
context "deprecated" do # to avoid redefining a test
|
73
|
-
should_return_from_session :special, "'$2 off your next purchase'"
|
74
|
-
end
|
75
|
-
should_fail do
|
76
|
-
should_return_from_session :special, "'not special'"
|
77
|
-
end
|
78
70
|
should_set_session(:mischief) { nil }
|
79
|
-
|
80
|
-
should_set_session
|
81
|
-
should_set_session
|
82
|
-
|
83
|
-
should_set_session(:special_user_id) { @user.id }
|
84
|
-
end
|
85
|
-
should_fail do # to avoid redefining a test
|
71
|
+
should_set_session(:special) { '$2 off your next purchase' }
|
72
|
+
should_set_session(:special_user_id) { @user.id }
|
73
|
+
should_set_session(:false_var) { false }
|
74
|
+
should_fail do
|
86
75
|
should_set_session(:special_user_id) { 'value' }
|
87
76
|
end
|
88
77
|
should_assign_to :user, :posts
|
@@ -96,11 +85,17 @@ class PostsControllerTest < Test::Unit::TestCase
|
|
96
85
|
should_render_with_layout :wide
|
97
86
|
end
|
98
87
|
should_assign_to :false_flag
|
88
|
+
should_set_the_flash_to nil
|
89
|
+
should_fail do
|
90
|
+
should_set_the_flash_to /.*/
|
91
|
+
end
|
99
92
|
end
|
100
93
|
|
101
94
|
context "on GET to #new" do
|
102
95
|
setup { get :new, :user_id => users(:first) }
|
103
96
|
should_render_without_layout
|
97
|
+
should_not_set_the_flash
|
98
|
+
should_render_a_form
|
104
99
|
end
|
105
100
|
|
106
101
|
context "on POST to #create" do
|
@@ -110,14 +105,15 @@ class PostsControllerTest < Test::Unit::TestCase
|
|
110
105
|
:body => 'blah blah blah' }
|
111
106
|
end
|
112
107
|
|
113
|
-
should_redirect_to 'user_post_url(@post.user, @post)'
|
114
108
|
should_redirect_to('the created post') { user_post_url(users(:first),
|
115
109
|
assigns(:post)) }
|
116
110
|
should_fail do
|
117
|
-
should_redirect_to
|
111
|
+
should_redirect_to('elsewhere') { user_posts_url(users(:first)) }
|
118
112
|
end
|
113
|
+
|
114
|
+
should_set_the_flash_to /success/
|
119
115
|
should_fail do
|
120
|
-
|
116
|
+
should_not_set_the_flash
|
121
117
|
end
|
122
118
|
end
|
123
119
|
end
|
@@ -4,7 +4,7 @@ require 'users_controller'
|
|
4
4
|
# Re-raise errors caught by the controller.
|
5
5
|
class UsersController; def rescue_action(e) raise e end; end
|
6
6
|
|
7
|
-
class UsersControllerTest <
|
7
|
+
class UsersControllerTest < ActionController::TestCase
|
8
8
|
fixtures :all
|
9
9
|
|
10
10
|
def setup
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class AllowMassAssignmentOfMatcherTest <
|
3
|
+
class AllowMassAssignmentOfMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "an attribute that is blacklisted from mass-assignment" do
|
6
6
|
setup do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class AllowValueMatcherTest <
|
3
|
+
class AllowValueMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "an attribute with a format validation" do
|
6
6
|
setup do
|
@@ -38,4 +38,27 @@ class AllowValueMatcherTest < Test::Unit::TestCase # :nodoc:
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
context "an attribute with several validations" do
|
42
|
+
setup do
|
43
|
+
define_model :example, :attr => :string do
|
44
|
+
validates_presence_of :attr
|
45
|
+
validates_length_of :attr, :within => 1..5
|
46
|
+
validates_numericality_of :attr, :greater_than_or_equal_to => 1,
|
47
|
+
:less_than_or_equal_to => 50000
|
48
|
+
end
|
49
|
+
@model = Example.new
|
50
|
+
end
|
51
|
+
|
52
|
+
should "allow a good value" do
|
53
|
+
assert_accepts allow_value("12345").for(:attr), @model
|
54
|
+
end
|
55
|
+
|
56
|
+
bad_values = [nil, "", "abc", "0", "50001", "123456"]
|
57
|
+
bad_values.each do |value|
|
58
|
+
should "not allow a bad value (#{value.inspect})" do
|
59
|
+
assert_rejects allow_value(value).for(:attr), @model
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
41
64
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class AssociationMatcherTest <
|
3
|
+
class AssociationMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "belong_to" do
|
6
6
|
setup do
|
@@ -126,7 +126,9 @@ class AssociationMatcherTest < Test::Unit::TestCase # :nodoc:
|
|
126
126
|
define_model :parent do
|
127
127
|
has_many :children
|
128
128
|
end
|
129
|
-
assert_rejects @matcher.through(:conceptions),
|
129
|
+
assert_rejects @matcher.through(:conceptions),
|
130
|
+
Parent.new,
|
131
|
+
:message => /does not have any relationship to conceptions/
|
130
132
|
end
|
131
133
|
|
132
134
|
should "reject an association that has the wrong :through option" do
|
@@ -137,9 +139,12 @@ class AssociationMatcherTest < Test::Unit::TestCase # :nodoc:
|
|
137
139
|
end
|
138
140
|
define_model :parent do
|
139
141
|
has_many :conceptions
|
142
|
+
has_many :relationships
|
140
143
|
has_many :children, :through => :conceptions
|
141
144
|
end
|
142
|
-
assert_rejects @matcher.through(:relationships),
|
145
|
+
assert_rejects @matcher.through(:relationships),
|
146
|
+
Parent.new,
|
147
|
+
:message => /through relationships, but got it through conceptions/
|
143
148
|
end
|
144
149
|
|
145
150
|
should "accept an association with a valid :dependent option" do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class EnsureInclusionOfMatcherTest <
|
3
|
+
class EnsureInclusionOfMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "an attribute which must be included in a range" do
|
6
6
|
setup do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class EnsureLengthOfMatcher <
|
3
|
+
class EnsureLengthOfMatcher < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "an attribute with a non-zero minimum length validation" do
|
6
6
|
setup do
|
data/test/matchers/active_record/{have_index_matcher_test.rb → have_db_index_matcher_test.rb}
RENAMED
@@ -1,10 +1,10 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class
|
3
|
+
class HaveDbIndexMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
|
-
context "
|
5
|
+
context "have_db_index" do
|
6
6
|
setup do
|
7
|
-
@matcher =
|
7
|
+
@matcher = have_db_index(:age)
|
8
8
|
end
|
9
9
|
|
10
10
|
should "accept an existing index" do
|
@@ -22,9 +22,9 @@ class HaveIndexMatcherTest < Test::Unit::TestCase # :nodoc:
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
context "
|
25
|
+
context "have_db_index with unique option" do
|
26
26
|
setup do
|
27
|
-
@matcher =
|
27
|
+
@matcher = have_db_index(:ssn).unique(true)
|
28
28
|
end
|
29
29
|
|
30
30
|
should "accept an index of correct unique" do
|
@@ -46,9 +46,9 @@ class HaveIndexMatcherTest < Test::Unit::TestCase # :nodoc:
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context "
|
49
|
+
context "have_db_index on multiple columns" do
|
50
50
|
setup do
|
51
|
-
@matcher =
|
51
|
+
@matcher = have_db_index([:geocodable_type, :geocodable_id])
|
52
52
|
end
|
53
53
|
|
54
54
|
should "accept an existing index" do
|
@@ -70,5 +70,22 @@ class HaveIndexMatcherTest < Test::Unit::TestCase # :nodoc:
|
|
70
70
|
assert_rejects @matcher, Geocoding.new
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
should "join columns with and describing multiple columns" do
|
75
|
+
assert_match /on columns user_id and post_id/,
|
76
|
+
have_db_index([:user_id, :post_id]).description
|
77
|
+
end
|
78
|
+
|
79
|
+
should "describe a unique index as unique" do
|
80
|
+
assert_match /a unique index/, have_db_index(:user_id).unique(true).description
|
81
|
+
end
|
82
|
+
|
83
|
+
should "describe a non-unique index as non-unique" do
|
84
|
+
assert_match /a non-unique index/, have_db_index(:user_id).unique(false).description
|
85
|
+
end
|
86
|
+
|
87
|
+
should "not describe an index's uniqueness when it isn't important" do
|
88
|
+
assert_no_match /unique/, have_db_index(:user_id).description
|
89
|
+
end
|
73
90
|
|
74
91
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class HaveReadonlyAttributesMatcherTest <
|
3
|
+
class HaveReadonlyAttributesMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "an attribute that cannot be set after being saved" do
|
6
6
|
setup do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class ValidateAcceptanceOfMatcherTest <
|
3
|
+
class ValidateAcceptanceOfMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "an attribute which must be accepted" do
|
6
6
|
setup do
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
|
3
|
+
class ValidateFormatOfMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
|
+
|
5
|
+
|
6
|
+
context "a postal code" do
|
7
|
+
setup do
|
8
|
+
define_model :example, :attr => :string do
|
9
|
+
validates_format_of :attr, :with => /^\d{5}$/
|
10
|
+
end
|
11
|
+
@model = Example.new
|
12
|
+
end
|
13
|
+
|
14
|
+
should "be valid" do
|
15
|
+
assert_accepts validate_format_of(:attr).with('12345'), @model
|
16
|
+
end
|
17
|
+
|
18
|
+
should "not be valid with alpha in zip" do
|
19
|
+
assert_rejects validate_format_of(:attr).not_with('1234a'), @model, :message=>"is invalid"
|
20
|
+
end
|
21
|
+
|
22
|
+
should "not be valid with to few digits" do
|
23
|
+
assert_rejects validate_format_of(:attr).not_with('1234'), @model, :message=>"is invalid"
|
24
|
+
end
|
25
|
+
|
26
|
+
should "not be valid with to many digits" do
|
27
|
+
assert_rejects validate_format_of(:attr).not_with('123456'), @model, :message=>"is invalid"
|
28
|
+
end
|
29
|
+
|
30
|
+
should "raise error if you try to call both with and not_with" do
|
31
|
+
assert_raise RuntimeError do
|
32
|
+
validate_format_of(:attr).not_with('123456').with('12345')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class ValidateNumericalityOfMatcherTest <
|
3
|
+
class ValidateNumericalityOfMatcherTest < ActiveSupport::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "a numeric attribute" do
|
6
6
|
setup do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class AssignToMatcherTest <
|
3
|
+
class AssignToMatcherTest < ActionController::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "a controller that assigns to an instance variable" do
|
6
6
|
setup do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class FilterParamMatcherTest <
|
3
|
+
class FilterParamMatcherTest < ActionController::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "a controller that filters no parameters" do
|
6
6
|
setup do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class RenderWithLayoutMatcherTest <
|
3
|
+
class RenderWithLayoutMatcherTest < ActionController::TestCase # :nodoc:
|
4
4
|
|
5
5
|
context "a controller that renders with a layout" do
|
6
6
|
setup do
|
@@ -1,27 +1,32 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
2
|
|
3
|
-
class RespondWithContentTypeMatcherTest <
|
4
|
-
|
3
|
+
class RespondWithContentTypeMatcherTest < ActionController::TestCase # :nodoc:
|
4
|
+
|
5
5
|
context "a controller responding with content type :xml" do
|
6
6
|
setup do
|
7
7
|
@controller = build_response { render :xml => { :user => "thoughtbot" }.to_xml }
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
should "accept responding with content type :xml" do
|
11
11
|
assert_accepts respond_with_content_type(:xml), @controller
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
should "accept responding with content type 'application/xml'" do
|
15
15
|
assert_accepts respond_with_content_type('application/xml'), @controller
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
should "accept responding with content type /xml/" do
|
19
19
|
assert_accepts respond_with_content_type(/xml/), @controller
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
should "reject responding with another content type" do
|
23
23
|
assert_rejects respond_with_content_type(:json), @controller
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
|
+
should "generate the correct test name" do
|
28
|
+
assert_equal "respond with content type of application/xml",
|
29
|
+
respond_with_content_type(:xml).description
|
30
|
+
end
|
31
|
+
|
27
32
|
end
|