second_level_cache 2.1.5 → 2.1.6
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/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/second_level_cache/record_marshal.rb +17 -2
- data/lib/second_level_cache/version.rb +1 -1
- data/test/model/user.rb +4 -0
- data/test/record_marshal_test.rb +16 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1392768f194ffb89966d45e3ff188e76d7434969
|
4
|
+
data.tar.gz: 5cd7882ada9458b1f3adae84c283baa5e1ecfa3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2714be392bb81513af6919240e559dd326d0361a4d24c020083aa4a74416e6ae5f7d576d923da4b6ee610b71ceaaafdd8cb8753969e2a7968c1ae9cb35fc748
|
7
|
+
data.tar.gz: ed1c0d06863e6385415bd25946851e7726b4887d4c4125345052b2685979ccc837eb53ede7075e25a67f88c8ee3a0ec8f9413eb72d245132aeae7e7ddffd6f61
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -27,13 +27,28 @@ module RecordMarshal
|
|
27
27
|
if ::ActiveRecord::VERSION::STRING < '4.2.0'
|
28
28
|
klass.serialized_attributes.each do |k, v|
|
29
29
|
next if attributes[k].nil? || attributes[k].is_a?(String)
|
30
|
-
|
30
|
+
if attributes[k].respond_to?(:unserialize)
|
31
|
+
if attributes[k].serialized_value.is_a?(String)
|
32
|
+
attributes[k] = attributes[k].serialized_value
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
36
|
+
if ::ActiveRecord::VERSION::STRING >= '4.1.0' && attributes[k].coder == ActiveRecord::Coders::JSON
|
37
|
+
attributes[k] = attributes[k].serialized_value.to_json
|
38
|
+
else
|
39
|
+
attributes[k] = attributes[k].serialized_value
|
40
|
+
end
|
41
|
+
end
|
31
42
|
end
|
32
43
|
else
|
33
44
|
klass.columns.select{|t| t.cast_type.is_a?(::ActiveRecord::Type::Serialized) }.each do |c|
|
34
45
|
name, coder = c.name, c.cast_type.coder
|
35
46
|
next if attributes[name].nil? || attributes[name].is_a?(String)
|
36
|
-
|
47
|
+
if coder.is_a?(ActiveRecord::Coders::YAMLColumn)
|
48
|
+
attributes[name] = coder.dump(attributes[name]) if attributes[name].is_a?(coder.object_class)
|
49
|
+
elsif coder == ActiveRecord::Coders::JSON
|
50
|
+
attributes[name] = attributes[name].to_json
|
51
|
+
end
|
37
52
|
end
|
38
53
|
end
|
39
54
|
klass.instantiate(attributes)
|
data/test/model/user.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
ActiveRecord::Base.connection.create_table(:users, :force => true) do |t|
|
3
3
|
t.text :options
|
4
|
+
t.text :json_options
|
4
5
|
t.string :name, :unique => true
|
5
6
|
t.string :email
|
6
7
|
t.integer :books_count, :default => 0
|
@@ -11,6 +12,9 @@ end
|
|
11
12
|
class User < ActiveRecord::Base
|
12
13
|
CacheVersion = 3
|
13
14
|
serialize :options, Array
|
15
|
+
if ::ActiveRecord::VERSION::STRING >= '4.1.0'
|
16
|
+
serialize :json_options, JSON
|
17
|
+
end
|
14
18
|
acts_as_cached(:version => CacheVersion, :expires_in => 3.day)
|
15
19
|
has_one :account
|
16
20
|
has_many :books
|
data/test/record_marshal_test.rb
CHANGED
@@ -3,7 +3,17 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class RecordMarshalTest < ActiveSupport::TestCase
|
5
5
|
def setup
|
6
|
-
|
6
|
+
if ::ActiveRecord::VERSION::STRING >= '4.1.0'
|
7
|
+
@json_options = { "name" => 'Test', "age" => 18 }
|
8
|
+
@user = User.create :name => 'csdn',
|
9
|
+
:email => 'test@csdn.com',
|
10
|
+
:options => [1,2],
|
11
|
+
:json_options => @json_options
|
12
|
+
else
|
13
|
+
@user = User.create :name => 'csdn',
|
14
|
+
:email => 'test@csdn.com',
|
15
|
+
:options => [1,2]
|
16
|
+
end
|
7
17
|
end
|
8
18
|
|
9
19
|
def test_should_dump_active_record_object
|
@@ -21,6 +31,11 @@ class RecordMarshalTest < ActiveSupport::TestCase
|
|
21
31
|
assert_equal Array, User.read_second_level_cache(@user.id).reload.options.class
|
22
32
|
assert_equal User.read_second_level_cache(@user.id).changed?, false
|
23
33
|
assert_equal [1,2], User.read_second_level_cache(@user.id).options
|
34
|
+
if ::ActiveRecord::VERSION::STRING >= '4.1.0'
|
35
|
+
result = User.read_second_level_cache(@user.id)
|
36
|
+
assert_equal @json_options["name"], result.json_options["name"]
|
37
|
+
assert_equal @json_options, result.json_options
|
38
|
+
end
|
24
39
|
assert User.read_second_level_cache(@user.id).persisted?
|
25
40
|
end
|
26
41
|
|