From 28097398c5087c3ffc7dc6cd63cd7f8304d3dae9 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 22 Feb 2016 16:53:07 -0300 Subject: Does not raise an error when Todo is already marked as done --- spec/models/todo_spec.rb | 69 +++++++++++++++++++++++++++++++++++ spec/models/todo_spec.rb.rb | 89 --------------------------------------------- 2 files changed, 69 insertions(+), 89 deletions(-) create mode 100644 spec/models/todo_spec.rb delete mode 100644 spec/models/todo_spec.rb.rb (limited to 'spec') diff --git a/spec/models/todo_spec.rb b/spec/models/todo_spec.rb new file mode 100644 index 00000000000..fe9ea7e7d1e --- /dev/null +++ b/spec/models/todo_spec.rb @@ -0,0 +1,69 @@ +# == Schema Information +# +# Table name: todos +# +# id :integer not null, primary key +# user_id :integer not null +# project_id :integer not null +# target_id :integer not null +# target_type :string not null +# author_id :integer +# note_id :integer +# action :integer not null +# state :string not null +# created_at :datetime +# updated_at :datetime +# + +require 'spec_helper' + +describe Todo, models: true do + describe 'relationships' do + it { is_expected.to belong_to(:author).class_name("User") } + it { is_expected.to belong_to(:note) } + it { is_expected.to belong_to(:project) } + it { is_expected.to belong_to(:target).touch(true) } + it { is_expected.to belong_to(:user) } + end + + describe 'respond to' do + it { is_expected.to respond_to(:author_name) } + it { is_expected.to respond_to(:author_email) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:action) } + it { is_expected.to validate_presence_of(:target) } + it { is_expected.to validate_presence_of(:user) } + end + + describe '#body' do + before do + subject.target = build(:issue, title: 'Bugfix') + end + + it 'returns target title when note is blank' do + subject.note = nil + + expect(subject.body).to eq 'Bugfix' + end + + it 'returns note when note is present' do + subject.note = build(:note, note: 'quick fix') + + expect(subject.body).to eq 'quick fix' + end + end + + 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 'does not raise error when is already done' do + todo = create(:todo, state: :done) + expect { todo.done! }.not_to raise_error + end + end +end diff --git a/spec/models/todo_spec.rb.rb b/spec/models/todo_spec.rb.rb deleted file mode 100644 index ac481bf9fbd..00000000000 --- a/spec/models/todo_spec.rb.rb +++ /dev/null @@ -1,89 +0,0 @@ -# == Schema Information -# -# Table name: todos -# -# id :integer not null, primary key -# user_id :integer not null -# project_id :integer not null -# target_id :integer not null -# target_type :string not null -# author_id :integer -# note_id :integer -# action :integer not null -# state :string not null -# created_at :datetime -# updated_at :datetime -# - -require 'spec_helper' - -describe Todo, models: true do - describe 'relationships' do - it { is_expected.to belong_to(:author).class_name("User") } - it { is_expected.to belong_to(:note) } - it { is_expected.to belong_to(:project) } - it { is_expected.to belong_to(:target).touch(true) } - it { is_expected.to belong_to(:user) } - end - - describe 'respond to' do - it { is_expected.to respond_to(:author_name) } - it { is_expected.to respond_to(:author_email) } - end - - describe 'validations' do - it { is_expected.to validate_presence_of(:action) } - it { is_expected.to validate_presence_of(:target) } - 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') - end - - it 'returns target title when note is blank' do - subject.note = nil - - expect(subject.body).to eq 'Bugfix' - end - - it 'returns note when note is present' do - subject.note = build(:note, note: 'quick fix') - - expect(subject.body).to eq 'quick fix' - 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 - 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 - end - end -end -- cgit v1.2.1