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

parent c29da3f8
...@@ -6,7 +6,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -6,7 +6,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end end
def destroy def destroy
todo.done! todo.done
todo_notice = 'Todo was successfully marked as done.' todo_notice = 'Todo was successfully marked as done.'
...@@ -20,7 +20,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -20,7 +20,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end end
def destroy_all def destroy_all
@todos.each(&:done!) @todos.each(&:done)
respond_to do |format| respond_to do |format|
format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' } format.html { redirect_to dashboard_todos_path, notice: 'All todos were marked as done.' }
......
...@@ -38,7 +38,7 @@ class Todo < ActiveRecord::Base ...@@ -38,7 +38,7 @@ class Todo < ActiveRecord::Base
state_machine :state, initial: :pending do state_machine :state, initial: :pending do
event :done do event :done do
transition [:pending, :done] => :done transition [:pending] => :done
end end
state :pending state :pending
......
...@@ -73,15 +73,15 @@ describe Todo, models: true do ...@@ -73,15 +73,15 @@ describe Todo, models: true do
end end
end end
describe '#done!' do describe '#done' do
it 'changes state to done' do it 'changes state to done' do
todo = create(:todo, state: :pending) 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 end
it 'does not raise error when is already done' do it 'does not raise error when is already done' do
todo = create(:todo, state: :done) todo = create(:todo, state: :done)
expect { todo.done! }.not_to raise_error expect { todo.done }.not_to raise_error
end end
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