Note that there are some explanatory texts on larger screens.

plurals
  1. POrails rspec controller action object method stub
    primarykey
    data
    text
    <p>I'm trying to test my controller #merge_with action. I want to test that @article is not nil, and gets assigned the article found in the database. Not sure why the test is failing, because the action seems to work just fine in the browser.</p> <p>The controller #merge_with action.</p> <pre><code>def merge_with unless current_user.admin? flash[:error] = _("You are not allowed to perform a merge action") redirect_to :action =&gt; :index return end @article = Article.find_by_id(params[:id]) if @article.merge_with(params[:merge_with]) flash[:notice] = _("Articles successfully merged!") redirect_to :action =&gt; :index else flash[:notice] = _("Articles couldn't be merged") redirect_to :action =&gt; :edit, :id =&gt; params[:id] end end </code></pre> <p>My RSpec test of the redirect is failing due to the merge_with called on the @article object. </p> <pre><code>context "when user is admin" do before :each do @admin_user = Factory(:user, :profile =&gt; Factory(:profile_admin)) @article = Factory(:article, :user =&gt; @user) request.session = {:user =&gt; @admin_user.id} end it "should merge articles" do Article.should_receive(:find_by_id).with(@article.id).and_return(@article) post :merge_with, id: @article.id assigns(:article).should == @article end end </code></pre> <p>The Error Message</p> <pre><code>expected: #&lt;Article id: 1, type: "Article", title: "A big article", author: nil, body: "A content with several data", extended: "extended content for fun", excerpt: nil, created_at: "2013-11-22 21:19:38", updated_at: "2013-11-22 21:19:36", user_id: nil, permalink: "a-big-article", guid: "deadbeef2", text_filter_id: nil, whiteboard: nil, name: nil, published: true, allow_pings: true, allow_comments: true, published_at: "2005-01-01 02:00:00", state: "published", parent_id: nil, settings: {}, post_type: "read"&gt; got: nil (using ==) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload