File tree Expand file tree Collapse file tree 4 files changed +29
-1
lines changed
activerecord/lib/active_record Expand file tree Collapse file tree 4 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
21
21
#
22
22
# They are stored in YAML files, one file per model, which are placed in the directories
23
23
# appointed by <tt>ActiveSupport::TestCase.fixture_paths=(path)</tt> (this is automatically
24
- # configured for Rails, so you can just put your files in <tt><your-rails-app>/test/fixtures/</tt>).
24
+ # configured for Rails, so you can just put your files in <tt><your-rails-app>/test/fixtures/</tt>,
25
+ # or in the <tt>test/fixtures</tt> folder under any of your application's engines).
25
26
# The fixture file ends with the +.yml+ file extension, for example:
26
27
# <tt><your-rails-app>/test/fixtures/web_sites.yml</tt>).
27
28
#
Original file line number Diff line number Diff line change
1
+ * Add engine's ` test/fixtures ` path to ` fixture_paths ` in ` on_load ` hook if
2
+ path exists and is under the Rails application root.
3
+
4
+ * Chris Salzberg*
5
+
1
6
* ` bin/rails app:template ` now runs ` bundle install ` and any ` after_bundle `
2
7
blocks after the template is executed.
3
8
Original file line number Diff line number Diff line change @@ -615,6 +615,15 @@ def load_seed
615
615
end
616
616
end
617
617
618
+ initializer :add_fixture_paths do
619
+ next if is_a? ( Rails ::Application )
620
+
621
+ fixtures = config . root . join ( "test" , "fixtures" )
622
+ if fixtures . exist? && fixtures . to_s . start_with? ( Rails . root . to_s )
623
+ ActiveSupport . on_load ( :active_record_fixtures ) { self . fixture_paths |= [ "#{ fixtures } /" ] }
624
+ end
625
+ end
626
+
618
627
initializer :prepend_helpers_path do |app |
619
628
if !isolated? || ( app == self )
620
629
app . config . helpers_paths . unshift ( *paths [ "app/helpers" ] . existent )
Original file line number Diff line number Diff line change @@ -304,6 +304,19 @@ def index
304
304
assert_equal "Hi bukkits\n " , response [ 2 ] . body
305
305
end
306
306
307
+ test "adds its fixtures path to fixture_paths" do
308
+ @plugin . write "test/fixtures/bukkits.yml" , ""
309
+
310
+ boot_rails
311
+
312
+ test_class = Class . new
313
+ test_class . singleton_class . attr_accessor :fixture_paths
314
+ test_class . fixture_paths = [ ]
315
+ ActiveSupport . run_load_hooks ( :active_record_fixtures , test_class )
316
+
317
+ assert_equal test_class . fixture_paths , [ "#{ Bukkits ::Engine . root } /test/fixtures/" ]
318
+ end
319
+
307
320
test "adds its mailer previews to mailer preview paths" do
308
321
@plugin . write "app/mailers/bukkit_mailer.rb" , <<-RUBY
309
322
class BukkitMailer < ActionMailer::Base
You can’t perform that action at this time.
0 commit comments