Skip to content

Commit

Permalink
Do not generate app/views and sprockets entries on http app
Browse files Browse the repository at this point in the history
[Carlos Antonio da Silva & Santiago Pastorino]
  • Loading branch information
carlosantoniodasilva authored and spastorino committed Mar 14, 2012
1 parent 570cc89 commit 96aea58
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -159,6 +159,10 @@ def initialize(*args)
if !options[:skip_active_record] && !DATABASES.include?(options[:database])
raise Error, "Invalid value for --database option. Supported for preconfiguration are: #{DATABASES.join(", ")}."
end

# Force sprockets to be skipped when generating http only app.
# Can't modify options hash as it's frozen by default.
self.options = options.merge(:skip_sprockets => true).freeze if options.http?
end

public_task :create_root
Expand All @@ -173,6 +177,7 @@ def create_root_files

def create_app_files
build(:app)
remove_file("app/views") if options.http?
end

def create_config_files
Expand Down
17 changes: 16 additions & 1 deletion railties/test/generators/app_generator_test.rb
Expand Up @@ -378,6 +378,22 @@ def test_http_generates_application_controller_with_protect_from_forgery_comment
assert_file "app/controllers/application_controller.rb", /^ # protect_from_forgery/
end

def test_http_does_not_generate_app_views_dir
run_generator [destination_root, "--http"]
assert_no_directory "app/views"
end

def test_http_skip_sprockets_entries_in_gemfile_and_application
run_generator [destination_root, "--http"]
assert_file "Gemfile" do |content|
assert_no_match(/group :assets/, content)
end
assert_file "config/application.rb" do |content|
assert_match(/^# require "sprockets/, content)
assert_no_match(/config\.assets/, content)
end
end

def test_pretend_option
output = run_generator [File.join(destination_root, "myapp"), "--pretend"]
assert_no_match(/run bundle install/, output)
Expand All @@ -388,7 +404,6 @@ def test_pretend_option
def action(*args, &block)
silence(:stdout) { generator.send(*args, &block) }
end

end

class CustomAppGeneratorTest < Rails::Generators::TestCase
Expand Down

0 comments on commit 96aea58

Please sign in to comment.