title: how to write rspec for ability using cancancan
body: <p>I have a implemented the post and user model where post model belongs to user model. I defined the ability model for authorisation so that only user who created the post can able to delete or update the post. i have the post controller like this:</p>
  
  <pre><code>def edit
    @post = @topic.posts.find(params[:id])
    authorize! :update, @post
  end
  </code></pre>
  
  <p>Ability model:</p>
  
  <pre><code>class Ability
    include CanCan::Ability
  
    def initialize(user)
      can :update, Post do |p|
        p.user == user
      end
  
      can :destroy, Post do |p|
        p.user == user
      end
  
      can :destroy, Comment do |c|
        c.user == user
      end
  
      can :create, Post
      can :create, Comment
    end
  end
  </code></pre>
  
  <p>What will be the rspec for the above model?
  Error:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>expected #&lt;User id: nil, email: "", created_at: nil, updated_at: nil&gt; to respond to `able_to?`
  
    0) User Check for Abilities What User can do should be able to :create and #&lt;Post id: nil, title: nil, body: nil, created_at: nil, updated_at: nil, topic_id: nil, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil, user_id: nil&gt;
       Failure/Error: it { should be_able_to(:create, Post.new) }
         expected #&lt;User id: nil, email: "", created_at: nil, updated_at: nil&gt; to respond to `able_to?`
       # ./spec/models/ability_spec.rb:8:in `block (4 levels) in &lt;top (required)&gt;'
  
  expected #&lt;User id: nil, email: "", created_at: nil, updated_at: nil&gt; to respond to `able_to?`
  
    0) User Check for Abilities What User can do should be able to :update and #&lt;Post id: nil, title: nil, body: nil, created_at: nil, updated_at: nil, topic_id: nil, image_file_name: nil, image_content_type: nil, image_file_size: nil, image_updated_at: nil, user_id: nil&gt;
       Failure/Error: it { should be_able_to(:update, Post.new) }
         expected #&lt;User id: nil, email: "", created_at: nil, updated_at: nil&gt; to respond to `able_to?`
       # ./spec/models/ability_spec.rb:9:in `block (4 levels) in &lt;top (required)&gt;'</code></pre>
  </div>
  </div>
  </p>