Skip to content

Instantly share code, notes, and snippets.

@pivotal-chorus
Created March 19, 2013 21:36
Show Gist options
  • Save pivotal-chorus/5200366 to your computer and use it in GitHub Desktop.
Save pivotal-chorus/5200366 to your computer and use it in GitHub Desktop.
`default_scope` breaks chained scopes in Rails 3.2.13
## db/migrate/20130319164401_create_animals.rb
class CreateAnimals < ActiveRecord::Migration
def change
create_table :animals do |t|
t.boolean :alive
t.timestamps
end
end
end
## app/models/animal.rb
class Animal < ActiveRecord::Base
default_scope where(:alive => true)
attr_accessible :alive
end
## spec/models/animal_spec.rb
require 'spec_helper'
describe Animal do
describe 'chained scopes' do
it 'chains them' do
first = Animal.create!(:alive => true)
expect {
Animal.where(:id => 12345).find(first.id)
}.to raise_error(ActiveRecord::RecordNotFound) # works with 3.2.12
end
end
end
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'activerecord-jdbcpostgresql-adapter'
gem 'rspec'
gem 'rspec-rails'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment