saviour 0.4.10 → 0.4.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d8f60221415cb3f9496b915d56999f2404784dba
4
- data.tar.gz: 9de5a6f7f39a3df2c15e72486915a60cd1cf7231
2
+ SHA256:
3
+ metadata.gz: 3759ef570763d52959c2939288131c3065fac5018e2abe0465b7098eb2572180
4
+ data.tar.gz: b5b51017fdc09079ad4c086340d9eba67e66e282ae86cc5d745cc4038ccc5c2f
5
5
  SHA512:
6
- metadata.gz: c2995d015c6a1f6b66278a85a953230c76ceba7cddc4e5fc5ba8cd76bbfd4dd53f760023e735fa06723f738da4bbd18a28e32d10bc73dab9ae53e380b41b48ec
7
- data.tar.gz: ab58fec40cdaac44bc69bf529336c7e07065e924fd49b15eab39268d129bfaa791c553c34614d090adbf76a7d72c8d2bdcf9d939b759b8f77b8a6de74132fbd0
6
+ metadata.gz: 56e95d8e497c5c1284fc0bc8e89fc182dcf8b044cc8d100e2925152816dacd4ce45ece02ef3253e75dd424c53d8afb73e44ceaa35f23f93d0c00ef9be7c242ef
7
+ data.tar.gz: 3477c312dd0f3d630ce43cbefc519f7db74c9b8b9d45c1f6f6b708ee0fb3038642fe8cc4ac220b198b3303d0f5dc55d6b9f3008ac357de2888cfd71ce6fa1295
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Saviour
2
- VERSION = "0.4.10"
2
+ VERSION = "0.4.11"
3
3
  end
@@ -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 ActiveRecord.version >= Gem::Version.new("5.0")
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.10
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-22 00:00:00.000000000 Z
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.5.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