From 082de142e410275469daa3b39ae2aa30dd52aae5 Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Thu, 28 May 2015 08:36:44 +1000 Subject: [PATCH] add tests to make sure we call super in the inheriting methods properly. fixes #139 --- test/representable_test.rb | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/representable_test.rb b/test/representable_test.rb index 39fb0b58..64358220 100644 --- a/test/representable_test.rb +++ b/test/representable_test.rb @@ -109,6 +109,56 @@ module SongJsonRepresenter assert_xml_equal "", @song.extend(SongXmlRepresenter).to_xml assert_json "{\"name\":\"Days Go By\"}", @song.extend(SongJsonRepresenter).to_json end + + + # test if we call super in + # ::inherited + # ::included + # ::extended + module Representer + include Representable # overrides ::inherited. + end + + class BaseClass + def self.inherited(subclass) + super + subclass.instance_eval { def other; end } + end + + include Representable # overrides ::inherited. + include Representer + end + + class SubClass < BaseClass # triggers Representable::inherited, then OtherModule::inherited. + end + + # test ::inherited. + it do + BaseClass.respond_to?(:other).must_equal false + SubClass.respond_to?(:other).must_equal true + end + + module DifferentIncluded + def included(includer) + includer.instance_eval { def different; end } + end + end + + module CombinedIncluded + extend DifferentIncluded # defines ::included. + include Representable # overrides ::included. + end + + class IncludingClass + include Representable + include CombinedIncluded + end + + # test ::included. + it do + IncludingClass.respond_to?(:representable_attrs) # from Representable + IncludingClass.respond_to?(:different) + end end