Skip to content

Fix/pay from offer #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ def dashboard
offers[category] = list if list.present?
end
end

def show
super

member = @offer.user.members.find_by(organization: current_organization)
@destination_account = member.account if member
end
end
1 change: 0 additions & 1 deletion app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def self.inherited(child)
belongs_to :user
belongs_to :organization
belongs_to :publisher, class_name: "User", foreign_key: "publisher_id"
# belongs_to :member, class_name: "Member", foreign_key: "user_id"
has_many :user_members, class_name: "Member", through: :user, source: :members
has_many :transfers
has_many :movements, through: :transfers
Expand Down
2 changes: 1 addition & 1 deletion app/views/offers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<% end %>
<% end %>
<% if current_user and @offer.user != current_user %>
<%= link_to new_transfer_path(id: @offer.user.id, offer: @offer.id),
<%= link_to new_transfer_path(id: @offer.user.id, offer: @offer.id, destination_account_id: @destination_account.id),
class: "btn btn-success" do %>
<%= glyph :time %>
<%= t ".give_time_for" %>
Expand Down
28 changes: 18 additions & 10 deletions spec/controllers/offers_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -60,16 +62,22 @@
describe "GET #show" do
context "with valid params" do
context "with a logged user" do
it "assigns the requested offer to @offer" do
login(another_member.user)
before { login(another_member.user) }

get "show", id: offer.id
it "assigns the requested offer to @offer" do
get :show, id: offer.id
expect(assigns(:offer)).to eq(offer)
end

it 'assigns the account destination of the transfer' do
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
get :show, id: offer.id
expect(assigns(:offer)).to eq(offer)
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/fabricators/account_fabricator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fabricator(:account) do
end
75 changes: 75 additions & 0 deletions spec/views/offers/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'spec_helper'

describe 'offers/show' do
let(:organization) { Fabricate(:organization) }
let(:member) { Fabricate(:member, organization: organization) }
let(:offer) { Fabricate(:offer, user: member.user, organization: organization) }
let(:destination_account) { Fabricate(:account) }

before do
allow(view).to receive(:admin?).and_return(false)
allow(view).to receive(:current_organization) { organization }

allow(offer).to receive(:member).and_return(member)
end

context 'when there is logged in' do
let(:logged_user) { Fabricate(:user) }

before do
Fabricate(
:member,
organization: organization,
user: logged_user
)

allow(view).to receive(:current_user).and_return(logged_user)
end

it 'renders a link to the transfer page' do
assign :offer, offer
assign :destination_account, destination_account
render template: 'offers/show'

expect(rendered).to have_link(
t('offers.show.give_time_for'),
href: new_transfer_path(
id: offer.user.id,
offer: offer.id,
destination_account_id: destination_account.id
)
)
end
end

context 'where is a guest user' do
before do
allow(view).to receive(:current_user).and_return(nil)
end

it 'does not render a link to the transfer page' do
assign :offer, offer
assign :destination_account, destination_account
render template: 'offers/show'

expect(rendered).not_to have_link(
t('offers.show.give_time_for'),
href: new_transfer_path(
id: offer.user.id,
offer: offer.id,
destination_account_id: destination_account.id
)
)
end

it 'renders a link to the login page' do
assign :offer, offer
render template: 'offers/show'

expect(rendered).to have_link(
t('layouts.application.login'),
href: new_user_session_path
)
end
end
end