diff --git a/app/views/queries/edit.html.erb b/app/views/queries/edit.html.erb
index 1c99ac077..46a530f16 100644
--- a/app/views/queries/edit.html.erb
+++ b/app/views/queries/edit.html.erb
@@ -1,6 +1,6 @@
<%= l(:label_query) %>
-<% form_tag({:action => 'edit', :id => @query}, :onsubmit => 'selectAllOptions("selected_columns");') do %>
+<% form_tag(@query.project_id ? project_query_path(:project_id => @query.project, :id => @query) : query_path(@query), :onsubmit => 'selectAllOptions("selected_columns");', :method => :put) do %>
<%= render :partial => 'form', :locals => {:query => @query} %>
<%= submit_tag l(:button_save) %>
<% end %>
diff --git a/app/views/queries/index.html.erb b/app/views/queries/index.html.erb
index 066f30edb..b03ac6216 100644
--- a/app/views/queries/index.html.erb
+++ b/app/views/queries/index.html.erb
@@ -1,5 +1,5 @@
-<%= link_to_if_authorized l(:label_query_new), {:controller => 'queries', :action => 'new', :project_id => @project}, :class => 'icon icon-add' %>
+<%= link_to_if_authorized l(:label_query_new), new_project_query_path(:project_id => @project), :class => 'icon icon-add' %>
<%= l(:label_query_plural) %>
@@ -16,8 +16,8 @@
<% if query.editable_by?(User.current) %>
- <%= link_to l(:button_edit), {:controller => 'queries', :action => 'edit', :id => query}, :class => 'icon icon-edit' %>
- <%= link_to l(:button_delete), {:controller => 'queries', :action => 'destroy', :id => query}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
+ <%= link_to l(:button_edit), edit_query_path(query), :class => 'icon icon-edit' %>
+ <%= link_to l(:button_delete), query_path(query), :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %>
<% end %>
|
diff --git a/app/views/queries/new.html.erb b/app/views/queries/new.html.erb
index a980d04ab..b5809fb88 100644
--- a/app/views/queries/new.html.erb
+++ b/app/views/queries/new.html.erb
@@ -1,6 +1,6 @@
<%= l(:label_query_new) %>
-<% form_tag({:action => 'new', :project_id => @query.project}, :onsubmit => 'selectAllOptions("selected_columns");') do %>
+<% form_tag(@project ? project_queries_path(:project_id => @project) : queries_path, :onsubmit => 'selectAllOptions("selected_columns");') do %>
<%= render :partial => 'form', :locals => {:query => @query} %>
<%= submit_tag l(:button_save) %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index c07004e69..8f0f39e48 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -77,7 +77,7 @@ ActionController::Routing::Routes.draw do |map|
end
map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
- map.resources :queries, :only => [:index]
+ map.resources :queries, :except => [:show]
# Misc issue routes. TODO: move into resources
map.auto_complete_issues '/issues/auto_complete', :controller => 'auto_completes', :action => 'issues'
@@ -156,6 +156,7 @@ ActionController::Routing::Routes.draw do |map|
project.resources :versions, :shallow => true, :collection => {:close_completed => :put}, :member => {:status_by => :post}
project.resources :news, :shallow => true
project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
+ project.resources :queries, :except => [:show]
project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
@@ -226,7 +227,6 @@ ActionController::Routing::Routes.draw do |map|
map.resources :groups
#left old routes at the bottom for backwards compat
- map.connect 'projects/:project_id/queries/:action', :controller => 'queries'
map.connect 'projects/:project_id/issues/:action', :controller => 'issues'
map.connect 'projects/:project_id/documents/:action', :controller => 'documents'
map.connect 'projects/:project_id/boards/:action/:id', :controller => 'boards'
diff --git a/test/functional/queries_controller_test.rb b/test/functional/queries_controller_test.rb
index b40ea6e7c..dfa5d6153 100644
--- a/test/functional/queries_controller_test.rb
+++ b/test/functional/queries_controller_test.rb
@@ -60,9 +60,8 @@ class QueriesControllerTest < ActionController::TestCase
def test_new_project_public_query
@request.session[:user_id] = 2
- post :new,
+ post :create,
:project_id => 'ecookbook',
- :confirm => '1',
:default_columns => '1',
:f => ["status_id", "assigned_to_id"],
:op => {"assigned_to_id" => "=", "status_id" => "o"},
@@ -78,9 +77,8 @@ class QueriesControllerTest < ActionController::TestCase
def test_new_project_private_query
@request.session[:user_id] = 3
- post :new,
+ post :create,
:project_id => 'ecookbook',
- :confirm => '1',
:default_columns => '1',
:fields => ["status_id", "assigned_to_id"],
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
@@ -96,8 +94,7 @@ class QueriesControllerTest < ActionController::TestCase
def test_new_global_private_query_with_custom_columns
@request.session[:user_id] = 3
- post :new,
- :confirm => '1',
+ post :create,
:fields => ["status_id", "assigned_to_id"],
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
@@ -112,10 +109,24 @@ class QueriesControllerTest < ActionController::TestCase
assert q.valid?
end
+ def test_new_global_query_with_custom_filters
+ @request.session[:user_id] = 3
+ post :create,
+ :fields => ["assigned_to_id"],
+ :operators => {"assigned_to_id" => "="},
+ :values => { "assigned_to_id" => ["me"]},
+ :query => {"name" => "test_new_global_query"}
+
+ q = Query.find_by_name('test_new_global_query')
+ assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
+ assert !q.has_filter?(:status_id)
+ assert_equal ['assigned_to_id'], q.filters.keys
+ assert q.valid?
+ end
+
def test_new_with_sort
@request.session[:user_id] = 1
- post :new,
- :confirm => '1',
+ post :create,
:default_columns => '1',
:operators => {"status_id" => "o"},
:values => {"status_id" => ["1"]},
@@ -144,9 +155,8 @@ class QueriesControllerTest < ActionController::TestCase
def test_edit_global_public_query
@request.session[:user_id] = 1
- post :edit,
+ put :update,
:id => 4,
- :confirm => '1',
:default_columns => '1',
:fields => ["status_id", "assigned_to_id"],
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
@@ -175,9 +185,8 @@ class QueriesControllerTest < ActionController::TestCase
def test_edit_global_private_query
@request.session[:user_id] = 3
- post :edit,
+ put :update,
:id => 3,
- :confirm => '1',
:default_columns => '1',
:fields => ["status_id", "assigned_to_id"],
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
@@ -234,7 +243,7 @@ class QueriesControllerTest < ActionController::TestCase
def test_destroy
@request.session[:user_id] = 2
- post :destroy, :id => 1
+ delete :destroy, :id => 1
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil
assert_nil Query.find_by_id(1)
end
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index 4591db053..cfdc5389e 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -218,8 +218,17 @@ class RoutingTest < ActionController::IntegrationTest
should_route :get, "/queries/new", :controller => 'queries', :action => 'new'
should_route :get, "/projects/redmine/queries/new", :controller => 'queries', :action => 'new', :project_id => 'redmine'
- should_route :post, "/queries/new", :controller => 'queries', :action => 'new'
- should_route :post, "/projects/redmine/queries/new", :controller => 'queries', :action => 'new', :project_id => 'redmine'
+ should_route :post, "/queries", :controller => 'queries', :action => 'create'
+ should_route :post, "/projects/redmine/queries", :controller => 'queries', :action => 'create', :project_id => 'redmine'
+
+ should_route :get, "/queries/1/edit", :controller => 'queries', :action => 'edit', :id => '1'
+ should_route :get, "/projects/redmine/queries/1/edit", :controller => 'queries', :action => 'edit', :id => '1', :project_id => 'redmine'
+
+ should_route :put, "/queries/1", :controller => 'queries', :action => 'update', :id => '1'
+ should_route :put, "/projects/redmine/queries/1", :controller => 'queries', :action => 'update', :id => '1', :project_id => 'redmine'
+
+ should_route :delete, "/queries/1", :controller => 'queries', :action => 'destroy', :id => '1'
+ should_route :delete, "/projects/redmine/queries/1", :controller => 'queries', :action => 'destroy', :id => '1', :project_id => 'redmine'
end
context "repositories" do