@@ -1,176 +1,176 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 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 | module Redmine |
|
18 | module Redmine | |
19 | module DefaultData |
|
19 | module DefaultData | |
20 | class DataAlreadyLoaded < Exception; end |
|
20 | class DataAlreadyLoaded < Exception; end | |
21 |
|
21 | |||
22 | module Loader |
|
22 | module Loader | |
23 | include Redmine::I18n |
|
23 | include Redmine::I18n | |
24 |
|
24 | |||
25 | class << self |
|
25 | class << self | |
26 | # Returns true if no data is already loaded in the database |
|
26 | # Returns true if no data is already loaded in the database | |
27 | # otherwise false |
|
27 | # otherwise false | |
28 | def no_data? |
|
28 | def no_data? | |
29 | !Role.find(:first, :conditions => {:builtin => 0}) && |
|
29 | !Role.find(:first, :conditions => {:builtin => 0}) && | |
30 | !Tracker.find(:first) && |
|
30 | !Tracker.find(:first) && | |
31 | !IssueStatus.find(:first) && |
|
31 | !IssueStatus.find(:first) && | |
32 | !Enumeration.find(:first) |
|
32 | !Enumeration.find(:first) | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | # Loads the default data |
|
35 | # Loads the default data | |
36 | # Raises a RecordNotSaved exception if something goes wrong |
|
36 | # Raises a RecordNotSaved exception if something goes wrong | |
37 | def load(lang=nil) |
|
37 | def load(lang=nil) | |
38 | raise DataAlreadyLoaded.new("Some configuration data is already loaded.") unless no_data? |
|
38 | raise DataAlreadyLoaded.new("Some configuration data is already loaded.") unless no_data? | |
39 | set_language_if_valid(lang) |
|
39 | set_language_if_valid(lang) | |
40 |
|
40 | |||
41 | Role.transaction do |
|
41 | Role.transaction do | |
42 | # Roles |
|
42 | # Roles | |
43 | manager = Role.create! :name => l(:default_role_manager), |
|
43 | manager = Role.create! :name => l(:default_role_manager), | |
44 | :position => 1 |
|
44 | :position => 1 | |
45 | manager.permissions = manager.setable_permissions.collect {|p| p.name} |
|
45 | manager.permissions = manager.setable_permissions.collect {|p| p.name} | |
46 | manager.save! |
|
46 | manager.save! | |
47 |
|
47 | |||
48 | developper = Role.create! :name => l(:default_role_developper), |
|
48 | developper = Role.create! :name => l(:default_role_developper), | |
49 | :position => 2, |
|
49 | :position => 2, | |
50 | :permissions => [:manage_versions, |
|
50 | :permissions => [:manage_versions, | |
51 | :manage_categories, |
|
51 | :manage_categories, | |
52 | :add_issues, |
|
52 | :add_issues, | |
53 | :edit_issues, |
|
53 | :edit_issues, | |
54 | :manage_issue_relations, |
|
54 | :manage_issue_relations, | |
55 | :add_issue_notes, |
|
55 | :add_issue_notes, | |
56 | :save_queries, |
|
56 | :save_queries, | |
57 | :view_gantt, |
|
57 | :view_gantt, | |
58 | :view_calendar, |
|
58 | :view_calendar, | |
59 | :log_time, |
|
59 | :log_time, | |
60 | :view_time_entries, |
|
60 | :view_time_entries, | |
61 | :comment_news, |
|
61 | :comment_news, | |
62 | :view_documents, |
|
62 | :view_documents, | |
63 | :view_wiki_pages, |
|
63 | :view_wiki_pages, | |
64 | :view_wiki_edits, |
|
64 | :view_wiki_edits, | |
65 | :edit_wiki_pages, |
|
65 | :edit_wiki_pages, | |
66 | :delete_wiki_pages, |
|
66 | :delete_wiki_pages, | |
67 | :add_messages, |
|
67 | :add_messages, | |
68 | :edit_own_messages, |
|
68 | :edit_own_messages, | |
69 | :view_files, |
|
69 | :view_files, | |
70 | :manage_files, |
|
70 | :manage_files, | |
71 | :browse_repository, |
|
71 | :browse_repository, | |
72 | :view_changesets, |
|
72 | :view_changesets, | |
73 | :commit_access] |
|
73 | :commit_access] | |
74 |
|
74 | |||
75 | reporter = Role.create! :name => l(:default_role_reporter), |
|
75 | reporter = Role.create! :name => l(:default_role_reporter), | |
76 | :position => 3, |
|
76 | :position => 3, | |
77 | :permissions => [:add_issues, |
|
77 | :permissions => [:add_issues, | |
78 | :add_issue_notes, |
|
78 | :add_issue_notes, | |
79 | :save_queries, |
|
79 | :save_queries, | |
80 | :view_gantt, |
|
80 | :view_gantt, | |
81 | :view_calendar, |
|
81 | :view_calendar, | |
82 | :log_time, |
|
82 | :log_time, | |
83 | :view_time_entries, |
|
83 | :view_time_entries, | |
84 | :comment_news, |
|
84 | :comment_news, | |
85 | :view_documents, |
|
85 | :view_documents, | |
86 | :view_wiki_pages, |
|
86 | :view_wiki_pages, | |
87 | :view_wiki_edits, |
|
87 | :view_wiki_edits, | |
88 | :add_messages, |
|
88 | :add_messages, | |
89 | :edit_own_messages, |
|
89 | :edit_own_messages, | |
90 | :view_files, |
|
90 | :view_files, | |
91 | :browse_repository, |
|
91 | :browse_repository, | |
92 | :view_changesets] |
|
92 | :view_changesets] | |
93 |
|
93 | |||
94 | Role.non_member.update_attribute :permissions, [:add_issues, |
|
94 | Role.non_member.update_attribute :permissions, [:add_issues, | |
95 | :add_issue_notes, |
|
95 | :add_issue_notes, | |
96 | :save_queries, |
|
96 | :save_queries, | |
97 | :view_gantt, |
|
97 | :view_gantt, | |
98 | :view_calendar, |
|
98 | :view_calendar, | |
99 | :view_time_entries, |
|
99 | :view_time_entries, | |
100 | :comment_news, |
|
100 | :comment_news, | |
101 | :view_documents, |
|
101 | :view_documents, | |
102 | :view_wiki_pages, |
|
102 | :view_wiki_pages, | |
103 | :view_wiki_edits, |
|
103 | :view_wiki_edits, | |
104 | :add_messages, |
|
104 | :add_messages, | |
105 | :view_files, |
|
105 | :view_files, | |
106 | :browse_repository, |
|
106 | :browse_repository, | |
107 | :view_changesets] |
|
107 | :view_changesets] | |
108 |
|
108 | |||
109 | Role.anonymous.update_attribute :permissions, [:view_gantt, |
|
109 | Role.anonymous.update_attribute :permissions, [:view_gantt, | |
110 | :view_calendar, |
|
110 | :view_calendar, | |
111 | :view_time_entries, |
|
111 | :view_time_entries, | |
112 | :view_documents, |
|
112 | :view_documents, | |
113 | :view_wiki_pages, |
|
113 | :view_wiki_pages, | |
114 | :view_wiki_edits, |
|
114 | :view_wiki_edits, | |
115 | :view_files, |
|
115 | :view_files, | |
116 | :browse_repository, |
|
116 | :browse_repository, | |
117 | :view_changesets] |
|
117 | :view_changesets] | |
118 |
|
118 | |||
119 | # Trackers |
|
119 | # Trackers | |
120 | Tracker.create!(:name => l(:default_tracker_bug), :is_in_chlog => true, :is_in_roadmap => false, :position => 1) |
|
120 | Tracker.create!(:name => l(:default_tracker_bug), :is_in_chlog => true, :is_in_roadmap => false, :position => 1) | |
121 | Tracker.create!(:name => l(:default_tracker_feature), :is_in_chlog => true, :is_in_roadmap => true, :position => 2) |
|
121 | Tracker.create!(:name => l(:default_tracker_feature), :is_in_chlog => true, :is_in_roadmap => true, :position => 2) | |
122 | Tracker.create!(:name => l(:default_tracker_support), :is_in_chlog => false, :is_in_roadmap => false, :position => 3) |
|
122 | Tracker.create!(:name => l(:default_tracker_support), :is_in_chlog => false, :is_in_roadmap => false, :position => 3) | |
123 |
|
123 | |||
124 | # Issue statuses |
|
124 | # Issue statuses | |
125 | new = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :is_default => true, :position => 1) |
|
125 | new = IssueStatus.create!(:name => l(:default_issue_status_new), :is_closed => false, :is_default => true, :position => 1) | |
126 | assigned = IssueStatus.create!(:name => l(:default_issue_status_assigned), :is_closed => false, :is_default => false, :position => 2) |
|
126 | assigned = IssueStatus.create!(:name => l(:default_issue_status_assigned), :is_closed => false, :is_default => false, :position => 2) | |
127 | resolved = IssueStatus.create!(:name => l(:default_issue_status_resolved), :is_closed => false, :is_default => false, :position => 3) |
|
127 | resolved = IssueStatus.create!(:name => l(:default_issue_status_resolved), :is_closed => false, :is_default => false, :position => 3) | |
128 | feedback = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :is_default => false, :position => 4) |
|
128 | feedback = IssueStatus.create!(:name => l(:default_issue_status_feedback), :is_closed => false, :is_default => false, :position => 4) | |
129 | closed = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :is_default => false, :position => 5) |
|
129 | closed = IssueStatus.create!(:name => l(:default_issue_status_closed), :is_closed => true, :is_default => false, :position => 5) | |
130 | rejected = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :is_default => false, :position => 6) |
|
130 | rejected = IssueStatus.create!(:name => l(:default_issue_status_rejected), :is_closed => true, :is_default => false, :position => 6) | |
131 |
|
131 | |||
132 | # Workflow |
|
132 | # Workflow | |
133 | Tracker.find(:all).each { |t| |
|
133 | Tracker.find(:all).each { |t| | |
134 | IssueStatus.find(:all).each { |os| |
|
134 | IssueStatus.find(:all).each { |os| | |
135 | IssueStatus.find(:all).each { |ns| |
|
135 | IssueStatus.find(:all).each { |ns| | |
136 | Workflow.create!(:tracker_id => t.id, :role_id => manager.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns |
|
136 | Workflow.create!(:tracker_id => t.id, :role_id => manager.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
137 | } |
|
137 | } | |
138 | } |
|
138 | } | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | Tracker.find(:all).each { |t| |
|
141 | Tracker.find(:all).each { |t| | |
142 | [new, assigned, resolved, feedback].each { |os| |
|
142 | [new, assigned, resolved, feedback].each { |os| | |
143 | [assigned, resolved, feedback, closed].each { |ns| |
|
143 | [assigned, resolved, feedback, closed].each { |ns| | |
144 | Workflow.create!(:tracker_id => t.id, :role_id => developper.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns |
|
144 | Workflow.create!(:tracker_id => t.id, :role_id => developper.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
145 | } |
|
145 | } | |
146 | } |
|
146 | } | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | Tracker.find(:all).each { |t| |
|
149 | Tracker.find(:all).each { |t| | |
150 | [new, assigned, resolved, feedback].each { |os| |
|
150 | [new, assigned, resolved, feedback].each { |os| | |
151 | [closed].each { |ns| |
|
151 | [closed].each { |ns| | |
152 | Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns |
|
152 | Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => os.id, :new_status_id => ns.id) unless os == ns | |
153 | } |
|
153 | } | |
154 | } |
|
154 | } | |
155 | Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => resolved.id, :new_status_id => feedback.id) |
|
155 | Workflow.create!(:tracker_id => t.id, :role_id => reporter.id, :old_status_id => resolved.id, :new_status_id => feedback.id) | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | # Enumerations |
|
158 | # Enumerations | |
159 |
|
|
159 | DocumentCategory.create!(:opt => "DCAT", :name => l(:default_doc_category_user), :position => 1) | |
160 |
|
|
160 | DocumentCategory.create!(:opt => "DCAT", :name => l(:default_doc_category_tech), :position => 2) | |
161 |
|
161 | |||
162 |
|
|
162 | IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_low), :position => 1) | |
163 |
|
|
163 | IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_normal), :position => 2, :is_default => true) | |
164 |
|
|
164 | IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_high), :position => 3) | |
165 |
|
|
165 | IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_urgent), :position => 4) | |
166 |
|
|
166 | IssuePriority.create!(:opt => "IPRI", :name => l(:default_priority_immediate), :position => 5) | |
167 |
|
167 | |||
168 |
|
|
168 | TimeEntryActivity.create!(:opt => "ACTI", :name => l(:default_activity_design), :position => 1) | |
169 |
|
|
169 | TimeEntryActivity.create!(:opt => "ACTI", :name => l(:default_activity_development), :position => 2) | |
170 | end |
|
170 | end | |
171 | true |
|
171 | true | |
172 | end |
|
172 | end | |
173 | end |
|
173 | end | |
174 | end |
|
174 | end | |
175 | end |
|
175 | end | |
176 | end |
|
176 | end |
@@ -1,46 +1,49 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 |
|
19 | |||
20 | class DefaultDataTest < Test::Unit::TestCase |
|
20 | class DefaultDataTest < Test::Unit::TestCase | |
21 | include Redmine::I18n |
|
21 | include Redmine::I18n | |
22 | fixtures :roles |
|
22 | fixtures :roles | |
23 |
|
23 | |||
24 | def test_no_data |
|
24 | def test_no_data | |
25 | assert !Redmine::DefaultData::Loader::no_data? |
|
25 | assert !Redmine::DefaultData::Loader::no_data? | |
26 | Role.delete_all("builtin = 0") |
|
26 | Role.delete_all("builtin = 0") | |
27 | Tracker.delete_all |
|
27 | Tracker.delete_all | |
28 | IssueStatus.delete_all |
|
28 | IssueStatus.delete_all | |
29 | Enumeration.delete_all |
|
29 | Enumeration.delete_all | |
30 | assert Redmine::DefaultData::Loader::no_data? |
|
30 | assert Redmine::DefaultData::Loader::no_data? | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_load |
|
33 | def test_load | |
34 | valid_languages.each do |lang| |
|
34 | valid_languages.each do |lang| | |
35 | begin |
|
35 | begin | |
36 | Role.delete_all("builtin = 0") |
|
36 | Role.delete_all("builtin = 0") | |
37 | Tracker.delete_all |
|
37 | Tracker.delete_all | |
38 | IssueStatus.delete_all |
|
38 | IssueStatus.delete_all | |
39 | Enumeration.delete_all |
|
39 | Enumeration.delete_all | |
40 | assert Redmine::DefaultData::Loader::load(lang) |
|
40 | assert Redmine::DefaultData::Loader::load(lang) | |
|
41 | assert_not_nil DocumentCategory.first | |||
|
42 | assert_not_nil IssuePriority.first | |||
|
43 | assert_not_nil TimeEntryActivity.first | |||
41 | rescue ActiveRecord::RecordInvalid => e |
|
44 | rescue ActiveRecord::RecordInvalid => e | |
42 | assert false, ":#{lang} default data is invalid (#{e.message})." |
|
45 | assert false, ":#{lang} default data is invalid (#{e.message})." | |
43 | end |
|
46 | end | |
44 | end |
|
47 | end | |
45 | end |
|
48 | end | |
46 | end |
|
49 | end |
General Comments 0
You need to be logged in to leave comments.
Login now