cacheable_delegator 1.2.0 → 1.2.1
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 +8 -8
- data/VERSION +1 -1
- data/cacheable_delegator.gemspec +1 -1
- data/lib/cacheable_delegator.rb +3 -1
- data/spec/mixin_active_record_inline_schema_spec.rb +33 -1
- data/spec/spec_records.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjRjYTRkYjIwNmIzYmQ1NTY4OTFlNzIzNDc5ZDJkYWZlYjg5MGJkNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDVjODg0N2EwYzQzZjliMmU1MmVjYWY3MmVkMGMwYjFkY2E1YzIzNA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2U0MThmYjY5ZGQ5ZmZkYTEyNjJlNWJiZmIxYjc4OTEwZmIxODRhODhhNDBi
|
10
|
+
ZGQ2OWU0Y2ZjYTEwNTk4ZGEyNmZkZDdkZjAyZDJjNzU4ZWFiODRkNmQyMTA0
|
11
|
+
NjBhMzI3NTc5MzcxZGZhZDU1NzIwNTExZmY0OWM0YTliNjkyYWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjZkYzAxZjgyN2RlNjhmOTczNmRlNzI0MTUwMWVkNDAwYThlOTJhYjY2ZjZk
|
14
|
+
Mzc0ODIyZjA1YWMzZmFlYmZmMDdlNjU3ODRjMTY5NThlMGZjMTAyZmQxMmI1
|
15
|
+
MzEzMzBkOGU2NWQ1OTQxZjZjZmZhMTE0OWRiMDQ2MmY2NWE2MWU=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.1
|
data/cacheable_delegator.gemspec
CHANGED
data/lib/cacheable_delegator.rb
CHANGED
@@ -120,7 +120,7 @@ module CacheableDelegator
|
|
120
120
|
col_str = col_name.to_s
|
121
121
|
is_bespoke = opts.delete :bespoke
|
122
122
|
if !(self.source_class.method_defined?(col_str) || self.source_class.new.respond_to?(col_str)) && is_bespoke != true
|
123
|
-
raise
|
123
|
+
raise NonExistentInstanceMethod, "Since :bespoke != true, instance of #{self.source_class} was expected to respond_to? :#{col_str}"
|
124
124
|
end
|
125
125
|
|
126
126
|
custom_columns[col_name.to_s] = opts
|
@@ -206,3 +206,5 @@ module CacheableDelegator
|
|
206
206
|
|
207
207
|
end
|
208
208
|
|
209
|
+
|
210
|
+
class NonExistentInstanceMethod < ArgumentError; end
|
@@ -47,7 +47,7 @@ describe CacheableDelegator do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'by default, should raise error if source_class does not respond_to custom column name' do
|
50
|
-
expect{ MyCachedRecord.add_custom_column :not_foo_of_record }.to raise_error
|
50
|
+
expect{ MyCachedRecord.add_custom_column :not_foo_of_record }.to raise_error NonExistentInstanceMethod
|
51
51
|
end
|
52
52
|
|
53
53
|
|
@@ -81,6 +81,38 @@ describe CacheableDelegator do
|
|
81
81
|
|
82
82
|
end
|
83
83
|
|
84
|
+
context 'enforcement of responds_to' do
|
85
|
+
it 'should allow adding of columns based on defined instance method' do
|
86
|
+
MyCachedRecord.add_custom_column :superfluous_instance_method
|
87
|
+
MyCachedRecord.upgrade_schema!
|
88
|
+
|
89
|
+
expect(MyCachedRecord.column_names.include?('superfluous_instance_method')).to be_true
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'respond_to_missing? works' do
|
93
|
+
it 'should allow reference to dynamically defined methods' do
|
94
|
+
MyCachedRecord.add_custom_column :dynamic_foo
|
95
|
+
MyCachedRecord.upgrade_schema!
|
96
|
+
|
97
|
+
expect(MyCachedRecord.column_names.include?('dynamic_foo')).to be_true
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'non-existent' do
|
103
|
+
it 'should raise error of undefined instance methods' do
|
104
|
+
expect{ MyCachedRecord.add_custom_column :non_existent_method }.to raise_error NonExistentInstanceMethod
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should not raise error if bespoke is true' do
|
108
|
+
MyCachedRecord.add_custom_column :non_existent_method, bespoke: true
|
109
|
+
MyCachedRecord.upgrade_schema!
|
110
|
+
expect(MyCachedRecord.column_names.include?('non_existent_method')).to be_true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
84
116
|
it 'should allow exclusion of specified columns'
|
85
117
|
|
86
118
|
|
data/spec/spec_records.rb
CHANGED
@@ -49,11 +49,35 @@ class MyRecord < ActiveRecord::Base
|
|
49
49
|
'special foo'
|
50
50
|
end
|
51
51
|
|
52
|
+
def superfluous_instance_method
|
53
|
+
'hello'
|
54
|
+
end
|
52
55
|
|
53
56
|
def foo_array
|
54
57
|
[awesome_value, 'foo!', awesome_value]
|
55
58
|
end
|
56
59
|
|
60
|
+
|
61
|
+
|
62
|
+
DELEGATING_REGEX ||= /^dynamic_(\w+)/
|
63
|
+
|
64
|
+
def method_missing(foo, *args, &block)
|
65
|
+
if foomatch = foo.to_s.match(DELEGATING_REGEX)
|
66
|
+
foo = foomatch[1].to_s
|
67
|
+
self.send(foo, *args, &block)
|
68
|
+
else
|
69
|
+
super
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def respond_to?(method, f=false)
|
74
|
+
method =~ DELEGATING_REGEX || super
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def respond_to_missing?(method, *)
|
79
|
+
method =~ DELEGATING_REGEX || super
|
80
|
+
end
|
57
81
|
end
|
58
82
|
|
59
83
|
class MyCover < ActiveRecord::Base
|