Sha256: 3e010918fc48ad0c30172c8a9c75778259a7cfaed41c5aed588b93bf9214e2a2

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 KB

Contents

RSpec.describe ApplicationController, type: :controller do

  controller do
    include Hydra::AccessControlsEnforcement
    include Ddr::Auth::RoleBasedAccessControlsEnforcement
  end

  let(:user) { FactoryGirl.create(:user) }

  before do
    allow(controller.current_ability).to receive(:agents) { [ user.agent, "foo", "bar" ] }
  end

  describe "#resource_role_filters" do
    it "should include clauses for each agent for the current ability" do
      expect(subject.resource_role_filters.split(" OR "))
        .to contain_exactly("_query_:\"{!raw f=resource_role_sim}foo\"",
                            "_query_:\"{!raw f=resource_role_sim}bar\"",
                            "_query_:\"{!raw f=resource_role_sim}#{user.agent}\"")
    end
  end

  describe "#policy_role_policies" do
    let(:collections) { FactoryGirl.build_list(:collection, 3) }
    before do
      collections[0].roles.grant type: "Curator", agent: user, scope: "policy"
      collections[0].save
      collections[1].roles.grant type: "Editor", agent: "foo", scope: "policy"
      collections[1].roles.grant type: "Contributor", agent: "bar", scope: "policy"
      collections[1].save
      collections[2].roles.grant type: "Viewer", agent: "foo:bar", scope: "policy"
      collections[2].save
    end
    it "should return a list of internal URIs for collections on which the current ability has a role" do
      expect(subject.policy_role_policies).to match_array([collections[0].internal_uri, collections[1].internal_uri])
    end
  end

  describe "#policy_role_filters" do
    before do
      allow(subject).to receive(:policy_role_policies) { ["info:fedora/test:13", "info:fedora/test:45"] }
    end
    it "should include clauses for is_governed_by relationships to the #policy_role_policies" do
      expect(subject.policy_role_filters).to eq("_query_:\"{!raw f=#{Ddr::IndexFields::IS_GOVERNED_BY}}info:fedora/test:13\" OR _query_:\"{!raw f=#{Ddr::IndexFields::IS_GOVERNED_BY}}info:fedora/test:45\"")
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ddr-models-2.0.0.rc5 spec/controllers/including_role_based_access_controls_enforcement_spec.rb
ddr-models-2.0.0.rc4 spec/controllers/including_role_based_access_controls_enforcement_spec.rb