Skip to content

Commit

Permalink
[GH-367] - Adds support to initializers.
Browse files Browse the repository at this point in the history
  - For more information: #367
  • Loading branch information
lucasallan committed Oct 29, 2015
1 parent 86df96b commit 1358837
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/lotus/commands/new/app.rb
Expand Up @@ -68,6 +68,7 @@ def add_test_templates
end

def add_empty_directories
add_mapping('.gitkeep', 'config/initializers/.gitkeep')
add_mapping('.gitkeep', 'app/controllers/.gitkeep')
add_mapping('.gitkeep', 'app/views/.gitkeep')
add_mapping('.gitkeep', "lib/#{ app_name }/entities/.gitkeep")
Expand Down
1 change: 1 addition & 0 deletions lib/lotus/commands/new/container.rb
Expand Up @@ -61,6 +61,7 @@ def add_test_templates
end

def add_empty_directories
add_mapping('.gitkeep', 'config/initializers/.gitkeep')
add_mapping('.gitkeep', "lib/#{ app_name }/entities/.gitkeep")
add_mapping('.gitkeep', "lib/#{ app_name }/repositories/.gitkeep")
add_mapping('.gitkeep', "lib/#{ app_name }/mailers/.gitkeep")
Expand Down
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions lib/lotus/loader.rb
Expand Up @@ -31,6 +31,7 @@ def load!
load_configuration_load_paths!
load_rack!
load_frameworks!
load_initializers!
end
end

Expand Down Expand Up @@ -211,5 +212,11 @@ def application_routes
def namespace
configuration.namespace || application_module
end

def load_initializers!
Dir["#{configuration.root}/config/initializers/**/*.rb"].each do |file|
require file
end
end
end
end
1 change: 1 addition & 0 deletions test/commands/new/app_test.rb
Expand Up @@ -89,6 +89,7 @@ def assert_generated_app(test_framework, original_wd)
assert_file_exists('.git')
assert_file_exists('app/controllers/.gitkeep')
assert_file_exists('app/views/.gitkeep')
assert_file_exists('config/initializers/.gitkeep')
assert_file_exists('lib/new_app/entities/.gitkeep')
assert_file_exists('lib/new_app/repositories/.gitkeep')
assert_file_exists('lib/new_app/mailers/.gitkeep')
Expand Down
1 change: 1 addition & 0 deletions test/commands/new/container_test.rb
Expand Up @@ -251,6 +251,7 @@ def assert_generated_container(test_framework, original_wd)
assert_generated_file(fixture_root.join('config', 'environment.rb'), 'config/environment.rb')
assert_generated_file(fixture_root.join('lib', 'new_container.rb'), 'lib/new_container.rb')
assert_generated_file(fixture_root.join('lib', 'config', 'mapping.rb'), 'lib/config/mapping.rb')
assert_file_exists('config/initializers/.gitkeep')
assert_file_exists('lib/new_container/entities/.gitkeep')
assert_file_exists('lib/new_container/repositories/.gitkeep')
assert_file_exists('lib/new_container/mailers/.gitkeep')
Expand Down
9 changes: 9 additions & 0 deletions test/loader_test.rb
Expand Up @@ -136,6 +136,15 @@ class Application < Lotus::Application
end
end

describe 'initializers' do

it 'loads all the initializers' do
assert_equal defined?(CollaborationInitializer1), 'constant'
assert_equal defined?(CollaborationInitializer2), 'constant'
end

end

# describe 'finalization' do
# it 'freeze CoffeeShop::View' do
# CoffeeShop::View.configuration.root.must_be :frozen?
Expand Down
5 changes: 4 additions & 1 deletion test/test_helper.rb
Expand Up @@ -91,8 +91,11 @@ def empty?
Lotus::Middleware.class_eval { attr_reader :stack }

Pathname.new(File.dirname(__FILE__)).join('../tmp/coffee_shop/app/templates').mkpath

Pathname.new(File.dirname(__FILE__)).join('../tmp/coffee_shop/app/templates/mailers').mkpath
Pathname.new(File.dirname(__FILE__)).join('../tmp/coffee_shop/config/initializers/').mkpath

File.open("#{File.dirname(__FILE__)}/../tmp/coffee_shop/config/initializers/init1.rb", 'w') { |f| f.write('class CollaborationInitializer1; end;') }
File.open("#{File.dirname(__FILE__)}/../tmp/coffee_shop/config/initializers/init2.rb", 'w') { |f| f.write('class CollaborationInitializer2; end;') }

class FakeRackBuilder
attr_reader :stack
Expand Down

0 comments on commit 1358837

Please sign in to comment.