Commit 1b7079e0 authored by hellekin's avatar hellekin

More policy specs

parent 95c5ab3c
# frozen_string_literal: true
class AddressPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
def index?
user.maintainer?
end
def show?
true
end
end
......@@ -9,18 +9,6 @@ class AgentPolicy < ApplicationPolicy
record == user.agent || record_public?
end
def create?
user.editor?
end
def update?
create?
end
def destroy?
user.maintainer?
end
class Scope < Scope
def resolve
if user.current_agent_is_incommon? || user.leader? || user.maintainer?
......
......@@ -17,7 +17,7 @@ class ApplicationPolicy
end
def create?
false
user.editor?
end
# We don't have #new in API mode
......@@ -26,7 +26,7 @@ class ApplicationPolicy
end
def update?
false
create?
end
# We don't have #edit in API mode
......@@ -35,7 +35,7 @@ class ApplicationPolicy
end
def destroy?
false
user.maintainer?
end
class Scope
......
# frozen_string_literal: true
class CategoryPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
class CategoryPolicy < TaxonomyPolicy
end
......@@ -9,18 +9,6 @@ class CollectionPolicy < ApplicationPolicy
true
end
def create?
user.editor?
end
def update?
create?
end
def destroy?
user.maintainer?
end
class Scope < Scope
def resolve
scope.all
......
......@@ -20,14 +20,11 @@ class CorsOriginsPolicy
end
def create?
user.admin?
user.maintainer?
end
alias update? create?
def update?
user.admin?
end
def delete?
user.admin?
def destroy?
user.maintainer?
end
end
# frozen_string_literal: true
class EmailPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
def index?
user.leader? || user.maintainer?
end
def show?
true
end
end
# frozen_string_literal: true
class LinkPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
def index
true
end
def show
true
end
end
# frozen_string_literal: true
class LocationPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
def index?
user.maintainer?
end
def show?
true
end
end
......@@ -8,10 +8,4 @@ class MapPolicy < ApplicationPolicy
def show?
record_public?
end
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class NilClassPolicy < ApplicationPolicy
def show?
false # Nobody can see anything
end
class Scope < Scope
def resolve
raise Pundit::NotDefinedError, 'Cannot scope NilClass'
end
end
def show?
true # false # Nobody can see nothing
end
end
# frozen_string_literal: true
class PhonePolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
def index?
user.maintainer?
end
def show?
true
end
end
......@@ -8,22 +8,4 @@ class PositionPolicy < ApplicationPolicy
def show?
true
end
def create?
user.editor?
end
def update?
create?
end
def destroy?
user.maintainer?
end
class Scope < Scope
def resolve
scope.all
end
end
end
# frozen_string_literal: true
class ResourceAddressPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
class ResourceAddressPolicy < AddressPolicy
end
# frozen_string_literal: true
class ResourceCollectionPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
class ResourceCollectionPolicy < CollectionPolicy
end
# frozen_string_literal: true
class ResourceEmailPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
class ResourceEmailPolicy < EmailPolicy
end
# frozen_string_literal: true
class ResourceLinkPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
class ResourceLinkPolicy < LinkPolicy
end
# frozen_string_literal: true
class ResourcePhonePolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
class ResourcePhonePolicy < PhonePolicy
end
......@@ -9,18 +9,6 @@ class ResourcePolicy < ApplicationPolicy
record_public?
end
def create?
user.editor?
end
def update?
create?
end
def destroy?
user.maintainer?
end
class Scope < Scope
def resolve
if user.authenticated? == true
......
# frozen_string_literal: true
class RolePolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
def index?
user.leader?
end
def show?
true
end
end
# frozen_string_literal: true
class SectionPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
class SectionPolicy < TaxonomyPolicy
end
# frozen_string_literal: true
class TaxonomyPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
def index?
true
end
def show?
true
end
end
# frozen_string_literal: true
class UserEmailPolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.all
end
end
class UserEmailPolicy < EmailPolicy
end
......@@ -5,23 +5,11 @@ RSpec.describe AddressPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending 'is allowed to maintainer'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
pending 'is always allowed'
end
end
......@@ -6,22 +6,18 @@ RSpec.describe AgentPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
pending 'resolves to all if current agent is IN COMMON'
pending 'resolves to all for leader'
pending 'resolves to all for maintainer'
pending 'resolves to visible records otherwise'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending 'is always allowed'
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
permissions :show? do
pending 'is allowed if user belongs to agent'
pending 'is allowed if record is public'
end
end
require 'rails_helper'
RSpec.describe ApplicationPolicy do
let(:user) { User.new }
subject { described_class }
permissions '.scope' do
pending 'resolves to all'
end
permissions :index? do
pending 'is not allowed'
end
permissions :show? do
pending 'is not allowed'
end
permissions :create? do
pending 'is allowed to editor'
end
permissions :new? do
pending 'is never allowed'
end
permissions :update? do
pending 'follows create policy'
end
permissions :edit? do
pending 'is never allowed'
end
permissions :destroy? do
pending 'is allowed to maintainer'
end
end
require 'rails_helper'
RSpec.describe CategoryPolicy do
let(:user) { User.new }
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
it 'follows TaxonomyPolicy' do
expect(subject.ancestors[1]).to eql(TaxonomyPolicy)
end
end
......@@ -6,22 +6,14 @@ RSpec.describe CollectionPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
pending 'resolves to all'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending "is always allowed"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
permissions :show? do
pending 'is always allowed'
end
end
require 'rails_helper'
RSpec.describe CorsOriginsPolicy do
let(:user) { User.new }
subject { described_class }
permissions :index? do
it 'is always allowed'
end
permissions :show? do
it 'is always allowed'
pending 'is only allowed for actual Agent\'s origins'
end
permissions :create? do
pending 'is allowed to maintainer'
end
permissions :update? do
pending 'follows create?'
end
permissions :destroy? do
pending 'follows create?'
end
end
......@@ -5,23 +5,13 @@ RSpec.describe EmailPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending 'is allowed for leader'
pending 'is allowed for maintainer'
pending 'is not allowed otherwise'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
pending 'is always allowed'
end
end
......@@ -5,23 +5,11 @@ RSpec.describe LinkPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending 'is always allowed'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
pending 'is always allowed'
end
end
......@@ -5,23 +5,11 @@ RSpec.describe LocationPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending 'can be listed by maintainers'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
pending 'is always allowed'
end
end
......@@ -5,23 +5,11 @@ RSpec.describe MapPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending 'is always allowed'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
pending 'is allowed for public (visible) maps'
end
end
......@@ -5,23 +5,11 @@ RSpec.describe PhonePolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending 'can be listed by maintainer'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
pending 'is always allowed'
end
end
......@@ -5,23 +5,11 @@ RSpec.describe PositionPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
permissions :index? do
pending 'is always allowed'
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
pending 'is always allowed'
end
end
......@@ -5,23 +5,7 @@ RSpec.describe ResourceAddressPolicy do
subject { described_class }
permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
it 'follows AddressPolicy' do
expect(subject.ancestors[1]).to eql(AddressPolicy)
end
end