class Inflector def self.pluralize a a + 's' end end require 'test/unit' require File.dirname(__FILE__) + '/../lib/checkbox_set_helper' class CheckboxSetHelperTest < Test::Unit::TestCase def test_basic f = Foo.new f.test_item_1 = "1" f.test_item_3 = "1" assert_equal [1, 3], f.test_items end def test_turn_off f = Foo.new f.test_item_1 = "1" f.test_item_1 = "0" assert_equal [], f.test_items end def test_multiple f = Foo.new b = Bar.new f.test_item_1 = "1" f.test_item_3 = "1" b.test2_item_1 = "1" b.test2_item_2 = "1" b.test3_item_2 = "1" assert_equal [1, 3], f.test_items assert_equal [1, 2], b.test2_items assert_equal [2], b.test3_items end def test_method_missing f = Foo.new f.method_missing_called = false begin f.bogus fail "A NoMethodError should have been raised" rescue NoMethodError => e assert f.method_missing_called end end end class Foo include CheckboxSetHelper checkbox_set 'test_item' attr_accessor :method_missing_called def method_missing methodname, *args self.method_missing_called = true super # Required, CheckboxSetHelper needs to intercept end end class Bar include CheckboxSetHelper checkbox_set 'test2_item' checkbox_set 'test3_item' end