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

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
Merge pull request #15 from TechforgoodCAST/dev
  • Loading branch information
suninthesky authored Nov 2, 2018
2 parents 407e2f2 + 42f4795 commit bceebbd
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.2)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
Expand All @@ -159,7 +159,7 @@ GEM
multi_json (1.13.1)
multipart-post (2.0.0)
nio4r (2.3.1)
nokogiri (1.8.4)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
pg (1.1.3)
Expand Down
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/models/partner.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Partner < ApplicationRecord
has_many :referrals
has_many :referrals, dependent: :destroy

has_secure_token :webhook_token

Expand Down
2 changes: 1 addition & 1 deletion app/models/referral.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Referral < ApplicationRecord
belongs_to :partner
acts_as_sequenced scope: :partner_id

has_many :reviews
has_many :reviews, dependent: :destroy

validates :last_state, inclusion: { in: STATES }
validates :original_response, presence: true
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 bceebbd

Please sign in to comment.