New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_attribute violates POLA #14357

Closed
khacanh opened this Issue Mar 12, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@khacanh

khacanh commented Mar 12, 2014

POLA http://en.wikipedia.org/wiki/Principle_of_least_astonishment

Examples

# user.rb
class User < ActiveRecord::Base
  attr_accessible :name, :username
  validates :username, uniqueness: true
end

user1 = User.create(name: 'Name 1', username: 'username1')
user2 = User.create(name: 'Name 2', username: 'username2')

user1.username = 'username2'
user1.save # => false
user1.update_attribute(name: 'New Name')
user1.reload

user1.username # => 'username2'
# update_attribute is expected to update the specified attribute, not other ones. Thus it is violating POLA
@arunagw

This comment has been minimized.

Show comment
Hide comment
@arunagw

arunagw Mar 12, 2014

Member

Hey @khacanh thanks for mentioning this. Can you please post this to rubyonrails-core google groups?

This issue tracker is mostly to track bugs.

thanks. Closing this now.

Member

arunagw commented Mar 12, 2014

Hey @khacanh thanks for mentioning this. Can you please post this to rubyonrails-core google groups?

This issue tracker is mostly to track bugs.

thanks. Closing this now.

@arunagw arunagw closed this Mar 12, 2014

@khacanh

This comment has been minimized.

Show comment
Hide comment
@khacanh

khacanh Mar 12, 2014

Ok, copying over...

khacanh commented Mar 12, 2014

Ok, copying over...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment