Skip to content

Commit

Permalink
Don't display Document Collection withdrawn documents
Browse files Browse the repository at this point in the history
  • Loading branch information
tvararu committed Dec 13, 2016
1 parent 4dd9dc3 commit 69cba15
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/presenters/document_collection_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ def contents
end

def groups
content_item["details"]["collection_groups"].reject do |group|
group_document_links(group).empty?
end
content_item["details"]["collection_groups"]
.reject { |group|
group_document_links(group).empty?
}
.map { |group|
group["documents"] = reject_withdrawn_documents(group)
group
}
end

def group_document_links(group)
Expand Down Expand Up @@ -50,4 +55,10 @@ def group_title_id(title)
def documents_hash
@documents_hash ||= Array(content_item["links"]["documents"]).map { |d| [d["content_id"], d] }.to_h
end

def reject_withdrawn_documents(group)
group_documents(group)
.reject { |document| document["withdrawn"] }
.map { |document| document["content_id"] }
end
end
17 changes: 17 additions & 0 deletions test/presenters/document_collection_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,21 @@ class GroupWithDocumentsWhenThereIsNoLinksDocuments < TestCase
assert_empty group_with_missing_documents
end
end

class GroupWithDocumentsWhenThereAreWithdrawnDocuments < TestCase
test "does not present withdrawn documents" do
presenter = presented_item(
"document_collection_with_withdrawn_links_documents"
)

groups_without_withdrawn_documents = presenter.groups.first["documents"]

number_of_documents_that_have_withdrawn_false = 2

assert_equal(
groups_without_withdrawn_documents.size,
number_of_documents_that_have_withdrawn_false
)
end
end
end

0 comments on commit 69cba15

Please sign in to comment.