Project

General

Profile

Patch #18059 » diff_all_in_one.diff

Marcin Świątkiewicz, 2014-10-10 14:15

View differences:

app/models/journal.rb
25 25
  has_many :details, :class_name => "JournalDetail", :dependent => :delete_all
26 26
  attr_accessor :indice
27 27

  
28
  acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
28
  acts_as_event :title => :event_title,
29 29
                :description => :notes,
30 30
                :author => :user,
31 31
                :group => :issue,
......
35 35
  acts_as_activity_provider :type => 'issues',
36 36
                            :author_key => :user_id,
37 37
                            :find_options => {:include => [{:issue => :project}, :details, :user],
38
                                              :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
39
                                                             " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
38
                            :conditions => @conditions}
40 39

  
41 40
  before_create :split_private_notes
42 41
  after_create :send_notification
......
49 48
      where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false)
50 49
  }
51 50

  
51
  def event_title
52
    data_for_assigned if new_status.blank? && !new_assigned.blank?
53
    data_for_status  if !new_status.blank? && new_assigned.blank?
54
    data_for_assigned_and_status if !new_assigned.blank? && !new_assigned.blank?
55
    @title = "" if @title.blank? # truncate
56
    @title
57
  end
58

  
52 59
  def save(*args)
53 60
    # Do not save an empty journal
54 61
    (details.empty? && notes.blank?) ? false : super
......
92 99
    s ? IssueStatus.find_by_id(s.to_i) : nil
93 100
  end
94 101

  
102
  def new_assigned
103
    a = new_value_for('assigned_to_id')
104
    a ? User.find(a.to_i) : nil
105
  end
106

  
95 107
  def new_value_for(prop)
96 108
    detail_for_attribute(prop).try(:value)
97 109
  end
......
196 208
      Mailer.deliver_issue_edit(self)
197 209
    end
198 210
  end
211

  
212
  def data_for_assigned
213
    assigned = ((a = new_assigned) ? " #{a}" : nil)
214
    query_for_assigned
215
    @title =  "##{issue.id} - now assigned to : (#{assigned})"
216
  end
217

  
218
  def data_for_status
219
    status = ((s = new_status) ? " (#{s})" : nil)
220
    query_for_status
221
    @title = "#{issue.tracker} ##{issue.id}#{status}: #{issue.subject}"
222
  end
223

  
224
  def data_for_assigned_and_status
225
    assigned = ((a = new_assigned) ? " #{a}" : nil)
226
    status = ((s = new_status) ? " (#{s})" : nil)
227
    query_for_assigned_and_status
228
    @title = "#{issue.tracker} ##{issue.id}#{status}: #{issue.subject}. Now assigned to:(#{assigned})"
229
  end
230

  
231
  def query_for_assigned_and_status
232
    @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
233
      " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')" +
234
      " (#{JournalDetail.table_name}.prop_key = 'assigned_to_id')"
235
  end
236

  
237
  def query_for_assigned
238
    @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
239
      " (#{JournalDetail.table_name}.prop_key = 'assigned_to_id')"
240
  end
241

  
242
  def query_for_status
243
    @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" +
244
      " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"
245
  end
199 246
end
config/database.yml.example
1
# Default setup is given for MySQL with ruby1.9. If you're running Redmine
2
# with MySQL and ruby1.8, replace the adapter name with `mysql`.
3
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
4
# Line indentation must be 2 spaces (no tabs).
5

  
6
production:
7
  adapter: mysql2
8
  database: redmine
9
  host: localhost
10
  username: root
11
  password: ""
12
  encoding: utf8
13

  
14
development:
15
  adapter: mysql2
16
  database: redmine_development
17
  host: localhost
18
  username: root
19
  password: ""
20
  encoding: utf8
21

  
22
# Warning: The database defined as "test" will be erased and
23
# re-generated from your development database when you run "rake".
24
# Do not set this db to the same as development or production.
25
test:
26
  adapter: mysql2
27
  database: redmine_test
28
  host: localhost
29
  username: root
30
  password: ""
31
  encoding: utf8
32

  
33
# PostgreSQL configuration example
34
#production:
35
#  adapter: postgresql
36
#  database: redmine
37
#  host: localhost
38
#  username: postgres
39
#  password: "postgres"
40

  
41
# SQLite3 configuration example
42
#production:
43
#  adapter: sqlite3
44
#  database: db/redmine.sqlite3
45

  
46
# SQL Server configuration example
47
#production:
48
#  adapter: sqlserver
49
#  database: redmine
50
#  host: localhost
51
#  username: jenkins
52
#  password: jenkins
test/fixtures/journal_details.yml
41 41
  value: 060719210727_picture.jpg
42 42
  prop_key: 4
43 43
  journal_id: 3
44
journal_details_007:
45
  old_value: "1"
46
  property: attr
47
  id: 7
48
  value: "4"
49
  prop_key: "status_id"
50
  journal_id: 6
51
journal_details_008:
52
  old_value: 
53
  property: attr
54
  id: 8
55
  value: "2"
56
  prop_key: "assigned_to_id"
57
  journal_id: 6
test/fixtures/journals.yml
34 34
  user_id: 2
35 35
  journalized_type: Issue
36 36
  journalized_id: 14
37
journals_006:
38
  id: 6
39
  created_on: <%= Date.today.to_date.to_s(:db) %>
40
  notes: "Change Status And Assigned."
41
  user_id: 2
42
  journalized_type: Issue
43
  journalized_id: 1
44

  
test/functional/activities_controller_test.rb
29 29
           :journals, :journal_details
30 30

  
31 31

  
32
  def test_edit_issue_with_new_assigned
33
    issue = Project.find(1).issues.first
34
    issue.status_id = 5
35
    issue.save
36
    get :index, :project_id => 1, :with_subprojects => 0
37
    assert_not_nil assigns(:events_by_day)
38
    assert_equal css_select('#activity dl dt a')[0].to_s[29..102], "Bug #1 (#{IssueStatus.find(4).name}): Can&#x27;t print recipes. Now assigned to:( #{User.find(2).name})"
39
  end
40
 
41

  
42

  
32 43
  def test_project_index
33 44
    get :index, :id => 1, :with_subprojects => 0
34 45
    assert_response :success
(5-5/6)