mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
make it possible to access fixtures excluded by a default_scope
.
Prior to this patch you'd end up with an error like: ``` ActiveRecord::RecordNotFound: Couldn't find <Model> with 'id'=<id> [WHERE (<default_scope condition>)] ```
This commit is contained in:
parent
8613b31627
commit
f766abd4cf
4 changed files with 24 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
* Make it possible to access fixtures excluded by a `default_scope`.
|
||||
|
||||
*Yves Senn*
|
||||
|
||||
* Add `Table#name` to match `TableDefinition#name`.
|
||||
|
||||
*Cody Cutrer*
|
||||
|
|
|
@ -806,7 +806,7 @@ module ActiveRecord
|
|||
|
||||
def find
|
||||
if model_class
|
||||
model_class.find(fixture[model_class.primary_key])
|
||||
model_class.unscoped.find(fixture[model_class.primary_key])
|
||||
else
|
||||
raise FixtureClassNotFound, "No class attached to find."
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ require 'models/admin/randomly_named_c1'
|
|||
require 'models/admin/user'
|
||||
require 'models/binary'
|
||||
require 'models/book'
|
||||
require 'models/bulb'
|
||||
require 'models/category'
|
||||
require 'models/company'
|
||||
require 'models/computer'
|
||||
|
@ -853,3 +854,16 @@ class CustomNameForFixtureOrModelTest < ActiveRecord::TestCase
|
|||
assert_equal 'randomly_named_table', Admin::ClassNameThatDoesNotFollowCONVENTIONS.table_name
|
||||
end
|
||||
end
|
||||
|
||||
class FixturesWithDefaultScopeTest < ActiveRecord::TestCase
|
||||
fixtures :bulbs
|
||||
|
||||
test "inserts fixtures excluded by a default scope" do
|
||||
assert_equal 1, Bulb.count
|
||||
assert_equal 2, Bulb.unscoped.count
|
||||
end
|
||||
|
||||
test "allows access to fixtures excluded by a default scope" do
|
||||
assert_equal "special", bulbs(:special).name
|
||||
end
|
||||
end
|
||||
|
|
5
activerecord/test/fixtures/bulbs.yml
vendored
Normal file
5
activerecord/test/fixtures/bulbs.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
defaulty:
|
||||
name: defaulty
|
||||
|
||||
special:
|
||||
name: special
|
Loading…
Reference in a new issue