Permalink
Browse files

Add test coverage for a couple of helper methods.

I'm planning on refactoring these methods, so it's useful to have some
test coverage beforehand.
  • Loading branch information...
1 parent 519e772 commit ea50deb4fb9cbd760e16bcdbeb2dbb472e7793da @floehopper floehopper committed Jan 31, 2012
Showing with 40 additions and 0 deletions.
  1. +40 −0 test/unit/helpers/admin/document_actions_helper_test.rb
@@ -0,0 +1,40 @@
+require 'test_helper'
+
+class Admin::DocumentActionsHelperTest < ActionView::TestCase
+ test "should generate publish button form for document" do
+ document = create(:submitted_document, title: "document-title")
+ html = publish_document_button(document)
+ fragment = Nokogiri::HTML.fragment(html)
+ assert_equal admin_document_publishing_path(document), (fragment/"form").first["action"]
+ refute_nil (fragment/"input[name='document[lock_version]'][type=hidden]").first
+ assert_equal "Publish", (fragment/"input[type=submit]").first["value"]
+ assert_equal "Publish document-title", (fragment/"input[type=submit]").first["title"]
+ assert_nil (fragment/"input[type=submit]").first["data-confirm"]
+ end
+
+ test "should generate publish button form for document with supporting pages alert" do
+ document = create(:submitted_policy, supporting_pages: [create(:supporting_page)])
+ publishing_path = admin_document_publishing_path(document)
+ html = publish_document_button(document)
+ fragment = Nokogiri::HTML.fragment(html)
+ assert_equal "Have you checked the 1 supporting pages?", (fragment/"input[type=submit]").first["data-confirm"]
+ end
+
+ test "should generate force-publish button form" do
+ document = create(:submitted_document, title: "document-title")
+ html = force_publish_document_button(document)
+ fragment = Nokogiri::HTML.fragment(html)
+ assert_equal admin_document_publishing_path(document, force: true), (fragment/"form").first["action"]
+ refute_nil (fragment/"input[name='document[lock_version]'][type=hidden]").first
+ assert_equal "Force Publish", (fragment/"input[type=submit]").first["value"]
+ assert_equal "Publish document-title", (fragment/"input[type=submit]").first["title"]
+ assert_equal "Are you sure you want to force publish this document?", (fragment/"input[type=submit]").first["data-confirm"]
+ end
+
+ test "should generate force-publish button form with supporting pages alert" do
+ document = create(:submitted_policy, supporting_pages: [create(:supporting_page)])
+ html = force_publish_document_button(document)
+ fragment = Nokogiri::HTML.fragment(html)
+ assert_equal "Are you sure you want to force publish this document? Have you checked the 1 supporting pages?", (fragment/"input[type=submit]").first["data-confirm"]
+ end
+end

0 comments on commit ea50deb

Please sign in to comment.