tessa 1.2.3 → 6.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +76 -3
- data/app/assets/javascripts/tessa.esm.js +212 -173
- data/app/assets/javascripts/tessa.js +206 -167
- data/app/javascript/activestorage/file_checksum.ts +76 -0
- data/app/javascript/tessa/index.ts +264 -0
- data/app/javascript/tessa/types.ts +34 -0
- data/config/routes.rb +0 -1
- data/docs/tessa-activestorage-sequence-diagram.drawio.png +0 -0
- data/lib/tessa/simple_form/asset_input.rb +24 -25
- data/lib/tessa/version.rb +1 -1
- data/lib/tessa.rb +0 -80
- data/package.json +7 -2
- data/rollup.config.js +5 -5
- data/spec/dummy/app/models/single_asset_model.rb +1 -1
- data/spec/dummy/app/models/single_asset_model_form.rb +3 -5
- data/spec/dummy/bin/rails +2 -2
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +14 -6
- data/spec/dummy/bin/yarn +9 -3
- data/spec/dummy/config/application.rb +11 -9
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +34 -5
- data/spec/dummy/config/environments/production.rb +49 -10
- data/spec/dummy/config/environments/test.rb +28 -12
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
- data/spec/dummy/config/initializers/content_security_policy.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
- data/spec/dummy/config/initializers/new_framework_defaults_6_1.rb +67 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +5 -0
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/config/storage.yml +31 -0
- data/spec/dummy/config.ru +2 -1
- data/spec/dummy/db/migrate/20230406194400_add_service_name_to_active_storage_blobs.active_storage.rb +22 -0
- data/spec/dummy/db/migrate/20230406194401_create_active_storage_variant_records.active_storage.rb +27 -0
- data/spec/dummy/db/schema.rb +15 -7
- data/tessa.gemspec +4 -6
- data/tsconfig.json +10 -0
- data/yarn.lock +74 -7
- metadata +37 -85
- data/app/javascript/activestorage/file_checksum.js +0 -53
- data/app/javascript/tessa/index.js.coffee +0 -183
- data/lib/tasks/tessa.rake +0 -7
- data/lib/tessa/active_storage/asset_wrapper.rb +0 -32
- data/lib/tessa/asset/failure.rb +0 -37
- data/lib/tessa/asset.rb +0 -47
- data/lib/tessa/asset_change.rb +0 -49
- data/lib/tessa/asset_change_set.rb +0 -49
- data/lib/tessa/config.rb +0 -24
- data/lib/tessa/controller_helpers.rb +0 -16
- data/lib/tessa/jobs/migrate_assets_job.rb +0 -225
- data/lib/tessa/model/dynamic_extensions.rb +0 -162
- data/lib/tessa/model/field.rb +0 -77
- data/lib/tessa/model.rb +0 -104
- data/lib/tessa/rack_upload_proxy.rb +0 -41
- data/lib/tessa/response_factory.rb +0 -15
- data/lib/tessa/upload/uploads_file.rb +0 -20
- data/lib/tessa/upload.rb +0 -31
- data/lib/tessa/view_helpers.rb +0 -23
- data/spec/dummy/app/models/multiple_asset_model.rb +0 -8
- data/spec/support/remote_call_macro.rb +0 -45
- data/spec/tessa/asset/failure_spec.rb +0 -48
- data/spec/tessa/asset_change_set_spec.rb +0 -198
- data/spec/tessa/asset_change_spec.rb +0 -86
- data/spec/tessa/asset_spec.rb +0 -196
- data/spec/tessa/config_spec.rb +0 -112
- data/spec/tessa/controller_helpers_spec.rb +0 -55
- data/spec/tessa/jobs/migrate_assets_job_spec.rb +0 -247
- data/spec/tessa/model_field_spec.rb +0 -72
- data/spec/tessa/model_spec.rb +0 -578
- data/spec/tessa/rack_upload_proxy_spec.rb +0 -83
- data/spec/tessa/upload/uploads_file_spec.rb +0 -72
- data/spec/tessa/upload_spec.rb +0 -125
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Tessa::Upload::UploadsFile do
|
4
|
-
describe "#initialize" do
|
5
|
-
it "requires an upload and sets it to attribute" do
|
6
|
-
expect { described_class.new }.to raise_error(ArgumentError)
|
7
|
-
obj = described_class.new(upload: :upload)
|
8
|
-
expect(obj.upload).to eq(:upload)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "optionally takes a connection" do
|
12
|
-
obj = described_class.new(upload: :upload, connection: :conn)
|
13
|
-
expect(obj.connection).to eq(:conn)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "defaults connection to empty Faraday connection" do
|
17
|
-
expect(described_class).to receive(:connection_factory).and_return(:foo)
|
18
|
-
obj = described_class.new(upload: :upload)
|
19
|
-
expect(obj.connection).to eq(:foo)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#call" do
|
24
|
-
let(:upload) {
|
25
|
-
instance_double(
|
26
|
-
Tessa::Upload,
|
27
|
-
upload_url: "http://upload/path?arg=1",
|
28
|
-
upload_method: "post"
|
29
|
-
)
|
30
|
-
}
|
31
|
-
let(:connection) {
|
32
|
-
Faraday.new { |f| f.adapter :test, stubs }
|
33
|
-
}
|
34
|
-
subject(:task) { described_class.new(upload: upload, connection: connection) }
|
35
|
-
|
36
|
-
context "uploads file successfully" do
|
37
|
-
let(:stubs) {
|
38
|
-
Faraday::Adapter::Test::Stubs.new do |stub|
|
39
|
-
stub.post("http://upload/path?arg=1") { |env|
|
40
|
-
[200, {}, '']
|
41
|
-
}
|
42
|
-
end
|
43
|
-
}
|
44
|
-
|
45
|
-
it "calls the upload_url with upload_method HTTP method" do
|
46
|
-
file = Tempfile.new("test")
|
47
|
-
file.write "hello there"
|
48
|
-
file.close
|
49
|
-
expect(connection).to receive(:post).with("http://upload/path?arg=1", "hello there").and_call_original
|
50
|
-
expect(task.call(file.path)).to be_truthy
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "uploads file successfully" do
|
55
|
-
let(:stubs) {
|
56
|
-
Faraday::Adapter::Test::Stubs.new do |stub|
|
57
|
-
stub.post("http://upload/path?arg=1") { |env|
|
58
|
-
[500, {}, '']
|
59
|
-
}
|
60
|
-
end
|
61
|
-
}
|
62
|
-
|
63
|
-
it "calls the upload_url with upload_method HTTP method" do
|
64
|
-
file = Tempfile.new("test")
|
65
|
-
file.write "hello there"
|
66
|
-
file.close
|
67
|
-
expect(connection).to receive(:post).with("http://upload/path?arg=1", "hello there").and_call_original
|
68
|
-
expect(task.call(file.path)).to be_falsey
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/spec/tessa/upload_spec.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Tessa::Upload do
|
4
|
-
subject(:upload) { described_class.new(args) }
|
5
|
-
let(:args) {
|
6
|
-
{
|
7
|
-
upload_url: "/upload",
|
8
|
-
upload_method: "put",
|
9
|
-
asset_id: 123,
|
10
|
-
}
|
11
|
-
}
|
12
|
-
|
13
|
-
describe "#initialize" do
|
14
|
-
context "with all arguments" do
|
15
|
-
it "sets upload_url to attribute" do
|
16
|
-
expect(upload.upload_url).to eq(args[:upload_url])
|
17
|
-
end
|
18
|
-
|
19
|
-
it "sets upload_method to attribute" do
|
20
|
-
expect(upload.upload_method).to eq(args[:upload_method])
|
21
|
-
end
|
22
|
-
|
23
|
-
it "sets asset_id to attribute" do
|
24
|
-
expect(upload.asset_id).to eq(args[:asset_id])
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#upload_file" do
|
30
|
-
subject(:upload) { described_class.new }
|
31
|
-
let(:task) { instance_double(described_class::UploadsFile) }
|
32
|
-
|
33
|
-
before :each do
|
34
|
-
allow(described_class::UploadsFile).to receive(:new).and_return(task)
|
35
|
-
allow(task).to receive(:call)
|
36
|
-
allow(Tessa::Asset).to receive(:new).and_return(instance_spy(Tessa::Asset))
|
37
|
-
end
|
38
|
-
|
39
|
-
it "initializes UploadsFile with self and passes argument to call" do
|
40
|
-
expect(task).to receive(:call).with(:file)
|
41
|
-
expect(described_class::UploadsFile).to receive(:new).with(upload: upload).and_return(task)
|
42
|
-
upload.upload_file(:file)
|
43
|
-
end
|
44
|
-
|
45
|
-
context "with a successful upload" do
|
46
|
-
before :each do
|
47
|
-
allow(task).to receive(:call).and_return(true)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "updates the asset to complete state and returns asset" do
|
51
|
-
upload.asset_id = 123
|
52
|
-
asset = Tessa::Asset.new(id: 123)
|
53
|
-
expect(Tessa::Asset).to receive(:new).with(id: 123).and_return(asset)
|
54
|
-
expect(asset).to receive(:complete!).and_return(:asset)
|
55
|
-
expect(upload.upload_file(:file)).to eq(:asset)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "with a failed upload" do
|
60
|
-
before :each do
|
61
|
-
allow(task).to receive(:call).and_return(false)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "updates the asset to canceled state and returns false" do
|
65
|
-
upload.asset_id = 123
|
66
|
-
asset = Tessa::Asset.new(id: 123)
|
67
|
-
expect(Tessa::Asset).to receive(:new).with(id: 123).and_return(asset)
|
68
|
-
expect(asset).to receive(:cancel!).and_return(:asset)
|
69
|
-
expect(upload.upload_file(:file)).to eq(false)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe ".create" do
|
75
|
-
subject(:call) { described_class.create(call_args) }
|
76
|
-
|
77
|
-
include_examples "remote call macro", :post, "/uploads", Tessa::Upload
|
78
|
-
|
79
|
-
context "with a full response" do
|
80
|
-
let(:remote_response) { args }
|
81
|
-
|
82
|
-
it "returns a new object initialized with the response" do
|
83
|
-
upload = described_class.create(connection: connection)
|
84
|
-
expect(upload.asset_id).to eq(args[:asset_id])
|
85
|
-
expect(upload.upload_url).to eq(args[:upload_url])
|
86
|
-
expect(upload.upload_method).to eq(args[:upload_method])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe ":strategy param" do
|
91
|
-
it "defaults to config.strategy" do
|
92
|
-
expect(Tessa.config).to receive(:strategy).and_return(:my_default)
|
93
|
-
expect_post_with_hash_including(strategy: :my_default)
|
94
|
-
described_class.create(connection: connection)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "overrides with :strategy argument" do
|
98
|
-
expect_post_with_hash_including(strategy: :my_default)
|
99
|
-
described_class.create(connection: connection, strategy: :my_default)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it "sets :name param from argument" do
|
104
|
-
expect_post_with_hash_including(name: "my-file.txt")
|
105
|
-
described_class.create(connection: connection, name: "my-file.txt")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "sets :size param from argument" do
|
109
|
-
expect_post_with_hash_including(size: 12345)
|
110
|
-
described_class.create(connection: connection, size: 12345)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "sets :mime_type param from argument" do
|
114
|
-
expect_post_with_hash_including(mime_type: "text/plain")
|
115
|
-
described_class.create(connection: connection, mime_type: "text/plain")
|
116
|
-
end
|
117
|
-
|
118
|
-
def expect_post_with_hash_including(expected)
|
119
|
-
expect(connection).to receive(:post)
|
120
|
-
.with("/uploads", hash_including(expected))
|
121
|
-
.and_call_original
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|