diff --git a/app/helpers/issue_meta_tags_helper.rb b/app/helpers/issue_meta_tags_helper.rb index 3e3bce91b..c35c0c654 100644 --- a/app/helpers/issue_meta_tags_helper.rb +++ b/app/helpers/issue_meta_tags_helper.rb @@ -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 diff --git a/spec/helpers/issue_meta_tags_helper_spec.rb b/spec/helpers/issue_meta_tags_helper_spec.rb new file mode 100644 index 000000000..01f9fb203 --- /dev/null +++ b/spec/helpers/issue_meta_tags_helper_spec.rb @@ -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