Skip to content
Draft
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
4 changes: 4 additions & 0 deletions app/policies/workshop_log_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def create?
authenticated?
end

def edit?
admin? || owner?
end

def update?
admin? || owner?
end
Expand Down
65 changes: 65 additions & 0 deletions spec/policies/workshop_log_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require "rails_helper"

RSpec.describe WorkshopLogPolicy, type: :policy do
let(:admin_user) { build_stubbed(:user, :admin) }
let(:owner_user) { build_stubbed(:user) }
let(:other_user) { build_stubbed(:user) }

let(:workshop_log) { build_stubbed(:workshop_log, created_by: owner_user) }

def policy_for(record: workshop_log, user:)
described_class.new(record, user: user)
end

describe "#edit?" do
context "with admin user" do
subject { policy_for(user: admin_user) }

it { is_expected.to be_allowed_to(:edit?) }
end

context "with owner user" do
subject { policy_for(user: owner_user) }

it { is_expected.to be_allowed_to(:edit?) }
end

context "with other user" do
subject { policy_for(user: other_user) }

it { is_expected.not_to be_allowed_to(:edit?) }
end

context "with no user" do
subject { policy_for(user: nil) }

it { is_expected.not_to be_allowed_to(:edit?) }
end
end

describe "#update?" do
context "with admin user" do
subject { policy_for(user: admin_user) }

it { is_expected.to be_allowed_to(:update?) }
end

context "with owner user" do
subject { policy_for(user: owner_user) }

it { is_expected.to be_allowed_to(:update?) }
end

context "with other user" do
subject { policy_for(user: other_user) }

it { is_expected.not_to be_allowed_to(:update?) }
end

context "with no user" do
subject { policy_for(user: nil) }

it { is_expected.not_to be_allowed_to(:update?) }
end
end
end
Loading