From e42506f9ea58511246f638e81002947ee3c36b18 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 20 Oct 2010 17:16:18 -0700 Subject: adding default limits when there is an offset for sqlite and mysql [#5316 state:resolved] --- test/support/fake_record.rb | 2 +- test/test_table.rb | 7 +++++++ test/visitors/test_mysql.rb | 21 +++++++++++++++++++++ test/visitors/test_sqlite.rb | 18 ++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/visitors/test_mysql.rb create mode 100644 test/visitors/test_sqlite.rb (limited to 'test') diff --git a/test/support/fake_record.rb b/test/support/fake_record.rb index ef3cc6a291..e0f9685c05 100644 --- a/test/support/fake_record.rb +++ b/test/support/fake_record.rb @@ -66,7 +66,7 @@ module FakeRecord attr_reader :spec, :connection def initialize - @spec = Spec.new(:adapter => 'sqlite3') + @spec = Spec.new(:adapter => 'america') @connection = Connection.new end diff --git a/test/test_table.rb b/test/test_table.rb index 9a275402cb..d34383922c 100644 --- a/test/test_table.rb +++ b/test/test_table.rb @@ -6,6 +6,13 @@ module Arel @relation = Table.new(:users) end + describe 'skip' do + it 'should add an offset' do + sm = @relation.skip 2 + sm.to_sql.must_be_like "SELECT FROM \"users\" OFFSET 2" + end + end + describe 'primary_key' do it 'should return an attribute' do @relation.primary_key.name.must_equal :id diff --git a/test/visitors/test_mysql.rb b/test/visitors/test_mysql.rb new file mode 100644 index 0000000000..1d38161caf --- /dev/null +++ b/test/visitors/test_mysql.rb @@ -0,0 +1,21 @@ +require 'helper' + +module Arel + module Visitors + describe 'the mysql visitor' do + before do + @visitor = MySQL.new Table.engine + end + + ### + # :'( + # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214 + it 'defaults limit to 18446744073709551615' do + stmt = Nodes::SelectStatement.new + stmt.offset = Nodes::Offset.new(1) + sql = @visitor.accept(stmt) + sql.must_be_like "SELECT LIMIT 18446744073709551615 OFFSET 1" + end + end + end +end diff --git a/test/visitors/test_sqlite.rb b/test/visitors/test_sqlite.rb new file mode 100644 index 0000000000..fb8392c504 --- /dev/null +++ b/test/visitors/test_sqlite.rb @@ -0,0 +1,18 @@ +require 'helper' + +module Arel + module Visitors + describe 'the sqlite visitor' do + before do + @visitor = SQLite.new Table.engine + end + + it 'defaults limit to -1' do + stmt = Nodes::SelectStatement.new + stmt.offset = Nodes::Offset.new(1) + sql = @visitor.accept(stmt) + sql.must_be_like "SELECT LIMIT -1 OFFSET 1" + end + end + end +end -- cgit v1.2.3