Sha256: 9b89de922704b51bcd2210b777f27bd3c82153195f56826fb57d28fb0cb4ee0b

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

require "spec_helper"

module Tuersteher

  describe ModelExtensions do

    class SampleModel
      include ModelExtensions

      def deactived
        check_access :deactived
      end
    end


    before do
      rules = [ModelAccessRule.new(SampleModel).grant.method(:deactived).role(:admin)]
      AccessRulesStorage.instance.stub(:model_rules).and_return(rules)
      @user = double('user')
      Thread.current[:user] = @user
    end


    context "check_access" do

      it "should not raise a Error for user with role :admin" do
        @user.stub(:has_role?){|role| role==:admin}
        model = SampleModel.new
        model.deactived
      end

      it "should raise a SecurityError for user with not role :admin" do
        @user.stub(:has_role?){|role| role==:user}
        model = SampleModel.new
        expect{ model.deactived }.to raise_error(SecurityError)
      end

    end # of context "grant with roles"


    context "purge_collection" do

      it "should purge nothing for user with role :admin" do
        @user.stub(:has_role?){|role| role==:admin}
        list = [SampleModel.new]
        SampleModel.purge_collection(list, :deactived).should == list
      end

      it "should purge all for user with not role :admin" do
        @user.stub(:has_role?){|role| role==:user}
        list = [SampleModel.new]
        SampleModel.purge_collection(list, :deactived).should == []
      end

    end # of  context "purge_collection"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tuersteher-1.0.1 spec/model_extensions_spec.rb
tuersteher-0.7.2 spec/model_extensions_spec.rb
tuersteher-0.7.1 spec/model_extensions_spec.rb
tuersteher-0.7.0 spec/model_extensions_spec.rb