mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-04 20:10:16 +01:00
Eliminated unnecessary double UPDATE on each todo when activating deferred Todos.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@659 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
b16ff933cb
commit
584fdf2d34
3 changed files with 3 additions and 8 deletions
|
|
@ -60,11 +60,6 @@ class Todo < ActiveRecord::Base
|
||||||
return saved
|
return saved
|
||||||
end
|
end
|
||||||
|
|
||||||
def activate_and_save!
|
|
||||||
activate!
|
|
||||||
save!
|
|
||||||
end
|
|
||||||
|
|
||||||
def show_from
|
def show_from
|
||||||
self[:show_from]
|
self[:show_from]
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class User < ActiveRecord::Base
|
||||||
:conditions => [ 'state = ?', 'deferred' ],
|
:conditions => [ 'state = ?', 'deferred' ],
|
||||||
:order => 'show_from ASC, todos.created_at DESC' do
|
:order => 'show_from ASC, todos.created_at DESC' do
|
||||||
def find_and_activate_ready
|
def find_and_activate_ready
|
||||||
find(:all, :conditions => ['show_from <= ?', proxy_owner.time ]).collect { |t| t.activate_and_save! }
|
find(:all, :conditions => ['show_from <= ?', proxy_owner.time ]).collect { |t| t.activate! }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
has_many :completed_todos,
|
has_many :completed_todos,
|
||||||
|
|
|
||||||
|
|
@ -107,13 +107,13 @@ class TodoTest < Test::Rails::TestCase
|
||||||
assert_equal :active, t.current_state
|
assert_equal :active, t.current_state
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_activate_and_save
|
def test_activate_also_saves
|
||||||
t = @not_completed1
|
t = @not_completed1
|
||||||
t.show_from = 1.week.from_now.to_date
|
t.show_from = 1.week.from_now.to_date
|
||||||
t.save!
|
t.save!
|
||||||
assert t.deferred?
|
assert t.deferred?
|
||||||
t.reload
|
t.reload
|
||||||
t.activate_and_save!
|
t.activate!
|
||||||
assert t.active?
|
assert t.active?
|
||||||
t.reload
|
t.reload
|
||||||
assert t.active?
|
assert t.active?
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue