Revision 1298:4f746d8966dd .svn/pristine/42

View differences:

.svn/pristine/42/42065d6686eb12e9679c9132fc4c1d7b2537270b.svn-base
1
xml.instruct!
2
xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
3
  xml.title   @title
4
  xml.link    "rel" => "self", "href" => url_for(:format => 'atom', :key => User.current.rss_key, :only_path => false)
5
  xml.link    "rel" => "alternate", "href" => home_url(:only_path => false)
6
  xml.id      url_for(:controller => 'welcome', :only_path => false)
7
  xml.updated((@journals.first ? @journals.first.event_datetime : Time.now).xmlschema)
8
  xml.author  { xml.name "#{Setting.app_title}" }
9
  @journals.each do |change|
10
    issue = change.issue
11
    xml.entry do
12
      xml.title   "#{issue.project.name} - #{issue.tracker.name} ##{issue.id}: #{issue.subject}"
13
      xml.link    "rel" => "alternate", "href" => url_for(:controller => 'issues' , :action => 'show', :id => issue, :only_path => false)
14
      xml.id      url_for(:controller => 'issues' , :action => 'show', :id => issue, :journal_id => change, :only_path => false)
15
      xml.updated change.created_on.xmlschema
16
      xml.author do
17
        xml.name change.user.name
18
        xml.email(change.user.mail) if change.user.is_a?(User) && !change.user.mail.blank? && !change.user.pref.hide_mail
19
      end
20
      xml.content "type" => "html" do
21
        xml.text! '<ul>'
22
        change.details.each do |detail|
23
          xml.text! '<li>' + show_detail(detail, false) + '</li>'
24
        end
25
        xml.text! '</ul>'
26
        xml.text! textilizable(change, :notes, :only_path => false) unless change.notes.blank?
27
      end
28
    end
29
  end
30
end
.svn/pristine/42/4222efb8f989394cbc29df18dfb204374b8d5e79.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2013  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
require File.expand_path('../../../test_helper', __FILE__)
19

  
20
class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base
21
  fixtures :projects, :trackers, :issue_statuses, :issues,
22
           :enumerations, :users, :issue_categories,
23
           :projects_trackers,
24
           :roles,
25
           :member_roles,
26
           :members,
27
           :enabled_modules,
28
           :news
29

  
30
  def setup
31
    Setting.rest_api_enabled = '1'
32
  end
33

  
34
  context "GET /news" do
35
    context ".xml" do
36
      should "return news" do
37
        get '/news.xml'
38

  
39
        assert_tag :tag => 'news',
40
          :attributes => {:type => 'array'},
41
          :child => {
42
            :tag => 'news',
43
            :child => {
44
              :tag => 'id',
45
              :content => '2'
46
            }
47
          }
48
      end
49
    end
50

  
51
    context ".json" do
52
      should "return news" do
53
        get '/news.json'
54

  
55
        json = ActiveSupport::JSON.decode(response.body)
56
        assert_kind_of Hash, json
57
        assert_kind_of Array, json['news']
58
        assert_kind_of Hash, json['news'].first
59
        assert_equal 2, json['news'].first['id']
60
      end
61
    end
62
  end
63

  
64
  context "GET /projects/:project_id/news" do
65
    context ".xml" do
66
      should_allow_api_authentication(:get, "/projects/onlinestore/news.xml")
67

  
68
      should "return news" do
69
        get '/projects/ecookbook/news.xml'
70

  
71
        assert_tag :tag => 'news',
72
          :attributes => {:type => 'array'},
73
          :child => {
74
            :tag => 'news',
75
            :child => {
76
              :tag => 'id',
77
              :content => '2'
78
            }
79
          }
80
      end
81
    end
82

  
83
    context ".json" do
84
      should_allow_api_authentication(:get, "/projects/onlinestore/news.json")
85

  
86
      should "return news" do
87
        get '/projects/ecookbook/news.json'
88

  
89
        json = ActiveSupport::JSON.decode(response.body)
90
        assert_kind_of Hash, json
91
        assert_kind_of Array, json['news']
92
        assert_kind_of Hash, json['news'].first
93
        assert_equal 2, json['news'].first['id']
94
      end
95
    end
96
  end
97
end
.svn/pristine/42/427b264a64a6d9342fb25880cb15db8377d4ab62.svn-base
1
<%= l(:text_issue_added, :id => "##{@issue.id}", :author => h(@issue.author)) %>
2
<hr />
3
<%= render :partial => "issue.html.erb", :locals => { :issue => @issue, :issue_url => @issue_url } %>
.svn/pristine/42/427c435973b09320d012f4a307265921e2e2fd84.svn-base
1
#!/usr/bin/perl
2
#
3
# redMine is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
7
# 
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
# 
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16

  
17
# modify to suit your repository base
18
my $repos_base = '/var/svn';
19

  
20
my $path = '/usr/bin/';
21
my %kwown_commands = map { $_ => 1 } qw/svnserve/;
22

  
23
umask 0002;
24

  
25
exec ('/usr/bin/svnserve', '-r', $repos_base, '-t');
.svn/pristine/42/428612395d9016270f63f32ed9dffa1b755e4922.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
class Issue < ActiveRecord::Base
19
  include Redmine::SafeAttributes
20

  
21
  belongs_to :project
22
  belongs_to :tracker
23
  belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
24
  belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
25
  belongs_to :assigned_to, :class_name => 'Principal', :foreign_key => 'assigned_to_id'
26
  belongs_to :fixed_version, :class_name => 'Version', :foreign_key => 'fixed_version_id'
27
  belongs_to :priority, :class_name => 'IssuePriority', :foreign_key => 'priority_id'
28
  belongs_to :category, :class_name => 'IssueCategory', :foreign_key => 'category_id'
29

  
30
  has_many :journals, :as => :journalized, :dependent => :destroy
31
  has_many :time_entries, :dependent => :delete_all
32
  has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC"
33

  
34
  has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all
35
  has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all
36

  
37
  acts_as_nested_set :scope => 'root_id', :dependent => :destroy
38
  acts_as_attachable :after_add => :attachment_added, :after_remove => :attachment_removed
39
  acts_as_customizable
40
  acts_as_watchable
41
  acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"],
42
                     :include => [:project, :journals],
43
                     # sort by id so that limited eager loading doesn't break with postgresql
44
                     :order_column => "#{table_name}.id"
45
  acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
46
                :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
47
                :type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') }
48

  
49
  acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
50
                            :author_key => :author_id
51

  
52
  DONE_RATIO_OPTIONS = %w(issue_field issue_status)
53

  
54
  attr_reader :current_journal
55

  
56
  validates_presence_of :subject, :priority, :project, :tracker, :author, :status
57

  
58
  validates_length_of :subject, :maximum => 255
59
  validates_inclusion_of :done_ratio, :in => 0..100
60
  validates_numericality_of :estimated_hours, :allow_nil => true
61
  validate :validate_issue
62

  
63
  named_scope :visible, lambda {|*args| { :include => :project,
64
                                          :conditions => Issue.visible_condition(args.shift || User.current, *args) } }
65

  
66
  named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
67

  
68
  named_scope :recently_updated, :order => "#{Issue.table_name}.updated_on DESC"
69
  named_scope :with_limit, lambda { |limit| { :limit => limit} }
70
  named_scope :on_active_project, :include => [:status, :project, :tracker],
71
                                  :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
72

  
73
  named_scope :without_version, lambda {
74
    {
75
      :conditions => { :fixed_version_id => nil}
76
    }
77
  }
78

  
79
  named_scope :with_query, lambda {|query|
80
    {
81
      :conditions => Query.merge_conditions(query.statement)
82
    }
83
  }
84

  
85
  before_create :default_assign
86
  before_save :close_duplicates, :update_done_ratio_from_issue_status
87
  after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal
88
  after_destroy :update_parent_attributes
89

  
90
  # Returns a SQL conditions string used to find all issues visible by the specified user
91
  def self.visible_condition(user, options={})
92
    Project.allowed_to_condition(user, :view_issues, options) do |role, user|
93
      case role.issues_visibility
94
      when 'all'
95
        nil
96
      when 'default'
97
        user_ids = [user.id] + user.groups.map(&:id)
98
        "(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
99
      when 'own'
100
        user_ids = [user.id] + user.groups.map(&:id)
101
        "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
102
      else
103
        '1=0'
104
      end
105
    end
106
  end
107

  
108
  # Returns true if usr or current user is allowed to view the issue
109
  def visible?(usr=nil)
110
    (usr || User.current).allowed_to?(:view_issues, self.project) do |role, user|
111
      case role.issues_visibility
112
      when 'all'
113
        true
114
      when 'default'
115
        !self.is_private? || self.author == user || user.is_or_belongs_to?(assigned_to)
116
      when 'own'
117
        self.author == user || user.is_or_belongs_to?(assigned_to)
118
      else
119
        false
120
      end
121
    end
122
  end
123

  
124
  def after_initialize
125
    if new_record?
126
      # set default values for new records only
127
      self.status ||= IssueStatus.default
128
      self.priority ||= IssuePriority.default
129
    end
130
  end
131

  
132
  # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields
133
  def available_custom_fields
134
    (project && tracker) ? (project.all_issue_custom_fields & tracker.custom_fields.all) : []
135
  end
136

  
137
  def copy_from(arg)
138
    issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
139
    self.attributes = issue.attributes.dup.except("id", "root_id", "parent_id", "lft", "rgt", "created_on", "updated_on")
140
    self.custom_field_values = issue.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
141
    self.status = issue.status
142
    self
143
  end
144

  
145
  # Moves/copies an issue to a new project and tracker
146
  # Returns the moved/copied issue on success, false on failure
147
  def move_to_project(*args)
148
    ret = Issue.transaction do
149
      move_to_project_without_transaction(*args) || raise(ActiveRecord::Rollback)
150
    end || false
151
  end
152

  
153
  def move_to_project_without_transaction(new_project, new_tracker = nil, options = {})
154
    options ||= {}
155
    issue = options[:copy] ? self.class.new.copy_from(self) : self
156

  
157
    if new_project && issue.project_id != new_project.id
158
      # delete issue relations
159
      unless Setting.cross_project_issue_relations?
160
        issue.relations_from.clear
161
        issue.relations_to.clear
162
      end
163
      # issue is moved to another project
164
      # reassign to the category with same name if any
165
      new_category = issue.category.nil? ? nil : new_project.issue_categories.find_by_name(issue.category.name)
166
      issue.category = new_category
167
      # Keep the fixed_version if it's still valid in the new_project
168
      unless new_project.shared_versions.include?(issue.fixed_version)
169
        issue.fixed_version = nil
170
      end
171
      issue.project = new_project
172
      if issue.parent && issue.parent.project_id != issue.project_id
173
        issue.parent_issue_id = nil
174
      end
175
    end
176
    if new_tracker
177
      issue.tracker = new_tracker
178
      issue.reset_custom_values!
179
    end
180
    if options[:copy]
181
      issue.author = User.current
182
      issue.custom_field_values = self.custom_field_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
183
      issue.status = if options[:attributes] && options[:attributes][:status_id]
184
                       IssueStatus.find_by_id(options[:attributes][:status_id])
185
                     else
186
                       self.status
187
                     end
188
    end
189
    # Allow bulk setting of attributes on the issue
190
    if options[:attributes]
191
      issue.attributes = options[:attributes]
192
    end
193
    if issue.save
194
      if options[:copy]
195
        if current_journal && current_journal.notes.present?
196
          issue.init_journal(current_journal.user, current_journal.notes)
197
          issue.current_journal.notify = false
198
          issue.save
199
        end
200
      else
201
        # Manually update project_id on related time entries
202
        TimeEntry.update_all("project_id = #{new_project.id}", {:issue_id => id})
203

  
204
        issue.children.each do |child|
205
          unless child.move_to_project_without_transaction(new_project)
206
            # Move failed and transaction was rollback'd
207
            return false
208
          end
209
        end
210
      end
211
    else
212
      return false
213
    end
214
    issue
215
  end
216

  
217
  def status_id=(sid)
218
    self.status = nil
219
    write_attribute(:status_id, sid)
220
  end
221

  
222
  def priority_id=(pid)
223
    self.priority = nil
224
    write_attribute(:priority_id, pid)
225
  end
226

  
227
  def tracker_id=(tid)
228
    self.tracker = nil
229
    result = write_attribute(:tracker_id, tid)
230
    @custom_field_values = nil
231
    result
232
  end
233

  
234
  def description=(arg)
235
    if arg.is_a?(String)
236
      arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n")
237
    end
238
    write_attribute(:description, arg)
239
  end
240

  
241
  # Overrides attributes= so that tracker_id gets assigned first
242
  def attributes_with_tracker_first=(new_attributes, *args)
243
    return if new_attributes.nil?
244
    new_tracker_id = new_attributes['tracker_id'] || new_attributes[:tracker_id]
245
    if new_tracker_id
246
      self.tracker_id = new_tracker_id
247
    end
248
    send :attributes_without_tracker_first=, new_attributes, *args
249
  end
250
  # Do not redefine alias chain on reload (see #4838)
251
  alias_method_chain(:attributes=, :tracker_first) unless method_defined?(:attributes_without_tracker_first=)
252

  
253
  def estimated_hours=(h)
254
    write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
255
  end
256

  
257
  safe_attributes 'tracker_id',
258
    'status_id',
259
    'parent_issue_id',
260
    'category_id',
261
    'assigned_to_id',
262
    'priority_id',
263
    'fixed_version_id',
264
    'subject',
265
    'description',
266
    'start_date',
267
    'due_date',
268
    'done_ratio',
269
    'estimated_hours',
270
    'custom_field_values',
271
    'custom_fields',
272
    'lock_version',
273
    :if => lambda {|issue, user| issue.new_record? || user.allowed_to?(:edit_issues, issue.project) }
274

  
275
  safe_attributes 'status_id',
276
    'assigned_to_id',
277
    'fixed_version_id',
278
    'done_ratio',
279
    :if => lambda {|issue, user| issue.new_statuses_allowed_to(user).any? }
280

  
281
  safe_attributes 'is_private',
282
    :if => lambda {|issue, user|
283
      user.allowed_to?(:set_issues_private, issue.project) ||
284
        (issue.author == user && user.allowed_to?(:set_own_issues_private, issue.project))
285
    }
286

  
287
  # Safely sets attributes
288
  # Should be called from controllers instead of #attributes=
289
  # attr_accessible is too rough because we still want things like
290
  # Issue.new(:project => foo) to work
291
  # TODO: move workflow/permission checks from controllers to here
292
  def safe_attributes=(attrs, user=User.current)
293
    return unless attrs.is_a?(Hash)
294

  
295
    # User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
296
    attrs = delete_unsafe_attributes(attrs, user)
297
    return if attrs.empty?
298

  
299
    # Tracker must be set before since new_statuses_allowed_to depends on it.
300
    if t = attrs.delete('tracker_id')
301
      self.tracker_id = t
302
    end
303

  
304
    if attrs['status_id']
305
      unless new_statuses_allowed_to(user).collect(&:id).include?(attrs['status_id'].to_i)
306
        attrs.delete('status_id')
307
      end
308
    end
309

  
310
    unless leaf?
311
      attrs.reject! {|k,v| %w(priority_id done_ratio start_date due_date estimated_hours).include?(k)}
312
    end
313

  
314
    if attrs.has_key?('parent_issue_id')
315
      if !user.allowed_to?(:manage_subtasks, project)
316
        attrs.delete('parent_issue_id')
317
      elsif !attrs['parent_issue_id'].blank?
318
        attrs.delete('parent_issue_id') unless Issue.visible(user).exists?(attrs['parent_issue_id'].to_i)
319
      end
320
    end
321

  
322
    self.attributes = attrs
323
  end
324

  
325
  def done_ratio
326
    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
327
      status.default_done_ratio
328
    else
329
      read_attribute(:done_ratio)
330
    end
331
  end
332

  
333
  def self.use_status_for_done_ratio?
334
    Setting.issue_done_ratio == 'issue_status'
335
  end
336

  
337
  def self.use_field_for_done_ratio?
338
    Setting.issue_done_ratio == 'issue_field'
339
  end
340

  
341
  def validate_issue
342
    if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
343
      errors.add :due_date, :not_a_date
344
    end
345

  
346
    if self.due_date and self.start_date and self.due_date < self.start_date
347
      errors.add :due_date, :greater_than_start_date
348
    end
349

  
350
    if start_date && soonest_start && start_date < soonest_start
351
      errors.add :start_date, :invalid
352
    end
353

  
354
    if fixed_version
355
      if !assignable_versions.include?(fixed_version)
356
        errors.add :fixed_version_id, :inclusion
357
      elsif reopened? && fixed_version.closed?
358
        errors.add :base, I18n.t(:error_can_not_reopen_issue_on_closed_version)
359
      end
360
    end
361

  
362
    # Checks that the issue can not be added/moved to a disabled tracker
363
    if project && (tracker_id_changed? || project_id_changed?)
364
      unless project.trackers.include?(tracker)
365
        errors.add :tracker_id, :inclusion
366
      end
367
    end
368

  
369
    # Checks parent issue assignment
370
    if @parent_issue
371
      if @parent_issue.project_id != project_id
372
        errors.add :parent_issue_id, :not_same_project
373
      elsif !new_record?
374
        # moving an existing issue
375
        if @parent_issue.root_id != root_id
376
          # we can always move to another tree
377
        elsif move_possible?(@parent_issue)
378
          # move accepted inside tree
379
        else
380
          errors.add :parent_issue_id, :not_a_valid_parent
381
        end
382
      end
383
    end
384
  end
385

  
386
  # Set the done_ratio using the status if that setting is set.  This will keep the done_ratios
387
  # even if the user turns off the setting later
388
  def update_done_ratio_from_issue_status
389
    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
390
      self.done_ratio = status.default_done_ratio
391
    end
392
  end
393

  
394
  def init_journal(user, notes = "")
395
    @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
396
    @issue_before_change = self.clone
397
    @issue_before_change.status = self.status
398
    @custom_values_before_change = {}
399
    self.custom_values.each {|c| @custom_values_before_change.store c.custom_field_id, c.value }
400
    # Make sure updated_on is updated when adding a note.
401
    updated_on_will_change!
402
    @current_journal
403
  end
404

  
405
  # Return true if the issue is closed, otherwise false
406
  def closed?
407
    self.status.is_closed?
408
  end
409

  
410
  # Return true if the issue is being reopened
411
  def reopened?
412
    if !new_record? && status_id_changed?
413
      status_was = IssueStatus.find_by_id(status_id_was)
414
      status_new = IssueStatus.find_by_id(status_id)
415
      if status_was && status_new && status_was.is_closed? && !status_new.is_closed?
416
        return true
417
      end
418
    end
419
    false
420
  end
421

  
422
  # Return true if the issue is being closed
423
  def closing?
424
    if !new_record? && status_id_changed?
425
      status_was = IssueStatus.find_by_id(status_id_was)
426
      status_new = IssueStatus.find_by_id(status_id)
427
      if status_was && status_new && !status_was.is_closed? && status_new.is_closed?
428
        return true
429
      end
430
    end
431
    false
432
  end
433

  
434
  # Returns true if the issue is overdue
435
  def overdue?
436
    !due_date.nil? && (due_date < Date.today) && !status.is_closed?
437
  end
438

  
439
  # Is the amount of work done less than it should for the due date
440
  def behind_schedule?
441
    return false if start_date.nil? || due_date.nil?
442
    done_date = start_date + ((due_date - start_date+1)* done_ratio/100).floor
443
    return done_date <= Date.today
444
  end
445

  
446
  # Does this issue have children?
447
  def children?
448
    !leaf?
449
  end
450

  
451
  # Users the issue can be assigned to
452
  def assignable_users
453
    users = project.assignable_users
454
    users << author if author
455
    users << assigned_to if assigned_to
456
    users.uniq.sort
457
  end
458

  
459
  # Versions that the issue can be assigned to
460
  def assignable_versions
461
    @assignable_versions ||= (project.shared_versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort
462
  end
463

  
464
  # Returns true if this issue is blocked by another issue that is still open
465
  def blocked?
466
    !relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
467
  end
468

  
469
  # Returns an array of status that user is able to apply
470
  def new_statuses_allowed_to(user, include_default=false)
471
    statuses = status.find_new_statuses_allowed_to(
472
      user.roles_for_project(project),
473
      tracker,
474
      author == user,
475
      assigned_to_id_changed? ? assigned_to_id_was == user.id : assigned_to_id == user.id
476
      )
477
    statuses << status unless statuses.empty?
478
    statuses << IssueStatus.default if include_default
479
    statuses = statuses.uniq.sort
480
    blocked? ? statuses.reject {|s| s.is_closed?} : statuses
481
  end
482

  
483
  # Returns the mail adresses of users that should be notified
484
  def recipients
485
    notified = project.notified_users
486
    # Author and assignee are always notified unless they have been
487
    # locked or don't want to be notified
488
    notified << author if author && author.active? && author.notify_about?(self)
489
    if assigned_to
490
      if assigned_to.is_a?(Group)
491
        notified += assigned_to.users.select {|u| u.active? && u.notify_about?(self)}
492
      else
493
        notified << assigned_to if assigned_to.active? && assigned_to.notify_about?(self)
494
      end
495
    end
496
    notified.uniq!
497
    # Remove users that can not view the issue
498
    notified.reject! {|user| !visible?(user)}
499
    notified.collect(&:mail)
500
  end
501

  
502
  # Returns the total number of hours spent on this issue and its descendants
503
  #
504
  # Example:
505
  #   spent_hours => 0.0
506
  #   spent_hours => 50.2
507
  def spent_hours
508
    @spent_hours ||= self_and_descendants.sum("#{TimeEntry.table_name}.hours", :include => :time_entries).to_f || 0.0
509
  end
510

  
511
  def relations
512
    @relations ||= (relations_from + relations_to).sort
513
  end
514

  
515
  # Preloads relations for a collection of issues
516
  def self.load_relations(issues)
517
    if issues.any?
518
      relations = IssueRelation.all(:conditions => ["issue_from_id IN (:ids) OR issue_to_id IN (:ids)", {:ids => issues.map(&:id)}])
519
      issues.each do |issue|
520
        issue.instance_variable_set "@relations", relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id}
521
      end
522
    end
523
  end
524

  
525
  # Finds an issue relation given its id.
526
  def find_relation(relation_id)
527
    IssueRelation.find(relation_id, :conditions => ["issue_to_id = ? OR issue_from_id = ?", id, id])
528
  end
529

  
530
  def all_dependent_issues(except=[])
531
    except << self
532
    dependencies = []
533
    relations_from.each do |relation|
534
      if relation.issue_to && !except.include?(relation.issue_to)
535
        dependencies << relation.issue_to
536
        dependencies += relation.issue_to.all_dependent_issues(except)
537
      end
538
    end
539
    dependencies
540
  end
541

  
542
  # Returns an array of issues that duplicate this one
543
  def duplicates
544
    relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from}
545
  end
546

  
547
  # Returns the due date or the target due date if any
548
  # Used on gantt chart
549
  def due_before
550
    due_date || (fixed_version ? fixed_version.effective_date : nil)
551
  end
552

  
553
  # Returns the time scheduled for this issue.
554
  #
555
  # Example:
556
  #   Start Date: 2/26/09, End Date: 3/04/09
557
  #   duration => 6
558
  def duration
559
    (start_date && due_date) ? due_date - start_date : 0
560
  end
561

  
562
  def soonest_start
563
    @soonest_start ||= (
564
        relations_to.collect{|relation| relation.successor_soonest_start} +
565
        ancestors.collect(&:soonest_start)
566
      ).compact.max
567
  end
568

  
569
  def reschedule_after(date)
570
    return if date.nil?
571
    if leaf?
572
      if start_date.nil? || start_date < date
573
        self.start_date, self.due_date = date, date + duration
574
        save
575
      end
576
    else
577
      leaves.each do |leaf|
578
        leaf.reschedule_after(date)
579
      end
580
    end
581
  end
582

  
583
  def <=>(issue)
584
    if issue.nil?
585
      -1
586
    elsif root_id != issue.root_id
587
      (root_id || 0) <=> (issue.root_id || 0)
588
    else
589
      (lft || 0) <=> (issue.lft || 0)
590
    end
591
  end
592

  
593
  def to_s
594
    "#{tracker} ##{id}: #{subject}"
595
  end
596

  
597
  # Returns a string of css classes that apply to the issue
598
  def css_classes
599
    s = "issue status-#{status.position} priority-#{priority.position}"
600
    s << ' closed' if closed?
601
    s << ' overdue' if overdue?
602
    s << ' child' if child?
603
    s << ' parent' unless leaf?
604
    s << ' private' if is_private?
605
    s << ' created-by-me' if User.current.logged? && author_id == User.current.id
606
    s << ' assigned-to-me' if User.current.logged? && assigned_to_id == User.current.id
607
    s
608
  end
609

  
610
  # Saves an issue, time_entry, attachments, and a journal from the parameters
611
  # Returns false if save fails
612
  def save_issue_with_child_records(params, existing_time_entry=nil)
613
    Issue.transaction do
614
      if params[:time_entry] && (params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) && User.current.allowed_to?(:log_time, project)
615
        @time_entry = existing_time_entry || TimeEntry.new
616
        @time_entry.project = project
617
        @time_entry.issue = self
618
        @time_entry.user = User.current
619
        @time_entry.spent_on = User.current.today
620
        @time_entry.attributes = params[:time_entry]
621
        self.time_entries << @time_entry
622
      end
623

  
624
      if valid?
625
        attachments = Attachment.attach_files(self, params[:attachments])
626
        # TODO: Rename hook
627
        Redmine::Hook.call_hook(:controller_issues_edit_before_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
628
        begin
629
          if save
630
            # TODO: Rename hook
631
            Redmine::Hook.call_hook(:controller_issues_edit_after_save, { :params => params, :issue => self, :time_entry => @time_entry, :journal => @current_journal})
632
          else
633
            raise ActiveRecord::Rollback
634
          end
635
        rescue ActiveRecord::StaleObjectError
636
          attachments[:files].each(&:destroy)
637
          errors.add :base, l(:notice_locking_conflict)
638
          raise ActiveRecord::Rollback
639
        end
640
      end
641
    end
642
  end
643

  
644
  # Unassigns issues from +version+ if it's no longer shared with issue's project
645
  def self.update_versions_from_sharing_change(version)
646
    # Update issues assigned to the version
647
    update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id])
648
  end
649

  
650
  # Unassigns issues from versions that are no longer shared
651
  # after +project+ was moved
652
  def self.update_versions_from_hierarchy_change(project)
653
    moved_project_ids = project.self_and_descendants.reload.collect(&:id)
654
    # Update issues of the moved projects and issues assigned to a version of a moved project
655
    Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids])
656
  end
657

  
658
  def parent_issue_id=(arg)
659
    parent_issue_id = arg.blank? ? nil : arg.to_i
660
    if parent_issue_id && @parent_issue = Issue.find_by_id(parent_issue_id)
661
      @parent_issue.id
662
    else
663
      @parent_issue = nil
664
      nil
665
    end
666
  end
667

  
668
  def parent_issue_id
669
    if instance_variable_defined? :@parent_issue
670
      @parent_issue.nil? ? nil : @parent_issue.id
671
    else
672
      parent_id
673
    end
674
  end
675

  
676
  # Extracted from the ReportsController.
677
  def self.by_tracker(project)
678
    count_and_group_by(:project => project,
679
                       :field => 'tracker_id',
680
                       :joins => Tracker.table_name)
681
  end
682

  
683
  def self.by_version(project)
684
    count_and_group_by(:project => project,
685
                       :field => 'fixed_version_id',
686
                       :joins => Version.table_name)
687
  end
688

  
689
  def self.by_priority(project)
690
    count_and_group_by(:project => project,
691
                       :field => 'priority_id',
692
                       :joins => IssuePriority.table_name)
693
  end
694

  
695
  def self.by_category(project)
696
    count_and_group_by(:project => project,
697
                       :field => 'category_id',
698
                       :joins => IssueCategory.table_name)
699
  end
700

  
701
  def self.by_assigned_to(project)
702
    count_and_group_by(:project => project,
703
                       :field => 'assigned_to_id',
704
                       :joins => User.table_name)
705
  end
706

  
707
  def self.by_author(project)
708
    count_and_group_by(:project => project,
709
                       :field => 'author_id',
710
                       :joins => User.table_name)
711
  end
712

  
713
  def self.by_subproject(project)
714
    ActiveRecord::Base.connection.select_all("select    s.id as status_id, 
715
                                                s.is_closed as closed, 
716
                                                #{Issue.table_name}.project_id as project_id,
717
                                                count(#{Issue.table_name}.id) as total 
718
                                              from 
719
                                                #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s
720
                                              where 
721
                                                #{Issue.table_name}.status_id=s.id
722
                                                and #{Issue.table_name}.project_id = #{Project.table_name}.id
723
                                                and #{visible_condition(User.current, :project => project, :with_subprojects => true)}
724
                                                and #{Issue.table_name}.project_id <> #{project.id}
725
                                              group by s.id, s.is_closed, #{Issue.table_name}.project_id") if project.descendants.active.any?
726
  end
727
  # End ReportsController extraction
728

  
729
  # Returns an array of projects that current user can move issues to
730
  def self.allowed_target_projects_on_move
731
    projects = []
732
    if User.current.admin?
733
      # admin is allowed to move issues to any active (visible) project
734
      projects = Project.visible.all
735
    elsif User.current.logged?
736
      if Role.non_member.allowed_to?(:move_issues)
737
        projects = Project.visible.all
738
      else
739
        User.current.memberships.each {|m| projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
740
      end
741
    end
742
    projects
743
  end
744

  
745
  private
746

  
747
  def update_nested_set_attributes
748
    if root_id.nil?
749
      # issue was just created
750
      self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id)
751
      set_default_left_and_right
752
      Issue.update_all("root_id = #{root_id}, lft = #{lft}, rgt = #{rgt}", ["id = ?", id])
753
      if @parent_issue
754
        move_to_child_of(@parent_issue)
755
      end
756
      reload
757
    elsif parent_issue_id != parent_id
758
      former_parent_id = parent_id
759
      # moving an existing issue
760
      if @parent_issue && @parent_issue.root_id == root_id
761
        # inside the same tree
762
        move_to_child_of(@parent_issue)
763
      else
764
        # to another tree
765
        unless root?
766
          move_to_right_of(root)
767
          reload
768
        end
769
        old_root_id = root_id
770
        self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id )
771
        target_maxright = nested_set_scope.maximum(right_column_name) || 0
772
        offset = target_maxright + 1 - lft
773
        Issue.update_all("root_id = #{root_id}, lft = lft + #{offset}, rgt = rgt + #{offset}",
774
                          ["root_id = ? AND lft >= ? AND rgt <= ? ", old_root_id, lft, rgt])
775
        self[left_column_name] = lft + offset
776
        self[right_column_name] = rgt + offset
777
        if @parent_issue
778
          move_to_child_of(@parent_issue)
779
        end
780
      end
781
      reload
782
      # delete invalid relations of all descendants
783
      self_and_descendants.each do |issue|
784
        issue.relations.each do |relation|
785
          relation.destroy unless relation.valid?
786
        end
787
      end
788
      # update former parent
789
      recalculate_attributes_for(former_parent_id) if former_parent_id
790
    end
791
    remove_instance_variable(:@parent_issue) if instance_variable_defined?(:@parent_issue)
792
  end
793

  
794
  def update_parent_attributes
795
    recalculate_attributes_for(parent_id) if parent_id
796
  end
797

  
798
  def recalculate_attributes_for(issue_id)
799
    if issue_id && p = Issue.find_by_id(issue_id)
800
      # priority = highest priority of children
801
      if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :include => :priority)
802
        p.priority = IssuePriority.find_by_position(priority_position)
803
      end
804

  
805
      # start/due dates = lowest/highest dates of children
806
      p.start_date = p.children.minimum(:start_date)
807
      p.due_date = p.children.maximum(:due_date)
808
      if p.start_date && p.due_date && p.due_date < p.start_date
809
        p.start_date, p.due_date = p.due_date, p.start_date
810
      end
811

  
812
      # done ratio = weighted average ratio of leaves
813
      unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
814
        leaves_count = p.leaves.count
815
        if leaves_count > 0
816
          average = p.leaves.average(:estimated_hours).to_f
817
          if average == 0
818
            average = 1
819
          end
820
          done = p.leaves.sum("COALESCE(estimated_hours, #{average}) * (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :include => :status).to_f
821
          progress = done / (average * leaves_count)
822
          p.done_ratio = progress.round
823
        end
824
      end
825

  
826
      # estimate = sum of leaves estimates
827
      p.estimated_hours = p.leaves.sum(:estimated_hours).to_f
828
      p.estimated_hours = nil if p.estimated_hours == 0.0
829

  
830
      # ancestors will be recursively updated
831
      p.save(false)
832
    end
833
  end
834

  
835
  # Update issues so their versions are not pointing to a
836
  # fixed_version that is not shared with the issue's project
837
  def self.update_versions(conditions=nil)
838
    # Only need to update issues with a fixed_version from
839
    # a different project and that is not systemwide shared
840
    Issue.all(:conditions => merge_conditions("#{Issue.table_name}.fixed_version_id IS NOT NULL" +
841
                                                " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" +
842
                                                " AND #{Version.table_name}.sharing <> 'system'",
843
                                                conditions),
844
              :include => [:project, :fixed_version]
845
              ).each do |issue|
846
      next if issue.project.nil? || issue.fixed_version.nil?
847
      unless issue.project.shared_versions.include?(issue.fixed_version)
848
        issue.init_journal(User.current)
849
        issue.fixed_version = nil
850
        issue.save
851
      end
852
    end
853
  end
854

  
855
  # Callback on attachment deletion
856
  def attachment_added(obj)
857
    if @current_journal && !obj.new_record?
858
      @current_journal.details << JournalDetail.new(:property => 'attachment', :prop_key => obj.id, :value => obj.filename)
859
    end
860
  end
861

  
862
  # Callback on attachment deletion
863
  def attachment_removed(obj)
864
    journal = init_journal(User.current)
865
    journal.details << JournalDetail.new(:property => 'attachment',
866
                                         :prop_key => obj.id,
867
                                         :old_value => obj.filename)
868
    journal.save
869
  end
870

  
871
  # Default assignment based on category
872
  def default_assign
873
    if assigned_to.nil? && category && category.assigned_to
874
      self.assigned_to = category.assigned_to
875
    end
876
  end
877

  
878
  # Updates start/due dates of following issues
879
  def reschedule_following_issues
880
    if start_date_changed? || due_date_changed?
881
      relations_from.each do |relation|
882
        relation.set_issue_to_dates
883
      end
884
    end
885
  end
886

  
887
  # Closes duplicates if the issue is being closed
888
  def close_duplicates
889
    if closing?
890
      duplicates.each do |duplicate|
891
        # Reload is need in case the duplicate was updated by a previous duplicate
892
        duplicate.reload
893
        # Don't re-close it if it's already closed
894
        next if duplicate.closed?
895
        # Same user and notes
896
        if @current_journal
897
          duplicate.init_journal(@current_journal.user, @current_journal.notes)
898
        end
899
        duplicate.update_attribute :status, self.status
900
      end
901
    end
902
  end
903

  
904
  # Saves the changes in a Journal
905
  # Called after_save
906
  def create_journal
907
    if @current_journal
908
      # attributes changes
909
      (Issue.column_names - %w(id root_id lft rgt lock_version created_on updated_on)).each {|c|
910
        before = @issue_before_change.send(c)
911
        after = send(c)
912
        next if before == after || (before.blank? && after.blank?)
913
        @current_journal.details << JournalDetail.new(:property => 'attr',
914
                                                      :prop_key => c,
915
                                                      :old_value => @issue_before_change.send(c),
916
                                                      :value => send(c))
917
      }
918
      # custom fields changes
919
      custom_values.each {|c|
920
        next if (@custom_values_before_change[c.custom_field_id]==c.value ||
921
                  (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
922
        @current_journal.details << JournalDetail.new(:property => 'cf',
923
                                                      :prop_key => c.custom_field_id,
924
                                                      :old_value => @custom_values_before_change[c.custom_field_id],
925
                                                      :value => c.value)
926
      }
927
      @current_journal.save
928
      # reset current journal
929
      init_journal @current_journal.user, @current_journal.notes
930
    end
931
  end
932

  
933
  # Query generator for selecting groups of issue counts for a project
934
  # based on specific criteria
935
  #
936
  # Options
937
  # * project - Project to search in.
938
  # * field - String. Issue field to key off of in the grouping.
939
  # * joins - String. The table name to join against.
940
  def self.count_and_group_by(options)
941
    project = options.delete(:project)
942
    select_field = options.delete(:field)
943
    joins = options.delete(:joins)
944

  
945
    where = "#{Issue.table_name}.#{select_field}=j.id"
946

  
947
    ActiveRecord::Base.connection.select_all("select    s.id as status_id, 
948
                                                s.is_closed as closed, 
949
                                                j.id as #{select_field},
950
                                                count(#{Issue.table_name}.id) as total 
951
                                              from 
952
                                                  #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s, #{joins} j
953
                                              where 
954
                                                #{Issue.table_name}.status_id=s.id 
955
                                                and #{where}
956
                                                and #{Issue.table_name}.project_id=#{Project.table_name}.id
957
                                                and #{visible_condition(User.current, :project => project)}
958
                                              group by s.id, s.is_closed, j.id")
959
  end
960
end
.svn/pristine/42/428ba80948c53d51011877b4e85f463b9e15c19b.svn-base
1
$('#users').html('<%= escape_javascript(render_principals_for_new_group_users(@group)) %>');
.svn/pristine/42/428bfa93a4c970791698a943e257eddabf08b22f.svn-base
1
<h4><%= link_to h(document.title), :controller => 'documents', :action => 'show', :id => document %></h4>
2
<p><em><%= format_time(document.updated_on) %></em></p>
3

  
4
<div class="wiki">
5
  <%= textilizable(truncate_lines(document.description), :object => document) %>
6
</div>
.svn/pristine/42/42cbd8a4f24d085f0d8c0a431c99b911f57d4034.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2013  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
require File.expand_path('../../test_helper', __FILE__)
19

  
20
class RepositoriesGitControllerTest < ActionController::TestCase
21
  tests RepositoriesController
22

  
23
  fixtures :projects, :users, :roles, :members, :member_roles,
24
           :repositories, :enabled_modules
25

  
26
  REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27
  REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28
  PRJ_ID     = 3
29
  CHAR_1_HEX = "\xc3\x9c"
30
  NUM_REV = 28
31

  
32
  ## Git, Mercurial and CVS path encodings are binary.
33
  ## Subversion supports URL encoding for path.
34
  ## Redmine Mercurial adapter and extension use URL encoding.
35
  ## Git accepts only binary path in command line parameter.
36
  ## So, there is no way to use binary command line parameter in JRuby.
37
  JRUBY_SKIP     = (RUBY_PLATFORM == 'java')
38
  JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39

  
40
  def setup
41
    @ruby19_non_utf8_pass =
42
      (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43

  
44
    User.current = nil
45
    @project    = Project.find(PRJ_ID)
46
    @repository = Repository::Git.create(
47
                      :project       => @project,
48
                      :url           => REPOSITORY_PATH,
49
                      :path_encoding => 'ISO-8859-1'
50
                      )
51
    assert @repository
52
    @char_1        = CHAR_1_HEX.dup
53
    if @char_1.respond_to?(:force_encoding)
54
      @char_1.force_encoding('UTF-8')
55
    end
56
  end
57

  
58
  def test_create_and_update
59
    @request.session[:user_id] = 1
60
    assert_difference 'Repository.count' do
61
      post :create, :project_id => 'subproject1',
62
                    :repository_scm => 'Git',
63
                    :repository => {
64
                       :url => '/test',
65
                       :is_default => '0',
66
                       :identifier => 'test-create',
67
                       :extra_report_last_commit => '1',
68
                     }
69
    end
70
    assert_response 302
71
    repository = Repository.first(:order => 'id DESC')
72
    assert_kind_of Repository::Git, repository
73
    assert_equal '/test', repository.url
74
    assert_equal true, repository.extra_report_last_commit
75

  
76
    put :update, :id => repository.id,
77
                 :repository => {
78
                     :extra_report_last_commit => '0'
79
                 }
80
    assert_response 302
81
    repo2 = Repository.find(repository.id)
82
    assert_equal false, repo2.extra_report_last_commit
83
  end
84

  
85
  if File.directory?(REPOSITORY_PATH)
86
    ## Ruby uses ANSI api to fork a process on Windows.
87
    ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
88
    ## and these are incompatible with ASCII.
89
    ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
90
    ## http://code.google.com/p/msysgit/issues/detail?id=80
91
    ## So, Latin-1 path tests fail on Japanese Windows
92
    WINDOWS_PASS = (Redmine::Platform.mswin? &&
93
                         Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
94
    WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
95

  
96
    def test_get_new
97
      @request.session[:user_id] = 1
98
      @project.repository.destroy
99
      get :new, :project_id => 'subproject1', :repository_scm => 'Git'
100
      assert_response :success
101
      assert_template 'new'
102
      assert_kind_of Repository::Git, assigns(:repository)
103
      assert assigns(:repository).new_record?
104
    end
105

  
106
    def test_browse_root
107
      assert_equal 0, @repository.changesets.count
108
      @repository.fetch_changesets
109
      @project.reload
110
      assert_equal NUM_REV, @repository.changesets.count
111

  
112
      get :show, :id => PRJ_ID
113
      assert_response :success
114
      assert_template 'show'
115
      assert_not_nil assigns(:entries)
116
      assert_equal 9, assigns(:entries).size
117
      assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
118
      assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
119
      assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
120
      assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
121
      assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
122
      assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
123
      assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
124
      assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
125
      assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
126
      assert_not_nil assigns(:changesets)
127
      assert assigns(:changesets).size > 0
128
    end
129

  
130
    def test_browse_branch
131
      assert_equal 0, @repository.changesets.count
132
      @repository.fetch_changesets
133
      @project.reload
134
      assert_equal NUM_REV, @repository.changesets.count
135
      get :show, :id => PRJ_ID, :rev => 'test_branch'
136
      assert_response :success
137
      assert_template 'show'
138
      assert_not_nil assigns(:entries)
139
      assert_equal 4, assigns(:entries).size
140
      assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
141
      assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
142
      assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
143
      assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
144
      assert_not_nil assigns(:changesets)
145
      assert assigns(:changesets).size > 0
146
    end
147

  
148
    def test_browse_tag
149
      assert_equal 0, @repository.changesets.count
150
      @repository.fetch_changesets
151
      @project.reload
152
      assert_equal NUM_REV, @repository.changesets.count
153
       [
154
        "tag00.lightweight",
155
        "tag01.annotated",
156
       ].each do |t1|
157
        get :show, :id => PRJ_ID, :rev => t1
158
        assert_response :success
159
        assert_template 'show'
160
        assert_not_nil assigns(:entries)
161
        assert assigns(:entries).size > 0
162
        assert_not_nil assigns(:changesets)
163
        assert assigns(:changesets).size > 0
164
      end
165
    end
166

  
167
    def test_browse_directory
168
      assert_equal 0, @repository.changesets.count
169
      @repository.fetch_changesets
170
      @project.reload
171
      assert_equal NUM_REV, @repository.changesets.count
172
      get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
173
      assert_response :success
174
      assert_template 'show'
175
      assert_not_nil assigns(:entries)
176
      assert_equal ['edit.png'], assigns(:entries).collect(&:name)
177
      entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
178
      assert_not_nil entry
179
      assert_equal 'file', entry.kind
180
      assert_equal 'images/edit.png', entry.path
181
      assert_not_nil assigns(:changesets)
182
      assert assigns(:changesets).size > 0
183
    end
184

  
185
    def test_browse_at_given_revision
186
      assert_equal 0, @repository.changesets.count
187
      @repository.fetch_changesets
188
      @project.reload
189
      assert_equal NUM_REV, @repository.changesets.count
190
      get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
191
          :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
192
      assert_response :success
193
      assert_template 'show'
194
      assert_not_nil assigns(:entries)
195
      assert_equal ['delete.png'], assigns(:entries).collect(&:name)
196
      assert_not_nil assigns(:changesets)
197
      assert assigns(:changesets).size > 0
198
    end
199

  
200
    def test_changes
201
      get :changes, :id => PRJ_ID,
202
          :path => repository_path_hash(['images', 'edit.png'])[:param]
203
      assert_response :success
204
      assert_template 'changes'
205
      assert_tag :tag => 'h2', :content => 'edit.png'
206
    end
207

  
208
    def test_entry_show
209
      get :entry, :id => PRJ_ID,
210
          :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
211
      assert_response :success
212
      assert_template 'entry'
213
      # Line 19
214
      assert_tag :tag => 'th',
215
                 :content => '11',
216
                 :attributes => { :class => 'line-num' },
217
                 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
218
    end
219

  
220
    def test_entry_show_latin_1
221
      if @ruby19_non_utf8_pass
222
        puts_ruby19_non_utf8_pass()
223
      elsif WINDOWS_PASS
224
        puts WINDOWS_SKIP_STR
225
      elsif JRUBY_SKIP
226
        puts JRUBY_SKIP_STR
227
      else
228
        with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
229
          ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
230
            get :entry, :id => PRJ_ID,
231
                :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
232
                :rev => r1
233
            assert_response :success
234
            assert_template 'entry'
235
            assert_tag :tag => 'th',
236
                   :content => '1',
237
                   :attributes => { :class => 'line-num' },
238
                   :sibling => { :tag => 'td',
239
                                 :content => /test-#{@char_1}.txt/ }
240
          end
241
        end
242
      end
243
    end
244

  
245
    def test_entry_download
246
      get :entry, :id => PRJ_ID,
247
          :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
248
          :format => 'raw'
249
      assert_response :success
250
      # File content
251
      assert @response.body.include?('WITHOUT ANY WARRANTY')
252
    end
253

  
254
    def test_directory_entry
255
      get :entry, :id => PRJ_ID,
256
          :path => repository_path_hash(['sources'])[:param]
257
      assert_response :success
258
      assert_template 'show'
259
      assert_not_nil assigns(:entry)
260
      assert_equal 'sources', assigns(:entry).name
261
    end
262

  
263
    def test_diff
264
      assert_equal true, @repository.is_default
265
      assert_nil @repository.identifier
266
      assert_equal 0, @repository.changesets.count
267
      @repository.fetch_changesets
268
      @project.reload
269
      assert_equal NUM_REV, @repository.changesets.count
270
      # Full diff of changeset 2f9c0091
271
      ['inline', 'sbs'].each do |dt|
272
        get :diff,
273
            :id   => PRJ_ID,
274
            :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
275
            :type => dt
276
        assert_response :success
277
        assert_template 'diff'
278
        # Line 22 removed
279
        assert_tag :tag => 'th',
280
                   :content => /22/,
281
                   :sibling => { :tag => 'td',
282
                                 :attributes => { :class => /diff_out/ },
283
                                 :content => /def remove/ }
284
        assert_tag :tag => 'h2', :content => /2f9c0091/
285
      end
286
    end
287

  
288
    def test_diff_with_rev_and_path
289
      assert_equal 0, @repository.changesets.count
290
      @repository.fetch_changesets
291
      @project.reload
292
      assert_equal NUM_REV, @repository.changesets.count
293
      with_settings :diff_max_lines_displayed => 1000 do
294
        # Full diff of changeset 2f9c0091
295
        ['inline', 'sbs'].each do |dt|
296
          get :diff,
297
              :id   => PRJ_ID,
298
              :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
299
              :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
300
              :type => dt
301
          assert_response :success
302
          assert_template 'diff'
303
          # Line 22 removed
304
          assert_tag :tag => 'th',
305
                     :content => '22',
306
                     :sibling => { :tag => 'td',
307
                                   :attributes => { :class => /diff_out/ },
308
                                   :content => /def remove/ }
309
          assert_tag :tag => 'h2', :content => /2f9c0091/
310
        end
311
      end
312
    end
313

  
314
    def test_diff_truncated
315
      assert_equal 0, @repository.changesets.count
316
      @repository.fetch_changesets
317
      @project.reload
318
      assert_equal NUM_REV, @repository.changesets.count
319

  
320
      with_settings :diff_max_lines_displayed => 5 do
321
        # Truncated diff of changeset 2f9c0091
322
        with_cache do
323
          with_settings :default_language => 'en' do
324
            get :diff, :id   => PRJ_ID, :type => 'inline',
325
                :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
326
            assert_response :success
327
            assert @response.body.include?("... This diff was truncated")
328
          end
329
          with_settings :default_language => 'fr' do
330
            get :diff, :id   => PRJ_ID, :type => 'inline',
331
                :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
332
            assert_response :success
333
            assert ! @response.body.include?("... This diff was truncated")
334
            assert @response.body.include?("... Ce diff")
335
          end
336
        end
337
      end
338
    end
339

  
340
    def test_diff_two_revs
341
      assert_equal 0, @repository.changesets.count
342
      @repository.fetch_changesets
343
      @project.reload
344
      assert_equal NUM_REV, @repository.changesets.count
345
      ['inline', 'sbs'].each do |dt|
346
        get :diff,
347
            :id     => PRJ_ID,
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff