composite_primary_keys 7.0.6 → 7.0.7

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: 6ac56003035ab69fb85bb4d3ec40644e5d3d80eb
4
- data.tar.gz: 5fa4ebe741e44a8334b63a52ee050acdfa42140f
3
+ metadata.gz: df048b0184c228678c8e77400bc92ec63f54c008
4
+ data.tar.gz: 01f520e6e90a9216c0d76e2174703ae9a2f0edbb
5
5
  SHA512:
6
- metadata.gz: 56e41e34385f9ae35be4a3c4fdeb8d5db149fdb6139122e67f169420637365c7c38d1e33e8e177eca175653fa0aa18fcd2d4e746126dafc66b6d20518b8c17d7
7
- data.tar.gz: b84fc59f176103f616bd31fc202a6e12e2c611cf75957ee6e4304da3850103b55da205d04b89f809d2652f8ad8c851186d41369c742a58f8a8b0319c98187be7
6
+ metadata.gz: db16567e55619423e804aeaed7f094d133af909875ad09ed59b8e52da55bae3e3aaeecf710cffc88423ed41dc90a4c31e43492ab8981c6088279c7b8b472a8e8
7
+ data.tar.gz: f526cdb914772be1e606fd7ec496829b29ed5682a29cbbddf19f19bd4cc6606f621726d7571a71df9ecf436a06392a148db878621576a086690e14eadbd2889c
@@ -1,6 +1,14 @@
1
+ == 7.0.7 (2014-07-29)
2
+
3
+ * Add back support for calling find like this (Sammy Larbi):
4
+
5
+ Membership.find('1,1')
6
+
7
+
1
8
  == 7.0.6 (2014-07-22)
2
9
 
3
- * Change the way we override ActiveRecord::Persistence to call sequence of included modules (such as callbacks)
10
+ * Change the way we override ActiveRecord::Persistence to call sequence of included modules such
11
+ as callbacks (Charlie Savage)
4
12
 
5
13
  == 7.0.5 (2014-07-21)
6
14
 
@@ -77,6 +77,8 @@ module CompositePrimaryKeys
77
77
  end
78
78
 
79
79
  def find_with_ids(*ids)
80
+ # CPK handle strings that come w/ calling to_param on CPK-enabled models
81
+ ids = parse_ids(ids)
80
82
  raise UnknownPrimaryKey.new(@klass) if primary_key.nil?
81
83
 
82
84
  expects_array = ids.first.kind_of?(Array)
@@ -84,7 +86,6 @@ module CompositePrimaryKeys
84
86
 
85
87
  # CPK - don't do this, we want an array of arrays
86
88
  #ids = ids.flatten.compact.uniq
87
-
88
89
  case ids.size
89
90
  when 0
90
91
  raise RecordNotFound, "Couldn't find #{@klass.name} without an ID"
@@ -170,6 +171,26 @@ module CompositePrimaryKeys
170
171
  raise_record_not_found_exception!(ids, result.size, expected_size)
171
172
  end
172
173
  end
174
+
175
+ private
176
+ def parse_ids(ids)
177
+ result = []
178
+ ids.each do |id|
179
+ if id.is_a?(String)
180
+ if id.index(",")
181
+ result << [id.split(",")]
182
+ else
183
+ result << [id]
184
+ end
185
+ elsif id.is_a?(Array) && id.count > 1 && id.first.to_s.index(",")
186
+ result << id.map{|subid| subid.split(",")}
187
+ else
188
+ result << [id]
189
+ end
190
+ end
191
+ result = result.flatten(1)
192
+ return result
193
+ end
173
194
  end
174
195
  end
175
196
  end
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 7
4
4
  MINOR = 0
5
- TINY = 6
5
+ TINY = 7
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -20,6 +20,10 @@ class TestFind < ActiveSupport::TestCase
20
20
  ref_code = ReferenceCode.find([1,3])
21
21
  assert_not_nil(ref_code)
22
22
  assert_equal([1,3], ref_code.id)
23
+
24
+ ref_code = ReferenceCode.find(1,3)
25
+ assert_not_nil(ref_code)
26
+ assert_equal([1,3], ref_code.id)
23
27
  end
24
28
 
25
29
  def test_find_some
@@ -91,4 +95,28 @@ class TestFind < ActiveSupport::TestCase
91
95
  employees = Employee.where(:department => department)
92
96
  assert_equal(2, employees.count)
93
97
  end
98
+
99
+ def test_find_one_with_params_id
100
+ params_id = ReferenceCode.find([1,3]).to_param
101
+ assert_equal params_id, "1,3"
102
+
103
+ ref_code = ReferenceCode.find(params_id)
104
+ assert_not_nil(ref_code)
105
+ assert_equal([1,3], ref_code.id)
106
+ end
107
+
108
+ def test_find_some_with_array_of_params_id
109
+ params_ids = ReferenceCode.find([1,3], [2,1]).map(&:to_param)
110
+ assert_equal ["1,3", "2,1"], params_ids
111
+
112
+ ref_codes = ReferenceCode.find(params_ids)
113
+ assert_kind_of(Array, ref_codes)
114
+ assert_equal(2, ref_codes.length)
115
+
116
+ ref_code = ref_codes[0]
117
+ assert_equal([1,3], ref_code.id)
118
+
119
+ ref_code = ref_codes[1]
120
+ assert_equal([2,1], ref_code.id)
121
+ end
94
122
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.6
4
+ version: 7.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-22 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord