lib/neo4j/active_node/validations.rb in neo4j-3.0.0.rc.5 vs lib/neo4j/active_node/validations.rb in neo4j-3.0.0
- old
+ new
@@ -29,22 +29,15 @@
conditions = scope_conditions(record)
# TODO: Added as find(:name => nil) throws error
value = "" if value == nil
- if options[:case_sensitive]
- conditions[attribute] = value
- else
- conditions[attribute] = /^#{Regexp.escape(value.to_s)}$/i
- end
+ conditions[attribute] = options[:case_sensitive] ? value : /^#{Regexp.escape(value.to_s)}$/i
# prevent that same object is returned
# TODO: add negative condtion to not return current record
found = record.class.where(conditions).to_a.select{|f| f.neo_id != record.neo_id}
-
- if found.count > 0
- record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
- end
+ record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value)) if found.count > 0
end
def message(instance)
super || "has already been taken"
end