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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:43:06+00:00 2026-05-30T13:43:06+00:00

When running functional tests on my controller code in a Rails 3 project, I

  • 0

When running functional tests on my controller code in a Rails 3 project, I have a fatal error; the params variable contains controller and action, and ActiveModel is not happy about it:

ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: controller, action
    /Users/phooze/.rvm/gems/ruby-1.9.3-p0/gems/activemodel-3.2.1/lib/active_model/mass_assignment_security/sanitizer.rb:48:in `process_removed_attributes'
    /Users/phooze/.rvm/gems/ruby-1.9.3-p0/gems/activemodel-3.2.1/lib/active_model/mass_assignment_security/sanitizer.rb:20:in `debug_protected_attribute_removal'
    /Users/phooze/.rvm/gems/ruby-1.9.3-p0/gems/activemodel-3.2.1/lib/active_model/mass_assignment_security/sanitizer.rb:12:in `sanitize'
    /Users/phooze/.rvm/gems/ruby-1.9.3-p0/gems/activemodel-3.2.1/lib/active_model/mass_assignment_security.rb:228:in `sanitize_for_mass_assignment'
    /Users/phooze/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/attribute_assignment.rb:75:in `assign_attributes'
    /Users/phooze/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.1/lib/active_record/base.rb:495:in `initialize'
    /Users/phooze/Documents/rails-app/app/controllers/credentials_controller.rb:40:in `new'

The application call is to the “new” method (where the error is occurring), the code is:

  # Credential#create (POST)
  def create
      @credential = Credential.new(params)
      # ... controller continues
  end

Finally, my test case:

  test "should create credential" do
    assert_difference('Credential.count', 1) do
      post :create, { :fid => "foobarbaz", :credentials_hash => "f00ba7f00ba7", :uid => "10023", :cid => "342" }
    end
    assert_response :created
  end

Changing my controller code to a “separate” parameter hash containing ONLY the fid, credentials_hash, uid, and cid makes it work. I’m pretty sure Rails is trying to be “nice” and provide me with addtional values for testing, but it seems to be causing problems.

Any recommendations on how to solve this?

  • 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-30T13:43:07+00:00Added an answer on May 30, 2026 at 1:43 pm

    Looks like you have set config.active_record.mass_assignment_sanitizer = :strict
    in your test environment only, but not in development or production, because params always contains controller and action, in any environment.

    I think the best-practice recommendation here is to always use form_for, so that you’d have your credentials in params[:credential], or, indeed, do params.slice(:fid, :uid, etc).

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

Sidebar

Related Questions

When running unit and functional tests using rake, on a rails application, I notice
I'm running CodeIgniter 2.0 and I have a test controller setup with this code
Hello friends i am running code given below which contains the setLogTimeEntery function and
I have generated some scaffolding for my rails app. I am running the generated
Our team is willing to unit-test a new code written under a running project
I have a CodeIgniter project, and I want to invoke one of my controller
I'm finding the feedback look pretty slow when running integration and functional tests in
I have a set of Test::Unit tests for a Rails application. It was developed
When running my functional tests, I'm getting the following warning in one of the
There doesn't seem to be many choices out there for running functional tests on

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.