Skip to content
Open
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
10 changes: 8 additions & 2 deletions app/helpers/issue_meta_tags_helper.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
module IssueMetaTagsHelper
def title_helper(issue)
if issue.bounty_total > 0
"#{number_to_currency(issue.bounty_total, precision: 0)} Bounty on #{issue.tracker.name}"
"#{whole_dollar_currency(issue.bounty_total)} Bounty on #{issue.tracker.name}"
elsif issue.bounty_total == 0 && !issue.paid_out
"Post a bounty on #{issue.tracker.name}!"
elsif issue.paid_out
#assumes there is only one paid_out bounty_claim for this issue
"A #{number_to_currency(issue.bounty_claims.collected.first.amount.to_i, precision: 0)} Bounty has been paid out for #{issue.tracker.name}"
"A #{whole_dollar_currency(issue.bounty_claims.collected.first.amount)} Bounty has been paid out for #{issue.tracker.name}"
else
#shouldn't occur, but just in case
"Check out this issue on Bountysource!"
end
end

private

def whole_dollar_currency(amount)
number_to_currency(amount.floor, precision: 0)
end
end
29 changes: 29 additions & 0 deletions spec/helpers/issue_meta_tags_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rails_helper'

RSpec.describe IssueMetaTagsHelper, type: :helper do
describe '#title_helper' do
let(:tracker) { double(name: 'Example Tracker') }

it 'floors fractional open bounty totals instead of rounding up' do
issue = double(
bounty_total: BigDecimal('5.50'),
tracker: tracker,
paid_out: false
)

expect(helper.title_helper(issue)).to eq('$5 Bounty on Example Tracker')
end

it 'floors fractional paid bounty amounts instead of rounding up' do
bounty_claim = double(amount: BigDecimal('5.50'))
issue = double(
bounty_total: BigDecimal('0'),
tracker: tracker,
paid_out: true,
bounty_claims: double(collected: double(first: bounty_claim))
)

expect(helper.title_helper(issue)).to eq('A $5 Bounty has been paid out for Example Tracker')
end
end
end