Permalink
Browse files

Stop mutating And nodes with & and -

Fixes #251
  • Loading branch information...
1 parent c04fc12 commit 616ec03d89f93c49acd68d7d0bbf4aab4985d1e3 @ernie ernie committed Jul 14, 2013
Showing with 10 additions and 11 deletions.
  1. +2 −1 CHANGELOG.md
  2. +4 −6 lib/squeel/nodes/nary.rb
  3. +4 −4 spec/squeel/nodes/predicate_operators_spec.rb
View
@@ -1,10 +1,11 @@
-## 1.1.0 (unreleased)
+## 1.1.0 (2013-07-14)
* Support for Active Record 4.0.0!
* Deprecated core extensions. In Squeel 2.0, the DSL will be the way to
construct queries, and Symbol/Hash extensions will go away.
* Prefix generated sifter methods with `sifter_` so as not to interfere with
similarly-named scopes.
+* No longer mutate And nodes when using `&` and `-` on the node
## 1.0.18 (2013-03-07)
View
@@ -17,20 +17,18 @@ def initialize(children)
@children = children
end
- # Add a new child to the node's children
+ # Returns a new Nary node, with an additional child.
# @param other A new child node
# @return [Nary] This node, with its updated children.
def &(other)
- @children << other
- self
+ self.class.new(@children + [other])
end
- # Append a new Not node to this node's children
+ # Returns a new Nary node, with an additional (negated) child.
# @param other A new child node
# @return [Nary] This node, with its new, negated child
def -(other)
- @children << Not.new(other)
- self
+ self.class.new(@children + [Not.new(other)])
end
# Implemented for equality testing
@@ -21,13 +21,13 @@ module Nodes
n.children.should eq [left, right]
end
- it 'appends nodes to children from other And nodes' do
+ it 'creates And nodes by appending a new child' do
left = :name.matches % 'J%' & :name.matches % '%e'
right = :id.gt % 0
expected = left.children + [right]
- left & right
- left.should be_a And
- left.children.should eq expected
+ new_and = left & right
+ new_and.should be_a And
+ new_and.children.should eq expected
end
end

0 comments on commit 616ec03

Please sign in to comment.