Skip to content

Commit

Permalink
Merge pull request #77 from alphagov/fix-displaying-time-ago-for-drafts
Browse files Browse the repository at this point in the history
Fix display for no last updated at
  • Loading branch information
chao-xian authored Feb 27, 2017
2 parents 49ed6d4 + 67ee604 commit 8948d4f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/views/content_items/_content_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
<% end %>
<td><%= content_item.document_type %></td>
<td><%= content_item.unique_page_views %></td>
<td><%= time_ago_in_words(content_item.public_updated_at) %> ago</td>
<td>
<% if content_item.public_updated_at %>
<%= time_ago_in_words(content_item.public_updated_at) %> ago
<% else %>
Never
<% end %>
</td>
</tr>
8 changes: 7 additions & 1 deletion app/views/content_items/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
</tr>
<tr>
<td>Last updated</td>
<td><%= time_ago_in_words(@content_item.public_updated_at) %> ago</td>
<td>
<% if @content_item.public_updated_at %>
<%= time_ago_in_words(@content_item.public_updated_at) %> ago
<% else %>
Never
<% end %>
</td>
</tr>
<tr>
<td>Organisation</td>
Expand Down
18 changes: 18 additions & 0 deletions spec/views/content_items/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
expect(rendered).to have_selector('table tbody tr', count: 2)
end

context 'items that have never been published' do
it 'renders for no last updated value' do
content_items[0].public_updated_at = nil
render

expect(rendered).to have_selector('table tr td:nth(5)', text: 'Never')
end
end

describe 'row content' do
it 'items depict the Organisations they each belong to' do
content_items[0].organisations.build(title: 'An organisation', slug: 'organisation-slug ')
Expand Down Expand Up @@ -114,6 +123,15 @@

expect(rendered).to have_link('Last Updated', href: href)
end

context 'items that have never been published' do
it 'renders for no last updated value' do
content_items[0].public_updated_at = nil
render

expect(rendered).to have_selector('table tr td:nth(4)', text: 'Never')
end
end
end
end
end
9 changes: 9 additions & 0 deletions spec/views/content_items/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,14 @@
expect(rendered).to have_selector('td', text: 'Organisation')
expect(rendered).to have_selector('td + td', text: 'An Organisation, Another Organisation')
end

context 'item has never been published' do
it 'renders for no last updated value' do
content_item.public_updated_at = nil
render

expect(rendered).to have_selector('table tbody tr:nth(5) td:nth(2)', text: 'Never')
end
end
end
end

0 comments on commit 8948d4f

Please sign in to comment.