Permalink
Browse files

Add and improve tests around presence of publishing buttons.

- This is partly in preparation for adding a 'change note' field to the
publish / force-publish form.
- It feels more appropriate to talk about a form rather than a button
given that in reality it is a form including a hidden filed. This will
become more so when I add the 'change note' field.
- Tests with apostrophes in the name confuse my text editor.
  • Loading branch information...
1 parent 0083c81 commit 1ac9cd8816a3224df944e5a66dfeed92eadcf8d0 @floehopper floehopper committed Jan 30, 2012
@@ -16,6 +16,7 @@ class Admin::ConsultationsControllerTest < ActionController::TestCase
should_allow_ministerial_roles_for :consultation
should_allow_attachments_for :consultation
should_be_rejectable :consultation
+ should_be_publishable :consultation
should_be_force_publishable :consultation
should_be_able_to_delete_a_document :consultation
should_link_to_public_version_when_published :consultation
@@ -16,6 +16,7 @@ class Admin::InternationalPrioritiesControllerTest < ActionController::TestCase
should_allow_organisations_for :international_priority
should_be_rejectable :international_priority
+ should_be_publishable :international_priority
should_be_force_publishable :international_priority
should_be_able_to_delete_a_document :international_priority
should_link_to_public_version_when_published :international_priority
@@ -15,6 +15,7 @@ class Admin::NewsArticlesControllerTest < ActionController::TestCase
should_allow_ministerial_roles_for :news_article
should_allow_association_between_countries_and :news_article
should_be_rejectable :news_article
+ should_be_publishable :news_article
should_be_force_publishable :news_article
should_be_able_to_delete_a_document :news_article
should_link_to_public_version_when_published :news_article
@@ -16,6 +16,7 @@ class Admin::PoliciesControllerTest < ActionController::TestCase
should_allow_ministerial_roles_for :policy
should_allow_association_between_countries_and :policy
should_be_rejectable :policy
+ should_be_publishable :policy
should_be_force_publishable :policy
should_be_able_to_delete_a_document :policy
should_link_to_public_version_when_published :policy
@@ -16,6 +16,7 @@ class Admin::PublicationsControllerTest < ActionController::TestCase
should_allow_attachments_for :publication
should_allow_association_between_countries_and :publication
should_be_rejectable :publication
+ should_be_publishable :publication
should_be_force_publishable :publication
should_be_able_to_delete_a_document :publication
should_link_to_public_version_when_published :publication
@@ -13,6 +13,7 @@ class Admin::SpeechesControllerTest < ActionController::TestCase
should_allow_association_between_countries_and :speech
should_be_rejectable :speech
+ should_be_publishable :speech
should_be_force_publishable :speech
should_be_able_to_delete_a_document :speech
should_link_to_public_version_when_published :speech
@@ -601,25 +601,54 @@ def should_be_rejectable(document_type)
end
end
+ def should_be_publishable(document_type)
+ document_class = document_class_for(document_type)
+
+ test "should display the publish form if document is publishable" do
+ document = create(document_type)
+ document.stubs(:publishable_by?).returns(true)
+ document_class.stubs(:find).with(document.to_param).returns(document)
+ get :show, id: document
+ assert_select publish_form_selector(document), count: 1
+ end
+
+ test "should not display the publish form if document is not publishable" do
+ document = create(document_type)
+ document.stubs(:publishable_by?).returns(false)
+ document_class.stubs(:find).with(document.to_param).returns(document)
+ get :show, id: document
+ refute_select publish_form_selector(document)
+ end
+ end
+
def should_be_force_publishable(document_type)
document_class = document_class_for(document_type)
- test "should display the 'Force Publish' button" do
+ test "should not display the force-publish form if document is publishable" do
+ document = create(document_type)
+ document.stubs(:publishable_by?).returns(true)
+ document.stubs(:force_publishable_by?).returns(true)
+ document_class.stubs(:find).with(document.to_param).returns(document)
+ get :show, id: document
+ refute_select force_publish_form_selector(document)
+ end
+
+ test "should display the force-publish form if document is not publishable but is force-publishable" do
document = create(document_type)
document.stubs(:publishable_by?).returns(false)
document.stubs(:force_publishable_by?).returns(true)
document_class.stubs(:find).with(document.to_param).returns(document)
get :show, id: document
- assert_select force_publish_button_selector(document), count: 1
+ assert_select force_publish_form_selector(document), count: 1
end
- test "shouldn't display the 'Force Publish' button" do
+ test "should not display the force-publish button if document is neither publishable nor force-publishable" do
document = create(document_type)
document.stubs(:publishable_by?).returns(false)
document.stubs(:force_publishable_by?).returns(false)
document_class.stubs(:find).with(document.to_param).returns(document)
get :show, id: document
- refute_select force_publish_button_selector(document)
+ refute_select force_publish_form_selector(document)
end
end
@@ -85,7 +85,11 @@ def countries_selector
"#countries"
end
- def force_publish_button_selector(document)
+ def publish_form_selector(document)
+ "form[action=#{admin_document_publishing_path(document)}]"
+ end
+
+ def force_publish_form_selector(document)
"form[action=#{admin_document_publishing_path(document, force: true)}]"
end

0 comments on commit 1ac9cd8

Please sign in to comment.