second_level_cache 2.1.2 → 2.1.5

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: fb07072700dce834842d9754944d53a7979dee6e
4
- data.tar.gz: af6487f82394c38724fb9b7dd5b74bcfab99c461
3
+ metadata.gz: f9098d3b53d06dba76eac46bf8ff1cfd425264b3
4
+ data.tar.gz: 77d704ad5801a62ef5724a0b27f9d29622c1c1af
5
5
  SHA512:
6
- metadata.gz: 6c3c0b7fee0c8d0a3438293a9f2ce74162ef64a42efa52022cb68a71ef8c84c7b54b371c1563f6a5a2022c64621db43905d709ea995537d2ae262798bc004809
7
- data.tar.gz: ad86ef72719f22ea78ba9c20e968d06ce8de57b9969aca6f4a2ac937edb6511892cceb80407623bb7131f9c2c4421d7528c99703d982dfab2a7d6e0722344361
6
+ metadata.gz: d7f1f0d957c2fa492acf8ece6fd84c119f655ddfa3b5312c77b66ea03b58f88c47bfd3799ffc64a8375fdca7d8af87fcfaab2996038a3325850f4bace189d5cd
7
+ data.tar.gz: 0bff288d367e69dccd31a9fff26563965750cdbd755fbd1032c4e8e3b8eb5387a21ddf1267a7a6b486017af78a492b7fc5f0dff0caedf627435980e28ec701a1
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.2"
20
+ gem "second_level_cache", "~> 2.1.5"
21
21
  ```
22
22
 
23
23
  For ActiveRecord 3:
@@ -30,7 +30,7 @@ module SecondLevelCache
30
30
 
31
31
  def cache_uniq_key(where_values)
32
32
  ext_key = where_values.collect { |k,v|
33
- v = Digest::MD5.hexdigest(v) if v.size >= 32
33
+ v = Digest::MD5.hexdigest(v) if v && v.size >= 32
34
34
  [k,v].join("_")
35
35
  }.join(",")
36
36
  "uniq_key_#{self.name}_#{ext_key}"
@@ -19,7 +19,24 @@ module RecordMarshal
19
19
  # load a cached record
20
20
  def load(serialized)
21
21
  return unless serialized
22
- serialized[0].constantize.instantiate(serialized[1])
22
+ #fix issues 19
23
+ #fix 2.1.2 object.changed? ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Hash, but was a String. -- "{:a=>\"t\", :b=>\"x\"}"
24
+ #fix 2.1.4 object.changed? is true
25
+ #fix Rails 4.2 is deprecating `serialized_attributes` without replacement to Rails 5 is deprecating `serialized_attributes` without replacement
26
+ klass, attributes = serialized[0].constantize, serialized[1]
27
+ if ::ActiveRecord::VERSION::STRING < '4.2.0'
28
+ klass.serialized_attributes.each do |k, v|
29
+ next if attributes[k].nil? || attributes[k].is_a?(String)
30
+ attributes[k] = attributes[k].serialized_value if attributes[k].respond_to?(:unserialize)
31
+ end
32
+ else
33
+ klass.columns.select{|t| t.cast_type.is_a?(::ActiveRecord::Type::Serialized) }.each do |c|
34
+ name, coder = c.name, c.cast_type.coder
35
+ 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)
37
+ end
38
+ end
39
+ klass.instantiate(attributes)
23
40
  end
24
41
 
25
42
  def load_multi(serializeds)
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module SecondLevelCache
3
- VERSION = "2.1.2"
3
+ VERSION = "2.1.5"
4
4
  end
@@ -35,5 +35,6 @@ Gem::Specification.new do |gem|
35
35
  gem.add_runtime_dependency "activerecord", ["> 4.0.0", "< 5.0"]
36
36
  gem.add_development_dependency "sqlite3"
37
37
  gem.add_development_dependency "rake"
38
+ gem.add_development_dependency 'pry'
38
39
  gem.add_development_dependency "database_cleaner", "~> 1.3.0"
39
40
  end
@@ -10,6 +10,7 @@ class FetchByUinqKeyTest < ActiveSupport::TestCase
10
10
  def test_cache_uniq_key
11
11
  assert_equal User.send(:cache_uniq_key, { :name => "hooopo" } ), "uniq_key_User_name_hooopo"
12
12
  assert_equal User.send(:cache_uniq_key, { :foo => 1, :bar => 2 } ), "uniq_key_User_foo_1,bar_2"
13
+ assert_equal User.send(:cache_uniq_key, { :foo => 1, :bar => nil } ), "uniq_key_User_foo_1,bar_"
13
14
  long_val = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
14
15
  assert_equal User.send(:cache_uniq_key, { :foo => 1, :bar => long_val } ), "uniq_key_User_foo_1,bar_#{Digest::MD5.hexdigest(long_val)}"
15
16
  end
@@ -3,7 +3,7 @@ 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'
6
+ @user = User.create :name => 'csdn', :email => 'test@csdn.com', :options => [1,2]
7
7
  end
8
8
 
9
9
  def test_should_dump_active_record_object
@@ -17,6 +17,11 @@ class RecordMarshalTest < ActiveSupport::TestCase
17
17
  def test_should_load_active_record_object
18
18
  @user.write_second_level_cache
19
19
  assert_equal @user, User.read_second_level_cache(@user.id)
20
+ assert_equal Array, User.read_second_level_cache(@user.id).options.class
21
+ assert_equal Array, User.read_second_level_cache(@user.id).reload.options.class
22
+ assert_equal User.read_second_level_cache(@user.id).changed?, false
23
+ assert_equal [1,2], User.read_second_level_cache(@user.id).options
24
+ assert User.read_second_level_cache(@user.id).persisted?
20
25
  end
21
26
 
22
27
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: second_level_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hooopo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-22 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: pry
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: database_cleaner
83
97
  requirement: !ruby/object:Gem::Requirement
@@ -158,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
172
  version: '0'
159
173
  requirements: []
160
174
  rubyforge_project:
161
- rubygems_version: 2.2.2
175
+ rubygems_version: 2.4.7
162
176
  signing_key:
163
177
  specification_version: 4
164
178
  summary: 'SecondLevelCache is a write-through and read-through caching library inspired