Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frozen model still allows attribute changes #198

Open
kaorukobo opened this issue Mar 13, 2024 · 0 comments
Open

Frozen model still allows attribute changes #198

kaorukobo opened this issue Mar 13, 2024 · 0 comments

Comments

@kaorukobo
Copy link

kaorukobo commented Mar 13, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant