Sha256: 8f0d656e1b598eddcca280dd92221f955b1cca1f405039cbb333cc6ed6431949

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

require File.dirname(__FILE__) + '/test_helper'

class ActiveRecordTest < Test::Unit::TestCase
  def setup
    @klass = Class.new(ActiveRecord::Base) do
      def initialize(value)
        self.foo = value
      end
    end
  end
  
  def test_should_evaluate_string_values
    @klass.attr_accessor(:foo)
    
    [nil, '', 'Name'].each do |value|
      assert_equal false, @klass.new(value).foo?, "#{value.inspect} is true"
    end
  end
  
  def test_should_evaluate_numeric_values
    @klass.attr_accessor(:foo)
    
    [nil, 0, '0'].each do |value|
      assert_equal false, @klass.new(value).foo?, "#{value.inspect} is true"
    end
    
    assert_equal true, @klass.new(1).foo?, '1 is false'
    assert_equal true, @klass.new('1').foo?, '"1" is false'
  end
  
  def test_should_evaluate_boolean_values
    @klass.attr_accessor(:foo)
    
    [nil, '', false, 'false', 'f', 0].each do |value|
      assert_equal false, @klass.new(value).foo?, "#{value.inspect} is true"
    end
    
    [true, 'true', '1', 1].each do |value|
      assert_equal true, @klass.new(value).foo?, "#{value.inspect} is false"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
attribute_predicates-0.2.1 test/active_record_test.rb
attribute_predicates-0.1.0 test/active_record_test.rb
attribute_predicates-0.1.1 test/active_record_test.rb
attribute_predicates-0.1.2 test/active_record_test.rb
attribute_predicates-0.2.0 test/active_record_test.rb