Sha256: 0195161c3d327015eae8dd16affa51a957dfc59f7e4bb3fb357d7d1ac86f22fd
Contents?: true
Size: 1.04 KB
Versions: 3
Compression:
Stored size: 1.04 KB
Contents
require 'spec_helper' describe 'validations' do class TestModel include Modis::Model attribute :name, :string validates :name, presence: true end let(:model) { TestModel.new } it 'responds to valid?' do model.name = nil model.valid?.should be_false end it 'sets errors on the model' do model.name = nil model.valid? model.errors[:name].should eq ["can't be blank"] end describe 'save' do it 'returns true if the model is valid' do model.name = "Ian" model.save.should be_true end it 'returns false if the model is invalid' do model.name = nil model.save.should be_false end end describe 'save!' do it 'raises an error if the model is invalid' do model.name = nil expect do model.save!.should be_false end.to raise_error(Modis::RecordInvalid) end end describe 'create!' do it 'raises an error if the record is not valid' do expect { TestModel.create!(name: nil) }.to raise_error(Modis::RecordInvalid) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
modis-1.1.0 | spec/validations_spec.rb |
modis-1.0.0 | spec/validations_spec.rb |
modis-0.0.1 | spec/validations_spec.rb |