From 02ab2b37d7fdd823cf3aaac66052437dde36daa3 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 16 Aug 2010 23:59:18 -0400 Subject: Statement nodes deep-copy AST nodes --- spec/arel/nodes/insert_statement_spec.rb | 22 ++++++++++++++++++++++ spec/arel/nodes/select_statement_spec.rb | 16 ++++++++++++++++ spec/arel/nodes/update_statement_spec.rb | 22 ++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 spec/arel/nodes/insert_statement_spec.rb create mode 100644 spec/arel/nodes/select_statement_spec.rb create mode 100644 spec/arel/nodes/update_statement_spec.rb (limited to 'spec/arel/nodes') diff --git a/spec/arel/nodes/insert_statement_spec.rb b/spec/arel/nodes/insert_statement_spec.rb new file mode 100644 index 0000000000..d8b02b6703 --- /dev/null +++ b/spec/arel/nodes/insert_statement_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe Arel::Nodes::InsertStatement do + describe "clone" do + it "clones cores" do + statement = Arel::Nodes::InsertStatement.new + statement.columns = %w[a b c] + statement.values = %w[x y z] + + statement.columns.each_with_index do |o, j| + o.should_receive(:clone).and_return("#{o}#{j}") + end + statement.values.each_with_index do |o, j| + o.should_receive(:clone).and_return("#{o}#{j}") + end + + dolly = statement.clone + dolly.columns.should == %w[a0 b1 c2] + dolly.values.should == %w[x0 y1 z2] + end + end +end diff --git a/spec/arel/nodes/select_statement_spec.rb b/spec/arel/nodes/select_statement_spec.rb new file mode 100644 index 0000000000..04b850823c --- /dev/null +++ b/spec/arel/nodes/select_statement_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe Arel::Nodes::SelectStatement do + describe "clone" do + it "clones cores" do + statement = Arel::Nodes::SelectStatement.new %w[a b c] + + statement.cores.each_with_index do |o, j| + o.should_receive(:clone).and_return("#{o}#{j}") + end + + dolly = statement.clone + dolly.cores.should == %w[a0 b1 c2] + end + end +end diff --git a/spec/arel/nodes/update_statement_spec.rb b/spec/arel/nodes/update_statement_spec.rb new file mode 100644 index 0000000000..438eaf1dc2 --- /dev/null +++ b/spec/arel/nodes/update_statement_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe Arel::Nodes::UpdateStatement do + describe "clone" do + it "clones cores" do + statement = Arel::Nodes::UpdateStatement.new + statement.wheres = %w[a b c] + statement.values = %w[x y z] + + statement.wheres.each_with_index do |o, j| + o.should_receive(:clone).and_return("#{o}#{j}") + end + statement.values.each_with_index do |o, j| + o.should_receive(:clone).and_return("#{o}#{j}") + end + + dolly = statement.clone + dolly.wheres.should == %w[a0 b1 c2] + dolly.values.should == %w[x0 y1 z2] + end + end +end -- cgit v1.2.3 From 6b056ef108526de90f9537e2a5f663a9a2b33409 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 19 Aug 2010 01:30:36 -0400 Subject: SelectCore deep copies attributes --- spec/arel/nodes/select_core_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/arel/nodes/select_core_spec.rb (limited to 'spec/arel/nodes') diff --git a/spec/arel/nodes/select_core_spec.rb b/spec/arel/nodes/select_core_spec.rb new file mode 100644 index 0000000000..cf717a3904 --- /dev/null +++ b/spec/arel/nodes/select_core_spec.rb @@ -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 -- cgit v1.2.3 From 91fe0cd99cc9c8aa9e73ebd51ae478f80076ecea Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 19 Aug 2010 01:30:21 -0400 Subject: cleaning up describe/it block names --- spec/arel/nodes/insert_statement_spec.rb | 4 ++-- spec/arel/nodes/select_statement_spec.rb | 2 +- spec/arel/nodes/update_statement_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/arel/nodes') diff --git a/spec/arel/nodes/insert_statement_spec.rb b/spec/arel/nodes/insert_statement_spec.rb index d8b02b6703..644e3fb192 100644 --- a/spec/arel/nodes/insert_statement_spec.rb +++ b/spec/arel/nodes/insert_statement_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe Arel::Nodes::InsertStatement do - describe "clone" do - it "clones cores" do + describe "#clone" do + it "clones columns and values" do statement = Arel::Nodes::InsertStatement.new statement.columns = %w[a b c] statement.values = %w[x y z] diff --git a/spec/arel/nodes/select_statement_spec.rb b/spec/arel/nodes/select_statement_spec.rb index 04b850823c..a024710c78 100644 --- a/spec/arel/nodes/select_statement_spec.rb +++ b/spec/arel/nodes/select_statement_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Arel::Nodes::SelectStatement do - describe "clone" do + describe "#clone" do it "clones cores" do statement = Arel::Nodes::SelectStatement.new %w[a b c] diff --git a/spec/arel/nodes/update_statement_spec.rb b/spec/arel/nodes/update_statement_spec.rb index 438eaf1dc2..8cbca1fd73 100644 --- a/spec/arel/nodes/update_statement_spec.rb +++ b/spec/arel/nodes/update_statement_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe Arel::Nodes::UpdateStatement do - describe "clone" do - it "clones cores" do + describe "#clone" do + it "clones wheres and values" do statement = Arel::Nodes::UpdateStatement.new statement.wheres = %w[a b c] statement.values = %w[x y z] -- cgit v1.2.3 From 06c92a8557f5171704a121d0f4412e4c1e9a9c2b Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 19 Aug 2010 02:00:28 -0400 Subject: DeleteStatement deep copy --- spec/arel/nodes/delete_statement_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 spec/arel/nodes/delete_statement_spec.rb (limited to 'spec/arel/nodes') diff --git a/spec/arel/nodes/delete_statement_spec.rb b/spec/arel/nodes/delete_statement_spec.rb new file mode 100644 index 0000000000..dd43b70d35 --- /dev/null +++ b/spec/arel/nodes/delete_statement_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Arel::Nodes::SelectStatement do + describe "#clone" do + it "clones where" do + statement = Arel::Nodes::DeleteStatement.new + statement.wheres = %w[a b c] + + statement.wheres.each_with_index do |o, j| + o.should_receive(:clone).and_return("#{o}#{j}") + end + + dolly = statement.clone + dolly.wheres.should == %w[a0 b1 c2] + end + end +end -- cgit v1.2.3