Skip to content
This repository has been archived by the owner on Sep 29, 2020. It is now read-only.

Commit

Permalink
Resolve #14 Sent referrals on Partner Dashboard should only be showin...
Browse files Browse the repository at this point in the history
  • Loading branch information
suninthesky committed Nov 2, 2018
1 parent f1fba9c commit 42f4795
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/controllers/referrals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ReferralsController < ApplicationController

def new
if @partner
@referrals = @partner.referrals.by_month(Time.zone.now.month)
@referrals = @partner.referrals.by_month(@date.month)
@used_referrals = @referrals.used
@total_available = @partner.max_monthly_referrals - @used_referrals.size
else
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_month_picker.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<span class="px15">
<%= "#{Date::MONTHNAMES[date.month]} #{Time.zone.now.year}" %>
</span>
<%= link_to('❯', send(path, date: date - 1.month), class: 'yellow no-decoration') %>
<%= link_to('❯', send(path, date: date - 1.month), class: 'yellow no-decoration', data: { turbolinks: false }) %>
</div>
44 changes: 25 additions & 19 deletions app/views/referrals/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,43 @@
</div>

<div class="fr1 mb20">
<h2 class="bold center mb20">Sent</h2>
<h2 class="bold center mb20">Used</h2>
<%= tag.div(
@referrals.size, id: "#{@partner.slug}-used-referrals",
@used_referrals.size, id: "#{@partner.slug}-used-referrals",
class: "lg stat-lg white bg-black"
) %>
</div>

</div>

<% if @partner.referrals.any? %>
<h2 class="bold px15 maroon">Sent Referrals</h2>
<% if @referrals.any? %>
<div class="mb40">
<h2 class="bold px15 maroon">Sent Referrals</h2>

<div class="row bold h2">
<div class="sm fr2 truncate">Name</div>
<div class="sm fr1 truncate">Status</div>
<div class="sm fr1 truncate">Date</div>
</div>
<div class="row bold h2">
<div class="sm fr2 truncate">Name</div>
<div class="sm fr1 truncate">Status</div>
<div class="sm fr1 truncate">Date</div>
</div>

<% @referrals.order(created_at: :desc).each do |r| %>

<% @partner.referrals.order(created_at: :desc).each do |r| %>
<div class="row with-border h3 mb10">
<span class="sm fr2 truncate bold">
<%= r.response_identifier %>
</span>
<%= status_text(r.last_state, classes: "sm fr1 truncate") %>
<span class="sm fr1 truncate">
<%= r.created_at.strftime('%d / %m / %y') %>
</span>
</div>

<div class="row with-border h3 mb10">
<span class="sm fr2 truncate bold">
<%= r.response_identifier %>
</span>
<%= status_text(r.last_state, classes: "sm fr1 truncate") %>
<span class="sm fr1 truncate">
<%= r.created_at.strftime('%d / %m / %y') %>
</span>
<% end %>
</div>
<% end %>

<% end %>
<% if user_signed_in? %>
<%= render(partial: 'layouts/month_picker', locals: { date: @date, path: :new_partner_referral_path }) %>
<% end %>

<script src="https://embed.typeform.com/embed.js" type="text/javascript"></script>
Expand Down
29 changes: 23 additions & 6 deletions test/system/partner_referral_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,45 @@ class PartnerReferralTest < ApplicationSystemTestCase
end

test 'hides list if no referrals' do
@user = create(:user)
visit new_user_session_path
sign_in
sign_in_user
visit new_partner_referral_path(@partner)
assert_no_text('Sent Referrals')
end

test 'shows list if logged in and referrals present' do
create(:referral, partner: @partner)
@user = create(:user)
visit new_user_session_path
sign_in
sign_in_user
visit new_partner_referral_path(@partner)
assert_text('Sent Referrals')
assert_selector('.row.with-border', count: 1)
end

test 'month picker hidden when logged out' do
visit new_partner_referral_path(@partner)
assert_text(month_name, count: 1)
end

test 'month picker shown when logged in' do
sign_in_user
visit new_partner_referral_path(@partner)
assert_text(month_name, count: 2)
end

def month_name
Date::MONTHNAMES[Date.today.month]
end

def send_fake_webhook_request(partner)
fake_webhook_request(
webhooks_new_response_path(partner.webhook_token),
headers: { 'Content-Type' => 'application/json' },
body: { event_id: 'LtWXD3crgy' }
)
end

def sign_in_user
@user = create(:user)
visit new_user_session_path
sign_in
end
end

0 comments on commit 42f4795

Please sign in to comment.