Commit 4d520921f9aa09ae28badadd5661e0d5107dcb11
Committed by
Daniela Feitosa
1 parent
794934ff
Exists in
staging
and in
42 other branches
Redefining tasks status named_scopes
Showing
3 changed files
with
42 additions
and
2 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
| @@ -9,7 +9,7 @@ class TasksController < MyProfileController | @@ -9,7 +9,7 @@ class TasksController < MyProfileController | ||
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | def processed | 11 | def processed |
| 12 | - @tasks = Task.to(profile).finished.sort_by(&:created_at) | 12 | + @tasks = Task.to(profile).closed.sort_by(&:created_at) |
| 13 | end | 13 | end |
| 14 | 14 | ||
| 15 | VALID_DECISIONS = [ 'finish', 'cancel', 'skip' ] | 15 | VALID_DECISIONS = [ 'finish', 'cancel', 'skip' ] |
app/models/task.rb
| @@ -267,7 +267,10 @@ class Task < ActiveRecord::Base | @@ -267,7 +267,10 @@ class Task < ActiveRecord::Base | ||
| 267 | end | 267 | end |
| 268 | 268 | ||
| 269 | named_scope :pending, :conditions => { :status => Task::Status::ACTIVE } | 269 | named_scope :pending, :conditions => { :status => Task::Status::ACTIVE } |
| 270 | - named_scope :finished, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] } | 270 | + named_scope :hidden, :conditions => { :status => Task::Status::HIDDEN } |
| 271 | + named_scope :finished, :conditions => { :status => Task::Status::FINISHED } | ||
| 272 | + named_scope :canceled, :conditions => { :status => Task::Status::CANCELLED } | ||
| 273 | + named_scope :closed, :conditions => { :status => [Task::Status::CANCELLED, Task::Status::FINISHED] } | ||
| 271 | named_scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } | 274 | named_scope :opened, :conditions => { :status => [Task::Status::ACTIVE, Task::Status::HIDDEN] } |
| 272 | named_scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } | 275 | named_scope :of, lambda { |type| conditions = type ? "type LIKE '#{type}'" : "1=1"; {:conditions => [conditions]} } |
| 273 | named_scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } | 276 | named_scope :order_by, lambda { |attribute, ord| {:order => "#{attribute} #{ord}"} } |
test/unit/task_test.rb
| @@ -335,6 +335,43 @@ class TaskTest < ActiveSupport::TestCase | @@ -335,6 +335,43 @@ class TaskTest < ActiveSupport::TestCase | ||
| 335 | assert_equal [t4,t3,t2,t1], Task.order_by('status', 'asc') | 335 | assert_equal [t4,t3,t2,t1], Task.order_by('status', 'asc') |
| 336 | end | 336 | end |
| 337 | 337 | ||
| 338 | + should 'retrieve tasks by status' do | ||
| 339 | + pending = fast_create(Task, :status => Task::Status::ACTIVE) | ||
| 340 | + hidden = fast_create(Task, :status => Task::Status::HIDDEN) | ||
| 341 | + finished = fast_create(Task, :status => Task::Status::FINISHED) | ||
| 342 | + canceled = fast_create(Task, :status => Task::Status::CANCELLED) | ||
| 343 | + | ||
| 344 | + assert_includes Task.pending, pending | ||
| 345 | + assert_not_includes Task.pending, hidden | ||
| 346 | + assert_not_includes Task.pending, finished | ||
| 347 | + assert_not_includes Task.pending, canceled | ||
| 348 | + | ||
| 349 | + assert_not_includes Task.hidden, pending | ||
| 350 | + assert_includes Task.hidden, hidden | ||
| 351 | + assert_not_includes Task.hidden, finished | ||
| 352 | + assert_not_includes Task.hidden, canceled | ||
| 353 | + | ||
| 354 | + assert_not_includes Task.finished, pending | ||
| 355 | + assert_not_includes Task.finished, hidden | ||
| 356 | + assert_includes Task.finished, finished | ||
| 357 | + assert_not_includes Task.finished, canceled | ||
| 358 | + | ||
| 359 | + assert_not_includes Task.canceled, pending | ||
| 360 | + assert_not_includes Task.canceled, hidden | ||
| 361 | + assert_not_includes Task.canceled, finished | ||
| 362 | + assert_includes Task.canceled, canceled | ||
| 363 | + | ||
| 364 | + assert_includes Task.opened, pending | ||
| 365 | + assert_includes Task.opened, hidden | ||
| 366 | + assert_not_includes Task.opened, finished | ||
| 367 | + assert_not_includes Task.opened, canceled | ||
| 368 | + | ||
| 369 | + assert_not_includes Task.closed, pending | ||
| 370 | + assert_not_includes Task.closed, hidden | ||
| 371 | + assert_includes Task.closed, finished | ||
| 372 | + assert_includes Task.closed, canceled | ||
| 373 | + end | ||
| 374 | + | ||
| 338 | protected | 375 | protected |
| 339 | 376 | ||
| 340 | def sample_user | 377 | def sample_user |