Sha256: 0fbf6270f96d343d9c0bde404260250a5b2a357edfcce188d0ed2aa6b66446d6

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 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 = stub('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

13 entries across 13 versions & 1 rubygems

Version Path
tuersteher-0.6.7 spec/model_extensions_spec.rb
tuersteher-0.6.6 spec/model_extensions_spec.rb
tuersteher-0.6.5 spec/model_extensions_spec.rb
tuersteher-0.6.4 spec/model_extensions_spec.rb
tuersteher-0.6.3 spec/model_extensions_spec.rb
tuersteher-0.6.2 spec/model_extensions_spec.rb
tuersteher-0.6.1 spec/model_extensions_spec.rb
tuersteher-0.6.0 spec/model_extensions_spec.rb
tuersteher-0.5.2 spec/model_extensions_spec.rb
tuersteher-0.5.1 spec/model_extensions_spec.rb
tuersteher-0.5.0 spec/model_extensions_spec.rb
tuersteher-0.4.1 spec/model_extensions_spec.rb
tuersteher-0.4.0 spec/model_extensions_spec.rb