Skip to content

Frozen model still allows attribute changes #198

Description

@kaorukobo

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions