Skip to content

Commit

Permalink
instance variable
Browse files Browse the repository at this point in the history
  • Loading branch information
artofhuman committed Sep 16, 2023
1 parent 4a3dbdb commit 840e72c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/sequel/model/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class MassAssignmentRestriction < Error
attr_reader :model

def self.create(msg, model)
@model = model
msg += " for class #{model.class.name}" if model.class.name
new(msg)
new(msg).tap do |err|
err.instance_variable_set(:@model, model)
end
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/model/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ def self.name; 'Item' end

err = proc{item.new(:a=>1)}.must_raise(Sequel::MassAssignmentRestriction)
err.message.must_equal("method a= doesn't exist for class Item")
err.model.class.must_equal(item)
end

it "should be disabled by strict_param_setting = false" do
Expand Down
15 changes: 15 additions & 0 deletions spec/model/exceptions_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative "spec_helper"

describe Sequel::MassAssignmentRestriction, "#create" do
it "should sets model attr" do
model_cls = Class.new
model_cls.class_eval do
def self.name; 'TestModel' end
end

model = model_cls.new
err = Sequel::MassAssignmentRestriction.create("method foo doesn't exist", model)
err.message.must_equal("method foo doesn't exist for class TestModel")
err.model.must_equal(model)
end
end

0 comments on commit 840e72c

Please sign in to comment.