Sha256: f9f216024f2837935af9dde446b62890fce013523fa44751e9ea4b8a42b6b582

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

require "spec_helper"
require "shamu/active_record"

module ActiveRecordPolicySpec
  class Policy < Shamu::Security::ActiveRecordPolicy
    def permissions
    end
  end
end

describe Shamu::Security::ActiveRecordPolicy do
  use_active_record

  let( :policy ) { ActiveRecordPolicySpec::Policy.new }

  describe "#refine_relation" do
    before( :each ) do
      ActiveRecordSpec::Favorite.create! name: "Example"
    end

    it "returns empty relation if there are no refinements" do
      relation = policy.refine_relation( :read, ActiveRecordSpec::Favorite.all )
      expect( relation ).to be_empty
    end

    it "applies matching refinements" do
      refinement = double( Shamu::Security::PolicyRefinement )
      allow( policy ).to receive( :refinements ).and_return [ refinement ]

      expect( refinement ).to receive( :match? ).and_return true
      expect( refinement ).to receive( :apply ).and_return ActiveRecordSpec::Favorite.all

      relation = policy.refine_relation( :read, ActiveRecordSpec::Favorite.all )
      expect( relation ).not_to be_empty
    end
  end

  describe "#refine" do
    it "adds a new refinement" do
      expect do
        policy.send( :refine, :read, ActiveRecordSpec::Favorite )
      end.to change { policy.send( :refinements ).length }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/security/active_record_policy_spec.rb
shamu-0.0.21 spec/lib/shamu/security/active_record_policy_spec.rb
shamu-0.0.20 spec/lib/shamu/security/active_record_policy_spec.rb
shamu-0.0.19 spec/lib/shamu/security/active_record_policy_spec.rb