giga-safe-box 0.0.1
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 +7 -0
- data/giga-safe-box.gemspec +11 -0
- data/shoulda-matchers-8.0.1/LICENSE +22 -0
- data/shoulda-matchers-8.0.1/README.md +567 -0
- data/shoulda-matchers-8.0.1/docs/errors/NonCaseSwappableValueError.md +111 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/callback_matcher.rb +121 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/filter_param_matcher.rb +70 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/flash_store.rb +86 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/permit_matcher.rb +445 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +96 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/render_template_matcher.rb +84 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +145 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +115 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/respond_with_matcher.rb +148 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/route_matcher.rb +207 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/route_params.rb +62 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +228 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_matcher.rb +163 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +107 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/action_controller.rb +24 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_changed_value_error.rb +45 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_does_not_exist_error.rb +23 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter.rb +232 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setter_and_validator.rb +62 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters.rb +40 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/attribute_setters_and_validators.rb +48 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/successful_check.rb +14 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher/successful_setting.rb +14 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/allow_value_matcher.rb +695 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/comparison_matcher.rb +157 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/disallow_value_matcher.rb +78 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/errors.rb +52 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/have_secure_password_matcher.rb +125 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/helpers.rb +37 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/even_number_matcher.rb +45 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +67 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher.rb +45 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher.rb +44 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb +71 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/submatchers.rb +53 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers.rb +9 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/allow_blank.rb +26 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/allow_nil.rb +26 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/ignore_interference_by_writer.rb +101 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers/ignoring_interference_by_writer.rb +21 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/qualifiers.rb +14 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +180 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +128 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_comparison_of_matcher.rb +567 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +185 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +272 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +664 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +575 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +711 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +428 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_matcher/build_description.rb +62 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_matcher.rb +195 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validation_message_finder.rb +63 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validator.rb +127 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model.rb +96 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/accept_nested_attributes_for_matcher.rb +217 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matcher.rb +2134 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/counter_cache_matcher.rb +74 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/dependent_matcher.rb +62 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/inverse_of_matcher.rb +41 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +105 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +101 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +89 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/option_verifier.rb +142 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/optional_matcher.rb +71 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/order_matcher.rb +41 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/required_matcher.rb +76 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/source_matcher.rb +42 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers/through_matcher.rb +65 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/association_matchers.rb +9 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +784 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/encrypt_matcher.rb +174 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_attached_matcher.rb +343 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_db_column_matcher.rb +366 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_db_index_matcher.rb +287 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_implicit_order_column.rb +104 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_readonly_attribute_matcher.rb +95 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_rich_text_matcher.rb +83 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/have_secure_token_matcher.rb +132 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/normalize_matcher.rb +151 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/serialize_matcher.rb +203 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/model.rb +58 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/namespace.rb +39 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/test_model_creator.rb +49 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness/test_models.rb +55 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/uniqueness.rb +14 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +1197 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_record.rb +37 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/configuration.rb +31 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double.rb +103 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double_collection.rb +60 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/double_implementation_registry.rb +31 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/method_call.rb +44 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/object_double.rb +43 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +32 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/stub_implementation.rb +31 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak/world.rb +63 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/doublespeak.rb +38 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/error.rb +29 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent/delegate_method_matcher/target_not_defined_error.rb +15 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent/delegate_method_matcher.rb +540 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/independent.rb +11 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/configuration.rb +70 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/action_controller.rb +33 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/rails.rb +31 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries/routing.rb +29 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/libraries.rb +16 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/rails.rb +12 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/registry.rb +28 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/integrations.rb +43 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/matcher_collection.rb +99 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/matcher_context.rb +36 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/rails_shim.rb +190 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/routing.rb +10 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/util/word_wrap.rb +211 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/util.rb +110 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/version.rb +6 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers/warn.rb +28 -0
- data/shoulda-matchers-8.0.1/lib/shoulda/matchers.rb +25 -0
- data/shoulda-matchers-8.0.1/lib/shoulda-matchers.rb +1 -0
- data/shoulda-matchers-8.0.1/shoulda-matchers.gemspec +43 -0
- metadata +178 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
class AllowValueMatcher
|
|
5
|
+
# @private
|
|
6
|
+
class AttributeSetter
|
|
7
|
+
def self.set(args)
|
|
8
|
+
new(args).set
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
attr_reader(
|
|
12
|
+
:attribute_name,
|
|
13
|
+
:result_of_checking,
|
|
14
|
+
:result_of_setting,
|
|
15
|
+
:value_written,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def initialize(args)
|
|
19
|
+
@args = args
|
|
20
|
+
@matcher_name = args.fetch(:matcher_name)
|
|
21
|
+
@object = args.fetch(:object)
|
|
22
|
+
@attribute_name = args.fetch(:attribute_name)
|
|
23
|
+
@value_written = args.fetch(:value)
|
|
24
|
+
@ignore_interference_by_writer = args.fetch(
|
|
25
|
+
:ignore_interference_by_writer,
|
|
26
|
+
Qualifiers::IgnoreInterferenceByWriter.new,
|
|
27
|
+
)
|
|
28
|
+
@after_set_callback = args.fetch(:after_set_callback, -> { })
|
|
29
|
+
|
|
30
|
+
@result_of_checking = nil
|
|
31
|
+
@result_of_setting = nil
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def description
|
|
35
|
+
description = ":#{attribute_name} to "
|
|
36
|
+
description << Shoulda::Matchers::Util.inspect_value(value_written)
|
|
37
|
+
|
|
38
|
+
if attribute_changed_value?
|
|
39
|
+
description << ' -- which was read back as '
|
|
40
|
+
description << Shoulda::Matchers::Util.inspect_value(value_read)
|
|
41
|
+
description << ' --'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
description
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def run
|
|
48
|
+
check && set
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def run!
|
|
52
|
+
check && set!
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def check
|
|
56
|
+
if attribute_exists?
|
|
57
|
+
@result_of_checking = successful_check
|
|
58
|
+
true
|
|
59
|
+
else
|
|
60
|
+
@result_of_checking = attribute_does_not_exist_error
|
|
61
|
+
false
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def set!
|
|
66
|
+
if attribute_exists?
|
|
67
|
+
set
|
|
68
|
+
|
|
69
|
+
unless result_of_setting.successful?
|
|
70
|
+
raise result_of_setting
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
@result_of_checking = successful_check
|
|
74
|
+
@result_of_setting = successful_setting
|
|
75
|
+
|
|
76
|
+
true
|
|
77
|
+
else
|
|
78
|
+
attribute_does_not_exist!
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def set
|
|
83
|
+
object.public_send("#{attribute_name}=", value_written)
|
|
84
|
+
after_set_callback.call
|
|
85
|
+
|
|
86
|
+
@result_of_checking = successful_check
|
|
87
|
+
|
|
88
|
+
if raise_attribute_changed_value_error?
|
|
89
|
+
@result_of_setting = attribute_changed_value_error
|
|
90
|
+
false
|
|
91
|
+
else
|
|
92
|
+
@result_of_setting = successful_setting
|
|
93
|
+
true
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def failure_message
|
|
98
|
+
if successful?
|
|
99
|
+
raise "We're not supposed to be here!"
|
|
100
|
+
elsif result_of_setting
|
|
101
|
+
result_of_setting.message
|
|
102
|
+
else
|
|
103
|
+
result_of_checking.message
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def successful?
|
|
108
|
+
successfully_checked? && successfully_set?
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def unsuccessful?
|
|
112
|
+
!successful?
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def checked?
|
|
116
|
+
!result_of_checking.nil?
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def successfully_checked?
|
|
120
|
+
checked? && result_of_checking.successful?
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def unsuccessfully_checked?
|
|
124
|
+
!successfully_checked?
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def set?
|
|
128
|
+
!result_of_setting.nil?
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def successfully_set?
|
|
132
|
+
set? && result_of_setting.successful?
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def value_read
|
|
136
|
+
@_value_read ||= object.public_send(attribute_name)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def attribute_changed_value?
|
|
140
|
+
value_written != value_read
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
protected
|
|
144
|
+
|
|
145
|
+
attr_reader :args, :matcher_name, :object, :after_set_callback
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
def model
|
|
150
|
+
object.class
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def attribute_exists?
|
|
154
|
+
if active_resource_object?
|
|
155
|
+
object.known_attributes.include?(attribute_name.to_s)
|
|
156
|
+
else
|
|
157
|
+
object.respond_to?("#{attribute_name}=")
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def ignore_interference_by_writer
|
|
162
|
+
@ignore_interference_by_writer
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def raise_attribute_changed_value_error?
|
|
166
|
+
attribute_changed_value? &&
|
|
167
|
+
!(attribute_is_an_enum? && value_read_is_expected_for_an_enum?) &&
|
|
168
|
+
!ignore_interference_by_writer.considering?(value_read)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def attribute_is_an_enum?
|
|
172
|
+
enum_values.any?
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def value_read_is_expected_for_an_enum?
|
|
176
|
+
enum_values.key?(value_read) &&
|
|
177
|
+
enum_values[value_read] == value_written
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def enum_values
|
|
181
|
+
defined_enums.fetch(attribute_name.to_s, {})
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def defined_enums
|
|
185
|
+
if model.respond_to?(:defined_enums)
|
|
186
|
+
model.defined_enums
|
|
187
|
+
else
|
|
188
|
+
{}
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def successful_check
|
|
193
|
+
SuccessfulCheck.new
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def successful_setting
|
|
197
|
+
SuccessfulSetting.new
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def attribute_changed_value!
|
|
201
|
+
raise attribute_changed_value_error
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def attribute_changed_value_error
|
|
205
|
+
AttributeChangedValueError.create(
|
|
206
|
+
model: object.class,
|
|
207
|
+
attribute_name:,
|
|
208
|
+
value_written:,
|
|
209
|
+
value_read:,
|
|
210
|
+
)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def attribute_does_not_exist!
|
|
214
|
+
raise attribute_does_not_exist_error
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def attribute_does_not_exist_error
|
|
218
|
+
AttributeDoesNotExistError.create(
|
|
219
|
+
model: object.class,
|
|
220
|
+
attribute_name:,
|
|
221
|
+
value: value_written,
|
|
222
|
+
)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def active_resource_object?
|
|
226
|
+
object.respond_to?(:known_attributes)
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'forwardable'
|
|
2
|
+
|
|
3
|
+
module Shoulda
|
|
4
|
+
module Matchers
|
|
5
|
+
module ActiveModel
|
|
6
|
+
class AllowValueMatcher
|
|
7
|
+
# @private
|
|
8
|
+
class AttributeSetterAndValidator
|
|
9
|
+
extend Forwardable
|
|
10
|
+
|
|
11
|
+
def_delegators(
|
|
12
|
+
:allow_value_matcher,
|
|
13
|
+
:after_setting_value_callback,
|
|
14
|
+
:attribute_to_check_message_against,
|
|
15
|
+
:context,
|
|
16
|
+
:expected_message,
|
|
17
|
+
:expects_strict?,
|
|
18
|
+
:ignore_interference_by_writer,
|
|
19
|
+
:instance,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
def initialize(allow_value_matcher, attribute_name, value)
|
|
23
|
+
@allow_value_matcher = allow_value_matcher
|
|
24
|
+
@attribute_name = attribute_name
|
|
25
|
+
@value = value
|
|
26
|
+
@_attribute_setter = nil
|
|
27
|
+
@_validator = nil
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def attribute_setter
|
|
31
|
+
@_attribute_setter ||= AttributeSetter.new(
|
|
32
|
+
matcher_name: :allow_value,
|
|
33
|
+
object: instance,
|
|
34
|
+
attribute_name:,
|
|
35
|
+
value:,
|
|
36
|
+
ignore_interference_by_writer:,
|
|
37
|
+
after_set_callback: after_setting_value_callback,
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def attribute_setter_description
|
|
42
|
+
attribute_setter.description
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def validator
|
|
46
|
+
@_validator ||= Validator.new(
|
|
47
|
+
instance,
|
|
48
|
+
attribute_to_check_message_against,
|
|
49
|
+
context:,
|
|
50
|
+
expects_strict: expects_strict?,
|
|
51
|
+
expected_message:,
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
protected
|
|
56
|
+
|
|
57
|
+
attr_reader :allow_value_matcher, :attribute_name, :value
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
class AllowValueMatcher
|
|
5
|
+
# @private
|
|
6
|
+
class AttributeSetters
|
|
7
|
+
include Enumerable
|
|
8
|
+
|
|
9
|
+
def initialize(allow_value_matcher, values)
|
|
10
|
+
@tuples = values.map do |attribute_name, value|
|
|
11
|
+
AttributeSetterAndValidator.new(
|
|
12
|
+
allow_value_matcher,
|
|
13
|
+
attribute_name,
|
|
14
|
+
value,
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def each(&block)
|
|
20
|
+
tuples.each(&block)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def first_failing
|
|
24
|
+
tuples.detect(&method(:does_not_match?))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
attr_reader :tuples
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def does_not_match?(tuple)
|
|
34
|
+
!tuple.attribute_setter.set!
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
class AllowValueMatcher
|
|
5
|
+
# @private
|
|
6
|
+
class AttributeSettersAndValidators
|
|
7
|
+
include Enumerable
|
|
8
|
+
|
|
9
|
+
def initialize(allow_value_matcher, values)
|
|
10
|
+
@tuples = values.map do |attribute_name, value|
|
|
11
|
+
AttributeSetterAndValidator.new(
|
|
12
|
+
allow_value_matcher,
|
|
13
|
+
attribute_name,
|
|
14
|
+
value,
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def each(&block)
|
|
20
|
+
tuples.each(&block)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def first_passing
|
|
24
|
+
tuples.detect(&method(:matches?))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def first_failing
|
|
28
|
+
tuples.detect(&method(:does_not_match?))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
protected
|
|
32
|
+
|
|
33
|
+
attr_reader :tuples
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def matches?(tuple)
|
|
38
|
+
tuple.attribute_setter.set! && tuple.validator.call
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def does_not_match?(tuple)
|
|
42
|
+
!matches?(tuple)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|