shoulda-matchers 4.0.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +189 -87
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +1 -0
- data/lib/shoulda/matchers/active_model/qualifiers.rb +1 -0
- data/lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb +26 -0
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +2 -1
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +171 -25
- data/lib/shoulda/matchers/active_record/association_matcher.rb +11 -7
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +120 -63
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +161 -45
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +3 -13
- data/lib/shoulda/matchers/configuration.rb +12 -1
- data/lib/shoulda/matchers/integrations/configuration.rb +7 -3
- data/lib/shoulda/matchers/rails_shim.rb +37 -0
- data/lib/shoulda/matchers/util.rb +1 -1
- data/lib/shoulda/matchers/util/word_wrap.rb +4 -3
- data/lib/shoulda/matchers/version.rb +1 -1
- data/shoulda-matchers.gemspec +20 -13
- metadata +9 -6
@@ -276,7 +276,7 @@ module Shoulda
|
|
276
276
|
end
|
277
277
|
|
278
278
|
def scoped_to(*scopes)
|
279
|
-
@options[:scopes] = [*scopes].flatten
|
279
|
+
@options[:scopes] = [*scopes].flatten.map(&:to_sym)
|
280
280
|
self
|
281
281
|
end
|
282
282
|
|
@@ -477,7 +477,7 @@ module Shoulda
|
|
477
477
|
|
478
478
|
def actual_sets_of_scopes
|
479
479
|
validations.map do |validation|
|
480
|
-
Array.wrap(validation.options[:scope])
|
480
|
+
Array.wrap(validation.options[:scope]).map(&:to_sym)
|
481
481
|
end.reject(&:empty?)
|
482
482
|
end
|
483
483
|
|
@@ -538,20 +538,12 @@ module Shoulda
|
|
538
538
|
|
539
539
|
def create_existing_record
|
540
540
|
@given_record.tap do |existing_record|
|
541
|
-
ensure_secure_password_set(existing_record)
|
542
541
|
existing_record.save(validate: false)
|
543
542
|
end
|
544
543
|
rescue ::ActiveRecord::StatementInvalid => error
|
545
544
|
raise ExistingRecordInvalid.create(underlying_exception: error)
|
546
545
|
end
|
547
546
|
|
548
|
-
def ensure_secure_password_set(instance)
|
549
|
-
if has_secure_password?
|
550
|
-
instance.password = "password"
|
551
|
-
instance.password_confirmation = "password"
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
547
|
def update_existing_record!(value)
|
556
548
|
if existing_value_read != value
|
557
549
|
set_attribute_on_existing_record!(@attribute, value)
|
@@ -576,9 +568,7 @@ module Shoulda
|
|
576
568
|
end
|
577
569
|
|
578
570
|
def has_secure_password?
|
579
|
-
|
580
|
-
'ActiveModel::SecurePassword::InstanceMethodsOnActivation'
|
581
|
-
)
|
571
|
+
Shoulda::Matchers::RailsShim.has_secure_password?(subject, @attribute)
|
582
572
|
end
|
583
573
|
|
584
574
|
def build_new_record
|
@@ -5,6 +5,11 @@ module Shoulda
|
|
5
5
|
yield configuration
|
6
6
|
end
|
7
7
|
|
8
|
+
# @private
|
9
|
+
def self.integrations
|
10
|
+
configuration.integrations
|
11
|
+
end
|
12
|
+
|
8
13
|
# @private
|
9
14
|
def self.configuration
|
10
15
|
@_configuration ||= Configuration.new
|
@@ -12,8 +17,14 @@ module Shoulda
|
|
12
17
|
|
13
18
|
# @private
|
14
19
|
class Configuration
|
20
|
+
attr_reader :integrations
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@integrations = nil
|
24
|
+
end
|
25
|
+
|
15
26
|
def integrate(&block)
|
16
|
-
Integrations::Configuration.apply(
|
27
|
+
@integrations = Integrations::Configuration.apply(&block)
|
17
28
|
end
|
18
29
|
end
|
19
30
|
end
|
@@ -5,11 +5,13 @@ module Shoulda
|
|
5
5
|
module Integrations
|
6
6
|
# @private
|
7
7
|
class Configuration
|
8
|
-
def self.apply(
|
9
|
-
new(
|
8
|
+
def self.apply(&block)
|
9
|
+
new(&block).apply
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
attr_reader :test_frameworks
|
13
|
+
|
14
|
+
def initialize(&block)
|
13
15
|
@test_frameworks = Set.new
|
14
16
|
@libraries = Set.new
|
15
17
|
|
@@ -47,6 +49,8 @@ EOT
|
|
47
49
|
test_framework.include(Shoulda::Matchers::Independent)
|
48
50
|
@libraries.each { |library| library.integrate_with(test_framework) }
|
49
51
|
end
|
52
|
+
|
53
|
+
self
|
50
54
|
end
|
51
55
|
|
52
56
|
private
|
@@ -119,6 +119,43 @@ module Shoulda
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
+
def parent_of(mod)
|
123
|
+
if mod.respond_to?(:module_parent)
|
124
|
+
mod.module_parent
|
125
|
+
else
|
126
|
+
mod.parent
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def has_secure_password?(record, attribute_name)
|
131
|
+
if secure_password_module
|
132
|
+
attribute_name == :password &&
|
133
|
+
record.class.ancestors.include?(secure_password_module)
|
134
|
+
else
|
135
|
+
record.respond_to?("authenticate_#{attribute_name}")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def digestible_attributes_in(record)
|
140
|
+
record.methods.inject([]) do |array, method_name|
|
141
|
+
match = method_name.to_s.match(
|
142
|
+
/\A(\w+)_(?:confirmation|digest)=\Z/,
|
143
|
+
)
|
144
|
+
|
145
|
+
if match
|
146
|
+
array.concat([match[1].to_sym])
|
147
|
+
else
|
148
|
+
array
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def secure_password_module
|
154
|
+
::ActiveModel::SecurePassword::InstanceMethodsOnActivation
|
155
|
+
rescue NameError
|
156
|
+
nil
|
157
|
+
end
|
158
|
+
|
122
159
|
private
|
123
160
|
|
124
161
|
def simply_generate_validation_message(
|
@@ -2,6 +2,8 @@ module Shoulda
|
|
2
2
|
module Matchers
|
3
3
|
# @private
|
4
4
|
module WordWrap
|
5
|
+
TERMINAL_WIDTH = 72
|
6
|
+
|
5
7
|
def word_wrap(document, options = {})
|
6
8
|
Document.new(document, options).wrap
|
7
9
|
end
|
@@ -112,7 +114,6 @@ module Shoulda
|
|
112
114
|
|
113
115
|
# @private
|
114
116
|
class Line
|
115
|
-
TERMINAL_WIDTH = 72
|
116
117
|
OFFSETS = { left: -1, right: +1 }
|
117
118
|
|
118
119
|
def initialize(line, indent: 0)
|
@@ -171,7 +172,7 @@ module Shoulda
|
|
171
172
|
def wrap_line(line, direction: :left)
|
172
173
|
index = nil
|
173
174
|
|
174
|
-
if line.length > TERMINAL_WIDTH
|
175
|
+
if line.length > Shoulda::Matchers::WordWrap::TERMINAL_WIDTH
|
175
176
|
index = determine_where_to_break_line(line, direction: :left)
|
176
177
|
|
177
178
|
if index == -1
|
@@ -192,7 +193,7 @@ module Shoulda
|
|
192
193
|
|
193
194
|
def determine_where_to_break_line(line, args)
|
194
195
|
direction = args.fetch(:direction)
|
195
|
-
index = TERMINAL_WIDTH
|
196
|
+
index = Shoulda::Matchers::WordWrap::TERMINAL_WIDTH
|
196
197
|
offset = OFFSETS.fetch(direction)
|
197
198
|
|
198
199
|
while line[index] !~ /\s/ && (0...line.length).cover?(index)
|
data/shoulda-matchers.gemspec
CHANGED
@@ -2,30 +2,37 @@ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
|
2
2
|
require 'shoulda/matchers/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
|
-
s.name =
|
5
|
+
s.name = 'shoulda-matchers'
|
6
6
|
s.version = Shoulda::Matchers::VERSION.dup
|
7
|
-
s.authors = [
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
s.authors = [
|
8
|
+
'Tammer Saleh',
|
9
|
+
'Joe Ferris',
|
10
|
+
'Ryan McGeary',
|
11
|
+
'Dan Croak',
|
12
|
+
'Matt Jankowski',
|
13
|
+
'Stafford Brunk',
|
14
|
+
'Elliot Winkler',
|
15
|
+
]
|
16
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
17
|
+
s.email = 'support@thoughtbot.com'
|
18
|
+
s.homepage = 'https://matchers.shoulda.io/'
|
19
|
+
s.summary = 'Simple one-liner tests for common Rails functionality'
|
20
|
+
s.license = 'MIT'
|
21
|
+
s.description = 'Shoulda Matchers provides RSpec- and Minitest-compatible one-liners to test common Rails functionality that, if written by hand, would be much longer, more complex, and error-prone.'
|
15
22
|
s.metadata = {
|
16
23
|
'bug_tracker_uri' => 'https://github.com/thoughtbot/shoulda-matchers/issues',
|
17
24
|
'changelog_uri' => 'https://github.com/thoughtbot/shoulda-matchers/blob/master/NEWS.md',
|
18
25
|
'documentation_uri' => 'https://matchers.shoulda.io/docs',
|
19
26
|
'homepage_uri' => 'https://matchers.shoulda.io',
|
20
|
-
'source_code_uri' => 'https://github.com/thoughtbot/shoulda-matchers'
|
27
|
+
'source_code_uri' => 'https://github.com/thoughtbot/shoulda-matchers',
|
21
28
|
}
|
22
29
|
|
23
|
-
s.files = Dir.chdir(File.expand_path(
|
30
|
+
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
31
|
`git ls-files -z -- {docs,lib,README.md,MIT-LICENSE,shoulda-matchers.gemspec}`.
|
25
32
|
split("\x0")
|
26
33
|
end
|
27
|
-
s.require_paths = [
|
34
|
+
s.require_paths = ['lib']
|
28
35
|
|
29
|
-
s.required_ruby_version = '>= 2.
|
36
|
+
s.required_ruby_version = '>= 2.4.0'
|
30
37
|
s.add_dependency('activesupport', '>= 4.2.0')
|
31
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tammer Saleh
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2019-
|
17
|
+
date: 2019-06-09 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activesupport
|
@@ -30,7 +30,9 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 4.2.0
|
33
|
-
description:
|
33
|
+
description: Shoulda Matchers provides RSpec- and Minitest-compatible one-liners to
|
34
|
+
test common Rails functionality that, if written by hand, would be much longer,
|
35
|
+
more complex, and error-prone.
|
34
36
|
email: support@thoughtbot.com
|
35
37
|
executables: []
|
36
38
|
extensions: []
|
@@ -79,6 +81,7 @@ files:
|
|
79
81
|
- lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb
|
80
82
|
- lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb
|
81
83
|
- lib/shoulda/matchers/active_model/qualifiers.rb
|
84
|
+
- lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb
|
82
85
|
- lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb
|
83
86
|
- lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb
|
84
87
|
- lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb
|
@@ -181,15 +184,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
184
|
requirements:
|
182
185
|
- - ">="
|
183
186
|
- !ruby/object:Gem::Version
|
184
|
-
version: 2.
|
187
|
+
version: 2.4.0
|
185
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
189
|
requirements:
|
187
190
|
- - ">="
|
188
191
|
- !ruby/object:Gem::Version
|
189
192
|
version: '0'
|
190
193
|
requirements: []
|
191
|
-
rubygems_version: 3.0.
|
194
|
+
rubygems_version: 3.0.3
|
192
195
|
signing_key:
|
193
196
|
specification_version: 4
|
194
|
-
summary:
|
197
|
+
summary: Simple one-liner tests for common Rails functionality
|
195
198
|
test_files: []
|