saviour 0.4.10 → 0.4.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/saviour/file.rb +3 -2
- data/lib/saviour/integrator.rb +14 -0
- data/lib/saviour/version.rb +1 -1
- data/spec/feature/crud_workflows_spec.rb +1 -5
- data/spec/feature/remove_attachment_spec.rb +83 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3759ef570763d52959c2939288131c3065fac5018e2abe0465b7098eb2572180
|
4
|
+
data.tar.gz: b5b51017fdc09079ad4c086340d9eba67e66e282ae86cc5d745cc4038ccc5c2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56e95d8e497c5c1284fc0bc8e89fc182dcf8b044cc8d100e2925152816dacd4ce45ece02ef3253e75dd424c53d8afb73e44ceaa35f23f93d0c00ef9be7c242ef
|
7
|
+
data.tar.gz: 3477c312dd0f3d630ce43cbefc519f7db74c9b8b9d45c1f6f6b708ee0fb3038642fe8cc4ac220b198b3303d0f5dc55d6b9f3008ac357de2888cfd71ce6fa1295
|
data/lib/saviour/file.rb
CHANGED
@@ -12,7 +12,6 @@ module Saviour
|
|
12
12
|
|
13
13
|
def set_path!(path)
|
14
14
|
@persisted_path = path
|
15
|
-
@persisted_path_before_last_save = path
|
16
15
|
end
|
17
16
|
|
18
17
|
def exists?
|
@@ -25,6 +24,9 @@ module Saviour
|
|
25
24
|
|
26
25
|
def delete
|
27
26
|
persisted? && Config.storage.delete(@persisted_path)
|
27
|
+
@persisted_path = nil
|
28
|
+
@source_was = nil
|
29
|
+
@source = nil
|
28
30
|
end
|
29
31
|
|
30
32
|
def public_url
|
@@ -148,7 +150,6 @@ module Saviour
|
|
148
150
|
end
|
149
151
|
|
150
152
|
@persisted_path = path
|
151
|
-
@persisted_path_before_last_save = path
|
152
153
|
path
|
153
154
|
end
|
154
155
|
end
|
data/lib/saviour/integrator.rb
CHANGED
@@ -49,6 +49,20 @@ module Saviour
|
|
49
49
|
define_method("#{attach_as}_changed?") do
|
50
50
|
send(attach_as).changed?
|
51
51
|
end
|
52
|
+
|
53
|
+
define_method("remove_#{attach_as}!") do
|
54
|
+
work = proc do
|
55
|
+
send(attach_as).delete
|
56
|
+
layer = persistence_klass.new(self)
|
57
|
+
layer.write(attach_as, nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
if ActiveRecord::Base.connection.current_transaction.open?
|
61
|
+
DbHelpers.run_after_commit &work
|
62
|
+
else
|
63
|
+
work.call
|
64
|
+
end
|
65
|
+
end
|
52
66
|
end
|
53
67
|
|
54
68
|
klass.include mod
|
data/lib/saviour/version.rb
CHANGED
@@ -82,11 +82,7 @@ describe "saving a new file" do
|
|
82
82
|
klass = Class.new(Test) do
|
83
83
|
attr_accessor :fail_at_save
|
84
84
|
before_save {
|
85
|
-
if
|
86
|
-
throw(:abort) if fail_at_save
|
87
|
-
else
|
88
|
-
!fail_at_save
|
89
|
-
end
|
85
|
+
throw(:abort) if fail_at_save
|
90
86
|
}
|
91
87
|
include Saviour::Model
|
92
88
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "remove attachment" do
|
4
|
+
before { allow(Saviour::Config).to receive(:storage).and_return(Saviour::LocalStorage.new(local_prefix: @tmpdir, public_url_prefix: "http://domain.com")) }
|
5
|
+
|
6
|
+
let(:uploader) {
|
7
|
+
Class.new(Saviour::BaseUploader) {
|
8
|
+
store_dir { "/store/dir" }
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:klass) {
|
13
|
+
a = Class.new(Test) { include Saviour::Model }
|
14
|
+
a.attach_file :file, uploader
|
15
|
+
a
|
16
|
+
}
|
17
|
+
|
18
|
+
context "without a transaction" do
|
19
|
+
it 'removes associated file and column when persisted' do
|
20
|
+
a = klass.create! file: Saviour::StringSource.new("Some contents", "filename.txt")
|
21
|
+
|
22
|
+
expect(a.file.read).to eq "Some contents"
|
23
|
+
|
24
|
+
a.remove_file!
|
25
|
+
|
26
|
+
expect(a.file.read).to be_falsey
|
27
|
+
expect(a[:file]).to be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'removes associated file and column when file not persisted' do
|
31
|
+
a = klass.create!
|
32
|
+
|
33
|
+
a.file = Saviour::StringSource.new("Some contents", "filename.txt")
|
34
|
+
|
35
|
+
a.remove_file!
|
36
|
+
|
37
|
+
expect(a.file.read).to be_falsey
|
38
|
+
expect(a[:file]).to be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "within a transaction" do
|
43
|
+
it "does not remove file and column on rollback" do
|
44
|
+
a = klass.create! file: Saviour::StringSource.new("Some contents", "filename.txt")
|
45
|
+
|
46
|
+
expect(a.file.read).to eq "Some contents"
|
47
|
+
|
48
|
+
ActiveRecord::Base.transaction do
|
49
|
+
a.remove_file!
|
50
|
+
raise ActiveRecord::Rollback
|
51
|
+
end
|
52
|
+
|
53
|
+
expect(a.file.read).to eq "Some contents"
|
54
|
+
expect(a[:file]).to be_present
|
55
|
+
end
|
56
|
+
|
57
|
+
it "removes associated file and column on commit" do
|
58
|
+
a = klass.create! file: Saviour::StringSource.new("Some contents", "filename.txt")
|
59
|
+
|
60
|
+
expect(a.file.read).to eq "Some contents"
|
61
|
+
|
62
|
+
ActiveRecord::Base.transaction do
|
63
|
+
a.remove_file!
|
64
|
+
expect(a.file.read).to eq "Some contents"
|
65
|
+
end
|
66
|
+
|
67
|
+
expect(a.file.read).to be_falsey
|
68
|
+
expect(a[:file]).to be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "removes associated file and column on commit on non-persisted file" do
|
72
|
+
a = klass.create!
|
73
|
+
a.file = Saviour::StringSource.new("Some contents", "filename.txt")
|
74
|
+
|
75
|
+
ActiveRecord::Base.transaction do
|
76
|
+
a.remove_file!
|
77
|
+
end
|
78
|
+
|
79
|
+
expect(a.file.read).to be_falsey
|
80
|
+
expect(a[:file]).to be_nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saviour
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Campos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- spec/feature/persisted_path_spec.rb
|
196
196
|
- spec/feature/processors_api_spec.rb
|
197
197
|
- spec/feature/reload_model_spec.rb
|
198
|
+
- spec/feature/remove_attachment_spec.rb
|
198
199
|
- spec/feature/reopens_file_at_every_process_spec.rb
|
199
200
|
- spec/feature/rewind_source_before_read_spec.rb
|
200
201
|
- spec/feature/transactional_behavior_spec.rb
|
@@ -234,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
235
|
version: '0'
|
235
236
|
requirements: []
|
236
237
|
rubyforge_project:
|
237
|
-
rubygems_version: 2.
|
238
|
+
rubygems_version: 2.7.3
|
238
239
|
signing_key:
|
239
240
|
specification_version: 4
|
240
241
|
summary: File storage handler following active record model lifecycle
|