diff --git a/lib/her/model/attributes.rb b/lib/her/model/attributes.rb index edf1facb..68d7aa8e 100644 --- a/lib/her/model/attributes.rb +++ b/lib/her/model/attributes.rb @@ -51,7 +51,7 @@ def self.initialize_collection(klass, parsed_data={}) def self.use_setter_methods(model, params) params ||= {} - reserved_keys = [:id, model.class.primary_key] + model.class.association_keys + reserved_keys = [:id, :class, model.class.primary_key] + model.class.association_keys model.class.attributes *params.keys.reject { |k| reserved_keys.include?(k) || reserved_keys.map(&:to_s).include?(k) } setter_method_names = model.class.setter_method_names diff --git a/spec/model/attributes_spec.rb b/spec/model/attributes_spec.rb index 601795f1..5aad66ab 100644 --- a/spec/model/attributes_spec.rb +++ b/spec/model/attributes_spec.rb @@ -300,6 +300,12 @@ def document? user.fullname?.should be_truthy end + it "does not define a getter for @attributes matching reserved words" do + user = Foo::User.new + user.assign_attributes(class: 'klass') + expect(user.class.name).to eq("Foo::User") + end + context "when attribute methods are already defined" do before do class AbstractUser