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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:01:20+00:00 2026-05-27T22:01:20+00:00

This is the default test generated with a scaffold I created. describe PUT update,

  • 0

This is the default test generated with a scaffold I created.

  describe "PUT update", focus: true do
    describe "with valid params" do
      it "updates the requested purchase_order" do
        current_valid_attr = valid_attributes
        purchase_order = PurchaseOrder.create! current_valid_attr
        # Assuming there are no other purchase_orders in the database, this
        # specifies that the PurchaseOrder created on the previous line
        # receives the :update_attributes message with whatever params are
        # submitted in the request.
        # PurchaseOrder.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
        # put :update, :id => purchase_order.id, :purchase_order => {'these' => 'params'}
        PurchaseOrder.any_instance.should_receive(:update_attributes).with(current_valid_attr)
        put :update, :id => purchase_order.id, :purchase_order => current_valid_attr
      end

The problem is I don’t understand what it is supposed to do and I can’t make it pass with the correct attributes. Here’s the error when I ran the test

Failures:

      1) PurchaseOrdersController PUT update with valid params updates the requested purchase_order
         Failure/Error: put :update, :id => purchase_order.id, :purchase_order => current_valid_attr
           #<PurchaseOrder:0x007fe3027521e0> received :update_attributes with unexpected arguments
             expected: ({"id"=>nil, "supplier_id"=>1, "no"=>1305, "no_rujukan"=>"Guiseppe Abshire", "jenis"=>"P", "mula_on"=>Sat, 23 Aug 2003 14:11:42 MYT +08:00, "created_at"=>nil, "updated_at"=>nil})
                  got: ({"id"=>nil, "supplier_id"=>"1", "no"=>"1305", "no_rujukan"=>"Guiseppe Abshire", "jenis"=>"P", "mula_on"=>"2003-08-23 14:11:42 +0800", "created_at"=>nil, "updated_at"=>nil})

Thanks in advance.

valid_attributes

  def valid_attributes
    Factory.build(:purchase_order).attributes
  end

The factory

FactoryGirl.define do
  factory :purchase_order do
      association           :supplier
      sequence(:no)         { |n| Random.rand(1000...9999) }
      sequence(:no_rujukan) { |n| Faker::Name.name }
      sequence(:jenis)      { |n| PurchaseOrder::PEROLEHAN[Random.rand(0..3).to_i] }
      sequence(:mula_on)    { |n| Random.rand(10.year).ago }
    end
end
  • 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-27T22:01:20+00:00Added an answer on May 27, 2026 at 10:01 pm

    This test checks that when request comes to PurchaseOrdersController#update action update_attributes method for one of PurchaseOrder models is called and request parameters are properly passed to this method.

    The problem here (as stated by error message) is that update_attributes is called with hash of attributes that has all values of type String. That’s because all values of params hash (containing all request parameters) that is most likely used in update action are strings.

    On the other hand your current_valid_attr hash contains values of different types like Fixnum and Time. And when time comes to compare expected and received values you get an error, because, for example, no attribute was expected to be Fixnum 1305, but after submitting request it was converted to string and update_attributes received String '1305' instead.

    One of the ways to fix the problem is to ensure that all values in current_valid_attr are strings:

    no = 1305
    mula_on = Time.now
    # explicitly convert all attributes to String
    current_valid_attr = { :no => no.to_s, :mula_on => mula_on.to_s }
    

    Updated

    There is paramify_values method that can be used in tests to convert hash of parameters to the same form that will be received by controller in params hash.

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

Sidebar

Related Questions

https://alpha.pbp1.com/Property/Secure/test.htm <a href=http://alpha.pbp1.com/Property/Default.aspx>Home</a> This is a simple HTML page with a single href with
the directory structure I'm trying to achieve would be this: application/default/views/layouts/layout.phtml application/default/views/scripts/index/index.phtml application/admin/views/layouts/layout.phtml application/admin/views/scripts/index/index.phtml
I tried to follow this but the default modelbinder let my array null on
I have a weird problem, and I don't know if this is the default
This is one of the default gnome screensavers - personal slideshow. It displays pictures
This DLL is added by default in Visual Studio 2010 projects. What is this
The default [1..5] gives this [1,2,3,4,5] and can also be done with the range
The default in Ruby on Rails is to have this set to false (in
this is my link in my page asp:HyperLink ID=HyperLink1 runat=server NavigateUrl=~/Default.aspx>Add Record /asp:HyperLink with
Given this class public partial class Default : Page { private IRepository repo; ...

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.