spec/authority/controller_spec.rb in authority-2.9.0 vs spec/authority/controller_spec.rb in authority-2.10.0

- old
+ new

@@ -107,20 +107,28 @@ end it "if :all_actions option is given, it overrides the action hash to use the action given" do overridden_action_map = controller_class.authority_action_map overridden_action_map.update(overridden_action_map) {|k,v| v = :annihilate} - child_controller.should_receive(:authority_actions).with(overridden_action_map) child_controller.authorize_actions_for(resource_class, :all_actions => :annihilate) + child_controller.authority_action_map.should eq(overridden_action_map) end - it "passes the action hash to the `authority_actions` method" do + it "passes the action hash to the `add_actions` method" do new_actions = {:synthesize => :create, :annihilate => 'delete'} - child_controller.should_receive(:authority_actions).with(new_actions) + child_controller.should_receive(:add_actions).with(new_actions) child_controller.authorize_actions_for(resource_class, :actions => new_actions) end + it "updates the action map if :actions option is given" do + updated_map = child_controller.authority_action_map + updated_map[:synthesize] = :create + new_actions = {:synthesize => :create} + child_controller.authorize_actions_for(resource_class, :actions => new_actions) + expect(child_controller.authority_action_map).to eq(updated_map) + end + end describe "authority_resource" do let(:child_controller) { Class.new(controller_class) } @@ -176,29 +184,10 @@ expect(controller_class.authority_action_map[:smite]).to eq(nil) end end - describe "overridden_actions" do - - it "overrides authority action map if option :all_actions is present" do - options = { :all_actions => :display, :actions => {:show => :display, :synthesize => :create} } - expect(controller_class.overridden_actions(options).values.uniq).to eq([:display]) - end - - it "returns :actions hash if option :all_actions is not present" do - options = { :actions => {:show => :display, :synthesize => :create, :annihilate => 'delete'} } - expect(controller_class.overridden_actions(options)).to eq(options[:actions]) - end - - it "returns an empty hash if no :all_actions nor :actions options present" do - options = { :show => :display, :synthesize => :create, :annihilate => 'delete' } - expect(controller_class.overridden_actions(options)).to eq({}) - end - - end - describe "ensure_authorization_performed" do let(:controller_instance) { controller_class.new } before(:each) do @@ -292,16 +281,31 @@ end end context "if the controller has such an instance method" do - before :each do - controller_instance.stub(:method_to_find_class).and_return(resource_class) + context "and the method returns a class" do + before :each do + controller_instance.stub(:method_to_find_class).and_return(resource_class) + end + + it "checks authorization on that class" do + controller_instance.should_receive(:authorize_action_for).with(resource_class) + controller_instance.send(:run_authorization_check) + end end - it "checks authorization on class returned by that method" do - controller_instance.should_receive(:authorize_action_for).with(resource_class) - controller_instance.send(:run_authorization_check) + context "and the method returns an array containing a class and some options" do + let(:some_options) { { :a => 1, :b => 2 } } + + before :each do + controller_instance.stub(:method_to_find_class).and_return([resource_class, some_options]) + end + + it "checks authorization on that class and passes the options" do + controller_instance.should_receive(:authorize_action_for).with(resource_class, some_options) + controller_instance.send(:run_authorization_check) + end end end context "if the controller has no such instance method" do