Skip to content

Commit b28f9c3

Browse files
authored
Merge pull request pact-foundation#164 from alexs333/published_date_in_words
changed date published to time ago in words, with full date as mouseover (pact-foundation#145)
2 parents f9bafe3 + 97feb74 commit b28f9c3

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/pact_broker/api/renderers/html_pact_renderer.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def pact_metadata
5757
<span class='value'>#{@pact.consumer_version_number}#{tags}</span>
5858
</li>
5959
<li>
60-
<span class='name'>Date published:</span>
61-
<span class='value'>#{published_date}</span>
60+
<span class='name' title='#{published_date}'>Date published:</span>
61+
<span class='value' title='#{published_date}'>#{published_date_in_words}</span>
6262
</li>
6363
<li>
6464
<a href=\"#{json_url}\">View in API Browser</a>
@@ -108,6 +108,10 @@ def published_date
108108
@pact.created_at.to_time.localtime.to_datetime.strftime("%a %d %b %Y, %l:%M%P %:z")
109109
end
110110

111+
def published_date_in_words
112+
PactBroker::DateHelper.distance_of_time_in_words(@pact.created_at.to_time, DateTime.now) + " ago"
113+
end
114+
111115
def json_url
112116
PactBroker::Api::PactBrokerUrls.hal_browser_url pact_url
113117
end

pact_broker.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ Gem::Specification.new do |gem|
5252
gem.add_development_dependency 'pg', '~>0.21'
5353
gem.add_development_dependency 'conventional-changelog', '~>1.3'
5454
gem.add_development_dependency 'bump', '~> 0.5'
55+
gem.add_development_dependency 'timecop', '~> 0.9'
5556
end

spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'spec_helper'
22
require 'pact_broker/api/renderers/html_pact_renderer'
3+
require 'timecop'
34

45
module PactBroker
56
module Api
@@ -10,10 +11,13 @@ module Renderers
1011
ENV['BACKUP_TZ'] = ENV['TZ']
1112
ENV['TZ'] = "Australia/Melbourne"
1213
PactBroker.configuration.enable_public_badge_access = true
14+
15+
Timecop.freeze(created_at + 3)
1316
end
1417

1518
after do
1619
ENV['TZ'] = ENV['BACKUP_TZ']
20+
Timecop.return
1721
end
1822

1923
let(:consumer) { double('consumer', name: 'Consumer')}
@@ -47,6 +51,7 @@ module Renderers
4751
expect(subject).to match /<h\d>.*Some Provider/
4852
expect(subject).to include("Date published:")
4953
expect(subject).to include("Thu 27 Feb 2014, 11:00am +11:00")
54+
expect(subject).to include("3 days ago")
5055
expect(subject).to match /title.*Pact between Consumer and Provider/
5156
expect(subject).to match /prod, master/
5257
end

0 commit comments

Comments
 (0)