Last active
January 1, 2016 10:19
-
-
Save fruchtose/8130334 to your computer and use it in GitHub Desktop.
Test case for issue https://github.com/rails/rails/issues/13479,"array literals ignored in ActiveRecord#where" by BenLubar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless File.exist?('Gemfile') | |
File.write('Gemfile', <<-GEMFILE) | |
source 'https://rubygems.org' | |
gem 'rails', github: 'rails/rails' | |
gem 'arel', github: 'rails/arel' | |
gem 'pg' | |
GEMFILE | |
system 'bundle' | |
end | |
require 'bundler' | |
Bundler.setup(:default) | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
require 'pg' | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'testdb') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :figures do |t| | |
t.string :spheres, array: true, null: false, default: [] | |
end | |
end unless ActiveRecord::Base.connection.table_exists?('figures') | |
class Figure < ActiveRecord::Base | |
end | |
Figure.create(spheres: ['1', '2']) | |
class BugTest < Minitest::Test | |
def test_where_empty_ary | |
refute_match /WHERE 1=0/, Figure.where(spheres: []).to_sql | |
end | |
def test_where_not_empty_ary | |
refute_match /WHERE \(1=1\)/, Figure.where.not(spheres: []).to_sql | |
end | |
def test_where_nested_ary | |
test_sql = Figure.where(spheres: [[]]).to_sql | |
result = begin | |
ActiveRecord::Base.connection.execute test_sql | |
'ok' | |
rescue ActiveRecord::StatementInvalid | |
$! | |
end | |
assert_equal result, 'ok' | |
end | |
def test_where_ary | |
test_sql = Figure.where(spheres: ['1', '2']).to_sql | |
result = begin | |
ActiveRecord::Base.connection.execute test_sql | |
'ok' | |
rescue ActiveRecord::StatementInvalid | |
$! | |
end | |
assert_equal result, 'ok' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment