composite_primary_keys 7.0.8 → 7.0.9

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
  SHA1:
3
- metadata.gz: cc0ec64847be066d4ea0a2e1cc8bbef8d938df03
4
- data.tar.gz: 27a854255a8c832b24ada64d40d056611d147b35
3
+ metadata.gz: 4b5c17b61f779d1923c042647a3a0dea63142517
4
+ data.tar.gz: 3861e029662b85465c42b792fa44ffdfc6671c1e
5
5
  SHA512:
6
- metadata.gz: 83dfb994708e614f2379506ae3282fcc3bd104ee29f37aadfb98bab8bfac019a9c9c8dd9376dd774c61e24da632296f1d7af8b8b5ada38bbbbe53f35870ed2fc
7
- data.tar.gz: 688a266a56600582a2853dd913684266953e17bd591a89594f903c12cfeaa181fe0832717fa33f961f47e74d96cd512d982700e27ecd9184d7eb314c999647db
6
+ metadata.gz: 97c81fea4acb2ba76454d845f3d7bd009739f1d254a920a9f2332d9976e8f15113fa5e4ef8e3f7805b61e3adfcee39ce7c3866c3948251a6955af8727ddef025
7
+ data.tar.gz: 9e92b5600385939973741abc0bb8b27b580cd0ad5931ef1015d8de7fa2cfa5aae38df75a20b68a798a856064bccb214a5a70b3025c7369ffc0ea376f2ec2e044
data/History.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 7.0.9 (2014-08-03)
2
+
3
+ * Second attemp at fixing instantiation of has_many records via :includes that use composite keys - this
4
+ time take into account no target records (Charlie Savage)
5
+
1
6
  == 7.0.8 (2014-08-03)
2
7
 
3
8
  * Fix instantiation of has_many records via :includes that use composite keys (Charlie Savage)
@@ -64,9 +64,10 @@ module ActiveRecord
64
64
  # CPK
65
65
  if key.is_a?(Array)
66
66
  id = Array(key).map do |column_alias|
67
- row[column_alias]
67
+ value = row[column_alias]
68
68
  end
69
- next if id.empty?
69
+ # At least the first value in the key has to be set. Should we require all values to be set?
70
+ next if id.first.nil?
70
71
  else
71
72
  id = row[key]
72
73
  next if id.nil?
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 7
4
4
  MINOR = 0
5
- TINY = 8
5
+ TINY = 9
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -43,20 +43,20 @@ class TestAssociations < ActiveSupport::TestCase
43
43
  product = products(:second_product)
44
44
  product_tarrif = product_tariffs(:second_free)
45
45
 
46
- # Old style, include a where clause to force eager loading
47
- #products = Product.find(:all, :include => :product_tariffs,
48
- # :conditions => ["product_tariffs.product_id = ?", product.id])
49
- products = Product.includes(:product_tariffs).where("product_tariffs.product_id = ?", product.id).references(:product_tariffs)
50
-
46
+ # First get a legitimate product tarrif
47
+ products = Product.includes(:product_tariffs).where('product_tariffs.product_id = ?', product.id).references(:product_tariffs)
51
48
  assert_equal(1, products.length)
52
49
  assert_equal(product, products.first)
53
- assert_equal([product_tarrif], product.product_tariffs)
50
+ assert_equal([product_tarrif], products.first.product_tariffs)
51
+ end
54
52
 
55
- # New style
56
- products = Product.includes(:product_tariffs).where('product_tariffs.product_id' => product.id)
53
+ def test_find_eager_loading_none
54
+ product = products(:third_product)
55
+
56
+ products = Product.includes(:product_tariffs).where(:id => product.id).references(:product_tariffs)
57
57
  assert_equal(1, products.length)
58
58
  assert_equal(product, products.first)
59
- assert_equal([product_tarrif], product.product_tariffs)
59
+ assert_empty(products.first.product_tariffs)
60
60
  end
61
61
 
62
62
  def test_find_includes_tariffs
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.8
4
+ version: 7.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage