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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:38:43+00:00 2026-06-01T13:38:43+00:00

I am creating a Rails application with TDD using rspec. I am getting an

  • 0

I am creating a Rails application with TDD using rspec. I am getting an error I can’t remove :

Failure/Error: invalid_user = User.new(@attr.merge("provider" => ""))
 ActiveModel::MassAssignmentSecurity::Error:
   Can't mass-assign protected attributes: uid, info

Here is my user spec :

user_spec.rb

require 'spec_helper'

describe User do
  before(:each) do
  @attr = {"provider" => "providerexample", "uid" => "uidexample", "info" => {"name" =>     "Example"}}
 end

it "should create a new instance given valid attributes" do
  user = User.create_with_omniauth(@attr)
end

it "should require a provider" do
  invalid_user = User.new(@attr.merge("provider" => ""))
  invalid_user.should_not be_valid
end 

it "should require a uid" do
  invalid_user = User.new(@attr.merge("uid" => ""))
  invalid_user.should_not be_valid
end
end

And my user.rb

class User < ActiveRecord::Base
  attr_accessible :name, :credits, :email, :provider

  validates :name, :provider, :uid, :presence => true

  def self.create_with_omniauth(auth)
    create! do |user|
    user.provider = auth["provider"]
    user.uid      = auth["uid"]
    user.name     = auth["info"]["name"]
  end
 end

end

If I debug the mass-assign error by adding uid and info to the attr_accessible, I still get the following error unknown attribute: info.

  • 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-06-01T13:38:45+00:00Added an answer on June 1, 2026 at 1:38 pm

    If you merge what you had as @attr with info, then it’ll exist for the create_with_omniauth call, but not the regular create methods.

    describe User do
      let(:user_attributes) { {"provider" => "providerexample", "uid" => "uidexample"} }
    
      it "should create a new instance given valid attributes" do
        expect {
          User.create_with_omniauth(user_attributes.merge({"info" => {"name" => "example"}))
        }.to not_raise_error
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i m getting this error when i m creating application in rails i type
I am creating a Rails application, which rather than using a database for the
I've just begun creating a rails application using mongomapper for my models. I'm wondering
I'm creating a new web application (Rails 3 beta), of which pieces of it
I'm creating a new plugin for a jruby on rails application that will eventually
I'm using devise in my rails 3.2 application. I have a users/new page where
When creating a new Rails application, it is automatically supplied with several quite large
I'm currently creating rspec test cases for a Rails 2.3 application. The problem I'm
We are starting to develop a new website using Rails 3, RSpec 2, and
I am creating a rails application with geographical locations using spatial_adapter and GeoRuby. When

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.