diff --git a/app/models/journal.rb b/app/models/journal.rb index e3de2b3..e80ae76 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -25,7 +25,7 @@ class Journal < ActiveRecord::Base has_many :details, :class_name => "JournalDetail", :dependent => :delete_all attr_accessor :indice - acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" }, + acts_as_event :title => :event_title, :description => :notes, :author => :user, :group => :issue, @@ -35,8 +35,7 @@ class Journal < ActiveRecord::Base acts_as_activity_provider :type => 'issues', :author_key => :user_id, :find_options => {:include => [{:issue => :project}, :details, :user], - :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + - " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} + :conditions => @conditions} before_create :split_private_notes after_create :send_notification @@ -49,6 +48,14 @@ class Journal < ActiveRecord::Base where("(#{Journal.table_name}.private_notes = ? OR (#{Project.allowed_to_condition(user, :view_private_notes, *args)}))", false) } + def event_title + data_for_assigned if new_status.blank? && !new_assigned.blank? + data_for_status if !new_status.blank? && new_assigned.blank? + data_for_assigned_and_status if !new_assigned.blank? && !new_assigned.blank? + @title = "" if @title.blank? # truncate + @title + end + def save(*args) # Do not save an empty journal (details.empty? && notes.blank?) ? false : super @@ -92,6 +99,11 @@ class Journal < ActiveRecord::Base s ? IssueStatus.find_by_id(s.to_i) : nil end + def new_assigned + a = new_value_for('assigned_to_id') + a ? User.find(a.to_i) : nil + end + def new_value_for(prop) detail_for_attribute(prop).try(:value) end @@ -196,4 +208,39 @@ class Journal < ActiveRecord::Base Mailer.deliver_issue_edit(self) end end + + def data_for_assigned + assigned = ((a = new_assigned) ? " #{a}" : nil) + query_for_assigned + @title = "##{issue.id} - now assigned to : (#{assigned})" + end + + def data_for_status + status = ((s = new_status) ? " (#{s})" : nil) + query_for_status + @title = "#{issue.tracker} ##{issue.id}#{status}: #{issue.subject}" + end + + def data_for_assigned_and_status + assigned = ((a = new_assigned) ? " #{a}" : nil) + status = ((s = new_status) ? " (#{s})" : nil) + query_for_assigned_and_status + @title = "#{issue.tracker} ##{issue.id}#{status}: #{issue.subject}. Now assigned to:(#{assigned})" + end + + def query_for_assigned_and_status + @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" + + " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')" + + " (#{JournalDetail.table_name}.prop_key = 'assigned_to_id')" + end + + def query_for_assigned + @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" + + " (#{JournalDetail.table_name}.prop_key = 'assigned_to_id')" + end + + def query_for_status + @conditions = "#{Journal.table_name}.journalized_type = 'Issue' AND" + + " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')" + end end diff --git a/config/database.yml.example b/config/database.yml.example deleted file mode 100644 index 5bcf17b..0000000 --- a/config/database.yml.example +++ /dev/null @@ -1,52 +0,0 @@ -# Default setup is given for MySQL with ruby1.9. If you're running Redmine -# with MySQL and ruby1.8, replace the adapter name with `mysql`. -# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end. -# Line indentation must be 2 spaces (no tabs). - -production: - adapter: mysql2 - database: redmine - host: localhost - username: root - password: "" - encoding: utf8 - -development: - adapter: mysql2 - database: redmine_development - host: localhost - username: root - password: "" - encoding: utf8 - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - adapter: mysql2 - database: redmine_test - host: localhost - username: root - password: "" - encoding: utf8 - -# PostgreSQL configuration example -#production: -# adapter: postgresql -# database: redmine -# host: localhost -# username: postgres -# password: "postgres" - -# SQLite3 configuration example -#production: -# adapter: sqlite3 -# database: db/redmine.sqlite3 - -# SQL Server configuration example -#production: -# adapter: sqlserver -# database: redmine -# host: localhost -# username: jenkins -# password: jenkins diff --git a/test/fixtures/journal_details.yml b/test/fixtures/journal_details.yml index ef028c8..abe0cfd 100644 --- a/test/fixtures/journal_details.yml +++ b/test/fixtures/journal_details.yml @@ -41,3 +41,17 @@ journal_details_006: value: 060719210727_picture.jpg prop_key: 4 journal_id: 3 +journal_details_007: + old_value: "1" + property: attr + id: 7 + value: "4" + prop_key: "status_id" + journal_id: 6 +journal_details_008: + old_value: + property: attr + id: 8 + value: "2" + prop_key: "assigned_to_id" + journal_id: 6 \ No newline at end of file diff --git a/test/fixtures/journals.yml b/test/fixtures/journals.yml index 2156b78..bd3923b 100644 --- a/test/fixtures/journals.yml +++ b/test/fixtures/journals.yml @@ -34,3 +34,11 @@ journals_005: user_id: 2 journalized_type: Issue journalized_id: 14 +journals_006: + id: 6 + created_on: <%= Date.today.to_date.to_s(:db) %> + notes: "Change Status And Assigned." + user_id: 2 + journalized_type: Issue + journalized_id: 1 + diff --git a/test/functional/activities_controller_test.rb b/test/functional/activities_controller_test.rb index 49d5aff..a5f5a44 100644 --- a/test/functional/activities_controller_test.rb +++ b/test/functional/activities_controller_test.rb @@ -29,6 +29,17 @@ class ActivitiesControllerTest < ActionController::TestCase :journals, :journal_details + def test_edit_issue_with_new_assigned + issue = Project.find(1).issues.first + issue.status_id = 5 + issue.save + get :index, :project_id => 1, :with_subprojects => 0 + assert_not_nil assigns(:events_by_day) + assert_equal css_select('#activity dl dt a')[0].to_s[29..102], "Bug #1 (#{IssueStatus.find(4).name}): Can't print recipes. Now assigned to:( #{User.find(2).name})" + end + + + def test_project_index get :index, :id => 1, :with_subprojects => 0 assert_response :success