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

  • Home
  • SEARCH
  • 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 7073143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:53:38+00:00 2026-05-28T05:53:38+00:00

Here is the create in rfq controller: def create if has_create_right? @rfq = Rfq.new(params[:rfq],

  • 0

Here is the create in rfq controller:

  def create
    if has_create_right?
      @rfq = Rfq.new(params[:rfq], :as => :roles_new )
      #save into join table rfqs_standards
      params[:rfq][:standard_ids].each do |sid|
        @rfq.standards << Standard.find(sid.to_i) if !sid.nil?
      end
    if @rfq.save
        redirect_to URI.escape("/view_handler?index=0&msg=RFQ saved!")
      else
        flash.now[:error] = "RFQ not saved!"
        render 'new'
      end
    end
  end

Here is the rspec code

  describe "'create'" do
    it "should be successful for corp head" do
      session[:corp_head] = true
      session[:user_id] = 1
      s = Factory(:standard)
      rfq = Factory.attributes_for(:rfq)
      rfq.standards << s
      get 'create', :rfq => rfq
      response.should redirect_to URI.escape("/view_handler?index=0&msg=RFQ saved!")
    end
  end

The error is:

  1) RfqsController 'create' should be successful for corp head
     Failure/Error: rfq.standards << s
     NoMethodError:
       undefined method `standards' for #<Hash:0x6741570>
     # ./spec/controllers/rfqs_controller_spec.rb:65:in `block (3 levels) in <top (requi

What’s the right way to test join record? 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-28T05:53:39+00:00Added an answer on May 28, 2026 at 5:53 am

    From this part of your test:

        rfq = Factory.attributes_for(:rfq)
        rfq.standards << s
    

    it would seem that rfq is created as an attributes hash and not a complete model. You can try joining the standard_ids like this:

    describe "'create'" do
      it "should be successful for corp head" do
        session[:corp_head] = true
        session[:user_id] = 1
        s = Factory(:standard)
        rfq = Factory.attributes_for(:rfq)
        rfq[:standard_ids] = [s.id] # attach standard_id's to mimic the POST'ed form data
        get 'create', :rfq => rfq
        response.should redirect_to URI.escape("/view_handler?index=0&msg=RFQ saved!")
      end
    end
    

    However, it seems that you can accomplish all of this using nested attributes – see http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

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

Sidebar

Related Questions

I am using git configuration mentioned here If I create a new tab and
I have two tables: entitytype and project . Here are the create table statements:
Here's my table: CREATE TABLE `alums_alumphoto` ( `id` int(11) NOT NULL auto_increment, `alum_id` int(11)
I have a simple self referencing table as depicted here: CREATE TABLE [dbo].[Project]( [ProjectId]
There are instructions here to create a C# assembly using the SimMetrics library. The
I am creating a web application using zend, here I create an interface from
Here it is Create a thread in suspended state. hThrd1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
My goal here is to create a very simple template language. At the moment,
Here is my problem: Create a constructor for a telephone number given a string
Here's my situation: I'm trying to create a SSL certificate that will be installed

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.