shoulda-matchers 4.5.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0268da0cff119fb6c9128b70f1826451b582bdc2495acf382f4e512a6636d0c8'
4
- data.tar.gz: bf0698ed7605d8a8ef6b7e78bdc198bfa9502e1f2df134e3c5f524d1809b82da
3
+ metadata.gz: a62f760706ab97ba90edd181dbdf330ce6e8203c8ec3ec37a258022e202a53a6
4
+ data.tar.gz: 68f333b57646a8a437b73ff43f617efa9231674fb92f68de73365eb1408932f0
5
5
  SHA512:
6
- metadata.gz: 407cc79fc367dd4f02b346a199a8d9a9c4ecc5f2d814b98b25989489d96fd2d02308459e2d3a086aeacd67cbd5a9e91e7e237f3fe04efb64c196307dd53abe71
7
- data.tar.gz: a4eb04356408c22c7606ef403e1d4a042461e5323a9459875ad6a67f9f5cbc2944dee295d6086e6f1bea5b1d4fd7cace0fc5b701a4ba0199c75f7f002939f47a
6
+ metadata.gz: ea01851ee8521ff08ab6b1caea192c161e34286e5fd361cbceb6b84404813fa952acb73c70481c3140b2c5116ffce8bb386bf1feea70754f827a3918292b1bfb
7
+ data.tar.gz: 286ac5e78d534651889c5e3ed3843e1afa50d0fd77ed896c4ca3cf3622596cb7e1f47d2ae053e38100ce443dbfd80fbf1a8d099ecdfbbcf8d70912dbe3f42ad3
@@ -1397,7 +1397,7 @@ module Shoulda
1397
1397
  if options.key?(:foreign_key) && !foreign_key_correct?
1398
1398
  @missing = foreign_key_failure_message(klass, options[:foreign_key])
1399
1399
  false
1400
- elsif !column_names_for(klass).include?(foreign_key)
1400
+ elsif !has_column?(klass, foreign_key)
1401
1401
  @missing = foreign_key_failure_message(klass, foreign_key)
1402
1402
  false
1403
1403
  else
@@ -1405,6 +1405,15 @@ module Shoulda
1405
1405
  end
1406
1406
  end
1407
1407
 
1408
+ def has_column?(klass, column)
1409
+ case column
1410
+ when Array
1411
+ column.all? { |c| has_column?(klass, c) }
1412
+ else
1413
+ column_names_for(klass).include?(column)
1414
+ end
1415
+ end
1416
+
1408
1417
  def foreign_key_correct?
1409
1418
  option_verifier.correct_for_string?(
1410
1419
  :foreign_key,
@@ -1434,12 +1443,18 @@ module Shoulda
1434
1443
  end
1435
1444
 
1436
1445
  def foreign_key
1437
- if foreign_key_reflection
1438
- if foreign_key_reflection.respond_to?(:foreign_key)
1439
- foreign_key_reflection.foreign_key.to_s
1440
- else
1441
- foreign_key_reflection.primary_key_name.to_s
1442
- end
1446
+ key = if foreign_key_reflection
1447
+ if foreign_key_reflection.respond_to?(:foreign_key)
1448
+ foreign_key_reflection.foreign_key
1449
+ else
1450
+ foreign_key_reflection.primary_key_name
1451
+ end
1452
+ end
1453
+
1454
+ if key.is_a?(Array)
1455
+ key.map(&:to_s)
1456
+ else
1457
+ key.to_s
1443
1458
  end
1444
1459
  end
1445
1460
 
@@ -1,6 +1,6 @@
1
1
  module Shoulda
2
2
  module Matchers
3
3
  # @private
4
- VERSION = '4.5.0'.freeze
4
+ VERSION = '4.5.1'.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: 4.5.0
4
+ version: 4.5.1
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: 2021-01-11 00:00:00.000000000 Z
17
+ date: 2021-01-22 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport