Sha256: a4be723c6438c326ce27455bac119d4dd910c21ce88d0dbe2291189c4dfb0492

Contents?: true

Size: 938 Bytes

Versions: 10

Compression:

Stored size: 938 Bytes

Contents

require 'test_helper'


class Order < ActiveRecord::Base
  add_to_bag bool: :boolean
end


class BagBooleanTest < ActiveSupport::TestCase

  def setup
    @order = Order.new
  end

  test "uninitialized boolean should return false" do
    assert_equal false, @order.bool
    assert_equal false, @order.bag.has_key?(:bool)
  end

  test "optimized storage of boolean" do
    @order.bool = false
    assert_equal false, @order.bag.has_key?(:bool)
    @order.bool = 0
    assert_equal false, @order.bag.has_key?(:bool)
    @order.bool = '0'
    assert_equal false, @order.bag.has_key?(:bool)
  end

  test "a true value requires storage in the bag" do
    @order.bool = true
    assert_equal true, @order.bag.has_key?(:bool)
    assert_equal true, @order.bool
  end

  test "reassigning a false value should drop storage in bag" do
    @order.bool = true
    @order.bool = false
    assert_equal false, @order.bag.has_key?(:bool)
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
act_with_bag-1.0.4 test/bag_boolean_test.rb
act_with_bag-1.0.3 test/bag_boolean_test.rb
act_with_bag-1.0.2 test/bag_boolean_test.rb
act_with_bag-1.0.0 test/bag_boolean_test.rb
act_with_bag-0.5.7 test/bag_boolean_test.rb
act_with_bag-0.5.6 test/bag_boolean_test.rb
act_with_bag-0.5.5 test/bag_boolean_test.rb
act_with_bag-0.5.3 test/bag_boolean_test.rb
act_with_bag-0.5.2 test/bag_boolean_test.rb
act_with_bag-0.5.1 test/bag_boolean_test.rb