Skip to content
Snippets Groups Projects
Commit fb72271e authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

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

parent c29da3f8
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -6,7 +6,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
 
def destroy
todo.done!
todo.done
 
todo_notice = 'Todo was successfully marked as done.'
 
Loading
Loading
@@ -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.' }
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment