1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
require "test_helper"
class HeritageTest < Minitest::Spec
module Hello
def hello
"Hello!"
end
end
module Ciao
def ciao
"Ciao!"
end
end
class A < Representable::Decorator
include Representable::Hash
feature Hello
property :id do
end
end
class B < A
feature Ciao # does NOT extend id, of course.
property :id, inherit: true do
end
end
class C < A
property :id do end # overwrite old :id.
end
it "B must inherit Hello! feature from A" do
B.representable_attrs.get(:id)[:extend].(nil).new(nil).hello.must_equal "Hello!"
end
it "B must have Ciao from module (feauture) Ciao" do
B.representable_attrs.get(:id)[:extend].(nil).new(nil).ciao.must_equal "Ciao!"
end
it "C must inherit Hello! feature from A" do
C.representable_attrs.get(:id)[:extend].(nil).new(nil).hello.must_equal "Hello!"
end
module M
include Representable
feature Hello
end
module N
include Representable
include M
feature Ciao
end
let(:obj_extending_N) { Object.new.extend(N) }
it "obj should inherit from N, and N from M" do
obj_extending_N.hello.must_equal "Hello!"
end
end
|