@@ -1,298 +1,298 | |||||
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 'SVG/Graph/Bar' |
|
18 | require 'SVG/Graph/Bar' | |
19 | require 'SVG/Graph/BarHorizontal' |
|
19 | require 'SVG/Graph/BarHorizontal' | |
20 | require 'digest/sha1' |
|
20 | require 'digest/sha1' | |
21 |
|
21 | |||
22 | class ChangesetNotFound < Exception |
|
22 | class ChangesetNotFound < Exception | |
23 | end |
|
23 | end | |
24 |
|
24 | |||
25 | class RepositoriesController < ApplicationController |
|
25 | class RepositoriesController < ApplicationController | |
26 | layout 'base' |
|
26 | layout 'base' | |
27 | menu_item :repository |
|
27 | menu_item :repository | |
28 | before_filter :find_repository, :except => :edit |
|
28 | before_filter :find_repository, :except => :edit | |
29 | before_filter :find_project, :only => :edit |
|
29 | before_filter :find_project, :only => :edit | |
30 | before_filter :authorize |
|
30 | before_filter :authorize | |
31 | accept_key_auth :revisions |
|
31 | accept_key_auth :revisions | |
32 |
|
32 | |||
33 | def edit |
|
33 | def edit | |
34 | @repository = @project.repository |
|
34 | @repository = @project.repository | |
35 | if !@repository |
|
35 | if !@repository | |
36 | @repository = Repository.factory(params[:repository_scm]) |
|
36 | @repository = Repository.factory(params[:repository_scm]) | |
37 | @repository.project = @project |
|
37 | @repository.project = @project | |
38 | end |
|
38 | end | |
39 | if request.post? |
|
39 | if request.post? | |
40 | @repository.attributes = params[:repository] |
|
40 | @repository.attributes = params[:repository] | |
41 | @repository.save |
|
41 | @repository.save | |
42 | end |
|
42 | end | |
43 | render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'} |
|
43 | render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'} | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def destroy |
|
46 | def destroy | |
47 | @repository.destroy |
|
47 | @repository.destroy | |
48 | redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository' |
|
48 | redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository' | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | def show |
|
51 | def show | |
52 | # check if new revisions have been committed in the repository |
|
52 | # check if new revisions have been committed in the repository | |
53 | @repository.fetch_changesets if Setting.autofetch_changesets? |
|
53 | @repository.fetch_changesets if Setting.autofetch_changesets? | |
54 | # get entries for the browse frame |
|
54 | # get entries for the browse frame | |
55 | @entries = @repository.entries('') |
|
55 | @entries = @repository.entries('') | |
56 | # latest changesets |
|
56 | # latest changesets | |
57 | @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC") |
|
57 | @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC") | |
58 |
show_error |
|
58 | show_error_not_found unless @entries || @changesets.any? | |
59 | rescue Redmine::Scm::Adapters::CommandFailed => e |
|
59 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
60 | show_error_command_failed(e.message) |
|
60 | show_error_command_failed(e.message) | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | def browse |
|
63 | def browse | |
64 | @entries = @repository.entries(@path, @rev) |
|
64 | @entries = @repository.entries(@path, @rev) | |
65 | if request.xhr? |
|
65 | if request.xhr? | |
66 | @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) |
|
66 | @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) | |
67 | else |
|
67 | else | |
68 | show_error unless @entries |
|
68 | show_error_not_found unless @entries | |
69 | end |
|
69 | end | |
70 | rescue Redmine::Scm::Adapters::CommandFailed => e |
|
70 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
71 | show_error_command_failed(e.message) |
|
71 | show_error_command_failed(e.message) | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def changes |
|
74 | def changes | |
75 | @entry = @repository.scm.entry(@path, @rev) |
|
75 | @entry = @repository.scm.entry(@path, @rev) | |
76 | show_error and return unless @entry |
|
76 | show_error_not_found and return unless @entry | |
77 | @changesets = @repository.changesets_for_path(@path) |
|
77 | @changesets = @repository.changesets_for_path(@path) | |
78 | rescue Redmine::Scm::Adapters::CommandFailed => e |
|
78 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
79 | show_error_command_failed(e.message) |
|
79 | show_error_command_failed(e.message) | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def revisions |
|
82 | def revisions | |
83 | @changeset_count = @repository.changesets.count |
|
83 | @changeset_count = @repository.changesets.count | |
84 | @changeset_pages = Paginator.new self, @changeset_count, |
|
84 | @changeset_pages = Paginator.new self, @changeset_count, | |
85 | per_page_option, |
|
85 | per_page_option, | |
86 | params['page'] |
|
86 | params['page'] | |
87 | @changesets = @repository.changesets.find(:all, |
|
87 | @changesets = @repository.changesets.find(:all, | |
88 | :limit => @changeset_pages.items_per_page, |
|
88 | :limit => @changeset_pages.items_per_page, | |
89 | :offset => @changeset_pages.current.offset) |
|
89 | :offset => @changeset_pages.current.offset) | |
90 |
|
90 | |||
91 | respond_to do |format| |
|
91 | respond_to do |format| | |
92 | format.html { render :layout => false if request.xhr? } |
|
92 | format.html { render :layout => false if request.xhr? } | |
93 | format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } |
|
93 | format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } | |
94 | end |
|
94 | end | |
95 | end |
|
95 | end | |
96 |
|
96 | |||
97 | def entry |
|
97 | def entry | |
98 | @content = @repository.scm.cat(@path, @rev) |
|
98 | @content = @repository.scm.cat(@path, @rev) | |
99 | show_error and return unless @content |
|
99 | show_error_not_found and return unless @content | |
100 | if 'raw' == params[:format] |
|
100 | if 'raw' == params[:format] | |
101 | send_data @content, :filename => @path.split('/').last |
|
101 | send_data @content, :filename => @path.split('/').last | |
102 | else |
|
102 | else | |
103 | # Prevent empty lines when displaying a file with Windows style eol |
|
103 | # Prevent empty lines when displaying a file with Windows style eol | |
104 | @content.gsub!("\r\n", "\n") |
|
104 | @content.gsub!("\r\n", "\n") | |
105 | end |
|
105 | end | |
106 | rescue Redmine::Scm::Adapters::CommandFailed => e |
|
106 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
107 | show_error_command_failed(e.message) |
|
107 | show_error_command_failed(e.message) | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def annotate |
|
110 | def annotate | |
111 | @annotate = @repository.scm.annotate(@path, @rev) |
|
111 | @annotate = @repository.scm.annotate(@path, @rev) | |
112 | show_error and return if @annotate.nil? || @annotate.empty? |
|
112 | show_error_not_found and return if @annotate.nil? || @annotate.empty? | |
113 | rescue Redmine::Scm::Adapters::CommandFailed => e |
|
113 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
114 | show_error_command_failed(e.message) |
|
114 | show_error_command_failed(e.message) | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def revision |
|
117 | def revision | |
118 | @changeset = @repository.changesets.find_by_revision(@rev) |
|
118 | @changeset = @repository.changesets.find_by_revision(@rev) | |
119 | raise ChangesetNotFound unless @changeset |
|
119 | raise ChangesetNotFound unless @changeset | |
120 | @changes_count = @changeset.changes.size |
|
120 | @changes_count = @changeset.changes.size | |
121 | @changes_pages = Paginator.new self, @changes_count, 150, params['page'] |
|
121 | @changes_pages = Paginator.new self, @changes_count, 150, params['page'] | |
122 | @changes = @changeset.changes.find(:all, |
|
122 | @changes = @changeset.changes.find(:all, | |
123 | :limit => @changes_pages.items_per_page, |
|
123 | :limit => @changes_pages.items_per_page, | |
124 | :offset => @changes_pages.current.offset) |
|
124 | :offset => @changes_pages.current.offset) | |
125 |
|
125 | |||
126 | respond_to do |format| |
|
126 | respond_to do |format| | |
127 | format.html |
|
127 | format.html | |
128 | format.js {render :layout => false} |
|
128 | format.js {render :layout => false} | |
129 | end |
|
129 | end | |
130 | rescue ChangesetNotFound |
|
130 | rescue ChangesetNotFound | |
131 | show_error |
|
131 | show_error_not_found | |
132 | rescue Redmine::Scm::Adapters::CommandFailed => e |
|
132 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
133 | show_error_command_failed(e.message) |
|
133 | show_error_command_failed(e.message) | |
134 | end |
|
134 | end | |
135 |
|
135 | |||
136 | def diff |
|
136 | def diff | |
137 | @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1) |
|
137 | @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1) | |
138 | @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' |
|
138 | @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' | |
139 | @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) |
|
139 | @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) | |
140 |
|
140 | |||
141 | # Save diff type as user preference |
|
141 | # Save diff type as user preference | |
142 | if User.current.logged? && @diff_type != User.current.pref[:diff_type] |
|
142 | if User.current.logged? && @diff_type != User.current.pref[:diff_type] | |
143 | User.current.pref[:diff_type] = @diff_type |
|
143 | User.current.pref[:diff_type] = @diff_type | |
144 | User.current.preference.save |
|
144 | User.current.preference.save | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
147 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") |
|
147 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") | |
148 | unless read_fragment(@cache_key) |
|
148 | unless read_fragment(@cache_key) | |
149 | @diff = @repository.diff(@path, @rev, @rev_to, @diff_type) |
|
149 | @diff = @repository.diff(@path, @rev, @rev_to, @diff_type) | |
150 |
show_error |
|
150 | show_error_not_found unless @diff | |
151 | end |
|
151 | end | |
152 | rescue Redmine::Scm::Adapters::CommandFailed => e |
|
152 | rescue Redmine::Scm::Adapters::CommandFailed => e | |
153 | show_error_command_failed(e.message) |
|
153 | show_error_command_failed(e.message) | |
154 | end |
|
154 | end | |
155 |
|
155 | |||
156 | def stats |
|
156 | def stats | |
157 | end |
|
157 | end | |
158 |
|
158 | |||
159 | def graph |
|
159 | def graph | |
160 | data = nil |
|
160 | data = nil | |
161 | case params[:graph] |
|
161 | case params[:graph] | |
162 | when "commits_per_month" |
|
162 | when "commits_per_month" | |
163 | data = graph_commits_per_month(@repository) |
|
163 | data = graph_commits_per_month(@repository) | |
164 | when "commits_per_author" |
|
164 | when "commits_per_author" | |
165 | data = graph_commits_per_author(@repository) |
|
165 | data = graph_commits_per_author(@repository) | |
166 | end |
|
166 | end | |
167 | if data |
|
167 | if data | |
168 | headers["Content-Type"] = "image/svg+xml" |
|
168 | headers["Content-Type"] = "image/svg+xml" | |
169 | send_data(data, :type => "image/svg+xml", :disposition => "inline") |
|
169 | send_data(data, :type => "image/svg+xml", :disposition => "inline") | |
170 | else |
|
170 | else | |
171 | render_404 |
|
171 | render_404 | |
172 | end |
|
172 | end | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | private |
|
175 | private | |
176 | def find_project |
|
176 | def find_project | |
177 | @project = Project.find(params[:id]) |
|
177 | @project = Project.find(params[:id]) | |
178 | rescue ActiveRecord::RecordNotFound |
|
178 | rescue ActiveRecord::RecordNotFound | |
179 | render_404 |
|
179 | render_404 | |
180 | end |
|
180 | end | |
181 |
|
181 | |||
182 | def find_repository |
|
182 | def find_repository | |
183 | @project = Project.find(params[:id]) |
|
183 | @project = Project.find(params[:id]) | |
184 | @repository = @project.repository |
|
184 | @repository = @project.repository | |
185 | render_404 and return false unless @repository |
|
185 | render_404 and return false unless @repository | |
186 | @path = params[:path].join('/') unless params[:path].nil? |
|
186 | @path = params[:path].join('/') unless params[:path].nil? | |
187 | @path ||= '' |
|
187 | @path ||= '' | |
188 | @rev = params[:rev].to_i if params[:rev] |
|
188 | @rev = params[:rev].to_i if params[:rev] | |
189 | rescue ActiveRecord::RecordNotFound |
|
189 | rescue ActiveRecord::RecordNotFound | |
190 | render_404 |
|
190 | render_404 | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
193 | def show_error_not_found |
|
193 | def show_error_not_found | |
194 | render_error l(:error_scm_not_found) |
|
194 | render_error l(:error_scm_not_found) | |
195 | end |
|
195 | end | |
196 |
|
196 | |||
197 | def show_error_command_failed(msg) |
|
197 | def show_error_command_failed(msg) | |
198 | render_error l(:error_scm_command_failed, msg) |
|
198 | render_error l(:error_scm_command_failed, msg) | |
199 | end |
|
199 | end | |
200 |
|
200 | |||
201 | def graph_commits_per_month(repository) |
|
201 | def graph_commits_per_month(repository) | |
202 | @date_to = Date.today |
|
202 | @date_to = Date.today | |
203 | @date_from = @date_to << 11 |
|
203 | @date_from = @date_to << 11 | |
204 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) |
|
204 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) | |
205 | commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
205 | commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | |
206 | commits_by_month = [0] * 12 |
|
206 | commits_by_month = [0] * 12 | |
207 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } |
|
207 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } | |
208 |
|
208 | |||
209 | changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
209 | changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | |
210 | changes_by_month = [0] * 12 |
|
210 | changes_by_month = [0] * 12 | |
211 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } |
|
211 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } | |
212 |
|
212 | |||
213 | fields = [] |
|
213 | fields = [] | |
214 | month_names = l(:actionview_datehelper_select_month_names_abbr).split(',') |
|
214 | month_names = l(:actionview_datehelper_select_month_names_abbr).split(',') | |
215 | 12.times {|m| fields << month_names[((Date.today.month - 1 - m) % 12)]} |
|
215 | 12.times {|m| fields << month_names[((Date.today.month - 1 - m) % 12)]} | |
216 |
|
216 | |||
217 | graph = SVG::Graph::Bar.new( |
|
217 | graph = SVG::Graph::Bar.new( | |
218 | :height => 300, |
|
218 | :height => 300, | |
219 | :width => 500, |
|
219 | :width => 500, | |
220 | :fields => fields.reverse, |
|
220 | :fields => fields.reverse, | |
221 | :stack => :side, |
|
221 | :stack => :side, | |
222 | :scale_integers => true, |
|
222 | :scale_integers => true, | |
223 | :step_x_labels => 2, |
|
223 | :step_x_labels => 2, | |
224 | :show_data_values => false, |
|
224 | :show_data_values => false, | |
225 | :graph_title => l(:label_commits_per_month), |
|
225 | :graph_title => l(:label_commits_per_month), | |
226 | :show_graph_title => true |
|
226 | :show_graph_title => true | |
227 | ) |
|
227 | ) | |
228 |
|
228 | |||
229 | graph.add_data( |
|
229 | graph.add_data( | |
230 | :data => commits_by_month[0..11].reverse, |
|
230 | :data => commits_by_month[0..11].reverse, | |
231 | :title => l(:label_revision_plural) |
|
231 | :title => l(:label_revision_plural) | |
232 | ) |
|
232 | ) | |
233 |
|
233 | |||
234 | graph.add_data( |
|
234 | graph.add_data( | |
235 | :data => changes_by_month[0..11].reverse, |
|
235 | :data => changes_by_month[0..11].reverse, | |
236 | :title => l(:label_change_plural) |
|
236 | :title => l(:label_change_plural) | |
237 | ) |
|
237 | ) | |
238 |
|
238 | |||
239 | graph.burn |
|
239 | graph.burn | |
240 | end |
|
240 | end | |
241 |
|
241 | |||
242 | def graph_commits_per_author(repository) |
|
242 | def graph_commits_per_author(repository) | |
243 | commits_by_author = repository.changesets.count(:all, :group => :committer) |
|
243 | commits_by_author = repository.changesets.count(:all, :group => :committer) | |
244 | commits_by_author.sort! {|x, y| x.last <=> y.last} |
|
244 | commits_by_author.sort! {|x, y| x.last <=> y.last} | |
245 |
|
245 | |||
246 | changes_by_author = repository.changes.count(:all, :group => :committer) |
|
246 | changes_by_author = repository.changes.count(:all, :group => :committer) | |
247 | h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} |
|
247 | h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} | |
248 |
|
248 | |||
249 | fields = commits_by_author.collect {|r| r.first} |
|
249 | fields = commits_by_author.collect {|r| r.first} | |
250 | commits_data = commits_by_author.collect {|r| r.last} |
|
250 | commits_data = commits_by_author.collect {|r| r.last} | |
251 | changes_data = commits_by_author.collect {|r| h[r.first] || 0} |
|
251 | changes_data = commits_by_author.collect {|r| h[r.first] || 0} | |
252 |
|
252 | |||
253 | fields = fields + [""]*(10 - fields.length) if fields.length<10 |
|
253 | fields = fields + [""]*(10 - fields.length) if fields.length<10 | |
254 | commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 |
|
254 | commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 | |
255 | changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10 |
|
255 | changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10 | |
256 |
|
256 | |||
257 | graph = SVG::Graph::BarHorizontal.new( |
|
257 | graph = SVG::Graph::BarHorizontal.new( | |
258 | :height => 300, |
|
258 | :height => 300, | |
259 | :width => 500, |
|
259 | :width => 500, | |
260 | :fields => fields, |
|
260 | :fields => fields, | |
261 | :stack => :side, |
|
261 | :stack => :side, | |
262 | :scale_integers => true, |
|
262 | :scale_integers => true, | |
263 | :show_data_values => false, |
|
263 | :show_data_values => false, | |
264 | :rotate_y_labels => false, |
|
264 | :rotate_y_labels => false, | |
265 | :graph_title => l(:label_commits_per_author), |
|
265 | :graph_title => l(:label_commits_per_author), | |
266 | :show_graph_title => true |
|
266 | :show_graph_title => true | |
267 | ) |
|
267 | ) | |
268 |
|
268 | |||
269 | graph.add_data( |
|
269 | graph.add_data( | |
270 | :data => commits_data, |
|
270 | :data => commits_data, | |
271 | :title => l(:label_revision_plural) |
|
271 | :title => l(:label_revision_plural) | |
272 | ) |
|
272 | ) | |
273 |
|
273 | |||
274 | graph.add_data( |
|
274 | graph.add_data( | |
275 | :data => changes_data, |
|
275 | :data => changes_data, | |
276 | :title => l(:label_change_plural) |
|
276 | :title => l(:label_change_plural) | |
277 | ) |
|
277 | ) | |
278 |
|
278 | |||
279 | graph.burn |
|
279 | graph.burn | |
280 | end |
|
280 | end | |
281 |
|
281 | |||
282 | end |
|
282 | end | |
283 |
|
283 | |||
284 | class Date |
|
284 | class Date | |
285 | def months_ago(date = Date.today) |
|
285 | def months_ago(date = Date.today) | |
286 | (date.year - self.year)*12 + (date.month - self.month) |
|
286 | (date.year - self.year)*12 + (date.month - self.month) | |
287 | end |
|
287 | end | |
288 |
|
288 | |||
289 | def weeks_ago(date = Date.today) |
|
289 | def weeks_ago(date = Date.today) | |
290 | (date.year - self.year)*52 + (date.cweek - self.cweek) |
|
290 | (date.year - self.year)*52 + (date.cweek - self.cweek) | |
291 | end |
|
291 | end | |
292 | end |
|
292 | end | |
293 |
|
293 | |||
294 | class String |
|
294 | class String | |
295 | def with_leading_slash |
|
295 | def with_leading_slash | |
296 | starts_with?('/') ? self : "/#{self}" |
|
296 | starts_with?('/') ? self : "/#{self}" | |
297 | end |
|
297 | end | |
298 | end |
|
298 | end |
@@ -1,91 +1,97 | |||||
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 RepositoriesSubversionControllerTest < Test::Unit::TestCase |
|
24 | class RepositoriesSubversionControllerTest < 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 | # No '..' in the repository path for svn |
|
27 | # No '..' in the repository path for svn | |
28 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository' |
|
28 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository' | |
29 |
|
29 | |||
30 | def setup |
|
30 | def setup | |
31 | @controller = RepositoriesController.new |
|
31 | @controller = RepositoriesController.new | |
32 | @request = ActionController::TestRequest.new |
|
32 | @request = ActionController::TestRequest.new | |
33 | @response = ActionController::TestResponse.new |
|
33 | @response = ActionController::TestResponse.new | |
34 | User.current = nil |
|
34 | User.current = nil | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
37 | if File.directory?(REPOSITORY_PATH) |
|
37 | if File.directory?(REPOSITORY_PATH) | |
38 | def test_show |
|
38 | def test_show | |
39 | get :show, :id => 1 |
|
39 | get :show, :id => 1 | |
40 | assert_response :success |
|
40 | assert_response :success | |
41 | assert_template 'show' |
|
41 | assert_template 'show' | |
42 | assert_not_nil assigns(:entries) |
|
42 | assert_not_nil assigns(:entries) | |
43 | assert_not_nil assigns(:changesets) |
|
43 | assert_not_nil assigns(:changesets) | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | def test_browse_root |
|
46 | def test_browse_root | |
47 | get :browse, :id => 1 |
|
47 | get :browse, :id => 1 | |
48 | assert_response :success |
|
48 | assert_response :success | |
49 | assert_template 'browse' |
|
49 | assert_template 'browse' | |
50 | assert_not_nil assigns(:entries) |
|
50 | assert_not_nil assigns(:entries) | |
51 | entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} |
|
51 | entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} | |
52 | assert_equal 'dir', entry.kind |
|
52 | assert_equal 'dir', entry.kind | |
53 | end |
|
53 | end | |
54 |
|
54 | |||
55 | def test_browse_directory |
|
55 | def test_browse_directory | |
56 | get :browse, :id => 1, :path => ['subversion_test'] |
|
56 | get :browse, :id => 1, :path => ['subversion_test'] | |
57 | assert_response :success |
|
57 | assert_response :success | |
58 | assert_template 'browse' |
|
58 | assert_template 'browse' | |
59 | assert_not_nil assigns(:entries) |
|
59 | assert_not_nil assigns(:entries) | |
60 | entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} |
|
60 | entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} | |
61 | assert_equal 'file', entry.kind |
|
61 | assert_equal 'file', entry.kind | |
62 | assert_equal 'subversion_test/helloworld.c', entry.path |
|
62 | assert_equal 'subversion_test/helloworld.c', entry.path | |
63 | end |
|
63 | end | |
64 |
|
64 | |||
65 | def test_entry |
|
65 | def test_entry | |
66 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] |
|
66 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] | |
67 | assert_response :success |
|
67 | assert_response :success | |
68 | assert_template 'entry' |
|
68 | assert_template 'entry' | |
69 | end |
|
69 | end | |
70 |
|
70 | |||
|
71 | def test_entry_not_found | |||
|
72 | get :entry, :id => 1, :path => ['subversion_test', 'zzz.c'] | |||
|
73 | assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |||
|
74 | :content => /Entry and\/or revision doesn't exist/ | |||
|
75 | end | |||
|
76 | ||||
71 | def test_entry_download |
|
77 | def test_entry_download | |
72 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' |
|
78 | get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' | |
73 | assert_response :success |
|
79 | assert_response :success | |
74 | end |
|
80 | end | |
75 |
|
81 | |||
76 | def test_diff |
|
82 | def test_diff | |
77 | get :diff, :id => 1, :rev => 3 |
|
83 | get :diff, :id => 1, :rev => 3 | |
78 | assert_response :success |
|
84 | assert_response :success | |
79 | assert_template 'diff' |
|
85 | assert_template 'diff' | |
80 | end |
|
86 | end | |
81 |
|
87 | |||
82 | def test_annotate |
|
88 | def test_annotate | |
83 | get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c'] |
|
89 | get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c'] | |
84 | assert_response :success |
|
90 | assert_response :success | |
85 | assert_template 'annotate' |
|
91 | assert_template 'annotate' | |
86 | end |
|
92 | end | |
87 | else |
|
93 | else | |
88 | puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" |
|
94 | puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" | |
89 | def test_fake; assert true end |
|
95 | def test_fake; assert true end | |
90 | end |
|
96 | end | |
91 | end |
|
97 | end |
General Comments 0
You need to be logged in to leave comments.
Login now