Created
July 20, 2016 01:38
-
-
Save rzane/2a331dad471e8a299a5da8d0a6ec80bc to your computer and use it in GitHub Desktop.
An attempt at reproducing https://github.com/rzane/baby_squeel/issues/16
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
require 'bundler/inline' | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
gemfile true do | |
source 'https://rubygems.org' | |
gem 'activerecord', '~> 5.0.0' | |
gem 'sqlite3' | |
gem 'baby_squeel', github: 'rzane/baby_squeel' | |
end | |
ActiveRecord::Base.establish_connection( | |
adapter: 'sqlite3', | |
database: ':memory:' | |
) | |
ActiveRecord::Schema.define do | |
create_table :owners, force: true | |
create_table :dogs, force: true do |t| | |
t.string :name | |
t.string :breed | |
t.belongs_to :owner | |
end | |
end | |
BabySqueel.enable_compatibility! | |
class Owner < ActiveRecord::Base | |
has_one :dog | |
end | |
class Dog < ActiveRecord::Base | |
belongs_to :owner | |
end | |
class BabySqueelTest < Minitest::Spec | |
let(:dog_name) { 'foo' } | |
let(:dog_breed) { 'bar' } | |
it 'works' do | |
scope = Owner.all | |
scope = scope.joins { dog }.where { dog.name == my { dog_name } } | |
scope = scope.joins { dog }.where { dog.breed == my { dog_breed } } | |
scope.to_sql.must_equal %{ | |
SELECT "owners".* FROM "owners" | |
INNER JOIN "dogs" ON "dogs"."owner_id" = "owners"."id" | |
WHERE "dogs"."name" = 'foo' AND "dogs"."breed" = 'bar' | |
}.squish | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment