@@ -1,103 +1,103 | |||||
1 | require 'active_record' |
|
1 | require 'active_record' | |
2 |
|
2 | |||
3 | module ActiveRecord |
|
3 | module ActiveRecord | |
4 | class Base |
|
4 | class Base | |
5 | include Redmine::I18n |
|
5 | include Redmine::I18n | |
6 | # Translate attribute names for validation errors display |
|
6 | # Translate attribute names for validation errors display | |
7 | def self.human_attribute_name(attr, *args) |
|
7 | def self.human_attribute_name(attr, *args) | |
8 | l("field_#{attr.to_s.gsub(/_id$/, '')}", :default => attr) |
|
8 | l("field_#{attr.to_s.gsub(/_id$/, '')}", :default => attr) | |
9 | end |
|
9 | end | |
10 | end |
|
10 | end | |
11 | end |
|
11 | end | |
12 |
|
12 | |||
13 | module ActionView |
|
13 | module ActionView | |
14 | module Helpers |
|
14 | module Helpers | |
15 | module DateHelper |
|
15 | module DateHelper | |
16 | # distance_of_time_in_words breaks when difference is greater than 30 years |
|
16 | # distance_of_time_in_words breaks when difference is greater than 30 years | |
17 | def distance_of_date_in_words(from_date, to_date = 0, options = {}) |
|
17 | def distance_of_date_in_words(from_date, to_date = 0, options = {}) | |
18 | from_date = from_date.to_date if from_date.respond_to?(:to_date) |
|
18 | from_date = from_date.to_date if from_date.respond_to?(:to_date) | |
19 | to_date = to_date.to_date if to_date.respond_to?(:to_date) |
|
19 | to_date = to_date.to_date if to_date.respond_to?(:to_date) | |
20 | distance_in_days = (to_date - from_date).abs |
|
20 | distance_in_days = (to_date - from_date).abs | |
21 |
|
21 | |||
22 | I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale| |
|
22 | I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale| | |
23 | case distance_in_days |
|
23 | case distance_in_days | |
24 | when 0..60 then locale.t :x_days, :count => distance_in_days.round |
|
24 | when 0..60 then locale.t :x_days, :count => distance_in_days.round | |
25 | when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round |
|
25 | when 61..720 then locale.t :about_x_months, :count => (distance_in_days / 30).round | |
26 | else locale.t :over_x_years, :count => (distance_in_days / 365).floor |
|
26 | else locale.t :over_x_years, :count => (distance_in_days / 365).floor | |
27 | end |
|
27 | end | |
28 | end |
|
28 | end | |
29 | end |
|
29 | end | |
30 | end |
|
30 | end | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | class Resolver |
|
33 | class Resolver | |
34 | def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[]) |
|
34 | def find_all(name, prefix=nil, partial=false, details={}, key=nil, locals=[]) | |
35 | cached(key, [name, prefix, partial], details, locals) do |
|
35 | cached(key, [name, prefix, partial], details, locals) do | |
36 | if details[:formats] & [:xml, :json] |
|
36 | if details[:formats] & [:xml, :json] | |
37 | details = details.dup |
|
37 | details = details.dup | |
38 | details[:formats] = details[:formats].dup + [:api] |
|
38 | details[:formats] = details[:formats].dup + [:api] | |
39 | end |
|
39 | end | |
40 | find_templates(name, prefix, partial, details) |
|
40 | find_templates(name, prefix, partial, details) | |
41 | end |
|
41 | end | |
42 | end |
|
42 | end | |
43 | end |
|
43 | end | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 |
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| |
|
46 | ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe } | |
47 |
|
47 | |||
48 | require 'mail' |
|
48 | require 'mail' | |
49 |
|
49 | |||
50 | module DeliveryMethods |
|
50 | module DeliveryMethods | |
51 | class AsyncSMTP < ::Mail::SMTP |
|
51 | class AsyncSMTP < ::Mail::SMTP | |
52 | def deliver!(*args) |
|
52 | def deliver!(*args) | |
53 | Thread.start do |
|
53 | Thread.start do | |
54 | super *args |
|
54 | super *args | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | class AsyncSendmail < ::Mail::Sendmail |
|
59 | class AsyncSendmail < ::Mail::Sendmail | |
60 | def deliver!(*args) |
|
60 | def deliver!(*args) | |
61 | Thread.start do |
|
61 | Thread.start do | |
62 | super *args |
|
62 | super *args | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | class TmpFile |
|
67 | class TmpFile | |
68 | def initialize(*args); end |
|
68 | def initialize(*args); end | |
69 |
|
69 | |||
70 | def deliver!(mail) |
|
70 | def deliver!(mail) | |
71 | dest_dir = File.join(Rails.root, 'tmp', 'emails') |
|
71 | dest_dir = File.join(Rails.root, 'tmp', 'emails') | |
72 | Dir.mkdir(dest_dir) unless File.directory?(dest_dir) |
|
72 | Dir.mkdir(dest_dir) unless File.directory?(dest_dir) | |
73 | File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) } |
|
73 | File.open(File.join(dest_dir, mail.message_id.gsub(/[<>]/, '') + '.eml'), 'wb') {|f| f.write(mail.encoded) } | |
74 | end |
|
74 | end | |
75 | end |
|
75 | end | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP |
|
78 | ActionMailer::Base.add_delivery_method :async_smtp, DeliveryMethods::AsyncSMTP | |
79 | ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail |
|
79 | ActionMailer::Base.add_delivery_method :async_sendmail, DeliveryMethods::AsyncSendmail | |
80 | ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile |
|
80 | ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile | |
81 |
|
81 | |||
82 | module ActionController |
|
82 | module ActionController | |
83 | module MimeResponds |
|
83 | module MimeResponds | |
84 | class Collector |
|
84 | class Collector | |
85 | def api(&block) |
|
85 | def api(&block) | |
86 | any(:xml, :json, &block) |
|
86 | any(:xml, :json, &block) | |
87 | end |
|
87 | end | |
88 | end |
|
88 | end | |
89 | end |
|
89 | end | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | module ActionController |
|
92 | module ActionController | |
93 | class Base |
|
93 | class Base | |
94 | # Displays an explicit message instead of a NoMethodError exception |
|
94 | # Displays an explicit message instead of a NoMethodError exception | |
95 | # when trying to start Redmine with an old session_store.rb |
|
95 | # when trying to start Redmine with an old session_store.rb | |
96 | # TODO: remove it in a later version |
|
96 | # TODO: remove it in a later version | |
97 | def self.session=(*args) |
|
97 | def self.session=(*args) | |
98 | $stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" + |
|
98 | $stderr.puts "Please remove config/initializers/session_store.rb and run `rake generate_secret_token`.\n" + | |
99 | "Setting the session secret with ActionController.session= is no longer supported in Rails 3." |
|
99 | "Setting the session secret with ActionController.session= is no longer supported in Rails 3." | |
100 | exit 1 |
|
100 | exit 1 | |
101 | end |
|
101 | end | |
102 | end |
|
102 | end | |
103 | end |
|
103 | end |
@@ -1,275 +1,276 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class QueriesControllerTest < ActionController::TestCase |
|
20 | class QueriesControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries |
|
21 | fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries | |
22 |
|
22 | |||
23 | def setup |
|
23 | def setup | |
24 | User.current = nil |
|
24 | User.current = nil | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def test_new_project_query |
|
27 | def test_new_project_query | |
28 | @request.session[:user_id] = 2 |
|
28 | @request.session[:user_id] = 2 | |
29 | get :new, :project_id => 1 |
|
29 | get :new, :project_id => 1 | |
30 | assert_response :success |
|
30 | assert_response :success | |
31 | assert_template 'new' |
|
31 | assert_template 'new' | |
32 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
32 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
33 | :name => 'query[is_public]', |
|
33 | :name => 'query[is_public]', | |
34 | :checked => nil } |
|
34 | :checked => nil } | |
35 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
35 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
36 | :name => 'query_is_for_all', |
|
36 | :name => 'query_is_for_all', | |
37 | :checked => nil, |
|
37 | :checked => nil, | |
38 | :disabled => nil } |
|
38 | :disabled => nil } | |
39 | assert_select 'select[name=?]', 'c[]' do |
|
39 | assert_select 'select[name=?]', 'c[]' do | |
40 | assert_select 'option[value=tracker]' |
|
40 | assert_select 'option[value=tracker]' | |
41 | assert_select 'option[value=subject]' |
|
41 | assert_select 'option[value=subject]' | |
42 | end |
|
42 | end | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | def test_new_global_query |
|
45 | def test_new_global_query | |
46 | @request.session[:user_id] = 2 |
|
46 | @request.session[:user_id] = 2 | |
47 | get :new |
|
47 | get :new | |
48 | assert_response :success |
|
48 | assert_response :success | |
49 | assert_template 'new' |
|
49 | assert_template 'new' | |
50 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
50 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
51 | :name => 'query[is_public]' } |
|
51 | :name => 'query[is_public]' } | |
52 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
52 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
53 | :name => 'query_is_for_all', |
|
53 | :name => 'query_is_for_all', | |
54 | :checked => 'checked', |
|
54 | :checked => 'checked', | |
55 | :disabled => nil } |
|
55 | :disabled => nil } | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def test_new_on_invalid_project |
|
58 | def test_new_on_invalid_project | |
59 | @request.session[:user_id] = 2 |
|
59 | @request.session[:user_id] = 2 | |
60 | get :new, :project_id => 'invalid' |
|
60 | get :new, :project_id => 'invalid' | |
61 | assert_response 404 |
|
61 | assert_response 404 | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_create_project_public_query |
|
64 | def test_create_project_public_query | |
65 | @request.session[:user_id] = 2 |
|
65 | @request.session[:user_id] = 2 | |
66 | post :create, |
|
66 | post :create, | |
67 | :project_id => 'ecookbook', |
|
67 | :project_id => 'ecookbook', | |
68 | :default_columns => '1', |
|
68 | :default_columns => '1', | |
69 | :f => ["status_id", "assigned_to_id"], |
|
69 | :f => ["status_id", "assigned_to_id"], | |
70 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
70 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, | |
71 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
71 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
72 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} |
|
72 | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} | |
73 |
|
73 | |||
74 | q = Query.find_by_name('test_new_project_public_query') |
|
74 | q = Query.find_by_name('test_new_project_public_query') | |
75 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
75 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |
76 | assert q.is_public? |
|
76 | assert q.is_public? | |
77 | assert q.has_default_columns? |
|
77 | assert q.has_default_columns? | |
78 | assert q.valid? |
|
78 | assert q.valid? | |
79 | end |
|
79 | end | |
80 |
|
80 | |||
81 | def test_create_project_private_query |
|
81 | def test_create_project_private_query | |
82 | @request.session[:user_id] = 3 |
|
82 | @request.session[:user_id] = 3 | |
83 | post :create, |
|
83 | post :create, | |
84 | :project_id => 'ecookbook', |
|
84 | :project_id => 'ecookbook', | |
85 | :default_columns => '1', |
|
85 | :default_columns => '1', | |
86 | :fields => ["status_id", "assigned_to_id"], |
|
86 | :fields => ["status_id", "assigned_to_id"], | |
87 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
87 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
88 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
88 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
89 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} |
|
89 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} | |
90 |
|
90 | |||
91 | q = Query.find_by_name('test_new_project_private_query') |
|
91 | q = Query.find_by_name('test_new_project_private_query') | |
92 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
|
92 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q | |
93 | assert !q.is_public? |
|
93 | assert !q.is_public? | |
94 | assert q.has_default_columns? |
|
94 | assert q.has_default_columns? | |
95 | assert q.valid? |
|
95 | assert q.valid? | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_create_global_private_query_with_custom_columns |
|
98 | def test_create_global_private_query_with_custom_columns | |
99 | @request.session[:user_id] = 3 |
|
99 | @request.session[:user_id] = 3 | |
100 | post :create, |
|
100 | post :create, | |
101 | :fields => ["status_id", "assigned_to_id"], |
|
101 | :fields => ["status_id", "assigned_to_id"], | |
102 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
102 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
103 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
103 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
104 | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, |
|
104 | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, | |
105 | :c => ["", "tracker", "subject", "priority", "category"] |
|
105 | :c => ["", "tracker", "subject", "priority", "category"] | |
106 |
|
106 | |||
107 | q = Query.find_by_name('test_new_global_private_query') |
|
107 | q = Query.find_by_name('test_new_global_private_query') | |
108 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
108 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q | |
109 | assert !q.is_public? |
|
109 | assert !q.is_public? | |
110 | assert !q.has_default_columns? |
|
110 | assert !q.has_default_columns? | |
111 | assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} |
|
111 | assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name} | |
112 | assert q.valid? |
|
112 | assert q.valid? | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_create_global_query_with_custom_filters |
|
115 | def test_create_global_query_with_custom_filters | |
116 | @request.session[:user_id] = 3 |
|
116 | @request.session[:user_id] = 3 | |
117 | post :create, |
|
117 | post :create, | |
118 | :fields => ["assigned_to_id"], |
|
118 | :fields => ["assigned_to_id"], | |
119 | :operators => {"assigned_to_id" => "="}, |
|
119 | :operators => {"assigned_to_id" => "="}, | |
120 | :values => { "assigned_to_id" => ["me"]}, |
|
120 | :values => { "assigned_to_id" => ["me"]}, | |
121 | :query => {"name" => "test_new_global_query"} |
|
121 | :query => {"name" => "test_new_global_query"} | |
122 |
|
122 | |||
123 | q = Query.find_by_name('test_new_global_query') |
|
123 | q = Query.find_by_name('test_new_global_query') | |
124 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
|
124 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q | |
125 | assert !q.has_filter?(:status_id) |
|
125 | assert !q.has_filter?(:status_id) | |
126 | assert_equal ['assigned_to_id'], q.filters.keys |
|
126 | assert_equal ['assigned_to_id'], q.filters.keys | |
127 | assert q.valid? |
|
127 | assert q.valid? | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | def test_create_with_sort |
|
130 | def test_create_with_sort | |
131 | @request.session[:user_id] = 1 |
|
131 | @request.session[:user_id] = 1 | |
132 | post :create, |
|
132 | post :create, | |
133 | :default_columns => '1', |
|
133 | :default_columns => '1', | |
134 | :operators => {"status_id" => "o"}, |
|
134 | :operators => {"status_id" => "o"}, | |
135 | :values => {"status_id" => ["1"]}, |
|
135 | :values => {"status_id" => ["1"]}, | |
136 | :query => {:name => "test_new_with_sort", |
|
136 | :query => {:name => "test_new_with_sort", | |
137 | :is_public => "1", |
|
137 | :is_public => "1", | |
138 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} |
|
138 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} | |
139 |
|
139 | |||
140 | query = Query.find_by_name("test_new_with_sort") |
|
140 | query = Query.find_by_name("test_new_with_sort") | |
141 | assert_not_nil query |
|
141 | assert_not_nil query | |
142 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
|
142 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def test_create_with_failure |
|
145 | def test_create_with_failure | |
146 | @request.session[:user_id] = 2 |
|
146 | @request.session[:user_id] = 2 | |
147 | assert_no_difference '::Query.count' do |
|
147 | assert_no_difference '::Query.count' do | |
148 | post :create, :project_id => 'ecookbook', :query => {:name => ''} |
|
148 | post :create, :project_id => 'ecookbook', :query => {:name => ''} | |
149 | end |
|
149 | end | |
150 | assert_response :success |
|
150 | assert_response :success | |
151 | assert_template 'new' |
|
151 | assert_template 'new' | |
|
152 | assert_select 'input[name=?]', 'query[name]' | |||
152 | end |
|
153 | end | |
153 |
|
154 | |||
154 | def test_edit_global_public_query |
|
155 | def test_edit_global_public_query | |
155 | @request.session[:user_id] = 1 |
|
156 | @request.session[:user_id] = 1 | |
156 | get :edit, :id => 4 |
|
157 | get :edit, :id => 4 | |
157 | assert_response :success |
|
158 | assert_response :success | |
158 | assert_template 'edit' |
|
159 | assert_template 'edit' | |
159 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
160 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
160 | :name => 'query[is_public]', |
|
161 | :name => 'query[is_public]', | |
161 | :checked => 'checked' } |
|
162 | :checked => 'checked' } | |
162 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
163 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
163 | :name => 'query_is_for_all', |
|
164 | :name => 'query_is_for_all', | |
164 | :checked => 'checked', |
|
165 | :checked => 'checked', | |
165 | :disabled => 'disabled' } |
|
166 | :disabled => 'disabled' } | |
166 | end |
|
167 | end | |
167 |
|
168 | |||
168 | def test_edit_global_private_query |
|
169 | def test_edit_global_private_query | |
169 | @request.session[:user_id] = 3 |
|
170 | @request.session[:user_id] = 3 | |
170 | get :edit, :id => 3 |
|
171 | get :edit, :id => 3 | |
171 | assert_response :success |
|
172 | assert_response :success | |
172 | assert_template 'edit' |
|
173 | assert_template 'edit' | |
173 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
174 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
174 | :name => 'query[is_public]' } |
|
175 | :name => 'query[is_public]' } | |
175 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
176 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
176 | :name => 'query_is_for_all', |
|
177 | :name => 'query_is_for_all', | |
177 | :checked => 'checked', |
|
178 | :checked => 'checked', | |
178 | :disabled => 'disabled' } |
|
179 | :disabled => 'disabled' } | |
179 | end |
|
180 | end | |
180 |
|
181 | |||
181 | def test_edit_project_private_query |
|
182 | def test_edit_project_private_query | |
182 | @request.session[:user_id] = 3 |
|
183 | @request.session[:user_id] = 3 | |
183 | get :edit, :id => 2 |
|
184 | get :edit, :id => 2 | |
184 | assert_response :success |
|
185 | assert_response :success | |
185 | assert_template 'edit' |
|
186 | assert_template 'edit' | |
186 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
187 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
187 | :name => 'query[is_public]' } |
|
188 | :name => 'query[is_public]' } | |
188 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
189 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
189 | :name => 'query_is_for_all', |
|
190 | :name => 'query_is_for_all', | |
190 | :checked => nil, |
|
191 | :checked => nil, | |
191 | :disabled => nil } |
|
192 | :disabled => nil } | |
192 | end |
|
193 | end | |
193 |
|
194 | |||
194 | def test_edit_project_public_query |
|
195 | def test_edit_project_public_query | |
195 | @request.session[:user_id] = 2 |
|
196 | @request.session[:user_id] = 2 | |
196 | get :edit, :id => 1 |
|
197 | get :edit, :id => 1 | |
197 | assert_response :success |
|
198 | assert_response :success | |
198 | assert_template 'edit' |
|
199 | assert_template 'edit' | |
199 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
200 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
200 | :name => 'query[is_public]', |
|
201 | :name => 'query[is_public]', | |
201 | :checked => 'checked' |
|
202 | :checked => 'checked' | |
202 | } |
|
203 | } | |
203 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
|
204 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', | |
204 | :name => 'query_is_for_all', |
|
205 | :name => 'query_is_for_all', | |
205 | :checked => nil, |
|
206 | :checked => nil, | |
206 | :disabled => 'disabled' } |
|
207 | :disabled => 'disabled' } | |
207 | end |
|
208 | end | |
208 |
|
209 | |||
209 | def test_edit_sort_criteria |
|
210 | def test_edit_sort_criteria | |
210 | @request.session[:user_id] = 1 |
|
211 | @request.session[:user_id] = 1 | |
211 | get :edit, :id => 5 |
|
212 | get :edit, :id => 5 | |
212 | assert_response :success |
|
213 | assert_response :success | |
213 | assert_template 'edit' |
|
214 | assert_template 'edit' | |
214 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
215 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, | |
215 | :child => { :tag => 'option', :attributes => { :value => 'priority', |
|
216 | :child => { :tag => 'option', :attributes => { :value => 'priority', | |
216 | :selected => 'selected' } } |
|
217 | :selected => 'selected' } } | |
217 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
|
218 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, | |
218 | :child => { :tag => 'option', :attributes => { :value => 'desc', |
|
219 | :child => { :tag => 'option', :attributes => { :value => 'desc', | |
219 | :selected => 'selected' } } |
|
220 | :selected => 'selected' } } | |
220 | end |
|
221 | end | |
221 |
|
222 | |||
222 | def test_edit_invalid_query |
|
223 | def test_edit_invalid_query | |
223 | @request.session[:user_id] = 2 |
|
224 | @request.session[:user_id] = 2 | |
224 | get :edit, :id => 99 |
|
225 | get :edit, :id => 99 | |
225 | assert_response 404 |
|
226 | assert_response 404 | |
226 | end |
|
227 | end | |
227 |
|
228 | |||
228 | def test_udpate_global_private_query |
|
229 | def test_udpate_global_private_query | |
229 | @request.session[:user_id] = 3 |
|
230 | @request.session[:user_id] = 3 | |
230 | put :update, |
|
231 | put :update, | |
231 | :id => 3, |
|
232 | :id => 3, | |
232 | :default_columns => '1', |
|
233 | :default_columns => '1', | |
233 | :fields => ["status_id", "assigned_to_id"], |
|
234 | :fields => ["status_id", "assigned_to_id"], | |
234 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
235 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
235 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
|
236 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, | |
236 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} |
|
237 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} | |
237 |
|
238 | |||
238 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
|
239 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 | |
239 | q = Query.find_by_name('test_edit_global_private_query') |
|
240 | q = Query.find_by_name('test_edit_global_private_query') | |
240 | assert !q.is_public? |
|
241 | assert !q.is_public? | |
241 | assert q.has_default_columns? |
|
242 | assert q.has_default_columns? | |
242 | assert q.valid? |
|
243 | assert q.valid? | |
243 | end |
|
244 | end | |
244 |
|
245 | |||
245 | def test_update_global_public_query |
|
246 | def test_update_global_public_query | |
246 | @request.session[:user_id] = 1 |
|
247 | @request.session[:user_id] = 1 | |
247 | put :update, |
|
248 | put :update, | |
248 | :id => 4, |
|
249 | :id => 4, | |
249 | :default_columns => '1', |
|
250 | :default_columns => '1', | |
250 | :fields => ["status_id", "assigned_to_id"], |
|
251 | :fields => ["status_id", "assigned_to_id"], | |
251 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
|
252 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, | |
252 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
|
253 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, | |
253 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} |
|
254 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} | |
254 |
|
255 | |||
255 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
|
256 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 | |
256 | q = Query.find_by_name('test_edit_global_public_query') |
|
257 | q = Query.find_by_name('test_edit_global_public_query') | |
257 | assert q.is_public? |
|
258 | assert q.is_public? | |
258 | assert q.has_default_columns? |
|
259 | assert q.has_default_columns? | |
259 | assert q.valid? |
|
260 | assert q.valid? | |
260 | end |
|
261 | end | |
261 |
|
262 | |||
262 | def test_update_with_failure |
|
263 | def test_update_with_failure | |
263 | @request.session[:user_id] = 1 |
|
264 | @request.session[:user_id] = 1 | |
264 | put :update, :id => 4, :query => {:name => ''} |
|
265 | put :update, :id => 4, :query => {:name => ''} | |
265 | assert_response :success |
|
266 | assert_response :success | |
266 | assert_template 'edit' |
|
267 | assert_template 'edit' | |
267 | end |
|
268 | end | |
268 |
|
269 | |||
269 | def test_destroy |
|
270 | def test_destroy | |
270 | @request.session[:user_id] = 2 |
|
271 | @request.session[:user_id] = 2 | |
271 | delete :destroy, :id => 1 |
|
272 | delete :destroy, :id => 1 | |
272 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
|
273 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil | |
273 | assert_nil Query.find_by_id(1) |
|
274 | assert_nil Query.find_by_id(1) | |
274 | end |
|
275 | end | |
275 | end |
|
276 | end |
General Comments 0
You need to be logged in to leave comments.
Login now