Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Query::OPTIONS should be included in the list of invalid property names

  • Loading branch information...
commit ea8d92b48af431a3197a8d589730e0f638709cad 1 parent 89fc6ec
@solnic solnic authored
Showing with 15 additions and 4 deletions.
  1. +8 −3 lib/dm-core/property.rb
  2. +7 −1 spec/public/model/property_spec.rb
View
11 lib/dm-core/property.rb
@@ -1,3 +1,6 @@
+require 'dm-core/resource'
+require 'dm-core/query'
+
module DataMapper
# = Properties
# Properties for a model are not derived from a database structure, but
@@ -370,6 +373,9 @@ def dump(value)
# Possible :visibility option values
VISIBILITY_OPTIONS = [ :public, :protected, :private ].to_set.freeze
+ # Invalid property names
+ INVALID_NAMES = (Resource.instance_methods + Resource.private_instance_methods + Query::OPTIONS.to_a).map { |name| name.to_s }.freeze
+
attr_reader :primitive, :model, :name, :instance_variable_name,
:type, :reader_visibility, :writer_visibility, :options,
:default, :repository_name, :allow_nil, :allow_blank, :required
@@ -793,9 +799,8 @@ def initialize(model, name, options = {}, type = nil)
@type = type
end
- reserved_method_names = DataMapper::Resource.instance_methods + DataMapper::Resource.private_instance_methods
- if reserved_method_names.map { |m| m.to_s }.include?(name.to_s)
- raise ArgumentError, "+name+ was #{name.inspect}, which cannot be used as a property name since it collides with an existing method"
+ if INVALID_NAMES.include?(name.to_s)
+ raise ArgumentError, "+name+ was #{name.inspect}, which cannot be used as a property name since it collides with an existing method or a query option"
end
assert_valid_options(options)
View
8 spec/public/model/property_spec.rb
@@ -30,7 +30,13 @@ class ::ModelPropertySpecs
it 'should raise an exception if the method exists' do
lambda {
ModelPropertySpecs.property(:key, String)
- }.should raise_error(ArgumentError, '+name+ was :key, which cannot be used as a property name since it collides with an existing method')
+ }.should raise_error(ArgumentError, '+name+ was :key, which cannot be used as a property name since it collides with an existing method or a query option')
+ end
+
+ it 'should raise an exception if the name is the same as one of the query options' do
+ lambda {
+ ModelPropertySpecs.property(:order, String)
+ }.should raise_error(ArgumentError, '+name+ was :order, which cannot be used as a property name since it collides with an existing method or a query option')
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.