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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:18:28+00:00 2026-05-26T10:18:28+00:00

Here is the failed spec code for create in customer controller: describe CustomersController do

  • 0

Here is the failed spec code for create in customer controller:

describe CustomersController do

  before(:each) do
    #the following recognizes that there is a before filter without execution of it.
    controller.should_receive(:require_signin)
    controller.should_receive(:require_employee)
  end

  render_views

    describe "'create' successful" do
      before(:each) do
        category = Factory(:category)
        sales = Factory(:user)      
        @customer = Factory.attributes_for(:customer, :category1_id => category.id, :sales_id => sales.id)
        session[:sales] =  true
        session[:user_id] = sales.id
        session[:user_name] = sales.name
        session[:page_step] = 1
        session['page1'] = customers_path
      end

      it "should create one customer record" do
        lambda do
          post 'create', @customer         
        end.should change(Customer, :count).by(1)
      end

      it "should redirect to customers path" do
        put 'create', @customer
        flash[:notice].should_not be_nil
        response.should redirect_to(customers_path)
      end
    end
 end

The customer has both sales id and category id which belong to user and category table respectively.

Here is the spec failure error:

  1) CustomersController GET customer page 'create' successful should create one customer record
     Failure/Error: lambda do
       count should have been changed by 1, but was changed by 0
     # ./spec/controllers/customers_controller_spec.rb:37:in `block (4 levels) in <top (required)>'

  2) CustomersController GET customer page 'create' successful should redirect to customers path
     Failure/Error: flash[:notice].should_not be_nil
       expected: not nil
            got: nil
     # ./spec/controllers/customers_controller_spec.rb:44:in `block (4 levels) in <top (required)>'

Here is the app code for create in customer controller:

  def create

    if session[:sales]
      @customer = Customer.new(params[:customer], :as => :roles_new_update)
      @customer.sales_id = session[:user_id]
      if @customer.save 
        @message = "New customer #{params[:name]} was created. Please check it out"
        @subject = "New customer #{params[:name]} was created BY {#session[:user_name]}"
        UserMailer.notify_tl_dh_ch_ceo(@message, @subject, session[:user_id])
        redirect_to session[('page' + session[:page_step].to_s).to_sym], :notice => 'Customer was created successfaully!'          
      else
        render 'new', :notice => 'Customer was not saved!'
      end
    end
  end

Here is the code in factories.rb:

Factory.define :customer do |c|
  c.name                    "test customer"
  c.short_name              "test"   
  c.email                   "t@acom.com"
  c.phone                   "12345678"
  c.cell                    "1234567890"
  c.active                  1
  c.category1_id            2
  c.sales_id                1
  c.address                 "1276 S. Highland Ave, Lombard, IL 67034"
  c.contact                 "Jun C"

end

Factory.define :category do |c|
  c.name                   "category name"
  c.description            "test category"
  c.active                 true
end

Factory.define :user do |user|

  user.name                  "Test User"
  user.email                 "test@test.com"
  user.password              "password1"
  user.password_confirmation "password1"
  user.status                "active"
  user.user_type             "employee"

end

It seems that the error was caused by @customer.save returning false and the code for “if @customer.save” was not executed. So the problem may be with the @customer generated by Factory which seems good to me. The code is executed without any problem when saving a customer.

Any suggestions? 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-05-26T10:18:28+00:00Added an answer on May 26, 2026 at 10:18 am
    post :create, :customer => @customer
    

    solves the problem with above.

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

Sidebar

Related Questions

Here is the failed rspec code: require 'spec_helper' describe MainMenuController do describe GET 'first_page'
Here is the test that is failing: before(:each) do @attr = { :user_id =>
gem install heroku failed with following message and I have tried the solution here
Please see my code below. ifstream myLibFile (libs//%s , line); // Compile failed here
The developer documentation has seemed to have failed me here. I can create a
there. I've searched my question around here but failed to find anything relevant. This
After my last, failed, attempt at asking a question here I'm trying a more
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior

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.