shoulda-matchers 4.5.1 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +15 -13
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +0 -87
- data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +3 -6
- data/lib/shoulda/matchers/active_model/helpers.rb +1 -1
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +13 -34
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +3 -5
- data/lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb +71 -0
- data/lib/shoulda/matchers/active_model/numericality_matchers/submatchers.rb +43 -0
- data/lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb +26 -0
- data/lib/shoulda/matchers/active_model/qualifiers.rb +1 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +14 -2
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +6 -4
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +47 -1
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +31 -6
- data/lib/shoulda/matchers/active_model/validator.rb +1 -6
- data/lib/shoulda/matchers/active_model.rb +2 -1
- data/lib/shoulda/matchers/active_record/association_matcher.rb +20 -22
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +125 -22
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +21 -3
- data/lib/shoulda/matchers/rails_shim.rb +14 -39
- data/lib/shoulda/matchers/util/word_wrap.rb +2 -2
- data/lib/shoulda/matchers/version.rb +1 -1
- data/shoulda-matchers.gemspec +3 -3
- metadata +10 -8
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -161
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
|
+
version: 5.3.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:
|
17
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: activesupport
|
@@ -22,14 +22,14 @@ dependencies:
|
|
22
22
|
requirements:
|
23
23
|
- - ">="
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version:
|
25
|
+
version: 5.2.0
|
26
26
|
type: :runtime
|
27
27
|
prerelease: false
|
28
28
|
version_requirements: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 5.2.0
|
33
33
|
description: 'Shoulda Matchers provides RSpec- and Minitest-compatible one-liners
|
34
34
|
to test common Rails functionality that, if written by hand, would be much longer,
|
35
35
|
more complex, and error-prone. '
|
@@ -60,7 +60,6 @@ files:
|
|
60
60
|
- lib/shoulda/matchers/action_controller/set_session_matcher.rb
|
61
61
|
- lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb
|
62
62
|
- lib/shoulda/matchers/active_model.rb
|
63
|
-
- lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb
|
64
63
|
- lib/shoulda/matchers/active_model/allow_value_matcher.rb
|
65
64
|
- lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb
|
66
65
|
- lib/shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error.rb
|
@@ -80,7 +79,10 @@ files:
|
|
80
79
|
- lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb
|
81
80
|
- lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb
|
82
81
|
- lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb
|
82
|
+
- lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb
|
83
|
+
- lib/shoulda/matchers/active_model/numericality_matchers/submatchers.rb
|
83
84
|
- lib/shoulda/matchers/active_model/qualifiers.rb
|
85
|
+
- lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb
|
84
86
|
- lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb
|
85
87
|
- lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb
|
86
88
|
- lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb
|
@@ -174,7 +176,7 @@ licenses:
|
|
174
176
|
- MIT
|
175
177
|
metadata:
|
176
178
|
bug_tracker_uri: https://github.com/thoughtbot/shoulda-matchers/issues
|
177
|
-
changelog_uri: https://github.com/thoughtbot/shoulda-matchers/blob/
|
179
|
+
changelog_uri: https://github.com/thoughtbot/shoulda-matchers/blob/main/CHANGELOG.md
|
178
180
|
documentation_uri: https://matchers.shoulda.io/docs
|
179
181
|
homepage_uri: https://matchers.shoulda.io
|
180
182
|
source_code_uri: https://github.com/thoughtbot/shoulda-matchers
|
@@ -186,14 +188,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
188
|
requirements:
|
187
189
|
- - ">="
|
188
190
|
- !ruby/object:Gem::Version
|
189
|
-
version: 2.
|
191
|
+
version: 2.6.0
|
190
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
193
|
requirements:
|
192
194
|
- - ">="
|
193
195
|
- !ruby/object:Gem::Version
|
194
196
|
version: '0'
|
195
197
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
198
|
+
rubygems_version: 3.3.7
|
197
199
|
signing_key:
|
198
200
|
specification_version: 4
|
199
201
|
summary: Simple one-liner tests for common Rails functionality
|
@@ -1,161 +0,0 @@
|
|
1
|
-
module Shoulda
|
2
|
-
module Matchers
|
3
|
-
module ActiveModel
|
4
|
-
# The `allow_mass_assignment_of` matcher tests usage of Rails 3's
|
5
|
-
# `attr_accessible` and `attr_protected` macros, asserting that an
|
6
|
-
# attribute in your model is contained in either the whitelist or
|
7
|
-
# blacklist and thus can or cannot be set via mass assignment.
|
8
|
-
#
|
9
|
-
# class Post
|
10
|
-
# include ActiveModel::Model
|
11
|
-
# include ActiveModel::MassAssignmentSecurity
|
12
|
-
# attr_accessor :title
|
13
|
-
#
|
14
|
-
# attr_accessible :title
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# class User
|
18
|
-
# include ActiveModel::Model
|
19
|
-
# include ActiveModel::MassAssignmentSecurity
|
20
|
-
# attr_accessor :encrypted_password
|
21
|
-
#
|
22
|
-
# attr_protected :encrypted_password
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# # RSpec
|
26
|
-
# RSpec.describe Post, type: :model do
|
27
|
-
# it { should allow_mass_assignment_of(:title) }
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
# RSpec.describe User, type: :model do
|
31
|
-
# it { should_not allow_mass_assignment_of(:encrypted_password) }
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# # Minitest (Shoulda)
|
35
|
-
# class PostTest < ActiveSupport::TestCase
|
36
|
-
# should allow_mass_assignment_of(:title)
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# class UserTest < ActiveSupport::TestCase
|
40
|
-
# should_not allow_mass_assignment_of(:encrypted_password)
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# #### Optional qualifiers
|
44
|
-
#
|
45
|
-
# ##### as
|
46
|
-
#
|
47
|
-
# Use `as` if your mass-assignment rules apply only under a certain role
|
48
|
-
# *(Rails >= 3.1 only)*.
|
49
|
-
#
|
50
|
-
# class Post
|
51
|
-
# include ActiveModel::Model
|
52
|
-
# include ActiveModel::MassAssignmentSecurity
|
53
|
-
# attr_accessor :title
|
54
|
-
#
|
55
|
-
# attr_accessible :title, as: :admin
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
# # RSpec
|
59
|
-
# RSpec.describe Post, type: :model do
|
60
|
-
# it { should allow_mass_assignment_of(:title).as(:admin) }
|
61
|
-
# end
|
62
|
-
#
|
63
|
-
# # Minitest (Shoulda)
|
64
|
-
# class PostTest < ActiveSupport::TestCase
|
65
|
-
# should allow_mass_assignment_of(:title).as(:admin)
|
66
|
-
# end
|
67
|
-
#
|
68
|
-
# @return [AllowMassAssignmentOfMatcher]
|
69
|
-
#
|
70
|
-
def allow_mass_assignment_of(value)
|
71
|
-
AllowMassAssignmentOfMatcher.new(value)
|
72
|
-
end
|
73
|
-
|
74
|
-
# @private
|
75
|
-
class AllowMassAssignmentOfMatcher
|
76
|
-
attr_reader :failure_message, :failure_message_when_negated
|
77
|
-
|
78
|
-
def initialize(attribute)
|
79
|
-
@attribute = attribute.to_s
|
80
|
-
@options = {}
|
81
|
-
end
|
82
|
-
|
83
|
-
def as(role)
|
84
|
-
@options[:role] = role
|
85
|
-
self
|
86
|
-
end
|
87
|
-
|
88
|
-
def matches?(subject)
|
89
|
-
@subject = subject
|
90
|
-
if attr_mass_assignable?
|
91
|
-
if whitelisting?
|
92
|
-
@failure_message_when_negated = "#{@attribute} was made "\
|
93
|
-
'accessible'
|
94
|
-
elsif protected_attributes.empty?
|
95
|
-
@failure_message_when_negated = 'no attributes were protected'
|
96
|
-
else
|
97
|
-
@failure_message_when_negated =
|
98
|
-
"#{class_name} is protecting " <<
|
99
|
-
"#{protected_attributes.to_a.to_sentence}, " <<
|
100
|
-
"but not #{@attribute}."
|
101
|
-
end
|
102
|
-
true
|
103
|
-
else
|
104
|
-
@failure_message =
|
105
|
-
if whitelisting?
|
106
|
-
"Expected #{@attribute} to be accessible"
|
107
|
-
else
|
108
|
-
"Did not expect #{@attribute} to be protected"
|
109
|
-
end
|
110
|
-
false
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def description
|
115
|
-
[base_description, role_description].compact.join(' ')
|
116
|
-
end
|
117
|
-
|
118
|
-
private
|
119
|
-
|
120
|
-
def base_description
|
121
|
-
"allow mass assignment of #{@attribute}"
|
122
|
-
end
|
123
|
-
|
124
|
-
def role_description
|
125
|
-
if role != :default
|
126
|
-
"as #{role}"
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def role
|
131
|
-
@options[:role] || :default
|
132
|
-
end
|
133
|
-
|
134
|
-
def protected_attributes
|
135
|
-
@_protected_attributes ||= (@subject.class.protected_attributes || [])
|
136
|
-
end
|
137
|
-
|
138
|
-
def accessible_attributes
|
139
|
-
@_accessible_attributes ||=
|
140
|
-
(@subject.class.accessible_attributes || [])
|
141
|
-
end
|
142
|
-
|
143
|
-
def whitelisting?
|
144
|
-
authorizer.is_a?(::ActiveModel::MassAssignmentSecurity::WhiteList)
|
145
|
-
end
|
146
|
-
|
147
|
-
def attr_mass_assignable?
|
148
|
-
!authorizer.deny?(@attribute)
|
149
|
-
end
|
150
|
-
|
151
|
-
def authorizer
|
152
|
-
@subject.class.active_authorizer[role]
|
153
|
-
end
|
154
|
-
|
155
|
-
def class_name
|
156
|
-
@subject.class.name
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|