Sha256: a9b63028dcb86ecac7f86fc929e5a1613cc5e3d82c197fcc9557f54961560211

Contents?: true

Size: 1011 Bytes

Versions: 6

Compression:

Stored size: 1011 Bytes

Contents

require 'spec_helper'

describe Snippet do

  let(:snippet) { FactoryBot.build(:snippet) }

  describe 'name' do
    it 'is invalid when blank' do
      snippet = FactoryBot.build(:snippet, name: '')
      snippet.valid?
      expect(snippet.errors[:name]).to include("This field is required.")
    end

    it 'should validate uniqueness of' do
      snippet = FactoryBot.build(:snippet, name: 'test_snippet', content: "Content!")
      snippet.save!
      other = FactoryBot.build(:snippet, name: 'test_snippet', content: "Content!")
      expect { other.save! }.to raise_error(ActiveRecord::RecordInvalid)
    end

    it 'should validate length of' do
      snippet = FactoryBot.build(:snippet, name: 'x' * 100)
      expect(snippet.errors[:name]).to be_blank
      snippet = FactoryBot.build(:snippet, name: 'x' * 101)
      expect { snippet.save! }.to raise_error(ActiveRecord::RecordInvalid)
      expect(snippet.errors[:name]).to include("This must not be longer than 100 characters")
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
trusty-cms-7.0.8 spec/models/snippets_spec.rb
trusty-cms-7.0.7 spec/models/snippets_spec.rb
trusty-cms-7.0.6 spec/models/snippets_spec.rb
trusty-cms-7.0.5 spec/models/snippets_spec.rb
trusty-cms-7.0.4 spec/models/snippets_spec.rb
trusty-cms-7.0.3 spec/models/snippets_spec.rb