Skip to content
This repository was archived by the owner on Jan 30, 2018. It is now read-only.

Commit 9030825

Browse files
committed
#447452: models: manager urgent flag (transitions, previous setting, validations)
1 parent 2ee6a49 commit 9030825

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

app/models/comment.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def previous_assigned
3939
:reject_if => lambda { |google_docs| google_docs['title'].blank? || google_docs['url'].blank? }
4040

4141
attr_accessible :body, :status, :assigned, :hours, :human_hours, :billable,
42-
:upload_ids, :uploads_attributes, :due_on, :google_docs_attributes, :private_ids, :is_private
42+
:upload_ids, :uploads_attributes, :due_on, :urgent, :google_docs_attributes, :private_ids, :is_private
4343

4444
attr_accessor :is_importing
4545
attr_accessor :private_ids
@@ -246,6 +246,7 @@ def cleanup_task
246246
if @last_comment_in_task
247247
self.target.assigned_id = previous_assigned_id
248248
self.target.due_on = previous_due_on
249+
self.target.urgent = previous_urgent
249250
self.target.status = previous_status || Task::STATUSES[:open]
250251
self.target.save!
251252
end

app/models/comment/conversions.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def to_api_hash(options = {})
5454
base[:status] = status
5555
base[:due_on] = due_on
5656
base[:previous_due_on] = previous_due_on
57+
base[:urgent] = urgent
58+
base[:previous_urgent] = previous_urgent
5759
end
5860

5961
if Array(options[:include]).include?(:uploads) && uploads.any?

app/models/comment/tasks.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def previously_closed?
55
end
66

77
def transition?
8-
status_transition? || assigned_transition? || due_on_change?
8+
status_transition? || assigned_transition? || due_on_change? || urgent_change?
99
end
1010

1111
def initial_status?
@@ -20,6 +20,10 @@ def due_on_change?
2020
due_on != previous_due_on
2121
end
2222

23+
def urgent_change?
24+
urgent != previous_urgent
25+
end
26+
2327
def assigned_transition?
2428
assigned_id != previous_assigned_id
2529
end
@@ -60,4 +64,4 @@ def previous_status_name
6064
Task::STATUS_NAMES[previous_status]
6165
end
6266

63-
end
67+
end

app/models/task.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Task < RoleRecord
2424
accepts_nested_attributes_for :comments, :allow_destroy => false,
2525
:reject_if => lambda { |comment| %w[is_private body hours human_hours uploads_attributes google_docs_attributes].all? { |k| comment[k].blank? } }
2626

27-
attr_accessible :name, :assigned_id, :status, :due_on, :comments_attributes, :user, :task_list_id
27+
attr_accessible :name, :assigned_id, :status, :due_on, :comments_attributes, :user, :task_list_id, :urgent
2828

2929
validates_presence_of :user
3030
validates_presence_of :task_list
@@ -49,14 +49,15 @@ class Task < RoleRecord
4949
before_save :save_completed_at
5050
before_validation :remember_comment_created, :on => :update
5151
before_save :update_google_calendar_event, :if => lambda {|t| t.assigned.try(:user) || !t.google_calendar_url_token.blank? }
52+
before_validation :nilize_due_on_for_urgent_tasks
5253

5354
def assigned
5455
@assigned ||= assigned_id ? Person.with_deleted.find_by_id(assigned_id) : nil
5556
end
5657

5758
def track_changes?
5859
(new_record? and not status_new?) or
59-
(updating_user and (status_changed? or assigned_id_changed? or due_on_changed?))
60+
(updating_user and (status_changed? or assigned_id_changed? or due_on_changed? or urgent_changed?))
6061
end
6162

6263
def archived?
@@ -299,7 +300,7 @@ def set_comments_author # before_save
299300
end
300301

301302
def remember_comment_created # before_update
302-
@comment_created = comments.any?(&:new_record?) || assigned_id_changed? || status_changed? || due_on_changed?
303+
@comment_created = comments.any?(&:new_record?) || assigned_id_changed? || status_changed? || due_on_changed? || urgent_changed?
303304
true
304305
end
305306

@@ -331,6 +332,11 @@ def save_changes_to_comment # before_save
331332
comment.previous_due_on = self.due_on_was if due_on_changed?
332333
end
333334

335+
if urgent_changed? or self.new_record?
336+
comment.urgent = self.urgent
337+
comment.previous_urgent = self.urgent_was if urgent_changed?
338+
end
339+
334340
@saved_changes_to_comment = true
335341
true
336342
end
@@ -465,4 +471,8 @@ def delete_old_events_if_required
465471
self.google_calendar_url_token = nil
466472
end
467473
end
474+
475+
def nilize_due_on_for_urgent_tasks
476+
self.due_on = nil if self.urgent?
477+
end
468478
end

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def pending_tasks
260260
Rails.cache.fetch("pending_tasks.#{id}") do
261261
active_project_ids.empty? ? [] :
262262
Task.where(:status => Task::ACTIVE_STATUS_CODES).where(:assigned_id => active_project_ids).order('ID desc').includes(:project).
263-
sort { |a,b| (a.due_on || 1.week.from_now.to_date) <=> (b.due_on || 1.year.from_now.to_date) }
263+
sort { |a,b| [a.urgent? ? 0 : 1, (a.due_on || 1.week.from_now.to_date)] <=> [b.urgent? ? 0 : 1, (b.due_on || 1.year.from_now.to_date)] }
264264
end
265265
end
266266

spec/models/task_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@
5757
task.status_name = 'silly'
5858
}.should raise_error(ArgumentError)
5959
end
60+
61+
it "should nilizie due_on only when urgent flag is set" do
62+
task1 = Factory(:task, :due_on => Time.now, :urgent => false)
63+
task1.due_on.should_not be_nil
64+
65+
task2 = Factory(:task, :due_on => Time.now, :urgent => true)
66+
task2.due_on.should be_nil
67+
end
6068

6169
describe "assigning tasks" do
6270
before do

spec/models/user_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,17 @@
449449
@task.project.update_attribute :archived, true
450450
@user.pending_tasks.should be_empty
451451
end
452+
it "should list active tasks sorted by (urgent, due_on ASC)" do
453+
@task.assign_to(@user)
454+
@task2 = Factory.create(:task, :due_on => 1.minute.from_now)
455+
@task3 = Factory.create(:task, :due_on => 2.days.from_now)
456+
@task4 = Factory.create(:task, :urgent => true)
457+
[@task2, @task3, @task4].each do |task|
458+
task.project.add_user(@user)
459+
task.assign_to(@user)
460+
end
461+
@user.pending_tasks.should == [@task4, @task2, @task3, @task]
462+
end
452463
end
453464

454465
describe "#assigned_tasks_count" do

0 commit comments

Comments
 (0)