Flowdock
method

attr_readonly

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

Attributes listed as readonly can be set for a new record, but will be ignored in database updates afterwards.

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