Sha256: 5414faa5f6317b863da53e34f6dc912d8142af64a64525fe8096f2fc2d1d07ca

Contents?: true

Size: 934 Bytes

Versions: 6

Compression:

Stored size: 934 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

6 entries across 6 versions & 1 rubygems

Version Path
act_with_bag-1.1.5 test/bag_boolean_test.rb
act_with_bag-1.1.4 test/bag_boolean_test.rb
act_with_bag-1.1.3 test/bag_boolean_test.rb
act_with_bag-1.1.2 test/bag_boolean_test.rb
act_with_bag-1.1.1 test/bag_boolean_test.rb
act_with_bag-1.1.0 test/bag_boolean_test.rb