diff options
| author | hukl <contact@smyck.org> | 2009-10-17 23:31:28 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-10-17 23:31:28 +0200 |
| commit | c7c4b007621fd28c88b65db5fd3296ef730097d9 (patch) | |
| tree | 6ccce73ace9fdecab09a2ae3b7eb6fd1b799b96b /test/functional | |
| parent | 07fc4a257f0f4c12a9dd9acd2e9926afb0d48c45 (diff) | |
added some more validations to ensure data integrity and applied necessary changes on tests
Diffstat (limited to 'test/functional')
| -rw-r--r-- | test/functional/content_controller_test.rb | 3 | ||||
| -rw-r--r-- | test/functional/nodes_controller_test.rb | 102 |
2 files changed, 78 insertions, 27 deletions
diff --git a/test/functional/content_controller_test.rb b/test/functional/content_controller_test.rb index b76e1d5..4fb3035 100644 --- a/test/functional/content_controller_test.rb +++ b/test/functional/content_controller_test.rb | |||
| @@ -94,8 +94,7 @@ class ContentControllerTest < ActionController::TestCase | |||
| 94 | protected | 94 | protected |
| 95 | 95 | ||
| 96 | def create_node_under_root slug | 96 | def create_node_under_root slug |
| 97 | node = Node.create! :slug => slug | 97 | node = Node.root.children.create! :slug => slug |
| 98 | node.move_to_child_of Node.root | ||
| 99 | node | 98 | node |
| 100 | end | 99 | end |
| 101 | 100 | ||
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb index eca7d93..f8d42da 100644 --- a/test/functional/nodes_controller_test.rb +++ b/test/functional/nodes_controller_test.rb | |||
| @@ -4,8 +4,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 4 | 4 | ||
| 5 | def test_get_index | 5 | def test_get_index |
| 6 | Node.root.descendants.delete_all | 6 | Node.root.descendants.delete_all |
| 7 | test_node = Node.create :slug => "foo" | 7 | test_node = Node.root.children.create :slug => "foo" |
| 8 | test_node.move_to_child_of Node.root | ||
| 9 | login_as :quentin | 8 | login_as :quentin |
| 10 | get :index | 9 | get :index |
| 11 | assert_response :success | 10 | assert_response :success |
| @@ -111,9 +110,22 @@ class NodesControllerTest < ActionController::TestCase | |||
| 111 | assert_equal "World", node.find_or_create_draft( User.first ).body | 110 | assert_equal "World", node.find_or_create_draft( User.first ).body |
| 112 | end | 111 | end |
| 113 | 112 | ||
| 113 | test "editing a locked node raises LockedByAnotherUser Exception" do | ||
| 114 | login_as :quentin | ||
| 115 | |||
| 116 | node = create_node_with_draft | ||
| 117 | node.lock_owner = User.last | ||
| 118 | node.save | ||
| 119 | |||
| 120 | assert node.locked? | ||
| 121 | |||
| 122 | get :edit, :id => node.id | ||
| 123 | assert_response :redirect | ||
| 124 | assert @response.flash[:error] =~ /Page is locked by another user/ | ||
| 125 | end | ||
| 126 | |||
| 114 | def test_update_a_draft | 127 | def test_update_a_draft |
| 115 | test_node = Node.create! :slug => "test_node" | 128 | test_node = Node.root.children.create! :slug => "test_node" |
| 116 | test_node.move_to_child_of Node.root | ||
| 117 | 129 | ||
| 118 | login_as :quentin | 130 | login_as :quentin |
| 119 | put :update, :id => test_node.id, :page => {:title => "Hello", :body => "There"} | 131 | put :update, :id => test_node.id, :page => {:title => "Hello", :body => "There"} |
| @@ -123,8 +135,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 123 | end | 135 | end |
| 124 | 136 | ||
| 125 | def test_update_a_draft_with_changing_the_template | 137 | def test_update_a_draft_with_changing_the_template |
| 126 | test_node = Node.create! :slug => "test_node" | 138 | test_node = Node.root.children.create! :slug => "test_node" |
| 127 | test_node.move_to_child_of Node.root | ||
| 128 | 139 | ||
| 129 | login_as :quentin | 140 | login_as :quentin |
| 130 | put :update, { | 141 | put :update, { |
| @@ -146,8 +157,7 @@ class NodesControllerTest < ActionController::TestCase | |||
| 146 | test "publish draft with staged_slug unqueal slug" do | 157 | test "publish draft with staged_slug unqueal slug" do |
| 147 | login_as :quentin | 158 | login_as :quentin |
| 148 | 159 | ||
| 149 | test_node = Node.create! :slug => "test_node", :staged_slug => "peter_pan" | 160 | test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" |
| 150 | test_node.move_to_child_of Node.root | ||
| 151 | 161 | ||
| 152 | put :publish, :id => test_node.id | 162 | put :publish, :id => test_node.id |
| 153 | 163 | ||
| @@ -159,10 +169,8 @@ class NodesControllerTest < ActionController::TestCase | |||
| 159 | test "publish draft with staged_slug with more levels of nodes" do | 169 | test "publish draft with staged_slug with more levels of nodes" do |
| 160 | login_as :quentin | 170 | login_as :quentin |
| 161 | 171 | ||
| 162 | test_node = Node.create! :slug => "test_node", :staged_slug => "peter_pan" | 172 | test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan" |
| 163 | test_node.move_to_child_of Node.root | 173 | test_node2 = test_node.children.create! :slug => "test_node2" |
| 164 | test_node2 = Node.create! :slug => "test_node2" | ||
| 165 | test_node2.move_to_child_of test_node | ||
| 166 | 174 | ||
| 167 | put :publish, :id => test_node.id | 175 | put :publish, :id => test_node.id |
| 168 | 176 | ||
| @@ -174,13 +182,10 @@ class NodesControllerTest < ActionController::TestCase | |||
| 174 | test "publish draft with staged_parent_id" do | 182 | test "publish draft with staged_parent_id" do |
| 175 | login_as :quentin | 183 | login_as :quentin |
| 176 | 184 | ||
| 177 | parent = Node.create! :slug => "parent" | 185 | parent = Node.root.children.create! :slug => "parent" |
| 178 | parent.move_to_child_of Node.root | 186 | test_node = Node.root.children.create! :slug => "test_node", :staged_parent_id => parent.id |
| 179 | test_node = Node.create! :slug => "test_node", :staged_parent_id => parent.id | 187 | test_node2 = test_node.children.create! :slug => "test_node2" |
| 180 | test_node.move_to_child_of Node.root | 188 | |
| 181 | test_node2 = Node.create! :slug => "test_node2" | ||
| 182 | test_node2.move_to_child_of test_node | ||
| 183 | |||
| 184 | put :publish, :id => test_node.id | 189 | put :publish, :id => test_node.id |
| 185 | 190 | ||
| 186 | test_node.reload; test_node2.reload | 191 | test_node.reload; test_node2.reload |
| @@ -191,18 +196,15 @@ class NodesControllerTest < ActionController::TestCase | |||
| 191 | test "publish draft with staged_parent_id and staged_slug" do | 196 | test "publish draft with staged_parent_id and staged_slug" do |
| 192 | login_as :quentin | 197 | login_as :quentin |
| 193 | 198 | ||
| 194 | parent = Node.create! :slug => "parent" | 199 | parent = Node.root.children.create! :slug => "parent" |
| 195 | parent.move_to_child_of Node.root | ||
| 196 | 200 | ||
| 197 | test_node = Node.create!( | 201 | test_node = Node.root.children.create!( |
| 198 | :slug => "test_node", | 202 | :slug => "test_node", |
| 199 | :staged_parent_id => parent.id, | 203 | :staged_parent_id => parent.id, |
| 200 | :staged_slug => "peter_pan" | 204 | :staged_slug => "peter_pan" |
| 201 | ) | 205 | ) |
| 202 | test_node.move_to_child_of Node.root | ||
| 203 | 206 | ||
| 204 | test_node2 = Node.create! :slug => "test_node2" | 207 | test_node2 = test_node.children.create! :slug => "test_node2" |
| 205 | test_node2.move_to_child_of test_node | ||
| 206 | 208 | ||
| 207 | put :publish, :id => test_node.id | 209 | put :publish, :id => test_node.id |
| 208 | 210 | ||
| @@ -211,4 +213,54 @@ class NodesControllerTest < ActionController::TestCase | |||
| 211 | assert_equal "parent/peter_pan/test_node2", test_node2.unique_name | 213 | assert_equal "parent/peter_pan/test_node2", test_node2.unique_name |
| 212 | end | 214 | end |
| 213 | 215 | ||
| 216 | test "show node with empty draft" do | ||
| 217 | login_as :quentin | ||
| 218 | assert_not_nil node = create_node_with_draft | ||
| 219 | get :show, :id => node.id | ||
| 220 | assert_response :success | ||
| 221 | end | ||
| 222 | |||
| 223 | test "show node with published draft" do | ||
| 224 | login_as :quentin | ||
| 225 | node = create_node_with_published_page | ||
| 226 | get :show, :id => node.id | ||
| 227 | assert_response :success | ||
| 228 | assert_select "td", :text => "Test", :count => 3 | ||
| 229 | end | ||
| 230 | |||
| 231 | test "unlocking a locked node" do | ||
| 232 | login_as :quentin | ||
| 233 | node = create_node_with_published_page | ||
| 234 | node.find_or_create_draft User.first | ||
| 235 | |||
| 236 | assert node.locked? | ||
| 237 | |||
| 238 | get :unlock, :id => node.id | ||
| 239 | assert_response :redirect | ||
| 240 | assert !node.reload.locked? | ||
| 241 | end | ||
| 242 | |||
| 243 | test "unlocking an already unlocked node" do | ||
| 244 | login_as :quentin | ||
| 245 | node = create_node_with_published_page | ||
| 246 | |||
| 247 | get :unlock, :id => node.id | ||
| 248 | assert_response :redirect | ||
| 249 | assert_equal "Already unlocked", @response.flash[:notice] | ||
| 250 | end | ||
| 251 | |||
| 252 | test "updating a node by changing its parent" do | ||
| 253 | Node.root.descendants.destroy_all | ||
| 254 | login_as :quentin | ||
| 255 | node = create_node_with_published_page | ||
| 256 | node.find_or_create_draft User.first | ||
| 257 | |||
| 258 | other_node = Node.root.children.create( :slug => "other" ) | ||
| 259 | |||
| 260 | node.staged_parent_id = other_node.id | ||
| 261 | node.publish_draft! | ||
| 262 | |||
| 263 | assert Node.valid? | ||
| 264 | |||
| 265 | end | ||
| 214 | end | 266 | end |
