diff options
Diffstat (limited to 'test/controllers/nodes_controller_test.rb')
| -rw-r--r-- | test/controllers/nodes_controller_test.rb | 105 |
1 files changed, 100 insertions, 5 deletions
diff --git a/test/controllers/nodes_controller_test.rb b/test/controllers/nodes_controller_test.rb index 5b66bd3..ddc4565 100644 --- a/test/controllers/nodes_controller_test.rb +++ b/test/controllers/nodes_controller_test.rb | |||
| @@ -140,7 +140,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 140 | :page => { | 140 | :page => { |
| 141 | :title => "Hello", | 141 | :title => "Hello", |
| 142 | :body => "There", | 142 | :body => "There", |
| 143 | :template_name => "Foobar" | 143 | :template_name => "title_only" |
| 144 | } | 144 | } |
| 145 | } | 145 | } |
| 146 | 146 | ||
| @@ -148,7 +148,17 @@ class NodesControllerTest < ActionController::TestCase | |||
| 148 | test_node.reload | 148 | test_node.reload |
| 149 | assert_equal "Hello", test_node.head.title | 149 | assert_equal "Hello", test_node.head.title |
| 150 | assert_equal "There", test_node.head.body | 150 | assert_equal "There", test_node.head.body |
| 151 | assert_equal "Foobar", test_node.head.template_name | 151 | assert_equal "title_only", test_node.head.template_name |
| 152 | end | ||
| 153 | |||
| 154 | def test_update_rejects_a_template_name_not_on_disk | ||
| 155 | test_node = Node.root.children.create! :slug => "test_node" | ||
| 156 | login_as :quentin | ||
| 157 | put :update, params: { :id => test_node.id, | ||
| 158 | :page => { :title => "Hello", :template_name => "Foobar" } } | ||
| 159 | |||
| 160 | test_node.reload | ||
| 161 | assert_not_equal "Foobar", test_node.draft&.template_name | ||
| 152 | end | 162 | end |
| 153 | 163 | ||
| 154 | test "publish draft with staged_slug unqueal slug" do | 164 | test "publish draft with staged_slug unqueal slug" do |
| @@ -417,11 +427,11 @@ class NodesControllerTest < ActionController::TestCase | |||
| 417 | test "show never renders a destroy link for events" do | 427 | test "show never renders a destroy link for events" do |
| 418 | login_as :quentin | 428 | login_as :quentin |
| 419 | node = create_node_with_published_page | 429 | node = create_node_with_published_page |
| 420 | Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) | 430 | event = Event.create!(node_id: node.id, start_time: Time.now, end_time: Time.now + 1.hour) |
| 421 | 431 | ||
| 422 | get :show, params: { id: node.id } | 432 | get :show, params: { id: node.id } |
| 423 | assert_response :success | 433 | assert_response :success |
| 424 | assert_select "form.button_to.destructive", count: 0 | 434 | assert_select "form[action=?]", event_path(event), count: 0 |
| 425 | end | 435 | end |
| 426 | 436 | ||
| 427 | test "reverting from nodes#show returns to the show page, not the editor, even if a draft remains" do | 437 | test "reverting from nodes#show returns to the show page, not the editor, even if a draft remains" do |
| @@ -469,7 +479,8 @@ class NodesControllerTest < ActionController::TestCase | |||
| 469 | login_as :quentin | 479 | login_as :quentin |
| 470 | get :show, params: { :id => node.id } | 480 | get :show, params: { :id => node.id } |
| 471 | assert_response :success | 481 | assert_response :success |
| 472 | assert_select "form.destructive", :count => 0 | 482 | assert_select "form[action=?]", revert_node_path(node), count: 0 |
| 483 | assert_select "form[action=?]", trash_node_path(node), count: 1 | ||
| 473 | end | 484 | end |
| 474 | 485 | ||
| 475 | test "drafts includes a never-published node with only a draft" do | 486 | test "drafts includes a never-published node with only a draft" do |
| @@ -662,4 +673,88 @@ class NodesControllerTest < ActionController::TestCase | |||
| 662 | assert_equal "Brand New", action.metadata["title"] | 673 | assert_equal "Brand New", action.metadata["title"] |
| 663 | assert_equal Node.last.unique_name, action.metadata["path"] | 674 | assert_equal Node.last.unique_name, action.metadata["path"] |
| 664 | end | 675 | end |
| 676 | |||
| 677 | test "trash moves the node and redirects to the Trash" do | ||
| 678 | login_as :quentin | ||
| 679 | node = Node.root.children.create!(:slug => "trash_me") | ||
| 680 | |||
| 681 | put :trash, params: { :id => node.id } | ||
| 682 | |||
| 683 | assert_redirected_to trashed_nodes_path | ||
| 684 | assert node.reload.in_trash? | ||
| 685 | end | ||
| 686 | |||
| 687 | test "trashing the Trash node itself is refused" do | ||
| 688 | login_as :quentin | ||
| 689 | |||
| 690 | put :trash, params: { :id => Node.trash.id } | ||
| 691 | |||
| 692 | assert_redirected_to node_path(Node.trash) | ||
| 693 | assert flash[:error].present? | ||
| 694 | end | ||
| 695 | |||
| 696 | test "restore_from_trash reparents to the given parent" do | ||
| 697 | login_as :quentin | ||
| 698 | node = Node.root.children.create!(:slug => "restore_me") | ||
| 699 | node.trash!(users(:quentin)) | ||
| 700 | target = Node.root.children.create!(:slug => "restore_home") | ||
| 701 | |||
| 702 | put :restore_from_trash, params: { :id => node.id, :parent_id => target.id } | ||
| 703 | |||
| 704 | assert_redirected_to node_path(node) | ||
| 705 | assert_equal target, node.reload.parent | ||
| 706 | end | ||
| 707 | |||
| 708 | test "destroy refuses a node outside the Trash" do | ||
| 709 | login_as :quentin | ||
| 710 | node = Node.root.children.create!(:slug => "not_deletable_here") | ||
| 711 | |||
| 712 | delete :destroy, params: { :id => node.id } | ||
| 713 | |||
| 714 | assert Node.exists?(node.id) | ||
| 715 | assert flash[:error].present? | ||
| 716 | end | ||
| 717 | |||
| 718 | test "destroy deletes a trashed node and redirects to the Trash" do | ||
| 719 | login_as :quentin | ||
| 720 | node = Node.root.children.create!(:slug => "deletable") | ||
| 721 | node.trash!(users(:quentin)) | ||
| 722 | |||
| 723 | delete :destroy, params: { :id => node.id } | ||
| 724 | |||
| 725 | assert_not Node.exists?(node.id) | ||
| 726 | assert_redirected_to trashed_nodes_path | ||
| 727 | end | ||
| 728 | |||
| 729 | test "trash lists trashed subtree roots" do | ||
| 730 | login_as :quentin | ||
| 731 | node = Node.root.children.create!(:slug => "listed_in_trash") | ||
| 732 | node.trash!(users(:quentin)) | ||
| 733 | |||
| 734 | get :trashed | ||
| 735 | assert_response :success | ||
| 736 | assert_select "a[href=?]", node_path(node) | ||
| 737 | end | ||
| 738 | |||
| 739 | test "trashed rows carry provenance and a delete for childless roots" do | ||
| 740 | login_as :quentin | ||
| 741 | node = Node.root.children.create!(:slug => "provenance_test") | ||
| 742 | node.trash!(users(:quentin)) | ||
| 743 | |||
| 744 | get :trashed | ||
| 745 | assert_select "td", /quentin/ | ||
| 746 | assert_select "form[action=?]", node_path(node), count: 1 | ||
| 747 | end | ||
| 748 | |||
| 749 | test "show annotates history rows with their lifecycle" do | ||
| 750 | login_as :quentin | ||
| 751 | node = Node.root.children.create!(:slug => "history_annotation_test") | ||
| 752 | Globalize.with_locale(I18n.default_locale) { node.draft.update!(:title => "Annotated") } | ||
| 753 | node.publish_draft!(users(:quentin)) | ||
| 754 | |||
| 755 | get :show, params: { :id => node.id } | ||
| 756 | |||
| 757 | assert_response :success | ||
| 758 | assert_select "span.revision_lifecycle", /quentin/ | ||
| 759 | end | ||
| 665 | end | 760 | end |
