Skip to content

Instantly share code, notes, and snippets.

@rzane
Created July 20, 2016 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rzane/2a331dad471e8a299a5da8d0a6ec80bc to your computer and use it in GitHub Desktop.
Save rzane/2a331dad471e8a299a5da8d0a6ec80bc to your computer and use it in GitHub Desktop.
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