diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 15:21:54 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-24 15:21:54 -0700 |
commit | 6b86ae4f9f2fb8cd145f958753fedf16aae3a0d4 (patch) | |
tree | fff66461830df50e3211d8ced131584e6d75f9d4 /spec/nodes | |
parent | 245d797a8ccab3ed2de9a0eedf455d3094a091ce (diff) | |
download | rails-6b86ae4f9f2fb8cd145f958753fedf16aae3a0d4.tar.gz rails-6b86ae4f9f2fb8cd145f958753fedf16aae3a0d4.tar.bz2 rails-6b86ae4f9f2fb8cd145f958753fedf16aae3a0d4.zip |
shuffling around the spec directory
Diffstat (limited to 'spec/nodes')
-rw-r--r-- | spec/nodes/count_spec.rb | 18 | ||||
-rw-r--r-- | spec/nodes/delete_statement_spec.rb | 15 | ||||
-rw-r--r-- | spec/nodes/equality_spec.rb | 54 | ||||
-rw-r--r-- | spec/nodes/insert_statement_spec.rb | 18 | ||||
-rw-r--r-- | spec/nodes/or_spec.rb | 20 | ||||
-rw-r--r-- | spec/nodes/select_core_spec.rb | 21 | ||||
-rw-r--r-- | spec/nodes/select_statement_spec.rb | 14 | ||||
-rw-r--r-- | spec/nodes/sql_literal_spec.rb | 19 | ||||
-rw-r--r-- | spec/nodes/sum_spec.rb | 12 | ||||
-rw-r--r-- | spec/nodes/update_statement_spec.rb | 18 |
10 files changed, 209 insertions, 0 deletions
diff --git a/spec/nodes/count_spec.rb b/spec/nodes/count_spec.rb new file mode 100644 index 0000000000..185b4d8eb9 --- /dev/null +++ b/spec/nodes/count_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Arel::Nodes::Count do + describe 'backwards compatibility' do + it 'must be an expression' do + Arel::Nodes::Count.new('foo').should be_kind_of Arel::Expression + end + end + + describe "as" do + it 'should alias the count' do + table = Arel::Table.new :users + table[:id].count.as('foo').to_sql.should be_like %{ + COUNT("users"."id") AS foo + } + end + end +end diff --git a/spec/nodes/delete_statement_spec.rb b/spec/nodes/delete_statement_spec.rb new file mode 100644 index 0000000000..4d12d184fb --- /dev/null +++ b/spec/nodes/delete_statement_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe Arel::Nodes::DeleteStatement do + describe "#clone" do + it "clones wheres" do + statement = Arel::Nodes::DeleteStatement.new + statement.wheres = %w[a b c] + + statement.wheres.should_receive(:clone).and_return([:wheres]) + + dolly = statement.clone + dolly.wheres.should == [:wheres] + end + end +end diff --git a/spec/nodes/equality_spec.rb b/spec/nodes/equality_spec.rb new file mode 100644 index 0000000000..81eea4d482 --- /dev/null +++ b/spec/nodes/equality_spec.rb @@ -0,0 +1,54 @@ +module Arel + module Nodes + describe 'equality' do + # FIXME: backwards compat + describe 'backwards compat' do + describe 'operator' do + it 'returns :==' do + attr = Table.new(:users)[:id] + left = attr.eq(10) + check left.operator.should == :== + end + end + + describe 'operand1' do + it "should equal left" do + attr = Table.new(:users)[:id] + left = attr.eq(10) + check left.left.should == left.operand1 + end + end + + describe 'operand2' do + it "should equal right" do + attr = Table.new(:users)[:id] + left = attr.eq(10) + check left.right.should == left.operand2 + end + end + end + + describe 'or' do + it 'makes an OR node' do + attr = Table.new(:users)[:id] + left = attr.eq(10) + right = attr.eq(11) + node = left.or right + check node.expr.left.should == left + check node.expr.right.should == right + end + end + + describe 'and' do + it 'makes and AND node' do + attr = Table.new(:users)[:id] + left = attr.eq(10) + right = attr.eq(11) + node = left.and right + check node.left.should == left + check node.right.should == right + end + end + end + end +end diff --git a/spec/nodes/insert_statement_spec.rb b/spec/nodes/insert_statement_spec.rb new file mode 100644 index 0000000000..0e2432c021 --- /dev/null +++ b/spec/nodes/insert_statement_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Arel::Nodes::InsertStatement 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] + + statement.columns.should_receive(:clone).and_return([:columns]) + statement.values.should_receive(:clone).and_return([:values]) + + dolly = statement.clone + check dolly.columns.should == [:columns] + check dolly.values.should == [:values] + end + end +end diff --git a/spec/nodes/or_spec.rb b/spec/nodes/or_spec.rb new file mode 100644 index 0000000000..88484ff4f7 --- /dev/null +++ b/spec/nodes/or_spec.rb @@ -0,0 +1,20 @@ +module Arel + module Nodes + describe 'or' do + describe '#or' do + it 'makes an OR node' do + attr = Table.new(:users)[:id] + left = attr.eq(10) + right = attr.eq(11) + node = left.or right + check node.expr.left.should == left + check node.expr.right.should == right + + oror = node.or(right) + check oror.expr.left == node + check oror.expr.right == right + end + end + end + end +end diff --git a/spec/nodes/select_core_spec.rb b/spec/nodes/select_core_spec.rb new file mode 100644 index 0000000000..d2e87c2c23 --- /dev/null +++ b/spec/nodes/select_core_spec.rb @@ -0,0 +1,21 @@ +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).should_receive(:clone).and_return([array_attr]) + end + + dolly = core.clone + check dolly.froms.should == [:froms] + check dolly.projections.should == [:projections] + check dolly.wheres.should == [:wheres] + end + end +end diff --git a/spec/nodes/select_statement_spec.rb b/spec/nodes/select_statement_spec.rb new file mode 100644 index 0000000000..68bde3c4f7 --- /dev/null +++ b/spec/nodes/select_statement_spec.rb @@ -0,0 +1,14 @@ +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.map { |x| x.should_receive(:clone).and_return(:f) } + + dolly = statement.clone + dolly.cores.should == [:f, :f, :f] + end + end +end diff --git a/spec/nodes/sql_literal_spec.rb b/spec/nodes/sql_literal_spec.rb new file mode 100644 index 0000000000..390eb708e1 --- /dev/null +++ b/spec/nodes/sql_literal_spec.rb @@ -0,0 +1,19 @@ +module Arel + module Nodes + describe 'sql literal' do + describe 'count' do + it 'makes a count node' do + node = SqlLiteral.new('*').count + viz = Visitors::ToSql.new Table.engine + viz.accept(node).should be_like %{ COUNT(*) } + end + + it 'makes a distinct node' do + node = SqlLiteral.new('*').count true + viz = Visitors::ToSql.new Table.engine + viz.accept(node).should be_like %{ COUNT(DISTINCT *) } + end + end + end + end +end diff --git a/spec/nodes/sum_spec.rb b/spec/nodes/sum_spec.rb new file mode 100644 index 0000000000..7691b06590 --- /dev/null +++ b/spec/nodes/sum_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Arel::Nodes::Sum do + describe "as" do + it 'should alias the sum' do + table = Arel::Table.new :users + table[:id].sum.as('foo').to_sql.should be_like %{ + SUM("users"."id") AS foo + } + end + end +end diff --git a/spec/nodes/update_statement_spec.rb b/spec/nodes/update_statement_spec.rb new file mode 100644 index 0000000000..860d1c448a --- /dev/null +++ b/spec/nodes/update_statement_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe Arel::Nodes::UpdateStatement 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] + + statement.wheres.should_receive(:clone).and_return([:wheres]) + statement.values.should_receive(:clone).and_return([:values]) + + dolly = statement.clone + check dolly.wheres.should == [:wheres] + check dolly.values.should == [:values] + end + end +end |