saviour 0.5.10 → 0.5.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/README.md +939 -346
- data/gemfiles/{5.0.gemfile → 5.2.gemfile} +2 -2
- data/lib/saviour.rb +1 -0
- data/lib/saviour/file.rb +11 -12
- data/lib/saviour/integrator.rb +30 -5
- data/lib/saviour/life_cycle.rb +18 -2
- data/lib/saviour/model.rb +1 -0
- data/lib/saviour/read_only_file.rb +35 -0
- data/lib/saviour/version.rb +1 -1
- data/saviour.gemspec +2 -2
- data/spec/feature/{concurrent_processors_spec.rb → concurrency_spec.rb} +49 -1
- data/spec/feature/crud_workflows_spec.rb +26 -2
- data/spec/feature/dirty_spec.rb +70 -8
- data/spec/feature/remove_attachment_spec.rb +50 -3
- data/spec/feature/stash_spec.rb +1 -2
- data/spec/models/file_spec.rb +6 -16
- data/spec/support/active_record_asserts.rb +10 -1
- metadata +9 -14
@@ -23,6 +23,7 @@ describe "remove attachment" do
|
|
23
23
|
|
24
24
|
a.remove_file!
|
25
25
|
|
26
|
+
expect(a.file.persisted?).to be_falsey
|
26
27
|
expect(a.file.read).to be_falsey
|
27
28
|
expect(a[:file]).to be_nil
|
28
29
|
end
|
@@ -44,24 +45,49 @@ describe "remove attachment" do
|
|
44
45
|
a = klass.create! file: Saviour::StringSource.new("Some contents", "filename.txt")
|
45
46
|
|
46
47
|
expect(a.file.read).to eq "Some contents"
|
48
|
+
path = a[:file]
|
47
49
|
|
48
50
|
ActiveRecord::Base.transaction do
|
49
51
|
a.remove_file!
|
50
52
|
raise ActiveRecord::Rollback
|
51
53
|
end
|
52
54
|
|
55
|
+
# Changes only propagate once the model is manually reloaded, same as any
|
56
|
+
# other AR attribute
|
57
|
+
expect(a.file.persisted?).to be_falsey
|
58
|
+
|
59
|
+
a.reload
|
60
|
+
|
61
|
+
expect(a.file.persisted?).to be_truthy
|
53
62
|
expect(a.file.read).to eq "Some contents"
|
54
|
-
expect(
|
63
|
+
expect(Saviour::Config.storage.exists?(path)).to be_truthy
|
64
|
+
end
|
65
|
+
|
66
|
+
it "removes associated file and column after commit" do
|
67
|
+
a = klass.create! file: Saviour::StringSource.new("Some contents", "filename.txt")
|
68
|
+
|
69
|
+
expect(a.file.read).to eq "Some contents"
|
70
|
+
path = a[:file]
|
71
|
+
|
72
|
+
ActiveRecord::Base.transaction do
|
73
|
+
a.remove_file!
|
74
|
+
expect(Saviour::Config.storage.exists?(path)).to be_truthy
|
75
|
+
end
|
76
|
+
|
77
|
+
expect(Saviour::Config.storage.exists?(path)).to be_falsey
|
78
|
+
expect(a.file.read).to be_falsey
|
79
|
+
expect(a[:file]).to be_nil
|
55
80
|
end
|
56
81
|
|
57
|
-
it "
|
82
|
+
it "attachment appears as nil after deletion and before commit" do
|
58
83
|
a = klass.create! file: Saviour::StringSource.new("Some contents", "filename.txt")
|
59
84
|
|
60
85
|
expect(a.file.read).to eq "Some contents"
|
61
86
|
|
62
87
|
ActiveRecord::Base.transaction do
|
63
88
|
a.remove_file!
|
64
|
-
expect(a.file.
|
89
|
+
expect(a.file.persisted?).to be_falsey
|
90
|
+
expect(a[:file]).to be_nil
|
65
91
|
end
|
66
92
|
|
67
93
|
expect(a.file.read).to be_falsey
|
@@ -79,6 +105,27 @@ describe "remove attachment" do
|
|
79
105
|
expect(a.file.read).to be_falsey
|
80
106
|
expect(a[:file]).to be_nil
|
81
107
|
end
|
108
|
+
|
109
|
+
it "allows for the same file path to be deleted and later updated" do
|
110
|
+
a = klass.create! file: Saviour::StringSource.new("Some contents", "filename.txt")
|
111
|
+
path = a[:file]
|
112
|
+
|
113
|
+
ActiveRecord::Base.transaction do
|
114
|
+
a.remove_file!
|
115
|
+
expect(a.file.persisted?).to be_falsey
|
116
|
+
expect(Saviour::Config.storage.exists?(path)).to be_truthy
|
117
|
+
expect(Saviour::Config.storage.read(path)).to eq "Some contents"
|
118
|
+
|
119
|
+
a.update_attributes!(file: Saviour::StringSource.new("Other contents", "filename.txt"))
|
120
|
+
expect(a.file.persisted?).to be_truthy
|
121
|
+
expect(a.file.read).to eq "Other contents"
|
122
|
+
expect(Saviour::Config.storage.exists?(path)).to be_truthy
|
123
|
+
end
|
124
|
+
|
125
|
+
# Deletion has not occurred
|
126
|
+
expect(Saviour::Config.storage.exists?(path)).to be_truthy
|
127
|
+
expect(Saviour::Config.storage.read(path)).to eq "Other contents"
|
128
|
+
end
|
82
129
|
end
|
83
130
|
|
84
131
|
context "with followers" do
|
data/spec/feature/stash_spec.rb
CHANGED
@@ -72,10 +72,9 @@ describe "stash data on process" do
|
|
72
72
|
|
73
73
|
a = klass.create!
|
74
74
|
|
75
|
-
# - 1 initial empty query
|
76
75
|
# - 2 queries to update size
|
77
76
|
# - 1 query to assign stored paths
|
78
|
-
expect_to_yield_queries(count:
|
77
|
+
expect_to_yield_queries(count: 3) do
|
79
78
|
a.update_attributes! file: Saviour::StringSource.new("a" * 74, "file.txt"),
|
80
79
|
file_thumb: Saviour::StringSource.new("a" * 31, "file_2.txt")
|
81
80
|
end
|
data/spec/models/file_spec.rb
CHANGED
@@ -131,8 +131,7 @@ describe Saviour::File do
|
|
131
131
|
|
132
132
|
describe "#filename" do
|
133
133
|
it "returns the filename of the persisted file" do
|
134
|
-
file = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
135
|
-
file.set_path! "/mocked/path/file.rar"
|
134
|
+
file = Saviour::File.new(uploader_klass, dummy_class.new, :file, "/mocked/path/file.rar")
|
136
135
|
expect(file.filename).to eq "file.rar"
|
137
136
|
end
|
138
137
|
|
@@ -149,8 +148,7 @@ describe Saviour::File do
|
|
149
148
|
end
|
150
149
|
|
151
150
|
it "it's false when not yet assigned but persisted" do
|
152
|
-
file = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
153
|
-
file.set_path! "/path/dummy.jpg"
|
151
|
+
file = Saviour::File.new(uploader_klass, dummy_class.new, :file, "/path/dummy.jpg")
|
154
152
|
expect(file).not_to be_blank
|
155
153
|
end
|
156
154
|
|
@@ -161,16 +159,14 @@ describe Saviour::File do
|
|
161
159
|
end
|
162
160
|
|
163
161
|
it "it's false when persisted and assigned" do
|
164
|
-
file = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
165
|
-
file.set_path! "/path/dummy.jpg"
|
162
|
+
file = Saviour::File.new(uploader_klass, dummy_class.new, :file, "/path/dummy.jpg")
|
166
163
|
expect(file).not_to be_blank
|
167
164
|
end
|
168
165
|
end
|
169
166
|
|
170
167
|
describe "#clone" do
|
171
168
|
it "returns a cloned instance pointing to the same stored file" do
|
172
|
-
file = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
173
|
-
file.set_path! "/path/dummy.jpg"
|
169
|
+
file = Saviour::File.new(uploader_klass, dummy_class.new, :file, "/path/dummy.jpg")
|
174
170
|
|
175
171
|
new_file = file.clone
|
176
172
|
expect(new_file.persisted_path).to eq "/path/dummy.jpg"
|
@@ -179,16 +175,10 @@ describe Saviour::File do
|
|
179
175
|
|
180
176
|
describe "#==" do
|
181
177
|
it "compares by object persisted path if persisted" do
|
182
|
-
a = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
183
|
-
|
184
|
-
|
185
|
-
b = Saviour::File.new(uploader_klass, dummy_class.new, :file)
|
186
|
-
b.set_path! "/path/dummy.jpg"
|
178
|
+
a = Saviour::File.new(uploader_klass, dummy_class.new, :file, "/path/dummy.jpg")
|
179
|
+
b = Saviour::File.new(uploader_klass, dummy_class.new, :file, "/path/dummy.jpg")
|
187
180
|
|
188
181
|
expect(a).to eq b
|
189
|
-
|
190
|
-
b.set_path! "/path/dummy2.jpg"
|
191
|
-
expect(a).to_not eq b
|
192
182
|
end
|
193
183
|
|
194
184
|
it "compares by content if not persisted" do
|
@@ -30,6 +30,15 @@ RSpec.configure do |config|
|
|
30
30
|
end
|
31
31
|
|
32
32
|
ActiveSupport::Notifications.subscribe "sql.active_record" do |name, started, finished, unique_id, data|
|
33
|
-
|
33
|
+
if ActiveRecord.gem_version >= Gem::Version.new("5.2.0")
|
34
|
+
if data[:name] =~ /(Create|Update|Destroy)/
|
35
|
+
sql = data[:sql]
|
36
|
+
sql = sql.gsub("?").with_index { |_, i| ActiveRecord::Base.connection.quote(data[:type_casted_binds][i]) }
|
37
|
+
|
38
|
+
AssertionsTracker.data.push(sql)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
AssertionsTracker.data.push(data[:sql]) if data[:name] == "SQL"
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
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.5.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2018-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,34 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5.
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '5.2'
|
19
|
+
version: '5.1'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '5.
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '5.2'
|
26
|
+
version: '5.1'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: activesupport
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '5.
|
33
|
+
version: '5.1'
|
40
34
|
type: :runtime
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
38
|
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '5.
|
40
|
+
version: '5.1'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: concurrent-ruby
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,8 +178,8 @@ files:
|
|
184
178
|
- LICENSE.txt
|
185
179
|
- README.md
|
186
180
|
- Rakefile
|
187
|
-
- gemfiles/5.0.gemfile
|
188
181
|
- gemfiles/5.1.gemfile
|
182
|
+
- gemfiles/5.2.gemfile
|
189
183
|
- lib/saviour.rb
|
190
184
|
- lib/saviour/base_uploader.rb
|
191
185
|
- lib/saviour/config.rb
|
@@ -196,6 +190,7 @@ files:
|
|
196
190
|
- lib/saviour/local_storage.rb
|
197
191
|
- lib/saviour/model.rb
|
198
192
|
- lib/saviour/persistence_layer.rb
|
193
|
+
- lib/saviour/read_only_file.rb
|
199
194
|
- lib/saviour/s3_storage.rb
|
200
195
|
- lib/saviour/source_filename_extractor.rb
|
201
196
|
- lib/saviour/string_source.rb
|
@@ -206,7 +201,7 @@ files:
|
|
206
201
|
- lib/saviour/version.rb
|
207
202
|
- saviour.gemspec
|
208
203
|
- spec/feature/allow_overriding_attached_as_method_spec.rb
|
209
|
-
- spec/feature/
|
204
|
+
- spec/feature/concurrency_spec.rb
|
210
205
|
- spec/feature/crud_workflows_spec.rb
|
211
206
|
- spec/feature/dirty_spec.rb
|
212
207
|
- spec/feature/follow_file_spec.rb
|