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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:54:01+00:00 2026-06-16T00:54:01+00:00

I have the following simplified model: class User attr_accessible :password validates :password, :presence =>

  • 0

I have the following simplified model:

class User
  attr_accessible :password
  validates :password, :presence => true
  validates_confirmation_of :password, :length => { :minimum => 4 }
end

That’s pretty straight forward. I’m testing it with RSpec/FactoryGirl, and have the following tests:

it "cannot create with password < 4 characters" do
  expect{ model = FactoryGirl.create(:user, :password => "12", :password_confirmation => "12") }.to raise_error
end

it "cannot update to password < 4 characters" do
  model = FactoryGirl.create(:user)
  model.should be_valid
  model.update_attributes({:password => "12", :password_confirmation => "12"})
  model.reload
  model.password.should_not eq("12")
end

However, the second test fails. For some reason, “12” seems to be able to be saved into the database as a valid password. Why? The API states that update_attributes should not bypass any of the validations!

  • 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-16T00:54:02+00:00Added an answer on June 16, 2026 at 12:54 am

    I don’t think it is skipping validations.

    I suspect this:

    model.update_attributes({:password => "12", :password_confirmation => "12"})
    

    is returning false. Password is probably not a column in your database, rather you probably have crypted_password and password_salt so reloading it does not read the password from the database (this would be bad)

    Also, you probably want :

    attr_accessible :password, :password_confirmation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following (simplified) model and migration: Model: class User < ActiveRecord::Base attr_readonly
I have the following User model on my application (simplified) class User < ActiveRecord::Base
I have the following - simplified - models: class User(models.Model): following = models.ManyToManyField(self, through='Following',
Lets say we have the following models: (simplified) class Collection(models.Model): slug = models.SlugField() class
I have the following model class (simplified) class A{ private String name; private List<B>
I have the following (heavily simplified) model, that uses will_paginate class Search < ActiveRecord::Base
I have the following model (greatly simplified for the purposes of this question): class
I have the following (simplified) models: class School(models.Model): name = models.CharField(max_length=128) class UserProfile(models.Model): school
I have the following model (simplified): abstract class CartItem { EntityReference<Cart> Cart; } class
I have the following model in rails (simplified): class Phone < ActiveRecord::Base include ActiveModel::Validations

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.