@@ -1,202 +1,216 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 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 | class Project < ActiveRecord::Base |
|
18 | class Project < ActiveRecord::Base | |
19 | # Project statuses |
|
19 | # Project statuses | |
20 | STATUS_ACTIVE = 1 |
|
20 | STATUS_ACTIVE = 1 | |
21 | STATUS_ARCHIVED = 9 |
|
21 | STATUS_ARCHIVED = 9 | |
22 |
|
22 | |||
23 | has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}" |
|
23 | has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}" | |
24 | has_many :users, :through => :members |
|
24 | has_many :users, :through => :members | |
25 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
25 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
26 | has_many :enabled_modules, :dependent => :delete_all |
|
26 | has_many :enabled_modules, :dependent => :delete_all | |
27 | has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" |
|
27 | has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" | |
28 | has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] |
|
28 | has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] | |
29 | has_many :issue_changes, :through => :issues, :source => :journals |
|
29 | has_many :issue_changes, :through => :issues, :source => :journals | |
30 | has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" |
|
30 | has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" | |
31 | has_many :time_entries, :dependent => :delete_all |
|
31 | has_many :time_entries, :dependent => :delete_all | |
32 | has_many :queries, :dependent => :delete_all |
|
32 | has_many :queries, :dependent => :delete_all | |
33 | has_many :documents, :dependent => :destroy |
|
33 | has_many :documents, :dependent => :destroy | |
34 | has_many :news, :dependent => :delete_all, :include => :author |
|
34 | has_many :news, :dependent => :delete_all, :include => :author | |
35 | has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" |
|
35 | has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" | |
36 | has_many :boards, :order => "position ASC" |
|
36 | has_many :boards, :order => "position ASC" | |
37 | has_one :repository, :dependent => :destroy |
|
37 | has_one :repository, :dependent => :destroy | |
38 | has_many :changesets, :through => :repository |
|
38 | has_many :changesets, :through => :repository | |
39 | has_one :wiki, :dependent => :destroy |
|
39 | has_one :wiki, :dependent => :destroy | |
40 | # Custom field for the project issues |
|
40 | # Custom field for the project issues | |
41 | has_and_belongs_to_many :custom_fields, |
|
41 | has_and_belongs_to_many :custom_fields, | |
42 | :class_name => 'IssueCustomField', |
|
42 | :class_name => 'IssueCustomField', | |
43 | :order => "#{CustomField.table_name}.position", |
|
43 | :order => "#{CustomField.table_name}.position", | |
44 | :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", |
|
44 | :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", | |
45 | :association_foreign_key => 'custom_field_id' |
|
45 | :association_foreign_key => 'custom_field_id' | |
46 |
|
46 | |||
47 | acts_as_tree :order => "name", :counter_cache => true |
|
47 | acts_as_tree :order => "name", :counter_cache => true | |
48 |
|
48 | |||
49 | acts_as_searchable :columns => ['name', 'description'], :project_key => 'id' |
|
49 | acts_as_searchable :columns => ['name', 'description'], :project_key => 'id' | |
50 | acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"}, |
|
50 | acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"}, | |
51 | :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}} |
|
51 | :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}} | |
52 |
|
52 | |||
53 | attr_protected :status, :enabled_module_names |
|
53 | attr_protected :status, :enabled_module_names | |
54 |
|
54 | |||
55 | validates_presence_of :name, :description, :identifier |
|
55 | validates_presence_of :name, :description, :identifier | |
56 | validates_uniqueness_of :name, :identifier |
|
56 | validates_uniqueness_of :name, :identifier | |
57 | validates_associated :custom_values, :on => :update |
|
57 | validates_associated :custom_values, :on => :update | |
58 | validates_associated :repository, :wiki |
|
58 | validates_associated :repository, :wiki | |
59 | validates_length_of :name, :maximum => 30 |
|
59 | validates_length_of :name, :maximum => 30 | |
60 | validates_length_of :description, :maximum => 255 |
|
60 | validates_length_of :description, :maximum => 255 | |
61 | validates_length_of :homepage, :maximum => 60 |
|
61 | validates_length_of :homepage, :maximum => 60 | |
62 | validates_length_of :identifier, :in => 3..20 |
|
62 | validates_length_of :identifier, :in => 3..20 | |
63 | validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ |
|
63 | validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ | |
64 |
|
64 | |||
65 | before_destroy :delete_all_members |
|
65 | before_destroy :delete_all_members | |
66 |
|
66 | |||
67 | def identifier=(identifier) |
|
67 | def identifier=(identifier) | |
68 | super unless identifier_frozen? |
|
68 | super unless identifier_frozen? | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
71 | def identifier_frozen? |
|
71 | def identifier_frozen? | |
72 | errors[:identifier].nil? && !(new_record? || identifier.blank?) |
|
72 | errors[:identifier].nil? && !(new_record? || identifier.blank?) | |
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | def issues_with_subprojects(include_subprojects=false) |
|
75 | def issues_with_subprojects(include_subprojects=false) | |
76 | conditions = nil |
|
76 | conditions = nil | |
77 | if include_subprojects && !active_children.empty? |
|
77 | if include_subprojects && !active_children.empty? | |
78 | ids = [id] + active_children.collect {|c| c.id} |
|
78 | ids = [id] + active_children.collect {|c| c.id} | |
79 | conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"] |
|
79 | conditions = ["#{Issue.table_name}.project_id IN (#{ids.join(',')})"] | |
80 | end |
|
80 | end | |
81 | conditions ||= ["#{Issue.table_name}.project_id = ?", id] |
|
81 | conditions ||= ["#{Issue.table_name}.project_id = ?", id] | |
82 | # Quick and dirty fix for Rails 2 compatibility |
|
82 | # Quick and dirty fix for Rails 2 compatibility | |
83 | Issue.send(:with_scope, :find => { :conditions => conditions }) do |
|
83 | Issue.send(:with_scope, :find => { :conditions => conditions }) do | |
84 | yield |
|
84 | yield | |
85 | end |
|
85 | end | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | # Return all issues status changes for the project between the 2 given dates |
|
88 | # Return all issues status changes for the project between the 2 given dates | |
89 | def issues_status_changes(from, to) |
|
89 | def issues_status_changes(from, to) | |
90 | Journal.find(:all, :include => [:issue, :details, :user], |
|
90 | Journal.find(:all, :include => [:issue, :details, :user], | |
91 | :conditions => ["#{Journal.table_name}.journalized_type = 'Issue'" + |
|
91 | :conditions => ["#{Journal.table_name}.journalized_type = 'Issue'" + | |
92 | " AND #{Issue.table_name}.project_id = ?" + |
|
92 | " AND #{Issue.table_name}.project_id = ?" + | |
93 | " AND #{JournalDetail.table_name}.prop_key = 'status_id'" + |
|
93 | " AND #{JournalDetail.table_name}.prop_key = 'status_id'" + | |
94 | " AND #{Journal.table_name}.created_on BETWEEN ? AND ?", |
|
94 | " AND #{Journal.table_name}.created_on BETWEEN ? AND ?", | |
95 | id, from, to+1]) |
|
95 | id, from, to+1]) | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | # returns latest created projects |
|
98 | # returns latest created projects | |
99 | # non public projects will be returned only if user is a member of those |
|
99 | # non public projects will be returned only if user is a member of those | |
100 | def self.latest(user=nil, count=5) |
|
100 | def self.latest(user=nil, count=5) | |
101 | find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC") |
|
101 | find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC") | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | def self.visible_by(user=nil) |
|
104 | def self.visible_by(user=nil) | |
105 | if user && user.admin? |
|
105 | if user && user.admin? | |
106 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" |
|
106 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" | |
107 | elsif user && user.memberships.any? |
|
107 | elsif user && user.memberships.any? | |
108 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))" |
|
108 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))" | |
109 | else |
|
109 | else | |
110 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}" |
|
110 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}" | |
111 | end |
|
111 | end | |
112 | end |
|
112 | end | |
113 |
|
113 | |||
|
114 | def self.find(*args) | |||
|
115 | if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/) | |||
|
116 | project = find_by_identifier(*args) | |||
|
117 | raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil? | |||
|
118 | project | |||
|
119 | else | |||
|
120 | super | |||
|
121 | end | |||
|
122 | end | |||
|
123 | ||||
|
124 | def to_param | |||
|
125 | identifier | |||
|
126 | end | |||
|
127 | ||||
114 | def active? |
|
128 | def active? | |
115 | self.status == STATUS_ACTIVE |
|
129 | self.status == STATUS_ACTIVE | |
116 | end |
|
130 | end | |
117 |
|
131 | |||
118 | def archive |
|
132 | def archive | |
119 | # Archive subprojects if any |
|
133 | # Archive subprojects if any | |
120 | children.each do |subproject| |
|
134 | children.each do |subproject| | |
121 | subproject.archive |
|
135 | subproject.archive | |
122 | end |
|
136 | end | |
123 | update_attribute :status, STATUS_ARCHIVED |
|
137 | update_attribute :status, STATUS_ARCHIVED | |
124 | end |
|
138 | end | |
125 |
|
139 | |||
126 | def unarchive |
|
140 | def unarchive | |
127 | return false if parent && !parent.active? |
|
141 | return false if parent && !parent.active? | |
128 | update_attribute :status, STATUS_ACTIVE |
|
142 | update_attribute :status, STATUS_ACTIVE | |
129 | end |
|
143 | end | |
130 |
|
144 | |||
131 | def active_children |
|
145 | def active_children | |
132 | children.select {|child| child.active?} |
|
146 | children.select {|child| child.active?} | |
133 | end |
|
147 | end | |
134 |
|
148 | |||
135 | # Deletes all project's members |
|
149 | # Deletes all project's members | |
136 | def delete_all_members |
|
150 | def delete_all_members | |
137 | Member.delete_all(['project_id = ?', id]) |
|
151 | Member.delete_all(['project_id = ?', id]) | |
138 | end |
|
152 | end | |
139 |
|
153 | |||
140 | # Users issues can be assigned to |
|
154 | # Users issues can be assigned to | |
141 | def assignable_users |
|
155 | def assignable_users | |
142 | members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort |
|
156 | members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort | |
143 | end |
|
157 | end | |
144 |
|
158 | |||
145 | # Returns the mail adresses of users that should be always notified on project events |
|
159 | # Returns the mail adresses of users that should be always notified on project events | |
146 | def recipients |
|
160 | def recipients | |
147 | members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail} |
|
161 | members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail} | |
148 | end |
|
162 | end | |
149 |
|
163 | |||
150 | # Returns an array of all custom fields enabled for project issues |
|
164 | # Returns an array of all custom fields enabled for project issues | |
151 | # (explictly associated custom fields and custom fields enabled for all projects) |
|
165 | # (explictly associated custom fields and custom fields enabled for all projects) | |
152 | def custom_fields_for_issues(tracker) |
|
166 | def custom_fields_for_issues(tracker) | |
153 | all_custom_fields.select {|c| tracker.custom_fields.include? c } |
|
167 | all_custom_fields.select {|c| tracker.custom_fields.include? c } | |
154 | end |
|
168 | end | |
155 |
|
169 | |||
156 | def all_custom_fields |
|
170 | def all_custom_fields | |
157 | @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq |
|
171 | @all_custom_fields ||= (IssueCustomField.for_all + custom_fields).uniq | |
158 | end |
|
172 | end | |
159 |
|
173 | |||
160 | def <=>(project) |
|
174 | def <=>(project) | |
161 | name.downcase <=> project.name.downcase |
|
175 | name.downcase <=> project.name.downcase | |
162 | end |
|
176 | end | |
163 |
|
177 | |||
164 | def allows_to?(action) |
|
178 | def allows_to?(action) | |
165 | if action.is_a? Hash |
|
179 | if action.is_a? Hash | |
166 | allowed_actions.include? "#{action[:controller]}/#{action[:action]}" |
|
180 | allowed_actions.include? "#{action[:controller]}/#{action[:action]}" | |
167 | else |
|
181 | else | |
168 | allowed_permissions.include? action |
|
182 | allowed_permissions.include? action | |
169 | end |
|
183 | end | |
170 | end |
|
184 | end | |
171 |
|
185 | |||
172 | def module_enabled?(module_name) |
|
186 | def module_enabled?(module_name) | |
173 | module_name = module_name.to_s |
|
187 | module_name = module_name.to_s | |
174 | enabled_modules.detect {|m| m.name == module_name} |
|
188 | enabled_modules.detect {|m| m.name == module_name} | |
175 | end |
|
189 | end | |
176 |
|
190 | |||
177 | def enabled_module_names=(module_names) |
|
191 | def enabled_module_names=(module_names) | |
178 | enabled_modules.clear |
|
192 | enabled_modules.clear | |
179 | module_names = [] unless module_names && module_names.is_a?(Array) |
|
193 | module_names = [] unless module_names && module_names.is_a?(Array) | |
180 | module_names.each do |name| |
|
194 | module_names.each do |name| | |
181 | enabled_modules << EnabledModule.new(:name => name.to_s) |
|
195 | enabled_modules << EnabledModule.new(:name => name.to_s) | |
182 | end |
|
196 | end | |
183 | end |
|
197 | end | |
184 |
|
198 | |||
185 | protected |
|
199 | protected | |
186 | def validate |
|
200 | def validate | |
187 | errors.add(parent_id, " must be a root project") if parent and parent.parent |
|
201 | errors.add(parent_id, " must be a root project") if parent and parent.parent | |
188 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 |
|
202 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 | |
189 | end |
|
203 | end | |
190 |
|
204 | |||
191 | private |
|
205 | private | |
192 | def allowed_permissions |
|
206 | def allowed_permissions | |
193 | @allowed_permissions ||= begin |
|
207 | @allowed_permissions ||= begin | |
194 | module_names = enabled_modules.collect {|m| m.name} |
|
208 | module_names = enabled_modules.collect {|m| m.name} | |
195 | Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name} |
|
209 | Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name} | |
196 | end |
|
210 | end | |
197 | end |
|
211 | end | |
198 |
|
212 | |||
199 | def allowed_actions |
|
213 | def allowed_actions | |
200 | @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten |
|
214 | @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten | |
201 | end |
|
215 | end | |
202 | end |
|
216 | end |
@@ -1,45 +1,45 | |||||
1 | --- |
|
1 | --- | |
2 | projects_001: |
|
2 | projects_001: | |
3 | created_on: 2006-07-19 19:13:59 +02:00 |
|
3 | created_on: 2006-07-19 19:13:59 +02:00 | |
4 | name: eCookbook |
|
4 | name: eCookbook | |
5 | updated_on: 2006-07-19 22:53:01 +02:00 |
|
5 | updated_on: 2006-07-19 22:53:01 +02:00 | |
6 | projects_count: 2 |
|
6 | projects_count: 2 | |
7 | id: 1 |
|
7 | id: 1 | |
8 | description: Recipes management application |
|
8 | description: Recipes management application | |
9 | homepage: http://ecookbook.somenet.foo/ |
|
9 | homepage: http://ecookbook.somenet.foo/ | |
10 | is_public: true |
|
10 | is_public: true | |
11 | identifier: ecookbook |
|
11 | identifier: ecookbook | |
12 | parent_id: |
|
12 | parent_id: | |
13 | projects_002: |
|
13 | projects_002: | |
14 | created_on: 2006-07-19 19:14:19 +02:00 |
|
14 | created_on: 2006-07-19 19:14:19 +02:00 | |
15 | name: OnlineStore |
|
15 | name: OnlineStore | |
16 | updated_on: 2006-07-19 19:14:19 +02:00 |
|
16 | updated_on: 2006-07-19 19:14:19 +02:00 | |
17 | projects_count: 0 |
|
17 | projects_count: 0 | |
18 | id: 2 |
|
18 | id: 2 | |
19 | description: E-commerce web site |
|
19 | description: E-commerce web site | |
20 | homepage: "" |
|
20 | homepage: "" | |
21 | is_public: false |
|
21 | is_public: false | |
22 | identifier: onlinestore |
|
22 | identifier: onlinestore | |
23 | parent_id: |
|
23 | parent_id: | |
24 | projects_003: |
|
24 | projects_003: | |
25 | created_on: 2006-07-19 19:15:21 +02:00 |
|
25 | created_on: 2006-07-19 19:15:21 +02:00 | |
26 | name: eCookbook Subproject 1 |
|
26 | name: eCookbook Subproject 1 | |
27 | updated_on: 2006-07-19 19:18:12 +02:00 |
|
27 | updated_on: 2006-07-19 19:18:12 +02:00 | |
28 | projects_count: 0 |
|
28 | projects_count: 0 | |
29 | id: 3 |
|
29 | id: 3 | |
30 | description: eCookBook Subproject 1 |
|
30 | description: eCookBook Subproject 1 | |
31 | homepage: "" |
|
31 | homepage: "" | |
32 | is_public: true |
|
32 | is_public: true | |
33 | identifier: subproject1 |
|
33 | identifier: subproject1 | |
34 | parent_id: 1 |
|
34 | parent_id: 1 | |
35 | projects_004: |
|
35 | projects_004: | |
36 | created_on: 2006-07-19 19:15:51 +02:00 |
|
36 | created_on: 2006-07-19 19:15:51 +02:00 | |
37 | name: eCookbook Subproject 2 |
|
37 | name: eCookbook Subproject 2 | |
38 | updated_on: 2006-07-19 19:17:07 +02:00 |
|
38 | updated_on: 2006-07-19 19:17:07 +02:00 | |
39 | projects_count: 0 |
|
39 | projects_count: 0 | |
40 | id: 4 |
|
40 | id: 4 | |
41 | description: eCookbook Subproject 2 |
|
41 | description: eCookbook Subproject 2 | |
42 | homepage: "" |
|
42 | homepage: "" | |
43 | is_public: true |
|
43 | is_public: true | |
44 |
identifier: subproject |
|
44 | identifier: subproject2 | |
45 | parent_id: 1 |
|
45 | parent_id: 1 |
@@ -1,163 +1,163 | |||||
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'issues_controller' |
|
19 | require 'issues_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class IssuesController; def rescue_action(e) raise e end; end |
|
22 | class IssuesController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class IssuesControllerTest < Test::Unit::TestCase |
|
24 | class IssuesControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, |
|
25 | fixtures :projects, | |
26 | :users, |
|
26 | :users, | |
27 | :roles, |
|
27 | :roles, | |
28 | :members, |
|
28 | :members, | |
29 | :issues, |
|
29 | :issues, | |
30 | :issue_statuses, |
|
30 | :issue_statuses, | |
31 | :trackers, |
|
31 | :trackers, | |
32 | :issue_categories, |
|
32 | :issue_categories, | |
33 | :enabled_modules, |
|
33 | :enabled_modules, | |
34 | :enumerations, |
|
34 | :enumerations, | |
35 | :attachments |
|
35 | :attachments | |
36 |
|
36 | |||
37 | def setup |
|
37 | def setup | |
38 | @controller = IssuesController.new |
|
38 | @controller = IssuesController.new | |
39 | @request = ActionController::TestRequest.new |
|
39 | @request = ActionController::TestRequest.new | |
40 | @response = ActionController::TestResponse.new |
|
40 | @response = ActionController::TestResponse.new | |
41 | User.current = nil |
|
41 | User.current = nil | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_index |
|
44 | def test_index | |
45 | get :index |
|
45 | get :index | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'index.rhtml' |
|
47 | assert_template 'index.rhtml' | |
48 | assert_not_nil assigns(:issues) |
|
48 | assert_not_nil assigns(:issues) | |
49 | assert_nil assigns(:project) |
|
49 | assert_nil assigns(:project) | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_index_with_project |
|
52 | def test_index_with_project | |
53 | get :index, :project_id => 1 |
|
53 | get :index, :project_id => 1 | |
54 | assert_response :success |
|
54 | assert_response :success | |
55 | assert_template 'index.rhtml' |
|
55 | assert_template 'index.rhtml' | |
56 | assert_not_nil assigns(:issues) |
|
56 | assert_not_nil assigns(:issues) | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def test_index_with_project_and_filter |
|
59 | def test_index_with_project_and_filter | |
60 | get :index, :project_id => 1, :set_filter => 1 |
|
60 | get :index, :project_id => 1, :set_filter => 1 | |
61 | assert_response :success |
|
61 | assert_response :success | |
62 | assert_template 'index.rhtml' |
|
62 | assert_template 'index.rhtml' | |
63 | assert_not_nil assigns(:issues) |
|
63 | assert_not_nil assigns(:issues) | |
64 | end |
|
64 | end | |
65 |
|
65 | |||
66 | def test_index_csv_with_project |
|
66 | def test_index_csv_with_project | |
67 | get :index, :format => 'csv' |
|
67 | get :index, :format => 'csv' | |
68 | assert_response :success |
|
68 | assert_response :success | |
69 | assert_not_nil assigns(:issues) |
|
69 | assert_not_nil assigns(:issues) | |
70 | assert_equal 'text/csv', @response.content_type |
|
70 | assert_equal 'text/csv', @response.content_type | |
71 |
|
71 | |||
72 | get :index, :project_id => 1, :format => 'csv' |
|
72 | get :index, :project_id => 1, :format => 'csv' | |
73 | assert_response :success |
|
73 | assert_response :success | |
74 | assert_not_nil assigns(:issues) |
|
74 | assert_not_nil assigns(:issues) | |
75 | assert_equal 'text/csv', @response.content_type |
|
75 | assert_equal 'text/csv', @response.content_type | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def test_index_pdf |
|
78 | def test_index_pdf | |
79 | get :index, :format => 'pdf' |
|
79 | get :index, :format => 'pdf' | |
80 | assert_response :success |
|
80 | assert_response :success | |
81 | assert_not_nil assigns(:issues) |
|
81 | assert_not_nil assigns(:issues) | |
82 | assert_equal 'application/pdf', @response.content_type |
|
82 | assert_equal 'application/pdf', @response.content_type | |
83 |
|
83 | |||
84 | get :index, :project_id => 1, :format => 'pdf' |
|
84 | get :index, :project_id => 1, :format => 'pdf' | |
85 | assert_response :success |
|
85 | assert_response :success | |
86 | assert_not_nil assigns(:issues) |
|
86 | assert_not_nil assigns(:issues) | |
87 | assert_equal 'application/pdf', @response.content_type |
|
87 | assert_equal 'application/pdf', @response.content_type | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | def test_changes |
|
90 | def test_changes | |
91 | get :changes, :project_id => 1 |
|
91 | get :changes, :project_id => 1 | |
92 | assert_response :success |
|
92 | assert_response :success | |
93 | assert_not_nil assigns(:changes) |
|
93 | assert_not_nil assigns(:changes) | |
94 | assert_equal 'application/atom+xml', @response.content_type |
|
94 | assert_equal 'application/atom+xml', @response.content_type | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def test_show |
|
97 | def test_show | |
98 | get :show, :id => 1 |
|
98 | get :show, :id => 1 | |
99 | assert_response :success |
|
99 | assert_response :success | |
100 | assert_template 'show.rhtml' |
|
100 | assert_template 'show.rhtml' | |
101 | assert_not_nil assigns(:issue) |
|
101 | assert_not_nil assigns(:issue) | |
102 | end |
|
102 | end | |
103 |
|
103 | |||
104 | def test_get_edit |
|
104 | def test_get_edit | |
105 | @request.session[:user_id] = 2 |
|
105 | @request.session[:user_id] = 2 | |
106 | get :edit, :id => 1 |
|
106 | get :edit, :id => 1 | |
107 | assert_response :success |
|
107 | assert_response :success | |
108 | assert_template 'edit' |
|
108 | assert_template 'edit' | |
109 | assert_not_nil assigns(:issue) |
|
109 | assert_not_nil assigns(:issue) | |
110 | assert_equal Issue.find(1), assigns(:issue) |
|
110 | assert_equal Issue.find(1), assigns(:issue) | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_post_edit |
|
113 | def test_post_edit | |
114 | @request.session[:user_id] = 2 |
|
114 | @request.session[:user_id] = 2 | |
115 | post :edit, :id => 1, :issue => {:subject => 'Modified subject'} |
|
115 | post :edit, :id => 1, :issue => {:subject => 'Modified subject'} | |
116 | assert_redirected_to 'issues/show/1' |
|
116 | assert_redirected_to 'issues/show/1' | |
117 | assert_equal 'Modified subject', Issue.find(1).subject |
|
117 | assert_equal 'Modified subject', Issue.find(1).subject | |
118 | end |
|
118 | end | |
119 |
|
119 | |||
120 | def test_post_change_status |
|
120 | def test_post_change_status | |
121 | issue = Issue.find(1) |
|
121 | issue = Issue.find(1) | |
122 | assert_equal 1, issue.status_id |
|
122 | assert_equal 1, issue.status_id | |
123 | @request.session[:user_id] = 2 |
|
123 | @request.session[:user_id] = 2 | |
124 | post :change_status, :id => 1, |
|
124 | post :change_status, :id => 1, | |
125 | :new_status_id => 2, |
|
125 | :new_status_id => 2, | |
126 | :issue => { :assigned_to_id => 3 }, |
|
126 | :issue => { :assigned_to_id => 3 }, | |
127 | :notes => 'Assigned to dlopper', |
|
127 | :notes => 'Assigned to dlopper', | |
128 | :confirm => 1 |
|
128 | :confirm => 1 | |
129 | assert_redirected_to 'issues/show/1' |
|
129 | assert_redirected_to 'issues/show/1' | |
130 | issue.reload |
|
130 | issue.reload | |
131 | assert_equal 2, issue.status_id |
|
131 | assert_equal 2, issue.status_id | |
132 | j = issue.journals.find(:first, :order => 'created_on DESC') |
|
132 | j = issue.journals.find(:first, :order => 'created_on DESC') | |
133 | assert_equal 'Assigned to dlopper', j.notes |
|
133 | assert_equal 'Assigned to dlopper', j.notes | |
134 | assert_equal 2, j.details.size |
|
134 | assert_equal 2, j.details.size | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def test_context_menu |
|
137 | def test_context_menu | |
138 | @request.session[:user_id] = 2 |
|
138 | @request.session[:user_id] = 2 | |
139 | get :context_menu, :id => 1 |
|
139 | get :context_menu, :id => 1 | |
140 | assert_response :success |
|
140 | assert_response :success | |
141 | assert_template 'context_menu' |
|
141 | assert_template 'context_menu' | |
142 | end |
|
142 | end | |
143 |
|
143 | |||
144 | def test_destroy |
|
144 | def test_destroy | |
145 | @request.session[:user_id] = 2 |
|
145 | @request.session[:user_id] = 2 | |
146 | post :destroy, :id => 1 |
|
146 | post :destroy, :id => 1 | |
147 |
assert_redirected_to 'projects/ |
|
147 | assert_redirected_to 'projects/ecookbook/issues' | |
148 | assert_nil Issue.find_by_id(1) |
|
148 | assert_nil Issue.find_by_id(1) | |
149 | end |
|
149 | end | |
150 |
|
150 | |||
151 | def test_destroy_attachment |
|
151 | def test_destroy_attachment | |
152 | issue = Issue.find(3) |
|
152 | issue = Issue.find(3) | |
153 | a = issue.attachments.size |
|
153 | a = issue.attachments.size | |
154 | @request.session[:user_id] = 2 |
|
154 | @request.session[:user_id] = 2 | |
155 | post :destroy_attachment, :id => 3, :attachment_id => 1 |
|
155 | post :destroy_attachment, :id => 3, :attachment_id => 1 | |
156 | assert_redirected_to 'issues/show/3' |
|
156 | assert_redirected_to 'issues/show/3' | |
157 | assert_nil Attachment.find_by_id(1) |
|
157 | assert_nil Attachment.find_by_id(1) | |
158 | issue.reload |
|
158 | issue.reload | |
159 | assert_equal((a-1), issue.attachments.size) |
|
159 | assert_equal((a-1), issue.attachments.size) | |
160 | j = issue.journals.find(:first, :order => 'created_on DESC') |
|
160 | j = issue.journals.find(:first, :order => 'created_on DESC') | |
161 | assert_equal 'attachment', j.details.first.property |
|
161 | assert_equal 'attachment', j.details.first.property | |
162 | end |
|
162 | end | |
163 | end |
|
163 | end |
@@ -1,257 +1,265 | |||||
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'projects_controller' |
|
19 | require 'projects_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class ProjectsController; def rescue_action(e) raise e end; end |
|
22 | class ProjectsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class ProjectsControllerTest < Test::Unit::TestCase |
|
24 | class ProjectsControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations |
|
25 | fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = ProjectsController.new |
|
28 | @controller = ProjectsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
33 | def test_index |
|
33 | def test_index | |
34 | get :index |
|
34 | get :index | |
35 | assert_response :success |
|
35 | assert_response :success | |
36 | assert_template 'list' |
|
36 | assert_template 'list' | |
37 | end |
|
37 | end | |
38 |
|
38 | |||
39 | def test_list |
|
39 | def test_list | |
40 | get :list |
|
40 | get :list | |
41 | assert_response :success |
|
41 | assert_response :success | |
42 | assert_template 'list' |
|
42 | assert_template 'list' | |
43 | assert_not_nil assigns(:project_tree) |
|
43 | assert_not_nil assigns(:project_tree) | |
44 | # Root project as hash key |
|
44 | # Root project as hash key | |
45 | assert assigns(:project_tree).has_key?(Project.find(1)) |
|
45 | assert assigns(:project_tree).has_key?(Project.find(1)) | |
46 | # Subproject in corresponding value |
|
46 | # Subproject in corresponding value | |
47 | assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3)) |
|
47 | assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3)) | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def test_show |
|
50 | def test_show_by_id | |
51 | get :show, :id => 1 |
|
51 | get :show, :id => 1 | |
52 | assert_response :success |
|
52 | assert_response :success | |
53 | assert_template 'show' |
|
53 | assert_template 'show' | |
54 | assert_not_nil assigns(:project) |
|
54 | assert_not_nil assigns(:project) | |
55 | end |
|
55 | end | |
|
56 | ||||
|
57 | def test_show_by_identifier | |||
|
58 | get :show, :id => 'ecookbook' | |||
|
59 | assert_response :success | |||
|
60 | assert_template 'show' | |||
|
61 | assert_not_nil assigns(:project) | |||
|
62 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |||
|
63 | end | |||
56 |
|
64 | |||
57 | def test_settings |
|
65 | def test_settings | |
58 | @request.session[:user_id] = 2 # manager |
|
66 | @request.session[:user_id] = 2 # manager | |
59 | get :settings, :id => 1 |
|
67 | get :settings, :id => 1 | |
60 | assert_response :success |
|
68 | assert_response :success | |
61 | assert_template 'settings' |
|
69 | assert_template 'settings' | |
62 | end |
|
70 | end | |
63 |
|
71 | |||
64 | def test_edit |
|
72 | def test_edit | |
65 | @request.session[:user_id] = 2 # manager |
|
73 | @request.session[:user_id] = 2 # manager | |
66 | post :edit, :id => 1, :project => {:name => 'Test changed name'} |
|
74 | post :edit, :id => 1, :project => {:name => 'Test changed name'} | |
67 |
assert_redirected_to 'projects/settings/ |
|
75 | assert_redirected_to 'projects/settings/ecookbook' | |
68 | project = Project.find(1) |
|
76 | project = Project.find(1) | |
69 | assert_equal 'Test changed name', project.name |
|
77 | assert_equal 'Test changed name', project.name | |
70 | end |
|
78 | end | |
71 |
|
79 | |||
72 | def test_get_destroy |
|
80 | def test_get_destroy | |
73 | @request.session[:user_id] = 1 # admin |
|
81 | @request.session[:user_id] = 1 # admin | |
74 | get :destroy, :id => 1 |
|
82 | get :destroy, :id => 1 | |
75 | assert_response :success |
|
83 | assert_response :success | |
76 | assert_template 'destroy' |
|
84 | assert_template 'destroy' | |
77 | assert_not_nil Project.find_by_id(1) |
|
85 | assert_not_nil Project.find_by_id(1) | |
78 | end |
|
86 | end | |
79 |
|
87 | |||
80 | def test_post_destroy |
|
88 | def test_post_destroy | |
81 | @request.session[:user_id] = 1 # admin |
|
89 | @request.session[:user_id] = 1 # admin | |
82 | post :destroy, :id => 1, :confirm => 1 |
|
90 | post :destroy, :id => 1, :confirm => 1 | |
83 | assert_redirected_to 'admin/projects' |
|
91 | assert_redirected_to 'admin/projects' | |
84 | assert_nil Project.find_by_id(1) |
|
92 | assert_nil Project.find_by_id(1) | |
85 | end |
|
93 | end | |
86 |
|
94 | |||
87 | def test_list_documents |
|
95 | def test_list_documents | |
88 | get :list_documents, :id => 1 |
|
96 | get :list_documents, :id => 1 | |
89 | assert_response :success |
|
97 | assert_response :success | |
90 | assert_template 'list_documents' |
|
98 | assert_template 'list_documents' | |
91 | assert_not_nil assigns(:grouped) |
|
99 | assert_not_nil assigns(:grouped) | |
92 | end |
|
100 | end | |
93 |
|
101 | |||
94 | def test_bulk_edit_issues |
|
102 | def test_bulk_edit_issues | |
95 | @request.session[:user_id] = 2 |
|
103 | @request.session[:user_id] = 2 | |
96 | # update issues priority |
|
104 | # update issues priority | |
97 | post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' |
|
105 | post :bulk_edit_issues, :id => 1, :issue_ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => '' | |
98 | assert_response 302 |
|
106 | assert_response 302 | |
99 | # check that the issues were updated |
|
107 | # check that the issues were updated | |
100 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
|
108 | assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | |
101 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes |
|
109 | assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes | |
102 | end |
|
110 | end | |
103 |
|
111 | |||
104 | def test_move_issues_to_another_project |
|
112 | def test_move_issues_to_another_project | |
105 | @request.session[:user_id] = 1 |
|
113 | @request.session[:user_id] = 1 | |
106 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2 |
|
114 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2 | |
107 |
assert_redirected_to 'projects/ |
|
115 | assert_redirected_to 'projects/ecookbook/issues' | |
108 | assert_equal 2, Issue.find(1).project_id |
|
116 | assert_equal 2, Issue.find(1).project_id | |
109 | assert_equal 2, Issue.find(2).project_id |
|
117 | assert_equal 2, Issue.find(2).project_id | |
110 | end |
|
118 | end | |
111 |
|
119 | |||
112 | def test_move_issues_to_another_tracker |
|
120 | def test_move_issues_to_another_tracker | |
113 | @request.session[:user_id] = 1 |
|
121 | @request.session[:user_id] = 1 | |
114 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 3 |
|
122 | post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 3 | |
115 |
assert_redirected_to 'projects/ |
|
123 | assert_redirected_to 'projects/ecookbook/issues' | |
116 | assert_equal 3, Issue.find(1).tracker_id |
|
124 | assert_equal 3, Issue.find(1).tracker_id | |
117 | assert_equal 3, Issue.find(2).tracker_id |
|
125 | assert_equal 3, Issue.find(2).tracker_id | |
118 | end |
|
126 | end | |
119 |
|
127 | |||
120 | def test_list_files |
|
128 | def test_list_files | |
121 | get :list_files, :id => 1 |
|
129 | get :list_files, :id => 1 | |
122 | assert_response :success |
|
130 | assert_response :success | |
123 | assert_template 'list_files' |
|
131 | assert_template 'list_files' | |
124 | assert_not_nil assigns(:versions) |
|
132 | assert_not_nil assigns(:versions) | |
125 | end |
|
133 | end | |
126 |
|
134 | |||
127 | def test_changelog |
|
135 | def test_changelog | |
128 | get :changelog, :id => 1 |
|
136 | get :changelog, :id => 1 | |
129 | assert_response :success |
|
137 | assert_response :success | |
130 | assert_template 'changelog' |
|
138 | assert_template 'changelog' | |
131 | assert_not_nil assigns(:versions) |
|
139 | assert_not_nil assigns(:versions) | |
132 | end |
|
140 | end | |
133 |
|
141 | |||
134 | def test_roadmap |
|
142 | def test_roadmap | |
135 | get :roadmap, :id => 1 |
|
143 | get :roadmap, :id => 1 | |
136 | assert_response :success |
|
144 | assert_response :success | |
137 | assert_template 'roadmap' |
|
145 | assert_template 'roadmap' | |
138 | assert_not_nil assigns(:versions) |
|
146 | assert_not_nil assigns(:versions) | |
139 | # Version with no date set appears |
|
147 | # Version with no date set appears | |
140 | assert assigns(:versions).include?(Version.find(3)) |
|
148 | assert assigns(:versions).include?(Version.find(3)) | |
141 | # Completed version doesn't appear |
|
149 | # Completed version doesn't appear | |
142 | assert !assigns(:versions).include?(Version.find(1)) |
|
150 | assert !assigns(:versions).include?(Version.find(1)) | |
143 | end |
|
151 | end | |
144 |
|
152 | |||
145 | def test_roadmap_with_completed_versions |
|
153 | def test_roadmap_with_completed_versions | |
146 | get :roadmap, :id => 1, :completed => 1 |
|
154 | get :roadmap, :id => 1, :completed => 1 | |
147 | assert_response :success |
|
155 | assert_response :success | |
148 | assert_template 'roadmap' |
|
156 | assert_template 'roadmap' | |
149 | assert_not_nil assigns(:versions) |
|
157 | assert_not_nil assigns(:versions) | |
150 | # Version with no date set appears |
|
158 | # Version with no date set appears | |
151 | assert assigns(:versions).include?(Version.find(3)) |
|
159 | assert assigns(:versions).include?(Version.find(3)) | |
152 | # Completed version appears |
|
160 | # Completed version appears | |
153 | assert assigns(:versions).include?(Version.find(1)) |
|
161 | assert assigns(:versions).include?(Version.find(1)) | |
154 | end |
|
162 | end | |
155 |
|
163 | |||
156 | def test_activity |
|
164 | def test_activity | |
157 | get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month |
|
165 | get :activity, :id => 1, :year => 2.days.ago.to_date.year, :month => 2.days.ago.to_date.month | |
158 | assert_response :success |
|
166 | assert_response :success | |
159 | assert_template 'activity' |
|
167 | assert_template 'activity' | |
160 | assert_not_nil assigns(:events_by_day) |
|
168 | assert_not_nil assigns(:events_by_day) | |
161 |
|
169 | |||
162 | assert_tag :tag => "h3", |
|
170 | assert_tag :tag => "h3", | |
163 | :content => /#{2.days.ago.to_date.day}/, |
|
171 | :content => /#{2.days.ago.to_date.day}/, | |
164 | :sibling => { :tag => "ul", |
|
172 | :sibling => { :tag => "ul", | |
165 | :child => { :tag => "li", |
|
173 | :child => { :tag => "li", | |
166 | :child => { :tag => "p", |
|
174 | :child => { :tag => "p", | |
167 | :content => /(#{IssueStatus.find(2).name})/, |
|
175 | :content => /(#{IssueStatus.find(2).name})/, | |
168 | } |
|
176 | } | |
169 | } |
|
177 | } | |
170 | } |
|
178 | } | |
171 |
|
179 | |||
172 | get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month |
|
180 | get :activity, :id => 1, :year => 3.days.ago.to_date.year, :month => 3.days.ago.to_date.month | |
173 | assert_response :success |
|
181 | assert_response :success | |
174 | assert_template 'activity' |
|
182 | assert_template 'activity' | |
175 | assert_not_nil assigns(:events_by_day) |
|
183 | assert_not_nil assigns(:events_by_day) | |
176 |
|
184 | |||
177 | assert_tag :tag => "h3", |
|
185 | assert_tag :tag => "h3", | |
178 | :content => /#{3.day.ago.to_date.day}/, |
|
186 | :content => /#{3.day.ago.to_date.day}/, | |
179 | :sibling => { :tag => "ul", |
|
187 | :sibling => { :tag => "ul", | |
180 | :child => { :tag => "li", |
|
188 | :child => { :tag => "li", | |
181 | :child => { :tag => "p", |
|
189 | :child => { :tag => "p", | |
182 | :content => /#{Issue.find(1).subject}/, |
|
190 | :content => /#{Issue.find(1).subject}/, | |
183 | } |
|
191 | } | |
184 | } |
|
192 | } | |
185 | } |
|
193 | } | |
186 | end |
|
194 | end | |
187 |
|
195 | |||
188 | def test_calendar |
|
196 | def test_calendar | |
189 | get :calendar, :id => 1 |
|
197 | get :calendar, :id => 1 | |
190 | assert_response :success |
|
198 | assert_response :success | |
191 | assert_template 'calendar' |
|
199 | assert_template 'calendar' | |
192 | assert_not_nil assigns(:calendar) |
|
200 | assert_not_nil assigns(:calendar) | |
193 | end |
|
201 | end | |
194 |
|
202 | |||
195 | def test_calendar_with_subprojects |
|
203 | def test_calendar_with_subprojects | |
196 | get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
204 | get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] | |
197 | assert_response :success |
|
205 | assert_response :success | |
198 | assert_template 'calendar' |
|
206 | assert_template 'calendar' | |
199 | assert_not_nil assigns(:calendar) |
|
207 | assert_not_nil assigns(:calendar) | |
200 | end |
|
208 | end | |
201 |
|
209 | |||
202 | def test_gantt |
|
210 | def test_gantt | |
203 | get :gantt, :id => 1 |
|
211 | get :gantt, :id => 1 | |
204 | assert_response :success |
|
212 | assert_response :success | |
205 | assert_template 'gantt.rhtml' |
|
213 | assert_template 'gantt.rhtml' | |
206 | assert_not_nil assigns(:events) |
|
214 | assert_not_nil assigns(:events) | |
207 | end |
|
215 | end | |
208 |
|
216 | |||
209 | def test_gantt_with_subprojects |
|
217 | def test_gantt_with_subprojects | |
210 | get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] |
|
218 | get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2] | |
211 | assert_response :success |
|
219 | assert_response :success | |
212 | assert_template 'gantt.rhtml' |
|
220 | assert_template 'gantt.rhtml' | |
213 | assert_not_nil assigns(:events) |
|
221 | assert_not_nil assigns(:events) | |
214 | end |
|
222 | end | |
215 |
|
223 | |||
216 | def test_gantt_export_to_pdf |
|
224 | def test_gantt_export_to_pdf | |
217 | get :gantt, :id => 1, :format => 'pdf' |
|
225 | get :gantt, :id => 1, :format => 'pdf' | |
218 | assert_response :success |
|
226 | assert_response :success | |
219 | assert_template 'gantt.rfpdf' |
|
227 | assert_template 'gantt.rfpdf' | |
220 | assert_equal 'application/pdf', @response.content_type |
|
228 | assert_equal 'application/pdf', @response.content_type | |
221 | assert_not_nil assigns(:events) |
|
229 | assert_not_nil assigns(:events) | |
222 | end |
|
230 | end | |
223 |
|
231 | |||
224 | def test_archive |
|
232 | def test_archive | |
225 | @request.session[:user_id] = 1 # admin |
|
233 | @request.session[:user_id] = 1 # admin | |
226 | post :archive, :id => 1 |
|
234 | post :archive, :id => 1 | |
227 | assert_redirected_to 'admin/projects' |
|
235 | assert_redirected_to 'admin/projects' | |
228 | assert !Project.find(1).active? |
|
236 | assert !Project.find(1).active? | |
229 | end |
|
237 | end | |
230 |
|
238 | |||
231 | def test_unarchive |
|
239 | def test_unarchive | |
232 | @request.session[:user_id] = 1 # admin |
|
240 | @request.session[:user_id] = 1 # admin | |
233 | Project.find(1).archive |
|
241 | Project.find(1).archive | |
234 | post :unarchive, :id => 1 |
|
242 | post :unarchive, :id => 1 | |
235 | assert_redirected_to 'admin/projects' |
|
243 | assert_redirected_to 'admin/projects' | |
236 | assert Project.find(1).active? |
|
244 | assert Project.find(1).active? | |
237 | end |
|
245 | end | |
238 |
|
246 | |||
239 | def test_add_issue |
|
247 | def test_add_issue | |
240 | @request.session[:user_id] = 2 |
|
248 | @request.session[:user_id] = 2 | |
241 | get :add_issue, :id => 1, :tracker_id => 1 |
|
249 | get :add_issue, :id => 1, :tracker_id => 1 | |
242 | assert_response :success |
|
250 | assert_response :success | |
243 | assert_template 'add_issue' |
|
251 | assert_template 'add_issue' | |
244 | post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5} |
|
252 | post :add_issue, :id => 1, :issue => {:tracker_id => 1, :subject => 'This is the test_add_issue issue', :description => 'This is the description', :priority_id => 5} | |
245 |
assert_redirected_to 'projects/ |
|
253 | assert_redirected_to 'projects/ecookbook/issues' | |
246 | assert Issue.find_by_subject('This is the test_add_issue issue') |
|
254 | assert Issue.find_by_subject('This is the test_add_issue issue') | |
247 | end |
|
255 | end | |
248 |
|
256 | |||
249 | def test_copy_issue |
|
257 | def test_copy_issue | |
250 | @request.session[:user_id] = 2 |
|
258 | @request.session[:user_id] = 2 | |
251 | get :add_issue, :id => 1, :copy_from => 1 |
|
259 | get :add_issue, :id => 1, :copy_from => 1 | |
252 | assert_template 'add_issue' |
|
260 | assert_template 'add_issue' | |
253 | assert_not_nil assigns(:issue) |
|
261 | assert_not_nil assigns(:issue) | |
254 | orig = Issue.find(1) |
|
262 | orig = Issue.find(1) | |
255 | assert_equal orig.subject, assigns(:issue).subject |
|
263 | assert_equal orig.subject, assigns(:issue).subject | |
256 | end |
|
264 | end | |
257 | end |
|
265 | end |
@@ -1,64 +1,64 | |||||
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'repositories_controller' |
|
19 | require 'repositories_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class RepositoriesController; def rescue_action(e) raise e end; end |
|
22 | class RepositoriesController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class RepositoriesControllerTest < Test::Unit::TestCase |
|
24 | class RepositoriesControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers |
|
25 | fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = RepositoriesController.new |
|
28 | @controller = RepositoriesController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_revisions |
|
34 | def test_revisions | |
35 | get :revisions, :id => 1 |
|
35 | get :revisions, :id => 1 | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'revisions' |
|
37 | assert_template 'revisions' | |
38 | assert_not_nil assigns(:changesets) |
|
38 | assert_not_nil assigns(:changesets) | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def test_revision_with_before_nil_and_afer_normal |
|
41 | def test_revision_with_before_nil_and_afer_normal | |
42 | get :revision, {:id => 1, :rev => 1} |
|
42 | get :revision, {:id => 1, :rev => 1} | |
43 | assert_response :success |
|
43 | assert_response :success | |
44 | assert_template 'revision' |
|
44 | assert_template 'revision' | |
45 | assert_no_tag :tag => "div", :attributes => { :class => "contextual" }, |
|
45 | assert_no_tag :tag => "div", :attributes => { :class => "contextual" }, | |
46 |
:child => { :tag => "a", :attributes => { :href => '/repositories/revision/ |
|
46 | :child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook?rev=0'} | |
47 | } |
|
47 | } | |
48 | assert_tag :tag => "div", :attributes => { :class => "contextual" }, |
|
48 | assert_tag :tag => "div", :attributes => { :class => "contextual" }, | |
49 |
:child => { :tag => "a", :attributes => { :href => '/repositories/revision/ |
|
49 | :child => { :tag => "a", :attributes => { :href => '/repositories/revision/ecookbook?rev=2'} | |
50 | } |
|
50 | } | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_graph_commits_per_month |
|
53 | def test_graph_commits_per_month | |
54 | get :graph, :id => 1, :graph => 'commits_per_month' |
|
54 | get :graph, :id => 1, :graph => 'commits_per_month' | |
55 | assert_response :success |
|
55 | assert_response :success | |
56 | assert_equal 'image/svg+xml', @response.content_type |
|
56 | assert_equal 'image/svg+xml', @response.content_type | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | def test_graph_commits_per_author |
|
59 | def test_graph_commits_per_author | |
60 | get :graph, :id => 1, :graph => 'commits_per_author' |
|
60 | get :graph, :id => 1, :graph => 'commits_per_author' | |
61 | assert_response :success |
|
61 | assert_response :success | |
62 | assert_equal 'image/svg+xml', @response.content_type |
|
62 | assert_equal 'image/svg+xml', @response.content_type | |
63 | end |
|
63 | end | |
64 | end |
|
64 | end |
@@ -1,73 +1,73 | |||||
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'versions_controller' |
|
19 | require 'versions_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class VersionsController; def rescue_action(e) raise e end; end |
|
22 | class VersionsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class VersionsControllerTest < Test::Unit::TestCase |
|
24 | class VersionsControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :versions, :users, :roles, :members, :enabled_modules |
|
25 | fixtures :projects, :versions, :users, :roles, :members, :enabled_modules | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = VersionsController.new |
|
28 | @controller = VersionsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_show |
|
34 | def test_show | |
35 | get :show, :id => 2 |
|
35 | get :show, :id => 2 | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'show' |
|
37 | assert_template 'show' | |
38 | assert_not_nil assigns(:version) |
|
38 | assert_not_nil assigns(:version) | |
39 |
|
39 | |||
40 | assert_tag :tag => 'h2', :content => /1.0/ |
|
40 | assert_tag :tag => 'h2', :content => /1.0/ | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | def test_get_edit |
|
43 | def test_get_edit | |
44 | @request.session[:user_id] = 2 |
|
44 | @request.session[:user_id] = 2 | |
45 | get :edit, :id => 2 |
|
45 | get :edit, :id => 2 | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'edit' |
|
47 | assert_template 'edit' | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | def test_post_edit |
|
50 | def test_post_edit | |
51 | @request.session[:user_id] = 2 |
|
51 | @request.session[:user_id] = 2 | |
52 | post :edit, :id => 2, |
|
52 | post :edit, :id => 2, | |
53 | :version => { :name => 'New version name', |
|
53 | :version => { :name => 'New version name', | |
54 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
54 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
55 |
assert_redirected_to 'projects/settings/ |
|
55 | assert_redirected_to 'projects/settings/ecookbook' | |
56 | version = Version.find(2) |
|
56 | version = Version.find(2) | |
57 | assert_equal 'New version name', version.name |
|
57 | assert_equal 'New version name', version.name | |
58 | assert_equal Date.today, version.effective_date |
|
58 | assert_equal Date.today, version.effective_date | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_destroy |
|
61 | def test_destroy | |
62 | @request.session[:user_id] = 2 |
|
62 | @request.session[:user_id] = 2 | |
63 | post :destroy, :id => 2 |
|
63 | post :destroy, :id => 2 | |
64 |
assert_redirected_to 'projects/settings/ |
|
64 | assert_redirected_to 'projects/settings/ecookbook' | |
65 | assert_nil Version.find_by_id(2) |
|
65 | assert_nil Version.find_by_id(2) | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def test_issue_status_by |
|
68 | def test_issue_status_by | |
69 | xhr :get, :status_by, :id => 2 |
|
69 | xhr :get, :status_by, :id => 2 | |
70 | assert_response :success |
|
70 | assert_response :success | |
71 | assert_template '_issue_counts' |
|
71 | assert_template '_issue_counts' | |
72 | end |
|
72 | end | |
73 | end |
|
73 | end |
@@ -1,145 +1,145 | |||||
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'wiki_controller' |
|
19 | require 'wiki_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class WikiController; def rescue_action(e) raise e end; end |
|
22 | class WikiController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class WikiControllerTest < Test::Unit::TestCase |
|
24 | class WikiControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions |
|
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = WikiController.new |
|
28 | @controller = WikiController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_show_start_page |
|
34 | def test_show_start_page | |
35 | get :index, :id => 1 |
|
35 | get :index, :id => 1 | |
36 | assert_response :success |
|
36 | assert_response :success | |
37 | assert_template 'show' |
|
37 | assert_template 'show' | |
38 | assert_tag :tag => 'h1', :content => /CookBook documentation/ |
|
38 | assert_tag :tag => 'h1', :content => /CookBook documentation/ | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def test_show_page_with_name |
|
41 | def test_show_page_with_name | |
42 | get :index, :id => 1, :page => 'Another_page' |
|
42 | get :index, :id => 1, :page => 'Another_page' | |
43 | assert_response :success |
|
43 | assert_response :success | |
44 | assert_template 'show' |
|
44 | assert_template 'show' | |
45 | assert_tag :tag => 'h1', :content => /Another page/ |
|
45 | assert_tag :tag => 'h1', :content => /Another page/ | |
46 | end |
|
46 | end | |
47 |
|
47 | |||
48 | def test_show_unexistent_page_without_edit_right |
|
48 | def test_show_unexistent_page_without_edit_right | |
49 | get :index, :id => 1, :page => 'Unexistent page' |
|
49 | get :index, :id => 1, :page => 'Unexistent page' | |
50 | assert_response 404 |
|
50 | assert_response 404 | |
51 | end |
|
51 | end | |
52 |
|
52 | |||
53 | def test_show_unexistent_page_with_edit_right |
|
53 | def test_show_unexistent_page_with_edit_right | |
54 | @request.session[:user_id] = 2 |
|
54 | @request.session[:user_id] = 2 | |
55 | get :index, :id => 1, :page => 'Unexistent page' |
|
55 | get :index, :id => 1, :page => 'Unexistent page' | |
56 | assert_response :success |
|
56 | assert_response :success | |
57 | assert_template 'edit' |
|
57 | assert_template 'edit' | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def test_create_page |
|
60 | def test_create_page | |
61 | @request.session[:user_id] = 2 |
|
61 | @request.session[:user_id] = 2 | |
62 | post :edit, :id => 1, |
|
62 | post :edit, :id => 1, | |
63 | :page => 'New page', |
|
63 | :page => 'New page', | |
64 | :content => {:comments => 'Created the page', |
|
64 | :content => {:comments => 'Created the page', | |
65 | :text => "h1. New page\n\nThis is a new page", |
|
65 | :text => "h1. New page\n\nThis is a new page", | |
66 | :version => 0} |
|
66 | :version => 0} | |
67 |
assert_redirected_to 'wiki/ |
|
67 | assert_redirected_to 'wiki/ecookbook/New_page' | |
68 | page = Project.find(1).wiki.find_page('New page') |
|
68 | page = Project.find(1).wiki.find_page('New page') | |
69 | assert !page.new_record? |
|
69 | assert !page.new_record? | |
70 | assert_not_nil page.content |
|
70 | assert_not_nil page.content | |
71 | assert_equal 'Created the page', page.content.comments |
|
71 | assert_equal 'Created the page', page.content.comments | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def test_preview |
|
74 | def test_preview | |
75 | @request.session[:user_id] = 2 |
|
75 | @request.session[:user_id] = 2 | |
76 | xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', |
|
76 | xhr :post, :preview, :id => 1, :page => 'CookBook_documentation', | |
77 | :content => { :comments => '', |
|
77 | :content => { :comments => '', | |
78 | :text => 'this is a *previewed text*', |
|
78 | :text => 'this is a *previewed text*', | |
79 | :version => 3 } |
|
79 | :version => 3 } | |
80 | assert_response :success |
|
80 | assert_response :success | |
81 | assert_template 'common/_preview' |
|
81 | assert_template 'common/_preview' | |
82 | assert_tag :tag => 'strong', :content => /previewed text/ |
|
82 | assert_tag :tag => 'strong', :content => /previewed text/ | |
83 | end |
|
83 | end | |
84 |
|
84 | |||
85 | def test_history |
|
85 | def test_history | |
86 | get :history, :id => 1, :page => 'CookBook_documentation' |
|
86 | get :history, :id => 1, :page => 'CookBook_documentation' | |
87 | assert_response :success |
|
87 | assert_response :success | |
88 | assert_template 'history' |
|
88 | assert_template 'history' | |
89 | assert_not_nil assigns(:versions) |
|
89 | assert_not_nil assigns(:versions) | |
90 | assert_equal 3, assigns(:versions).size |
|
90 | assert_equal 3, assigns(:versions).size | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_diff |
|
93 | def test_diff | |
94 | get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 |
|
94 | get :diff, :id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1 | |
95 | assert_response :success |
|
95 | assert_response :success | |
96 | assert_template 'diff' |
|
96 | assert_template 'diff' | |
97 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, |
|
97 | assert_tag :tag => 'span', :attributes => { :class => 'diff_in'}, | |
98 | :content => /updated/ |
|
98 | :content => /updated/ | |
99 | end |
|
99 | end | |
100 |
|
100 | |||
101 | def test_rename_with_redirect |
|
101 | def test_rename_with_redirect | |
102 | @request.session[:user_id] = 2 |
|
102 | @request.session[:user_id] = 2 | |
103 | post :rename, :id => 1, :page => 'Another_page', |
|
103 | post :rename, :id => 1, :page => 'Another_page', | |
104 | :wiki_page => { :title => 'Another renamed page', |
|
104 | :wiki_page => { :title => 'Another renamed page', | |
105 | :redirect_existing_links => 1 } |
|
105 | :redirect_existing_links => 1 } | |
106 |
assert_redirected_to 'wiki/ |
|
106 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' | |
107 | wiki = Project.find(1).wiki |
|
107 | wiki = Project.find(1).wiki | |
108 | # Check redirects |
|
108 | # Check redirects | |
109 | assert_not_nil wiki.find_page('Another page') |
|
109 | assert_not_nil wiki.find_page('Another page') | |
110 | assert_nil wiki.find_page('Another page', :with_redirect => false) |
|
110 | assert_nil wiki.find_page('Another page', :with_redirect => false) | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_rename_without_redirect |
|
113 | def test_rename_without_redirect | |
114 | @request.session[:user_id] = 2 |
|
114 | @request.session[:user_id] = 2 | |
115 | post :rename, :id => 1, :page => 'Another_page', |
|
115 | post :rename, :id => 1, :page => 'Another_page', | |
116 | :wiki_page => { :title => 'Another renamed page', |
|
116 | :wiki_page => { :title => 'Another renamed page', | |
117 | :redirect_existing_links => "0" } |
|
117 | :redirect_existing_links => "0" } | |
118 |
assert_redirected_to 'wiki/ |
|
118 | assert_redirected_to 'wiki/ecookbook/Another_renamed_page' | |
119 | wiki = Project.find(1).wiki |
|
119 | wiki = Project.find(1).wiki | |
120 | # Check that there's no redirects |
|
120 | # Check that there's no redirects | |
121 | assert_nil wiki.find_page('Another page') |
|
121 | assert_nil wiki.find_page('Another page') | |
122 | end |
|
122 | end | |
123 |
|
123 | |||
124 | def test_destroy |
|
124 | def test_destroy | |
125 | @request.session[:user_id] = 2 |
|
125 | @request.session[:user_id] = 2 | |
126 | post :destroy, :id => 1, :page => 'CookBook_documentation' |
|
126 | post :destroy, :id => 1, :page => 'CookBook_documentation' | |
127 |
assert_redirected_to 'wiki/ |
|
127 | assert_redirected_to 'wiki/ecookbook/Page_index/special' | |
128 | end |
|
128 | end | |
129 |
|
129 | |||
130 | def test_page_index |
|
130 | def test_page_index | |
131 |
get :special, :id => |
|
131 | get :special, :id => 'ecookbook', :page => 'Page_index' | |
132 | assert_response :success |
|
132 | assert_response :success | |
133 | assert_template 'special_page_index' |
|
133 | assert_template 'special_page_index' | |
134 | pages = assigns(:pages) |
|
134 | pages = assigns(:pages) | |
135 | assert_not_nil pages |
|
135 | assert_not_nil pages | |
136 | assert_equal 2, pages.size |
|
136 | assert_equal 2, pages.size | |
137 |
assert_tag :tag => 'a', :attributes => { :href => '/wiki/ |
|
137 | assert_tag :tag => 'a', :attributes => { :href => '/wiki/ecookbook/CookBook_documentation' }, | |
138 | :content => /CookBook documentation/ |
|
138 | :content => /CookBook documentation/ | |
139 | end |
|
139 | end | |
140 |
|
140 | |||
141 | def test_not_found |
|
141 | def test_not_found | |
142 | get :index, :id => 999 |
|
142 | get :index, :id => 999 | |
143 | assert_response 404 |
|
143 | assert_response 404 | |
144 | end |
|
144 | end | |
145 | end |
|
145 | end |
@@ -1,56 +1,56 | |||||
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 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'wikis_controller' |
|
19 | require 'wikis_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class WikisController; def rescue_action(e) raise e end; end |
|
22 | class WikisController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class WikisControllerTest < Test::Unit::TestCase |
|
24 | class WikisControllerTest < Test::Unit::TestCase | |
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis |
|
25 | fixtures :projects, :users, :roles, :members, :enabled_modules, :wikis | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = WikisController.new |
|
28 | @controller = WikisController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | User.current = nil |
|
31 | User.current = nil | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_create |
|
34 | def test_create | |
35 | @request.session[:user_id] = 1 |
|
35 | @request.session[:user_id] = 1 | |
36 | assert_nil Project.find(3).wiki |
|
36 | assert_nil Project.find(3).wiki | |
37 | post :edit, :id => 3, :wiki => { :start_page => 'Start page' } |
|
37 | post :edit, :id => 3, :wiki => { :start_page => 'Start page' } | |
38 | assert_response :success |
|
38 | assert_response :success | |
39 | wiki = Project.find(3).wiki |
|
39 | wiki = Project.find(3).wiki | |
40 | assert_not_nil wiki |
|
40 | assert_not_nil wiki | |
41 | assert_equal 'Start page', wiki.start_page |
|
41 | assert_equal 'Start page', wiki.start_page | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_destroy |
|
44 | def test_destroy | |
45 | @request.session[:user_id] = 1 |
|
45 | @request.session[:user_id] = 1 | |
46 | post :destroy, :id => 1, :confirm => 1 |
|
46 | post :destroy, :id => 1, :confirm => 1 | |
47 |
assert_redirected_to 'projects/settings/ |
|
47 | assert_redirected_to 'projects/settings/ecookbook' | |
48 | assert_nil Project.find(1).wiki |
|
48 | assert_nil Project.find(1).wiki | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | def test_not_found |
|
51 | def test_not_found | |
52 | @request.session[:user_id] = 1 |
|
52 | @request.session[:user_id] = 1 | |
53 | post :destroy, :id => 999, :confirm => 1 |
|
53 | post :destroy, :id => 999, :confirm => 1 | |
54 | assert_response 404 |
|
54 | assert_response 404 | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end |
@@ -1,58 +1,58 | |||||
1 | require "#{File.dirname(__FILE__)}/../test_helper" |
|
1 | require "#{File.dirname(__FILE__)}/../test_helper" | |
2 |
|
2 | |||
3 | class IssuesTest < ActionController::IntegrationTest |
|
3 | class IssuesTest < ActionController::IntegrationTest | |
4 | fixtures :projects, :users, :trackers, :issue_statuses, :issues, :enumerations |
|
4 | fixtures :projects, :users, :trackers, :issue_statuses, :issues, :enumerations | |
5 |
|
5 | |||
6 | # create an issue |
|
6 | # create an issue | |
7 | def test_add_issue |
|
7 | def test_add_issue | |
8 | log_user('jsmith', 'jsmith') |
|
8 | log_user('jsmith', 'jsmith') | |
9 | get "projects/add_issue/1", :tracker_id => "1" |
|
9 | get "projects/add_issue/1", :tracker_id => "1" | |
10 | assert_response :success |
|
10 | assert_response :success | |
11 | assert_template "projects/add_issue" |
|
11 | assert_template "projects/add_issue" | |
12 |
|
12 | |||
13 | post "projects/add_issue/1", :tracker_id => "1", |
|
13 | post "projects/add_issue/1", :tracker_id => "1", | |
14 | :issue => { :start_date => "2006-12-26", |
|
14 | :issue => { :start_date => "2006-12-26", | |
15 | :priority_id => "3", |
|
15 | :priority_id => "3", | |
16 | :subject => "new test issue", |
|
16 | :subject => "new test issue", | |
17 | :category_id => "", |
|
17 | :category_id => "", | |
18 | :description => "new issue", |
|
18 | :description => "new issue", | |
19 | :done_ratio => "0", |
|
19 | :done_ratio => "0", | |
20 | :due_date => "", |
|
20 | :due_date => "", | |
21 | :assigned_to_id => "" } |
|
21 | :assigned_to_id => "" } | |
22 | # find created issue |
|
22 | # find created issue | |
23 | issue = Issue.find_by_subject("new test issue") |
|
23 | issue = Issue.find_by_subject("new test issue") | |
24 | assert_kind_of Issue, issue |
|
24 | assert_kind_of Issue, issue | |
25 |
|
25 | |||
26 | # check redirection |
|
26 | # check redirection | |
27 |
assert_redirected_to "projects/ |
|
27 | assert_redirected_to "projects/ecookbook/issues" | |
28 | follow_redirect! |
|
28 | follow_redirect! | |
29 | assert assigns(:issues).include?(issue) |
|
29 | assert assigns(:issues).include?(issue) | |
30 |
|
30 | |||
31 | # check issue attributes |
|
31 | # check issue attributes | |
32 | assert_equal 'jsmith', issue.author.login |
|
32 | assert_equal 'jsmith', issue.author.login | |
33 | assert_equal 1, issue.project.id |
|
33 | assert_equal 1, issue.project.id | |
34 | assert_equal 1, issue.status.id |
|
34 | assert_equal 1, issue.status.id | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | # add then remove 2 attachments to an issue |
|
37 | # add then remove 2 attachments to an issue | |
38 | def test_issue_attachements |
|
38 | def test_issue_attachements | |
39 | log_user('jsmith', 'jsmith') |
|
39 | log_user('jsmith', 'jsmith') | |
40 |
|
40 | |||
41 | post "issues/add_note/1", { :notes => 'Some notes', 'attachments[]' => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain') } |
|
41 | post "issues/add_note/1", { :notes => 'Some notes', 'attachments[]' => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain') } | |
42 | assert_redirected_to "issues/show/1" |
|
42 | assert_redirected_to "issues/show/1" | |
43 |
|
43 | |||
44 | # make sure attachment was saved |
|
44 | # make sure attachment was saved | |
45 | attachment = Issue.find(1).attachments.find_by_filename("testfile.txt") |
|
45 | attachment = Issue.find(1).attachments.find_by_filename("testfile.txt") | |
46 | assert_kind_of Attachment, attachment |
|
46 | assert_kind_of Attachment, attachment | |
47 | assert_equal Issue.find(1), attachment.container |
|
47 | assert_equal Issue.find(1), attachment.container | |
48 | # verify the size of the attachment stored in db |
|
48 | # verify the size of the attachment stored in db | |
49 | #assert_equal file_data_1.length, attachment.filesize |
|
49 | #assert_equal file_data_1.length, attachment.filesize | |
50 | # verify that the attachment was written to disk |
|
50 | # verify that the attachment was written to disk | |
51 | assert File.exist?(attachment.diskfile) |
|
51 | assert File.exist?(attachment.diskfile) | |
52 |
|
52 | |||
53 | # remove the attachments |
|
53 | # remove the attachments | |
54 | Issue.find(1).attachments.each(&:destroy) |
|
54 | Issue.find(1).attachments.each(&:destroy) | |
55 | assert_equal 0, Issue.find(1).attachments.length |
|
55 | assert_equal 0, Issue.find(1).attachments.length | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | end |
|
58 | end |
General Comments 0
You need to be logged in to leave comments.
Login now