ar-simple-idmap 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/README +12 -8
- data/VERSION +1 -1
- data/lib/identity_map/action_controller/dispatcher.rb +105 -43
- data/lib/identity_map/active_record/base.rb +36 -14
- data/lib/identity_map/cache.rb +113 -86
- data/spec/identity_map_spec.rb +108 -100
- data/spec/spec.opts +1 -3
- data/spec/spec_helper.rb +5 -1
- metadata +5 -6
- data/lib/autotest/discover.rb +0 -5
data/.gitignore
CHANGED
data/README
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
IdentityMap
|
2
|
-
===========
|
1
|
+
= IdentityMap
|
3
2
|
|
4
3
|
Adds simple hand controlled identity map for ActiveRecord.
|
5
4
|
|
6
|
-
Installing
|
7
|
-
==========
|
5
|
+
== Installing
|
8
6
|
|
9
7
|
in Rails 2.3 in config/environment.rb
|
10
8
|
|
@@ -14,8 +12,7 @@ in Rails 3 in Gemfile
|
|
14
12
|
|
15
13
|
gem 'ar-simple-idmap', :require => 'identity_map'
|
16
14
|
|
17
|
-
Enabling
|
18
|
-
========
|
15
|
+
== Enabling
|
19
16
|
|
20
17
|
To enable in ApplicationController (it is not enabled by default).
|
21
18
|
|
@@ -73,10 +70,17 @@ you could temporary disable it:
|
|
73
70
|
# all things here goes without identity map
|
74
71
|
# not only for Client
|
75
72
|
end
|
73
|
+
|
74
|
+
class ClientsController
|
75
|
+
def strange_action
|
76
|
+
without_identity_map do
|
77
|
+
do_strange_things_without_identity_map
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
76
81
|
|
77
82
|
|
78
|
-
Copyright
|
79
|
-
=========
|
83
|
+
== Copyright
|
80
84
|
|
81
85
|
inspired by http://github.com/pjdavis/identity-map
|
82
86
|
Copyright (c) 2010 Sokolov Yura aka funny_falcon, released under the MIT license.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -1,54 +1,116 @@
|
|
1
|
-
module ActionController
|
2
|
-
class Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
1
|
+
module ActionController # :nodoc:
|
2
|
+
class Base # :nodoc:
|
3
|
+
module IdentityMap # :nodoc:
|
4
|
+
module InstanceMethods
|
5
|
+
# Execute block with identity map.
|
6
|
+
#
|
7
|
+
# If it called with +true+, then new instance of identity map would be used
|
8
|
+
# regardless of any present.
|
9
|
+
#
|
10
|
+
# If it called with +false+, then it only ensures that identity map created if absent.
|
11
|
+
#
|
12
|
+
# Default is +true+
|
13
|
+
#
|
14
|
+
# Typical usage is around filter, which is most times better than direct call.
|
15
|
+
#
|
16
|
+
# Usage:
|
17
|
+
# class ThingsController
|
18
|
+
# def action1
|
19
|
+
# with_identity_map do
|
20
|
+
# #some_actions
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
# #around_filter :with_identity_map, :only => :action2
|
24
|
+
# use_identity_map :only => :action2
|
25
|
+
# def action2
|
26
|
+
# #some_actions
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# Method declared as a helper method, so could be used in a views.
|
31
|
+
def with_identity_map( fresh = true )
|
32
|
+
ActiveRecord::Base.with_id_map(fresh) {
|
33
|
+
yield
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
# Temporary disables identity map.
|
38
|
+
#
|
39
|
+
# Could be used if identity map introduced undesired behaviour.
|
40
|
+
#
|
41
|
+
# Usage:
|
42
|
+
# class ThingsController
|
43
|
+
# def action1
|
44
|
+
# without_identity_map do
|
45
|
+
# #some_actions
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# around_filter :without_identity_map, :only => :action2
|
49
|
+
# def action2
|
50
|
+
# #some_actions
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
# Method declared as a helper method, so could be used in a views.
|
54
|
+
def without_identity_map
|
55
|
+
ActiveRecord::Base.without_id_map {
|
56
|
+
yield
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
module ClassMethods
|
62
|
+
# Puts around filter which is enable identity map usage for actions.
|
63
|
+
#
|
64
|
+
# <tt>use_identity_map *args</tt> is shorthand for <tt>around_filter :with_identity_map, *args</tt>
|
65
|
+
#
|
66
|
+
# Typically you could put it in a ApplicationController
|
67
|
+
# class ApplicationController
|
68
|
+
# use_identity_map
|
69
|
+
# end
|
70
|
+
def use_identity_map(*args)
|
71
|
+
around_filter :with_identity_map, *args
|
72
|
+
end
|
73
|
+
|
74
|
+
# Puts around filter which is disable identity map usage for actions.
|
75
|
+
#
|
76
|
+
# <tt>dont_use_identity_map *args</tt> is shorthand for <tt>around_filter :without_identity_map, *args</tt>
|
77
|
+
#
|
78
|
+
# Typically you would call it if undesired behaviour were introduced by identity_map
|
79
|
+
# class ThingsController
|
80
|
+
# dont_use_identity_map :only => :some_strange_action
|
81
|
+
# end
|
82
|
+
def dont_use_identity_map(*args)
|
83
|
+
around_filter :without_identity_map, *args
|
84
|
+
end
|
85
|
+
|
86
|
+
# Put identity map creation onto lower level, actually on a dispatcher
|
87
|
+
# may be for use in a Metal or Rack actions
|
88
|
+
def use_dispatcher_identity_map
|
89
|
+
if defined? ::ActionDispatch
|
90
|
+
ActionDispatch::Callbacks.before :create_identity_map
|
91
|
+
ActionDispatch::Callbacks.after :remove_identity_map
|
92
|
+
else
|
93
|
+
ActionController::Dispatcher.before_dispatch :create_identity_map
|
94
|
+
ActionController::Dispatcher.after_dispatch :remove_identity_map
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
38
99
|
|
39
|
-
|
40
|
-
|
41
|
-
|
100
|
+
end
|
101
|
+
extend IdentityMap::ClassMethods
|
102
|
+
include IdentityMap::InstanceMethods
|
103
|
+
helper_method :with_identity_map, :without_identity_map
|
42
104
|
end
|
43
105
|
end
|
44
|
-
|
106
|
+
# :enddoc:
|
45
107
|
module DispatcherMethods
|
46
108
|
def create_identity_map
|
47
|
-
|
109
|
+
ActiveRecord::Base.create_identity_map
|
48
110
|
end
|
49
111
|
|
50
112
|
def remove_identity_map
|
51
|
-
|
113
|
+
ActiveRecord::Base.drop_identity_map
|
52
114
|
end
|
53
115
|
end
|
54
116
|
|
@@ -1,22 +1,37 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
class Base
|
3
|
-
module IdentityMap
|
1
|
+
module ActiveRecord # :nodoc:
|
2
|
+
class Base # :nodoc:
|
3
|
+
module IdentityMap # :nodoc:
|
4
4
|
module ClassMethods
|
5
5
|
private
|
6
|
-
|
6
|
+
# Prepares model for work with identity map.
|
7
|
+
# If you want to turn on identity map for certain classes (recomended)
|
8
|
+
# you should do like this:
|
9
|
+
#
|
10
|
+
# class Address
|
11
|
+
# use_id_map
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# If you want to turn on identity map for all ActiveRecord models (not recomended)
|
15
|
+
# you should put in some initializator:
|
16
|
+
#
|
17
|
+
# class ActiveRecord::Base
|
18
|
+
# use_id_map
|
19
|
+
# end
|
20
|
+
def use_id_map() # :doc:
|
7
21
|
unless is_a? IdMapClassMethods
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
extend IdMapClassMethods
|
23
|
+
include IdMapInstanceMethods
|
24
|
+
class << self
|
25
|
+
alias_method_chain :find, :identity_map
|
26
|
+
alias_method_chain :instantiate, :identity_map
|
27
|
+
end
|
28
|
+
alias_method_chain :create, :identity_map
|
29
|
+
alias_method_chain :destroy, :identity_map
|
16
30
|
end
|
17
31
|
end
|
18
32
|
end
|
19
33
|
|
34
|
+
# :enddoc:
|
20
35
|
module IdMapClassMethods
|
21
36
|
|
22
37
|
def id_map
|
@@ -29,10 +44,17 @@ module ActiveRecord
|
|
29
44
|
end
|
30
45
|
|
31
46
|
private
|
47
|
+
|
48
|
+
def fetch_single(map, id)
|
49
|
+
if (obj = map[id]) && obj.attribute_names == column_names
|
50
|
+
obj
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
32
54
|
def fetch_from_map(map, ids)
|
33
55
|
result, not_cached = [], []
|
34
56
|
ids.each do |id|
|
35
|
-
if ( obj = map
|
57
|
+
if ( obj = fetch_single(map, id) )
|
36
58
|
result << obj
|
37
59
|
else
|
38
60
|
not_cached << id
|
@@ -74,7 +96,7 @@ module ActiveRecord
|
|
74
96
|
end
|
75
97
|
end
|
76
98
|
else
|
77
|
-
map
|
99
|
+
fetch_single(map, ids)
|
78
100
|
end
|
79
101
|
end
|
80
102
|
end || find_without_identity_map(*args)
|
data/lib/identity_map/cache.rb
CHANGED
@@ -1,89 +1,116 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
class Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
1
|
+
module ActiveRecord # :nodoc:
|
2
|
+
class Base # :nodoc:
|
3
|
+
module ThreadIdentityMap # :nodoc:
|
4
|
+
# ClassIdMap do the job of properly use typecasted +id+ value of model object
|
5
|
+
# for search in a cache
|
6
|
+
class ClassIdMap
|
7
|
+
def initialize(klass)
|
8
|
+
@objects = {}
|
9
|
+
@object = klass.allocate
|
10
|
+
@object.instance_variable_set(:@attributes, {:id=>nil})
|
11
|
+
@object.instance_variable_set(:@attributes_cache, {})
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](id)
|
15
|
+
@object.id = id
|
16
|
+
@objects[@object.id]
|
17
|
+
end
|
18
|
+
|
19
|
+
def []=(id, v)
|
20
|
+
@object.id = id
|
21
|
+
@objects[@object.id] = v
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(id)
|
25
|
+
@object.id = id
|
26
|
+
@objects.delete(@object.id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Manages separated object caches for each model
|
31
|
+
class IdMap
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@objects = {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def for_class(klass)
|
38
|
+
@objects[ klass.base_class ] ||= ClassIdMap.new(klass)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
module ClassMethods
|
44
|
+
# Creates new identity map and put it in thread local storage
|
45
|
+
#
|
46
|
+
# For most use cases +with_id_map+ should be used instead.
|
47
|
+
#
|
48
|
+
# Usage:
|
49
|
+
# ActiveRecord::Base.create_identity_map
|
50
|
+
def create_identity_map
|
51
|
+
set_thread_id_map IdMap.new
|
52
|
+
end
|
53
|
+
|
54
|
+
# Remove identity map from thread local storage
|
55
|
+
#
|
56
|
+
# For most use cases +without_id_map+ should be used instead.
|
57
|
+
#
|
58
|
+
# Usage:
|
59
|
+
# ActiveRecord::Base.drop_identity_map
|
60
|
+
def drop_identity_map
|
61
|
+
set_thread_id_map nil
|
62
|
+
end
|
63
|
+
|
64
|
+
# Execute block with identity map.
|
65
|
+
#
|
66
|
+
# If it called with +true+, then new instance of identity map would be used
|
67
|
+
# regardless of any present.
|
68
|
+
#
|
69
|
+
# If it called with +false+, then it only ensures that identity map created if absent.
|
70
|
+
#
|
71
|
+
# Default is +true+
|
72
|
+
#
|
73
|
+
# Usage:
|
74
|
+
# ActiveRecord::Base.with_id_map do
|
75
|
+
# #do_some_actions
|
76
|
+
# end
|
77
|
+
def with_id_map( fresh = true)
|
78
|
+
old = thread_id_map
|
79
|
+
create_identity_map if fresh || old.nil?
|
80
|
+
yield
|
81
|
+
ensure
|
82
|
+
set_thread_id_map old
|
83
|
+
end
|
84
|
+
|
85
|
+
# Execute block with identity map turned off.
|
86
|
+
#
|
87
|
+
# Usage:
|
88
|
+
# ActiveRecord::Base.without_id_map do
|
89
|
+
# #do_some_actions
|
90
|
+
# end
|
91
|
+
def without_id_map
|
92
|
+
old = thread_id_map
|
93
|
+
drop_identity_map
|
94
|
+
yield
|
95
|
+
ensure
|
96
|
+
set_thread_id_map old
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
|
101
|
+
def thread_id_map
|
102
|
+
Thread.current[:ar_identity_map]
|
103
|
+
end
|
104
|
+
|
105
|
+
def thread_id_map=(v)
|
106
|
+
Thread.current[:ar_identity_map] = v
|
107
|
+
end
|
108
|
+
|
109
|
+
alias set_thread_id_map thread_id_map=
|
110
|
+
|
111
|
+
end
|
84
112
|
end
|
85
|
-
|
86
|
-
|
87
|
-
# self.class.send :alias_method_chain, :uncached, :identity_map
|
113
|
+
|
114
|
+
extend ThreadIdentityMap::ClassMethods
|
88
115
|
end
|
89
116
|
end
|
data/spec/identity_map_spec.rb
CHANGED
@@ -12,124 +12,132 @@ describe "Customers" do
|
|
12
12
|
c1.__id__.should == c2.__id__
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
it "should fetch loaded model from cache" do
|
16
|
+
c1 = Customer.first
|
17
|
+
Customer.connection.should_not_receive(:select_all)
|
18
|
+
c2 = Customer.find(c1.id)
|
19
|
+
end
|
20
20
|
|
21
21
|
it "should work for has_many associations" do
|
22
22
|
p1 = PhoneNumber.first
|
23
23
|
ps = Customer.first.phone_numbers
|
24
|
-
|
24
|
+
p2 = ps.first
|
25
25
|
p1.__id__.should == p2.__id__
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should work for belongs_to assocations" do
|
29
29
|
d1 = Customer.first
|
30
30
|
p1 = PhoneNumber.first
|
31
|
-
|
32
|
-
|
31
|
+
Customer.connection.should_not_receive(:select_all)
|
32
|
+
d2 = p1.customer
|
33
33
|
d1.__id__.should == d2.target.__id__
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
it "should fetch same model with not handled conditions" do
|
37
|
+
d1 = Customer.first
|
38
|
+
d2 = Customer.find(:first, :conditions=>["id = ?", d1.id])
|
39
|
+
d1.__id__.should == d2.__id__
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should refetch to fill missed attributes" do
|
43
|
+
d1 = Customer.find(:first, :select => 'id, name')
|
44
|
+
d1.read_attribute(:value).should be_nil
|
45
|
+
d2 = Customer.find(d1.id)
|
46
|
+
d2.__id__.should == d1.__id__
|
47
|
+
d1.value.should_not be_nil
|
48
|
+
end
|
41
49
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
50
|
+
context "creation and deletion:" do
|
51
|
+
before(:each) do
|
52
|
+
@billy = Customer.create(:name => "billy")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should work for creating objects" do
|
56
|
+
c2 = Customer.find_by_name("billy")
|
57
|
+
@billy.__id__.should == c2.__id__
|
58
|
+
Customer.connection.should_not_receive(:select_all)
|
59
|
+
c3 = Customer.find(@billy.id)
|
60
|
+
@billy.__id__.should == c3.__id__
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should work for destroyed objects" do
|
64
|
+
@billy.destroy
|
65
|
+
c2 = Customer.find_by_id(@billy.id)
|
66
|
+
c2.should be_nil
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should reload adequatly" do
|
70
|
+
Customer.connection.update_sql('update customers set value=2;')
|
71
|
+
@billy.reload
|
72
|
+
@billy.value.should == 2
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should leave changed columns" do
|
76
|
+
@billy.value = 3
|
77
|
+
b = Customer.find_by_name("billy")
|
78
|
+
b.value.should == 3
|
79
|
+
b.value_changed?.should be_true
|
80
|
+
b.changes.should == {'value'=>[1,3]}
|
81
|
+
Customer.connection.update_sql('update customers set value=2;')
|
82
|
+
b = Customer.find_by_name("billy")
|
83
|
+
b.changes.should == {'value'=>[2,3]}
|
84
|
+
end
|
85
|
+
|
86
|
+
after(:each) do
|
87
|
+
@billy.destroy unless @billy.destroyed?
|
88
|
+
end
|
81
89
|
end
|
82
90
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
end
|
127
|
-
end
|
128
|
-
c1.__id__.should_not == c2.__id__
|
129
|
-
c1.__id__.should_not == c3.__id__
|
130
|
-
c3.__id__.should == c2.__id__
|
91
|
+
context "switching identity map:" do
|
92
|
+
it "should disable id_map with `without_id_map`" do
|
93
|
+
c1, c2, c3 = Customer.first, nil, nil
|
94
|
+
Customer.without_id_map do
|
95
|
+
c2 = Customer.first
|
96
|
+
c3 = Customer.first
|
97
|
+
end
|
98
|
+
c1.__id__.should_not == c2.__id__
|
99
|
+
c1.__id__.should_not == c3.__id__
|
100
|
+
c3.__id__.should_not == c2.__id__
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should use current id_map with `with_id_map(false)`" do
|
104
|
+
c1, c2, c3 = Customer.first, nil, nil
|
105
|
+
Customer.with_id_map(false) do
|
106
|
+
c2 = Customer.first
|
107
|
+
Customer.connection.should_not_receive(:select_all)
|
108
|
+
c3 = Customer.find(c2.id)
|
109
|
+
end
|
110
|
+
c1.__id__.should == c2.__id__
|
111
|
+
c1.__id__.should == c3.__id__
|
112
|
+
c3.__id__.should == c2.__id__
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should create new id_map with `with_id_map`" do
|
116
|
+
c1, c2, c3 = Customer.first, nil, nil
|
117
|
+
Customer.with_id_map do
|
118
|
+
c2 = Customer.first
|
119
|
+
Customer.connection.should_not_receive(:select_all)
|
120
|
+
c3 = Customer.find(c2.id)
|
121
|
+
end
|
122
|
+
c1.__id__.should_not == c2.__id__
|
123
|
+
c1.__id__.should_not == c3.__id__
|
124
|
+
c3.__id__.should == c2.__id__
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should reenable id_map with `with_id_map`" do
|
128
|
+
c1, c2, c3 = Customer.first, nil, nil
|
129
|
+
Customer.without_id_map do
|
130
|
+
Customer.with_id_map do
|
131
|
+
c2 = Customer.first
|
132
|
+
Customer.connection.should_not_receive(:select_all)
|
133
|
+
c3 = Customer.find(c2.id)
|
131
134
|
end
|
135
|
+
end
|
136
|
+
c1.__id__.should_not == c2.__id__
|
137
|
+
c1.__id__.should_not == c3.__id__
|
138
|
+
c3.__id__.should == c2.__id__
|
132
139
|
end
|
140
|
+
end
|
133
141
|
|
134
142
|
after(:each) do
|
135
143
|
ActiveRecord::Base.drop_identity_map
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-simple-idmap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sokolov Yura aka funny_falcon
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-21 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,7 +48,6 @@ files:
|
|
48
48
|
- VERSION
|
49
49
|
- init.rb
|
50
50
|
- install.rb
|
51
|
-
- lib/autotest/discover.rb
|
52
51
|
- lib/identity_map.rb
|
53
52
|
- lib/identity_map/action_controller/dispatcher.rb
|
54
53
|
- lib/identity_map/active_record/base.rb
|
@@ -91,5 +90,5 @@ signing_key:
|
|
91
90
|
specification_version: 3
|
92
91
|
summary: Simple identity map for ActiveRecord
|
93
92
|
test_files:
|
94
|
-
- spec/spec_helper.rb
|
95
93
|
- spec/identity_map_spec.rb
|
94
|
+
- spec/spec_helper.rb
|