Skip to content

Commit

Permalink
bah travis
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhempel committed Apr 2, 2019
1 parent 19f1137 commit 3cb6e38
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rails_5_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ gem 'rails', '~> 5.1.0'
# https://bitbucket.org/ged/ruby-pg/issues/270/pg-100-x64-mingw32-rails-server-not-start
gem 'pg', '~> 0.21'

gem 'sqlite3', '~> 1.4.0'
gem 'sqlite3', '~> 1.3.6'
2 changes: 1 addition & 1 deletion rails_5_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ gem 'rails', '~> 5.2.0'

gem 'pg'

gem 'sqlite3', '~> 1.4.0'
gem 'sqlite3', '~> 1.3.6'
36 changes: 27 additions & 9 deletions spec/union_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,31 @@ class PublishedPost < ActiveRecord::Base

context "in SQLite" do
it "lets ORDER BY in query subselects throw a syntax error" do
expect(union.to_sql.squish).to eq(
"SELECT \"posts\".* FROM ( SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = 1 ORDER BY \"posts\".\"created_at\" ASC UNION SELECT \"posts\".* FROM \"posts\" WHERE (created_at > '#{SQL_TIME}') ORDER BY \"posts\".\"created_at\" ASC ) \"posts\" ORDER BY \"posts\".\"created_at\" ASC"
)
if ([ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] <=> [5, 2]) >= 0
expect(union.to_sql.squish).to eq(
"SELECT \"posts\".* FROM ( SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = 1 ORDER BY \"posts\".\"created_at\" ASC UNION SELECT \"posts\".* FROM \"posts\" WHERE (created_at > '2014-07-19 00:00:00') ORDER BY \"posts\".\"created_at\" ASC ) \"posts\" ORDER BY \"created_at\" ASC"
)
else
expect(union.to_sql.squish).to eq(
"SELECT \"posts\".* FROM ( SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = 1 ORDER BY \"posts\".\"created_at\" ASC UNION SELECT \"posts\".* FROM \"posts\" WHERE (created_at > '#{SQL_TIME}') ORDER BY \"posts\".\"created_at\" ASC ) \"posts\" ORDER BY \"posts\".\"created_at\" ASC"
)
end
expect{union.to_a}.to raise_error(ActiveRecord::StatementInvalid)
end
end

context "in Postgres" do
it "wraps query subselects in parentheses to allow ORDER BY clauses" do
Databases.with_postgres do
expect(union.to_sql.squish).to eq(
"SELECT \"posts\".* FROM ( (SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = 1 ORDER BY \"posts\".\"created_at\" ASC) UNION (SELECT \"posts\".* FROM \"posts\" WHERE (created_at > '#{SQL_TIME}') ORDER BY \"posts\".\"created_at\" ASC) ) \"posts\" ORDER BY \"posts\".\"created_at\" ASC"
)
if ([ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] <=> [5, 2]) >= 0
expect(union.to_sql.squish).to eq(
"SELECT \"posts\".* FROM ( (SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = 1 ORDER BY \"posts\".\"created_at\" ASC) UNION (SELECT \"posts\".* FROM \"posts\" WHERE (created_at > '2014-07-19 00:00:00') ORDER BY \"posts\".\"created_at\" ASC) ) \"posts\" ORDER BY \"created_at\" ASC"
)
else
expect(union.to_sql.squish).to eq(
"SELECT \"posts\".* FROM ( (SELECT \"posts\".* FROM \"posts\" WHERE \"posts\".\"user_id\" = 1 ORDER BY \"posts\".\"created_at\" ASC) UNION (SELECT \"posts\".* FROM \"posts\" WHERE (created_at > '#{SQL_TIME}') ORDER BY \"posts\".\"created_at\" ASC) ) \"posts\" ORDER BY \"posts\".\"created_at\" ASC"
)
end
expect{union.to_a}.to_not raise_error
end
end
Expand All @@ -126,9 +138,15 @@ class PublishedPost < ActiveRecord::Base
context "in MySQL" do
it "wraps query subselects in parentheses to allow ORDER BY clauses" do
Databases.with_mysql do
expect(union.to_sql.squish).to eq(
"SELECT `posts`.* FROM ( (SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` = 1 ORDER BY `posts`.`created_at` ASC) UNION (SELECT `posts`.* FROM `posts` WHERE (created_at > '#{SQL_TIME}') ORDER BY `posts`.`created_at` ASC) ) `posts` ORDER BY `posts`.`created_at` ASC"
)
if ([ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR] <=> [5, 2]) >= 0
expect(union.to_sql.squish).to eq(
"SELECT `posts`.* FROM ( (SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` = 1 ORDER BY `posts`.`created_at` ASC) UNION (SELECT `posts`.* FROM `posts` WHERE (created_at > '2014-07-19 00:00:00') ORDER BY `posts`.`created_at` ASC) ) `posts` ORDER BY `created_at` ASC"
)
else
expect(union.to_sql.squish).to eq(
"SELECT `posts`.* FROM ( (SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` = 1 ORDER BY `posts`.`created_at` ASC) UNION (SELECT `posts`.* FROM `posts` WHERE (created_at > '#{SQL_TIME}') ORDER BY `posts`.`created_at` ASC) ) `posts` ORDER BY `posts`.`created_at` ASC"
)
end
expect{union.to_a}.to_not raise_error
end
end
Expand Down

0 comments on commit 3cb6e38

Please sign in to comment.