aboutsummaryrefslogtreecommitdiffstats
path: root/test/nodes
diff options
context:
space:
mode:
authorRyan Davis <ryand-ruby@zenspider.com>2010-10-18 15:41:21 -0700
committerRyan Davis <ryand-ruby@zenspider.com>2010-10-18 15:41:21 -0700
commite1ebe6e949ef3674434bfa90d271a7b74c2ac153 (patch)
treeb0c340817d75bddf9840c97a946a7217ff12e8ab /test/nodes
parent7959e55ead84be096247d9622404d1c60ca21c88 (diff)
downloadrails-e1ebe6e949ef3674434bfa90d271a7b74c2ac153.tar.gz
rails-e1ebe6e949ef3674434bfa90d271a7b74c2ac153.tar.bz2
rails-e1ebe6e949ef3674434bfa90d271a7b74c2ac153.zip
Fisting arel specs -- still needs tree_manager and cleanup
Diffstat (limited to 'test/nodes')
-rw-r--r--test/nodes/test_count.rb18
-rw-r--r--test/nodes/test_delete_statement.rb14
-rw-r--r--test/nodes/test_equality.rb74
-rw-r--r--test/nodes/test_insert_statement.rb18
-rw-r--r--test/nodes/test_or.rb22
-rw-r--r--test/nodes/test_select_core.rb22
-rw-r--r--test/nodes/test_select_statement.rb13
-rw-r--r--test/nodes/test_sql_literal.rb28
-rw-r--r--test/nodes/test_sum.rb12
-rw-r--r--test/nodes/test_update_statement.rb18
10 files changed, 239 insertions, 0 deletions
diff --git a/test/nodes/test_count.rb b/test/nodes/test_count.rb
new file mode 100644
index 0000000000..d65df03313
--- /dev/null
+++ b/test/nodes/test_count.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').must_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.must_be_like %{
+ COUNT("users"."id") AS foo
+ }
+ end
+ end
+end
diff --git a/test/nodes/test_delete_statement.rb b/test/nodes/test_delete_statement.rb
new file mode 100644
index 0000000000..a71da7adae
--- /dev/null
+++ b/test/nodes/test_delete_statement.rb
@@ -0,0 +1,14 @@
+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]
+
+ dolly = statement.clone
+ dolly.wheres.must_equal statement.wheres
+ dolly.wheres.wont_be_same_as statement.wheres
+ end
+ end
+end
diff --git a/test/nodes/test_equality.rb b/test/nodes/test_equality.rb
new file mode 100644
index 0000000000..513cafd87f
--- /dev/null
+++ b/test/nodes/test_equality.rb
@@ -0,0 +1,74 @@
+require 'spec_helper'
+
+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.must_equal :==
+ end
+ end
+
+ describe 'operand1' do
+ it "should equal left" do
+ attr = Table.new(:users)[:id]
+ left = attr.eq(10)
+ check left.left.must_equal left.operand1
+ end
+ end
+
+ describe 'operand2' do
+ it "should equal right" do
+ attr = Table.new(:users)[:id]
+ left = attr.eq(10)
+ check left.right.must_equal left.operand2
+ end
+ end
+
+ describe 'to_sql' do
+ it 'takes an engine' do
+ engine = FakeRecord::Base.new
+ engine.connection.extend Module.new {
+ attr_accessor :quote_count
+ def quote(*args) @quote_count += 1; super; end
+ def quote_column_name(*args) @quote_count += 1; super; end
+ def quote_table_name(*args) @quote_count += 1; super; end
+ }
+ engine.connection.quote_count = 0
+
+ attr = Table.new(:users)[:id]
+ test = attr.eq(10)
+ test.to_sql engine
+ check engine.connection.quote_count.must_equal 2
+ 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.must_equal left
+ check node.expr.right.must_equal 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.must_equal left
+ check node.right.must_equal right
+ end
+ end
+ end
+ end
+end
diff --git a/test/nodes/test_insert_statement.rb b/test/nodes/test_insert_statement.rb
new file mode 100644
index 0000000000..47f3c27dee
--- /dev/null
+++ b/test/nodes/test_insert_statement.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]
+
+ dolly = statement.clone
+ dolly.columns.must_equal statement.columns
+ dolly.values.must_equal statement.values
+
+ dolly.columns.wont_be_same_as statement.columns
+ dolly.values.wont_be_same_as statement.values
+ end
+ end
+end
diff --git a/test/nodes/test_or.rb b/test/nodes/test_or.rb
new file mode 100644
index 0000000000..354d803110
--- /dev/null
+++ b/test/nodes/test_or.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+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.must_equal left
+ check node.expr.right.must_equal right
+
+ oror = node.or(right)
+ check oror.expr.left.must_equal node
+ check oror.expr.right.must_equal right
+ end
+ end
+ end
+ end
+end
diff --git a/test/nodes/test_select_core.rb b/test/nodes/test_select_core.rb
new file mode 100644
index 0000000000..0aacf41720
--- /dev/null
+++ b/test/nodes/test_select_core.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe Arel::Nodes::SelectCore do
+ describe "#clone" do
+ it "clones froms, projections and wheres" do
+ core = Arel::Nodes::SelectCore.new
+ core.froms = %w[a b c]
+ core.projections = %w[d e f]
+ core.wheres = %w[g h i]
+
+ dolly = core.clone
+
+ dolly.froms.must_equal core.froms
+ dolly.projections.must_equal core.projections
+ dolly.wheres.must_equal core.wheres
+
+ dolly.froms.wont_be_same_as core.froms
+ dolly.projections.wont_be_same_as core.projections
+ dolly.wheres.wont_be_same_as core.wheres
+ end
+ end
+end
diff --git a/test/nodes/test_select_statement.rb b/test/nodes/test_select_statement.rb
new file mode 100644
index 0000000000..45613bfa4d
--- /dev/null
+++ b/test/nodes/test_select_statement.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+
+describe Arel::Nodes::SelectStatement do
+ describe "#clone" do
+ it "clones cores" do
+ statement = Arel::Nodes::SelectStatement.new %w[a b c]
+
+ dolly = statement.clone
+ dolly.cores.must_equal statement.cores
+ dolly.cores.wont_be_same_as statement.cores
+ end
+ end
+end
diff --git a/test/nodes/test_sql_literal.rb b/test/nodes/test_sql_literal.rb
new file mode 100644
index 0000000000..3aeab41f0c
--- /dev/null
+++ b/test/nodes/test_sql_literal.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+module Arel
+ module Nodes
+ describe 'sql literal' do
+ describe 'sql' do
+ it 'makes a sql literal node' do
+ sql = Arel.sql 'foo'
+ sql.must_be_kind_of Arel::Nodes::SqlLiteral
+ end
+ end
+
+ describe 'count' do
+ it 'makes a count node' do
+ node = SqlLiteral.new('*').count
+ viz = Visitors::ToSql.new Table.engine
+ viz.accept(node).must_be_like %{ COUNT(*) }
+ end
+
+ it 'makes a distinct node' do
+ node = SqlLiteral.new('*').count true
+ viz = Visitors::ToSql.new Table.engine
+ viz.accept(node).must_be_like %{ COUNT(DISTINCT *) }
+ end
+ end
+ end
+ end
+end
diff --git a/test/nodes/test_sum.rb b/test/nodes/test_sum.rb
new file mode 100644
index 0000000000..e6a57e4dd6
--- /dev/null
+++ b/test/nodes/test_sum.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.must_be_like %{
+ SUM("users"."id") AS foo
+ }
+ end
+ end
+end
diff --git a/test/nodes/test_update_statement.rb b/test/nodes/test_update_statement.rb
new file mode 100644
index 0000000000..88c147b268
--- /dev/null
+++ b/test/nodes/test_update_statement.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]
+
+ dolly = statement.clone
+ dolly.wheres.must_equal statement.wheres
+ dolly.wheres.wont_be_same_as statement.wheres
+
+ dolly.values.must_equal statement.values
+ dolly.values.wont_be_same_as statement.values
+ end
+ end
+end