I need to write specs to check permitted params for create action.
module Backoffice
class JobsController < BaseController
def create
@job = Job.new(job_params)
end
def job_params
params.require(:job).permit(:title)
end
end
end
RSpec.describe Backoffice::JobsController, type: :controller do
it do
params = {
job: {
title: 'John'
}
}
should permit(:title).
for(:create, params: params).
on(:job)
end
end
For some reason I'm getting:
Expected POST #create to restrict parameters on :job to :title, but it did not restrict any parameters.
Is it because controller in a module?
This is because your params should not be a hash, these params come from
ActionController::Parameters
. Try something like: