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

parent c29da3f8
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment