From 69a37065f9f523c25bc4edb9c70a9b21578d46f6 Mon Sep 17 00:00:00 2001 From: hukl Date: Fri, 27 Feb 2009 16:53:11 +0100 Subject: more tests and fixes. always write tests - they are so good! --- app/models/node.rb | 28 +++++++++++++-------- test/functional/content_controller_test.rb | 40 ++++++++++++++++++++++++++++++ test/unit/page_test.rb | 4 ++- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/app/models/node.rb b/app/models/node.rb index 33c82c9..e2cb564 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -65,26 +65,34 @@ class Node < ActiveRecord::Base end def create_new_draft user - p = self.pages.create! + page = self.pages.create! - p.tag_list = self.head.tag_list.join(", ") + if self.head + clone_attributes_to page + end + + page.user = user + page.save + page.reload + page + end + + def clone_attributes_to page + page.tag_list = self.head.tag_list.join(", ") locale_before = I18n.locale I18n.available_locales.each do |l| next if l == :root I18n.locale = l - p.title = self.head.title - p.abstract = self.head.abstract - p.body = self.head.body + page.title = self.head.title + page.abstract = self.head.abstract + page.body = self.head.body end I18n.locale = locale_before - - p.user = user - p.save - p.reload - p + + page end def publish_draft! diff --git a/test/functional/content_controller_test.rb b/test/functional/content_controller_test.rb index d64de60..2e0ee0e 100644 --- a/test/functional/content_controller_test.rb +++ b/test/functional/content_controller_test.rb @@ -2,6 +2,15 @@ require 'test_helper' class ContentControllerTest < ActionController::TestCase + def setup + @root = Node.find(1) + @first_child = Node.find(2) + @second_child = Node.find(3) + + @user1 = User.create :login => 'demo', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' + @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar' + end + def test_custom_page_route assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'de', :page_path => ['foo', 'bar'] }, '/de/foo/bar') assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'en', :page_path => ['home'] }, '/en/home') @@ -23,4 +32,35 @@ class ContentControllerTest < ActionController::TestCase assert_response :success assert_equal "layouts/application", @response.layout end + + def test_page_containing_aggregator + assert_not_nil Node.root + + d1 = @first_child.find_or_create_draft @user1 + d1.title = "one" + d1.tag_list = "update" + d1.body = '' + d1.save + @first_child.publish_draft! + + d2 = @second_child.find_or_create_draft @user1 + d2.title = "two" + d2.tag_list = "update" + d2.save + @second_child.publish_draft! + + get :render_page, :locale => 'de', :page_path => ["first_child"] + assert_response :success + + assert_select("h2", "one") + assert_select("h2", "two") + end + + + + protected + + def create_update + + end end diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb index bf4bca1..21b8910 100644 --- a/test/unit/page_test.rb +++ b/test/unit/page_test.rb @@ -14,10 +14,11 @@ class PageTest < ActiveSupport::TestCase n1.move_to_child_of Node.root n2.move_to_child_of Node.root - # get the drafts created_with + # get the drafts and assign a user to it assert_not_nil d1 = n1.find_or_create_draft( @user1 ) assert_not_nil d3 = n2.find_or_create_draft( @user1 ) + # tag and double publish so we have 4 pages tagged with "update" d1.tag_list = "update" d1.save n1.publish_draft! @@ -33,6 +34,7 @@ class PageTest < ActiveSupport::TestCase d4 = n2.find_or_create_draft @user1 n2.publish_draft! + # Set up two options hashes for the assertions options1 = { :tags => "update" } -- cgit v1.3