Sha256: 8856c590492addfcdeece1488a6109843a42661ab2b549eb1b40e1c098f3650e

Contents?: true

Size: 1.5 KB

Versions: 18

Compression:

Stored size: 1.5 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe 'have_readonly_attributes' do
  include ModelBuilder

  def define_and_validate(options={})
    @model = define_model :product, :title => :string, :category => :string do
      attr_readonly :title, :category   if options[:readonly] == true
      attr_readonly *options[:readonly] if options[:readonly].is_a?(Array)
    end

    have_readonly_attributes(:title, :category)
  end

  describe 'messages' do

    it 'should contain a description' do
      @matcher = have_readonly_attributes(:title, :category)
      @matcher.description.should == 'make title and category read-only'
    end

    it 'should set is_readonly? message' do
      @matcher = define_and_validate(:readonly => [:another])
      @matcher.matches?(@model)
      @matcher.failure_message.should == 'Expected Product to make title read-only, got ["another"]'
    end

  end

  describe 'matchers' do
    it { should define_and_validate(:readonly => true) }
    it { should_not define_and_validate(:readonly => false) }
    it { should_not define_and_validate(:accessible => [:another]) }
  end

  describe 'macros' do
    before(:each){ define_and_validate(:readonly => true) }

    should_have_readonly_attributes :title
    should_have_readonly_attributes :category
    should_have_readonly_attributes :title, :category

    should_not_have_readonly_attributes :another
    should_not_have_readonly_attributes :title, :another
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
remarkable_activerecord-3.1.7 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.1.8 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.10 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.3 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.4 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.6 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.5 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.2 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.1.3 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.7 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.8 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.1.0 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.1.1 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.1.2 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.1.4 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.0.9 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.1.6 spec/have_readonly_attributes_matcher_spec.rb
remarkable_activerecord-3.1.5 spec/have_readonly_attributes_matcher_spec.rb