summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-02-27 16:53:11 +0100
committerhukl <contact@smyck.org>2009-02-27 16:53:11 +0100
commit69a37065f9f523c25bc4edb9c70a9b21578d46f6 (patch)
tree550e750f9c48dee36f472fa1c8bae54e5bd95f17
parent463da8c96569f4ef9450f0eb75c7209f6a25b84b (diff)
more tests and fixes. always write tests - they are so good!
-rw-r--r--app/models/node.rb28
-rw-r--r--test/functional/content_controller_test.rb40
-rw-r--r--test/unit/page_test.rb4
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
65 end 65 end
66 66
67 def create_new_draft user 67 def create_new_draft user
68 p = self.pages.create! 68 page = self.pages.create!
69 69
70 p.tag_list = self.head.tag_list.join(", ") 70 if self.head
71 clone_attributes_to page
72 end
73
74 page.user = user
75 page.save
76 page.reload
77 page
78 end
79
80 def clone_attributes_to page
81 page.tag_list = self.head.tag_list.join(", ")
71 82
72 locale_before = I18n.locale 83 locale_before = I18n.locale
73 84
74 I18n.available_locales.each do |l| 85 I18n.available_locales.each do |l|
75 next if l == :root 86 next if l == :root
76 I18n.locale = l 87 I18n.locale = l
77 p.title = self.head.title 88 page.title = self.head.title
78 p.abstract = self.head.abstract 89 page.abstract = self.head.abstract
79 p.body = self.head.body 90 page.body = self.head.body
80 end 91 end
81 92
82 I18n.locale = locale_before 93 I18n.locale = locale_before
83 94
84 p.user = user 95 page
85 p.save
86 p.reload
87 p
88 end 96 end
89 97
90 def publish_draft! 98 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'
2 2
3class ContentControllerTest < ActionController::TestCase 3class ContentControllerTest < ActionController::TestCase
4 4
5 def setup
6 @root = Node.find(1)
7 @first_child = Node.find(2)
8 @second_child = Node.find(3)
9
10 @user1 = User.create :login => 'demo', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar'
11 @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar'
12 end
13
5 def test_custom_page_route 14 def test_custom_page_route
6 assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'de', :page_path => ['foo', 'bar'] }, '/de/foo/bar') 15 assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'de', :page_path => ['foo', 'bar'] }, '/de/foo/bar')
7 assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'en', :page_path => ['home'] }, '/en/home') 16 assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'en', :page_path => ['home'] }, '/en/home')
@@ -23,4 +32,35 @@ class ContentControllerTest < ActionController::TestCase
23 assert_response :success 32 assert_response :success
24 assert_equal "layouts/application", @response.layout 33 assert_equal "layouts/application", @response.layout
25 end 34 end
35
36 def test_page_containing_aggregator
37 assert_not_nil Node.root
38
39 d1 = @first_child.find_or_create_draft @user1
40 d1.title = "one"
41 d1.tag_list = "update"
42 d1.body = '<aggregate tags="update" limit="20" />'
43 d1.save
44 @first_child.publish_draft!
45
46 d2 = @second_child.find_or_create_draft @user1
47 d2.title = "two"
48 d2.tag_list = "update"
49 d2.save
50 @second_child.publish_draft!
51
52 get :render_page, :locale => 'de', :page_path => ["first_child"]
53 assert_response :success
54
55 assert_select("h2", "one")
56 assert_select("h2", "two")
57 end
58
59
60
61 protected
62
63 def create_update
64
65 end
26end 66end
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
14 n1.move_to_child_of Node.root 14 n1.move_to_child_of Node.root
15 n2.move_to_child_of Node.root 15 n2.move_to_child_of Node.root
16 16
17 # get the drafts created_with 17 # get the drafts and assign a user to it
18 assert_not_nil d1 = n1.find_or_create_draft( @user1 ) 18 assert_not_nil d1 = n1.find_or_create_draft( @user1 )
19 assert_not_nil d3 = n2.find_or_create_draft( @user1 ) 19 assert_not_nil d3 = n2.find_or_create_draft( @user1 )
20 20
21 # tag and double publish so we have 4 pages tagged with "update"
21 d1.tag_list = "update" 22 d1.tag_list = "update"
22 d1.save 23 d1.save
23 n1.publish_draft! 24 n1.publish_draft!
@@ -33,6 +34,7 @@ class PageTest < ActiveSupport::TestCase
33 d4 = n2.find_or_create_draft @user1 34 d4 = n2.find_or_create_draft @user1
34 n2.publish_draft! 35 n2.publish_draft!
35 36
37 # Set up two options hashes for the assertions
36 options1 = { 38 options1 = {
37 :tags => "update" 39 :tags => "update"
38 } 40 }