Created
February 9, 2015 18:43
-
-
Save stiff/e967dc2bc7ab1eb21e04 to your computer and use it in GitHub Desktop.
Rails 4 issue 18862 test
This file contains 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
# Activate the gem you are reporting the issue against. | |
gem 'activerecord', '4.2.0' | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# This connection will do for database-independent bug reports. | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :bookings do |t| | |
t.integer :client_id | |
t.string :status | |
t.datetime :start_time | |
end | |
end | |
class Booking < ActiveRecord::Base | |
scope :cancelled, -> { where(:status => :cancelled) } | |
scope :by_new_client, -> { a = arel_table.alias; where(:start_time => Booking.select('min(bookings_2.start_time)').from(a).where(:client_id => a[:client_id])) } | |
end | |
class BugTest < Minitest::Test | |
def test_scopes_order_doesnt_matter | |
sql1 = Booking.cancelled.by_new_client.to_sql | |
sql2 = Booking.by_new_client.cancelled.to_sql | |
assert sql1 == sql2, 'Generated SQL must be the same' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment