Sha256: 87e8bb317eabe2adf7c6916e4df2dda3875e1339961a9cfcf444d1022c705be3

Contents?: true

Size: 1.3 KB

Versions: 8

Compression:

Stored size: 1.3 KB

Contents

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

8 entries across 8 versions & 1 rubygems

Version Path
act_with_flags-3.1.9 test/inheritance_test.rb
act_with_flags-3.1.6 test/inheritance_test.rb
act_with_flags-3.1.5 test/inheritance_test.rb
act_with_flags-3.1.3 test/inheritance_test.rb
act_with_flags-3.1.2 test/inheritance_test.rb
act_with_flags-3.1.1 test/inheritance_test.rb
act_with_flags-3.1.0 test/inheritance_test.rb
act_with_flags-3.0.1 test/inheritance_test.rb