Sha256: ad0f5913d9da75940b16ccc9ae7b0ff8fae722a8aef814c41df29835308d2bd6

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

describe UserPolicy do
  subject { UserPolicy }

  let (:current_user) { FactoryBot.build_stubbed :user }
  let (:other_user) { FactoryBot.build_stubbed :user }
  let (:admin) { FactoryBot.build_stubbed :user, :admin }

  permissions :index? do
    it "denies access if not an admin" do
      expect(UserPolicy).not_to permit(current_user)
    end
    it "allows access for an admin" do
      expect(UserPolicy).to permit(admin)
    end
  end

  permissions :show? do
    it "prevents other users from seeing your profile" do
      expect(subject).not_to permit(current_user, other_user)
    end
    it "allows you to see your own profile" do
      expect(subject).to permit(current_user, current_user)
    end
    it "allows an admin to see any profile" do
      expect(subject).to permit(admin)
    end
  end

  permissions :update? do
    it "prevents updates if not an admin" do
      expect(subject).not_to permit(current_user)
    end
    it "allows an admin to make updates" do
      expect(subject).to permit(admin)
    end
  end

  permissions :destroy? do
    it "prevents deleting yourself" do
      expect(subject).not_to permit(current_user, current_user)
    end
    it "allows an admin to delete any user" do
      expect(subject).to permit(admin, other_user)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_apps_testing-0.3.13 lib/generators/testing/configure/templates/spec/pundit/policies/user_policy_spec.rb