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
data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
|
2
|
+
|
|
3
|
+
module Shoulda
|
|
4
|
+
module Matchers
|
|
5
|
+
module ActiveModel
|
|
6
|
+
module NumericalityMatchers
|
|
7
|
+
# @private
|
|
8
|
+
class RangeMatcher < ValidationMatcher
|
|
9
|
+
OPERATORS = [:>=, :<=].freeze
|
|
10
|
+
|
|
11
|
+
delegate :failure_message, to: :submatchers
|
|
12
|
+
|
|
13
|
+
def initialize(numericality_matcher, attribute, range)
|
|
14
|
+
super(attribute)
|
|
15
|
+
unless numericality_matcher.respond_to? :diff_to_compare
|
|
16
|
+
raise ArgumentError, 'numericality_matcher is invalid'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
@numericality_matcher = numericality_matcher
|
|
20
|
+
@range = range
|
|
21
|
+
@attribute = attribute
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def matches?(subject)
|
|
25
|
+
@subject = subject
|
|
26
|
+
submatchers.matches?(subject)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def simple_description
|
|
30
|
+
description = ''
|
|
31
|
+
|
|
32
|
+
if expects_strict?
|
|
33
|
+
description << ' strictly'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
description +
|
|
37
|
+
"disallow :#{attribute} from being a number that is not " +
|
|
38
|
+
range_description
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def range_description
|
|
42
|
+
"from #{Shoulda::Matchers::Util.inspect_range(@range)}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def submatchers
|
|
46
|
+
@_submatchers ||= NumericalityMatchers::Submatchers.new(build_submatchers)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def build_submatchers
|
|
52
|
+
submatcher_combos.map do |value, operator|
|
|
53
|
+
build_comparison_submatcher(value, operator)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def submatcher_combos
|
|
58
|
+
@range.minmax.zip(OPERATORS)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def build_comparison_submatcher(value, operator)
|
|
62
|
+
ComparisonMatcher.new(@numericality_matcher, value, operator).
|
|
63
|
+
for(@attribute).
|
|
64
|
+
with_message(@message).
|
|
65
|
+
on(@context)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/numericality_matchers/submatchers.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
module NumericalityMatchers
|
|
5
|
+
# @private
|
|
6
|
+
class Submatchers
|
|
7
|
+
def initialize(submatchers)
|
|
8
|
+
@submatchers = submatchers
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def matches?(subject)
|
|
12
|
+
@subject = subject
|
|
13
|
+
failing_submatchers.empty?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def failure_message
|
|
17
|
+
failing_submatcher.failure_message
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def failure_message_when_negated
|
|
21
|
+
non_failing_submatcher.failure_message_when_negated
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def add(submatcher)
|
|
25
|
+
@submatchers << submatcher
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def failing_submatchers
|
|
31
|
+
@_failing_submatchers ||= @submatchers.reject do |submatcher|
|
|
32
|
+
submatcher.matches?(@subject)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def non_failing_submatchers
|
|
37
|
+
@_non_failing_submatchers ||= @submatchers.reject do |submatcher|
|
|
38
|
+
submatcher.does_not_match?(@subject)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def failing_submatcher
|
|
43
|
+
failing_submatchers.last
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def non_failing_submatcher
|
|
47
|
+
non_failing_submatchers.last
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
module Qualifiers
|
|
5
|
+
# @private
|
|
6
|
+
module AllowBlank
|
|
7
|
+
def initialize(*args)
|
|
8
|
+
super
|
|
9
|
+
@expects_to_allow_blank = false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def allow_blank
|
|
13
|
+
@expects_to_allow_blank = true
|
|
14
|
+
self
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def expects_to_allow_blank?
|
|
20
|
+
@expects_to_allow_blank
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
module Qualifiers
|
|
5
|
+
# @private
|
|
6
|
+
module AllowNil
|
|
7
|
+
def initialize(*args)
|
|
8
|
+
super
|
|
9
|
+
@expects_to_allow_nil = false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def allow_nil
|
|
13
|
+
@expects_to_allow_nil = true
|
|
14
|
+
self
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def expects_to_allow_nil?
|
|
20
|
+
@expects_to_allow_nil
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
module Qualifiers
|
|
5
|
+
# @private
|
|
6
|
+
class IgnoreInterferenceByWriter
|
|
7
|
+
attr_reader :setting, :condition
|
|
8
|
+
|
|
9
|
+
def initialize(argument = :always)
|
|
10
|
+
set(argument)
|
|
11
|
+
@changed = false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def set(argument)
|
|
15
|
+
if argument.is_a?(self.class)
|
|
16
|
+
@setting = argument.setting
|
|
17
|
+
@condition = argument.condition
|
|
18
|
+
else
|
|
19
|
+
case argument
|
|
20
|
+
when true, :always
|
|
21
|
+
@setting = :always
|
|
22
|
+
when false, :never
|
|
23
|
+
@setting = :never
|
|
24
|
+
else
|
|
25
|
+
@setting = :sometimes
|
|
26
|
+
|
|
27
|
+
if argument.is_a?(Hash)
|
|
28
|
+
@condition = argument.fetch(:when)
|
|
29
|
+
else
|
|
30
|
+
raise invalid_argument_error(argument)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
@changed = true
|
|
36
|
+
|
|
37
|
+
self
|
|
38
|
+
rescue KeyError
|
|
39
|
+
raise invalid_argument_error(argument)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def default_to(argument)
|
|
43
|
+
temporary_ignore_interference_by_writer =
|
|
44
|
+
IgnoreInterferenceByWriter.new(argument)
|
|
45
|
+
|
|
46
|
+
unless changed?
|
|
47
|
+
@setting = temporary_ignore_interference_by_writer.setting
|
|
48
|
+
@condition = temporary_ignore_interference_by_writer.condition
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
self
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def considering?(value)
|
|
55
|
+
case setting
|
|
56
|
+
when :always then true
|
|
57
|
+
when :never then false
|
|
58
|
+
else condition_matches?(value)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def always?
|
|
63
|
+
setting == :always
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def never?
|
|
67
|
+
setting == :never
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def changed?
|
|
71
|
+
@changed
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def invalid_argument_error(invalid_argument)
|
|
77
|
+
ArgumentError.new(<<-ERROR)
|
|
78
|
+
Unknown argument: #{invalid_argument.inspect}.
|
|
79
|
+
|
|
80
|
+
ignoring_interference_by_writer takes one of three arguments:
|
|
81
|
+
|
|
82
|
+
* A symbol, either :never or :always.
|
|
83
|
+
* A boolean, either true (which means always) or false (which means
|
|
84
|
+
never).
|
|
85
|
+
* A hash with a single key, :when, and a single value, which is either
|
|
86
|
+
the name of a method or a Proc.
|
|
87
|
+
ERROR
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def condition_matches?(value)
|
|
91
|
+
if condition.respond_to?(:call)
|
|
92
|
+
condition.call(value)
|
|
93
|
+
else
|
|
94
|
+
value.public_send(condition)
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
module Qualifiers
|
|
5
|
+
# @private
|
|
6
|
+
module IgnoringInterferenceByWriter
|
|
7
|
+
attr_reader :ignore_interference_by_writer
|
|
8
|
+
|
|
9
|
+
def initialize(*)
|
|
10
|
+
@ignore_interference_by_writer = IgnoreInterferenceByWriter.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def ignoring_interference_by_writer(value = :always)
|
|
14
|
+
@ignore_interference_by_writer.set(value)
|
|
15
|
+
self
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
# @private
|
|
5
|
+
module Qualifiers
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
require_relative 'qualifiers/allow_nil'
|
|
12
|
+
require_relative 'qualifiers/allow_blank'
|
|
13
|
+
require_relative 'qualifiers/ignore_interference_by_writer'
|
|
14
|
+
require_relative 'qualifiers/ignoring_interference_by_writer'
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
# The `validate_absence_of` matcher tests the usage of the
|
|
5
|
+
# `validates_absence_of` validation.
|
|
6
|
+
#
|
|
7
|
+
# class PowerHungryCountry
|
|
8
|
+
# include ActiveModel::Model
|
|
9
|
+
# attr_accessor :nuclear_weapons
|
|
10
|
+
#
|
|
11
|
+
# validates_absence_of :nuclear_weapons
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# # RSpec
|
|
15
|
+
# RSpec.describe PowerHungryCountry, type: :model do
|
|
16
|
+
# it { should validate_absence_of(:nuclear_weapons) }
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# # Minitest (Shoulda)
|
|
20
|
+
# class PowerHungryCountryTest < ActiveSupport::TestCase
|
|
21
|
+
# should validate_absence_of(:nuclear_weapons)
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# #### Qualifiers
|
|
25
|
+
#
|
|
26
|
+
# ##### on
|
|
27
|
+
#
|
|
28
|
+
# Use `on` if your validation applies only under a certain context.
|
|
29
|
+
#
|
|
30
|
+
# class PowerHungryCountry
|
|
31
|
+
# include ActiveModel::Model
|
|
32
|
+
# attr_accessor :nuclear_weapons
|
|
33
|
+
#
|
|
34
|
+
# validates_absence_of :nuclear_weapons, on: :create
|
|
35
|
+
# end
|
|
36
|
+
#
|
|
37
|
+
# # RSpec
|
|
38
|
+
# RSpec.describe PowerHungryCountry, type: :model do
|
|
39
|
+
# it { should validate_absence_of(:nuclear_weapons).on(:create) }
|
|
40
|
+
# end
|
|
41
|
+
#
|
|
42
|
+
# # Minitest (Shoulda)
|
|
43
|
+
# class PowerHungryCountryTest < ActiveSupport::TestCase
|
|
44
|
+
# should validate_absence_of(:nuclear_weapons).on(:create)
|
|
45
|
+
# end
|
|
46
|
+
#
|
|
47
|
+
# ##### with_message
|
|
48
|
+
#
|
|
49
|
+
# Use `with_message` if you are using a custom validation message.
|
|
50
|
+
#
|
|
51
|
+
# class PowerHungryCountry
|
|
52
|
+
# include ActiveModel::Model
|
|
53
|
+
# attr_accessor :nuclear_weapons
|
|
54
|
+
#
|
|
55
|
+
# validates_absence_of :nuclear_weapons,
|
|
56
|
+
# message: "there shall be peace on Earth"
|
|
57
|
+
# end
|
|
58
|
+
#
|
|
59
|
+
# # RSpec
|
|
60
|
+
# RSpec.describe PowerHungryCountry, type: :model do
|
|
61
|
+
# it do
|
|
62
|
+
# should validate_absence_of(:nuclear_weapons).
|
|
63
|
+
# with_message("there shall be peace on Earth")
|
|
64
|
+
# end
|
|
65
|
+
# end
|
|
66
|
+
#
|
|
67
|
+
# # Minitest (Shoulda)
|
|
68
|
+
# class PowerHungryCountryTest < ActiveSupport::TestCase
|
|
69
|
+
# should validate_absence_of(:nuclear_weapons).
|
|
70
|
+
# with_message("there shall be peace on Earth")
|
|
71
|
+
# end
|
|
72
|
+
#
|
|
73
|
+
# #### Multiple attributes
|
|
74
|
+
#
|
|
75
|
+
# You can pass multiple attributes to assert that each one has the
|
|
76
|
+
# validation. Any qualifier chained on the matcher is applied to
|
|
77
|
+
# every attribute uniformly.
|
|
78
|
+
#
|
|
79
|
+
# class Robot
|
|
80
|
+
# include ActiveModel::Model
|
|
81
|
+
# attr_accessor :arms, :legs
|
|
82
|
+
#
|
|
83
|
+
# validates_absence_of :arms, :legs
|
|
84
|
+
# end
|
|
85
|
+
#
|
|
86
|
+
# # RSpec
|
|
87
|
+
# RSpec.describe Robot, type: :model do
|
|
88
|
+
# it { should validate_absence_of(:arms, :legs) }
|
|
89
|
+
# end
|
|
90
|
+
#
|
|
91
|
+
# # Minitest (Shoulda)
|
|
92
|
+
# class RobotTest < ActiveSupport::TestCase
|
|
93
|
+
# should validate_absence_of(:arms, :legs)
|
|
94
|
+
# end
|
|
95
|
+
#
|
|
96
|
+
# @return [ValidateAbsenceOfMatcher}
|
|
97
|
+
#
|
|
98
|
+
def validate_absence_of(*attrs)
|
|
99
|
+
MatcherCollection.build(attrs) { |attr| ValidateAbsenceOfMatcher.new(attr) }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# @private
|
|
103
|
+
class ValidateAbsenceOfMatcher < ValidationMatcher
|
|
104
|
+
def initialize(attribute)
|
|
105
|
+
super
|
|
106
|
+
@expected_message = :present
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def matches?(subject)
|
|
110
|
+
super(subject)
|
|
111
|
+
disallows_value_of(value, @expected_message)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def does_not_match?(subject)
|
|
115
|
+
super(subject)
|
|
116
|
+
allows_value_of(value, @expected_message)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def simple_description
|
|
120
|
+
"validate that :#{@attribute} is empty/falsy"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
private
|
|
124
|
+
|
|
125
|
+
def value
|
|
126
|
+
if reflection
|
|
127
|
+
obj = reflection.klass.new
|
|
128
|
+
if collection?
|
|
129
|
+
[obj]
|
|
130
|
+
else
|
|
131
|
+
obj
|
|
132
|
+
end
|
|
133
|
+
elsif array_column?
|
|
134
|
+
['an arbitrary value']
|
|
135
|
+
elsif enum_column?
|
|
136
|
+
enum_values.first
|
|
137
|
+
else
|
|
138
|
+
case column_type
|
|
139
|
+
when :integer, :float then 1
|
|
140
|
+
when :decimal then BigDecimal(1, 0)
|
|
141
|
+
when :datetime, :time, :timestamp then Time.current
|
|
142
|
+
when :date then Date.new
|
|
143
|
+
when :binary then '0'
|
|
144
|
+
when :uuid then SecureRandom.uuid
|
|
145
|
+
else 'an arbitrary value'
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def column_type
|
|
151
|
+
@subject.class.respond_to?(:columns_hash) &&
|
|
152
|
+
@subject.class.columns_hash[@attribute.to_s].respond_to?(:type) &&
|
|
153
|
+
@subject.class.columns_hash[@attribute.to_s].type
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def collection?
|
|
157
|
+
if reflection
|
|
158
|
+
[:has_many, :has_and_belongs_to_many].include?(reflection.macro)
|
|
159
|
+
else
|
|
160
|
+
false
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def reflection
|
|
165
|
+
@subject.class.respond_to?(:reflect_on_association) &&
|
|
166
|
+
@subject.class.reflect_on_association(@attribute)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def enum_column?
|
|
170
|
+
@subject.class.respond_to?(:defined_enums) &&
|
|
171
|
+
@subject.class.defined_enums.key?(@attribute.to_s)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def enum_values
|
|
175
|
+
@subject.class.defined_enums[@attribute.to_s].values
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
data/shoulda-matchers-8.0.1/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
module Shoulda
|
|
2
|
+
module Matchers
|
|
3
|
+
module ActiveModel
|
|
4
|
+
# The `validate_acceptance_of` matcher tests usage of the
|
|
5
|
+
# `validates_acceptance_of` validation.
|
|
6
|
+
#
|
|
7
|
+
# class Registration
|
|
8
|
+
# include ActiveModel::Model
|
|
9
|
+
# attr_accessor :eula
|
|
10
|
+
#
|
|
11
|
+
# validates_acceptance_of :eula
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# # RSpec
|
|
15
|
+
# RSpec.describe Registration, type: :model do
|
|
16
|
+
# it { should validate_acceptance_of(:eula) }
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
# # Minitest (Shoulda)
|
|
20
|
+
# class RegistrationTest < ActiveSupport::TestCase
|
|
21
|
+
# should validate_acceptance_of(:eula)
|
|
22
|
+
# end
|
|
23
|
+
#
|
|
24
|
+
# #### Qualifiers
|
|
25
|
+
#
|
|
26
|
+
# ##### on
|
|
27
|
+
#
|
|
28
|
+
# Use `on` if your validation applies only under a certain context.
|
|
29
|
+
#
|
|
30
|
+
# class Registration
|
|
31
|
+
# include ActiveModel::Model
|
|
32
|
+
# attr_accessor :terms_of_service
|
|
33
|
+
#
|
|
34
|
+
# validates_acceptance_of :terms_of_service, on: :create
|
|
35
|
+
# end
|
|
36
|
+
#
|
|
37
|
+
# # RSpec
|
|
38
|
+
# RSpec.describe Registration, type: :model do
|
|
39
|
+
# it do
|
|
40
|
+
# should validate_acceptance_of(:terms_of_service).
|
|
41
|
+
# on(:create)
|
|
42
|
+
# end
|
|
43
|
+
# end
|
|
44
|
+
#
|
|
45
|
+
# # Minitest (Shoulda)
|
|
46
|
+
# class RegistrationTest < ActiveSupport::TestCase
|
|
47
|
+
# should validate_acceptance_of(:terms_of_service).on(:create)
|
|
48
|
+
# end
|
|
49
|
+
#
|
|
50
|
+
# ##### with_message
|
|
51
|
+
#
|
|
52
|
+
# Use `with_message` if you are using a custom validation message.
|
|
53
|
+
#
|
|
54
|
+
# class Registration
|
|
55
|
+
# include ActiveModel::Model
|
|
56
|
+
# attr_accessor :terms_of_service
|
|
57
|
+
#
|
|
58
|
+
# validates_acceptance_of :terms_of_service,
|
|
59
|
+
# message: 'You must accept the terms of service'
|
|
60
|
+
# end
|
|
61
|
+
#
|
|
62
|
+
# # RSpec
|
|
63
|
+
# RSpec.describe Registration, type: :model do
|
|
64
|
+
# it do
|
|
65
|
+
# should validate_acceptance_of(:terms_of_service).
|
|
66
|
+
# with_message('You must accept the terms of service')
|
|
67
|
+
# end
|
|
68
|
+
# end
|
|
69
|
+
#
|
|
70
|
+
# # Minitest (Shoulda)
|
|
71
|
+
# class RegistrationTest < ActiveSupport::TestCase
|
|
72
|
+
# should validate_acceptance_of(:terms_of_service).
|
|
73
|
+
# with_message('You must accept the terms of service')
|
|
74
|
+
# end
|
|
75
|
+
#
|
|
76
|
+
# #### Multiple attributes
|
|
77
|
+
#
|
|
78
|
+
# You can pass multiple attributes to assert that each one has the
|
|
79
|
+
# validation. Any qualifier chained on the matcher is applied to
|
|
80
|
+
# every attribute uniformly.
|
|
81
|
+
#
|
|
82
|
+
# class User
|
|
83
|
+
# include ActiveModel::Model
|
|
84
|
+
# attr_accessor :terms, :privacy_policy
|
|
85
|
+
#
|
|
86
|
+
# validates_acceptance_of :terms, :privacy_policy
|
|
87
|
+
# end
|
|
88
|
+
#
|
|
89
|
+
# # RSpec
|
|
90
|
+
# RSpec.describe User, type: :model do
|
|
91
|
+
# it { should validate_acceptance_of(:terms, :privacy_policy) }
|
|
92
|
+
# end
|
|
93
|
+
#
|
|
94
|
+
# # Minitest (Shoulda)
|
|
95
|
+
# class UserTest < ActiveSupport::TestCase
|
|
96
|
+
# should validate_acceptance_of(:terms, :privacy_policy)
|
|
97
|
+
# end
|
|
98
|
+
#
|
|
99
|
+
# @return [ValidateAcceptanceOfMatcher]
|
|
100
|
+
#
|
|
101
|
+
def validate_acceptance_of(*attrs)
|
|
102
|
+
MatcherCollection.build(attrs) { |attr| ValidateAcceptanceOfMatcher.new(attr) }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# @private
|
|
106
|
+
class ValidateAcceptanceOfMatcher < ValidationMatcher
|
|
107
|
+
def initialize(attribute)
|
|
108
|
+
super
|
|
109
|
+
@expected_message = :accepted
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def matches?(subject)
|
|
113
|
+
super(subject)
|
|
114
|
+
disallows_value_of(false, @expected_message)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def does_not_match?(subject)
|
|
118
|
+
super(subject)
|
|
119
|
+
allows_value_of(false, @expected_message)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def simple_description
|
|
123
|
+
%(validate that :#{@attribute} has been set to "1")
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|