Skip to content
This repository
Browse code

Test clarification and method rename with deprecation

  • Loading branch information...
commit 9f2dc745d39c7277a62f685bd8f84016713f2905 1 parent 2e85484
Nathan Long authored December 08, 2012
6  CHANGELOG.markdown
Source Rendered
... ...
@@ -1,5 +1,11 @@
1 1
 # Changelog
2 2
 
  3
+## Unreleased
  4
+
  5
+- Added generic `current_user.can?(:mimic_lemurs)` for cases where there is no resource to work with. This calls a corresponding class method on `ApplicationAuthorizer`, like `ApplicationAuthorizer.can_mimic_lemurs?`.
  6
+- Renamed `authority_action` to `authority_actions` (plural) to reflect the fact that you can set multiple actions at once. Use of the old method will raise a deprecation warning.
  7
+- Lots of test cleanup so that test output is clearer - run rspec with `--format doc --order default` to see it.
  8
+
3 9
 ## v2.2.0
4 10
 
5 11
 Allow passing options hash to `authorize_action_for`, like `authorize_action_for(@llama, :sporting => @hat_style)`.
12  lib/authority/controller.rb
@@ -26,17 +26,25 @@ module ClassMethods
26 26
       # ones and any other options applicable to a before_filter
27 27
       def authorize_actions_for(model_class, options = {})
28 28
         self.authority_resource = model_class
29  
-        authority_action(options[:actions] || {})
  29
+        authority_actions(options[:actions] || {})
30 30
         before_filter :run_authorization_check, options
31 31
       end
32 32
 
33 33
       # Allows defining and overriding a controller's map of its actions to the model's authorizer methods
34 34
       #
35 35
       # @param [Hash] action_map - controller actions and methods, to be merged with existing action_map
36  
-      def authority_action(action_map)
  36
+      def authority_actions(action_map)
37 37
         authority_action_map.merge!(action_map.symbolize_keys)
38 38
       end
39 39
 
  40
+      def authority_action(action_map)
  41
+        puts "Authority's `authority_action` method has been renamed \
  42
+        to `authority_actions` (plural) to reflect the fact that you can \
  43
+        set multiple actions in one shot. Please update your controllers \
  44
+        accordingly. (called from #{caller.first})".squeeze(' ')
  45
+        authority_actions(action_map)
  46
+      end
  47
+
40 48
       # The controller action to authority action map used for determining
41 49
       # which Rails actions map to which authority actions (ex: index to read)
42 50
       #
6  spec/authority/controller_spec.rb
@@ -82,7 +82,7 @@
82 82
         it "passes the action hash to the `authority_action` method" do
83 83
           example_controller = Class.new(ExampleController)
84 84
           new_actions = {:synthesize => :create, :annihilate => 'delete'}
85  
-          example_controller.should_receive(:authority_action).with(new_actions)
  85
+          example_controller.should_receive(:authority_actions).with(new_actions)
86 86
           example_controller.authorize_actions_for(ExampleModel, :actions => new_actions)
87 87
         end
88 88
 
@@ -93,7 +93,7 @@
93 93
         it "modifies this controller's authority action map" do
94 94
           example_controller = Class.new(ExampleController)
95 95
           new_actions = {:show => :display, :synthesize => :create, :annihilate => 'delete'}
96  
-          example_controller.authority_action(new_actions)
  96
+          example_controller.authority_actions(new_actions)
97 97
           expect(example_controller.authority_action_map).to eq(
98 98
             Authority.configuration.controller_action_map.merge(new_actions)
99 99
           )
@@ -101,7 +101,7 @@
101 101
 
102 102
         it "only affects the controller it's called in" do
103 103
           child_controller = Class.new(ExampleController)
104  
-          child_controller.authority_action(:smite => 'delete')
  104
+          child_controller.authority_actions(:smite => 'delete')
105 105
           expect(ExampleController.authority_action_map[:smite]).to eq(nil)
106 106
         end
107 107
 

0 notes on commit 9f2dc74

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