Does not raise an error when Todo is already marked as done
This commit is contained in:
parent
f5be56710f
commit
28097398c5
|
@ -15,7 +15,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.' }
|
||||||
|
|
|
@ -36,7 +36,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
|
transition [:pending, :done] => :done
|
||||||
end
|
end
|
||||||
|
|
||||||
state :pending
|
state :pending
|
||||||
|
|
|
@ -37,20 +37,6 @@ describe Todo, models: true do
|
||||||
it { is_expected.to validate_presence_of(:user) }
|
it { is_expected.to validate_presence_of(:user) }
|
||||||
end
|
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
|
describe '#body' do
|
||||||
before do
|
before do
|
||||||
subject.target = build(:issue, title: 'Bugfix')
|
subject.target = build(:issue, title: 'Bugfix')
|
||||||
|
@ -69,21 +55,15 @@ describe Todo, models: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#target_iid' do
|
describe '#done!' do
|
||||||
let(:issue) { build(:issue, id: 1, iid: 5) }
|
it 'changes state to done' do
|
||||||
|
todo = create(:todo, state: :pending)
|
||||||
before do
|
expect { todo.done! }.to change(todo, :state).from('pending').to('done')
|
||||||
subject.target = issue
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns target.iid when target respond to iid' do
|
it 'does not raise error when is already done' do
|
||||||
expect(subject.target_iid).to eq 5
|
todo = create(:todo, state: :done)
|
||||||
end
|
expect { todo.done! }.not_to raise_error
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue