shoulda-matchers 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +3 -1
  3. data/Gemfile +1 -2
  4. data/Gemfile.lock +8 -2
  5. data/NEWS.md +29 -1
  6. data/README.md +3 -11
  7. data/doc_config/yard/templates/default/fulldoc/html/css/global.css +17 -0
  8. data/doc_config/yard/templates/default/fulldoc/html/css/style.css +3 -4
  9. data/doc_config/yard/templates/default/layout/html/breadcrumb.erb +1 -1
  10. data/doc_config/yard/templates/default/layout/html/footer.erb +6 -0
  11. data/docs/errors/NonCaseSwappableValueError.md +111 -0
  12. data/gemfiles/4.0.0.gemfile +1 -2
  13. data/gemfiles/4.0.0.gemfile.lock +5 -2
  14. data/gemfiles/4.0.1.gemfile +1 -2
  15. data/gemfiles/4.0.1.gemfile.lock +5 -2
  16. data/gemfiles/4.1.gemfile +1 -2
  17. data/gemfiles/4.1.gemfile.lock +5 -2
  18. data/gemfiles/4.2.gemfile +1 -2
  19. data/gemfiles/4.2.gemfile.lock +5 -2
  20. data/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +1 -5
  21. data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +26 -4
  22. data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +9 -8
  23. data/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +14 -8
  24. data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +47 -12
  25. data/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +15 -9
  26. data/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +14 -7
  27. data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +16 -4
  28. data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +67 -5
  29. data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +35 -0
  30. data/lib/shoulda/matchers/util.rb +2 -0
  31. data/lib/shoulda/matchers/util/word_wrap.rb +178 -0
  32. data/lib/shoulda/matchers/version.rb +1 -1
  33. data/lib/shoulda/matchers/warn.rb +1 -10
  34. data/spec/acceptance_spec_helper.rb +2 -10
  35. data/spec/doublespeak_spec_helper.rb +1 -17
  36. data/spec/spec_helper.rb +23 -0
  37. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +1 -1
  38. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +5 -2
  39. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +5 -2
  40. data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +5 -1
  41. data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +91 -4
  42. data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +292 -2
  43. data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +16 -2
  44. data/spec/unit/shoulda/matchers/util/word_wrap_spec.rb +197 -0
  45. data/spec/unit_spec_helper.rb +1 -16
  46. data/tasks/documentation.rb +10 -17
  47. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d2511e64aa43fb787466f5a74f3988cbd42b3ff
4
- data.tar.gz: d8ca90b46025cb37d4acd8111b1686902837257e
3
+ metadata.gz: 2fe80273c48fdbadb3d479406470fa875abfcf61
4
+ data.tar.gz: 3cac554e34d73023e1e3cd5a65bc23291159ff87
5
5
  SHA512:
6
- metadata.gz: 57e1a16493c88afaedc21664cd8725e140b4c5528941de796543a53086644d60c43aa980229bdbed70bd4340e415bf9e66c9825ac3bffdd74d2d8c281933363e
7
- data.tar.gz: 7e8e7a91c8073833e9f1ee756201eebea1e67037c141d2d4602be1656407e192fea3c254177f8c05072625235c24d8d9f171d14bd1d4a5b9e7b6d086634e023e
6
+ metadata.gz: df7679b9a7384f93e221a7a9a07411bd6e6f93cd3dc267e262e803b3c7359b3272b4adb037039e09662bf7bb6e9b31d094748109dec3e9050967df8d3691f8f8
7
+ data.tar.gz: f5c6cea2751c9cf331b96447af1d8f70c6ecd1edae2aac4c587361e438a14caa8cd8da563873135b0421450f28663e1c1b7c4f542182b9a5311cee1480d29520
data/.yardopts CHANGED
@@ -1,8 +1,10 @@
1
1
  --no-private
2
2
  --protected
3
3
  --readme README.md
4
- --files NEWS.md
5
4
  --markup markdown
6
5
  --hide-tag return
7
6
  --hide-tag param
8
7
  -e ./doc_config/yard/setup.rb
8
+ -
9
+ NEWS.md
10
+ docs/**/*.md
data/Gemfile CHANGED
@@ -5,8 +5,7 @@ gem 'bundler', '~> 1.1'
5
5
  gem 'pry', github: 'pry/pry'
6
6
  gem 'pry-byebug'
7
7
  gem 'rake', '~> 10.0'
8
- gem 'rspec-core', '>= 3.2.0', '< 4'
9
- gem 'rspec-expectations', '>= 3.2.0', '< 4'
8
+ gem 'rspec', '~> 3.2'
10
9
 
11
10
  # YARD
12
11
  gem 'yard'
data/Gemfile.lock CHANGED
@@ -30,11 +30,18 @@ GEM
30
30
  yajl-ruby (~> 1.1.0)
31
31
  rake (10.4.2)
32
32
  redcarpet (3.0.0)
33
+ rspec (3.3.0)
34
+ rspec-core (~> 3.3.0)
35
+ rspec-expectations (~> 3.3.0)
36
+ rspec-mocks (~> 3.3.0)
33
37
  rspec-core (3.3.2)
34
38
  rspec-support (~> 3.3.0)
35
39
  rspec-expectations (3.3.1)
36
40
  diff-lcs (>= 1.2.0, < 2.0)
37
41
  rspec-support (~> 3.3.0)
42
+ rspec-mocks (3.3.2)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.3.0)
38
45
  rspec-support (3.3.0)
39
46
  slop (3.6.0)
40
47
  thor (0.19.1)
@@ -53,8 +60,7 @@ DEPENDENCIES
53
60
  pygments.rb
54
61
  rake (~> 10.0)
55
62
  redcarpet
56
- rspec-core (>= 3.2.0, < 4)
57
- rspec-expectations (>= 3.2.0, < 4)
63
+ rspec (~> 3.2)
58
64
  yard
59
65
 
60
66
  BUNDLED WITH
data/NEWS.md CHANGED
@@ -1,3 +1,29 @@
1
+ # 3.0.1
2
+
3
+ ### Bug fixes
4
+
5
+ * Fix `validate_inclusion_of` + `in_array` when used against a date or datetime
6
+ column/attribute so that it does not raise a CouldNotSetAttributeError.
7
+ ([#783], [8fa97b4])
8
+
9
+ * Fix `validate_numericality_of` when used against a numeric column so that it
10
+ no longer raises a CouldNotSetAttributeError if the matcher has been qualified
11
+ in any way (`only_integer`, `greater_than`, `odd`, etc.). ([#784], [#812])
12
+
13
+ ### Improvements
14
+
15
+ * `validate_uniqueness_of` now raises a NonCaseSwappableValueError if the value
16
+ the matcher is using to test uniqueness cannot be case-swapped -- in other
17
+ words, if it doesn't contain any alpha characters. When this is the case, the
18
+ matcher cannot work effectively. ([#789], [ada9bd3])
19
+
20
+ [#783]: https://github.com/thoughtbot/shoulda-matchers/pull/783
21
+ [8fa97b4]: https://github.com/thoughtbot/shoulda-matchers/commit/8fa97b4ff33b57ce16dfb96be1ec892502f2aa9e
22
+ [#784]: https://github.com/thoughtbot/shoulda-matchers/pull/784
23
+ [#789]: https://github.com/thoughtbot/shoulda-matchers/pull/789
24
+ [ada9bd3]: https://github.com/thoughtbot/shoulda-matchers/commit/ada9bd3a1b9f2bb9fa74d0dfe1f8f7080314298c
25
+ [#812]: https://github.com/thoughtbot/shoulda-matchers/pull/812
26
+
1
27
  # 3.0.0
2
28
 
3
29
  ### Backward-incompatible changes
@@ -150,7 +176,7 @@
150
176
 
151
177
  ([9d9dc4e])
152
178
 
153
- * `validate_uniqueness_of` is now properly case-insensitive by default, to match
179
+ * `validate_uniqueness_of` is now properly case-sensitive by default, to match
154
180
  the default behavior of the validation itself. This is a backward-incompatible
155
181
  change because this test which incorrectly passed before will now fail:
156
182
 
@@ -215,6 +241,8 @@
215
241
  [#752]: https://github.com/thoughtbot/shoulda-matchers/pull/752
216
242
  [9d9dc4e]: https://github.com/thoughtbot/shoulda-matchers/commit/9d9dc4e6b9cf2c19df66a1b4ba432ad8d3e5dded
217
243
  [32c0e62]: https://github.com/thoughtbot/shoulda-matchers/commit/32c0e62596b87e37a301f87bbe21cfcc77750552
244
+ [af98a23]: https://github.com/thoughtbot/shoulda-matchers/commit/af98a23091551fb40aded5a8d4f9e5be926f53a9
245
+ [8cf449b]: https://github.com/thoughtbot/shoulda-matchers/commit/8cf449b4ca37d0d7446d2cabbfa5a1582358256d
218
246
 
219
247
  ### Bug fixes
220
248
 
data/README.md CHANGED
@@ -4,10 +4,7 @@ Shoulda Matchers provides RSpec- and Minitest-compatible one-liners that test
4
4
  common Rails functionality. These tests would otherwise be much longer, more
5
5
  complex, and error-prone.
6
6
 
7
- [View the official documentation for the latest version (2.8.0).][rubydocs]
8
-
9
- **Heads up! This is the README for the master branch. [You might be more
10
- interested in the README for 2.8.0 instead.][2.8.0-README]**
7
+ [View the official documentation for the latest version (3.0.0).][rubydocs]
11
8
 
12
9
  ----
13
10
 
@@ -108,7 +105,7 @@ Include `shoulda-matchers` in your Gemfile:
108
105
 
109
106
  ``` ruby
110
107
  group :test do
111
- gem 'shoulda-matchers'
108
+ gem 'shoulda-matchers', '~> 3.0'
112
109
  end
113
110
  ```
114
111
 
@@ -144,7 +141,7 @@ gem in your Gemfile instead:
144
141
 
145
142
  ```ruby
146
143
  group :test do
147
- gem 'shoulda'
144
+ gem 'shoulda', '~> 3.5'
148
145
  end
149
146
  ```
150
147
 
@@ -161,10 +158,6 @@ end
161
158
 
162
159
  ### Configuration
163
160
 
164
- **NOTE: The new configuration syntax isn't available in a public release just
165
- yet -- please refer to the [README for 2.8.0][2.8.0-README] for the current
166
- installation instructions.**
167
-
168
161
  Before you can use Shoulda Matchers, you'll need to tell it a couple of things:
169
162
 
170
163
  * Which test framework you're using
@@ -255,4 +248,3 @@ We are [available for hire][hire].
255
248
  [contributors]: https://github.com/thoughtbot/shoulda-matchers/contributors
256
249
  [shoulda]: http://github.com/thoughtbot/shoulda
257
250
  [shoulda-context]: http://github.com/thoughtbot/shoulda-context
258
- [2.8.0-README]: https://github.com/thoughtbot/shoulda-matchers/tree/v2.8.0#shoulda-matchers---
@@ -43,3 +43,20 @@ ul, ol {
43
43
  margin-left: 1em;
44
44
  padding-left: 1em;
45
45
  }
46
+
47
+ p, blockquote {
48
+ margin-bottom: 1.25em;
49
+ }
50
+
51
+ blockquote {
52
+ font-style: italic;
53
+ padding-top: 0;
54
+ padding-bottom: 0;
55
+ padding-left: 1em;
56
+ }
57
+
58
+ blockquote p {
59
+ font-size: inherit;
60
+ font-weight: inherit;
61
+ line-height: inherit;
62
+ }
@@ -91,7 +91,7 @@ h4 + h5 {
91
91
  #menu, #search {
92
92
  height: 6rem;
93
93
  line-height: 6rem;
94
- text-transform: uppercase;
94
+ font-size: 1.1em;
95
95
  }
96
96
  #main {
97
97
  top: 6rem;
@@ -99,10 +99,9 @@ h4 + h5 {
99
99
 
100
100
  #menu {
101
101
  float: left;
102
- letter-spacing: 1px;
103
102
  padding-left: 2em;
104
103
  position: relative;
105
- width: 30em;
104
+ width: 45em;
106
105
  }
107
106
 
108
107
  #menu .noframes {
@@ -111,7 +110,6 @@ h4 + h5 {
111
110
 
112
111
  #search {
113
112
  float: right;
114
- font-size: 0.9em;
115
113
  }
116
114
 
117
115
  #search ul {
@@ -201,6 +199,7 @@ h4 + h5 {
201
199
  padding: 10px;
202
200
  text-align: center;
203
201
  text-shadow: 0 1px 1px rgba(0,0,0,0.4);
202
+ font-size: 0.9em;
204
203
  }
205
204
 
206
205
  #footer a {
@@ -5,7 +5,7 @@
5
5
  </span> &raquo;
6
6
  <% end %>
7
7
  <% if @contents || @file %>
8
- <span class="title"><%= @breadcrumb_title %></span>
8
+ <span class="title"><%= @breadcrumb_title.sub(/\AFile: /, "") %></span>
9
9
  <% elsif object.is_a?(CodeObjects::Base) %>
10
10
  <%= @breadcrumb.map {|obj| "<span class='title'>" + linkify(obj, obj.name) + "</span>" }.join(" &raquo; ") %>
11
11
  <%= @breadcrumb.size > 0 ? " &raquo; " : "" %>
@@ -0,0 +1,6 @@
1
+ <div id="footer">
2
+ Generated on
3
+ <%= Time.now.strftime("%B %-d, %Y") %>
4
+ by
5
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">YARD</a>.
6
+ </div>
@@ -0,0 +1,111 @@
1
+ # @title NonCaseSwappableValueError
2
+
3
+ # NonCaseSwappableValueError
4
+
5
+ This error is raised when using `validate_uniqueness_of`. This matcher, of
6
+ course, tests that an attribute disallows a non-unique value -- and what
7
+ constitutes as "unique" depends on whether the case-sensitivity of that value
8
+ matters. If it does matter -- meaning that the uniqueness validation in your
9
+ model isn't using `case_sensitive: false` and you haven't qualified the matcher
10
+ with `case_insensitive` -- then the matcher will run the following test:
11
+
12
+ > Creating first a record with a value of "A":
13
+ >
14
+ > * A new record with a value of "A" should not be valid (failing the uniqueness
15
+ > validation)
16
+ > * A new record with a value of "a" should be valid
17
+
18
+ The test value we're using is in this case "A", and this is what the matcher
19
+ will use if an existing record is not already present in the database. But if
20
+ a record already exists, then the matcher will use it as comparison -- it will
21
+ read the attribute under test off of the record and use its value. So a better
22
+ example might be:
23
+
24
+ > Given an existing record with a value:
25
+ >
26
+ > * A new record with the same value should not be valid (failing the uniqueness
27
+ > validation)
28
+ > * A new record with the same value, but where the case is swapped (using
29
+ > String#swapcase), should be valid
30
+
31
+ Now, what happens if an existing record is there, but the value being used is
32
+ not one whose case can be swapped, such as `"123"` or `"{-#%}"`? Then the second
33
+ assertion cannot be made effectively.
34
+
35
+ So this is why you're getting this exception. What can you do about it? As the
36
+ error message explains, you have two options:
37
+
38
+ 1. If you want the uniqueness validation in the model to operate
39
+ case-sensitively and you didn't mean to use a non-case-swappable value,
40
+ then you need to provide an existing record with a different value, one that
41
+ contains alpha characters. Here's an example:
42
+
43
+ # Model
44
+ class User < ActiveRecord::Base
45
+ validates_uniqueness_of :username
46
+ end
47
+
48
+ # RSpec
49
+ describe User do
50
+ context "validations" do
51
+ subject do
52
+ # Note that "123" == "123".swapcase. This is a problem!
53
+ User.new(username: "123")
54
+ end
55
+
56
+ it do
57
+ # So you can either override it like this, or just fix the subject.
58
+ user = User.create!(username: "john123")
59
+ expect(user).to validate_uniqueness_of(:username)
60
+ end
61
+ end
62
+ end
63
+
64
+ # Minitest (Shoulda)
65
+ class UserTest < ActiveSupport::TestCase
66
+ context "validations" do
67
+ subject do
68
+ # Note that "123" == "123".swapcase. This is a problem!
69
+ User.new(username: "123")
70
+ end
71
+
72
+ should "validate uniqueness of :username" do
73
+ # So you can either override it like this, or just fix the subject.
74
+ user = User.create!(username: "john123")
75
+ assert_accepts validate_uniqueness_of(:username), record
76
+ end
77
+ end
78
+ end
79
+
80
+ 2. If you don't want the uniqueness validation to operate case-sensitively,
81
+ then you need to add `case_sensitive: false` to the validation and add
82
+ `case_insensitive` to the matcher:
83
+
84
+ # Model
85
+ class User < ActiveRecord::Base
86
+ validates_uniqueness_of :username, case_sensitive: false
87
+ end
88
+
89
+ # RSpec
90
+ describe User do
91
+ context "validations" do
92
+ subject do
93
+ # Note that "123" == "123".swapcase, but it's okay
94
+ User.new(username: "123")
95
+ end
96
+
97
+ it { should validate_uniqueness_of(:username).case_insensitive }
98
+ end
99
+ end
100
+
101
+ # Minitest (Shoulda)
102
+ class UserTest < ActiveSupport::TestCase
103
+ context "validations" do
104
+ subject do
105
+ # Note that "123" == "123".swapcase, but it's okay
106
+ User.new(username: "123")
107
+ end
108
+
109
+ should validate_uniqueness_of(:username).case_insensitive
110
+ end
111
+ end
@@ -7,8 +7,7 @@ gem "bundler", "~> 1.1"
7
7
  gem "pry", :github => "pry/pry"
8
8
  gem "pry-byebug"
9
9
  gem "rake", "~> 10.0"
10
- gem "rspec-core", ">= 3.2.0", "< 4"
11
- gem "rspec-expectations", ">= 3.2.0", "< 4"
10
+ gem "rspec", "~> 3.2"
12
11
  gem "yard"
13
12
  gem "redcarpet"
14
13
  gem "pygments.rb"
@@ -118,6 +118,10 @@ GEM
118
118
  rake (10.4.2)
119
119
  rdoc (4.2.0)
120
120
  redcarpet (3.3.2)
121
+ rspec (3.3.0)
122
+ rspec-core (~> 3.3.0)
123
+ rspec-expectations (~> 3.3.0)
124
+ rspec-mocks (~> 3.3.0)
121
125
  rspec-core (3.3.2)
122
126
  rspec-support (~> 3.3.0)
123
127
  rspec-expectations (3.3.1)
@@ -199,8 +203,7 @@ DEPENDENCIES
199
203
  rails (= 4.0.0)
200
204
  rake (~> 10.0)
201
205
  redcarpet
202
- rspec-core (>= 3.2.0, < 4)
203
- rspec-expectations (>= 3.2.0, < 4)
206
+ rspec (~> 3.2)
204
207
  rspec-rails (>= 3.2.0, < 4)
205
208
  sass-rails (~> 4.0.0)
206
209
  sdoc
@@ -7,8 +7,7 @@ gem "bundler", "~> 1.1"
7
7
  gem "pry", :github => "pry/pry"
8
8
  gem "pry-byebug"
9
9
  gem "rake", "~> 10.0"
10
- gem "rspec-core", ">= 3.2.0", "< 4"
11
- gem "rspec-expectations", ">= 3.2.0", "< 4"
10
+ gem "rspec", "~> 3.2"
12
11
  gem "yard"
13
12
  gem "redcarpet"
14
13
  gem "pygments.rb"
@@ -120,6 +120,10 @@ GEM
120
120
  rake (10.4.2)
121
121
  rdoc (4.2.0)
122
122
  redcarpet (3.3.2)
123
+ rspec (3.3.0)
124
+ rspec-core (~> 3.3.0)
125
+ rspec-expectations (~> 3.3.0)
126
+ rspec-mocks (~> 3.3.0)
123
127
  rspec-core (3.3.2)
124
128
  rspec-support (~> 3.3.0)
125
129
  rspec-expectations (3.3.1)
@@ -201,8 +205,7 @@ DEPENDENCIES
201
205
  rails (= 4.0.1)
202
206
  rake (~> 10.0)
203
207
  redcarpet
204
- rspec-core (>= 3.2.0, < 4)
205
- rspec-expectations (>= 3.2.0, < 4)
208
+ rspec (~> 3.2)
206
209
  rspec-rails (>= 3.2.0, < 4)
207
210
  sass-rails (~> 4.0.0)
208
211
  sdoc
data/gemfiles/4.1.gemfile CHANGED
@@ -7,8 +7,7 @@ gem "bundler", "~> 1.1"
7
7
  gem "pry", :github => "pry/pry"
8
8
  gem "pry-byebug"
9
9
  gem "rake", "~> 10.0"
10
- gem "rspec-core", ">= 3.2.0", "< 4"
11
- gem "rspec-expectations", ">= 3.2.0", "< 4"
10
+ gem "rspec", "~> 3.2"
12
11
  gem "yard"
13
12
  gem "redcarpet"
14
13
  gem "pygments.rb"
@@ -116,6 +116,10 @@ GEM
116
116
  rake (10.4.2)
117
117
  rdoc (4.2.0)
118
118
  redcarpet (3.3.2)
119
+ rspec (3.3.0)
120
+ rspec-core (~> 3.3.0)
121
+ rspec-expectations (~> 3.3.0)
122
+ rspec-mocks (~> 3.3.0)
119
123
  rspec-core (3.3.2)
120
124
  rspec-support (~> 3.3.0)
121
125
  rspec-expectations (3.3.1)
@@ -196,8 +200,7 @@ DEPENDENCIES
196
200
  rails (~> 4.1.0)
197
201
  rake (~> 10.0)
198
202
  redcarpet
199
- rspec-core (>= 3.2.0, < 4)
200
- rspec-expectations (>= 3.2.0, < 4)
203
+ rspec (~> 3.2)
201
204
  rspec-rails (>= 3.2.0, < 4)
202
205
  sass-rails (~> 4.0.3)
203
206
  sdoc (~> 0.4.0)