asset_cloud 2.2.8 → 2.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/asset_cloud.gemspec +1 -1
- data/lib/asset_cloud.rb +2 -2
- data/lib/asset_cloud/callbacks.rb +1 -1
- data/spec/callbacks_spec.rb +33 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e767cf7119375ff7308f312b510f99cd89705e1d44ae556e89853bc8f55f2dd
|
4
|
+
data.tar.gz: 285705891684bc782af8326be994698a9282a4abf19d24df0759cc9a53461752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b10838d5eb09a7efcb7a09ecbdc0ac63e879b233e6208a28aefde0faa811f53464eafb944aaf46bc8f71de3115cdade371bcd8516ad09e18162b8bfe2e383eb7
|
7
|
+
data.tar.gz: 738c8e086da574cfe5200b19da555a765cf482c8df341eb6168ee3864f08a42a211844f340177fda5aa34573473552d764063e7df6510a11ae0b2d66c8aa5cfe
|
data/asset_cloud.gemspec
CHANGED
data/lib/asset_cloud.rb
CHANGED
@@ -41,8 +41,8 @@ AssetCloud::Asset.class_eval do
|
|
41
41
|
validate :valid_key
|
42
42
|
|
43
43
|
def execute_callbacks(symbol, args)
|
44
|
-
super
|
45
|
-
@extensions.
|
44
|
+
result = super
|
45
|
+
result && @extensions.all? { |ext| ext.execute_callbacks(symbol, args) }
|
46
46
|
end
|
47
47
|
|
48
48
|
protected
|
data/spec/callbacks_spec.rb
CHANGED
@@ -2,15 +2,20 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
class CallbackAsset < AssetCloud::Asset
|
4
4
|
before_store :callback_before_store
|
5
|
+
before_delete :callback_before_delete
|
5
6
|
after_delete :callback_after_delete
|
6
7
|
before_validate :make_value_valid
|
7
8
|
after_validate :add_spice
|
8
9
|
validate :valid_value
|
9
10
|
|
10
11
|
private
|
12
|
+
|
13
|
+
def callback_before_delete(*args); end
|
14
|
+
|
11
15
|
def make_value_valid
|
12
16
|
self.value = 'valid'
|
13
17
|
end
|
18
|
+
|
14
19
|
def add_spice
|
15
20
|
self.value += ' spice'
|
16
21
|
end
|
@@ -32,6 +37,9 @@ class CallbackCloud < AssetCloud::Base
|
|
32
37
|
|
33
38
|
after_write :callback_after_write
|
34
39
|
before_write :callback_before_write
|
40
|
+
|
41
|
+
def callback_before_write(*args); end
|
42
|
+
def callback_after_write(*args); end
|
35
43
|
end
|
36
44
|
|
37
45
|
class MethodRecordingCloud < AssetCloud::Base
|
@@ -48,21 +56,34 @@ class MethodRecordingCloud < AssetCloud::Base
|
|
48
56
|
end
|
49
57
|
|
50
58
|
describe CallbackCloud do
|
51
|
-
before
|
59
|
+
before do
|
60
|
+
@fs = CallbackCloud.new(File.dirname(__FILE__) + '/files', 'http://assets/')
|
61
|
+
@fs.write('tmp/file.txt', 'foo')
|
62
|
+
end
|
52
63
|
|
53
64
|
it "should invoke callbacks after store" do
|
54
65
|
@fs.should_receive(:callback_before_write).with('tmp/file.txt', 'text').and_return(true)
|
55
66
|
@fs.should_receive(:callback_after_write).with('tmp/file.txt', 'text').and_return(true)
|
56
67
|
|
57
68
|
|
58
|
-
@fs.write
|
69
|
+
@fs.write('tmp/file.txt', 'text').should == true
|
70
|
+
@fs.read('tmp/file.txt').should == 'text'
|
59
71
|
end
|
60
72
|
|
61
73
|
it "should invoke callbacks after delete" do
|
62
74
|
@fs.should_receive(:callback_before_delete).with('tmp/file.txt').and_return(true)
|
63
75
|
@fs.should_receive(:callback_after_delete).with('tmp/file.txt').and_return(true)
|
64
76
|
|
65
|
-
@fs.delete
|
77
|
+
@fs.delete('tmp/file.txt').should == 'foo'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not invoke other callbacks when a before_ filter returns false" do
|
81
|
+
@fs.should_receive(:callback_before_delete)
|
82
|
+
.with('tmp/file.txt')
|
83
|
+
.and_return(false)
|
84
|
+
@fs.should_not_receive(:callback_after_delete)
|
85
|
+
|
86
|
+
@fs.delete('tmp/file.txt').should == nil
|
66
87
|
end
|
67
88
|
|
68
89
|
it "should invoke callbacks even when constructing a new asset" do
|
@@ -72,7 +93,7 @@ describe CallbackCloud do
|
|
72
93
|
|
73
94
|
asset = @fs.build('tmp/file.txt')
|
74
95
|
asset.value = 'hello'
|
75
|
-
asset.store
|
96
|
+
asset.store.should == true
|
76
97
|
end
|
77
98
|
end
|
78
99
|
|
@@ -113,6 +134,13 @@ describe CallbackAsset do
|
|
113
134
|
@asset.should_not_receive(:callback_before_store)
|
114
135
|
@asset.should_receive(:callback_after_delete).and_return(true)
|
115
136
|
|
116
|
-
@asset.delete
|
137
|
+
@asset.delete.should == 'bar'
|
138
|
+
end
|
139
|
+
|
140
|
+
it "not invoke other callbacks when a before_ filter returns false" do
|
141
|
+
@asset.should_receive(:callback_before_delete).and_return(false)
|
142
|
+
@asset.should_not_receive(:callback_after_delete)
|
143
|
+
|
144
|
+
@asset.delete.should == nil
|
117
145
|
end
|
118
146
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asset_cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|