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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9098d3b53d06dba76eac46bf8ff1cfd425264b3
4
- data.tar.gz: 77d704ad5801a62ef5724a0b27f9d29622c1c1af
3
+ metadata.gz: 1392768f194ffb89966d45e3ff188e76d7434969
4
+ data.tar.gz: 5cd7882ada9458b1f3adae84c283baa5e1ecfa3d
5
5
  SHA512:
6
- metadata.gz: d7f1f0d957c2fa492acf8ece6fd84c119f655ddfa3b5312c77b66ea03b58f88c47bfd3799ffc64a8375fdca7d8af87fcfaab2996038a3325850f4bace189d5cd
7
- data.tar.gz: 0bff288d367e69dccd31a9fff26563965750cdbd755fbd1032c4e8e3b8eb5387a21ddf1267a7a6b486017af78a492b7fc5f0dff0caedf627435980e28ec701a1
6
+ metadata.gz: b2714be392bb81513af6919240e559dd326d0361a4d24c020083aa4a74416e6ae5f7d576d923da4b6ee610b71ceaaafdd8cb8753969e2a7968c1ae9cb35fc748
7
+ data.tar.gz: ed1c0d06863e6385415bd25946851e7726b4887d4c4125345052b2685979ccc837eb53ede7075e25a67f88c8ee3a0ec8f9413eb72d245132aeae7e7ddffd6f61
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 4.0'
5
+ gem 'rails', '~> 4.1'
data/README.md CHANGED
@@ -17,7 +17,7 @@ Write-Through: As objects are created, updated, and deleted, all of the caches a
17
17
  In your gem file:
18
18
 
19
19
  ```ruby
20
- gem "second_level_cache", "~> 2.1.5"
20
+ gem "second_level_cache", "~> 2.1.6"
21
21
  ```
22
22
 
23
23
  For ActiveRecord 3:
@@ -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
- attributes[k] = attributes[k].serialized_value if attributes[k].respond_to?(:unserialize)
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
- attributes[name] = coder.dump(attributes[name]) if attributes[name].is_a?(coder.object_class)
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)
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module SecondLevelCache
3
- VERSION = "2.1.5"
3
+ VERSION = "2.1.6"
4
4
  end
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
@@ -3,7 +3,17 @@ require 'test_helper'
3
3
 
4
4
  class RecordMarshalTest < ActiveSupport::TestCase
5
5
  def setup
6
- @user = User.create :name => 'csdn', :email => 'test@csdn.com', :options => [1,2]
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: second_level_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hooopo