method
attr_readonly
v3.1.0 -
Show latest stable
- 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.
1Note
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