saviour 0.6.0 → 0.6.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 +4 -4
- data/lib/saviour/life_cycle.rb +12 -7
- data/lib/saviour/version.rb +1 -1
- data/spec/feature/crud_workflows_spec.rb +29 -4
- data/spec/feature/stash_spec.rb +0 -1
- data/spec/support/models.rb +4 -0
- data/spec/support/schema.rb +5 -0
- 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: 0121fbeb0549f71c53b630c648c3791c3b47c48accb0839c2d887490ade48868
|
4
|
+
data.tar.gz: 1494bc8c02a203fc199117210e43d0a5e694b6766774799d85a8cd34049f0c87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8a223b8b404728287418c24391db7320332ed09a931fffb550a024948d12a335187df393f85defa26fbd3e943dc18c2f49cf6467d743d066c42a21b57212211
|
7
|
+
data.tar.gz: d8c1ab1f0b7f72e2d376391c62fd166b708182bb2733a13ffef2310fdc6c1b8d5152b5364ca5837b2b7da09d46e770d276b42dc65fc234f00d0bc0d1748f02be
|
data/lib/saviour/life_cycle.rb
CHANGED
@@ -49,7 +49,7 @@ module Saviour
|
|
49
49
|
end
|
50
50
|
|
51
51
|
@new_path = @file.write(
|
52
|
-
|
52
|
+
before_write: ->(path) { dup_file.call if @current_path == path }
|
53
53
|
)
|
54
54
|
|
55
55
|
return unless @new_path
|
@@ -112,22 +112,22 @@ module Saviour
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def update!
|
115
|
-
process_upload(FileUpdater)
|
115
|
+
process_upload(FileUpdater, touch: true)
|
116
116
|
end
|
117
117
|
|
118
118
|
private
|
119
119
|
|
120
|
-
def process_upload(klass)
|
120
|
+
def process_upload(klass, touch: false)
|
121
121
|
persistence_layer = @persistence_klass.new(@model)
|
122
122
|
|
123
123
|
uploaders = attached_files.map do |column|
|
124
124
|
next unless @model.send(column).changed?
|
125
125
|
|
126
126
|
klass.new(
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
persistence_layer.read(column),
|
128
|
+
@model.send(column),
|
129
|
+
column,
|
130
|
+
ActiveRecord::Base.connection
|
131
131
|
)
|
132
132
|
end.compact
|
133
133
|
|
@@ -161,6 +161,11 @@ module Saviour
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
+
if attrs.length > 0 && touch && @model.class.record_timestamps
|
165
|
+
touches = @model.class.send(:timestamp_attributes_for_update_in_model).map { |x| [x, Time.current] }.to_h
|
166
|
+
attrs.merge!(touches)
|
167
|
+
end
|
168
|
+
|
164
169
|
persistence_layer.write_attrs(attrs) if attrs.length > 0
|
165
170
|
end
|
166
171
|
|
data/lib/saviour/version.rb
CHANGED
@@ -117,8 +117,8 @@ describe "CRUD" do
|
|
117
117
|
expected_query = %Q{UPDATE "tests" SET "file" = '/store/dir/file.txt', "file_thumb" = '/store/dir/file.txt'}
|
118
118
|
expect_to_yield_queries(count: 2, including: [expected_query]) do
|
119
119
|
klass.create!(
|
120
|
-
|
121
|
-
|
120
|
+
file: Saviour::StringSource.new("foo", "file.txt"),
|
121
|
+
file_thumb: Saviour::StringSource.new("foo", "file.txt")
|
122
122
|
)
|
123
123
|
end
|
124
124
|
end
|
@@ -188,6 +188,31 @@ describe "CRUD" do
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
+
describe "touch updated_at" do
|
192
|
+
it "touches updated_at if the model has it" do
|
193
|
+
time = Time.now - 4.years
|
194
|
+
a = klass.create! updated_at: time
|
195
|
+
a.update_attributes! file: Saviour::StringSource.new("foo", "file.txt")
|
196
|
+
|
197
|
+
expect(a.updated_at).to be > time + 2.years
|
198
|
+
end
|
199
|
+
|
200
|
+
context do
|
201
|
+
let(:klass) {
|
202
|
+
a = Class.new(TestNoTimestamp) { include Saviour::Model }
|
203
|
+
a.attach_file :file, uploader
|
204
|
+
a
|
205
|
+
}
|
206
|
+
|
207
|
+
it "works with models that do not have updated_at" do
|
208
|
+
a = klass.create!
|
209
|
+
expect(a).not_to respond_to(:updated_at)
|
210
|
+
a.update_attributes! file: Saviour::StringSource.new("foo", "file.txt")
|
211
|
+
expect(a.file.read).to eq "foo"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
191
216
|
context do
|
192
217
|
let(:klass) {
|
193
218
|
a = Class.new(Test) { include Saviour::Model }
|
@@ -202,8 +227,8 @@ describe "CRUD" do
|
|
202
227
|
expected_query = %Q{UPDATE "tests" SET "file" = '/store/dir/file.txt', "file_thumb" = '/store/dir/file.txt'}
|
203
228
|
expect_to_yield_queries(count: 1, including: [expected_query]) do
|
204
229
|
a.update_attributes!(
|
205
|
-
|
206
|
-
|
230
|
+
file: Saviour::StringSource.new("foo", "file.txt"),
|
231
|
+
file_thumb: Saviour::StringSource.new("foo", "file.txt")
|
207
232
|
)
|
208
233
|
end
|
209
234
|
end
|
data/spec/feature/stash_spec.rb
CHANGED
data/spec/support/models.rb
CHANGED
@@ -2,6 +2,10 @@ class Test < ActiveRecord::Base
|
|
2
2
|
|
3
3
|
end
|
4
4
|
|
5
|
+
class TestNoTimestamp < ActiveRecord::Base
|
6
|
+
|
7
|
+
end
|
8
|
+
|
5
9
|
# Constant lookup in ruby works by lexical scope, so we can't create classes dynamically to test this.
|
6
10
|
class TestForSaviourFileResolution < Test
|
7
11
|
include Saviour::Model
|
data/spec/support/schema.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Campos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|