2

I`m doing excercise from book Rails 4 in Action (listing 8-12). I installed pundit gem and wrote test, Rspec gives me strange error:

    1) ProjectPolicy show? blocks anonymous users
 Failure/Error:
   def initialize(user, record)
     @user = user
     @record = record

 ArgumentError:
   wrong number of arguments (given 0, expected 2)
 # ./app/policies/application_policy.rb:4:in `initialize'
 # ./spec/policies/project_policy_spec.rb:10:in `block (3 levels) in <top (required)>'

My spec for project

describe ProjectPolicy do

permissions :show? do
  let(:user) { FactoryGirl.create :user }
  let(:project) { FactoryGirl.create :project }

  it "blocks anonymous users" do
    expect(subject).not_to permit(nil, project)
  end
end

end

Application policy (if was autogenerated by gem, nothing was changed there)

class ApplicationPolicy
attr_reader :user, :record

def initialize(user, record)
  @user = user
  @record = record
end

rest omitted

Leorisar
  • 91
  • 1
  • 6
  • did you follow the guidelines in the Pundit docs? https://github.com/elabs/pundit#policy-specs – zetetic May 03 '16 at 00:29
  • 1
    @zetetic I updated spec according to docs and it worked, thanks! I had to add line `subject { described_class }` which was not statet in book. – Leorisar May 04 '16 at 17:45

0 Answers0