1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

SelectCore deep copies attributes

This commit is contained in:
Mike Dalessio 2010-08-19 01:30:36 -04:00
parent 02ab2b37d7
commit 6b056ef108
2 changed files with 30 additions and 0 deletions

View file

@ -8,6 +8,13 @@ module Arel
@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

View file

@ -0,0 +1,23 @@
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