Sha256: 28dfbff58215fb3070b98ce8f94d3ecc93b75c6e7b3e09ac352d1bf27d8c6f37

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

require 'unit_spec_helper'

describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher, type: :model do
  context 'a read-only attribute' do
    it 'accepts' do
      expect(with_readonly_attr).to have_readonly_attribute(:attr)
    end
  end

  context 'an attribute that is not part of the read-only set' do
    it 'rejects being read-only' do
      model = define_model :example, attr: :string, other: :string do
        attr_readonly :attr
      end.new

      expect(model).not_to have_readonly_attribute(:other)
    end
  end

  context 'an attribute on a class with no readonly attributes' do
    it 'rejects being read-only' do
      expect(define_model(:example, attr: :string).new).
        not_to have_readonly_attribute(:attr)
    end

    it 'assigns a failure message' do
      model = define_model(:example, attr: :string).new
      matcher = have_readonly_attribute(:attr)

      matcher.matches?(model)

      expect(matcher.failure_message).not_to be_nil
    end
  end

  def with_readonly_attr
    define_model :example, attr: :string do
      attr_readonly :attr
    end.new
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
shoulda-matchers-3.1.3 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-4.0.0.rc1 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-3.1.2 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/shoulda-matchers-2.8.0/spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-3.1.1 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-3.1.0 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-3.0.1 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-3.0.0 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-3.0.0.rc1 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-2.8.0 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-2.8.0.rc2 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-2.8.0.rc1 spec/unit/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb