aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/concern_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/test/concern_test.rb')
-rw-r--r--activesupport/test/concern_test.rb88
1 files changed, 88 insertions, 0 deletions
diff --git a/activesupport/test/concern_test.rb b/activesupport/test/concern_test.rb
new file mode 100644
index 0000000000..22f7ec2064
--- /dev/null
+++ b/activesupport/test/concern_test.rb
@@ -0,0 +1,88 @@
+require 'abstract_unit'
+require 'active_support/concern'
+
+class ConcernTest < Test::Unit::TestCase
+ module Baz
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ def baz
+ "baz"
+ end
+
+ def included_ran=(value)
+ @@included_ran = value
+ end
+
+ def included_ran
+ @@included_ran
+ end
+ end
+
+ included do
+ self.included_ran = true
+ end
+
+ def baz
+ "baz"
+ end
+ end
+
+ module Bar
+ extend ActiveSupport::Concern
+
+ depends_on Baz
+
+ def bar
+ "bar"
+ end
+
+ def baz
+ "bar+" + super
+ end
+ end
+
+ module Foo
+ extend ActiveSupport::Concern
+
+ depends_on Bar, Baz
+ end
+
+ def setup
+ @klass = Class.new
+ end
+
+ def test_module_is_included_normally
+ @klass.send(:include, Baz)
+ assert_equal "baz", @klass.new.baz
+ assert_equal ConcernTest::Baz, @klass.included_modules[0]
+
+ @klass.send(:include, Baz)
+ assert_equal "baz", @klass.new.baz
+ assert_equal ConcernTest::Baz, @klass.included_modules[0]
+ end
+
+ def test_class_methods_are_extended
+ @klass.send(:include, Baz)
+ assert_equal "baz", @klass.baz
+ assert_equal ConcernTest::Baz::ClassMethods, (class << @klass; self.included_modules; end)[0]
+ end
+
+ def test_included_block_is_ran
+ @klass.send(:include, Baz)
+ assert_equal true, @klass.included_ran
+ end
+
+ def test_modules_dependencies_are_met
+ @klass.send(:include, Bar)
+ assert_equal "bar", @klass.new.bar
+ assert_equal "bar+baz", @klass.new.baz
+ assert_equal "baz", @klass.baz
+ assert_equal [ConcernTest::Bar, ConcernTest::Baz], @klass.included_modules[0..1]
+ end
+
+ def test_depends_on_with_multiple_modules
+ @klass.send(:include, Foo)
+ assert_equal [ConcernTest::Foo, ConcernTest::Bar, ConcernTest::Baz], @klass.included_modules[0..2]
+ end
+end