Sha256: b5e7cc82cd9e80c270c91798714468ca05e907e8d1bc5779eb0627b0b7e55038

Contents?: true

Size: 1.71 KB

Versions: 82

Compression:

Stored size: 1.71 KB

Contents

module Ddr::Auth
  module Roles
    RSpec.describe DetachedRoleSet do

      subject { described_class.new(wrapped) }
      
      let(:wrapped) { Set.new }

      it_behaves_like "a role set"

      describe "deserialization" do
        let(:role1) { {type: "Editor", agent: "bob@example.com", scope: "resource"} }
        let(:role2) { {type: "Curator", agent: "sue@example.com", scope: "policy"} }

        before { subject.grant role1, role2 }
        
        it "should deserialize to an equalivalent role set" do
          expect(described_class.deserialize(subject.serialize)).to eq(subject)
        end

        it "should load JSON data" do
          expect(described_class.from_json("[{\"role_type\":[\"Editor\"],\"agent\":[\"bob@example.com\"],\"scope\":[\"resource\"]},{\"role_type\":[\"Curator\"],\"agent\":[\"sue@example.com\"],\"scope\":[\"policy\"]}]")).to eq(subject)
        end
      end

      describe "conversion to a plain Array" do
        let(:role1) { FactoryGirl.build(:role, :curator, :person, :policy) }
        let(:role2) { FactoryGirl.build(:role, :editor, :group, :resource) }
        before { subject.grant role1, role2 }
        its(:to_a) { should eq([role1, role2]) }
      end

      describe "equality" do
        let(:role1) { FactoryGirl.build(:role, :curator, :person, :policy) }
        let(:role2) { FactoryGirl.build(:role, :editor, :group, :resource) }        
        let(:other) { described_class.new(Array.new) }
        before do
          subject.grant role1, role2
          other.grant role2, role1
        end
        it "should be equal to another role set if it has the same roles, regardless of order" do
          expect(subject).to eq(other)
        end
      end

    end
    
  end
end

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
ddr-models-2.11.0 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.10.2 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.10.1 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.10.0 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.10.0.rc2 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.10.0.rc1 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.9.2 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.9.1 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.9.0 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.9.0.rc1 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.8.0 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.8.0.rc1 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.7.6 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.7.5 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.7.4 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.7.3 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.7.2 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.7.1 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.7.0 spec/auth/roles/detached_role_set_spec.rb
ddr-models-2.7.0.rc1 spec/auth/roles/detached_role_set_spec.rb