Project

General

Profile

Feature #10314 » feature-10314.patch

Mizuki ISHIKAWA, 2022-06-22 09:42

View differences:

app/helpers/timelog_helper.rb
26 26
  def activity_collection_for_select_options(time_entry=nil, project=nil)
27 27
    project ||= time_entry.try(:project)
28 28
    project ||= @project
29
    if project.nil?
30
      activities = TimeEntryActivity.shared.active
31
    else
32
      activities = project.activities
33
    end
29
    activities = TimeEntryActivity.chooseable_activities(@project)
34 30

  
35 31
    collection = []
36 32
    if time_entry && time_entry.activity && !time_entry.activity.active?
app/models/time_entry.rb
109 109
    if new_record? && self.activity.nil?
110 110
      if default_activity = TimeEntryActivity.default(self.project)
111 111
        self.activity_id = default_activity.id
112
      elsif (activities = TimeEntryActivity.chooseable_activities(self.project)) && activities.count == 1
113
        self.activity_id = activities.first.id
112 114
      end
113 115
      self.hours = nil if hours == 0
114 116
    end
app/models/time_entry_activity.rb
32 32
    project.activities.detect { |activity| activity.parent_id == default_activity.id }
33 33
  end
34 34

  
35
  def self.chooseable_activities(project=nil)
36
    if project.nil?
37
      TimeEntryActivity.shared.active
38
    else
39
      project.activities
40
    end
41
  end
42

  
35 43
  def option_name
36 44
    OptionName
37 45
  end
test/unit/time_entry_test.rb
139 139
    assert_equal entry.activity_id, project_specific_default_activity.id
140 140
  end
141 141

  
142
  def test_activity_id_should_be_set_automatically_if_there_is_only_one_activity_available
143
    project = Project.find(1)
144
    TimeEntry.all.destroy_all
145
    TimeEntryActivity.destroy_all
146
    only_one_activity = TimeEntryActivity.create!(name: 'Development', parent_id: nil, project_id: nil, is_default: false)
147

  
148
    entry = TimeEntry.new(project: project)
149
    assert_equal entry.activity_id, only_one_activity.id
150
  end
151

  
142 152
  def test_should_accept_future_dates
143 153
    entry = TimeEntry.generate
144 154
    entry.spent_on = User.current.today + 1
(1-1/2)