提交 6b056ef1 编写于 作者: M Mike Dalessio

SelectCore deep copies attributes

上级 02ab2b37
......@@ -8,6 +8,13 @@ def initialize
@projections = []
@wheres = []
end
def initialize_copy other
super
@froms = @froms.map { |o| o.clone }
@projections = @projections.map { |o| o.clone }
@wheres = @wheres.map { |o| o.clone }
end
end
end
end
require 'spec_helper'
describe Arel::Nodes::SelectCore do
describe "#clone" do
it "clones froms, projections and wheres" do
core = Arel::Nodes::SelectCore.new
core.instance_variable_set "@froms", %w[a b c]
core.instance_variable_set "@projections", %w[d e f]
core.instance_variable_set "@wheres", %w[g h i]
[:froms, :projections, :wheres].each do |array_attr|
core.send(array_attr).each_with_index do |o, j|
o.should_receive(:clone).and_return("#{o}#{j}")
end
end
dolly = core.clone
dolly.froms.should == %w[a0 b1 c2]
dolly.projections.should == %w[d0 e1 f2]
dolly.wheres.should == %w[g0 h1 i2]
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册