Summary
The model including ActiveAttr::Model should reject attribute changes by throwing FrozenError after#freeze is called.
Reproduction
require "bundler/inline"
gemfile(true) do
gem "active_attr", git: "https://github.com/cgriego/active_attr.git"
gem "rspec"
end
require "rspec/autorun"
class Foo
include ActiveAttr::Model
attribute :qux
end
RSpec.describe do
it "raises FrozenError" do
foo = Foo.new.freeze
expect {
foo.qux = "grault" # ==> does not throw FrozenError!
}.to raise_error(FrozenError)
end
end
Behavior of ActiveModel::Model
ActiveModel::Model does not allow attribute changes.
I think it is an ideal behavior.
require "bundler/inline"
gemfile(true) do
gem "activemodel"
gem "rspec"
end
require "rspec/autorun"
require "active_model"
class Foo
include ActiveModel::Model
attr_accessor :qux
end
RSpec.describe do
it "raises FrozenError" do
foo = Foo.new.freeze
expect {
foo.qux = "grault"
}.to raise_error(FrozenError)
end
end
Summary
The model including
ActiveAttr::Modelshould reject attribute changes by throwing FrozenError after#freezeis called.Reproduction
Behavior of
ActiveModel::ModelActiveModel::Modeldoes not allow attribute changes.I think it is an ideal behavior.