Skip to content

Commit a04a06a

Browse files
committed
Use has_one for relationship call
1 parent ae2cbfa commit a04a06a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/cirro_io/client/payout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module CirroIO
22
module Client
33
class Payout < Base
4-
belongs_to :app_worker
4+
has_one :app_worker
55
end
66
end
77
end

spec/cirro_io/client/payout_spec.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
end
2424

2525
describe '.create' do
26-
let(:payout) { described_class.create app_worker_id: app_worker.id, **attributes }
27-
26+
let(:request_url) { "#{test_site}/v1/payouts" }
27+
let(:payout) { described_class.create app_worker: app_worker, **attributes }
2828
let(:attributes) do
2929
{
3030
title: Faker::Hipster.sentence,
@@ -35,14 +35,29 @@
3535
end
3636

3737
before do
38-
stub_request(:post, "#{test_site}/v1/app-workers/#{app_worker.id}/payouts")
38+
stub_request(:post, request_url)
3939
.with(headers: request_headers)
4040
.to_return(body: File.read('./spec/fixtures/payout.json'), headers: response_headers)
4141
end
4242

4343
it 'creates a payout for the app worker' do
44+
request_body = {
45+
data: {
46+
type: 'payouts',
47+
relationships: {
48+
'app-worker': {
49+
data: {
50+
type: 'app-workers',
51+
id: 1,
52+
},
53+
},
54+
},
55+
attributes: attributes
56+
}
57+
}
58+
4459
expect(payout).to be_persisted
45-
expect(payout.app_worker_id).to eq 1
60+
expect(a_request(:post, request_url).with(body: request_body.to_json)).to have_been_made
4661
end
4762
end
4863
end

0 commit comments

Comments
 (0)