Created
March 19, 2013 21:36
-
-
Save pivotal-chorus/5200366 to your computer and use it in GitHub Desktop.
`default_scope` breaks chained scopes in Rails 3.2.13
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
## 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 |
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
## app/models/animal.rb | |
class Animal < ActiveRecord::Base | |
default_scope where(:alive => true) | |
attr_accessible :alive | |
end |
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
## 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 |
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
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