Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fisting arel specs -- still needs tree_manager and cleanup

  • Loading branch information...
commit e1ebe6e949ef3674434bfa90d271a7b74c2ac153 1 parent 7959e55
@zenspider zenspider authored
Showing with 6,108 additions and 404 deletions.
  1. +26 −0 .autotest
  2. +5 −1 Rakefile
  3. +5,725 −0 TAGS
  4. +1 −5 lib/arel/table.rb
  5. +0 −21 spec/nodes/select_core_spec.rb
  6. +0 −3  spec/spec.opts
  7. +0 −18 spec/spec_helper.rb
  8. +0 −6 spec/support/check.rb
  9. +0 −1  spec/support/matchers.rb
  10. +0 −24 spec/support/matchers/be_like.rb
  11. +83 −83 spec/attributes/attribute_spec.rb → test/attributes/test_attribute.rb
  12. +2 −2 spec/nodes/count_spec.rb → test/nodes/test_count.rb
  13. +2 −3 spec/nodes/delete_statement_spec.rb → test/nodes/test_delete_statement.rb
  14. +10 −8 spec/nodes/equality_spec.rb → test/nodes/test_equality.rb
  15. +5 −5 spec/nodes/insert_statement_spec.rb → test/nodes/test_insert_statement.rb
  16. +6 −4 spec/nodes/or_spec.rb → test/nodes/test_or.rb
  17. +22 −0 test/nodes/test_select_core.rb
  18. +2 −3 spec/nodes/select_statement_spec.rb → test/nodes/test_select_statement.rb
  19. +5 −3 spec/nodes/sql_literal_spec.rb → test/nodes/test_sql_literal.rb
  20. +1 −1  spec/nodes/sum_spec.rb → test/nodes/test_sum.rb
  21. +5 −5 spec/nodes/update_statement_spec.rb → test/nodes/test_update_statement.rb
  22. +21 −0 test/spec_helper.rb
  23. 0  {spec → test}/support/fake_record.rb
  24. +1 −1  spec/activerecord_compat_spec.rb → test/test_activerecord_compat.rb
  25. +6 −6 spec/attributes_spec.rb → test/test_attributes.rb
  26. +3 −3 spec/crud_spec.rb → test/test_crud.rb
  27. +15 −14 spec/delete_manager_spec.rb → test/test_delete_manager.rb
  28. +22 −23 spec/insert_manager_spec.rb → test/test_insert_manager.rb
  29. +65 −65 spec/select_manager_spec.rb → test/test_select_manager.rb
  30. +31 −53 spec/table_spec.rb → test/test_table.rb
  31. +20 −19 spec/update_manager_spec.rb → test/test_update_manager.rb
  32. +2 −2 spec/visitors/join_sql_spec.rb → test/visitors/test_join_sql.rb
  33. +9 −9 spec/visitors/oracle_spec.rb → test/visitors/test_oracle.rb
  34. +1 −1  spec/visitors/postgres_spec.rb → test/visitors/test_postgres.rb
  35. +12 −12 spec/visitors/to_sql_spec.rb → test/visitors/test_to_sql.rb
View
26 .autotest
@@ -0,0 +1,26 @@
+# -*- ruby -*-
+
+# require 'autotest/restart'
+
+ENV['GEM_PATH'] = "tmp/isolate/ruby-1.8"
+
+module Autotest::Restart
+ Autotest.add_hook :updated do |at, *args|
+ if args.flatten.include? ".autotest" then
+ warn "Detected change to .autotest, restarting"
+ cmd = %w(autotest)
+ cmd << " -v" if $v
+ cmd += ARGV
+
+ exec(*cmd)
+ end
+ end
+end
+
+Autotest.add_hook :initialize do |at|
+ at.add_exception 'tmp'
+ at.testlib = "minitest/autorun"
+
+ at.find_directories = ARGV unless ARGV.empty?
+end
+
View
6 Rakefile
@@ -2,6 +2,7 @@ require "rubygems"
gem 'hoe', '>= 2.1.0'
require 'hoe'
+Hoe.plugin :isolate
Hoe.plugin :gemspec # `gem install hoe-gemspec`
Hoe.spec 'arel' do
@@ -13,5 +14,8 @@ Hoe.spec 'arel' do
self.readme_file = 'README.markdown'
self.extra_rdoc_files = FileList['README.markdown']
self.extra_dev_deps << ['rspec', '~> 1.3.0']
- self.testlib = :rspec
+ self.extra_dev_deps << ['ZenTest']
+ self.extra_dev_deps << ['minitest']
+ self.extra_dev_deps << ['hoe-gemspec']
+ self.testlib = :minitest
end
View
5,725 TAGS
5,725 additions, 0 deletions not shown
View
6 lib/arel/table.rb
@@ -1,8 +1,4 @@
-def Table(name, engine = Arel::Table.engine)
- Arel::Table.new(name, engine)
-end
-
-module Arel
+module Arel
class Table
include Arel::Crud
View
21 spec/nodes/select_core_spec.rb
@@ -1,21 +0,0 @@
-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
View
3  spec/spec.opts
@@ -1,3 +0,0 @@
---backtrace
---diff
---color
View
18 spec/spec_helper.rb
@@ -1,18 +0,0 @@
-require 'rubygems'
-require 'spec'
-require 'fileutils'
-require 'arel'
-
-require 'support/matchers/be_like'
-require 'support/check'
-require 'support/fake_record'
-require 'support/shared/tree_manager_shared'
-
-Spec::Runner.configure do |config|
- config.include Matchers
- config.include Check
-
- config.before do
- Arel::Table.engine = Arel::Sql::Engine.new(FakeRecord::Base.new)
- end
-end
View
6 spec/support/check.rb
@@ -1,6 +0,0 @@
-module Check
- # This is used to eliminate Ruby warnings on some RSpec assertion lines
- # See: https://rspec.lighthouseapp.com/projects/5645/tickets/504
- def check(*args)
- end
-end
View
1  spec/support/matchers.rb
@@ -1 +0,0 @@
-require "support/matchers/be_like"
View
24 spec/support/matchers/be_like.rb
@@ -1,24 +0,0 @@
-module Matchers
- class BeLike
- def initialize(expected)
- @expected = expected.gsub(/\s+/, ' ').strip
- end
-
- def matches?(actual)
- @actual = actual.gsub(/\s+/, ' ').strip
- @expected == @actual
- end
-
- def failure_message
- "expected\n#{@actual}\nto be like\n#{@expected}"
- end
-
- def negative_failure_message
- "expected\n#{@actual}\nto be unlike\n#{@expected}"
- end
- end
-
- def be_like(expected)
- BeLike.new(expected)
- end
-end
View
166 spec/attributes/attribute_spec.rb → test/attributes/test_attribute.rb
@@ -6,14 +6,14 @@ module Attributes
describe '#not_eq' do
it 'should create a NotEqual node' do
relation = Table.new(:users)
- relation[:id].not_eq(10).should be_kind_of Nodes::NotEqual
+ relation[:id].not_eq(10).must_be_kind_of Nodes::NotEqual
end
it 'should generate != in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq(10)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" != 10
}
end
@@ -22,7 +22,7 @@ module Attributes
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq(nil)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" IS NOT NULL
}
end
@@ -31,14 +31,14 @@ module Attributes
describe '#not_eq_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].not_eq_any([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].not_eq_any([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq_any([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" != 1 OR "users"."id" != 2)
}
end
@@ -47,14 +47,14 @@ module Attributes
describe '#not_eq_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].not_eq_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].not_eq_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_eq_all([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" != 1 AND "users"."id" != 2)
}
end
@@ -63,14 +63,14 @@ module Attributes
describe '#gt' do
it 'should create a GreaterThan node' do
relation = Table.new(:users)
- relation[:id].gt(10).should be_kind_of Nodes::GreaterThan
+ relation[:id].gt(10).must_be_kind_of Nodes::GreaterThan
end
it 'should generate >= in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gt(10)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" > 10
}
end
@@ -79,14 +79,14 @@ module Attributes
describe '#gt_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].gt_any([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].gt_any([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gt_any([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" > 1 OR "users"."id" > 2)
}
end
@@ -95,14 +95,14 @@ module Attributes
describe '#gt_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].gt_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].gt_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gt_all([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" > 1 AND "users"."id" > 2)
}
end
@@ -111,14 +111,14 @@ module Attributes
describe '#gteq' do
it 'should create a GreaterThanOrEqual node' do
relation = Table.new(:users)
- relation[:id].gteq(10).should be_kind_of Nodes::GreaterThanOrEqual
+ relation[:id].gteq(10).must_be_kind_of Nodes::GreaterThanOrEqual
end
it 'should generate >= in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gteq(10)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" >= 10
}
end
@@ -127,14 +127,14 @@ module Attributes
describe '#gteq_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].gteq_any([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].gteq_any([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gteq_any([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" >= 1 OR "users"."id" >= 2)
}
end
@@ -143,14 +143,14 @@ module Attributes
describe '#gteq_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].gteq_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].gteq_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].gteq_all([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" >= 1 AND "users"."id" >= 2)
}
end
@@ -159,14 +159,14 @@ module Attributes
describe '#lt' do
it 'should create a LessThan node' do
relation = Table.new(:users)
- relation[:id].lt(10).should be_kind_of Nodes::LessThan
+ relation[:id].lt(10).must_be_kind_of Nodes::LessThan
end
it 'should generate < in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lt(10)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" < 10
}
end
@@ -175,14 +175,14 @@ module Attributes
describe '#lt_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].lt_any([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].lt_any([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lt_any([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" < 1 OR "users"."id" < 2)
}
end
@@ -191,14 +191,14 @@ module Attributes
describe '#lt_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].lt_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].lt_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lt_all([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" < 1 AND "users"."id" < 2)
}
end
@@ -207,14 +207,14 @@ module Attributes
describe '#lteq' do
it 'should create a LessThanOrEqual node' do
relation = Table.new(:users)
- relation[:id].lteq(10).should be_kind_of Nodes::LessThanOrEqual
+ relation[:id].lteq(10).must_be_kind_of Nodes::LessThanOrEqual
end
it 'should generate <= in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lteq(10)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" <= 10
}
end
@@ -223,14 +223,14 @@ module Attributes
describe '#lteq_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].lteq_any([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].lteq_any([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lteq_any([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" <= 1 OR "users"."id" <= 2)
}
end
@@ -239,14 +239,14 @@ module Attributes
describe '#lteq_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].lteq_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].lteq_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].lteq_all([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" <= 1 AND "users"."id" <= 2)
}
end
@@ -255,14 +255,14 @@ module Attributes
describe '#average' do
it 'should create a AVG node' do
relation = Table.new(:users)
- relation[:id].average.should be_kind_of Nodes::Avg
+ relation[:id].average.must_be_kind_of Nodes::Avg
end
# FIXME: backwards compat. Is this really necessary?
it 'should set the alias to "avg_id"' do
relation = Table.new(:users)
mgr = relation.project relation[:id].average
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT AVG("users"."id") AS avg_id
FROM "users"
}
@@ -272,14 +272,14 @@ module Attributes
describe '#maximum' do
it 'should create a MAX node' do
relation = Table.new(:users)
- relation[:id].maximum.should be_kind_of Nodes::Max
+ relation[:id].maximum.must_be_kind_of Nodes::Max
end
# FIXME: backwards compat. Is this really necessary?
it 'should set the alias to "max_id"' do
relation = Table.new(:users)
mgr = relation.project relation[:id].maximum
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT MAX("users"."id") AS max_id
FROM "users"
}
@@ -289,21 +289,21 @@ module Attributes
describe '#minimum' do
it 'should create a Min node' do
relation = Table.new(:users)
- relation[:id].minimum.should be_kind_of Nodes::Min
+ relation[:id].minimum.must_be_kind_of Nodes::Min
end
end
describe '#sum' do
it 'should create a SUM node' do
relation = Table.new(:users)
- relation[:id].sum.should be_kind_of Nodes::Sum
+ relation[:id].sum.must_be_kind_of Nodes::Sum
end
# FIXME: backwards compat. Is this really necessary?
it 'should set the alias to "sum_id"' do
relation = Table.new(:users)
mgr = relation.project relation[:id].sum
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT SUM("users"."id") AS sum_id
FROM "users"
}
@@ -313,14 +313,14 @@ module Attributes
describe '#count' do
it 'should return a count node' do
relation = Table.new(:users)
- relation[:id].count.should be_kind_of Nodes::Count
+ relation[:id].count.must_be_kind_of Nodes::Count
end
it 'should take a distinct param' do
relation = Table.new(:users)
count = relation[:id].count(nil)
- count.should be_kind_of Nodes::Count
- count.distinct.should be_nil
+ count.must_be_kind_of Nodes::Count
+ count.distinct.must_be_nil
end
end
@@ -328,16 +328,16 @@ module Attributes
it 'should return an equality node' do
attribute = Attribute.new nil, nil, nil
equality = attribute.eq 1
- check equality.left.should == attribute
- check equality.right.should == 1
- equality.should be_kind_of Nodes::Equality
+ check equality.left.must_equal attribute
+ check equality.right.must_equal 1
+ equality.must_be_kind_of Nodes::Equality
end
it 'should generate = in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq(10)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" = 10
}
end
@@ -346,7 +346,7 @@ module Attributes
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq(nil)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" IS NULL
}
end
@@ -355,14 +355,14 @@ module Attributes
describe '#eq_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].eq_any([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].eq_any([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq_any([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 OR "users"."id" = 2)
}
end
@@ -371,14 +371,14 @@ module Attributes
describe '#eq_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].eq_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].eq_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq_all([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2)
}
end
@@ -387,14 +387,14 @@ module Attributes
describe '#matches' do
it 'should create a Matches node' do
relation = Table.new(:users)
- relation[:name].matches('%bacon%').should be_kind_of Nodes::Matches
+ relation[:name].matches('%bacon%').must_be_kind_of Nodes::Matches
end
it 'should generate LIKE in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].matches('%bacon%')
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."name" LIKE '%bacon%'
}
end
@@ -403,14 +403,14 @@ module Attributes
describe '#matches_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:name].matches_any(['%chunky%','%bacon%']).should be_kind_of Nodes::Grouping
+ relation[:name].matches_any(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].matches_any(['%chunky%','%bacon%'])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" LIKE '%chunky%' OR "users"."name" LIKE '%bacon%')
}
end
@@ -419,14 +419,14 @@ module Attributes
describe '#matches_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:name].matches_all(['%chunky%','%bacon%']).should be_kind_of Nodes::Grouping
+ relation[:name].matches_all(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].matches_all(['%chunky%','%bacon%'])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" LIKE '%chunky%' AND "users"."name" LIKE '%bacon%')
}
end
@@ -435,14 +435,14 @@ module Attributes
describe '#does_not_match' do
it 'should create a DoesNotMatch node' do
relation = Table.new(:users)
- relation[:name].does_not_match('%bacon%').should be_kind_of Nodes::DoesNotMatch
+ relation[:name].does_not_match('%bacon%').must_be_kind_of Nodes::DoesNotMatch
end
it 'should generate NOT LIKE in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].does_not_match('%bacon%')
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."name" NOT LIKE '%bacon%'
}
end
@@ -451,14 +451,14 @@ module Attributes
describe '#does_not_match_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:name].does_not_match_any(['%chunky%','%bacon%']).should be_kind_of Nodes::Grouping
+ relation[:name].does_not_match_any(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].does_not_match_any(['%chunky%','%bacon%'])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" NOT LIKE '%chunky%' OR "users"."name" NOT LIKE '%bacon%')
}
end
@@ -467,14 +467,14 @@ module Attributes
describe '#does_not_match_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:name].does_not_match_all(['%chunky%','%bacon%']).should be_kind_of Nodes::Grouping
+ relation[:name].does_not_match_all(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%'])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."name" NOT LIKE '%chunky%' AND "users"."name" NOT LIKE '%bacon%')
}
end
@@ -487,15 +487,15 @@ module Attributes
it 'should return an in node' do
attribute = Attribute.new nil, nil, nil
node = Nodes::In.new attribute, [1,2,3]
- check node.left.should == attribute
- check node.right.should == [1, 2, 3]
+ check node.left.must_equal attribute
+ check node.right.must_equal [1, 2, 3]
end
it 'should generate IN in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].in([1,2,3])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" IN (1, 2, 3)
}
end
@@ -504,14 +504,14 @@ module Attributes
describe '#in_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].in_any([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].in_any([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].in_any([[1,2], [3,4]])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" IN (1, 2) OR "users"."id" IN (3, 4))
}
end
@@ -520,14 +520,14 @@ module Attributes
describe '#in_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].in_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].in_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].in_all([[1,2], [3,4]])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" IN (1, 2) AND "users"."id" IN (3, 4))
}
end
@@ -540,15 +540,15 @@ module Attributes
it 'should return a NotIn node' do
attribute = Attribute.new nil, nil, nil
node = Nodes::NotIn.new attribute, [1,2,3]
- check node.left.should == attribute
- check node.right.should == [1, 2, 3]
+ check node.left.must_equal attribute
+ check node.right.must_equal [1, 2, 3]
end
it 'should generate NOT IN in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_in([1,2,3])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE "users"."id" NOT IN (1, 2, 3)
}
end
@@ -557,14 +557,14 @@ module Attributes
describe '#not_in_any' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].not_in_any([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].not_in_any([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ORs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_in_any([[1,2], [3,4]])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" NOT IN (1, 2) OR "users"."id" NOT IN (3, 4))
}
end
@@ -573,14 +573,14 @@ module Attributes
describe '#not_in_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].not_in_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].not_in_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].not_in_all([[1,2], [3,4]])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" NOT IN (1, 2) AND "users"."id" NOT IN (3, 4))
}
end
@@ -589,14 +589,14 @@ module Attributes
describe '#eq_all' do
it 'should create a Grouping node' do
relation = Table.new(:users)
- relation[:id].eq_all([1,2]).should be_kind_of Nodes::Grouping
+ relation[:id].eq_all([1,2]).must_be_kind_of Nodes::Grouping
end
it 'should generate ANDs in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.where relation[:id].eq_all([1,2])
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2)
}
end
@@ -605,14 +605,14 @@ module Attributes
describe '#asc' do
it 'should create an Ordering node' do
relation = Table.new(:users)
- relation[:id].asc.should be_kind_of Nodes::Ordering
+ relation[:id].asc.must_be_kind_of Nodes::Ordering
end
it 'should generate ASC in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.order relation[:id].asc
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" ORDER BY "users"."id" ASC
}
end
@@ -621,14 +621,14 @@ module Attributes
describe '#desc' do
it 'should create an Ordering node' do
relation = Table.new(:users)
- relation[:id].desc.should be_kind_of Nodes::Ordering
+ relation[:id].desc.must_be_kind_of Nodes::Ordering
end
it 'should generate DESC in sql' do
relation = Table.new(:users)
mgr = relation.project relation[:id]
mgr.order relation[:id].desc
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT "users"."id" FROM "users" ORDER BY "users"."id" DESC
}
end
@@ -640,7 +640,7 @@ module Attributes
it 'should produce sql' do
table = Table.new :users
condition = table['id'].eq 1
- condition.to_sql.should == '"users"."id" = 1'
+ condition.to_sql.must_equal '"users"."id" = 1'
end
end
end
View
4 spec/nodes/count_spec.rb → test/nodes/test_count.rb
@@ -3,14 +3,14 @@
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
+ 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.should be_like %{
+ table[:id].count.as('foo').to_sql.must_be_like %{
COUNT("users"."id") AS foo
}
end
View
5 spec/nodes/delete_statement_spec.rb → test/nodes/test_delete_statement.rb
@@ -6,10 +6,9 @@
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]
+ dolly.wheres.must_equal statement.wheres
+ dolly.wheres.wont_be_same_as statement.wheres
end
end
end
View
18 spec/nodes/equality_spec.rb → test/nodes/test_equality.rb
@@ -1,3 +1,5 @@
+require 'spec_helper'
+
module Arel
module Nodes
describe 'equality' do
@@ -7,7 +9,7 @@ module Nodes
it 'returns :==' do
attr = Table.new(:users)[:id]
left = attr.eq(10)
- check left.operator.should == :==
+ check left.operator.must_equal :==
end
end
@@ -15,7 +17,7 @@ module Nodes
it "should equal left" do
attr = Table.new(:users)[:id]
left = attr.eq(10)
- check left.left.should == left.operand1
+ check left.left.must_equal left.operand1
end
end
@@ -23,7 +25,7 @@ module Nodes
it "should equal right" do
attr = Table.new(:users)[:id]
left = attr.eq(10)
- check left.right.should == left.operand2
+ check left.right.must_equal left.operand2
end
end
@@ -41,7 +43,7 @@ def quote_table_name(*args) @quote_count += 1; super; end
attr = Table.new(:users)[:id]
test = attr.eq(10)
test.to_sql engine
- check engine.connection.quote_count.should == 2
+ check engine.connection.quote_count.must_equal 2
end
end
end
@@ -52,8 +54,8 @@ def quote_table_name(*args) @quote_count += 1; super; end
left = attr.eq(10)
right = attr.eq(11)
node = left.or right
- check node.expr.left.should == left
- check node.expr.right.should == right
+ check node.expr.left.must_equal left
+ check node.expr.right.must_equal right
end
end
@@ -63,8 +65,8 @@ def quote_table_name(*args) @quote_count += 1; super; end
left = attr.eq(10)
right = attr.eq(11)
node = left.and right
- check node.left.should == left
- check node.right.should == right
+ check node.left.must_equal left
+ check node.right.must_equal right
end
end
end
View
10 spec/nodes/insert_statement_spec.rb → test/nodes/test_insert_statement.rb
@@ -7,12 +7,12 @@
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]
+ 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
View
10 spec/nodes/or_spec.rb → test/nodes/test_or.rb
@@ -1,3 +1,5 @@
+require 'spec_helper'
+
module Arel
module Nodes
describe 'or' do
@@ -7,12 +9,12 @@ module Nodes
left = attr.eq(10)
right = attr.eq(11)
node = left.or right
- check node.expr.left.should == left
- check node.expr.right.should == right
+ check node.expr.left.must_equal left
+ check node.expr.right.must_equal right
oror = node.or(right)
- check oror.expr.left == node
- check oror.expr.right == right
+ check oror.expr.left.must_equal node
+ check oror.expr.right.must_equal right
end
end
end
View
22 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
View
5 spec/nodes/select_statement_spec.rb → test/nodes/test_select_statement.rb
@@ -5,10 +5,9 @@
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]
+ dolly.cores.must_equal statement.cores
+ dolly.cores.wont_be_same_as statement.cores
end
end
end
View
8 spec/nodes/sql_literal_spec.rb → test/nodes/test_sql_literal.rb
@@ -1,10 +1,12 @@
+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.should be_kind_of Arel::Nodes::SqlLiteral
+ sql.must_be_kind_of Arel::Nodes::SqlLiteral
end
end
@@ -12,13 +14,13 @@ module Nodes
it 'makes a count node' do
node = SqlLiteral.new('*').count
viz = Visitors::ToSql.new Table.engine
- viz.accept(node).should be_like %{ COUNT(*) }
+ 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).should be_like %{ COUNT(DISTINCT *) }
+ viz.accept(node).must_be_like %{ COUNT(DISTINCT *) }
end
end
end
View
2  spec/nodes/sum_spec.rb → test/nodes/test_sum.rb
@@ -4,7 +4,7 @@
describe "as" do
it 'should alias the sum' do
table = Arel::Table.new :users
- table[:id].sum.as('foo').to_sql.should be_like %{
+ table[:id].sum.as('foo').to_sql.must_be_like %{
SUM("users"."id") AS foo
}
end
View
10 spec/nodes/update_statement_spec.rb → test/nodes/test_update_statement.rb
@@ -7,12 +7,12 @@
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]
+ 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
View
21 test/spec_helper.rb
@@ -0,0 +1,21 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'fileutils'
+require 'arel'
+
+require 'support/fake_record'
+Arel::Table.engine = Arel::Sql::Engine.new(FakeRecord::Base.new)
+
+# HACK require 'support/shared/tree_manager_shared'
+
+class Object
+ def must_be_like other
+ self.gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
+ end
+
+ # TODO: remove
+ def check truthiness
+ raise "not truthy" unless truthiness
+ end
+end
+
View
0  spec/support/fake_record.rb → test/support/fake_record.rb
File renamed without changes
View
2  spec/activerecord_compat_spec.rb → test/test_activerecord_compat.rb
@@ -11,7 +11,7 @@ module Arel
check manager.wheres.map { |x|
x.value
- }.join(', ').should == "\"users\".\"id\" = 1, \"users\".\"name\" = 'Aaron'"
+ }.join(', ').must_equal "\"users\".\"id\" = 1, \"users\".\"name\" = 'Aaron'"
end
end
end
View
12 spec/attributes_spec.rb → test/test_attributes.rb
@@ -6,34 +6,34 @@ module Arel
it 'returns the correct constant for strings' do
[:string, :text, :binary].each do |type|
column = Struct.new(:type).new type
- Attributes.for(column).should == Attributes::String
+ Attributes.for(column).must_equal Attributes::String
end
end
it 'returns the correct constant for ints' do
column = Struct.new(:type).new :integer
- Attributes.for(column).should == Attributes::Integer
+ Attributes.for(column).must_equal Attributes::Integer
end
it 'returns the correct constant for floats' do
column = Struct.new(:type).new :float
- Attributes.for(column).should == Attributes::Float
+ Attributes.for(column).must_equal Attributes::Float
end
it 'returns the correct constant for decimals' do
column = Struct.new(:type).new :decimal
- Attributes.for(column).should == Attributes::Decimal
+ Attributes.for(column).must_equal Attributes::Decimal
end
it 'returns the correct constant for boolean' do
column = Struct.new(:type).new :boolean
- Attributes.for(column).should == Attributes::Boolean
+ Attributes.for(column).must_equal Attributes::Boolean
end
it 'returns the correct constant for time' do
[:date, :datetime, :timestamp, :time].each do |type|
column = Struct.new(:type).new type
- Attributes.for(column).should == Attributes::Time
+ Attributes.for(column).must_equal Attributes::Time
end
end
end
View
6 spec/crud_spec.rb → test/test_crud.rb
@@ -38,7 +38,7 @@ def initialize engine = FakeEngine.new
fc.insert [[table[:id], 'foo']]
fc.engine.calls.find { |method, _|
method == :insert
- }.should_not be_nil
+ }.wont_be_nil
end
end
@@ -50,7 +50,7 @@ def initialize engine = FakeEngine.new
fc.update [[table[:id], 'foo']]
fc.engine.calls.find { |method, _|
method == :update
- }.should_not be_nil
+ }.wont_be_nil
end
end
@@ -62,7 +62,7 @@ def initialize engine = FakeEngine.new
fc.delete
fc.engine.calls.find { |method, _|
method == :delete
- }.should_not be_nil
+ }.wont_be_nil
end
end
end
View
29 spec/delete_manager_spec.rb → test/test_delete_manager.rb
@@ -13,13 +13,13 @@ module Arel
table = Table.new(:users)
dm = Arel::DeleteManager.new Table.engine
dm.from table
- dm.to_sql.should be_like %{ DELETE FROM "users" }
+ dm.to_sql.must_be_like %{ DELETE FROM "users" }
end
it 'chains' do
table = Table.new(:users)
dm = Arel::DeleteManager.new Table.engine
- check dm.from(table).should == dm
+ check dm.from(table).must_equal dm
end
end
@@ -29,25 +29,26 @@ module Arel
dm = Arel::DeleteManager.new Table.engine
dm.from table
dm.where table[:id].eq(10)
- dm.to_sql.should be_like %{ DELETE FROM "users" WHERE "users"."id" = 10}
+ dm.to_sql.must_be_like %{ DELETE FROM "users" WHERE "users"."id" = 10}
end
it 'chains' do
table = Table.new(:users)
dm = Arel::DeleteManager.new Table.engine
- check dm.where(table[:id].eq(10)).should == dm
+ check dm.where(table[:id].eq(10)).must_equal dm
end
end
- describe "TreeManager" do
- subject do
- table = Table.new :users
- Arel::DeleteManager.new(Table.engine).tap do |manager|
- manager.where(table[:id].eq(10))
- end
- end
-
- it_should_behave_like "TreeManager"
- end
+ # HACK
+ # describe "TreeManager" do
+ # before do
+ # table = Table.new :users
+ # Arel::DeleteManager.new(Table.engine).tap do |manager|
+ # manager.where(table[:id].eq(10))
+ # end
+ # end
+ #
+ # it_should_behave_like "TreeManager"
+ # end
end
end
View
45 spec/insert_manager_spec.rb → test/test_insert_manager.rb
@@ -13,12 +13,10 @@ module Arel
table = Table.new(:users)
manager = Arel::InsertManager.new Table.engine
- table[:id].column.extend(Module.new {
- def type; :boolean; end
- })
+ table[:id].column.extend(Module.new { def type; :boolean; end })
manager.insert [[table[:id], false]]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users" ("id") VALUES ('f')
}
end
@@ -27,7 +25,7 @@ def type; :boolean; end
table = Table.new(:users)
manager = Arel::InsertManager.new Table.engine
manager.insert [[table[:id], nil]]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users" ("id") VALUES (NULL)
}
end
@@ -41,7 +39,7 @@ def type; :boolean; end
attribute.column.type = :date
manager.insert [[attribute, time]]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users" ("id") VALUES (#{Table.engine.connection.quote time})
}
end
@@ -51,7 +49,7 @@ def type; :boolean; end
manager = Arel::InsertManager.new Table.engine
manager.into table
manager.insert [[table[:id], 1], [table[:name], 'aaron']]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users" ("id", "name") VALUES (1, 'aaron')
}
end
@@ -60,7 +58,7 @@ def type; :boolean; end
table = Table.new(:users)
manager = Arel::InsertManager.new Table.engine
manager.insert [[table[:id], 1], [table[:name], 'aaron']]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users" ("id", "name") VALUES (1, 'aaron')
}
end
@@ -74,14 +72,14 @@ def type; :boolean; end
describe 'into' do
it 'takes an engine' do
manager = Arel::InsertManager.new Table.engine
- manager.into(Table.new(:users)).should == manager
+ manager.into(Table.new(:users)).must_equal manager
end
it 'converts to sql' do
table = Table.new :users
manager = Arel::InsertManager.new Table.engine
manager.into table
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users"
}
end
@@ -93,7 +91,7 @@ def type; :boolean; end
manager = Arel::InsertManager.new Table.engine
manager.into table
manager.columns << table[:id]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users" ("id")
}
end
@@ -106,7 +104,7 @@ def type; :boolean; end
manager.into table
manager.values = Nodes::Values.new [1]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users" VALUES (1)
}
end
@@ -121,21 +119,22 @@ def type; :boolean; end
manager.values = Nodes::Values.new [1, 'aaron']
manager.columns << table[:id]
manager.columns << table[:name]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
INSERT INTO "users" ("id", "name") VALUES (1, 'aaron')
}
end
end
- describe "TreeManager" do
- subject do
- table = Table.new(:users)
- Arel::InsertManager.new(Table.engine).tap do |manager|
- manager.insert [[table[:id], nil]]
- end
- end
-
- it_should_behave_like "TreeManager"
- end
+ # HACK
+ # describe "TreeManager" do
+ # subject do
+ # table = Table.new(:users)
+ # Arel::InsertManager.new(Table.engine).tap do |manager|
+ # manager.insert [[table[:id], nil]]
+ # end
+ # end
+ #
+ # it_should_behave_like "TreeManager"
+ # end
end
end
View
130 spec/select_manager_spec.rb → test/test_select_manager.rb
@@ -43,7 +43,7 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.project :id
manager.from table
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT id FROM "users"
}
end
@@ -56,7 +56,7 @@ def execute sql, name = nil, *args
manager.project SqlLiteral.new '*'
manager.from table
manager.order :foo
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT * FROM "users" ORDER BY foo
}
end
@@ -68,7 +68,7 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.group :foo
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT FROM "users" GROUP BY foo
}
end
@@ -82,7 +82,7 @@ def execute sql, name = nil, *args
manager.from table
manager.from 'users'
manager.project table['id']
- manager.to_sql.should be_like 'SELECT "users"."id" FROM users'
+ manager.to_sql.must_be_like 'SELECT "users"."id" FROM users'
end
end
@@ -91,7 +91,7 @@ def execute sql, name = nil, *args
table = Table.new :users
mgr = table.from table
mgr.having 'foo'
- mgr.to_sql.should be_like %{ SELECT FROM "users" HAVING foo }
+ mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo }
end
end
end
@@ -102,8 +102,7 @@ def execute sql, name = nil, *args
mgr = table.from table
m2 = mgr.clone
m2.project "foo"
-
- check mgr.to_sql.should_not == m2.to_sql
+ mgr.to_sql.wont_equal m2.to_sql
end
end
@@ -112,7 +111,7 @@ def execute sql, name = nil, *args
table = Table.new :users, :engine => Table.engine, :as => 'foo'
mgr = table.from table
mgr.skip 10
- mgr.to_sql.should be_like %{ SELECT FROM "users" "foo" OFFSET 10 }
+ mgr.to_sql.must_be_like %{ SELECT FROM "users" "foo" OFFSET 10 }
end
end
@@ -121,13 +120,13 @@ def execute sql, name = nil, *args
table = Table.new :users
mgr = table.from table
mgr.skip 10
- mgr.to_sql.should be_like %{ SELECT FROM "users" OFFSET 10 }
+ mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
end
it 'should chain' do
table = Table.new :users
mgr = table.from table
- mgr.skip(10).to_sql.should be_like %{ SELECT FROM "users" OFFSET 10 }
+ mgr.skip(10).to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 }
end
end
@@ -136,7 +135,7 @@ def execute sql, name = nil, *args
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
manager.take 10
- check manager.taken.should == 10
+ check manager.taken.must_equal 10
end
end
@@ -148,7 +147,7 @@ def execute sql, name = nil, *args
manager.from table
manager.insert 'VALUES(NULL)'
- engine.executed.last.should be_like %{
+ engine.executed.last.must_be_like %{
INSERT INTO "users" VALUES(NULL)
}
end
@@ -159,7 +158,7 @@ def execute sql, name = nil, *args
it 'adds a lock node' do
table = Table.new :users
mgr = table.from table
- mgr.lock.to_sql.should be_like %{ SELECT FROM "users" }
+ mgr.lock.to_sql.must_be_like %{ SELECT FROM "users" }
end
end
@@ -169,7 +168,7 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
order = table[:id]
manager.order table[:id]
- check manager.orders.should == [order]
+ check manager.orders.must_equal [order]
end
end
@@ -180,7 +179,7 @@ def execute sql, name = nil, *args
manager.project SqlLiteral.new '*'
manager.from table
manager.order table[:id]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT * FROM "users" ORDER BY "users"."id"
}
end
@@ -192,7 +191,7 @@ def execute sql, name = nil, *args
manager.project SqlLiteral.new '*'
manager.from table
manager.order table[:id], table[:name]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT * FROM "users" ORDER BY "users"."id", "users"."name"
}
end
@@ -200,7 +199,7 @@ def execute sql, name = nil, *args
it 'chains' do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
- check manager.order(table[:id]).should == manager
+ check manager.order(table[:id]).must_equal manager
end
end
@@ -213,7 +212,7 @@ def execute sql, name = nil, *args
manager.from left
manager.join(right).on(predicate, predicate)
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT FROM "users"
INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id" AND
@@ -233,7 +232,7 @@ def execute sql, name = nil, *args
predicate,
left[:name].eq(right[:name])
)
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT FROM "users"
INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id" AND
@@ -252,7 +251,7 @@ def execute sql, name = nil, *args
manager.from left
manager.join(right).on(predicate)
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT FROM "users"
INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@@ -267,7 +266,7 @@ def execute sql, name = nil, *args
manager.from left
manager.join(right, Nodes::OuterJoin).on(predicate)
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT FROM "users"
LEFT OUTER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@@ -276,7 +275,7 @@ def execute sql, name = nil, *args
it 'noops on nil' do
manager = Arel::SelectManager.new Table.engine
- check manager.join(nil).should == manager
+ check manager.join(nil).must_equal manager
end
end
@@ -286,10 +285,10 @@ def execute sql, name = nil, *args
aliaz = table.alias
manager = Arel::SelectManager.new Table.engine
manager.from Nodes::InnerJoin.new(table, aliaz, table[:id].eq(aliaz[:id]))
- manager.join_sql.should be_like %{
+ manager.join_sql.must_be_like %{
INNER JOIN "users" "users_2" "users"."id" = "users_2"."id"
}
- check manager.joins(manager).should == manager.join_sql
+ check manager.joins(manager).must_equal manager.join_sql
end
it 'returns outer join sql' do
@@ -297,10 +296,10 @@ def execute sql, name = nil, *args
aliaz = table.alias
manager = Arel::SelectManager.new Table.engine
manager.from Nodes::OuterJoin.new(table, aliaz, table[:id].eq(aliaz[:id]))
- manager.join_sql.should be_like %{
+ manager.join_sql.must_be_like %{
LEFT OUTER JOIN "users" "users_2" "users"."id" = "users_2"."id"
}
- check manager.joins(manager).should == manager.join_sql
+ check manager.joins(manager).must_equal manager.join_sql
end
it 'returns string join sql' do
@@ -308,13 +307,13 @@ def execute sql, name = nil, *args
aliaz = table.alias
manager = Arel::SelectManager.new Table.engine
manager.from Nodes::StringJoin.new(table, 'hello')
- manager.join_sql.should be_like %{ 'hello' }
- check manager.joins(manager).should == manager.join_sql
+ manager.join_sql.must_be_like %{ 'hello' }
+ check manager.joins(manager).must_equal manager.join_sql
end
it 'returns nil join sql' do
manager = Arel::SelectManager.new Table.engine
- manager.join_sql.should be_nil
+ manager.join_sql.must_be_nil
end
end
@@ -325,7 +324,7 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.order table[:id]
- manager.order_clauses.first.should be_like %{ "users"."id" }
+ manager.order_clauses.first.must_be_like %{ "users"."id" }
end
end
@@ -335,7 +334,7 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.group table[:id]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT FROM "users" GROUP BY "users"."id"
}
end
@@ -343,7 +342,7 @@ def execute sql, name = nil, *args
it 'chains' do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
- check manager.group(table[:id]).should == manager
+ check manager.group(table[:id]).must_equal manager
end
it 'takes multiple args' do
@@ -351,7 +350,7 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.group table[:id], table[:name]
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT FROM "users" GROUP BY "users"."id", "users"."name"
}
end
@@ -362,7 +361,7 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.group 'foo'
- manager.to_sql.should be_like %{ SELECT FROM "users" GROUP BY foo }
+ manager.to_sql.must_be_like %{ SELECT FROM "users" GROUP BY foo }
end
end
@@ -374,7 +373,7 @@ def execute sql, name = nil, *args
manager.from table
manager.delete
- engine.executed.last.should be_like %{ DELETE FROM "users" }
+ engine.executed.last.must_be_like %{ DELETE FROM "users" }
end
it "copies where" do
@@ -385,7 +384,7 @@ def execute sql, name = nil, *args
manager.where table[:id].eq 10
manager.delete
- engine.executed.last.should be_like %{
+ engine.executed.last.must_be_like %{
DELETE FROM "users" WHERE "users"."id" = 10
}
end
@@ -397,14 +396,14 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.from table
manager.where table[:id].eq 10
- manager.where_sql.should be_like %{ WHERE "users"."id" = 10 }
+ manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 }
end
it 'returns nil when there are no wheres' do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
manager.from table
- manager.where_sql.should be_nil
+ manager.where_sql.must_be_nil
end
end
@@ -417,7 +416,7 @@ def execute sql, name = nil, *args
manager.take 1
manager.update(SqlLiteral.new('foo = bar'))
- engine.executed.last.should be_like %{
+ engine.executed.last.must_be_like %{
UPDATE "users" SET foo = bar
WHERE "users"."id" IN (SELECT "users"."id" FROM "users" LIMIT 1)
}
@@ -431,7 +430,7 @@ def execute sql, name = nil, *args
manager.order :foo
manager.update(SqlLiteral.new('foo = bar'))
- engine.executed.last.should be_like %{
+ engine.executed.last.must_be_like %{
UPDATE "users" SET foo = bar
WHERE "users"."id" IN (SELECT "users"."id" FROM "users" ORDER BY foo)
}
@@ -444,7 +443,7 @@ def execute sql, name = nil, *args
manager.from table
manager.update(SqlLiteral.new('foo = bar'))
- engine.executed.last.should be_like %{ UPDATE "users" SET foo = bar }
+ engine.executed.last.must_be_like %{ UPDATE "users" SET foo = bar }
end
it 'copies where clauses' do
@@ -455,7 +454,7 @@ def execute sql, name = nil, *args
manager.from table
manager.update(table[:id] => 1)
- engine.executed.last.should be_like %{
+ engine.executed.last.must_be_like %{
UPDATE "users" SET "id" = 1 WHERE "users"."id" = 10
}
end
@@ -467,7 +466,7 @@ def execute sql, name = nil, *args
manager.from table
manager.update(table[:id] => 1)
- engine.executed.last.should be_like %{
+ engine.executed.last.must_be_like %{
UPDATE "users" SET "id" = 1
}
end
@@ -479,21 +478,21 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.project Nodes::SqlLiteral.new('foo'),
Nodes::SqlLiteral.new('bar')
- manager.to_sql.should be_like %{ SELECT foo, bar }
+ manager.to_sql.must_be_like %{ SELECT foo, bar }
end
it 'takes strings' do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
manager.project Nodes::SqlLiteral.new('*')
- manager.to_sql.should be_like %{ SELECT * }
+ manager.to_sql.must_be_like %{ SELECT * }
end
it "takes sql literals" do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
manager.project Nodes::SqlLiteral.new '*'
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT *
}
end
@@ -507,7 +506,7 @@ def execute sql, name = nil, *args
manager.where(table['id'].eq(1))
manager.take 1
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT "users"."id"
FROM "users"
WHERE "users"."id" = 1
@@ -518,7 +517,7 @@ def execute sql, name = nil, *args
it "chains" do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
- manager.take(1).should == manager
+ manager.take(1).must_equal manager
end
end
@@ -528,7 +527,7 @@ def execute sql, name = nil, *args
manager = Arel::SelectManager.new Table.engine
manager.from(table).project(table['id'])
manager.where(table['id'].eq(1))
- manager.to_sql.should be_like %{
+ manager.to_sql.must_be_like %{
SELECT "users"."id"
FROM "users"
WHERE "users"."id" = 1
@@ -539,7 +538,7 @@ def execute sql, name = nil, *args
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
manager.from(table)
- manager.project(table['id']).where(table['id'].eq 1).should == manager
+ manager.project(table['id']).where(table['id'].eq 1).must_equal manager
end
end
@@ -551,9 +550,9 @@ def execute sql, name = nil, *args
mgr = left.join(right)
mgr.project Nodes::SqlLiteral.new('*')
- check mgr.on(predicate).should == mgr
+ check mgr.on(predicate).must_equal mgr
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT * FROM "users"
INNER JOIN "users" "users_2"
ON "users"."id" = "users_2"."id"
@@ -568,26 +567,27 @@ def execute sql, name = nil, *args
manager.from table
manager.project table['id']
- manager.to_sql.should be_like 'SELECT "users"."id" FROM "users"'
+ manager.to_sql.must_be_like 'SELECT "users"."id" FROM "users"'
end
it "chains" do
table = Table.new :users
manager = Arel::SelectManager.new Table.engine
- check manager.from(table).project(table['id']).should == manager
- manager.to_sql.should be_like 'SELECT "users"."id" FROM "users"'
+ check manager.from(table).project(table['id']).must_equal manager
+ manager.to_sql.must_be_like 'SELECT "users"."id" FROM "users"'
end
end
- describe "TreeManager" do
- subject do
- table = Table.new :users
- Arel::SelectManager.new(Table.engine).tap do |manager|
- manager.from(table).project(table['id'])
- end
- end
-
- it_should_behave_like "TreeManager"
- end
+ # HACK
+ # describe "TreeManager" do
+ # subject do
+ # table = Table.new :users
+ # Arel::SelectManager.new(Table.engine).tap do |manager|
+ # manager.from(table).project(table['id'])
+ # end
+ # end
+ #
+ # it_should_behave_like "TreeManager"
+ # end
end
end
View
84 spec/table_spec.rb → test/test_table.rb
@@ -1,27 +1,6 @@
require 'spec_helper'
-describe '#Table' do
- it 'creates a base relation variable' do
- name = :foo
- Table(name) == Arel::Table.new(name)
- end
-
- it 'should have a default engine' do
- Table(:foo).engine.should == Arel::Table.engine
- end
-
- it 'can take an engine' do
- engine = Arel::Table.engine
- Table(:foo, engine).engine.should be engine
- end
- it 'can take an options hash' do
- engine = Arel::Table.engine
- options = { :engine => engine }
- Table(:foo, options).engine.should be engine
- end
-end
-
-module Arel
+module Arel
describe Table do
before do
@relation = Table.new(:users)
@@ -29,21 +8,21 @@ module Arel
describe 'primary_key' do
it 'should return an attribute' do
- check @relation.primary_key.name.should == :id
+ check @relation.primary_key.name.must_equal :id
end
end
describe 'select_manager' do
it 'should return an empty select manager' do
sm = @relation.select_manager
- sm.to_sql.should be_like 'SELECT'
+ sm.to_sql.must_be_like 'SELECT'
end
end
describe 'having' do
it 'adds a having clause' do
mgr = @relation.having @relation[:id].eq(10)
- mgr.to_sql.should be_like %{
+ mgr.to_sql.must_be_like %{
SELECT FROM "users" HAVING "users"."id" = 10
}
end
@@ -52,7 +31,7 @@ module Arel
describe 'backwards compat' do
describe 'joins' do
it 'returns nil' do
- check @relation.joins(nil).should == nil
+ check @relation.joins(nil).must_equal nil
end
end
@@ -60,7 +39,7 @@ module Arel
it 'noops on nil' do
mgr = @relation.join nil
- mgr.to_sql.should be_like %{ SELECT FROM "users" }
+ mgr.to_sql.must_be_like %{ SELECT FROM "users" }
end
it 'takes a second argument for join type' do
@@ -68,7 +47,7 @@ module Arel
predicate = @relation[:id].eq(right[:id])
mgr = @relation.join(right, Nodes::OuterJoin).on(predicate)