From 262f4e0c2abfefbd6965358fdfd9a8c332a38d57 Mon Sep 17 00:00:00 2001 From: hukl Date: Wed, 7 Oct 2009 23:36:03 +0200 Subject: refactored revsions controller to act as a nested resource of nodes. boy that cleaned up some stuff quite a bit. also having tests for that is just feeling great --- test/functional/nodes_controller_test.rb | 2 +- test/functional/revisions_controller_test.rb | 59 ++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) (limited to 'test/functional') diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index 3dae9db..eca7d93 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb @@ -84,7 +84,7 @@ class NodesControllerTest < ActionController::TestCase end end - def test_editing_a_node + test "editing a node" do login_as :quentin node = Node.find_by_unique_name("fourth_child") diff --git a/test/functional/revisions_controller_test.rb b/test/functional/revisions_controller_test.rb index d752b0e..43001df 100644 --- a/test/functional/revisions_controller_test.rb +++ b/test/functional/revisions_controller_test.rb @@ -1,8 +1,61 @@ require 'test_helper' class RevisionsControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true + + def setup + Node.root.descendants.destroy_all + @user = User.find_by_login("aaron") + @node = Node.root.children.create!( :slug => "version_me" ) + + draft = @node.draft + draft.body = "first" + @node.publish_draft! + @node.find_or_create_draft @user + draft = @node.draft + draft.update_attributes(:body => "second") + @node.publish_draft! + end + + test "setup" do + assert_equal 2, Node.count + assert_equal 2, @node.pages.count + assert_equal ["first", "second"], @node.pages.map {|p| p.body} + end + + test "get list of revisions for a given node" do + login_as :quentin + get :index, :node_id => @node.id + assert_response :success + assert_select ".revision", 2 + end + + test "showing one revision" do + login_as :quentin + get :show, :node_id => @node.id, :id => @node.pages.last.id + assert_response :success + assert_select "strong", "Body" + assert_select "td", {:count => 1, :text => "second"} + end + + test "diffing two revisions" do + login_as :quentin + post( + :diff, + :node_id => @node.id, + :start_revision => @node.pages.first.revision, + :end_revision => @node.pages.last.revision + ) + assert_response :success + end + + test "restoring a revision" do + assert_equal "second", @node.head.body + + login_as :aaron + put( :restore, :node_id => @node.id, :id => @node.pages.first.id ) + + @node.reload + assert_equal @node.head, @node.pages.first + assert_equal "first", @node.head.reload.body end end -- cgit v1.3