tessa 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93cafce92a98390762cbd8d7f1d033e7b03e15a1
4
- data.tar.gz: ac5791937677c234980abb77e77caec40a7f6898
3
+ metadata.gz: aa71b4d8f37b7ec9bd2f7f3aeff6c216e5ecc7d3
4
+ data.tar.gz: 40ed20d8dff97b804bc008f1e5040a2e718c2e41
5
5
  SHA512:
6
- metadata.gz: d0146024146bcf5204facc53f4abf14df135a2728e8101715630dfa5b8b52634672296fd94e2655922d1bd1aa50aceb788c3428cb2e25f5baa105e1bd8a984ca
7
- data.tar.gz: 28c21e8452a61969bba191101298638d1489a163ec4ea1d1be889dd892c7f7cfb91665691ccbbf077d56e62ff59f300467492c9f97c248b7d15f1e977ef767ac
6
+ metadata.gz: b496921808084403c16b79f967692a5d72a79a1fd92cdb5c5daa31169e39766d34e7883ddd245af7142c2e36a2319ff38184580b4d5502b490c9a3a88d5c4dff
7
+ data.tar.gz: cdc99adff6059964428e89280843ac338166f8dd6036f1a040fac9a5f73376d50916d027d892d20f1e3173104b78641e6b1e5f485426b44e8c74f3f9252deb93
data/lib/tessa/asset.rb CHANGED
@@ -11,6 +11,14 @@ module Tessa
11
11
  attribute :private_url, String
12
12
  attribute :delete_url, String
13
13
 
14
+ def complete!(connection: Tessa.config.connection)
15
+ Asset.new_from_response connection.patch("/assets/#{id}/completed")
16
+ end
17
+
18
+ def cancel!(connection: Tessa.config.connection)
19
+ Asset.new_from_response connection.patch("/assets/#{id}/cancelled")
20
+ end
21
+
14
22
  def self.find(*ids,
15
23
  connection: Tessa.config.connection)
16
24
  new_from_response connection.get("/assets/#{ids.join(",")}")
data/lib/tessa/upload.rb CHANGED
@@ -3,19 +3,10 @@ module Tessa
3
3
  include Virtus.model
4
4
  extend ResponseFactory
5
5
 
6
- attribute :success_url, String
7
- attribute :cancel_url, String
6
+ attribute :asset_id, Integer
8
7
  attribute :upload_url, String
9
8
  attribute :upload_method, String
10
9
 
11
- def complete!(connection: Tessa.config.connection)
12
- Asset.new_from_response connection.patch(success_url)
13
- end
14
-
15
- def cancel!(connection: Tessa.config.connection)
16
- Asset.new_from_response connection.patch(cancel_url)
17
- end
18
-
19
10
  def self.create(connection: Tessa.config.connection,
20
11
  strategy: Tessa.config.strategy,
21
12
  **options)
data/lib/tessa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tessa
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'tessa'
2
2
 
3
+ Dir[File.expand_path("../support/*.rb", __FILE__)].each do |file|
4
+ require file
5
+ end
6
+
3
7
  RSpec.configure do |config|
4
8
  config.expect_with :rspec do |expectations|
5
9
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
@@ -0,0 +1,42 @@
1
+ RSpec.shared_examples_for "remote call macro" do |method, path, return_type|
2
+ let(:remote_response) { {} }
3
+ let(:faraday_stubs) {
4
+ Faraday::Adapter::Test::Stubs.new do |stub|
5
+ stub.send(method, path) { |env| [200, {}, remote_response.to_json] }
6
+ end
7
+ }
8
+ let(:connection) { Faraday.new { |f| f.adapter :test, faraday_stubs } }
9
+ let(:call_args) { { connection: connection } }
10
+
11
+ it "calls #{method} method with #{path}" do
12
+ expect(connection).to receive(method).with(path, any_args).and_call_original
13
+ call
14
+ end
15
+
16
+ context "with no connection passed" do
17
+ let(:call_args) { {} }
18
+
19
+ it "defaults connection to Tessa.config.connection" do
20
+ expect(Tessa.config).to receive(:connection).and_return(connection)
21
+ expect(connection).to receive(method).and_call_original
22
+ call
23
+ end
24
+ end
25
+
26
+ context "when response is not successful" do
27
+ let(:faraday_stubs) {
28
+ Faraday::Adapter::Test::Stubs.new do |stub|
29
+ stub.send(method, path) { |env| [422, {}, { "error" => "error" }.to_json] }
30
+ end
31
+ }
32
+
33
+ it "raises Tessa::RequestFailed" do
34
+ expect{ call }.to raise_error(Tessa::RequestFailed)
35
+ end
36
+ end
37
+
38
+ it "returns an instance of #{return_type}" do
39
+ expect(call).to be_a(return_type)
40
+ end
41
+ end
42
+
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe Tessa::Asset do
4
+ subject(:asset) { described_class.new(args) }
4
5
  let(:args) {
5
6
  {
6
7
  id: 123,
@@ -15,8 +16,6 @@ RSpec.describe Tessa::Asset do
15
16
 
16
17
  describe "#initialize" do
17
18
  context "with all arguments" do
18
- subject(:asset) { described_class.new(args) }
19
-
20
19
  it "sets id to attribute" do
21
20
  expect(asset.id).to eq(args[:id])
22
21
  end
@@ -48,6 +47,18 @@ RSpec.describe Tessa::Asset do
48
47
  end
49
48
  end
50
49
 
50
+ describe "#complete!" do
51
+ subject(:call) { asset.complete!(call_args) }
52
+
53
+ include_examples "remote call macro", :patch, "/assets/123/completed", Tessa::Asset
54
+ end
55
+
56
+ describe "#cancel!" do
57
+ subject(:call) { asset.cancel!(call_args) }
58
+
59
+ include_examples "remote call macro", :patch, "/assets/123/cancelled", Tessa::Asset
60
+ end
61
+
51
62
  describe "#find" do
52
63
  let(:faraday_stubs) {
53
64
  Faraday::Adapter::Test::Stubs.new do |stub|
@@ -4,23 +4,14 @@ RSpec.describe Tessa::Upload do
4
4
  subject(:upload) { described_class.new(args) }
5
5
  let(:args) {
6
6
  {
7
- success_url: "/success",
8
- cancel_url: "/cancel",
9
7
  upload_url: "/upload",
10
8
  upload_method: "put",
9
+ asset_id: 123,
11
10
  }
12
11
  }
13
12
 
14
13
  describe "#initialize" do
15
14
  context "with all arguments" do
16
- it "sets success_url to attribute" do
17
- expect(upload.success_url).to eq(args[:success_url])
18
- end
19
-
20
- it "sets cancel_url to attribute" do
21
- expect(upload.cancel_url).to eq(args[:cancel_url])
22
- end
23
-
24
15
  it "sets upload_url to attribute" do
25
16
  expect(upload.upload_url).to eq(args[:upload_url])
26
17
  end
@@ -28,61 +19,11 @@ RSpec.describe Tessa::Upload do
28
19
  it "sets upload_method to attribute" do
29
20
  expect(upload.upload_method).to eq(args[:upload_method])
30
21
  end
31
- end
32
- end
33
-
34
- shared_examples_for "remote call macro" do |method, path, return_type|
35
- let(:remote_response) { {} }
36
- let(:faraday_stubs) {
37
- Faraday::Adapter::Test::Stubs.new do |stub|
38
- stub.send(method, path) { |env| [200, {}, remote_response.to_json] }
39
- end
40
- }
41
- let(:connection) { Faraday.new { |f| f.adapter :test, faraday_stubs } }
42
- let(:call_args) { { connection: connection } }
43
-
44
- it "calls #{method} method with #{path}" do
45
- expect(connection).to receive(method).with(path, any_args).and_call_original
46
- call
47
- end
48
-
49
- context "with no connection passed" do
50
- let(:call_args) { {} }
51
-
52
- it "defaults connection to Tessa.config.connection" do
53
- expect(Tessa.config).to receive(:connection).and_return(connection)
54
- expect(connection).to receive(method).and_call_original
55
- call
56
- end
57
- end
58
22
 
59
- context "when response is not successful" do
60
- let(:faraday_stubs) {
61
- Faraday::Adapter::Test::Stubs.new do |stub|
62
- stub.send(method, path) { |env| [422, {}, { "error" => "error" }.to_json] }
63
- end
64
- }
65
-
66
- it "raises Tessa::RequestFailed" do
67
- expect{ call }.to raise_error(Tessa::RequestFailed)
23
+ it "sets asset_id to attribute" do
24
+ expect(upload.asset_id).to eq(args[:asset_id])
68
25
  end
69
26
  end
70
-
71
- it "returns an instance of #{return_type}" do
72
- expect(call).to be_a(return_type)
73
- end
74
- end
75
-
76
- describe "#complete!" do
77
- subject(:call) { upload.complete!(call_args) }
78
-
79
- include_examples "remote call macro", :patch, "/success", Tessa::Asset
80
- end
81
-
82
- describe "#cancel!" do
83
- subject(:call) { upload.cancel!(call_args) }
84
-
85
- include_examples "remote call macro", :patch, "/cancel", Tessa::Asset
86
27
  end
87
28
 
88
29
  describe "::create" do
@@ -95,8 +36,7 @@ RSpec.describe Tessa::Upload do
95
36
 
96
37
  it "returns a new object initialized with the response" do
97
38
  upload = described_class.create(connection: connection)
98
- expect(upload.success_url).to eq(args[:success_url])
99
- expect(upload.cancel_url).to eq(args[:cancel_url])
39
+ expect(upload.asset_id).to eq(args[:asset_id])
100
40
  expect(upload.upload_url).to eq(args[:upload_url])
101
41
  expect(upload.upload_method).to eq(args[:upload_method])
102
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tessa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Powell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-11 00:00:00.000000000 Z
12
+ date: 2015-03-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -118,6 +118,7 @@ files:
118
118
  - lib/tessa/upload.rb
119
119
  - lib/tessa/version.rb
120
120
  - spec/spec_helper.rb
121
+ - spec/support/remote_call_macro.rb
121
122
  - spec/tessa/asset_spec.rb
122
123
  - spec/tessa/config_spec.rb
123
124
  - spec/tessa/upload_spec.rb
@@ -148,6 +149,7 @@ specification_version: 4
148
149
  summary: Manage your assets.
149
150
  test_files:
150
151
  - spec/spec_helper.rb
152
+ - spec/support/remote_call_macro.rb
151
153
  - spec/tessa/asset_spec.rb
152
154
  - spec/tessa/config_spec.rb
153
155
  - spec/tessa/upload_spec.rb