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 8957831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:04:48+00:00 2026-06-15T15:04:48+00:00

I have this factory: @host = FactoryGirl.create(:host) This test passes: it ‘should update and

  • 0

I have this factory: @host = FactoryGirl.create(:host)

This test passes:

it 'should update and redirect to the show page' do                                  
  new_attr = @host.attributes.merge("hostname" => "New_name")             
  put 'update', id: @host, host: new_attr              
  response.should redirect_to(host_path(@host))                           
end¬   

But this one fails:

  it 'should fail on validation for empty hostname and redirect to edit' do                                           
    bad_attr = @host.attributes.merge("hostname" => "")                     
    put 'update', id: @host, host: bad_attr                                 
    response.should redirect_to(edit_host_path(@host))                
  end 

With this error:

   1) HostsController POST update failure should redirect to edit
         Failure/Error: response.should redirect_to(edit_host_path(@host))
           Expected response to be a redirect to <http://test.host/hosts/1/edit> but was a redirect to <http://test.host/hosts/1>
         # ./spec/controllers/hosts_controller_spec.rb:127:in `block (4 levels) in <top (required)>'

In the #update of my HostsController, host objects that fail validation with empty hostnames are supposed to redirect_to edit_host_path(@host). Here is my HostsController#update

def update                                                                    
  @host = Host.find(params[:id])                                              
  if @host.save                 
    flash[:notice] = 'Host was successfully updated.'                         
    redirect_to host_path(@host)                                              
  else¬                                                                        
    redirect_to edit_host_path(@host)    
  end
end            

I’ve played with saving and updating attributes in the console and my validations work. So why this error? Any ideas? Rspec seems to be saying that my factory objects with bad attributes are passing validation, but my model validates fine. Thank you.

  • 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-15T15:04:49+00:00Added an answer on June 15, 2026 at 3:04 pm

    /me does a face-palm.

    In HostsController#update, this:

    @host = Host.find(params[:id])
    @host.save
    

    Should be this:

    @host = Host.find(params[:id])
    @host.update_attributes(params[:host])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this example FactoryGirl.define do @site = FactoryGirl.create(:my_site) factory :user do email {
I have this factory: FactoryGirl.define do factory :from_sector, class: Sector do sequence(:name) { |n|
I have a Factory like this: FactoryGirl.define do factory :subject do name 'Calculus' end
I'm trying to create an EJB factory class, which works like this: You have
I have this rspec scenario: background do Factory.create(:project, :name => NAME, :url_name => url
Let's say we have a code portion like this: IProduct product = ProductCreator.CreateProduct(); //Factory
I have a WCF Host with something like this: [ServiceContract] public interface IMountToOs {
I have a configuration of a blog factory like this : - blogcrea.com/a-blog/ ->
I have a host application that controls various factory classes which produce implementations of
Hi i have this class to instantiate DAL classes: public class Factory { public

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.