Skip to content

Instantly share code, notes, and snippets.

@simpl1g
Created October 28, 2015 14:25
Show Gist options
  • Save simpl1g/2932182f24147665498c to your computer and use it in GitHub Desktop.
Save simpl1g/2932182f24147665498c to your computer and use it in GitHub Desktop.
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'activerecord', '4.2.4'
gem 'sqlite3'
gem 'pg'
end
require 'active_record'
require 'minitest/autorun'
require 'logger'
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
database_configuration = {
adapter: 'postgresql',
database: 'rails_issues',
username: 'konstantin',
password: 'postgres',
host: 'localhost'
}
adapter_tasker = ActiveRecord::Tasks::PostgreSQLDatabaseTasks.new(database_configuration.stringify_keys)
adapter_tasker.drop
adapter_tasker.create
ActiveRecord::Schema.define do
create_table :users do |t|
t.string :status
t.string :gender
end
end
class User < ActiveRecord::Base
scope :active, -> { where(status: :active) }
scope :male, -> { where(gender: :male) }
def self.custom_arel_scope
# Compose two scopes and JOIN with OR
where(active.male.where_values.reduce(:or))
end
end
class BugTest < Minitest::Test
def test_pg_binding
assert User.custom_arel_scope.to_a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment