summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/nodes_controller.rb17
-rw-r--r--app/views/nodes/index.html.erb3
-rw-r--r--config/routes.rb2
-rw-r--r--public/stylesheets/admin.css10
-rw-r--r--test/fixtures/nodes.yml13
-rw-r--r--test/fixtures/pages.yml7
-rw-r--r--test/functional/nodes_controller_test.rb22
7 files changed, 65 insertions, 9 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb
index a403b95..81ead62 100644
--- a/app/controllers/nodes_controller.rb
+++ b/app/controllers/nodes_controller.rb
@@ -7,7 +7,8 @@ class NodesController < ApplicationController
7 :edit, 7 :edit,
8 :update, 8 :update,
9 :destroy, 9 :destroy,
10 :publish 10 :publish,
11 :unlock
11 ] 12 ]
12 13
13 def index 14 def index
@@ -67,6 +68,20 @@ class NodesController < ApplicationController
67 redirect_to node_path 68 redirect_to node_path
68 end 69 end
69 70
71 def unlock
72 # TODO that actually has to be implemented in the model, once we have
73 # permissions
74 if draft = @node.draft
75 draft.user = nil
76 draft.save
77 flash[:notice] = "Node unlocked"
78 else
79 flash[:notice] = "Cannot unlock"
80 end
81
82 redirect_to nodes_path
83 end
84
70 def move_to 85 def move_to
71 parent = Node.find params[:parent_id] 86 parent = Node.find params[:parent_id]
72 @node.move_to_child_of parent 87 @node.move_to_child_of parent
diff --git a/app/views/nodes/index.html.erb b/app/views/nodes/index.html.erb
index 1429d1a..833ffed 100644
--- a/app/views/nodes/index.html.erb
+++ b/app/views/nodes/index.html.erb
@@ -23,7 +23,8 @@
23 <td> 23 <td>
24 <%= link_to 'Show', node_path(node) %> 24 <%= link_to 'Show', node_path(node) %>
25 <%= link_to 'Edit', edit_node_path(node) %> 25 <%= link_to 'Edit', edit_node_path(node) %>
26 <%= link_to 'Destroy', node, :method => :delete %> 26 <%= link_to 'Destroy', node, :method => :delete, :confirm => "Are you sure you want to delete this node?" %>
27 <%= link_to 'Unlock', unlock_node_path(node), :method => :put, :confirm => "Are you sure you want to unlock?" %>
27 </td> 28 </td>
28 <td> 29 <td>
29 <%= "#{node.draft.user.login}" if node.draft && node.draft.user %> 30 <%= "#{node.draft.user.login}" if node.draft && node.draft.user %>
diff --git a/config/routes.rb b/config/routes.rb
index 5f2a9dc..4305a21 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -9,7 +9,7 @@ ActionController::Routing::Routes.draw do |map|
9 map.filter :locale 9 map.filter :locale
10 10
11 map.resources :pages 11 map.resources :pages
12 map.resources :nodes, :member => {:publish => :put} 12 map.resources :nodes, :member => {:publish => :put, :unlock => :put}
13 13
14 map.logout '/logout', :controller => 'sessions', :action => 'destroy' 14 map.logout '/logout', :controller => 'sessions', :action => 'destroy'
15 map.login '/login', :controller => 'sessions', :action => 'new' 15 map.login '/login', :controller => 'sessions', :action => 'new'
diff --git a/public/stylesheets/admin.css b/public/stylesheets/admin.css
index 0b7e630..5fe88f1 100644
--- a/public/stylesheets/admin.css
+++ b/public/stylesheets/admin.css
@@ -10,7 +10,7 @@ a {
10table {} 10table {}
11 11
12table#node_table { 12table#node_table {
13 width: 800px; 13 width: 1000px;
14} 14}
15 15
16tr.odd { 16tr.odd {
@@ -22,7 +22,7 @@ th {
22} 22}
23 23
24th.title { 24th.title {
25 width: 450px; 25 width: 400px;
26} 26}
27 27
28th.path { 28th.path {
@@ -30,7 +30,11 @@ th.path {
30} 30}
31 31
32th.actions { 32th.actions {
33 width: 150px; 33 width: 180px;
34}
35
36th.editor {
37 width: 120px;
34} 38}
35 39
36td { 40td {
diff --git a/test/fixtures/nodes.yml b/test/fixtures/nodes.yml
index 8574c1b..a0e185b 100644
--- a/test/fixtures/nodes.yml
+++ b/test/fixtures/nodes.yml
@@ -3,7 +3,7 @@
3root: 3root:
4 id: 1 4 id: 1
5 lft: 1 5 lft: 1
6 rgt: 8 6 rgt: 10
7 parent_id: 7 parent_id:
8 slug: 8 slug:
9 unique_name: 9 unique_name:
@@ -34,4 +34,13 @@ third_child:
34 parent_id: 1 34 parent_id: 1
35 draft_id: 102 35 draft_id: 102
36 slug: third_child 36 slug: third_child
37 unique_name: third_child \ No newline at end of file 37 unique_name: third_child
38
39fourth_child:
40 id: 5
41 lft: 8
42 rgt: 9
43 parent_id: 1
44 draft_id: 103
45 slug: fourth_child
46 unique_name: fourth_child \ No newline at end of file
diff --git a/test/fixtures/pages.yml b/test/fixtures/pages.yml
index 8171b38..271c494 100644
--- a/test/fixtures/pages.yml
+++ b/test/fixtures/pages.yml
@@ -23,4 +23,9 @@ draft2:
23draft3: 23draft3:
24 id: 102 24 id: 102
25 revision: 1 25 revision: 1
26 node_id: 4 \ No newline at end of file 26 node_id: 4
27
28draft4:
29 id: 103
30 revision: 1
31 node_id: 5 \ No newline at end of file
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb
index ed8afd8..afe7576 100644
--- a/test/functional/nodes_controller_test.rb
+++ b/test/functional/nodes_controller_test.rb
@@ -22,6 +22,28 @@ class NodesControllerTest < ActionController::TestCase
22 assert_redirected_to node_path(Node.last) 22 assert_redirected_to node_path(Node.last)
23 end 23 end
24 24
25 def test_editing_a_node
26 login_as :quentin
27
28 node = Node.find_by_unique_name("fourth_child")
29
30 assert_equal 1, node.pages.length
31
32 draft = node.find_or_create_draft( User.first )
33 draft.title = "Hello"
34 draft.body = "World"
35 draft.save
36 node.publish_draft!
37
38 get :edit, :id => node.id
39 assert_response :success
40
41 node.reload
42 assert_equal 2, node.pages.length
43 assert_equal "Hello", node.find_or_create_draft( User.first ).title
44 assert_equal "World", node.find_or_create_draft( User.first ).body
45 end
46
25 def test_update_a_draft 47 def test_update_a_draft
26 test_node = Node.create! :slug => "test_node" 48 test_node = Node.create! :slug => "test_node"
27 test_node.move_to_child_of Node.root 49 test_node.move_to_child_of Node.root