task_spec.rb revision a8b44c144d607c18209804f032dfc213cb2aba0f
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksarequire 'spec_helper'
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksadescribe Task do
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa context 'Migrations' do
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa it { should have_db_column(:name).of_type(:text) }
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa it { should have_db_column(:description).of_type(:text) }
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa it { should have_db_index(:name).unique(true) }
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa end
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa context 'Validations' do
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa context 'when no name is taken' do
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa it { should allow_value('foo').for :name }
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa end
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa context 'when name is already taken' do
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa before do
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa Task.create!(name: 'foo')
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa end
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa it { should_not allow_value('foo').for :name }
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa end
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa context 'when Task without name is to be saved' do
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa it 'raise error' do
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa expect { Task.create! }.to raise_error(ActiveRecord::RecordInvalid)
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa end
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa end
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksa end
a8b44c144d607c18209804f032dfc213cb2aba0fEugen Kuksaend