Sha256: 57f3edf05050b4b12e9f7fcb1aabc5cd65f2ca81911a3d4d9370d561c013181f

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require 'helper'

class Model
  include HasConstant

  attr_accessor :salutation
end

class TestHasConstant < Test::Unit::TestCase
  should 'default accessor to singular of the constant name' do
    Model.has_constant :titles, ['Mr', 'Mrs']
    assert Model.new.respond_to?(:title)
    assert Model.new.respond_to?(:title=)
  end

  should 'be able to override accessor' do
    Model.has_constant :titles, ['Mr', 'Mrs'], :accessor => :salutation
    m = Model.new
    m.salutation = 'Mr'
    assert_equal 'Mr', m.salutation
  end

  should 'be able to use an array' do
    Model.has_constant :titles, ['Mr', 'Mrs']
    assert_equal ['Mr', 'Mrs'], Model.titles
  end

  should 'be able to use a proc' do
    Model.has_constant :titles, Proc.new { ['Mr', 'Mrs'] }
    assert_equal ['Mr', 'Mrs'], Model.titles
  end

  should 'be able to use lambda' do
    Model.has_constant :titles, lambda { ['Mr', 'Mrs'] }
    assert_equal ['Mr', 'Mrs'], Model.titles
  end

  should 'provide singular_is? comparison method' do
    Model.has_constant :titles, ['Mr', 'Mrs']
    m = Model.new
    m.title = 'Mr'
    assert m.title_is?('Mr')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
has_constant-0.2.2 test/has_constant_test.rb
has_constant-0.2.1 test/has_constant_test.rb
has_constant-0.2.0 test/has_constant_test.rb