Sha256: 27d10b818e114c92abfc780fe219b36e26efc943f1c3073af52a7be48599272c

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 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){ rules }
      expect(AccessRulesStorage.instance).to receive(:model_rules){ rules }
      @login_context = double('login_context')
      Thread.current[:login_context] = @login_context
    end


    context "check_access" do

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

      it "should raise a SecurityError for login_context with not role :admin" do
        expect(@login_context).to receive(: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 login_context with role :admin" do
        expect(@login_context).to receive(:has_role?){|role| role==:admin}
        list = [SampleModel.new]
        expect(SampleModel.purge_collection(list, :deactived)).to eq list
      end

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

    end # of  context "purge_collection"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tuersteher-1.0.4 spec/model_extensions_spec.rb
tuersteher-1.0.3 spec/model_extensions_spec.rb
tuersteher-1.0.2 spec/model_extensions_spec.rb