##// END OF EJS Templates
Resourcified boards....
Jean-Philippe Lang -
r7900:2967023a0e4d
parent child
Show More
@@ -62,23 +62,34 class BoardsController < ApplicationController
62 62 end
63 63 end
64 64
65 verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
66
67 65 def new
68 @board = Board.new(params[:board])
69 @board.project = @project
70 if request.post? && @board.save
66 @board = @project.boards.build(params[:board])
67 end
68
69 verify :method => :post, :only => :create, :redirect_to => { :action => :index }
70 def create
71 @board = @project.boards.build(params[:board])
72 if @board.save
71 73 flash[:notice] = l(:notice_successful_create)
72 74 redirect_to_settings_in_projects
75 else
76 render :action => 'new'
73 77 end
74 78 end
75 79
76 80 def edit
77 if request.post? && @board.update_attributes(params[:board])
81 end
82
83 verify :method => :put, :only => :update, :redirect_to => { :action => :index }
84 def update
85 if @board.update_attributes(params[:board])
78 86 redirect_to_settings_in_projects
87 else
88 render :action => 'edit'
79 89 end
80 90 end
81 91
92 verify :method => :delete, :only => :destroy, :redirect_to => { :action => :index }
82 93 def destroy
83 94 @board.destroy
84 95 redirect_to_settings_in_projects
@@ -1,8 +1,6
1 <%= error_messages_for 'board' %>
1 <%= f.error_messages %>
2 2
3 <!--[form:board]-->
4 <div class="box">
3 <div class="box tabular">
5 4 <p><%= f.text_field :name, :required => true %></p>
6 5 <p><%= f.text_field :description, :required => true, :size => 80 %></p>
7 6 </div>
8 <!--[eoform:board]-->
@@ -1,6 +1,6
1 1 <h2><%= l(:label_board) %></h2>
2 2
3 <% labelled_tabular_form_for :board, @board, :url => {:action => 'edit', :id => @board} do |f| %>
3 <% labelled_form_for @board, :url => project_board_path(@project, @board) do |f| %>
4 4 <%= render :partial => 'form', :locals => {:f => f} %>
5 5 <%= submit_tag l(:button_save) %>
6 6 <% end %>
@@ -1,6 +1,6
1 1 <h2><%= l(:label_board_new) %></h2>
2 2
3 <% labelled_tabular_form_for :board, @board, :url => {:action => 'new'} do |f| %>
3 <% labelled_form_for @board, :url => project_boards_path(@project) do |f| %>
4 4 <%= render :partial => 'form', :locals => {:f => f} %>
5 5 <%= submit_tag l(:button_create) %>
6 6 <% end %>
@@ -1,4 +1,4
1 <%= breadcrumb link_to(l(:label_board_plural), {:controller => 'boards', :action => 'index', :project_id => @project}) %>
1 <%= breadcrumb link_to(l(:label_board_plural), project_boards_path(@project)) %>
2 2
3 3 <div class="contextual">
4 4 <%= link_to_if_authorized l(:label_message_new),
@@ -1,5 +1,5
1 <%= breadcrumb link_to(l(:label_board_plural), {:controller => 'boards', :action => 'index', :project_id => @project}),
2 link_to(h(@board.name), {:controller => 'boards', :action => 'show', :project_id => @project, :id => @board}) %>
1 <%= breadcrumb link_to(l(:label_board_plural), project_boards_path(@project)),
2 link_to(h(@board.name), project_board_path(@project, @board)) %>
3 3
4 4 <div class="contextual">
5 5 <%= watcher_tag(@topic, User.current) %>
@@ -14,12 +14,14
14 14 <td><%=h board.description %></td>
15 15 <td align="center">
16 16 <% if authorize_for("boards", "edit") %>
17 <%= reorder_links('board', {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}) %>
17 <%= reorder_links('board', {:controller => 'boards', :action => 'update', :project_id => @project, :id => board}, :put) %>
18 18 <% end %>
19 19 </td>
20 20 <td class="buttons">
21 <%= link_to_if_authorized l(:button_edit), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}, :class => 'icon icon-edit' %>
22 <%= link_to_if_authorized l(:button_delete), {:controller => 'boards', :action => 'destroy', :project_id => @project, :id => board}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
21 <% if User.current.allowed_to?(:manage_boards, @project) %>
22 <%= link_to l(:button_edit), edit_project_board_path(@project, board), :class => 'icon icon-edit' %>
23 <%= link_to l(:button_delete), project_board_path(@project, board), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %>
24 <% end %>
23 25 </td>
24 26 </tr>
25 27 <% end %>
@@ -29,4 +31,6
29 31 <p class="nodata"><%= l(:label_no_data) %></p>
30 32 <% end %>
31 33
32 <p><%= link_to_if_authorized l(:label_board_new), {:controller => 'boards', :action => 'new', :project_id => @project}, :class => 'icon icon-add' %></p>
34 <% if User.current.allowed_to?(:manage_boards, @project) %>
35 <p><%= link_to l(:label_board_new), new_project_board_path(@project), :class => 'icon icon-add' %></p>
36 <% end %>
@@ -49,20 +49,6 ActionController::Routing::Routes.draw do |map|
49 49 end
50 50 end
51 51
52 map.with_options :controller => 'boards' do |board_routes|
53 board_routes.with_options :conditions => {:method => :get} do |board_views|
54 board_views.connect 'projects/:project_id/boards', :action => 'index'
55 board_views.connect 'projects/:project_id/boards/new', :action => 'new'
56 board_views.connect 'projects/:project_id/boards/:id', :action => 'show'
57 board_views.connect 'projects/:project_id/boards/:id.:format', :action => 'show'
58 board_views.connect 'projects/:project_id/boards/:id/edit', :action => 'edit'
59 end
60 board_routes.with_options :conditions => {:method => :post} do |board_actions|
61 board_actions.connect 'projects/:project_id/boards', :action => 'new'
62 board_actions.connect 'projects/:project_id/boards/:id/:action', :action => /edit|destroy/
63 end
64 end
65
66 52 map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
67 53 map.resources :queries, :except => [:show]
68 54
@@ -141,6 +127,7 ActionController::Routing::Routes.draw do |map|
141 127 project.resources :queries, :only => [:new, :create]
142 128 project.resources :issue_categories, :shallow => true
143 129 project.resources :documents, :shallow => true, :member => {:add_attachment => :post}
130 project.resources :boards
144 131
145 132 project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
146 133 project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
@@ -212,7 +199,6 ActionController::Routing::Routes.draw do |map|
212 199 map.resources :issue_statuses, :except => :show, :collection => {:update_issue_done_ratio => :post}
213 200
214 201 #left old routes at the bottom for backwards compat
215 map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
216 202 map.connect 'boards/:board_id/topics/:action/:id', :controller => 'messages'
217 203 map.connect 'wiki/:id/:page/:action', :page => nil, :controller => 'wiki'
218 204 map.connect 'projects/:project_id/news/:action', :controller => 'news'
@@ -131,7 +131,7 Redmine::AccessControl.map do |map|
131 131 end
132 132
133 133 map.project_module :boards do |map|
134 map.permission :manage_boards, {:boards => [:new, :edit, :destroy]}, :require => :member
134 map.permission :manage_boards, {:boards => [:new, :create, :edit, :update, :destroy]}, :require => :member
135 135 map.permission :view_messages, {:boards => [:index, :show], :messages => [:show]}, :public => true
136 136 map.permission :add_messages, {:messages => [:new, :reply, :quote]}
137 137 map.permission :edit_messages, {:messages => :edit}, :require => :member
@@ -16,18 +16,11
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'boards_controller'
20
21 # Re-raise errors caught by the controller.
22 class BoardsController; def rescue_action(e) raise e end; end
23 19
24 20 class BoardsControllerTest < ActionController::TestCase
25 21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
26 22
27 23 def setup
28 @controller = BoardsController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 24 User.current = nil
32 25 end
33 26
@@ -53,14 +46,6 class BoardsControllerTest < ActionController::TestCase
53 46 assert_not_nil assigns(:topics)
54 47 end
55 48
56 def test_post_new
57 @request.session[:user_id] = 2
58 assert_difference 'Board.count' do
59 post :new, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
60 end
61 assert_redirected_to '/projects/ecookbook/settings/boards'
62 end
63
64 49 def test_show
65 50 get :show, :project_id => 1, :id => 1
66 51 assert_response :success
@@ -79,19 +64,65 class BoardsControllerTest < ActionController::TestCase
79 64 assert_not_nil assigns(:messages)
80 65 end
81 66
82 def test_post_edit
67 def test_show_not_found
68 get :index, :project_id => 1, :id => 97
69 assert_response 404
70 end
71
72 def test_new
73 @request.session[:user_id] = 2
74 get :new, :project_id => 1
75 assert_response :success
76 assert_template 'new'
77 end
78
79 def test_create
80 @request.session[:user_id] = 2
81 assert_difference 'Board.count' do
82 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
83 end
84 assert_redirected_to '/projects/ecookbook/settings/boards'
85 board = Board.first(:order => 'id DESC')
86 assert_equal 'Testing', board.name
87 assert_equal 'Testing board creation', board.description
88 end
89
90 def test_create_with_failure
83 91 @request.session[:user_id] = 2
84 92 assert_no_difference 'Board.count' do
85 post :edit, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
93 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
94 end
95 assert_response :success
96 assert_template 'new'
97 end
98
99 def test_edit
100 @request.session[:user_id] = 2
101 get :edit, :project_id => 1, :id => 2
102 assert_response :success
103 assert_template 'edit'
104 end
105
106 def test_update
107 @request.session[:user_id] = 2
108 assert_no_difference 'Board.count' do
109 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
86 110 end
87 111 assert_redirected_to '/projects/ecookbook/settings/boards'
88 112 assert_equal 'Testing', Board.find(2).name
89 113 end
90 114
91 def test_post_destroy
115 def test_update_with_failure
116 @request.session[:user_id] = 2
117 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
118 assert_response :success
119 assert_template 'edit'
120 end
121
122 def test_destroy
92 123 @request.session[:user_id] = 2
93 124 assert_difference 'Board.count', -1 do
94 post :destroy, :project_id => 1, :id => 2
125 delete :destroy, :project_id => 1, :id => 2
95 126 end
96 127 assert_redirected_to '/projects/ecookbook/settings/boards'
97 128 assert_nil Board.find_by_id(2)
@@ -39,9 +39,9 class RoutingTest < ActionController::IntegrationTest
39 39 should_route :get, "/projects/world_domination/boards/44.atom", :controller => 'boards', :action => 'show', :project_id => 'world_domination', :id => '44', :format => 'atom'
40 40 should_route :get, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
41 41
42 should_route :post, "/projects/world_domination/boards/new", :controller => 'boards', :action => 'new', :project_id => 'world_domination'
43 should_route :post, "/projects/world_domination/boards/44/edit", :controller => 'boards', :action => 'edit', :project_id => 'world_domination', :id => '44'
44 should_route :post, "/projects/world_domination/boards/44/destroy", :controller => 'boards', :action => 'destroy', :project_id => 'world_domination', :id => '44'
42 should_route :post, "/projects/world_domination/boards", :controller => 'boards', :action => 'create', :project_id => 'world_domination'
43 should_route :put, "/projects/world_domination/boards/44", :controller => 'boards', :action => 'update', :project_id => 'world_domination', :id => '44'
44 should_route :delete, "/projects/world_domination/boards/44", :controller => 'boards', :action => 'destroy', :project_id => 'world_domination', :id => '44'
45 45
46 46 end
47 47
General Comments 0
You need to be logged in to leave comments. Login now