Skip to content

Commit

Permalink
Change notes should display published_at not first_published_at.
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Feb 2, 2012
1 parent 1bda4ff commit 007eac6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/models/document_identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def unpublished_edition
end

def editions_ever_published
documents.where(state: [:published, :archived]).by_first_published_at
documents.where(state: [:published, :archived]).by_published_at
end

def update_slug_if_possible(new_title)
Expand Down
2 changes: 1 addition & 1 deletion app/views/policies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ul>
<% @policy.editions_ever_published.each do |edition| %>
<li class="group">
<%= time_ago(edition.first_published_at, class: 'first_published_at') %>
<%= time_ago(edition.published_at, class: 'published_at') %>
<p><%= edition.change_note %></p>
</li>
<% end %>
Expand Down
17 changes: 17 additions & 0 deletions test/functional/policies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,21 @@ class PoliciesControllerTest < ActionController::TestCase
get :show, id: policy.document_identity
refute_select_policy_section_list
end

test "show displays change history for policy in reverse chronological order" do
editions = []
editions << create(:published_policy, change_note: "Third edition.", published_at: 1.month.ago)
document_identity = editions.first.document_identity
editions << create(:archived_policy, change_note: "Second edition.", document_identity: document_identity, published_at: 2.months.ago)
editions << create(:archived_policy, change_note: "First published.", document_identity: document_identity, published_at: 3.months.ago)

get :show, id: document_identity

assert_select ".policy .change_notes li" do |list_items|
list_items.each_with_index do |list_item, index|
assert_select list_item, ".published_at[title='#{editions[index].published_at.iso8601}']"
assert_select list_item, "p", text: editions[index].change_note
end
end
end
end
8 changes: 4 additions & 4 deletions test/unit/document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -751,11 +751,11 @@ class DocumentTest < ActiveSupport::TestCase
new_edition.publish_as(create(:departmental_editor), force: true)
end

test "should provide a list of all editions ever published in reverse chronological order by first publication date" do
original_edition = create(:archived_document, first_published_at: 3.days.ago)
test "should provide a list of all editions ever published in reverse chronological order by publication date" do
original_edition = create(:archived_document, published_at: 3.days.ago)
document_identity = original_edition.document_identity
new_edition_1 = create(:archived_document, document_identity: document_identity, first_published_at: 2.days.ago)
new_edition_2 = create(:published_document, document_identity: document_identity, first_published_at: 1.day.ago)
new_edition_1 = create(:archived_document, document_identity: document_identity, published_at: 2.days.ago)
new_edition_2 = create(:published_document, document_identity: document_identity, published_at: 1.day.ago)
draft_edition = create(:draft_document, document_identity: document_identity)

assert_equal [new_edition_2, new_edition_1, original_edition], new_edition_2.editions_ever_published
Expand Down

0 comments on commit 007eac6

Please sign in to comment.