tessa 0.1.0 → 0.1.1

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: 81149b78c787bad3ecc780af3813bdd561a6bee6
4
- data.tar.gz: 47db4550ad97c731ead3e96578108b0017422247
3
+ metadata.gz: 93cafce92a98390762cbd8d7f1d033e7b03e15a1
4
+ data.tar.gz: ac5791937677c234980abb77e77caec40a7f6898
5
5
  SHA512:
6
- metadata.gz: 61d136b95f0682a8609a43130d2cd1bf5f91d6195c8ccadd99a152cee2b9ad6660f80311f41f008227ced1f4fee885e9d90d5b0bcad9151b8b158386e3ce2678
7
- data.tar.gz: 15c2e37be659860fbb28b9e525f1316c924e14fea7ed64b72ef91948e1a923a9f1812d17a5dc5249cf1bab762952a9f00561e2ba45dae37cb70a261959e6ad4e
6
+ metadata.gz: d0146024146bcf5204facc53f4abf14df135a2728e8101715630dfa5b8b52634672296fd94e2655922d1bd1aa50aceb788c3428cb2e25f5baa105e1bd8a984ca
7
+ data.tar.gz: 28c21e8452a61969bba191101298638d1489a163ec4ea1d1be889dd892c7f7cfb91665691ccbbf077d56e62ff59f300467492c9f97c248b7d15f1e977ef767ac
data/.env.example CHANGED
@@ -1,5 +1,5 @@
1
1
  TESSA_USERNAME=username
2
2
  TESSA_PASSWORD=password
3
3
  TESSA_URL=http://tessa.dev
4
- TESSA_DEFAULT_STRATEGY=default
4
+ TESSA_STRATEGY=default
5
5
 
data/lib/tessa.rb CHANGED
@@ -18,4 +18,6 @@ module Tessa
18
18
  def self.setup
19
19
  yield config
20
20
  end
21
+
22
+ class RequestFailed < StandardError; end
21
23
  end
data/lib/tessa/config.rb CHANGED
@@ -2,10 +2,12 @@ module Tessa
2
2
  class Config
3
3
  include Virtus.model
4
4
 
5
+ DEFAULT_STRATEGY = "default"
6
+
5
7
  attribute :username, String, default: -> (*_) { ENV['TESSA_USERNAME'] }
6
8
  attribute :password, String, default: -> (*_) { ENV['TESSA_PASSWORD'] }
7
9
  attribute :url, String, default: -> (*_) { ENV['TESSA_URL'] }
8
- attribute :default_strategy, String, default: -> (*_) { ENV['TESSA_DEFAULT_STRATEGY'] }
10
+ attribute :strategy, String, default: -> (*_) { ENV['TESSA_STRATEGY'] || DEFAULT_STRATEGY }
9
11
 
10
12
  def connection
11
13
  @connection ||= Faraday.new(url: url) do |conn|
@@ -2,6 +2,7 @@ module Tessa
2
2
  module ResponseFactory
3
3
 
4
4
  def new_from_response(response)
5
+ raise RequestFailed unless response.success?
5
6
  case json = JSON.parse(response.body)
6
7
  when Array
7
8
  json.map { |record| new record }
data/lib/tessa/upload.rb CHANGED
@@ -17,7 +17,7 @@ module Tessa
17
17
  end
18
18
 
19
19
  def self.create(connection: Tessa.config.connection,
20
- strategy: Tessa.config.default_strategy,
20
+ strategy: Tessa.config.strategy,
21
21
  **options)
22
22
  new_from_response connection.post('/uploads', options.merge(strategy: strategy))
23
23
  end
data/lib/tessa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tessa
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -52,15 +52,19 @@ RSpec.describe Tessa::Config do
52
52
  end
53
53
  end
54
54
 
55
- describe "#default_strategy" do
55
+ describe "#strategy" do
56
56
  it_behaves_like "defaults to environment variable" do
57
- let(:variable_name) { 'TESSA_DEFAULT_STRATEGY' }
58
- subject(:default_strategy) { config.default_strategy }
57
+ let(:variable_name) { 'TESSA_STRATEGY' }
58
+ subject(:strategy) { config.strategy }
59
+ end
60
+
61
+ it "uses the string 'default' when no envvar passed" do
62
+ expect(config.strategy).to eq("default")
59
63
  end
60
64
 
61
65
  it "behaves like a normal accessor" do
62
- config.default_strategy = "my-new-value"
63
- expect(config.default_strategy).to eq("my-new-value")
66
+ config.strategy = "my-new-value"
67
+ expect(config.strategy).to eq("my-new-value")
64
68
  end
65
69
  end
66
70
 
@@ -56,6 +56,18 @@ RSpec.describe Tessa::Upload do
56
56
  end
57
57
  end
58
58
 
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)
68
+ end
69
+ end
70
+
59
71
  it "returns an instance of #{return_type}" do
60
72
  expect(call).to be_a(return_type)
61
73
  end
@@ -91,8 +103,8 @@ RSpec.describe Tessa::Upload do
91
103
  end
92
104
 
93
105
  describe ":strategy param" do
94
- it "defaults to config.default_strategy" do
95
- expect(Tessa.config).to receive(:default_strategy).and_return(:my_default)
106
+ it "defaults to config.strategy" do
107
+ expect(Tessa.config).to receive(:strategy).and_return(:my_default)
96
108
  expect_post_with_hash_including(strategy: :my_default)
97
109
  described_class.create(connection: connection)
98
110
  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.0
4
+ version: 0.1.1
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-10 00:00:00.000000000 Z
12
+ date: 2015-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday