|
174 | 174 | } }
|
175 | 175 | end
|
176 | 176 |
|
| 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 | + |
177 | 185 | let(:user) { member_admin.user }
|
178 | 186 | context 'the transfer is within the same organisation' do
|
179 | 187 | it 'creates a new Transfer' do
|
|
197 | 205 | end
|
198 | 206 | end
|
199 | 207 |
|
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 |
216 | 231 | create_between_orgs
|
217 |
| - second_member_taker.reload |
218 |
| - end.to change { second_member_taker.account.balance.to_i }.by 5 |
219 |
| - end |
220 | 232 |
|
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 |
223 | 236 |
|
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 |
226 | 240 | end
|
227 | 241 |
|
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 |
230 | 273 | end
|
231 | 274 | end
|
232 | 275 | end
|
|
301 | 344 | expect(second_organization.global_balance).to equal 5
|
302 | 345 | end
|
303 | 346 |
|
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) |
306 | 349 | end
|
307 | 350 | end
|
308 | 351 | end
|
|
0 commit comments