Questions tagged [pundit]

Pundit provides a set of helpers that guide Ruby programmer in leveraging regular Ruby classes and object oriented design patterns to build a simple, robust and scaleable authorization system.

439 questions
2
votes
1 answer

Why is my enum value wrong in minitest using Pundit gem?

I created a starter app from RailsApps with the rails-devise-pundit example app. I am trying to write a user controller test because I plan to change some functionality and I want to make sure things still work. The pundit UserPolicy is not…
Mike F.
  • 69
  • 1
  • 9
2
votes
1 answer

CanCan not fully supported in Rails 4

It seems that Ryan Bates stopped developing CanCan. Rails 4 is nos fully supported. And, ready4rails4 says that it isn't work. Should I replace CanCan for another authorization library? Regards
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
2
votes
2 answers

RSpec test for pundit using expect syntax

I'm trying to convert the following spec to new expect syntax, could anyone help? describe PostPolicy do subject { PostPolicy } permissions :create? do it "denies access if post is published" do should_not permit(User.new(:admin =>…
Ilya I
  • 1,282
  • 1
  • 12
  • 19
1
vote
1 answer

Rails 7 - pundit scope for has many through

I recently started using the Pundit gem for authorization in my Rails app. In my app I have models for Company, each Company can have multiple Employees, this is done through a has many through relationship: # company.rb has_many :employees,…
Anders
  • 2,903
  • 7
  • 58
  • 114
1
vote
1 answer

How to limit simple form association to show only current user's values

I'm building an expense tracker with Ruby on Rails 7. I used pundit gem to authorize each user to access only their own data. But still, when I try to add a new transaction, it shows all bank accounts not only current users' accounts. This is how I…
1
vote
1 answer

Test a policy with rspec

I have this policy for cards, only i am using scope, its very simple, but once i tried to test with rspec i am getting errors, i am pasting my code and the below of that is the error: this is the test, i am creating user, card and the scope, i dont…
mtsyumm
  • 39
  • 5
1
vote
1 answer

To test pundit, its necessary to log in at the app first?

I am using pundit gem to authorize in my system app. before to implement pundit I had my endpoint index like this: def index @cars = Car.all render json: @cars end worked ok, but now with pundit, i made a change like this …
mtsyumm
  • 39
  • 5
1
vote
1 answer

Rails 7 pass session params to pundit policy

I'm using Devise to authenticate User in my Rails 7 app and Pundit for authorization. I would like to extend the standard login flow to check if the user has met the 2FA requirements. 2FA is simple and delivered by an external microservice - the…
mr_muscle
  • 2,536
  • 18
  • 61
1
vote
1 answer

Expect mock result to receive method

I'm trying to mock a class, so that I can expect it is instantiated and that a certain method is then called. I tried: expect(MyPolicy). to receive(:new). and_wrap_original do |method, *args| expect(method.call(*args)).to…
Jaffa
  • 12,442
  • 4
  • 49
  • 101
1
vote
1 answer

Pundit gem error class overriding my custom error class in ruby

my application has custom error classes defined lib/error/* example #lib/error/custom_error.rb module Error class CustomError < StandardError attr_accessor :error, :status, :message def initialize error, status, message …
Nijeesh Joshy
  • 1,426
  • 13
  • 24
1
vote
3 answers

ActiveRecord::NotNullViolation: PG::NotNullViolation: ERROR: null value in column "created_at" violates not-null constraint

I have a new model, this is my migration: def change create_table :news do |t| t.string :title t.text :content t.timestamps end end and this is my schema create_table "news", force: :cascade do |t| t.string…
problems
  • 95
  • 1
  • 8
1
vote
2 answers

Using searchkick with pundit: policyscope error

I am trying to implement a basic search engine with filtering options and i am stuck on the implementation of searchkick. Here is my code: class ProductsController < ApplicationController def index if params[:query].present? @products =…
1
vote
1 answer

Rails validate params in pundit policy

I am creating a trello style app where a user can drag cards between lists. I am handling all the reordering logic on the js side, and am posting the list_id and position to the rails update action in my controller: card = authorize…
I_A
  • 331
  • 2
  • 14
1
vote
1 answer

current_user is nil and user_signed_in? returning false react-rails with devise

I have a rails 5.2 app that was originally built with Devise and plain old erb files. I could check current_user in the frontend and all that. Now I am trying to slowly move it to React frontend. I haven't changed any of my setup but my…
Coding Enthusiast
  • 3,865
  • 1
  • 27
  • 50
1
vote
0 answers

Nested Parameters not working with Pundit

I'm trying to figure out why my update function won't accept nested parameters for a relation. I've included the "accepts_nested_attributes_for :stream" in my User model. # UsersController # PATCH/PUT /users/me # PATCH/PUT /users/1 def update #…
TemporaryName
  • 487
  • 5
  • 16