summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-10-17 23:31:28 +0200
committerhukl <contact@smyck.org>2009-10-17 23:31:28 +0200
commitc7c4b007621fd28c88b65db5fd3296ef730097d9 (patch)
tree6ccce73ace9fdecab09a2ae3b7eb6fd1b799b96b /test/unit
parent07fc4a257f0f4c12a9dd9acd2e9926afb0d48c45 (diff)
added some more validations to ensure data integrity and applied necessary changes on tests
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/event_test.rb3
-rw-r--r--test/unit/node_test.rb59
-rw-r--r--test/unit/page_test.rb15
3 files changed, 23 insertions, 54 deletions
diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb
index 78e082c..f310af8 100644
--- a/test/unit/event_test.rb
+++ b/test/unit/event_test.rb
@@ -4,8 +4,7 @@ class EventTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 Page.delete_all 6 Page.delete_all
7 @cal_node = Node.create :slug => "calendar" 7 @cal_node = Node.root.children.create! :slug => "calendar"
8 @cal_node.move_to_child_of Node.root
9 @draft = @cal_node.find_or_create_draft User.first 8 @draft = @cal_node.find_or_create_draft User.first
10 @draft.title = "99C3" 9 @draft.title = "99C3"
11 @draft.abstract = "The 99th Chaos Comunication Congress" 10 @draft.abstract = "The 99th Chaos Comunication Congress"
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb
index ee4d71f..92870aa 100644
--- a/test/unit/node_test.rb
+++ b/test/unit/node_test.rb
@@ -16,8 +16,7 @@ class NodeTest < ActiveSupport::TestCase
16 end 16 end
17 17
18 def test_returning_existing_drafts 18 def test_returning_existing_drafts
19 test_node = Node.create! :slug => "test_node" 19 test_node = Node.root.children.create! :slug => "test_node"
20 test_node.move_to_child_of Node.root
21 20
22 assert_not_nil test_node.draft 21 assert_not_nil test_node.draft
23 assert_equal 1, test_node.pages.length 22 assert_equal 1, test_node.pages.length
@@ -39,10 +38,7 @@ class NodeTest < ActiveSupport::TestCase
39 38
40 def test_unique_path_returns_an_array 39 def test_unique_path_returns_an_array
41 assert_equal ["first_child"], @first_child.unique_path 40 assert_equal ["first_child"], @first_child.unique_path
42 41 new_node = @first_child.children.create! :slug => "third_child"
43 new_node = Node.create! :slug => "third_child"
44 new_node.move_to_child_of @first_child
45
46 assert_equal ["first_child", "third_child"], new_node.unique_path 42 assert_equal ["first_child", "third_child"], new_node.unique_path
47 end 43 end
48 44
@@ -87,8 +83,7 @@ class NodeTest < ActiveSupport::TestCase
87 end 83 end
88 84
89 def test_created_nodes_have_an_empty_draft_and_no_head 85 def test_created_nodes_have_an_empty_draft_and_no_head
90 node = Node.create :slug => "third_child" 86 node = Node.root.children.create! :slug => "third_child_beta"
91 node.move_to_child_of @root
92 87
93 assert !node.pages.empty? 88 assert !node.pages.empty?
94 assert_equal 1, node.pages.length 89 assert_equal 1, node.pages.length
@@ -98,23 +93,18 @@ class NodeTest < ActiveSupport::TestCase
98 end 93 end
99 94
100 def test_create_new_draft_of_published_page 95 def test_create_new_draft_of_published_page
101 node = Node.create :slug => "xyz" 96 node = Node.root.children.create :slug => "xyz"
102 node.move_to_child_of @root
103
104 assert node.publish_draft! 97 assert node.publish_draft!
105 end 98 end
106 99
107 def test_find_or_create_draft_if_no_draft_exists 100 def test_find_or_create_draft_if_no_draft_exists
108 node = Node.create :slug => "xyz" 101 node = Node.root.children.create :slug => "xyz"
109 node.move_to_child_of @root
110 node.publish_draft! 102 node.publish_draft!
111
112 assert_not_nil node.find_or_create_draft( @user1 ) 103 assert_not_nil node.find_or_create_draft( @user1 )
113 end 104 end
114 105
115 def test_find_or_create_draft_if_draft_exists_and_is_owned_by_user 106 def test_find_or_create_draft_if_draft_exists_and_is_owned_by_user
116 node = Node.create :slug => "xyz" 107 node = Node.root.children.create :slug => "xyz"
117 node.move_to_child_of @root
118 node.publish_draft! 108 node.publish_draft!
119 109
120 node.find_or_create_draft @user1 110 node.find_or_create_draft @user1
@@ -122,8 +112,7 @@ class NodeTest < ActiveSupport::TestCase
122 end 112 end
123 113
124 def test_exception_if_draft_exists_but_locked_by_another_user 114 def test_exception_if_draft_exists_but_locked_by_another_user
125 node = Node.create :slug => "xyz" 115 node = Node.root.children.create :slug => "xyz"
126 node.move_to_child_of @root
127 node.publish_draft! 116 node.publish_draft!
128 node.find_or_create_draft @user1 117 node.find_or_create_draft @user1
129 assert_equal @user1, node.lock_owner 118 assert_equal @user1, node.lock_owner
@@ -133,13 +122,11 @@ class NodeTest < ActiveSupport::TestCase
133 end 122 end
134 123
135 def test_creation_of_unique_name 124 def test_creation_of_unique_name
136 node = Node.create :slug => 'child' 125 node = Node.root.children.create :slug => 'child'
137 node.move_to_child_of @root
138 node.reload 126 node.reload
139 assert_equal 'child', node.unique_name 127 assert_equal 'child', node.unique_name
140 128
141 node = Node.create :slug => 'deep_child' 129 node = @first_child.children.create :slug => 'deep_child'
142 node.move_to_child_of @first_child
143 node.reload 130 node.reload
144 assert_equal 'first_child/deep_child', node.unique_name 131 assert_equal 'first_child/deep_child', node.unique_name
145 end 132 end
@@ -177,14 +164,9 @@ class NodeTest < ActiveSupport::TestCase
177 end 164 end
178 165
179 def test_retrieving_page_current 166 def test_retrieving_page_current
180 updates = Node.create(:slug => 'updates') 167 updates = Node.root.children.create(:slug => 'updates')
181 updates.move_to_child_of @root 168 year = updates.children.create(:slug => '2008')
182 169 foo = year.children.create(:slug => 'foo')
183 year = Node.create(:slug => '2008')
184 year.move_to_child_of updates
185
186 foo = Node.create(:slug => 'foo')
187 foo.move_to_child_of year
188 170
189 assert_not_nil Node.find_by_unique_name('updates/2008/foo') 171 assert_not_nil Node.find_by_unique_name('updates/2008/foo')
190 172
@@ -201,14 +183,9 @@ class NodeTest < ActiveSupport::TestCase
201 end 183 end
202 184
203 def test_retrieving_page_by_revision 185 def test_retrieving_page_by_revision
204 updates = Node.create(:slug => 'updates') 186 updates = Node.root.children.create(:slug => 'updates')
205 updates.move_to_child_of @root 187 year = updates.children.create(:slug => '2008')
206 188 foo = year.children.create(:slug => 'foo')
207 year = Node.create(:slug => '2008')
208 year.move_to_child_of updates
209
210 foo = Node.create(:slug => 'foo')
211 foo.move_to_child_of year
212 189
213 assert_not_nil Node.find_by_unique_name('updates/2008/foo') 190 assert_not_nil Node.find_by_unique_name('updates/2008/foo')
214 191
@@ -224,8 +201,7 @@ class NodeTest < ActiveSupport::TestCase
224 # Thats a lengthy test to make sure everything works as it should, it was 201 # Thats a lengthy test to make sure everything works as it should, it was
225 # created during a bug hunt 202 # created during a bug hunt
226 def test_creating_new_draft 203 def test_creating_new_draft
227 test_node = Node.create! :slug => "test_node" 204 test_node = Node.root.children.create! :slug => "test_node"
228 test_node.move_to_child_of Node.root
229 test_node.draft.user = @user1 205 test_node.draft.user = @user1
230 test_node.save 206 test_node.save
231 assert test_node.publish_draft! 207 assert test_node.publish_draft!
@@ -241,8 +217,7 @@ class NodeTest < ActiveSupport::TestCase
241 end 217 end
242 218
243 test "restoring a revision" do 219 test "restoring a revision" do
244 test_node = Node.create! :slug => "test_node" 220 test_node = Node.root.children.create! :slug => "test_node"
245 test_node.move_to_child_of Node.root
246 create_revisions( test_node, 3 ) 221 create_revisions( test_node, 3 )
247 test_node.find_or_create_draft @user1 222 test_node.find_or_create_draft @user1
248 test_node.reload 223 test_node.reload
diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb
index a2083c0..c2599e3 100644
--- a/test/unit/page_test.rb
+++ b/test/unit/page_test.rb
@@ -9,10 +9,8 @@ class PageTest < ActiveSupport::TestCase
9 9
10 def test_aggregation 10 def test_aggregation
11 # Create two nodes and move them beneath the root node 11 # Create two nodes and move them beneath the root node
12 n1 = Node.create! :slug => "one" 12 n1 = Node.root.children.create! :slug => "one"
13 n2 = Node.create! :slug => "two" 13 n2 = Node.root.children.create! :slug => "two"
14 n1.move_to_child_of Node.root
15 n2.move_to_child_of Node.root
16 14
17 # get the drafts and assign a user to it 15 # get the drafts and assign a user to it
18 assert_not_nil d1 = n1.find_or_create_draft( @user1 ) 16 assert_not_nil d1 = n1.find_or_create_draft( @user1 )
@@ -50,8 +48,7 @@ class PageTest < ActiveSupport::TestCase
50 end 48 end
51 49
52 def test_before_save_rewrite_links_in_body 50 def test_before_save_rewrite_links_in_body
53 n = Node.create :slug => "link_test" 51 n = Node.root.children.create :slug => "link_test"
54 n.move_to_child_of Node.root
55 d = n.find_or_create_draft @user1 52 d = n.find_or_create_draft @user1
56 53
57 before = "<h1>Hello World</h1>\n" \ 54 before = "<h1>Hello World</h1>\n" \
@@ -69,8 +66,7 @@ class PageTest < ActiveSupport::TestCase
69 end 66 end
70 67
71 def test_before_save_rewrite_links_in_body_if_no_locale_prefix_present 68 def test_before_save_rewrite_links_in_body_if_no_locale_prefix_present
72 n = Node.create :slug => "link_test" 69 n = Node.root.children.create :slug => "link_test"
73 n.move_to_child_of Node.root
74 d = n.find_or_create_draft @user1 70 d = n.find_or_create_draft @user1
75 71
76 before = "<h1>Hello World</h1>\n" \ 72 before = "<h1>Hello World</h1>\n" \
@@ -88,8 +84,7 @@ class PageTest < ActiveSupport::TestCase
88 end 84 end
89 85
90 def test_before_save_rewrite_links_skips_on_external_links 86 def test_before_save_rewrite_links_skips_on_external_links
91 n = Node.create :slug => "link_test" 87 n = Node.root.children.create :slug => "link_test"
92 n.move_to_child_of Node.root
93 d = n.find_or_create_draft @user1 88 d = n.find_or_create_draft @user1
94 89
95 before = "<h1>Hello World</h1>\n" \ 90 before = "<h1>Hello World</h1>\n" \