Sha256: 95c98429c1e4d9f2163bc1f3c4386c8c0db73a21a879179e4ec5d539743daf89
Contents?: true
Size: 1.06 KB
Versions: 6
Compression:
Stored size: 1.06 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 expect(model.valid?).to be false end it 'sets errors on the model' do model.name = nil model.valid? expect(model.errors[:name]).to eq(["can't be blank"]) end describe 'save' do it 'returns true if the model is valid' do model.name = "Ian" expect(model.save).to be true end it 'returns false if the model is invalid' do model.name = nil expect(model.save).to be false end end describe 'save!' do it 'raises an error if the model is invalid' do model.name = nil expect do expect(model.save!).to 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
6 entries across 6 versions & 1 rubygems