Created
January 2, 2013 09:43
-
-
Save tatey/4433315 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Countable | |
def self.included do | |
define_method "#{self.name}s" do | |
# ... | |
end | |
end | |
def self.name | |
self.class.to_s.sub('FeedItem', '').downcase | |
end | |
end | |
class DonationFeedItem | |
include Countable | |
end | |
item = DonationFeedItem.new | |
item.donations | |
class CountableTest < MiniTest::Unit::TestCase | |
class TestFeedItem | |
include Countable | |
end | |
def test_plural_method | |
item = TestFeedItem.new | |
assert item.tests | |
end | |
end | |
class DonationFeedItemTest < MiniTest::UnitTestCase | |
def test_countable | |
assert_includes DonationFeedItem.constants, Countable | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment