Provide destination_account to offers show view

This commit is contained in:
Pau Perez
2018-02-01 13:55:35 +01:00
parent c88e959ea9
commit 49aaef0868
2 changed files with 25 additions and 6 deletions

View File

@ -18,4 +18,13 @@ class OffersController < PostsController
offers[category] = list if list.present?
end
end
def show
super
@destination_account = @offer
.user
.members
.find_by(organization: current_organization)
.account
end
end

View File

@ -1,18 +1,20 @@
require "spec_helper"
describe OffersController, type: :controller do
let (:test_organization) { Fabricate(:organization) }
let (:member) { Fabricate(:member, organization: test_organization) }
let (:another_member) { Fabricate(:member, organization: test_organization) }
let (:yet_another_member) { Fabricate(:member) }
let (:test_category) { Fabricate(:category) }
let! (:offer) do
let(:test_organization) { Fabricate(:organization) }
let(:member) { Fabricate(:member, organization: test_organization) }
let(:another_member) { Fabricate(:member, organization: test_organization) }
let(:yet_another_member) { Fabricate(:member) }
let(:test_category) { Fabricate(:category) }
let!(:offer) do
Fabricate(:offer,
user: member.user,
organization: test_organization,
category: test_category)
end
include_context "stub browser locale"
before { set_browser_locale("ca") }
describe "GET #index" do
@ -66,7 +68,15 @@ describe OffersController, type: :controller do
get "show", id: offer.id
expect(assigns(:offer)).to eq(offer)
end
it 'assigns the account destination of the transfer' do
login(another_member.user)
get :show, id: offer.id
expect(assigns(:destination_account)).to eq(member.account)
end
end
context "without a logged in user" do
it "assigns the requested offer to @offer" do
get "show", id: offer.id