Sha256: 9579c127505e8531a43839e3809c0aaed0159074e24dad2e083d45d57f97b0c8

Contents?: true

Size: 1.53 KB

Versions: 35

Compression:

Stored size: 1.53 KB

Contents

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

      describe "JSON serialization / deserialization" do
        subject { described_class.new roles: [role1, role2] }

        let(:role1) { {role_type: "Editor", agent: "bob@example.com", scope: "resource"} }
        let(:role2) { {role_type: "Curator", agent: "sue@example.com", scope: "policy"} }
        let(:json) { "{\"roles\":[{\"agent\":\"bob@example.com\",\"role_type\":\"Editor\",\"scope\":\"resource\"},{\"agent\":\"sue@example.com\",\"role_type\":\"Curator\",\"scope\":\"policy\"}]}" }

        its(:to_json) { is_expected.to eq(json) }
        it "loads data from JSON" do
          expect(described_class.from_json(json).roles).to eq(Set.new([Role.new(role1), Role.new(role2)]))
        end
      end

      describe "conversion to array" do
        subject { described_class.new roles: roles }

        let(:roles) { FactoryGirl.build_list(:role, 3, :contributor, :person, :resource) }

        its(:to_a) { is_expected.to be_a(Array) }
        it { is_expected.to contain_exactly(*roles) }
      end

      describe "equality" do
        subject { described_class.new roles: [role1, role2] }

        let(:role1) { FactoryGirl.build(:role, :curator, :person, :policy) }
        let(:role2) { FactoryGirl.build(:role, :editor, :group, :resource) }
        let(:other) { described_class.new roles: [role2, role1] }

        it "is 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

35 entries across 35 versions & 1 rubygems

Version Path
ddr-models-3.0.8 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.7 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.6 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.5 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.4 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.3 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.2 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.1 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.rc6 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.rc5 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.rc4 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.rc3 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.rc2 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.rc1 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.beta.22 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.beta.21 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.beta.20 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.beta.18 spec/auth/roles/role_set_spec.rb
ddr-models-3.0.0.beta.17 spec/auth/roles/role_set_spec.rb