@@ -1,118 +1,118 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 TimelogCustomFieldsVisibilityTest < ActionController::TestCase |
|
20 | class TimelogCustomFieldsVisibilityTest < ActionController::TestCase | |
21 | tests TimelogController |
|
21 | tests TimelogController | |
22 | fixtures :projects, |
|
22 | fixtures :projects, | |
23 | :users, |
|
23 | :users, | |
24 | :roles, |
|
24 | :roles, | |
25 | :members, |
|
25 | :members, | |
26 | :member_roles, |
|
26 | :member_roles, | |
27 | :issue_statuses, |
|
27 | :issue_statuses, | |
28 | :trackers, |
|
28 | :trackers, | |
29 | :projects_trackers, |
|
29 | :projects_trackers, | |
30 | :enabled_modules, |
|
30 | :enabled_modules, | |
31 | :enumerations, |
|
31 | :enumerations, | |
32 | :workflows |
|
32 | :workflows | |
33 |
|
33 | |||
34 | def setup |
|
34 | def setup | |
35 | field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all} |
|
35 | field_attributes = {:field_format => 'string', :is_for_all => true, :is_filter => true, :trackers => Tracker.all} | |
36 | @fields = [] |
|
36 | @fields = [] | |
37 | @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true))) |
|
37 | @fields << (@field1 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 1', :visible => true))) | |
38 | @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2]))) |
|
38 | @fields << (@field2 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 2', :visible => false, :role_ids => [1, 2]))) | |
39 | @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3]))) |
|
39 | @fields << (@field3 = IssueCustomField.create!(field_attributes.merge(:name => 'Field 3', :visible => false, :role_ids => [1, 3]))) | |
40 | @issue = Issue.generate!( |
|
40 | @issue = Issue.generate!( | |
41 | :author_id => 1, |
|
41 | :author_id => 1, | |
42 | :project_id => 1, |
|
42 | :project_id => 1, | |
43 | :tracker_id => 1, |
|
43 | :tracker_id => 1, | |
44 | :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'} |
|
44 | :custom_field_values => {@field1.id => 'Value0', @field2.id => 'Value1', @field3.id => 'Value2'} | |
45 | ) |
|
45 | ) | |
46 | TimeEntry.generate!(:issue => @issue) |
|
46 | TimeEntry.generate!(:issue => @issue) | |
47 |
|
47 | |||
48 | @user_with_role_on_other_project = User.generate! |
|
48 | @user_with_role_on_other_project = User.generate! | |
49 | User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3)) |
|
49 | User.add_to_project(@user_with_role_on_other_project, Project.find(2), Role.find(3)) | |
50 |
|
50 | |||
51 | @users_to_test = { |
|
51 | @users_to_test = { | |
52 | User.find(1) => [@field1, @field2, @field3], |
|
52 | User.find(1) => [@field1, @field2, @field3], | |
53 | User.find(3) => [@field1, @field2], |
|
53 | User.find(3) => [@field1, @field2], | |
54 | @user_with_role_on_other_project => [@field1], # should see field1 only on Project 1 |
|
54 | @user_with_role_on_other_project => [@field1], # should see field1 only on Project 1 | |
55 | User.generate! => [@field1], |
|
55 | User.generate! => [@field1], | |
56 | User.anonymous => [@field1] |
|
56 | User.anonymous => [@field1] | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | Member.where(:project_id => 1).each do |member| |
|
59 | Member.where(:project_id => 1).each do |member| | |
60 | member.destroy unless @users_to_test.keys.include?(member.principal) |
|
60 | member.destroy unless @users_to_test.keys.include?(member.principal) | |
61 | end |
|
61 | end | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_index_should_show_visible_custom_fields_only |
|
64 | def test_index_should_show_visible_custom_fields_only | |
65 | @users_to_test.each do |user, fields| |
|
65 | @users_to_test.each do |user, fields| | |
66 | @request.session[:user_id] = user.id |
|
66 | @request.session[:user_id] = user.id | |
67 | get :index, :project_id => 1, :issue_id => @issue.id, :c => (['hours'] + @fields.map{|f| "issue.cf_#{f.id}"}) |
|
67 | get :index, :project_id => 1, :issue_id => @issue.id, :c => (['hours'] + @fields.map{|f| "issue.cf_#{f.id}"}) | |
68 | @fields.each_with_index do |field, i| |
|
68 | @fields.each_with_index do |field, i| | |
69 | if fields.include?(field) |
|
69 | if fields.include?(field) | |
70 | assert_select 'td', {:text => "Value#{i}", :count => 1}, "User #{user.id} was not able to view #{field.name}" |
|
70 | assert_select 'td', {:text => "Value#{i}", :count => 1}, "User #{user.id} was not able to view #{field.name}" | |
71 | else |
|
71 | else | |
72 | assert_select 'td', {:text => "Value#{i}", :count => 0}, "User #{user.id} was able to view #{field.name}" |
|
72 | assert_select 'td', {:text => "Value#{i}", :count => 0}, "User #{user.id} was able to view #{field.name}" | |
73 | end |
|
73 | end | |
74 | end |
|
74 | end | |
75 | end |
|
75 | end | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_index_as_csv_should_show_visible_custom_fields_only |
|
78 | def test_index_as_csv_should_show_visible_custom_fields_only | |
79 | @users_to_test.each do |user, fields| |
|
79 | @users_to_test.each do |user, fields| | |
80 | @request.session[:user_id] = user.id |
|
80 | @request.session[:user_id] = user.id | |
81 | get :index, :project_id => 1, :issue_id => @issue.id, :c => (['hours'] + @fields.map{|f| "issue.cf_#{f.id}"}), :format => 'csv' |
|
81 | get :index, :project_id => 1, :issue_id => @issue.id, :c => (['hours'] + @fields.map{|f| "issue.cf_#{f.id}"}), :format => 'csv' | |
82 | @fields.each_with_index do |field, i| |
|
82 | @fields.each_with_index do |field, i| | |
83 | if fields.include?(field) |
|
83 | if fields.include?(field) | |
84 | assert_include "Value#{i}", response.body, "User #{user.id} was not able to view #{field.name} in CSV" |
|
84 | assert_include "Value#{i}", response.body, "User #{user.id} was not able to view #{field.name} in CSV" | |
85 | else |
|
85 | else | |
86 | assert_not_include "Value#{i}", response.body, "User #{user.id} was able to view #{field.name} in CSV" |
|
86 | assert_not_include "Value#{i}", response.body, "User #{user.id} was able to view #{field.name} in CSV" | |
87 | end |
|
87 | end | |
88 | end |
|
88 | end | |
89 | end |
|
89 | end | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def test_index_with_partial_custom_field_visibility_should_show_visible_custom_fields_only |
|
92 | def test_index_with_partial_custom_field_visibility_should_show_visible_custom_fields_only | |
93 | Issue.delete_all |
|
93 | Issue.delete_all | |
94 | TimeEntry.delete_all |
|
94 | TimeEntry.delete_all | |
95 | p1 = Project.generate! |
|
95 | p1 = Project.generate! | |
96 | p2 = Project.generate! |
|
96 | p2 = Project.generate! | |
97 | user = User.generate! |
|
97 | user = User.generate! | |
98 | User.add_to_project(user, p1, Role.find_all_by_id(1,3)) |
|
98 | User.add_to_project(user, p1, Role.find_all_by_id([1, 3])) | |
99 | User.add_to_project(user, p2, Role.find_all_by_id(3)) |
|
99 | User.add_to_project(user, p2, Role.find_all_by_id(3)) | |
100 | TimeEntry.generate!( |
|
100 | TimeEntry.generate!( | |
101 | :issue => Issue.generate!(:project => p1, :tracker_id => 1, |
|
101 | :issue => Issue.generate!(:project => p1, :tracker_id => 1, | |
102 | :custom_field_values => {@field2.id => 'ValueA'})) |
|
102 | :custom_field_values => {@field2.id => 'ValueA'})) | |
103 | TimeEntry.generate!( |
|
103 | TimeEntry.generate!( | |
104 | :issue => Issue.generate!(:project => p2, :tracker_id => 1, |
|
104 | :issue => Issue.generate!(:project => p2, :tracker_id => 1, | |
105 | :custom_field_values => {@field2.id => 'ValueB'})) |
|
105 | :custom_field_values => {@field2.id => 'ValueB'})) | |
106 | TimeEntry.generate!( |
|
106 | TimeEntry.generate!( | |
107 | :issue => Issue.generate!(:project => p1, :tracker_id => 1, |
|
107 | :issue => Issue.generate!(:project => p1, :tracker_id => 1, | |
108 | :custom_field_values => {@field2.id => 'ValueC'})) |
|
108 | :custom_field_values => {@field2.id => 'ValueC'})) | |
109 | @request.session[:user_id] = user.id |
|
109 | @request.session[:user_id] = user.id | |
110 | get :index, :c => ["hours", "issue.cf_#{@field2.id}"] |
|
110 | get :index, :c => ["hours", "issue.cf_#{@field2.id}"] | |
111 | assert_select 'td', :text => 'ValueA' |
|
111 | assert_select 'td', :text => 'ValueA' | |
112 | assert_select 'td', :text => 'ValueB', :count => 0 |
|
112 | assert_select 'td', :text => 'ValueB', :count => 0 | |
113 | assert_select 'td', :text => 'ValueC' |
|
113 | assert_select 'td', :text => 'ValueC' | |
114 |
|
114 | |||
115 | get :index, :set_filter => '1', "issue.cf_#{@field2.id}" => '*' |
|
115 | get :index, :set_filter => '1', "issue.cf_#{@field2.id}" => '*' | |
116 | assert_equal %w(ValueA ValueC), assigns(:entries).map{|i| i.issue.custom_field_value(@field2)}.sort |
|
116 | assert_equal %w(ValueA ValueC), assigns(:entries).map{|i| i.issue.custom_field_value(@field2)}.sort | |
117 | end |
|
117 | end | |
118 | end |
|
118 | end |
General Comments 0
You need to be logged in to leave comments.
Login now