Permalink
Browse files

Show change note for first edition and ignore blank change notes.

  • Loading branch information...
1 parent 53bf1b3 commit 427f3c43a665d7ea1d4f0524a5de4551f05f8a71 @floehopper floehopper committed Feb 2, 2012
Showing with 40 additions and 7 deletions.
  1. +9 −0 app/helpers/document_helper.rb
  2. +3 −3 app/views/policies/show.html.erb
  3. +28 −4 test/functional/policies_controller_test.rb
@@ -0,0 +1,9 @@
+module DocumentHelper
+ def change_history(document)
+ history = document.editions_ever_published.map do |e|
+ {published_at: e.published_at, change_note: e.change_note}
+ end
+ history.last[:change_note] ||= "First published." if history.last
+ history.reject { |e| e[:change_note].blank? }
+ end
+end
@@ -11,10 +11,10 @@
<section class="change_notes">
<h1>Policy change notes</h1>
<ul>
- <% @policy.editions_ever_published.each do |edition| %>
+ <% change_history(@policy).each do |edition| %>
<li class="group">
- <%= time_ago(edition.published_at, class: 'published_at') %>
- <p><%= edition.change_note %></p>
+ <%= time_ago(edition[:published_at], class: 'published_at') %>
+ <p><%= edition[:change_note] %></p>
</li>
<% end %>
</ul>
@@ -302,12 +302,12 @@ class PoliciesControllerTest < ActionController::TestCase
refute_select_policy_section_list
end
- test "show displays change history for policy in reverse chronological order" do
+ test "show displays change history in reverse chronological order" do
editions = []
- editions << create(:published_policy, change_note: "Third edition.", published_at: 1.month.ago)
+ editions << create(:published_policy, change_note: "Third go.", 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)
+ editions << create(:archived_policy, change_note: "Second attempt.", document_identity: document_identity, published_at: 2.months.ago)
+ editions << create(:archived_policy, change_note: "First effort.", document_identity: document_identity, published_at: 3.months.ago)
get :show, id: document_identity
@@ -318,4 +318,28 @@ class PoliciesControllerTest < ActionController::TestCase
end
end
end
+
+ test "show displays default change note for first edition" do
+ first_edition = create(:published_policy, change_note: nil, published_at: 1.month.ago)
+
+ get :show, id: first_edition.document_identity
+
+ assert_select ".policy .change_notes li" do
+ assert_select ".published_at[title='#{first_edition.published_at.iso8601}']"
+ assert_select "p", text: "First published."
+ end
+ end
+
+ test "show does not display blank change notes in change history" do
+ second_edition = create(:published_policy, change_note: nil, published_at: 1.months.ago)
+ document_identity = second_edition.document_identity
+ first_edition = create(:archived_policy, change_note: "First effort.", document_identity: document_identity, published_at: 2.months.ago)
+
+ get :show, id: document_identity
+
+ assert_select ".policy .change_notes li" do
+ refute_select ".published_at[title='#{second_edition.published_at.iso8601}']"
+ refute_select "p", text: ""
+ end
+ end
end

0 comments on commit 427f3c4

Please sign in to comment.