shoulda-matchers 4.3.0 → 5.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +170 -90
- data/lib/shoulda/matchers/action_controller/callback_matcher.rb +4 -89
- data/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +3 -2
- data/lib/shoulda/matchers/action_controller/flash_store.rb +2 -4
- data/lib/shoulda/matchers/action_controller/permit_matcher.rb +29 -27
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +6 -8
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +16 -13
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +2 -1
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -6
- data/lib/shoulda/matchers/action_controller/route_params.rb +1 -1
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +19 -13
- data/lib/shoulda/matchers/active_model.rb +0 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +29 -27
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +5 -5
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +2 -2
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +1 -1
- data/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +1 -1
- data/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +51 -25
- data/lib/shoulda/matchers/active_model/helpers.rb +1 -1
- data/lib/shoulda/matchers/active_model/numericality_matchers/comparison_matcher.rb +32 -30
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +1 -1
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +10 -2
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +2 -2
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +8 -7
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +28 -46
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +33 -9
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +72 -27
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_model/validation_matcher.rb +31 -6
- data/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +2 -4
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +2 -4
- data/lib/shoulda/matchers/active_model/validator.rb +4 -9
- data/lib/shoulda/matchers/active_record.rb +26 -24
- data/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +6 -3
- data/lib/shoulda/matchers/active_record/association_matcher.rb +119 -50
- data/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +5 -2
- data/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +11 -6
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +14 -15
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +30 -8
- data/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +23 -5
- data/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +3 -3
- data/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +4 -4
- data/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +3 -2
- data/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +7 -5
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +18 -9
- data/lib/shoulda/matchers/active_record/have_attached_matcher.rb +185 -0
- data/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +39 -17
- data/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +1 -1
- data/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +106 -0
- data/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +12 -10
- data/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +11 -7
- data/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +30 -9
- data/lib/shoulda/matchers/active_record/serialize_matcher.rb +13 -9
- data/lib/shoulda/matchers/active_record/uniqueness.rb +1 -1
- data/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +1 -3
- data/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +0 -2
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +80 -73
- data/lib/shoulda/matchers/doublespeak.rb +2 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +8 -5
- data/lib/shoulda/matchers/doublespeak/object_double.rb +1 -1
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +1 -5
- data/lib/shoulda/matchers/doublespeak/world.rb +2 -2
- data/lib/shoulda/matchers/error.rb +1 -1
- data/lib/shoulda/matchers/independent.rb +0 -1
- data/lib/shoulda/matchers/independent/delegate_method_matcher.rb +14 -13
- data/lib/shoulda/matchers/integrations/configuration.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +1 -1
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +2 -2
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +1 -1
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +1 -1
- data/lib/shoulda/matchers/rails_shim.rb +7 -40
- data/lib/shoulda/matchers/util.rb +16 -4
- data/lib/shoulda/matchers/util/word_wrap.rb +8 -8
- data/lib/shoulda/matchers/version.rb +1 -1
- data/lib/shoulda/matchers/warn.rb +3 -3
- data/shoulda-matchers.gemspec +12 -9
- metadata +15 -15
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +0 -159
- data/lib/shoulda/matchers/independent/delegate_method_matcher/stubbed_target.rb +0 -37
@@ -0,0 +1,185 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Matchers
|
3
|
+
module ActiveRecord
|
4
|
+
# The `have_one_attached` matcher tests usage of the
|
5
|
+
# `has_one_attached` macro.
|
6
|
+
#
|
7
|
+
# #### Example
|
8
|
+
#
|
9
|
+
# class User < ApplicationRecord
|
10
|
+
# has_one_attached :avatar
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# # RSpec
|
14
|
+
# RSpec.describe User, type: :model do
|
15
|
+
# it { should have_one_attached(:avatar) }
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# # Minitest (Shoulda)
|
19
|
+
# class UserTest < ActiveSupport::TestCase
|
20
|
+
# should have_one_attached(:avatar)
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# @return [HaveAttachedMatcher]
|
24
|
+
#
|
25
|
+
def have_one_attached(name)
|
26
|
+
HaveAttachedMatcher.new(:one, name)
|
27
|
+
end
|
28
|
+
|
29
|
+
# The `have_many_attached` matcher tests usage of the
|
30
|
+
# `has_many_attached` macro.
|
31
|
+
#
|
32
|
+
# #### Example
|
33
|
+
#
|
34
|
+
# class Message < ApplicationRecord
|
35
|
+
# has_many_attached :images
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# # RSpec
|
39
|
+
# RSpec.describe Message, type: :model do
|
40
|
+
# it { should have_many_attached(:images) }
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# # Minitest (Shoulda)
|
44
|
+
# class MessageTest < ActiveSupport::TestCase
|
45
|
+
# should have_many_attached(:images)
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# @return [HaveAttachedMatcher]
|
49
|
+
#
|
50
|
+
def have_many_attached(name)
|
51
|
+
HaveAttachedMatcher.new(:many, name)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @private
|
55
|
+
class HaveAttachedMatcher
|
56
|
+
attr_reader :name
|
57
|
+
|
58
|
+
def initialize(macro, name)
|
59
|
+
@macro = macro
|
60
|
+
@name = name
|
61
|
+
end
|
62
|
+
|
63
|
+
def description
|
64
|
+
"have a has_#{macro}_attached called #{name}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def failure_message
|
68
|
+
<<-MESSAGE
|
69
|
+
Expected #{expectation}, but this could not be proved.
|
70
|
+
#{@failure}
|
71
|
+
MESSAGE
|
72
|
+
end
|
73
|
+
|
74
|
+
def failure_message_when_negated
|
75
|
+
<<-MESSAGE
|
76
|
+
Did not expect #{expectation}, but it does.
|
77
|
+
MESSAGE
|
78
|
+
end
|
79
|
+
|
80
|
+
def expectation
|
81
|
+
"#{model_class.name} to #{description}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def matches?(subject)
|
85
|
+
@subject = subject
|
86
|
+
reader_attribute_exists? &&
|
87
|
+
writer_attribute_exists? &&
|
88
|
+
attachments_association_exists? &&
|
89
|
+
blobs_association_exists? &&
|
90
|
+
eager_loading_scope_exists?
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
attr_reader :subject, :macro
|
96
|
+
|
97
|
+
def reader_attribute_exists?
|
98
|
+
if subject.respond_to?(name)
|
99
|
+
true
|
100
|
+
else
|
101
|
+
@failure = "#{model_class.name} does not have a :#{name} method."
|
102
|
+
false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def writer_attribute_exists?
|
107
|
+
if subject.respond_to?("#{name}=")
|
108
|
+
true
|
109
|
+
else
|
110
|
+
@failure = "#{model_class.name} does not have a :#{name}= method."
|
111
|
+
false
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def attachments_association_exists?
|
116
|
+
if attachments_association_matcher.matches?(subject)
|
117
|
+
true
|
118
|
+
else
|
119
|
+
@failure = attachments_association_matcher.failure_message
|
120
|
+
false
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def attachments_association_matcher
|
125
|
+
@_attachments_association_matcher ||=
|
126
|
+
AssociationMatcher.new(
|
127
|
+
:"has_#{macro}",
|
128
|
+
attachments_association_name,
|
129
|
+
).
|
130
|
+
conditions(name: name).
|
131
|
+
class_name('ActiveStorage::Attachment').
|
132
|
+
inverse_of(:record)
|
133
|
+
end
|
134
|
+
|
135
|
+
def attachments_association_name
|
136
|
+
case macro
|
137
|
+
when :one then "#{name}_attachment"
|
138
|
+
when :many then "#{name}_attachments"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def blobs_association_exists?
|
143
|
+
if blobs_association_matcher.matches?(subject)
|
144
|
+
true
|
145
|
+
else
|
146
|
+
@failure = blobs_association_matcher.failure_message
|
147
|
+
false
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def blobs_association_matcher
|
152
|
+
@_blobs_association_matcher ||=
|
153
|
+
AssociationMatcher.new(
|
154
|
+
:"has_#{macro}",
|
155
|
+
blobs_association_name,
|
156
|
+
).
|
157
|
+
through(attachments_association_name).
|
158
|
+
class_name('ActiveStorage::Blob').
|
159
|
+
source(:blob)
|
160
|
+
end
|
161
|
+
|
162
|
+
def blobs_association_name
|
163
|
+
case macro
|
164
|
+
when :one then "#{name}_blob"
|
165
|
+
when :many then "#{name}_blobs"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def eager_loading_scope_exists?
|
170
|
+
if model_class.respond_to?("with_attached_#{name}")
|
171
|
+
true
|
172
|
+
else
|
173
|
+
@failure = "#{model_class.name} does not have a " \
|
174
|
+
":with_attached_#{name} scope."
|
175
|
+
false
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def model_class
|
180
|
+
subject.class
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -84,6 +84,8 @@ module Shoulda
|
|
84
84
|
|
85
85
|
# @private
|
86
86
|
class HaveDbColumnMatcher
|
87
|
+
OPTIONS = %i(precision limit default null scale primary).freeze
|
88
|
+
|
87
89
|
def initialize(column)
|
88
90
|
@column = column
|
89
91
|
@options = {}
|
@@ -95,7 +97,8 @@ module Shoulda
|
|
95
97
|
end
|
96
98
|
|
97
99
|
def with_options(opts = {})
|
98
|
-
|
100
|
+
validate_options(opts)
|
101
|
+
OPTIONS.each do |attribute|
|
99
102
|
if opts.key?(attribute.to_sym)
|
100
103
|
@options[attribute.to_sym] = opts[attribute.to_sym]
|
101
104
|
end
|
@@ -125,23 +128,38 @@ module Shoulda
|
|
125
128
|
|
126
129
|
def description
|
127
130
|
desc = "have db column named #{@column}"
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
desc << " of
|
131
|
+
if @options.key?(:column_type)
|
132
|
+
desc << " of type #{@options[:column_type]}"
|
133
|
+
end
|
134
|
+
if @options.key?(:precision)
|
135
|
+
desc << " of precision #{@options[:precision]}"
|
136
|
+
end
|
137
|
+
desc << " of limit #{@options[:limit]}" if @options.key?(:limit)
|
138
|
+
desc << " of default #{@options[:default]}" if @options.key?(:default)
|
139
|
+
desc << " of null #{@options[:null]}" if @options.key?(:null)
|
140
|
+
desc << " of primary #{@options[:primary]}" if @options.key?(:primary)
|
141
|
+
desc << " of scale #{@options[:scale]}" if @options.key?(:scale)
|
135
142
|
desc
|
136
143
|
end
|
137
144
|
|
138
145
|
protected
|
139
146
|
|
147
|
+
def validate_options(opts)
|
148
|
+
invalid_options = opts.keys.map(&:to_sym) - OPTIONS
|
149
|
+
if invalid_options.any?
|
150
|
+
raise(
|
151
|
+
ArgumentError,
|
152
|
+
"Unknown option(s): #{invalid_options.map(&:inspect).join(', ')}",
|
153
|
+
)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
140
157
|
def column_exists?
|
141
158
|
if model_class.column_names.include?(@column.to_s)
|
142
159
|
true
|
143
160
|
else
|
144
|
-
@missing =
|
161
|
+
@missing =
|
162
|
+
"#{model_class} does not have a db column named #{@column}."
|
145
163
|
false
|
146
164
|
end
|
147
165
|
end
|
@@ -152,8 +170,9 @@ module Shoulda
|
|
152
170
|
if matched_column.type.to_s == @options[:column_type].to_s
|
153
171
|
true
|
154
172
|
else
|
155
|
-
@missing =
|
156
|
-
|
173
|
+
@missing =
|
174
|
+
"#{model_class} has a db column named #{@column} " <<
|
175
|
+
"of type #{matched_column.type}, not #{@options[:column_type]}."
|
157
176
|
false
|
158
177
|
end
|
159
178
|
end
|
@@ -229,18 +248,21 @@ module Shoulda
|
|
229
248
|
true
|
230
249
|
else
|
231
250
|
@missing = "#{model_class} has a db column named #{@column} "
|
232
|
-
|
233
|
-
@
|
234
|
-
|
235
|
-
|
236
|
-
|
251
|
+
@missing <<
|
252
|
+
if @options[:primary]
|
253
|
+
'that is not primary, but should be'
|
254
|
+
else
|
255
|
+
'that is primary, but should not be'
|
256
|
+
end
|
237
257
|
false
|
238
258
|
end
|
239
259
|
end
|
240
260
|
|
241
261
|
def matched_column
|
242
262
|
@_matched_column ||= begin
|
243
|
-
column = model_class.columns.detect
|
263
|
+
column = model_class.columns.detect do |each|
|
264
|
+
each.name == @column.to_s
|
265
|
+
end
|
244
266
|
DecoratedColumn.new(model_class, column)
|
245
267
|
end
|
246
268
|
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module Shoulda
|
2
|
+
module Matchers
|
3
|
+
module ActiveRecord
|
4
|
+
# The `have_implicit_order_column` matcher tests that the model has `implicit_order_column`
|
5
|
+
# assigned to one of the table columns. (Rails 6+ only)
|
6
|
+
#
|
7
|
+
# class Product < ApplicationRecord
|
8
|
+
# self.implicit_order_column = :created_at
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# # RSpec
|
12
|
+
# RSpec.describe Product, type: :model do
|
13
|
+
# it { should have_implicit_order_column(:created_at) }
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # Minitest (Shoulda)
|
17
|
+
# class ProductTest < ActiveSupport::TestCase
|
18
|
+
# should have_implicit_order_column(:created_at)
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# @return [HaveImplicitOrderColumnMatcher]
|
22
|
+
#
|
23
|
+
if RailsShim.active_record_gte_6?
|
24
|
+
def have_implicit_order_column(column_name)
|
25
|
+
HaveImplicitOrderColumnMatcher.new(column_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# @private
|
30
|
+
class HaveImplicitOrderColumnMatcher
|
31
|
+
attr_reader :failure_message
|
32
|
+
|
33
|
+
def initialize(column_name)
|
34
|
+
@column_name = column_name
|
35
|
+
end
|
36
|
+
|
37
|
+
def matches?(subject)
|
38
|
+
@subject = subject
|
39
|
+
check_column_exists!
|
40
|
+
check_implicit_order_column_matches!
|
41
|
+
true
|
42
|
+
rescue SecondaryCheckFailedError => e
|
43
|
+
@failure_message = Shoulda::Matchers.word_wrap(
|
44
|
+
"Expected #{model.name} to #{expectation}, " +
|
45
|
+
"but that could not be proved: #{e.message}.",
|
46
|
+
)
|
47
|
+
false
|
48
|
+
rescue PrimaryCheckFailedError => e
|
49
|
+
@failure_message = Shoulda::Matchers.word_wrap(
|
50
|
+
"Expected #{model.name} to #{expectation}, but #{e.message}.",
|
51
|
+
)
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def failure_message_when_negated
|
56
|
+
Shoulda::Matchers.word_wrap(
|
57
|
+
"Expected #{model.name} not to #{expectation}, but it did.",
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
def description
|
62
|
+
expectation
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
attr_reader :column_name, :subject
|
68
|
+
|
69
|
+
def check_column_exists!
|
70
|
+
matcher = HaveDbColumnMatcher.new(column_name)
|
71
|
+
|
72
|
+
if !matcher.matches?(@subject)
|
73
|
+
raise SecondaryCheckFailedError.new(
|
74
|
+
"The :#{model.table_name} table does not have a " +
|
75
|
+
":#{column_name} column",
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def check_implicit_order_column_matches!
|
81
|
+
if model.implicit_order_column.to_s != column_name.to_s
|
82
|
+
message =
|
83
|
+
if model.implicit_order_column.nil?
|
84
|
+
'implicit_order_column is not set'
|
85
|
+
else
|
86
|
+
"it is :#{model.implicit_order_column}"
|
87
|
+
end
|
88
|
+
|
89
|
+
raise PrimaryCheckFailedError.new(message)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def model
|
94
|
+
subject.class
|
95
|
+
end
|
96
|
+
|
97
|
+
def expectation
|
98
|
+
"have an implicit_order_column of :#{column_name}"
|
99
|
+
end
|
100
|
+
|
101
|
+
class SecondaryCheckFailedError < StandardError; end
|
102
|
+
class PrimaryCheckFailedError < StandardError; end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -35,17 +35,19 @@ module Shoulda
|
|
35
35
|
def matches?(subject)
|
36
36
|
@subject = subject
|
37
37
|
if readonly_attributes.include?(@attribute)
|
38
|
-
@failure_message_when_negated = "Did not expect #{@attribute}
|
38
|
+
@failure_message_when_negated = "Did not expect #{@attribute}"\
|
39
|
+
' to be read-only'
|
39
40
|
true
|
40
41
|
else
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
"#{
|
47
|
-
|
48
|
-
|
42
|
+
@failure_message =
|
43
|
+
if readonly_attributes.empty?
|
44
|
+
"#{class_name} attribute #{@attribute} " <<
|
45
|
+
'is not read-only'
|
46
|
+
else
|
47
|
+
"#{class_name} is making " <<
|
48
|
+
"#{readonly_attributes.to_a.to_sentence} " <<
|
49
|
+
"read-only, but not #{@attribute}."
|
50
|
+
end
|
49
51
|
false
|
50
52
|
end
|
51
53
|
end
|
@@ -57,7 +59,7 @@ module Shoulda
|
|
57
59
|
private
|
58
60
|
|
59
61
|
def readonly_attributes
|
60
|
-
@
|
62
|
+
@_readonly_attributes ||= (@subject.class.readonly_attributes || [])
|
61
63
|
end
|
62
64
|
|
63
65
|
def class_name
|
@@ -12,7 +12,7 @@ module Shoulda
|
|
12
12
|
#
|
13
13
|
# # RSpec
|
14
14
|
# RSpec.describe Post, type: :model do
|
15
|
-
# it {
|
15
|
+
# it { should have_rich_text(:content) }
|
16
16
|
# end
|
17
17
|
#
|
18
18
|
# # Minitest (Shoulda)
|
@@ -20,20 +20,21 @@ module Shoulda
|
|
20
20
|
# should have_rich_text(:content)
|
21
21
|
# end
|
22
22
|
#
|
23
|
-
# @return [
|
23
|
+
# @return [HaveRichTextMatcher]
|
24
24
|
#
|
25
25
|
def have_rich_text(rich_text_attribute)
|
26
|
-
|
26
|
+
HaveRichTextMatcher.new(rich_text_attribute)
|
27
27
|
end
|
28
28
|
|
29
29
|
# @private
|
30
|
-
class
|
30
|
+
class HaveRichTextMatcher
|
31
31
|
def initialize(rich_text_attribute)
|
32
32
|
@rich_text_attribute = rich_text_attribute
|
33
33
|
end
|
34
34
|
|
35
35
|
def description
|
36
|
-
"have configured :#{rich_text_attribute} as a
|
36
|
+
"have configured :#{rich_text_attribute} as a "\
|
37
|
+
'ActionText::RichText association'
|
37
38
|
end
|
38
39
|
|
39
40
|
def failure_message
|
@@ -41,7 +42,8 @@ module Shoulda
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def failure_message_when_negated
|
44
|
-
"Did not expect #{subject.class} to have ActionText::RichText
|
45
|
+
"Did not expect #{subject.class} to have ActionText::RichText"\
|
46
|
+
" :#{rich_text_attribute}"
|
45
47
|
end
|
46
48
|
|
47
49
|
def matches?(subject)
|
@@ -67,7 +69,9 @@ module Shoulda
|
|
67
69
|
end
|
68
70
|
|
69
71
|
def has_expected_action_text?
|
70
|
-
|
72
|
+
defined?(ActionText::RichText) &&
|
73
|
+
@subject.send(rich_text_attribute).
|
74
|
+
instance_of?(ActionText::RichText)
|
71
75
|
end
|
72
76
|
|
73
77
|
def error_description
|