Use todo.done without ! in the controller to mark todo as done

This commit is contained in:
Douglas Barbosa Alexandre 2016-03-16 20:56:23 -03:00
parent c29da3f8ca
commit fb72271e24
3 changed files with 6 additions and 6 deletions

View File

@ -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.' }

View File

@ -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

View File

@ -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