Use todo.done without ! in the controller to mark todo as done
This commit is contained in:
parent
c29da3f8ca
commit
fb72271e24
|
@ -6,7 +6,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
todo.done!
|
||||
todo.done
|
||||
|
||||
todo_notice = 'Todo was successfully marked as done.'
|
||||
|
||||
|
@ -20,7 +20,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
|
|||
end
|
||||
|
||||
def destroy_all
|
||||
@todos.each(&:done!)
|
||||
@todos.each(&:done)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
|
||||
|
|
|
@ -38,7 +38,7 @@ class Todo < ActiveRecord::Base
|
|||
|
||||
state_machine :state, initial: :pending do
|
||||
event :done do
|
||||
transition [:pending, :done] => :done
|
||||
transition [:pending] => :done
|
||||
end
|
||||
|
||||
state :pending
|
||||
|
|
|
@ -73,15 +73,15 @@ describe Todo, models: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#done!' do
|
||||
describe '#done' do
|
||||
it 'changes state to done' do
|
||||
todo = create(:todo, state: :pending)
|
||||
expect { todo.done! }.to change(todo, :state).from('pending').to('done')
|
||||
expect { todo.done }.to change(todo, :state).from('pending').to('done')
|
||||
end
|
||||
|
||||
it 'does not raise error when is already done' do
|
||||
todo = create(:todo, state: :done)
|
||||
expect { todo.done! }.not_to raise_error
|
||||
expect { todo.done }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue