composite_primary_keys 7.0.9 → 7.0.10
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 +6 -0
- data/lib/composite_primary_keys/attribute_methods/dirty.rb +1 -8
- data/lib/composite_primary_keys/attribute_methods/read.rb +25 -8
- data/lib/composite_primary_keys/attribute_methods/write.rb +11 -15
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/fixtures/comment.rb +2 -0
- data/test/fixtures/db_definitions/mysql.sql +1 -0
- data/test/fixtures/db_definitions/oracle.sql +1 -0
- data/test/fixtures/db_definitions/postgresql.sql +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +1 -0
- data/test/fixtures/db_definitions/sqlserver.sql +1 -0
- data/test/test_enum.rb +20 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc3c55fbf216f962790b277309e53b78e6359a09
|
4
|
+
data.tar.gz: 4c427b0fe5b5eb3d71f955dbc7f377ae04c3d1a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d29164453f49e2a09edcd699012ecc9264df1284875afaa3dba760a47ee9cdf4fa74c2d5792a2fec799006c03288df3f5aff48cd0d78d733275413ac0525598b
|
7
|
+
data.tar.gz: 91c39473f95f039f88a3094b75b884982263d2857fdf930c86a26a356972e43f0bf426b300cba6a7b67b26471b246b061eb70ba90f345924394ffac7cd98d163
|
data/History.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 7.0.10 (2014-08-07)
|
2
|
+
|
3
|
+
* Update attribute dirty methods to allow attribute *_was
|
4
|
+
fields to be calculated correctly for enum fields (Zachary Salzbank)
|
5
|
+
* Update read/write methods to match latest version of ActiveRecord (Charlie Savage)
|
6
|
+
|
1
7
|
== 7.0.9 (2014-08-03)
|
2
8
|
|
3
9
|
* Second attemp at fixing instantiation of has_many records via :includes that use composite keys - this
|
@@ -10,14 +10,7 @@ module ActiveRecord
|
|
10
10
|
else
|
11
11
|
attr = attr.to_s
|
12
12
|
|
13
|
-
|
14
|
-
if attribute_changed?(attr)
|
15
|
-
old = @changed_attributes[attr]
|
16
|
-
@changed_attributes.delete(attr) unless _field_changed?(attr, old, value)
|
17
|
-
else
|
18
|
-
old = clone_attribute_value(:read_attribute, attr)
|
19
|
-
@changed_attributes[attr] = old if _field_changed?(attr, old, value)
|
20
|
-
end
|
13
|
+
save_changed_attribute(attr, value)
|
21
14
|
end
|
22
15
|
|
23
16
|
# Carry on.
|
@@ -1,18 +1,35 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module AttributeMethods
|
3
3
|
module Read
|
4
|
-
|
5
|
-
define_method(:read_attribute) do |attr_name|
|
4
|
+
def read_attribute(attr_name)
|
6
5
|
if attr_name.kind_of?(Array)
|
7
6
|
attr_name.map {|name| read_attribute(name)}.to_composite_keys
|
8
7
|
else
|
9
|
-
|
8
|
+
# If it's cached, just return it
|
9
|
+
# We use #[] first as a perf optimization for non-nil values. See https://gist.github.com/jonleighton/3552829.
|
10
|
+
name = attr_name.to_s
|
11
|
+
@attributes_cache[name] || @attributes_cache.fetch(name) {
|
12
|
+
column = @column_types_override[name] if @column_types_override
|
13
|
+
column ||= @column_types[name]
|
14
|
+
|
15
|
+
return @attributes.fetch(name) {
|
16
|
+
if name == 'id' && self.class.primary_key != name
|
17
|
+
read_attribute(self.class.primary_key)
|
18
|
+
end
|
19
|
+
} unless column
|
20
|
+
|
21
|
+
value = @attributes.fetch(name) {
|
22
|
+
return block_given? ? yield(name) : nil
|
23
|
+
}
|
24
|
+
|
25
|
+
if self.class.cache_attribute?(name)
|
26
|
+
@attributes_cache[name] = column.type_cast(value)
|
27
|
+
else
|
28
|
+
column.type_cast value
|
29
|
+
end
|
30
|
+
}
|
10
31
|
end
|
11
32
|
end
|
12
33
|
end
|
13
34
|
end
|
14
|
-
end
|
15
|
-
|
16
|
-
ActiveRecord::Base.class_eval do
|
17
|
-
alias :[] :read_attribute
|
18
|
-
end
|
35
|
+
end
|
@@ -1,8 +1,7 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module AttributeMethods
|
3
3
|
module Write
|
4
|
-
def
|
5
|
-
# CPK
|
4
|
+
def write_attribute_with_type_cast(attr_name, value, type_cast_method)
|
6
5
|
if attr_name.kind_of?(Array)
|
7
6
|
value = [nil]*attr_name.length if value.nil?
|
8
7
|
unless value.length == attr_name.length
|
@@ -18,22 +17,19 @@ module ActiveRecord
|
|
18
17
|
@attributes_cache.delete(attr_name)
|
19
18
|
column = column_for_attribute(attr_name)
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
# If we're dealing with a binary column, write the data to the cache
|
21
|
+
# so we don't attempt to typecast multiple times.
|
22
|
+
if column && column.binary?
|
23
|
+
@attributes_cache[attr_name] = value
|
24
|
+
end
|
25
|
+
|
26
|
+
if column || @attributes.has_key?(attr_name)
|
27
|
+
@attributes[attr_name] = send(type_cast_method, column, value)
|
28
|
+
else
|
29
|
+
raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attr_name}'"
|
26
30
|
end
|
27
|
-
@attributes[attr_name] = type_cast_attribute_for_write(column, value)
|
28
31
|
end
|
29
32
|
end
|
30
|
-
alias_method :raw_write_attribute, :write_attribute
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
35
|
-
ActiveRecord::Base.class_eval do
|
36
|
-
alias_method :raw_write_attribute, :write_attribute
|
37
|
-
alias :[]= :write_attribute
|
38
|
-
public :[]=
|
39
|
-
end
|
data/test/fixtures/comment.rb
CHANGED
@@ -116,6 +116,7 @@ create sequence comments_seq start with 1000;
|
|
116
116
|
create table comments (
|
117
117
|
id number(11) not null primary key,
|
118
118
|
person_id number(11) default null,
|
119
|
+
shown number(11) default null,
|
119
120
|
person_type varchar(100) default null,
|
120
121
|
hack_id number(11) default null
|
121
122
|
);
|
data/test/test_enum.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
class TestEnum < ActiveSupport::TestCase
|
4
|
+
fixtures :comments
|
5
|
+
|
6
|
+
def test_enum_was
|
7
|
+
comment = Comment.first
|
8
|
+
assert_nil comment.shown
|
9
|
+
|
10
|
+
comment.shown = :true
|
11
|
+
assert_equal 'true', comment.shown
|
12
|
+
assert_nil comment.shown_was
|
13
|
+
|
14
|
+
comment.save
|
15
|
+
|
16
|
+
comment.shown = :false
|
17
|
+
assert_equal 'false', comment.shown
|
18
|
+
assert_equal 'true', comment.shown_was
|
19
|
+
end
|
20
|
+
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.
|
4
|
+
version: 7.0.10
|
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-08-
|
11
|
+
date: 2014-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- test/test_delete.rb
|
178
178
|
- test/test_delete_all.rb
|
179
179
|
- test/test_dup.rb
|
180
|
+
- test/test_enum.rb
|
180
181
|
- test/test_equal.rb
|
181
182
|
- test/test_exists.rb
|
182
183
|
- test/test_find.rb
|
@@ -235,6 +236,7 @@ test_files:
|
|
235
236
|
- test/test_delete.rb
|
236
237
|
- test/test_delete_all.rb
|
237
238
|
- test/test_dup.rb
|
239
|
+
- test/test_enum.rb
|
238
240
|
- test/test_equal.rb
|
239
241
|
- test/test_exists.rb
|
240
242
|
- test/test_find.rb
|