composite_primary_keys 7.0.2 → 7.0.3

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
  SHA1:
3
- metadata.gz: 1a95b00436decb1d0c5da9fc42f706be34aaf6dc
4
- data.tar.gz: 08b6d26c4d0e136b577c59394becfc82af3b0a21
3
+ metadata.gz: 4e6b7d1159c668d23e4edcdf8b2fcb0634a81c7a
4
+ data.tar.gz: ba6783910246e18e7aaa729e0fec71160ca8c7fb
5
5
  SHA512:
6
- metadata.gz: 1e02f25ffa1220a27361433d224c07f584ec130dc7cb2dfbf1f542e903486d80dec239555b62a96a96a3375eec45fa82bf9810374700d40184075aeb7ddd30b0
7
- data.tar.gz: a5d9c69b6eccada21cfed579bcd2bd9a4f6ea1987a9bb3cf4c43700c31a4859d24fb0514d8b27d8d46d00cd6ccc79b59dd89e5568bb8646953051810ecd4ef3e
6
+ metadata.gz: a2943835037daa080b7a2d1f1e4d18a60d761968729c45460d8a4ce4da1f980aaa53f9c346e18459f7d3347811df83de0d4710835d3c1f8792a2f0f00255a787
7
+ data.tar.gz: 9e2b28913094cb75c372572a8c4eaed1d167cef8fd73b091aeb75e93799dbac68d1ccfe0be1ca1478d4469533fa81caf7df6ea866396320881daba4f64b2b796
@@ -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)
@@ -26,7 +26,7 @@ $:.unshift(File.dirname(__FILE__)) unless
26
26
 
27
27
  unless defined?(ActiveRecord)
28
28
  require 'rubygems'
29
- gem 'activerecord', '~>4.1.0'
29
+ gem 'activerecord', '~>4.1.4'
30
30
  require 'active_record'
31
31
  end
32
32
 
@@ -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 row_hash[primary_key].kind_of?(Array)
22
- row_hash[primary_key].map {|key| type_caster.type_cast key}
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.scoped.where(*eq_predicates).to_a
34
+ association.scope.where(*eq_predicates).to_a
35
35
  else
36
36
  []
37
37
  end
@@ -81,7 +81,7 @@ module ActiveRecord
81
81
  end
82
82
  end
83
83
 
84
- def update_record(values, id, id_was)
84
+ def _update_record(values, id, id_was)
85
85
  substitutes, binds = substitute_values values
86
86
 
87
87
  # CPK
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 7
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -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")
@@ -8,4 +8,10 @@ drnic-cpk:
8
8
  id: 2
9
9
  user_id: 2
10
10
  group_id: 1
11
- status: Owner
11
+ status: Owner
12
+
13
+ cfis-cpk:
14
+ id: 3
15
+ user_id: 3
16
+ group_id: 2
17
+ status: Active
@@ -4,4 +4,8 @@ santiago-cpk:
4
4
 
5
5
  drnic-cpk:
6
6
  user_id: 2
7
- group_id: 1
7
+ group_id: 1
8
+
9
+ cfis-cpk:
10
+ user_id: 3
11
+ group_id: 2
@@ -4,4 +4,8 @@ santiago:
4
4
 
5
5
  drnic:
6
6
  id: 2
7
- name: Dr Nic
7
+ name: Dr Nic
8
+
9
+ cfis:
10
+ id: 3
11
+ name: cfis
@@ -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(1, memberships.length)
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
@@ -1,77 +1,99 @@
1
- require File.expand_path('../abstract_unit', __FILE__)
2
-
3
- class TestUpdate < ActiveSupport::TestCase
4
- fixtures :suburbs
5
-
6
- def setup
7
- @@callbacks = OpenStruct.new
8
- end
9
-
10
- Suburb.class_eval do
11
- before_create do
12
- @@callbacks.before_create = true
13
- end
14
-
15
- after_create do
16
- @@callbacks.after_create = true
17
- end
18
-
19
- around_create do |suburb, block|
20
- @@callbacks.around_create = true
21
- block.call
22
- end
23
-
24
- before_save do
25
- @@callbacks.before_save = true
26
- end
27
-
28
- after_save do
29
- @@callbacks.after_save = true
30
- end
31
-
32
- around_save do |suburb, block|
33
- @@callbacks.around_save = true
34
- block.call
35
- end
36
-
37
- before_update do
38
- @@callbacks.before_update = true
39
- end
40
-
41
- after_update do
42
- @@callbacks.after_update = true
43
- end
44
-
45
- around_update do |suburb, block|
46
- @@callbacks.around_update = true
47
- block.call
48
- end
49
- end
50
-
51
- def test_create
52
- suburb = Suburb.new(:city_id => 3, :suburb_id => 3, :name => 'created')
53
- suburb.save!
54
-
55
- assert(@@callbacks.before_save)
56
- assert(@@callbacks.after_save)
57
- assert(@@callbacks.around_save)
58
-
59
- assert(@@callbacks.before_create)
60
- assert(@@callbacks.after_create)
61
- assert(@@callbacks.around_create)
62
- end
63
-
64
- def test_update
65
- suburb = suburbs(:first)
66
- suburb.name = 'Updated'
67
- suburb.save
68
-
69
- assert(@@callbacks.before_update)
70
- assert(@@callbacks.after_update)
71
- assert(@@callbacks.around_update)
72
-
73
- assert(@@callbacks.before_save)
74
- assert(@@callbacks.after_save)
75
- assert(@@callbacks.around_save)
76
- end
77
- end
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
@@ -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
@@ -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.2
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-06-01 00:00:00.000000000 Z
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.0
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.0
26
+ version: 4.1.4
27
27
  description: Composite key support for ActiveRecord
28
28
  email:
29
29
  executables: []