diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb index 9ee9039f00434be9941f5b91c73895c8c6a27a8b..43cf8fa71af4d468ebf0a30d8df7e13c879cf508 100644 --- a/app/controllers/dashboard/todos_controller.rb +++ b/app/controllers/dashboard/todos_controller.rb @@ -15,7 +15,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.' } diff --git a/app/models/todo.rb b/app/models/todo.rb index 34d71c1b0d32c7cb04afcc664e533d4084f3f057..5f91991f781811c79e8e85fbd40cca4582970f8e 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -36,7 +36,7 @@ class Todo < ActiveRecord::Base state_machine :state, initial: :pending do event :done do - transition pending: :done + transition [:pending, :done] => :done end state :pending diff --git a/spec/models/todo_spec.rb.rb b/spec/models/todo_spec.rb similarity index 66% rename from spec/models/todo_spec.rb.rb rename to spec/models/todo_spec.rb index ac481bf9fbd2bfab2649b99d20c68bc6fcd645b0..fe9ea7e7d1ec4b2d9ae4366a2eb0acab8291329f 100644 --- a/spec/models/todo_spec.rb.rb +++ b/spec/models/todo_spec.rb @@ -37,20 +37,6 @@ describe Todo, models: true do it { is_expected.to validate_presence_of(:user) } end - describe '#action_name' do - it 'returns proper message when action is an assigment' do - subject.action = Todo::ASSIGNED - - expect(subject.action_name).to eq 'assigned' - end - - it 'returns proper message when action is a mention' do - subject.action = Todo::MENTIONED - - expect(subject.action_name).to eq 'mentioned you on' - end - end - describe '#body' do before do subject.target = build(:issue, title: 'Bugfix') @@ -69,21 +55,15 @@ describe Todo, models: true do end end - describe '#target_iid' do - let(:issue) { build(:issue, id: 1, iid: 5) } - - before do - subject.target = issue - end - - it 'returns target.iid when target respond to iid' do - expect(subject.target_iid).to eq 5 + 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') end - it 'returns target_id when target does not respond to iid' do - allow(issue).to receive(:respond_to?).with(:iid).and_return(false) - - expect(subject.target_iid).to eq 1 + it 'does not raise error when is already done' do + todo = create(:todo, state: :done) + expect { todo.done! }.not_to raise_error end end end