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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:02:23+00:00 2026-05-27T10:02:23+00:00

Here is rspec code for controller: it should render edit if update was not

  • 0

Here is rspec code for controller:

it "should render edit if update was not saved" do
  item = Factory(:lease_item)
  session[:corp_head] = true
  post 'update', {:id => item.id, :name => 'nil'}
  flash[:notice].should_not be_nil
  response.should render 'edit'    
end

The update in controller is:

  def update
    if (eng? && dept_head?) || corp_head? || ceo?
      @lease_item = LeaseItem.find(params[:id])
      @lease_item.input_by_id = session[:user_id]
      if @lease_item.update_attributes(params[:lease_item], :as => :roles_update)

        #redirect
        redirect_to URI.escape("/view_handler?index=0&msg=Lease item updated successfully")
      else
        #back to new
        render 'edit', :notice => "Item NOT updated"
      end
    else
      #back to previous page
      redirect_to URI.escape("/view_handler?index=0&msg=NO right to update lease item")
    end    
  end

Here is the error code from rspec:

  1) LeaseItemsController GET 'update' should render edit if update was not saved
     Failure/Error: flash[:notice].should_not be_nil
       expected: not nil
            got: nil

“Item NOT updated” was expected in flash. However why there is nothing with flash[:notice]? Or how to rspec there is a message with render ‘edit’, :notice => ‘Item NOT updated’

Thanks.

UPDATE:

Here is change in controller:

      ...........
      else
        #back to new
        flash[:notice] = "Item NOT updated"
        render 'edit'
      end
      .........

Here is the rspec code which passes:

   it "should render edit if update was not saved" do
      item = Factory(:lease_item)
      session[:corp_head] = true
      post 'update', {:id => item.id, :lease_item => {:name => 'nil'}}
      flash.should_not be_nil
      response.should render_template(:action=> "edit")  
    end

It did not work if using flash[:notice].should_not be_nil (or .. flash.now[:notice]…). The error is Got nil which is the same as before. Also response.should render ‘edit’ (or … render :action => ‘edit’) did not pass as well. The error is NameError or NoMethodError. Not sure why.

  • 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-05-27T10:02:24+00:00Added an answer on May 27, 2026 at 10:02 am

    change your else to:

    else
      #back to new
      flash[:notice] = "Item NOT updated"
      render 'edit'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the rspec code for testing show in customers controller: it 'show' should
Here is the error for update in rspec: 4) CustomersController GET customer page 'update'
Ruby 1.9.2 Rails 3.1 Here is the problem bundle exec rspec spec/ does not
OK, here's my rspec code ... before(:each) do @attr = { :greeting => Lorem
Here is the failed rspec code: require 'spec_helper' describe MainMenuController do describe GET 'first_page'
Here is the rspec error message: 5) CustomersController GET customer page 'show' should be
I use Rails 3 and RSpec 2.6.0. Not sure if that's possible, but here
Here is my code, which takes two version identifiers in the form 1, 5,
Here is the create in rfq controller: def create if has_create_right? @rfq = Rfq.new(params[:rfq],
Not sure if this is a Rails 3 issue or an RSpec 2 issue,

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.