shoulda-matchers 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/.travis.yml +11 -3
  2. data/Appraisals +3 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +69 -70
  5. data/MIT-LICENSE +1 -1
  6. data/NEWS.md +22 -4
  7. data/README.md +3 -1
  8. data/Rakefile +9 -5
  9. data/features/step_definitions/rails_steps.rb +7 -7
  10. data/features/support/env.rb +1 -1
  11. data/gemfiles/3.0.gemfile +1 -1
  12. data/gemfiles/3.0.gemfile.lock +25 -22
  13. data/gemfiles/3.1.gemfile +1 -1
  14. data/gemfiles/3.1.gemfile.lock +27 -24
  15. data/gemfiles/3.2.gemfile +1 -1
  16. data/gemfiles/3.2.gemfile.lock +56 -52
  17. data/lib/shoulda/matchers/action_controller.rb +3 -2
  18. data/lib/shoulda/matchers/action_controller/assign_to_matcher.rb +10 -8
  19. data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +2 -4
  20. data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +3 -4
  21. data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +3 -4
  22. data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +6 -6
  23. data/lib/shoulda/matchers/action_controller/respond_with_content_type_matcher.rb +5 -2
  24. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +2 -2
  25. data/lib/shoulda/matchers/action_controller/route_matcher.rb +12 -12
  26. data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +3 -4
  27. data/lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb +10 -11
  28. data/lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb +121 -0
  29. data/lib/shoulda/matchers/action_mailer/have_sent_email_matcher.rb +7 -4
  30. data/lib/shoulda/matchers/active_model.rb +1 -1
  31. data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +8 -8
  32. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +5 -4
  33. data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +3 -3
  34. data/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb +2 -2
  35. data/lib/shoulda/matchers/active_model/exception_message_finder.rb +0 -1
  36. data/lib/shoulda/matchers/active_model/helpers.rb +16 -7
  37. data/lib/shoulda/matchers/active_model/only_integer_matcher.rb +3 -3
  38. data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +8 -6
  39. data/lib/shoulda/matchers/active_model/validate_format_of_matcher.rb +19 -10
  40. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +4 -4
  41. data/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +19 -21
  42. data/lib/shoulda/matchers/active_model/validation_matcher.rb +7 -7
  43. data/lib/shoulda/matchers/active_model/validation_message_finder.rb +1 -1
  44. data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +5 -5
  45. data/lib/shoulda/matchers/active_record/association_matcher.rb +3 -3
  46. data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +11 -7
  47. data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +2 -2
  48. data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +5 -5
  49. data/lib/shoulda/matchers/active_record/query_the_database_matcher.rb +5 -2
  50. data/lib/shoulda/matchers/active_record/serialize_matcher.rb +3 -3
  51. data/lib/shoulda/matchers/assertion_error.rb +4 -1
  52. data/lib/shoulda/matchers/independent/delegate_matcher.rb +17 -7
  53. data/lib/shoulda/matchers/integrations/rspec.rb +19 -33
  54. data/lib/shoulda/matchers/version.rb +1 -1
  55. data/shoulda-matchers.gemspec +6 -4
  56. data/spec/shoulda/matchers/action_controller/assign_to_matcher_spec.rb +66 -0
  57. data/spec/shoulda/matchers/action_controller/filter_param_matcher_spec.rb +22 -0
  58. data/spec/shoulda/matchers/action_controller/redirect_to_matcher_spec.rb +42 -0
  59. data/spec/shoulda/matchers/action_controller/render_template_matcher_spec.rb +78 -0
  60. data/spec/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +58 -0
  61. data/spec/shoulda/matchers/action_controller/respond_with_content_type_matcher_spec.rb +31 -0
  62. data/spec/shoulda/matchers/action_controller/respond_with_matcher_spec.rb +31 -0
  63. data/spec/shoulda/matchers/action_controller/route_matcher_spec.rb +65 -0
  64. data/spec/shoulda/matchers/action_controller/set_session_matcher_spec.rb +51 -0
  65. data/spec/shoulda/matchers/action_controller/set_the_flash_matcher_spec.rb +153 -0
  66. data/spec/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +142 -0
  67. data/spec/shoulda/matchers/action_mailer/have_sent_email_spec.rb +324 -0
  68. data/spec/shoulda/matchers/active_model/allow_mass_assignment_of_matcher_spec.rb +111 -0
  69. data/spec/shoulda/matchers/active_model/allow_value_matcher_spec.rb +124 -0
  70. data/spec/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +43 -0
  71. data/spec/shoulda/matchers/active_model/ensure_exclusion_of_matcher_spec.rb +74 -0
  72. data/spec/shoulda/matchers/active_model/ensure_inclusion_of_matcher_spec.rb +171 -0
  73. data/spec/shoulda/matchers/active_model/ensure_length_of_matcher_spec.rb +113 -0
  74. data/spec/shoulda/{active_model → matchers/active_model}/exception_message_finder_spec.rb +2 -2
  75. data/spec/shoulda/matchers/active_model/helpers_spec.rb +158 -0
  76. data/spec/shoulda/matchers/active_model/only_integer_matcher_spec.rb +52 -0
  77. data/spec/shoulda/matchers/active_model/validate_acceptance_of_matcher_spec.rb +41 -0
  78. data/spec/shoulda/matchers/active_model/validate_confirmation_of_matcher_spec.rb +41 -0
  79. data/spec/shoulda/matchers/active_model/validate_format_of_matcher_spec.rb +75 -0
  80. data/spec/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +73 -0
  81. data/spec/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +127 -0
  82. data/spec/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +175 -0
  83. data/spec/shoulda/{active_model → matchers/active_model}/validation_message_finder_spec.rb +0 -1
  84. data/spec/shoulda/matchers/active_record/accept_nested_attributes_for_matcher_spec.rb +106 -0
  85. data/spec/shoulda/matchers/active_record/association_matcher_spec.rb +534 -0
  86. data/spec/shoulda/matchers/active_record/have_db_column_matcher_spec.rb +111 -0
  87. data/spec/shoulda/matchers/active_record/have_db_index_matcher_spec.rb +78 -0
  88. data/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb +41 -0
  89. data/spec/shoulda/{active_record → matchers/active_record}/query_the_database_matcher_spec.rb +10 -10
  90. data/spec/shoulda/matchers/active_record/serialize_matcher_spec.rb +86 -0
  91. data/spec/shoulda/{independent → matchers/independent}/delegate_matcher_spec.rb +55 -34
  92. data/spec/spec_helper.rb +1 -2
  93. data/spec/support/active_model_versions.rb +4 -0
  94. data/spec/support/activemodel_helpers.rb +19 -0
  95. data/spec/support/controller_builder.rb +38 -12
  96. data/spec/support/model_builder.rb +8 -2
  97. metadata +106 -98
  98. data/spec/fixtures/addresses.yml +0 -3
  99. data/spec/fixtures/friendships.yml +0 -0
  100. data/spec/fixtures/posts.yml +0 -5
  101. data/spec/fixtures/products.yml +0 -0
  102. data/spec/fixtures/taggings.yml +0 -0
  103. data/spec/fixtures/tags.yml +0 -9
  104. data/spec/fixtures/users.yml +0 -6
  105. data/spec/shoulda/action_controller/assign_to_matcher_spec.rb +0 -63
  106. data/spec/shoulda/action_controller/filter_param_matcher_spec.rb +0 -20
  107. data/spec/shoulda/action_controller/redirect_to_matcher_spec.rb +0 -40
  108. data/spec/shoulda/action_controller/render_template_matcher_spec.rb +0 -69
  109. data/spec/shoulda/action_controller/render_with_layout_matcher_spec.rb +0 -55
  110. data/spec/shoulda/action_controller/respond_with_content_type_matcher_spec.rb +0 -28
  111. data/spec/shoulda/action_controller/respond_with_matcher_spec.rb +0 -83
  112. data/spec/shoulda/action_controller/route_matcher_spec.rb +0 -65
  113. data/spec/shoulda/action_controller/set_session_matcher_spec.rb +0 -46
  114. data/spec/shoulda/action_controller/set_the_flash_matcher_spec.rb +0 -130
  115. data/spec/shoulda/action_mailer/have_sent_email_spec.rb +0 -333
  116. data/spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb +0 -115
  117. data/spec/shoulda/active_model/allow_value_matcher_spec.rb +0 -131
  118. data/spec/shoulda/active_model/disallow_value_matcher_spec.rb +0 -65
  119. data/spec/shoulda/active_model/ensure_exclusion_of_matcher_spec.rb +0 -79
  120. data/spec/shoulda/active_model/ensure_inclusion_of_matcher_spec.rb +0 -181
  121. data/spec/shoulda/active_model/ensure_length_of_matcher_spec.rb +0 -138
  122. data/spec/shoulda/active_model/helpers_spec.rb +0 -129
  123. data/spec/shoulda/active_model/only_integer_matcher_spec.rb +0 -69
  124. data/spec/shoulda/active_model/validate_acceptance_of_matcher_spec.rb +0 -43
  125. data/spec/shoulda/active_model/validate_confirmation_of_matcher_spec.rb +0 -48
  126. data/spec/shoulda/active_model/validate_format_of_matcher_spec.rb +0 -79
  127. data/spec/shoulda/active_model/validate_numericality_of_matcher_spec.rb +0 -112
  128. data/spec/shoulda/active_model/validate_presence_of_matcher_spec.rb +0 -135
  129. data/spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb +0 -154
  130. data/spec/shoulda/active_record/accept_nested_attributes_for_matcher_spec.rb +0 -84
  131. data/spec/shoulda/active_record/association_matcher_spec.rb +0 -642
  132. data/spec/shoulda/active_record/have_db_column_matcher_spec.rb +0 -185
  133. data/spec/shoulda/active_record/have_db_index_matcher_spec.rb +0 -105
  134. data/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb +0 -46
  135. data/spec/shoulda/active_record/serialize_matcher_spec.rb +0 -81
@@ -1,185 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveRecord::HaveDbColumnMatcher do
4
- context "have_db_column" do
5
- before do
6
- @matcher = have_db_column(:nickname)
7
- end
8
-
9
- it "should accept an existing database column" do
10
- create_table 'superheros' do |table|
11
- table.string :nickname
12
- end
13
- define_model_class 'Superhero'
14
- Superhero.new.should @matcher
15
- end
16
-
17
- it "should reject a nonexistent database column" do
18
- define_model :superhero
19
- Superhero.new.should_not @matcher
20
- end
21
- end
22
-
23
- context "have_db_column of type string" do
24
- before do
25
- @matcher = have_db_column(:nickname).of_type(:string)
26
- end
27
-
28
- it "should accept a column of correct type" do
29
- create_table 'superheros' do |table|
30
- table.string :nickname
31
- end
32
- define_model_class 'Superhero'
33
- Superhero.new.should @matcher
34
- end
35
-
36
- it "should reject a nonexistent database column" do
37
- define_model :superhero
38
- Superhero.new.should_not @matcher
39
- end
40
-
41
- it "should reject a column of wrong type" do
42
- create_table 'superheros' do |table|
43
- table.integer :nickname
44
- end
45
- define_model_class 'Superhero'
46
- Superhero.new.should_not @matcher
47
- end
48
- end
49
-
50
- context "have_db_column with precision option" do
51
- before do
52
- @matcher = have_db_column(:salary).with_options(:precision => 5)
53
- end
54
-
55
- it "should accept a column of correct precision" do
56
- create_table 'superheros' do |table|
57
- table.decimal :salary, :precision => 5
58
- end
59
- define_model_class 'Superhero'
60
- Superhero.new.should @matcher
61
- end
62
-
63
- it "should reject a column of wrong precision" do
64
- create_table 'superheros' do |table|
65
- table.decimal :salary, :precision => 15
66
- end
67
- define_model_class 'Superhero'
68
- Superhero.new.should_not @matcher
69
- end
70
- end
71
-
72
- context "have_db_column with limit option" do
73
- before do
74
- @matcher = have_db_column(:email).
75
- of_type(:string).
76
- with_options(:limit => 255)
77
- end
78
-
79
- it "should accept a column of correct limit" do
80
- create_table 'superheros' do |table|
81
- table.string :email, :limit => 255
82
- end
83
- define_model_class 'Superhero'
84
- Superhero.new.should @matcher
85
- end
86
-
87
- it "should reject a column of wrong limit" do
88
- create_table 'superheros' do |table|
89
- table.string :email, :limit => 500
90
- end
91
- define_model_class 'Superhero'
92
- Superhero.new.should_not @matcher
93
- end
94
- end
95
-
96
- context "have_db_column with default option" do
97
- before do
98
- @matcher = have_db_column(:admin).
99
- of_type(:boolean).
100
- with_options(:default => false)
101
- end
102
-
103
- it "should accept a column of correct default" do
104
- create_table 'superheros' do |table|
105
- table.boolean :admin, :default => false
106
- end
107
- define_model_class 'Superhero'
108
- Superhero.new.should @matcher
109
- end
110
-
111
- it "should reject a column of wrong default" do
112
- create_table 'superheros' do |table|
113
- table.boolean :admin, :default => true
114
- end
115
- define_model_class 'Superhero'
116
- Superhero.new.should_not @matcher
117
- end
118
- end
119
-
120
- context "have_db_column with null option" do
121
- before do
122
- @matcher = have_db_column(:admin).
123
- of_type(:boolean).
124
- with_options(:null => false)
125
- end
126
-
127
- it "should accept a column of correct null" do
128
- create_table 'superheros' do |table|
129
- table.boolean :admin, :null => false
130
- end
131
- define_model_class 'Superhero'
132
- Superhero.new.should @matcher
133
- end
134
-
135
- it "should reject a column of wrong null" do
136
- create_table 'superheros' do |table|
137
- table.boolean :admin, :null => true
138
- end
139
- define_model_class 'Superhero'
140
- Superhero.new.should_not @matcher
141
- end
142
- end
143
-
144
- context "have_db_column with scale option" do
145
- before do
146
- @matcher = have_db_column(:salary).
147
- of_type(:decimal).
148
- with_options(:scale => 2)
149
- end
150
-
151
- it "should accept a column of correct scale" do
152
- create_table 'superheros' do |table|
153
- table.decimal :salary, :precision => 10, :scale => 2
154
- end
155
- define_model_class 'Superhero'
156
- Superhero.new.should @matcher
157
- end
158
-
159
- it "should reject a column of wrong scale" do
160
- create_table 'superheros' do |table|
161
- table.decimal :salary, :precision => 10, :scale => 4
162
- end
163
- define_model_class 'Superhero'
164
- Superhero.new.should_not @matcher
165
- end
166
- end
167
-
168
- context "have_db_column with primary option" do
169
- it "should accept a column that is primary" do
170
- create_table 'superheros' do |table|
171
- table.integer :id, :primary => true
172
- end
173
- define_model_class 'Superhero'
174
- Superhero.new.should have_db_column(:id).with_options(:primary => true)
175
- end
176
-
177
- it "should reject a column that is not primary" do
178
- create_table 'superheros' do |table|
179
- table.integer :primary
180
- end
181
- define_model_class 'Superhero'
182
- Superhero.new.should_not have_db_column(:primary).with_options(:primary => true)
183
- end
184
- end
185
- end
@@ -1,105 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveRecord::HaveDbIndexMatcher do
4
- context "have_db_index" do
5
- before do
6
- @matcher = have_db_index(:age)
7
- end
8
-
9
- it "should accept an existing index" do
10
- db_connection = create_table 'superheros' do |table|
11
- table.integer :age
12
- end
13
- db_connection.add_index :superheros, :age
14
- define_model_class 'Superhero'
15
- Superhero.new.should @matcher
16
- end
17
-
18
- it "should reject a nonexistent index" do
19
- define_model :superhero
20
- Superhero.new.should_not @matcher
21
- end
22
- end
23
-
24
- context "have_db_index with unique option" do
25
- before do
26
- @matcher = have_db_index(:ssn).unique(true)
27
- end
28
-
29
- it "should accept an index of correct unique" do
30
- db_connection = create_table 'superheros' do |table|
31
- table.integer :ssn
32
- end
33
- db_connection.add_index :superheros, :ssn, :unique => true
34
- define_model_class 'Superhero'
35
- Superhero.new.should @matcher
36
- end
37
-
38
- it "should reject an index of wrong unique" do
39
- db_connection = create_table 'superheros' do |table|
40
- table.integer :ssn
41
- end
42
- db_connection.add_index :superheros, :ssn, :unique => false
43
- define_model_class 'Superhero'
44
- Superhero.new.should_not @matcher
45
- end
46
- end
47
-
48
- context "have_db_index on multiple columns" do
49
- before do
50
- @matcher = have_db_index([:geocodable_type, :geocodable_id])
51
- end
52
-
53
- it "should accept an existing index" do
54
- db_connection = create_table 'geocodings' do |table|
55
- table.integer :geocodable_id
56
- table.string :geocodable_type
57
- end
58
- db_connection.add_index :geocodings, [:geocodable_type, :geocodable_id]
59
- define_model_class 'Geocoding'
60
- Geocoding.new.should @matcher
61
- end
62
-
63
- it "should reject a nonexistant index" do
64
- db_connection = create_table 'geocodings' do |table|
65
- table.integer :geocodable_id
66
- table.string :geocodable_type
67
- end
68
- define_model_class 'Geocoding'
69
- Geocoding.new.should_not @matcher
70
- end
71
- end
72
-
73
- it "should join columns with and describing multiple columns" do
74
- have_db_index([:user_id, :post_id]).description.should =~ /on columns user_id and post_id/
75
- end
76
-
77
- it "should context a unique index as unique" do
78
- have_db_index(:user_id).unique(true).description.should =~ /a unique index/
79
- end
80
-
81
- it "should context a non-unique index as non-unique" do
82
- have_db_index(:user_id).unique(false).description.should =~ /a non-unique index/
83
- end
84
-
85
- it "should not context an index's uniqueness when it isn't important" do
86
- have_db_index(:user_id).description.should_not =~ /unique/
87
- end
88
-
89
- it "allows an IndexDefinition to have a truthy value for unique" do
90
- db_connection = create_table 'superheros' do |table|
91
- table.integer :age
92
- end
93
- db_connection.add_index :superheros, :age
94
- define_model_class 'Superhero'
95
-
96
- @matcher = have_db_index(:age).unique(true)
97
-
98
- index_definition = stub("ActiveRecord::ConnectionAdapters::IndexDefinition",
99
- :unique => 7,
100
- :name => :age)
101
- @matcher.stubs(:matched_index => index_definition)
102
-
103
- Superhero.new.should @matcher
104
- end
105
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher do
4
- context "an attribute that cannot be set after being saved" do
5
- before do
6
- define_model :example, :attr => :string do
7
- attr_readonly :attr
8
- end
9
- @model = Example.new
10
- end
11
-
12
- it "should accept being read-only" do
13
- @model.should have_readonly_attribute(:attr)
14
- end
15
- end
16
-
17
- context "an attribute not included in the readonly set" do
18
- before do
19
- define_model :example, :attr => :string, :other => :string do
20
- attr_readonly :other
21
- end
22
- @model = Example.new
23
- end
24
-
25
- it "should not accept being read-only" do
26
- @model.should_not have_readonly_attribute(:attr)
27
- end
28
- end
29
-
30
- context "an attribute on a class with no readonly attributes" do
31
- before do
32
- define_model :example, :attr => :string
33
- @model = Example.new
34
- end
35
-
36
- it "should not accept being read-only" do
37
- @model.should_not have_readonly_attribute(:attr)
38
- end
39
-
40
- it "should assign a failure message" do
41
- matcher = have_readonly_attribute(:attr)
42
- matcher.matches?(@model).should == false
43
- matcher.failure_message.should_not be_nil
44
- end
45
- end
46
- end
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoulda::Matchers::ActiveRecord::SerializeMatcher do
4
- context "an attribute that should be serialized" do
5
- let(:model) do
6
- define_model(:example, :attr => :string) do
7
- serialize :attr
8
- end.new
9
- end
10
-
11
- it "should be serialized" do
12
- model.should serialize(:attr)
13
- end
14
- end
15
-
16
- context "an attribute that should be serialized with a type of Hash" do
17
- let(:model) do
18
- define_model(:example, :attr => :string) do
19
- serialize :attr, Hash
20
- end.new
21
- end
22
-
23
- it "should be serialized" do
24
- model.should serialize(:attr).as(Hash)
25
- end
26
-
27
- it "should not match when using as_instance_of" do
28
- model.should_not serialize(:attr).as_instance_of(Hash)
29
- end
30
- end
31
-
32
- context "an attribute that should be serialized with a type of Array" do
33
- let(:model) do
34
- define_model(:example, :attr => :string, :attr2 => :string) do
35
- serialize :attr, Array
36
- serialize :attr2, Array
37
- end.new
38
- end
39
-
40
- it "should be serialized" do
41
- model.should serialize(:attr).as(Array)
42
- end
43
- end
44
-
45
- context "an attribute that should be serialized but isn't" do
46
- let(:model) { define_model(:example, :attr => :string).new }
47
-
48
- it "should assign a failure message" do
49
- matcher = serialize(:attr)
50
- matcher.matches?(model).should == false
51
- matcher.failure_message.should_not be_nil
52
- end
53
-
54
- it "should assign a failure message with 'as'" do
55
- matcher = serialize(:attr).as(Hash)
56
- matcher.matches?(model).should == false
57
- matcher.failure_message.should_not be_nil
58
- end
59
-
60
- context "a serializer that is an instance of a class" do
61
- before do
62
- define_class(:ExampleSerializer) do
63
- def load(*); end
64
- def dump(*); end
65
- end
66
- define_model :example, :attr => :string do
67
- serialize :attr, ExampleSerializer.new
68
- end
69
- @model = Example.new
70
- end
71
-
72
- it "should match when using as_instance_of" do
73
- @model.should serialize(:attr).as_instance_of(ExampleSerializer)
74
- end
75
-
76
- it "should not match when using as" do
77
- @model.should_not serialize(:attr).as(ExampleSerializer)
78
- end
79
- end
80
- end
81
- end