Skip to content

Commit

Permalink
Merge pull request #164 from alexs333/published_date_in_words
Browse files Browse the repository at this point in the history
changed date published to time ago in words, with full date as mouseover (#145)
  • Loading branch information
bethesque authored Nov 23, 2017
2 parents f9bafe3 + 97feb74 commit b28f9c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/pact_broker/api/renderers/html_pact_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def pact_metadata
<span class='value'>#{@pact.consumer_version_number}#{tags}</span>
</li>
<li>
<span class='name'>Date published:</span>
<span class='value'>#{published_date}</span>
<span class='name' title='#{published_date}'>Date published:</span>
<span class='value' title='#{published_date}'>#{published_date_in_words}</span>
</li>
<li>
<a href=\"#{json_url}\">View in API Browser</a>
Expand Down Expand Up @@ -108,6 +108,10 @@ def published_date
@pact.created_at.to_time.localtime.to_datetime.strftime("%a %d %b %Y, %l:%M%P %:z")
end

def published_date_in_words
PactBroker::DateHelper.distance_of_time_in_words(@pact.created_at.to_time, DateTime.now) + " ago"
end

def json_url
PactBroker::Api::PactBrokerUrls.hal_browser_url pact_url
end
Expand Down
1 change: 1 addition & 0 deletions pact_broker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'pg', '~>0.21'
gem.add_development_dependency 'conventional-changelog', '~>1.3'
gem.add_development_dependency 'bump', '~> 0.5'
gem.add_development_dependency 'timecop', '~> 0.9'
end
5 changes: 5 additions & 0 deletions spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'pact_broker/api/renderers/html_pact_renderer'
require 'timecop'

module PactBroker
module Api
Expand All @@ -10,10 +11,13 @@ module Renderers
ENV['BACKUP_TZ'] = ENV['TZ']
ENV['TZ'] = "Australia/Melbourne"
PactBroker.configuration.enable_public_badge_access = true

Timecop.freeze(created_at + 3)
end

after do
ENV['TZ'] = ENV['BACKUP_TZ']
Timecop.return
end

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

0 comments on commit b28f9c3

Please sign in to comment.