rexpense 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +22 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.rubocop.yml +54 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +97 -0
- data/LICENSE.txt +21 -0
- data/README.md +195 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +21 -0
- data/bin/setup +7 -0
- data/lib/rexpense/client.rb +39 -0
- data/lib/rexpense/configuration.rb +13 -0
- data/lib/rexpense/entities/activity.rb +11 -0
- data/lib/rexpense/entities/activity_collection.rb +14 -0
- data/lib/rexpense/entities/advancement.rb +14 -0
- data/lib/rexpense/entities/advancement_collection.rb +14 -0
- data/lib/rexpense/entities/advancement_devolution.rb +13 -0
- data/lib/rexpense/entities/attachment.rb +13 -0
- data/lib/rexpense/entities/attachment_collection.rb +14 -0
- data/lib/rexpense/entities/base.rb +9 -0
- data/lib/rexpense/entities/collection.rb +65 -0
- data/lib/rexpense/entities/comment.rb +13 -0
- data/lib/rexpense/entities/comment_collection.rb +14 -0
- data/lib/rexpense/entities/expense.rb +22 -0
- data/lib/rexpense/entities/expense_collection.rb +14 -0
- data/lib/rexpense/entities/membership.rb +10 -0
- data/lib/rexpense/entities/membership_collection.rb +14 -0
- data/lib/rexpense/entities/organization.rb +14 -0
- data/lib/rexpense/entities/organization_collection.rb +14 -0
- data/lib/rexpense/entities/pre_expense.rb +17 -0
- data/lib/rexpense/entities/pre_expense_collection.rb +14 -0
- data/lib/rexpense/entities/reimbursement.rb +14 -0
- data/lib/rexpense/entities/reimbursement_collection.rb +14 -0
- data/lib/rexpense/entities/tag.rb +8 -0
- data/lib/rexpense/entities/tag_collection.rb +14 -0
- data/lib/rexpense/entities/user.rb +14 -0
- data/lib/rexpense/entities/user_collection.rb +14 -0
- data/lib/rexpense/entities/webhook.rb +10 -0
- data/lib/rexpense/entities/webhook_collection.rb +14 -0
- data/lib/rexpense/exception.rb +11 -0
- data/lib/rexpense/http.rb +41 -0
- data/lib/rexpense/request.rb +56 -0
- data/lib/rexpense/resources/activity.rb +24 -0
- data/lib/rexpense/resources/advancement.rb +20 -0
- data/lib/rexpense/resources/advancement_devolution.rb +36 -0
- data/lib/rexpense/resources/base.rb +52 -0
- data/lib/rexpense/resources/expense.rb +39 -0
- data/lib/rexpense/resources/nested_endpoints/attachment.rb +48 -0
- data/lib/rexpense/resources/nested_endpoints/comment.rb +84 -0
- data/lib/rexpense/resources/nested_endpoints/membership.rb +74 -0
- data/lib/rexpense/resources/nested_endpoints/participant.rb +43 -0
- data/lib/rexpense/resources/organization.rb +31 -0
- data/lib/rexpense/resources/pre_expense.rb +56 -0
- data/lib/rexpense/resources/reimbursement.rb +20 -0
- data/lib/rexpense/resources/resource_base.rb +105 -0
- data/lib/rexpense/resources/tag.rb +82 -0
- data/lib/rexpense/resources/webhook.rb +82 -0
- data/lib/rexpense/response.rb +43 -0
- data/lib/rexpense/version.rb +3 -0
- data/lib/rexpense.rb +19 -0
- data/rexpense.gemspec +48 -0
- data/spec/lib/rexpense/client_spec.rb +47 -0
- data/spec/lib/rexpense/configuration_spec.rb +26 -0
- data/spec/lib/rexpense/entities/activity_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/activity_spec.rb +9 -0
- data/spec/lib/rexpense/entities/advancement_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/advancement_devolution_spec.rb +9 -0
- data/spec/lib/rexpense/entities/advancement_spec.rb +10 -0
- data/spec/lib/rexpense/entities/base_spec.rb +28 -0
- data/spec/lib/rexpense/entities/collection_spec.rb +70 -0
- data/spec/lib/rexpense/entities/comment_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/comment_spec.rb +10 -0
- data/spec/lib/rexpense/entities/expense_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/expense_spec.rb +14 -0
- data/spec/lib/rexpense/entities/membership_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/membership_spec.rb +7 -0
- data/spec/lib/rexpense/entities/organization_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/organization_spec.rb +8 -0
- data/spec/lib/rexpense/entities/pre_expense_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/pre_expense_spec.rb +10 -0
- data/spec/lib/rexpense/entities/reimbursement_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/reimbursement_spec.rb +10 -0
- data/spec/lib/rexpense/entities/user_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/user_spec.rb +10 -0
- data/spec/lib/rexpense/entities/webhook_collection_spec.rb +5 -0
- data/spec/lib/rexpense/entities/webhook_spec.rb +7 -0
- data/spec/lib/rexpense/http_spec.rb +37 -0
- data/spec/lib/rexpense/request_spec.rb +29 -0
- data/spec/lib/rexpense/resources/activity_spec.rb +16 -0
- data/spec/lib/rexpense/resources/advancement_devolution_spec.rb +29 -0
- data/spec/lib/rexpense/resources/advancement_spec.rb +207 -0
- data/spec/lib/rexpense/resources/expense_spec.rb +227 -0
- data/spec/lib/rexpense/resources/organization_spec.rb +162 -0
- data/spec/lib/rexpense/resources/pre_expense_spec.rb +83 -0
- data/spec/lib/rexpense/resources/reimbursement_spec.rb +207 -0
- data/spec/lib/rexpense/resources/tag_specs.rb +77 -0
- data/spec/lib/rexpense/resources/webhook_spec.rb +51 -0
- data/spec/lib/rexpense/response_spec.rb +91 -0
- data/spec/lib/rexpense_spec.rb +34 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/support/attachments/logo.png +0 -0
- data/spec/support/client.rb +3 -0
- data/spec/support/matchers/have_attr_accessor.rb +18 -0
- data/spec/support/shared_examples/entity_attributes.rb +9 -0
- data/spec/support/shared_examples/entity_collection.rb +19 -0
- data/spec/support/shared_examples/http_request_methods.rb +35 -0
- data/spec/support/vcr.rb +7 -0
- metadata +390 -0
data/rexpense.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "rexpense/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rexpense"
|
7
|
+
spec.version = Rexpense::VERSION
|
8
|
+
spec.authors = ["Eduardo Hertz", "Dante Alighieri"]
|
9
|
+
spec.email = [
|
10
|
+
"dante.alighierimds@gmail.com",
|
11
|
+
"eduardohertz@gmail.com",
|
12
|
+
]
|
13
|
+
spec.required_ruby_version = ">= 2.0.0"
|
14
|
+
|
15
|
+
spec.summary = %q{A Ruby client for the Rexpense REST API}
|
16
|
+
spec.description = %q{A Ruby client for the Rexpense REST API: http://developers.rexpense.com}
|
17
|
+
spec.homepage = "https://github.com/myfreecomm/rexpense-client-ruby"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
# Prevent pushing this gem to RubyGems.org by setting "allowed_push_host", or
|
21
|
+
# delete this section to allow pushing this gem to any host.
|
22
|
+
if spec.respond_to?(:metadata)
|
23
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
24
|
+
else
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.files = `git ls-files`.split($/).reject { |f| f =~ %r{(vcr_cassettes)/} }
|
29
|
+
spec.bindir = "bin"
|
30
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
31
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_dependency "typhoeus", "~> 0.8"
|
35
|
+
spec.add_dependency "virtus", "~> 1.0.5"
|
36
|
+
spec.add_dependency "mime-types", "~> 2.99"
|
37
|
+
spec.add_dependency "require_all", "~> 1.4.0"
|
38
|
+
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec"
|
41
|
+
spec.add_development_dependency "vcr", "~> 2.4"
|
42
|
+
spec.add_development_dependency "webmock", "~> 1.9.3"
|
43
|
+
spec.add_development_dependency "pry", "~> 0.9"
|
44
|
+
spec.add_development_dependency "pry-nav", "~> 0.2"
|
45
|
+
spec.add_development_dependency "awesome_print", "~> 1.1"
|
46
|
+
spec.add_development_dependency "simplecov", "~> 0.9"
|
47
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
|
48
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rexpense::Client do
|
4
|
+
subject { client }
|
5
|
+
|
6
|
+
shared_examples :resource do |method, type|
|
7
|
+
describe "##{method}" do
|
8
|
+
it "instantiates a new #{type}" do
|
9
|
+
allow(type).to receive(:new)
|
10
|
+
subject.send(method)
|
11
|
+
expect(type).to have_received(:new).with(subject.http)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#initialize" do
|
17
|
+
it "instantiates a new Rexpense::Http object" do
|
18
|
+
expect(Rexpense::Http).to receive(:new).with("abc")
|
19
|
+
Rexpense::Client.new("abc")
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when account_id is present" do
|
23
|
+
it "instantiates a new Rexpense::Http object" do
|
24
|
+
expect(Rexpense::Http).to receive(:new).with("abc")
|
25
|
+
Rexpense::Client.new("abc")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#authenticated?" do
|
31
|
+
context "with a valid token" do
|
32
|
+
it "returns true" do
|
33
|
+
VCR.use_cassette("client/authenticated/true") { expect(subject.authenticated?).to be_truthy }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with an invalid token" do
|
38
|
+
subject { described_class.new("FAKE-TOKEN") }
|
39
|
+
|
40
|
+
it "returns false" do
|
41
|
+
VCR.use_cassette("client/authenticated/false") { expect(subject.authenticated?).to be_falsey }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# include_examples :resource, :entities, Rexpense::Resources::Entity
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Rexpense::Configuration do
|
5
|
+
subject { Rexpense::Configuration.new }
|
6
|
+
|
7
|
+
it "uses the production mode by default" do
|
8
|
+
expect(subject.api_mode).to eq("production")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "uses a default user agent" do
|
12
|
+
expect(subject.user_agent).to eq("Rexpense Ruby Client v#{Rexpense::VERSION}")
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'allows setting the configuration parameters' do
|
16
|
+
subject.api_mode = "sandbox"
|
17
|
+
subject.user_agent = "My specific user agent"
|
18
|
+
|
19
|
+
expect(subject.api_mode).to eq("sandbox")
|
20
|
+
expect(subject.user_agent).to eq("My specific user agent")
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'does not respond to #token' do
|
24
|
+
expect(subject).to_not respond_to(:token)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rexpense::Entities::Advancement do
|
4
|
+
subject { described_class.new({}) }
|
5
|
+
|
6
|
+
it_behaves_like "entity_attributes", [
|
7
|
+
:id, :comments_count, :activities_count, :description, :currency,
|
8
|
+
:amount, :tags, :created_at, :updated_at, :payer, :receiver
|
9
|
+
]
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rexpense::Entities::Base do
|
4
|
+
|
5
|
+
class DummyEntity < Rexpense::Entities::Base
|
6
|
+
attribute :property_1, String
|
7
|
+
attribute :property_2, String
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:hash) { { property_1: 1, property_2: 2 } }
|
11
|
+
subject { DummyEntity.new(hash) }
|
12
|
+
|
13
|
+
it "builds an object from a hash" do
|
14
|
+
expect(subject).to respond_to(:property_1)
|
15
|
+
expect(subject).to respond_to(:property_2)
|
16
|
+
expect(subject.property_1).to eq("1")
|
17
|
+
expect(subject.property_2).to eq("2")
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#attributes" do
|
21
|
+
it "returns a hash from object attributes" do
|
22
|
+
expect(subject.to_hash).to eq({
|
23
|
+
property_1: "1",
|
24
|
+
property_2: "2"
|
25
|
+
})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rexpense::Entities::Collection do
|
4
|
+
let(:response) { double(headers: {"Link" => "<https://sandbox.rexpense.com/api/v1/expenses?page=3>; rel=next, <https://sandbox.rexpense.com/api/v1/expenses?page=1>; rel=prev, <https://sandbox.rexpense.com/api/v1/expenses?page=3>; rel=last, <https://sandbox.rexpense.com/api/v1/expenses?page=1>; rel=first" },
|
5
|
+
body: "[]") }
|
6
|
+
|
7
|
+
subject { described_class.new(response) }
|
8
|
+
|
9
|
+
describe '#build' do
|
10
|
+
it 'raises NotImplementedError' do
|
11
|
+
expect { subject.build }.to raise_error(NotImplementedError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#next_page' do
|
16
|
+
it 'returns next page (3)' do
|
17
|
+
expect(subject.next_page).to eq(3)
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when there is no next page' do
|
21
|
+
let(:response) { double(headers: {"Link" => ""}, body: "") }
|
22
|
+
|
23
|
+
it 'returns nil' do
|
24
|
+
expect(subject.next_page).to be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#last_page' do
|
30
|
+
it 'returns last page (3)' do
|
31
|
+
expect(subject.last_page).to eq(3)
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when there is no last page' do
|
35
|
+
let(:response) { double(headers: {"Link" => ""}, body: "") }
|
36
|
+
|
37
|
+
it 'returns nil' do
|
38
|
+
expect(subject.last_page).to be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#previous_page' do
|
44
|
+
it 'returns previous page (3)' do
|
45
|
+
expect(subject.previous_page).to eq(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when there is no previous page' do
|
49
|
+
let(:response) { double(headers: {"Link" => ""}, body: "") }
|
50
|
+
|
51
|
+
it 'returns nil' do
|
52
|
+
expect(subject.previous_page).to be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#first_page' do
|
58
|
+
it 'returns first page (3)' do
|
59
|
+
expect(subject.first_page).to eq(1)
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when there is no first page' do
|
63
|
+
let(:response) { double(headers: {"Link" => ""}, body: "") }
|
64
|
+
|
65
|
+
it 'returns nil' do
|
66
|
+
expect(subject.first_page).to be_nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rexpense::Entities::Expense do
|
4
|
+
subject { described_class.new({}) }
|
5
|
+
|
6
|
+
it_behaves_like "entity_attributes", [
|
7
|
+
:id, :attachments_count, :comments_count, :activities_count, :travel_time,
|
8
|
+
:description, :currency, :approved_amount_currency, :kind, :status,
|
9
|
+
:distance_kind, :destination, :origin, :amount, :approved_amount, :latitude,
|
10
|
+
:longitude, :distance, :destination_latitude, :destination_longitude,
|
11
|
+
:origin_longitude, :origin_latitude, :tags, :liquidate_through_advancement,
|
12
|
+
:created_at, :updated_at, :pre_expense_id, :payer, :receiver
|
13
|
+
]
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rexpense::Entities::PreExpense do
|
4
|
+
subject { described_class.new({}) }
|
5
|
+
|
6
|
+
it_behaves_like "entity_attributes", [
|
7
|
+
:id, :amount, :description, :currency, :created_at, :converted_at, :updated_at,
|
8
|
+
:ignored_at, :occurred_at, :tags, :payer, :receiver
|
9
|
+
]
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rexpense::Entities::Reimbursement do
|
4
|
+
subject { described_class.new({}) }
|
5
|
+
|
6
|
+
it_behaves_like "entity_attributes", [
|
7
|
+
:id, :comments_count, :activities_count, :description, :currency,
|
8
|
+
:amount, :tags, :created_at, :updated_at, :payer, :receiver
|
9
|
+
]
|
10
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rexpense::Http do
|
4
|
+
subject { Rexpense::Http.new('8cd049b4afca9213fb2455528394ab2fb0bc34f5c905f33c') }
|
5
|
+
|
6
|
+
describe '#get' do
|
7
|
+
let(:http_method) { :get }
|
8
|
+
let(:url) { '/organizations/68/tags' }
|
9
|
+
let(:params) { {} }
|
10
|
+
|
11
|
+
it_behaves_like 'available http request methods'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#post' do
|
15
|
+
let(:http_method) { :post }
|
16
|
+
let(:url) { '/organizations/68/tags' }
|
17
|
+
let(:params) { { name: 'Rexpense gem client' } }
|
18
|
+
|
19
|
+
it_behaves_like 'available http request methods'
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#put' do
|
23
|
+
let(:http_method) { :put }
|
24
|
+
let(:url) { '/organizations/68/tags/172' }
|
25
|
+
let(:params) { { name: 'Rexpense gem client 02' } }
|
26
|
+
|
27
|
+
it_behaves_like 'available http request methods'
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#delete' do
|
31
|
+
let(:http_method) { :delete }
|
32
|
+
let(:url) { '/organizations/68/tags/114' }
|
33
|
+
let(:params) { {} }
|
34
|
+
|
35
|
+
it_behaves_like 'available http request methods'
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rexpense::Request do
|
4
|
+
describe "#run" do
|
5
|
+
subject { described_class.new({ method: 'post', params: {}, url: 'https://sandbox.rexpense.com', user_agent: 'My Test User-Agent', token: 'my-auth-hash' }) }
|
6
|
+
|
7
|
+
it "does a request using Typhoeus::Request" do
|
8
|
+
expect(Typhoeus::Request).to receive(:new).with("https://sandbox.rexpense.com", { method: "post", params: {}, headers: { "Accept" => "application/json", "Content-Type" => "application/json", "User-Agent" => "My Test User-Agent", "Authorization" => "Basic bXktYXV0aC1oYXNoOlg=" }, accept_encoding: "gzip", params_encoding: :rack }).and_return(double(run: true, response: true))
|
9
|
+
subject.run
|
10
|
+
end
|
11
|
+
|
12
|
+
it "invokes Typhoeus::Request#run" do
|
13
|
+
expect_any_instance_of(Typhoeus::Request).to receive(:run)
|
14
|
+
subject.run
|
15
|
+
end
|
16
|
+
|
17
|
+
it "invokes Typhoeus::Request#response" do
|
18
|
+
allow_any_instance_of(Typhoeus::Request).to receive(:run)
|
19
|
+
expect_any_instance_of(Typhoeus::Request).to receive(:response)
|
20
|
+
subject.run
|
21
|
+
end
|
22
|
+
|
23
|
+
it "generates the base 64 of the user token" do
|
24
|
+
allow_any_instance_of(Typhoeus::Request).to receive(:run)
|
25
|
+
expect(Base64).to receive(:strict_encode64).with("my-auth-hash:X").and_call_original
|
26
|
+
subject.run
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rexpense::Resources::Activity, vcr: true do
|
4
|
+
let(:activity_klass) { Rexpense::Entities::Activity }
|
5
|
+
|
6
|
+
describe "#find_all" do
|
7
|
+
context "with success" do
|
8
|
+
subject { client.activities.find_all }
|
9
|
+
|
10
|
+
it "show all activities successfully" do
|
11
|
+
expect(subject.class).to eq(Rexpense::Entities::ActivityCollection)
|
12
|
+
expect(subject.collection.first.class).to eq(activity_klass)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rexpense::Resources::AdvancementDevolution, vcr: true do
|
4
|
+
let(:devolution_klass) { Rexpense::Entities::AdvancementDevolution }
|
5
|
+
|
6
|
+
describe "#create" do
|
7
|
+
let(:params) do
|
8
|
+
{
|
9
|
+
payer_id: 35, receiver_id: 2, amount: 10.10,
|
10
|
+
currency: 'BRL', date: '27/09/2017'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
it 'create a new devolution' do
|
16
|
+
result = client.advancement_devolutions.create(params)
|
17
|
+
expect(result).to be_a(devolution_klass)
|
18
|
+
expect(result.amount).to eq(10.10)
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with error" do
|
22
|
+
it "raises Rexpense::RequestError with 422 status code" do
|
23
|
+
expect { client.advancement_devolutions.create({}) }.to raise_error(Rexpense::RequestError) do |error|
|
24
|
+
expect(error.code).to eq(422)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|