Skip to content

Commit 4f59f9d

Browse files
committed
tests: added tests for the case where the organisation is the source. Issue #638
1 parent 1c61670 commit 4f59f9d

File tree

1 file changed

+70
-27
lines changed

1 file changed

+70
-27
lines changed

spec/controllers/transfers_controller_spec.rb

+70-27
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@
174174
} }
175175
end
176176

177+
subject(:create_between_src_org) do
178+
post 'create', params: { transfer: {
179+
source: test_organization.account.id,
180+
destination: second_member_taker.account.id,
181+
amount: 5
182+
} }
183+
end
184+
177185
let(:user) { member_admin.user }
178186
context 'the transfer is within the same organisation' do
179187
it 'creates a new Transfer' do
@@ -197,36 +205,71 @@
197205
end
198206
end
199207

200-
context 'the transfer is between members of different organisations' do
201-
it 'creates three news Transfers' do
202-
expect { create_between_orgs }.to change(Transfer, :count).by 3
203-
end
204-
205-
it 'creates six Movements' do
206-
expect { create_between_orgs }.to change { Movement.count }.by 6
207-
end
208-
209-
it 'updates the balance of both accounts' do
210-
expect do
211-
create_between_orgs
212-
member_giver.reload
213-
end.to change { member_giver.account.balance.to_i }.by -5
214-
215-
expect do
208+
context 'the transfer is between different organisations' do
209+
context 'the source is a member' do
210+
it 'creates three news Transfers' do
211+
expect { create_between_orgs }.to change(Transfer, :count).by 3
212+
end
213+
214+
it 'creates six Movements' do
215+
expect { create_between_orgs }.to change { Movement.count }.by 6
216+
end
217+
218+
it 'updates the balance of both accounts' do
219+
expect do
220+
create_between_orgs
221+
member_giver.reload
222+
end.to change { member_giver.account.balance.to_i }.by -5
223+
224+
expect do
225+
create_between_orgs
226+
second_member_taker.reload
227+
end.to change { second_member_taker.account.balance.to_i }.by 5
228+
end
229+
230+
it 'updates the global balance of both organizations' do
216231
create_between_orgs
217-
second_member_taker.reload
218-
end.to change { second_member_taker.account.balance.to_i }.by 5
219-
end
220232

221-
it 'updates the global balance of both organizations' do
222-
create_between_orgs
233+
expect(test_organization.global_balance).to equal -5
234+
expect(second_organization.global_balance).to equal 5
235+
end
223236

224-
expect(test_organization.global_balance).to equal -5
225-
expect(second_organization.global_balance).to equal 5
237+
it 'redirects to destination organization' do
238+
expect(create_between_orgs).to redirect_to(second_member_taker.organization)
239+
end
226240
end
227241

228-
it 'redirects to source user' do
229-
expect(create_between_orgs).to redirect_to(member_giver.user)
242+
context 'the source is a organization' do
243+
it 'creates two news Transfers' do
244+
expect { create_between_src_org }.to change(Transfer, :count).by 2
245+
end
246+
247+
it 'creates four Movements' do
248+
expect { create_between_src_org }.to change { Movement.count }.by 4
249+
end
250+
251+
it 'updates the balance of both accounts' do
252+
expect do
253+
create_between_src_org
254+
test_organization.reload
255+
end.to change { test_organization.account.balance.to_i }.by -5
256+
257+
expect do
258+
create_between_src_org
259+
second_member_taker.reload
260+
end.to change { second_member_taker.account.balance.to_i }.by 5
261+
end
262+
263+
it 'updates the global balance of both organizations' do
264+
create_between_src_org
265+
266+
expect(test_organization.global_balance).to equal -5
267+
expect(second_organization.global_balance).to equal 5
268+
end
269+
270+
it 'redirects to destination organization' do
271+
expect(create_between_src_org).to redirect_to(second_member_taker.organization)
272+
end
230273
end
231274
end
232275
end
@@ -301,8 +344,8 @@
301344
expect(second_organization.global_balance).to equal 5
302345
end
303346

304-
it 'redirects to source' do
305-
expect(create_between_orgs).to redirect_to(member_giver.user)
347+
it 'redirects to destination organization' do
348+
expect(create_between_orgs).to redirect_to(second_member_taker.organization)
306349
end
307350
end
308351
end

0 commit comments

Comments
 (0)