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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:35:29+00:00 2026-06-18T00:35:29+00:00

I have the following action in my controller: def create @user = current_user @vin

  • 0

I have the following action in my controller:

def create
    @user = current_user
    @vin = @user.vins.new(params[:vin])

    if @vin.save
        # waiting for implementation
        logger.debug("here we are")
    else
        redirect_to(vins_path)
    end         
end

I’d like to test with with rspec. However, I want to stub out the save operation to simulate a failure:

it "should send user to vins_path if there is a problem creating the VIN" do
    @vin.stub!(:save).and_return(false)
    post 'create', :vin => { :name => "Test 1", :vin => "test" }
    response.should redirect_to(vins_path)
end

However, the stub doesn’t seem to work as the save operation is always successful. What am I doing wrong?

Thanks

  • 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-18T00:35:30+00:00Added an answer on June 18, 2026 at 12:35 am

    Try this:

    Vin.any_instance.stub(:save).and_return(false)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my controller action, I have the following: def index @articles = (params[:mine] ==
Okay, I have the following create action #posts_controller, nested resource under discussions def create
I have the following code in my controller action method: if (User.Identity.IsAuthenticated) { //
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
If i have a controller action Create that returns a view with the following
I have the following code in my gsp <select onChange=${remoteFunction(action:'superior', controller:'employee', params: '\'name=\' +
I have the following action in my tags controller: ( params[:q] comes from this
I have the following controller action: [HttpGet] public JsonpResult getTestValues(int? entityId, int? id) {
I have the following route: routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with
I have a controller with the following action code: public JsonResult CheckPasswordStrength(string password, string

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.