Skip to content

Commit

Permalink
add tests to make sure we call super in the inheriting methods proper…
Browse files Browse the repository at this point in the history
…ly. fixes #139
  • Loading branch information
apotonick committed May 27, 2015
1 parent d7554bf commit 082de14
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/representable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,56 @@ module SongJsonRepresenter
assert_xml_equal "<song name=\"Days Go By\"/>", @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


Expand Down

0 comments on commit 082de14

Please sign in to comment.