method

attr_readonly

Importance_1
v3.0.0 - Show latest stable - 1 note - Class: ActiveRecord::Base
attr_readonly(*attributes) public

Attributes listed as readonly will be used to create a new record but update operations will ignore these fields.

Show source
Register or log in to add new notes.
August 5, 2011
0 thanks

Speccing read_only requirements

To test if an attribute is defined readonly:

class MyModel < ActiveRecord::Base
  attr_readonly :important_type_thingie
end

#RSpec
describe MyModel do
 its('class.readonly_attributes') { should include "important_type_thingie" }

 it "should not update the thingie" do
   m = create :my_model, :important_type_thingie => 'foo'
   m.update_attributes :important_type_thingie => 'bar'
   m.reload.important_type_thingie.should eql 'foo'
 end
end