Skip to content
Browse files

Merge pull request #21 from finalist/master

Apply helper_method only on ActionController::Base
  • Loading branch information...
2 parents b9cee9e + 9c6d630 commit b929d271a07bd1af2b641439b3ca5765a27427c5 @josevalim josevalim committed
Showing with 23 additions and 2 deletions.
  1. +4 −2 lib/has_scope.rb
  2. +19 −0 test/has_scope_test.rb
View
6 lib/has_scope.rb
@@ -11,7 +11,6 @@ module HasScope
def self.included(base)
base.class_eval do
extend ClassMethods
- helper_method :current_scopes
class_attribute :scopes_configuration, :instance_writer => false
end
end
@@ -184,4 +183,7 @@ def current_scopes
end
end
-ActionController::Base.send :include, HasScope
+ActionController::Base.instance_eval do
+ include HasScope
+ helper_method :current_scopes
+end
View
19 test/has_scope_test.rb
@@ -247,3 +247,22 @@ def current_scopes
end
end
+class TreeHugger
+ include HasScope
+
+ has_scope :color
+
+ def by_color
+ apply_scopes(Tree, :color => 'blue')
+ end
+
+end
+
+class HasScopeOutsideControllerTest < ActiveSupport::TestCase
+
+ def test_has_scope_usable_outside_controller
+ Tree.expects(:color).with('blue')
+ TreeHugger.new.by_color
+ end
+
+end

0 comments on commit b929d27

Please sign in to comment.
Something went wrong with that request. Please try again.