Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/models/solidus_static_content/permission_sets/page_display.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
module SolidusStaticContent
module PermissionSets
class PageDisplay < Spree::PermissionSets::Base
class << self
def privilege
:display
end

def category
:page
end
end

def activate!
can [:display, :admin], Spree::Page
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
module SolidusStaticContent
module PermissionSets
class PageManagement < Spree::PermissionSets::Base
class << self
def privilege
:management
end

def category
:page
end
end

def activate!
can :manage, Spree::Page
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

require "spec_helper"
require "cancan/matchers"

describe SolidusStaticContent::PermissionSets::PageDisplay do
let(:ability) { Class.new { include CanCan::Ability }.new }

subject { ability }

context "when activated" do
before { described_class.new(ability).activate! }

it { is_expected.to be_able_to(:display, Spree::Page) }
it { is_expected.to be_able_to(:admin, Spree::Page) }

it { is_expected.not_to be_able_to(:update, Spree::Page) }
it { is_expected.not_to be_able_to(:create, Spree::Page) }
it { is_expected.not_to be_able_to(:destroy, Spree::Page) }
end

context "when not activated" do
it { is_expected.not_to be_able_to(:display, Spree::Page) }
it { is_expected.not_to be_able_to(:admin, Spree::Page) }
end

describe ".privilege" do
it "returns the correct privilege symbol" do
expect(described_class.privilege).to eq(:display)
end
end

describe ".category" do
it "returns the correct category symbol" do
expect(described_class.category).to eq(:page)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require "spec_helper"
require "cancan/matchers"

describe SolidusStaticContent::PermissionSets::PageManagement do
let(:ability) { Class.new { include CanCan::Ability }.new }

subject { ability }

context "when activated" do
before { described_class.new(ability).activate! }

it { is_expected.to be_able_to(:manage, Spree::Page) }
it { is_expected.to be_able_to(:display, Spree::Page) }
it { is_expected.to be_able_to(:admin, Spree::Page) }
it { is_expected.to be_able_to(:update, Spree::Page) }
it { is_expected.to be_able_to(:destroy, Spree::Page) }
end

context "when not activated" do
it { is_expected.not_to be_able_to(:manage, Spree::Page) }
it { is_expected.not_to be_able_to(:admin, Spree::Page) }
end

describe ".privilege" do
it "returns the correct privilege symbol" do
expect(described_class.privilege).to eq(:management)
end
end

describe ".category" do
it "returns the correct category symbol" do
expect(described_class.category).to eq(:page)
end
end
end
Loading