Sha256: b263c3f0ecf9a3380fda61dd88631e46c56990c6e1dc4971cf2b436901198528

Contents?: true

Size: 1.08 KB

Versions: 17

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'

describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher do
  context 'a read-only attribute' do
    it 'accepts' do
      with_readonly_attr.should 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

      model.should_not have_readonly_attribute(:other)
    end
  end

  context 'an attribute on a class with no readonly attributes' do
    it 'rejects being read-only' do
      define_model(:example, :attr => :string).new.
        should_not 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)

      matcher.failure_message_for_should.should_not be_nil
    end
  end

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

Version data entries

17 entries across 16 versions & 2 rubygems

Version Path
shoulda-matchers-2.4.0 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-2.4.0.rc1 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-2.3.0 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
challah-1.0.0 vendor/bundle/gems/shoulda-matchers-2.2.0/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-2.2.0 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-2.1.0/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-2.1.0 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-2.0.0 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-1.5.6 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-1.5.5 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-1.5.4 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-1.5.2 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-1.5.1 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb
shoulda-matchers-1.5.0 spec/shoulda/matchers/active_record/have_readonly_attributes_matcher_spec.rb