diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2013-12-17 02:31:57 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2013-12-17 02:31:57 -0700 |
commit | 1eee0ca6de975b42524105a59e0521d18b38ab81 (patch) | |
tree | b3f3e6cabf4abde34943c65caef263b914d96310 /activesupport/test | |
parent | c28d0f2031d31aeb5289b73acbb5c1adb7bd71d4 (diff) | |
download | rails-1eee0ca6de975b42524105a59e0521d18b38ab81.tar.gz rails-1eee0ca6de975b42524105a59e0521d18b38ab81.tar.bz2 rails-1eee0ca6de975b42524105a59e0521d18b38ab81.zip |
Introduce Module#concerning
A natural, low-ceremony way to separate responsibilities within a class.
Imported from https://github.com/37signals/concerning#readme
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/module/concerning_test.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/module/concerning_test.rb b/activesupport/test/core_ext/module/concerning_test.rb new file mode 100644 index 0000000000..c6863b24a4 --- /dev/null +++ b/activesupport/test/core_ext/module/concerning_test.rb @@ -0,0 +1,35 @@ +require 'abstract_unit' +require 'active_support/core_ext/module/concerning' + +class ConcerningTest < ActiveSupport::TestCase + def test_concern_shortcut_creates_a_module_but_doesnt_include_it + mod = Module.new { concern(:Foo) { } } + assert_kind_of Module, mod::Foo + assert mod::Foo.respond_to?(:included) + assert !mod.ancestors.include?(mod::Foo), mod.ancestors.inspect + end + + def test_concern_creates_a_module_extended_with_active_support_concern + klass = Class.new do + concern :Foo do + included { @foo = 1 } + def should_be_public; end + end + end + + # Declares a concern but doesn't include it + assert_kind_of Module, klass::Foo + assert !klass.ancestors.include?(klass::Foo), klass.ancestors.inspect + + # Public method visibility by default + assert klass::Foo.public_instance_methods.map(&:to_s).include?('should_be_public') + + # Calls included hook + assert_equal 1, Class.new { include klass::Foo }.instance_variable_get('@foo') + end + + def test_concerning_declares_a_concern_and_includes_it_immediately + klass = Class.new { concerning(:Foo) { } } + assert klass.ancestors.include?(klass::Foo), klass.ancestors.inspect + end +end |