Sha256: b26aa6083402b3f925bdf7d878b25fee90f621955d6062303f0be96db6633baf

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

# rubocop: disable all

require 'test_helper'

class A < Order
end

class B < Order
  add_to_flags y: 2
end

class C < Order
  before_create { |row|  row.flags2 = 0 }

  attr_accessor :flags2
  add_to_flags z: 3, origin: :flags2
end

describe 'inheritance' do
  let(:admina) { A.act_with_flags }
  let(:adminb) { B.act_with_flags }

  let(:a) { A.create }
  let(:b) { B.create }
  let(:c) { C.create }

  def setup
    reset_order
    Order.add_to_flags x: 1
  end

  it 'inheritance #1' do
    assert a.respond_to?(:flags)
    assert a.respond_to?(:x)
    assert_equal 0, a.flags
    assert_equal false, a.x
  end

  it 'inheritance #2' do
    a.x = false
    assert_equal false, a.x
    a.x = true
    assert_equal true, a.x
    assert_equal 0x02, a.flags
  end

  it 'inheritance #3' do
    assert b.respond_to?(:flags)
    assert b.respond_to?(:x)
    assert b.respond_to?(:y)
    assert_equal 0, b.flags
    assert_equal false, b.x
    assert_equal false, b.y
    b.x = true
    assert_equal true, b.x
    b.y = true
    assert_equal true, b.y
    assert_equal 0x06, b.flags
  end

  it 'inheritance #4' do
    assert c.respond_to?(:x)
    assert c.respond_to?(:z)
    assert_equal false, c.z
    c.x = true
    assert_equal true, c.x
    c.z = true
    assert_equal true, c.z
    assert_equal 0x02, c.flags
    assert_equal 0x08, c.flags2
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
act_with_flags-0.2.4 test/inheritance_test.rb
act_with_flags-0.2.3 test/inheritance_test.rb
act_with_flags-0.2.0 test/inheritance_test.rb