Sha256: 037942c2412d03e04d1d73c6ca88085bd98a45c1387af124129f5bc45d9d6820

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper.rb'

describe AttrOptional, '.attr_optional' do
  before do
    @a, @b = A.new, B.new
  end

  it 'should define accessible attributes' do
    @a.should respond_to(:attr_optional_a)
    @a.should respond_to(:attr_optional_a=)
    @b.should respond_to(:attr_optional_b)
    @b.should respond_to(:attr_optional_b=)
  end

  it 'should be inherited' do
    @b.should respond_to(:attr_optional_a)
    @b.should respond_to(:attr_optional_a=)
  end
end

describe AttrOptional, '.attr_optional?' do
  it 'should answer whether the attributes is optional or not' do
    A.attr_optional?(:attr_optional_a).should be_true
    B.attr_optional?(:attr_optional_a).should be_true
    B.attr_optional?(:attr_optional_b).should be_true
    B.attr_optional?(:to_s).should be_false
  end
end

describe AttrOptional, '#attr_optional?' do
  before do
    @a, @b = A.new, B.new
  end

  it 'should answer whether the attributes is optional or not' do
    @a.attr_optional?(:attr_optional_a).should be_true
    @b.attr_optional?(:attr_optional_a).should be_true
    @b.attr_optional?(:attr_optional_b).should be_true
    @b.attr_optional?(:to_s).should be_false
  end
end

describe AttrOptional, '.optional_attributes' do
  it 'should return all optional attributes keys' do
    A.optional_attributes.should == [:attr_optional_a]
    B.optional_attributes.should == [:attr_optional_a, :attr_optional_b]
  end
end

describe AttrOptional, '#optional_attributes' do
  before do
    @a, @b = A.new, B.new
  end

  it 'should return optional attributes keys' do
    @a.optional_attributes.should == [:attr_optional_a]
    @b.optional_attributes.should == [:attr_optional_a, :attr_optional_b]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attr_required-0.0.3 spec/attr_optional_spec.rb
attr_required-0.0.2 spec/attr_optional_spec.rb