Last active
April 12, 2020 13:17
-
-
Save vamsipavanmahesh/ff7434fcf1c7c9c6ace13f16291e4ad7 to your computer and use it in GitHub Desktop.
Some example tests for pundit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookGroupPolicy < ApplicationPolicy | |
attr_reader :user, :book_group | |
def initialize(user, book_group) | |
@user = user | |
@book_group = book_group | |
end | |
def update? | |
user.moderator?(book_group) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe BookGroupPolicy do | |
let(:user) { create(:user) } | |
let(:book_group) { create(:book_group) } | |
let(:admin_user) { create(:user) } | |
let!(:book_group_user) { BookGroupUser.create(book_group: book_group, user: admin_user, admin: true) } | |
it do | |
expect(Pundit.policy(user, book_group).update?).to eq false | |
expect(Pundit.policy(admin_user, book_group).update?).to eq true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment