composite_primary_keys 6.0.0 → 6.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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTg5ODVmZTc1ZThmM2U1Y2Q1OTllMDM1MGNhMGZiNTk5ZTc0ZWIwMg==
5
- data.tar.gz: !binary |-
6
- MDg4MjRkMzllODdmNTIwMjE3YTk4OTlmNDgyYzdlNmIxYmEyNDY2YQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MmYzM2E0YWY5MTY2ZWY0YTc3NGYwMmY0NDIxZjc4ODgzMzFmZmQyOTljNjQ5
10
- NmNmYTZmNzJmZjkxMzMzMDgxNzU3NTE1MWZlMmU0Mjk4MTlkN2RjNDQ1NzIy
11
- NTdlZDZjNjI5NTU3MWUxNmM5NTdlZjZiNTk4NzQ0MzNiNWVjNDY=
12
- data.tar.gz: !binary |-
13
- YTU3N2Y3YWM3N2I1OGMzNmE5NmI0ZDljNTgwNzRmYzQ2Nzg1YzdhM2E0MWI4
14
- OGY5NzUzNWUyNzZkOGU2MjgzOTM2MmMzYTAyYTkxYmJjMTM0NzZlNjViMDg2
15
- NjQ1NGUxNTI2ODFhZjVjYzk2YjNhYzg3OGYxNzMzZjczNjIzZGE=
2
+ SHA1:
3
+ metadata.gz: c978ed5109a507f202bab7ad54362c0f543d7ed6
4
+ data.tar.gz: 65dac9d9389d1cbf8727ec25a5cc1a93a706d91f
5
+ SHA512:
6
+ metadata.gz: 340806c9233d93bb1d18e4203080650600de58400231302bcf50b9f019f056d99d0c9883dc534d8483d081249b968bcf205f29e35fdb852565cc795ac9f4da5c
7
+ data.tar.gz: 10e4247371f8e979b96074ebe2e55ee79da37cc6a37ea03be8f21e48610180d122625f6690cd70eabf6fec65d4c017061cc52042ea81376b5bec0b72a94f3833
@@ -1,3 +1,11 @@
1
+ == 6.0.1 (2013-11-29)
2
+
3
+ * Handle records == :all in HasManyAssociation#delete_records. Without this calling
4
+ delete or clear on a has_many assocation can result in an exception (Tom Hughes)
5
+ * Don't include cpk key as an attributes - fixes json serialization - #168 (Charlie Savage)
6
+ * Fix tests running on ruby 1.9.3 (Charlie Savage)
7
+ * Update nested_attributes to work with activerecord 4.0.x (Nick DeLuca)
8
+
1
9
  == 6.0.0 (2013-08-04)
2
10
  * ActiveRecord 4.0 support (Sammy Larbi)
3
11
 
@@ -26,7 +26,7 @@ $:.unshift(File.dirname(__FILE__)) unless
26
26
 
27
27
  unless defined?(ActiveRecord)
28
28
  require 'rubygems'
29
- gem 'activerecord', '4.0.0'
29
+ gem 'activerecord', '~>4.0.0'
30
30
  require 'active_record'
31
31
  end
32
32
 
@@ -6,23 +6,27 @@ module ActiveRecord
6
6
  records.each { |r| r.destroy }
7
7
  update_counter(-records.length) unless inverse_updates_counter_cache?
8
8
  else
9
- # CPK
10
- # keys = records.map { |r| r[reflection.association_primary_key] }
11
- # scope = scope.where(reflection.association_primary_key => keys)
12
- table = Arel::Table.new(reflection.table_name)
13
- and_conditions = records.map do |record|
14
- eq_conditions = Array(reflection.association_primary_key).map do |name|
15
- table[name].eq(record[name])
9
+ if records == :all
10
+ scope = self.scope
11
+ else
12
+ # CPK
13
+ # keys = records.map { |r| r[reflection.association_primary_key] }
14
+ # scope = scope.where(reflection.association_primary_key => keys)
15
+ table = Arel::Table.new(reflection.table_name)
16
+ and_conditions = records.map do |record|
17
+ eq_conditions = Array(reflection.association_primary_key).map do |name|
18
+ table[name].eq(record[name])
19
+ end
20
+ Arel::Nodes::And.new(eq_conditions)
16
21
  end
17
- Arel::Nodes::And.new(eq_conditions)
18
- end
19
22
 
20
- condition = and_conditions.shift
21
- and_conditions.each do |and_condition|
22
- condition = condition.or(and_condition)
23
- end
23
+ condition = and_conditions.shift
24
+ and_conditions.each do |and_condition|
25
+ condition = condition.or(and_condition)
26
+ end
24
27
 
25
- scope = scope.where(condition)
28
+ scope = self.scope.where(condition)
29
+ end
26
30
 
27
31
  if method == :delete_all
28
32
  update_counter(-scope.delete_all)
@@ -1,5 +1,12 @@
1
1
  module ActiveRecord
2
2
  module Core
3
+ def init_internals_with_cpk
4
+ init_internals_without_cpk
5
+ # Remove cpk array from attributes, fixes to_json
6
+ @attributes.delete(self.class.primary_key) if self.composite?
7
+ end
8
+ alias_method_chain :init_internals, :cpk
9
+
3
10
  def initialize_dup(other)
4
11
  cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast)
5
12
  self.class.initialize_attributes(cloned_attributes, :serialized => false)
@@ -1,23 +1,21 @@
1
1
  module ActiveRecord
2
2
  module NestedAttributes
3
- def assign_nested_attributes_for_collection_association(association_name, attributes_collection, assignment_opts = {})
3
+ def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
4
4
  options = self.nested_attributes_options[association_name]
5
5
 
6
6
  unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
7
7
  raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
8
8
  end
9
9
 
10
- if options[:limit] && attributes_collection.size > options[:limit]
11
- raise TooManyRecords, "Maximum #{options[:limit]} records are allowed. Got #{attributes_collection.size} records instead."
12
- end
10
+ check_record_limit!(options[:limit], attributes_collection)
13
11
 
14
12
  if attributes_collection.is_a? Hash
15
13
  keys = attributes_collection.keys
16
14
  attributes_collection = if keys.include?('id') || keys.include?(:id)
17
- Array.wrap(attributes_collection)
18
- else
19
- attributes_collection.values
20
- end
15
+ [attributes_collection]
16
+ else
17
+ attributes_collection.values
18
+ end
21
19
  end
22
20
 
23
21
  association = association(association_name)
@@ -40,7 +38,7 @@ module ActiveRecord
40
38
  end.flatten.compact
41
39
  else
42
40
  attribute_ids = attributes_collection.map {|a| a['id'] || a[:id] }.compact
43
- attribute_ids.empty? ? [] : association.scoped.where(association.klass.primary_key => attribute_ids)
41
+ attribute_ids.empty? ? [] : association.scope.where(association.klass.primary_key => attribute_ids)
44
42
  end
45
43
 
46
44
  attributes_collection.each do |attributes|
@@ -48,11 +46,11 @@ module ActiveRecord
48
46
 
49
47
  if attributes['id'].blank?
50
48
  unless reject_new_record?(association_name, attributes)
51
- association.build(attributes.except(*unassignable_keys(assignment_opts)), assignment_opts)
49
+ association.build(attributes.except(*UNASSIGNABLE_KEYS))
52
50
  end
53
51
  elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes['id'].to_s }
54
- unless association.loaded? || call_reject_if(association_name, attributes)
55
- # Make sure we are operating on the actual object which is in the association's
52
+ unless call_reject_if(association_name, attributes)
53
+ # Make sure we are operatingon the actual object which is in the assocaition's
56
54
  # proxy_target array (either by finding it, or adding it if not found)
57
55
  target_record = association.target.detect { |record| record == existing_record }
58
56
 
@@ -61,16 +59,13 @@ module ActiveRecord
61
59
  else
62
60
  association.add_to_target(existing_record)
63
61
  end
64
-
65
62
  end
66
63
 
67
64
  if !call_reject_if(association_name, attributes)
68
- assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy], assignment_opts)
65
+ assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
69
66
  end
70
- elsif assignment_opts[:without_protection]
71
- association.build(attributes.except(*unassignable_keys(assignment_opts)), assignment_opts)
72
67
  else
73
- raise_nested_attributes_record_not_found(association_name, attributes['id'])
68
+ raise_nested_attributes_record_not_found!(association_name, attributes['id'])
74
69
  end
75
70
  end
76
71
  end
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 6
4
4
  MINOR = 0
5
- TINY = 0
5
+ TINY = 1
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -1,6 +1,9 @@
1
1
  PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
2
2
 
3
- require "test/unit"
3
+ require 'active_support/test_case'
4
+ require 'minitest/autorun'
5
+ require 'minitest/reporters'
6
+ MiniTest::Reporters.use!
4
7
 
5
8
  # To make debugging easier, test within this source tree versus an installed gem
6
9
  $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../abstract_unit', __FILE__)
2
+
3
+ class TestEqual < ActiveSupport::TestCase
4
+ fixtures :departments
5
+
6
+ def test_json
7
+ department = Department.first
8
+ assert_equal('{"department_id":1,"location_id":1}', department.to_json)
9
+ end
10
+
11
+ def test_serializable_hash
12
+ department = Department.first
13
+ assert_equal({"department_id" => 1,"location_id" => 1}, department.serializable_hash)
14
+ end
15
+ end
@@ -17,10 +17,10 @@
17
17
  test_polymorphic
18
18
  test_predicates
19
19
  test_santiago
20
+ test_serialize
20
21
  test_tutorial_example
21
22
  test_update
22
23
  test_validations
23
- test_delete_without_pk
24
24
  ).each do |test|
25
25
  require File.expand_path("../#{test}", __FILE__)
26
26
  end
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: 6.0.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-04 00:00:00.000000000 Z
12
+ date: 2013-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: 4.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: 4.0.0
28
28
  description: Composite key support for ActiveRecord
@@ -179,6 +179,7 @@ files:
179
179
  - test/test_polymorphic.rb
180
180
  - test/test_predicates.rb
181
181
  - test/test_santiago.rb
182
+ - test/test_serialize.rb
182
183
  - test/test_suite.rb
183
184
  - test/test_touch.rb
184
185
  - test/test_tutorial_example.rb
@@ -193,17 +194,17 @@ require_paths:
193
194
  - lib
194
195
  required_ruby_version: !ruby/object:Gem::Requirement
195
196
  requirements:
196
- - - ! '>='
197
+ - - '>='
197
198
  - !ruby/object:Gem::Version
198
199
  version: 1.9.3
199
200
  required_rubygems_version: !ruby/object:Gem::Requirement
200
201
  requirements:
201
- - - ! '>='
202
+ - - '>='
202
203
  - !ruby/object:Gem::Version
203
204
  version: '0'
204
205
  requirements: []
205
206
  rubyforge_project: compositekeys
206
- rubygems_version: 2.0.6
207
+ rubygems_version: 2.1.11
207
208
  signing_key:
208
209
  specification_version: 4
209
210
  summary: Composite key support for ActiveRecord
@@ -233,6 +234,7 @@ test_files:
233
234
  - test/test_polymorphic.rb
234
235
  - test/test_predicates.rb
235
236
  - test/test_santiago.rb
237
+ - test/test_serialize.rb
236
238
  - test/test_suite.rb
237
239
  - test/test_touch.rb
238
240
  - test/test_tutorial_example.rb