Created
          July 13, 2016 09:13 
        
      - 
      
 - 
        
Save aranair/15db62fe150944cb5c7fe4053721f537 to your computer and use it in GitHub Desktop.  
    25712
  
        
  
    
      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
    
  
  
    
  | 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 'rails', '4.2.6' | |
| gem 'pg' | |
| end | |
| require 'active_record' | |
| require 'minitest/autorun' | |
| require 'logger' | |
| DB_NAME = '25712' | |
| ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: DB_NAME) | |
| ActiveRecord::Base.logger = Logger.new(STDOUT) | |
| ActiveRecord::Schema.define do | |
| create_table :posts, force: true do |t| | |
| t.integer :author_id | |
| t.integer :status | |
| t.string :name | |
| end | |
| create_table :authors, force: true do |t| | |
| end | |
| end | |
| class Post < ActiveRecord::Base | |
| default_scope { where(name: 'test', status: 1) } | |
| scope :byau, -> (id) { where(author_id: id) } | |
| belongs_to :author | |
| end | |
| class Author < ActiveRecord::Base | |
| end | |
| class BugTest < Minitest::Test | |
| def test_should_not_error | |
| a = Author.create | |
| Post.create(author: a, status: 0) | |
| Post.create(author: a, status: 1) | |
| Post.byau(1).unscope(where: [:name, :status]).where(status: 0).to_a | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment