Hi There

I'm using pundit for authorization and rspec for testing in my rails app. I 
wrote some controller tests those are failing due to pundit admin role 
authorization. How can make them pass? Please help me, any suggestion will 
be appreciated.

Here is my controller specs file.

require 'rails_helper'
require 'rails-controller-testing'

RSpec.describe Admin::PostsController, :type => :controller do
  # This should return the minimal set of attributes required to create a 
valid
  # Product. As you add validations to Product, be sure to
  # adjust the attributes here as well.
  let(:valid_attributes) {
    FactoryGirl.attributes_for(:post)
  }

 let(:invalid_attributes) {
    { title: nil}
  }

 # This should return the minimal set of values that should be in the 
session
  # in order to pass any filters (e.g. authentication) defined in
  # Admin::ProductsController. Be sure to keep this updated too.
  let(:valid_session) { {} }

 describe "GET index" do
    it "assigns all posts as @posts" do
      post = Post.create! valid_attributes
      get :index, {}, valid_session
      expect(assigns(:posts)).to eq([post])
    end
  end

 describe "GET show" do
    it "assigns the requested post as @post" do
      post = Post.create! valid_attributes
      get :show, {:id => post.to_param}, valid_session
      expect(assigns(:post)).to eq(post)
    end
  end

 describe "GET new" do
    it "assigns a new post as @post" do
      get :new, {}, valid_session
      expect(assigns(:post)).to be_a_new(Post)
    end
  end

 describe "GET edit" do
    it "assigns the requested post as @post" do
      post = Post.create! valid_attributes
      get :edit, {:id => post.to_param}, valid_session
      expect(assigns(:post)).to eq(post)
    end
  end

 describe "POST create" do
    describe "with valid params" do
      it "creates a new Post" do
        expect {
          post :create, {:post => valid_attributes}, valid_session
        }.to change(Post, :count).by(1)
      end

     it "assigns a newly created post as @post" do
        post :create, {:post => valid_attributes}, valid_session
        expect(assigns(:post)).to be_a(Post)
        expect(assigns(:post)).to be_persisted
      end

     it "redirects to the index page after success" do
        post :create, {:post => valid_attributes}, valid_session
        expect(response).to redirect_to(admin_posts_path)
      end
    end
  end
end


Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/e4aa205f-2cab-4caa-a326-5c82af997463%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to