shoulda-matchers 6.3.1 → 6.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7de031f9a61f686180773f3541fe1b46124cd62dbc04198ed401d251594df5c5
4
- data.tar.gz: 7c237464b869b7bdbe9e567546852e3d84650d0b1d45c6d8c4b582598599f1eb
3
+ metadata.gz: 0a3a788cc37a73b615004a4e88dacb051413e00f9a752b78f00cfa8b529e4149
4
+ data.tar.gz: 99e5319049435d5ae107d068cecacd547bbd5135e1f1966bf8e15c40e5cde84f
5
5
  SHA512:
6
- metadata.gz: 3d96634f823c0f5ca1dd6c934e1117dfc30e87074cae350b3aeebb634733147a6add1be704e710039054cbd8819f4bd2e9eff9eebdd6864e2aacb1e78ab905e1
7
- data.tar.gz: 56e5672313e8c941ead528cf4c6f25884d29205624d9ee5fee2e562d97ffce52b5619fa5b8fb38ebc84c43b6068ee976084847ec2a9ec0804228e914940b258e
6
+ metadata.gz: 5f2b4708f133c2e0a790c99de4608d976d8dfe8704436adeea539e816a18bc6bca7612e7ff669bc4830f8f617550a0db7a70574f611a791dc27879d66f6ed09c
7
+ data.tar.gz: 460ac28a8c3833b30ec3171f62a5d5225712132837caeb1c620df49cdcc1fc2d92614a8a652ac93f7707b06d4fe24c5c9ee70fc9759b8b34a3929f845931a2b5
data/README.md CHANGED
@@ -167,9 +167,9 @@ end
167
167
  Most of the matchers provided by this gem are useful in a Rails context, and as
168
168
  such, can be used for different parts of a Rails app:
169
169
 
170
- * [database models backed by ActiveRecord](#activemodel-matchers)
170
+ * [database models backed by ActiveRecord](#activerecord-matchers)
171
171
  * [non-database models, form objects, etc. backed by
172
- ActiveModel](#activerecord-matchers)
172
+ ActiveModel](#activemodel-matchers)
173
173
  * [controllers](#actioncontroller-matchers)
174
174
  * [routes](#routing-matchers) (RSpec only)
175
175
  * [Rails-specific features like `delegate`](#independent-matchers)
@@ -19,10 +19,7 @@ module Shoulda
19
19
  def matches?(subject)
20
20
  self.subject = ModelReflector.new(subject, name)
21
21
 
22
- if option_verifier.correct_for_string?(
23
- :counter_cache,
24
- counter_cache,
25
- )
22
+ if correct_value?
26
23
  true
27
24
  else
28
25
  self.missing_option = "#{name} should have #{description}"
@@ -34,9 +31,42 @@ module Shoulda
34
31
 
35
32
  attr_accessor :subject, :counter_cache, :name
36
33
 
34
+ def correct_value?
35
+ expected = normalize_value
36
+
37
+ if expected.is_a?(Hash)
38
+ option_verifier.correct_for_hash?(
39
+ :counter_cache,
40
+ expected,
41
+ )
42
+ else
43
+ option_verifier.correct_for_string?(
44
+ :counter_cache,
45
+ expected,
46
+ )
47
+ end
48
+ end
49
+
37
50
  def option_verifier
38
51
  @_option_verifier ||= OptionVerifier.new(subject)
39
52
  end
53
+
54
+ def normalize_value
55
+ if Rails::VERSION::STRING >= '7.2'
56
+ case counter_cache
57
+ when true
58
+ { active: true, column: nil }
59
+ when String, Symbol
60
+ { active: true, column: counter_cache.to_s }
61
+ when Hash
62
+ { active: true, column: nil }.merge(counter_cache)
63
+ else
64
+ raise ArgumentError, 'Invalid counter_cache option'
65
+ end
66
+ else
67
+ counter_cache
68
+ end
69
+ end
40
70
  end
41
71
  end
42
72
  end
@@ -655,11 +655,22 @@ module Shoulda
655
655
  end
656
656
 
657
657
  def actual_default_value
658
- attribute_schema = model.attributes_to_define_after_schema_loads[attribute_name.to_s]
658
+ attribute_schema = if model.respond_to?(:_default_attributes)
659
+ model._default_attributes[attribute_name.to_s]
660
+ else
661
+ model.attributes_to_define_after_schema_loads[attribute_name.to_s]
662
+ end
663
+
664
+ if Kernel.const_defined?('ActiveModel::Attribute::UserProvidedDefault') &&
665
+ attribute_schema.is_a?(::ActiveModel::Attribute::UserProvidedDefault)
666
+ attribute_schema = attribute_schema.marshal_dump
667
+ end
659
668
 
660
669
  value = case attribute_schema
661
670
  in [_, { default: default_value } ]
662
671
  default_value
672
+ in [_, default_value, *]
673
+ default_value
663
674
  in [_, default_value]
664
675
  default_value
665
676
  end
@@ -1,6 +1,6 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  # @private
4
- VERSION = '6.3.1'.freeze
4
+ VERSION = '6.4.0'.freeze
5
5
  end
6
6
  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: 6.3.1
4
+ version: 6.4.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: 2024-08-13 00:00:00.000000000 Z
17
+ date: 2024-08-16 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport