Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:58:41+00:00 2026-06-05T13:58:41+00:00

Expected response to be a <:redirect>, but was <200> My tests has: describe Link

  • 0

Expected response to be a <:redirect>, but was <200>

My tests has:

describe "Link POST #create" do

  context "with valid attributes" do
    it "creates a new link" do
      expect{
        post :create, link: FactoryGirl.create(:link, :group => @group)
      }.to change(Link,:count).by(1)
    end

    it "redirects to the new link" do
      post :create, link: FactoryGirl.create(:link, :group => @group)
      # response.should redirect_to @link # Link.unscoped.last
      response.should redirect_to Link.unscoped.last # render_template :show
    end
  end

The first test passes but the second fails.

My code is:

  def create
    @link = Link.new(params[:link])

    respond_to do |format|
      if @link.save
        flash[:notice] = 'Link was successfully created.'
        format.html { redirect_to(@link) }
        format.xml  { render :xml => @link, :status => :created, :location => @link }
      else
        @selected_group = params[:group_id]
        format.html { render :action => "new" }
        format.xml  { render :xml => @link.errors, :status => :unprocessable_entity }
      end
    end
  end

I’ve tried redirect and render but can’t get the 2nd test to pass.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:58:42+00:00Added an answer on June 5, 2026 at 1:58 pm

    Here’s something that should make it work:

    describe "Link POST #create" do
    
      context "with valid attributes" do
    
        def do_post( format = 'html' )
          attributes = FactoryGirl.build(:link).attributes.merge( :group_id => @group.id )
          post :create, :link => attributes, :format => 'html'
        end
    
        it "creates a new link" do
          expect{
            do_post
          }.to change(Link,:count).by(1)
        end
    
        it "redirects to the new link" do
          do_post
          response.should redirect_to( assigns[:link] )
        end
      end
    

    The first spec was working only because you were calling FactoryGirl.create so a record was being created out of the controller, but most likely the controller call wasn’t working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to redirect my response but I got stuck at the link path.
Receiving the following error when doing a simple calendar fetch: Expected response code 200,
I expected this to print [b] but it prints [] : $x = abc;
Getting Expected ',' or '{' but found '#44559' error. My code looks like this:
Hello I am trying to do a redirect if the response is a 404
My OnTransactionCommit method is not being called on IIS 7 when I use Response.Redirect
I have the following test written in RSpec: describe '#create' do ... it 'redirects
I have a SOAP service, the request and responses work as expected with good
Expected Outcome: Successful installtion of Plone 4.1.4 Actual Outcome: Installation fails with: libxml2: cmmi
Expected output & output I get in debug mode, and release mode under VS2010,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.