Sha256: e91111736c9ad3b28a63c16336e050b8249b756b605ad772a997efb3e0d501f1

Contents?: true

Size: 1.97 KB

Versions: 4

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

describe AccessRight do
  [
    [false, AccessRight::PERMISSION_TEXT_VALUE_PUBLIC, nil, true, false, false],
    [false, AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED, nil, true, false, false],
    [false, nil, nil, true, false, false],
    [false, nil, AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, true, false, false],
    [false, nil, AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED, false, true, false],
    [false, nil, AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, false, false, true],
    [true, AccessRight::PERMISSION_TEXT_VALUE_PUBLIC, nil, true, false, false],
    [true, AccessRight::PERMISSION_TEXT_VALUE_AUTHENTICATED, nil, false, true, false],
    [true, nil, nil, false, false, true],
    [true, nil, AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, true, false, false],
    [true, nil, AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED, false, true, false],
    [true, nil, AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, false, false, true],
  ].each do |given_persisted, givin_permission, given_visibility, expected_open_access, expected_authentication_only, expected_private|
    spec_text = <<-TEXT

    GIVEN: {
      persisted: #{given_persisted.inspect},
      permission: #{givin_permission.inspect},
      visibility: #{given_visibility.inspect}
    },
    EXPECTED: {
      open_access: #{expected_open_access.inspect},
      restricted: #{expected_authentication_only.inspect},
      private: #{expected_private.inspect}
    },
    TEXT

    it spec_text do
      permissions = [{access: :edit, name: givin_permission}]
      permissionable = double(
        'permissionable',
        permissions: permissions,
        visibility: given_visibility,
        persisted?: given_persisted
      )
      access_right = AccessRight.new(permissionable)

      expect(access_right.open_access?).to eq(expected_open_access)
      expect(access_right.authenticated_only?).to eq(expected_authentication_only)
      expect(access_right.private?).to eq(expected_private)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
curate-0.1.3 spec/models/access_right_spec.rb
curate-0.1.2 spec/models/access_right_spec.rb
curate-0.1.1 spec/models/access_right_spec.rb
curate-0.1.0 spec/models/access_right_spec.rb