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

Add "class" to reserved words when creating attribute getters/setters #372

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/her/model/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/model/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down