File tree Expand file tree Collapse file tree 4 files changed +29
-10
lines changed Expand file tree Collapse file tree 4 files changed +29
-10
lines changed Original file line number Diff line number Diff line change 99require File . expand_path ( '../../../spec/support/detect_rails_version' , __FILE__ )
1010ENV [ "RAILS" ] = detect_rails_version
1111
12+ ENV [ "RAILS_ENV" ] ||= "cucumber"
13+ ENV [ 'RAILS_ROOT' ] = File . expand_path ( "../../../spec/rails/rails-#{ ENV [ "RAILS" ] } " , __FILE__ )
14+
15+
1216require 'rubygems'
1317require "bundler"
1418Bundler . setup
1519
16- ENV [ "RAILS_ENV" ] ||= "cucumber"
17- ENV [ 'RAILS_ROOT' ] = File . expand_path ( "../../../spec/rails/rails-#{ ENV [ "RAILS" ] } " , __FILE__ )
18-
1920# Create the test app if it doesn't exists
2021unless File . exists? ( ENV [ 'RAILS_ROOT' ] )
2122 system 'rake setup'
2223end
2324
25+ # Ensure the Active Admin load path is happy
26+ require 'rails'
27+ require 'active_admin'
28+ ActiveAdmin . application . load_paths = [ ENV [ 'RAILS_ROOT' ] + "/app/admin" ]
29+
2430require ENV [ 'RAILS_ROOT' ] + '/config/environment'
2531
2632# Setup autoloading of ActiveAdmin and the load path
Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ def remove_active_admin_load_paths_from_rails_autoload_and_eager_load
211211 end
212212
213213 def attach_reloader
214- ActiveAdmin ::Reloader . new ( Rails . version ) . attach!
214+ ActiveAdmin ::Reloader . new ( self , Rails . version ) . attach!
215215 end
216216
217217
Original file line number Diff line number Diff line change @@ -6,16 +6,21 @@ class Reloader
66 # @param [String] rails_version
77 # The version of Rails we're using. We use this to switch between
88 # the correcr Rails reloader class.
9- def initialize ( rails_version )
9+ def initialize ( app , rails_version )
10+ @app = app
1011 @rails_version = rails_version . to_s
1112 end
1213
1314 # Attach to Rails and perform the reload on each request.
1415 def attach!
15- reloader_class . to_prepare do
16+ file_update_checker = ActiveSupport :: FileUpdateChecker . new ( @app . load_paths ) do
1617 ActiveAdmin . application . unload!
1718 Rails . application . reload_routes!
1819 end
20+
21+ reloader_class . to_prepare do
22+ file_update_checker . execute_if_updated
23+ end
1924 end
2025
2126 def reloader_class
Original file line number Diff line number Diff line change 44begin
55 ActionDispatch ::Reloader
66rescue
7- module ActionDispatch ; module Reloader ; end ; end
7+ module ActionDispatch ; module Reloader ; def self . to_prepare ; end ; end ; end
88end
99
1010begin
1111 ActionDispatch ::Callbacks
1212rescue
13- module ActionDispatch ; module Callbacks ; end ; end
13+ module ActionDispatch ; module Callbacks ; def self . to_prepare ; end ; end ; end
1414end
1515
1616
1717describe ActiveAdmin ::Reloader do
1818
19+ let ( :mock_app ) { mock ( :load_paths => [ ] ) }
20+
1921 it "should use ActionDispatch::Reloader if rails 3.1" do
20- reloader = ActiveAdmin ::Reloader . new '3.1.0'
22+ reloader = ActiveAdmin ::Reloader . new mock_app , '3.1.0'
2123 reloader . reloader_class . should == ActionDispatch ::Reloader
2224 end
2325
2426 it "should use ActionDispatch::Callbacks if rails 3.0" do
25- reloader = ActiveAdmin ::Reloader . new '3.0.0'
27+ reloader = ActiveAdmin ::Reloader . new mock_app , '3.0.0'
2628 reloader . reloader_class . should == ActionDispatch ::Callbacks
2729 end
30+
31+ it "should initialize a new file update checker" do
32+ ActiveSupport ::FileUpdateChecker . should_receive ( :new ) . with ( mock_app . load_paths ) . and_return ( mock ( :execute_if_updated => true ) )
33+ ActiveAdmin ::Reloader . new ( mock_app , '3.1.0' ) . attach!
34+ end
35+
2836end
You can’t perform that action at this time.
0 commit comments