composite_primary_keys 7.0.2 → 7.0.3
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 +4 -4
- data/History.rdoc +7 -0
- data/lib/composite_primary_keys.rb +1 -1
- data/lib/composite_primary_keys/associations/join_dependency.rb +16 -2
- data/lib/composite_primary_keys/attribute_methods/read.rb +0 -24
- data/lib/composite_primary_keys/base.rb +1 -0
- data/lib/composite_primary_keys/nested_attributes.rb +1 -1
- data/lib/composite_primary_keys/relation.rb +1 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/abstract_unit.rb +1 -2
- data/test/fixtures/membership_statuses.yml +7 -1
- data/test/fixtures/memberships.yml +5 -1
- data/test/fixtures/users.yml +5 -1
- data/test/test_associations.rb +2 -1
- data/test/test_callbacks.rb +99 -77
- data/test/test_suite.rb +4 -0
- data/test/test_touch.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e6b7d1159c668d23e4edcdf8b2fcb0634a81c7a
|
4
|
+
data.tar.gz: ba6783910246e18e7aaa729e0fec71160ca8c7fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2943835037daa080b7a2d1f1e4d18a60d761968729c45460d8a4ce4da1f980aaa53f9c346e18459f7d3347811df83de0d4710835d3c1f8792a2f0f00255a787
|
7
|
+
data.tar.gz: 9e2b28913094cb75c372572a8c4eaed1d167cef8fd73b091aeb75e93799dbac68d1ccfe0be1ca1478d4469533fa81caf7df6ea866396320881daba4f64b2b796
|
data/History.rdoc
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 7.0.3 (2014-07-04)
|
2
|
+
|
3
|
+
* Fixes for Rails 4.1.2+ compatibility (Tom Hughes)
|
4
|
+
* Nested attribute fix (Sammy Larb)
|
5
|
+
* Test fixes (Sammy Larb)
|
6
|
+
* Fixes instantiating join records (Charlie Savage)
|
7
|
+
|
1
8
|
== 7.0.2 (2014-06-01)
|
2
9
|
|
3
10
|
* Fix id_was when one of the column names is called id (Adrian Hooper)
|
@@ -1,6 +1,20 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module Associations
|
3
3
|
class JoinDependency
|
4
|
+
class Aliases # :nodoc:
|
5
|
+
def column_alias(node, column)
|
6
|
+
# CPK
|
7
|
+
#@alias_cache[node][column]
|
8
|
+
if column.kind_of?(Array)
|
9
|
+
column.map do |a_column|
|
10
|
+
@alias_cache[node][a_column]
|
11
|
+
end
|
12
|
+
else
|
13
|
+
@alias_cache[node][column]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
4
18
|
def instantiate(result_set, aliases)
|
5
19
|
primary_key = aliases.column_alias(join_root, join_root.primary_key)
|
6
20
|
type_caster = result_set.column_type primary_key
|
@@ -18,8 +32,8 @@ module ActiveRecord
|
|
18
32
|
result_set.each { |row_hash|
|
19
33
|
# CPK
|
20
34
|
#primary_id = type_caster.type_cast row_hash[primary_key]
|
21
|
-
primary_id = if
|
22
|
-
|
35
|
+
primary_id = if primary_key.kind_of?(Array)
|
36
|
+
primary_key.map {|key| type_caster.type_cast row_hash[key]}
|
23
37
|
else
|
24
38
|
type_caster.type_cast row_hash[primary_key]
|
25
39
|
end
|
@@ -1,30 +1,6 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module AttributeMethods
|
3
3
|
module Read
|
4
|
-
module ClassMethods
|
5
|
-
def internal_attribute_access_code(attr_name, cast_code)
|
6
|
-
# CPK - this is a really horrid hack, needed to get
|
7
|
-
# right class namespace :(
|
8
|
-
if cast_code.match(/^ActiveRecord/)
|
9
|
-
cast_code = "::#{cast_code}"
|
10
|
-
end
|
11
|
-
access_code = "(v=@attributes[attr_name]) && #{cast_code}"
|
12
|
-
|
13
|
-
# CPK
|
14
|
-
#unless attr_name == primary_key
|
15
|
-
primary_keys = Array(self.primary_key)
|
16
|
-
unless primary_keys.include?(attr_name.to_s)
|
17
|
-
access_code.insert(0, "missing_attribute(attr_name, caller) unless @attributes.has_key?(attr_name); ")
|
18
|
-
end
|
19
|
-
|
20
|
-
if cache_attribute?(attr_name)
|
21
|
-
access_code = "@attributes_cache[attr_name] ||= (#{access_code})"
|
22
|
-
end
|
23
|
-
|
24
|
-
"attr_name = '#{attr_name}'; #{access_code}"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
4
|
rails_read_attribute = instance_method(:read_attribute)
|
29
5
|
define_method(:read_attribute) do |attr_name|
|
30
6
|
if attr_name.kind_of?(Array)
|
@@ -114,6 +114,7 @@ module ActiveRecord
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def ==(comparison_object)
|
117
|
+
return false if !persisted? && comparison_object.object_id != object_id
|
117
118
|
return true if equal? comparison_object
|
118
119
|
ids.is_a?(Array) ? super(comparison_object) && ids.all? {|id| !id.nil?} : super(comparison_object)
|
119
120
|
end
|
@@ -31,7 +31,7 @@ module ActiveRecord
|
|
31
31
|
eq_predicates = association.klass.primary_key.zip(ids).map do |primary_key, value|
|
32
32
|
association.klass.arel_table[primary_key].eq(value)
|
33
33
|
end
|
34
|
-
association.
|
34
|
+
association.scope.where(*eq_predicates).to_a
|
35
35
|
else
|
36
36
|
[]
|
37
37
|
end
|
data/test/abstract_unit.rb
CHANGED
@@ -3,9 +3,8 @@ PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
3
3
|
# To make debugging easier, test within this source tree versus an installed gem
|
4
4
|
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
5
5
|
require 'composite_primary_keys'
|
6
|
-
|
7
|
-
require 'active_support/test_case'
|
8
6
|
require 'minitest/autorun'
|
7
|
+
require 'active_support/test_case'
|
9
8
|
|
10
9
|
# Now load the connection spec
|
11
10
|
require File.join(PROJECT_ROOT, "test", "connections", "connection_spec")
|
data/test/fixtures/users.yml
CHANGED
data/test/test_associations.rb
CHANGED
@@ -255,8 +255,9 @@ class TestAssociations < ActiveSupport::TestCase
|
|
255
255
|
|
256
256
|
def test_has_many_with_primary_key_with_associations
|
257
257
|
memberships = Membership.includes(:statuses).where("membership_statuses.status = ?", 'Active').references(:membership_statuses)
|
258
|
-
assert_equal(
|
258
|
+
assert_equal(2, memberships.length)
|
259
259
|
assert_equal([1,1], memberships[0].id)
|
260
|
+
assert_equal([3,2], memberships[1].id)
|
260
261
|
end
|
261
262
|
|
262
263
|
def test_limitable_reflections
|
data/test/test_callbacks.rb
CHANGED
@@ -1,77 +1,99 @@
|
|
1
|
-
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
-
|
3
|
-
class
|
4
|
-
fixtures :suburbs
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@@callbacks = OpenStruct.new
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
suburb.name
|
67
|
-
suburb.save
|
68
|
-
|
69
|
-
assert(@@callbacks.
|
70
|
-
assert(@@callbacks.
|
71
|
-
assert(@@callbacks.
|
72
|
-
|
73
|
-
assert(@@callbacks.
|
74
|
-
assert(@@callbacks.
|
75
|
-
assert(@@callbacks.
|
76
|
-
end
|
77
|
-
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestCallbacks < ActiveSupport::TestCase
|
4
|
+
fixtures :suburbs
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@@callbacks = OpenStruct.new
|
8
|
+
|
9
|
+
Suburb.class_eval do
|
10
|
+
before_create do
|
11
|
+
@@callbacks.before_create = true
|
12
|
+
end
|
13
|
+
|
14
|
+
after_create do
|
15
|
+
@@callbacks.after_create = true
|
16
|
+
end
|
17
|
+
|
18
|
+
around_create do |suburb, block|
|
19
|
+
@@callbacks.around_create = true
|
20
|
+
block.call
|
21
|
+
end
|
22
|
+
|
23
|
+
before_save do
|
24
|
+
@@callbacks.before_save = true
|
25
|
+
end
|
26
|
+
|
27
|
+
after_save do
|
28
|
+
@@callbacks.after_save = true
|
29
|
+
end
|
30
|
+
|
31
|
+
around_save do |suburb, block|
|
32
|
+
@@callbacks.around_save = true
|
33
|
+
block.call
|
34
|
+
end
|
35
|
+
|
36
|
+
before_update do
|
37
|
+
@@callbacks.before_update = true
|
38
|
+
end
|
39
|
+
|
40
|
+
after_update do
|
41
|
+
@@callbacks.after_update = true
|
42
|
+
end
|
43
|
+
|
44
|
+
around_update do |suburb, block|
|
45
|
+
@@callbacks.around_update = true
|
46
|
+
block.call
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def teardown
|
52
|
+
Suburb.reset_callbacks(:create)
|
53
|
+
Suburb.reset_callbacks(:save)
|
54
|
+
Suburb.reset_callbacks(:update)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_create
|
58
|
+
refute(@@callbacks.before_save)
|
59
|
+
refute(@@callbacks.after_save)
|
60
|
+
refute(@@callbacks.around_save)
|
61
|
+
|
62
|
+
refute(@@callbacks.before_create)
|
63
|
+
refute(@@callbacks.after_create)
|
64
|
+
refute(@@callbacks.around_create)
|
65
|
+
|
66
|
+
suburb = Suburb.new(:city_id => 3, :suburb_id => 3, :name => 'created')
|
67
|
+
suburb.save!
|
68
|
+
|
69
|
+
assert(@@callbacks.before_save)
|
70
|
+
assert(@@callbacks.after_save)
|
71
|
+
assert(@@callbacks.around_save)
|
72
|
+
|
73
|
+
assert(@@callbacks.before_create)
|
74
|
+
assert(@@callbacks.after_create)
|
75
|
+
assert(@@callbacks.around_create)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_update
|
79
|
+
refute(@@callbacks.before_save)
|
80
|
+
refute(@@callbacks.after_save)
|
81
|
+
refute(@@callbacks.around_save)
|
82
|
+
|
83
|
+
refute(@@callbacks.before_create)
|
84
|
+
refute(@@callbacks.after_create)
|
85
|
+
refute(@@callbacks.around_create)
|
86
|
+
|
87
|
+
suburb = suburbs(:first)
|
88
|
+
suburb.name = 'Updated'
|
89
|
+
suburb.save
|
90
|
+
|
91
|
+
assert(@@callbacks.before_update)
|
92
|
+
assert(@@callbacks.after_update)
|
93
|
+
assert(@@callbacks.around_update)
|
94
|
+
|
95
|
+
assert(@@callbacks.before_save)
|
96
|
+
assert(@@callbacks.after_save)
|
97
|
+
assert(@@callbacks.around_save)
|
98
|
+
end
|
99
|
+
end
|
data/test/test_suite.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
%w(
|
2
|
+
test_aliases
|
2
3
|
test_associations
|
3
4
|
test_attribute_methods
|
4
5
|
test_attributes
|
5
6
|
test_calculations
|
7
|
+
test_callbacks
|
6
8
|
test_composite_arrays
|
7
9
|
test_create
|
8
10
|
test_delete
|
@@ -13,11 +15,13 @@
|
|
13
15
|
test_habtm
|
14
16
|
test_ids
|
15
17
|
test_miscellaneous
|
18
|
+
test_nested_attributes
|
16
19
|
test_pagination
|
17
20
|
test_polymorphic
|
18
21
|
test_predicates
|
19
22
|
test_santiago
|
20
23
|
test_serialize
|
24
|
+
test_touch
|
21
25
|
test_tutorial_example
|
22
26
|
test_update
|
23
27
|
test_validations
|
data/test/test_touch.rb
CHANGED
@@ -11,8 +11,8 @@ class TestTouch < ActiveSupport::TestCase
|
|
11
11
|
previously_updated_at = tariff.updated_at
|
12
12
|
|
13
13
|
tariff.amount = previous_amount + 1
|
14
|
+
sleep 1.0 # we need to sleep for 1 second because the times updated (on mysql, at least) are only precise to 1 second.
|
14
15
|
tariff.touch
|
15
|
-
sleep 0.1
|
16
16
|
assert_not_equal previously_updated_at, tariff.updated_at
|
17
17
|
assert_equal previous_amount + 1, tariff.amount
|
18
18
|
assert tariff.amount_changed?, 'tarif amount should have changed'
|
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.
|
4
|
+
version: 7.0.3
|
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-
|
11
|
+
date: 2014-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.1.
|
19
|
+
version: 4.1.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.1.
|
26
|
+
version: 4.1.4
|
27
27
|
description: Composite key support for ActiveRecord
|
28
28
|
email:
|
29
29
|
executables: []
|