Skip to content

Fix to generated app file path for coffee & em #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/generators/templates/application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#= require ember-data
#= require active-model-adapter
#= require_self
#= require <%= application_name.underscore %>
#= require ./<%= application_name.underscore.dasherize %>

# for more details see: http://emberjs.com/guides/application/
window.<%= application_name.camelize %> = Ember.Application.create()
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/application.em
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#= require ember-data
#= require active-model-adapter
#= require_self
#= require <%= application_name.underscore %>
#= require ./<%= application_name.underscore.dasherize %>

# for more details see: http://emberjs.com/guides/application/
window.<%= application_name.camelize %> = Ember.Application.create()
52 changes: 32 additions & 20 deletions test/generators/bootstrap_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,72 @@ def prepare_destination
%w(js coffee em es6).each do |engine|

test "create bootstrap with #{engine} engine" do
extension = engine_to_extension(engine)
run_generator ["--javascript-engine=#{engine}"]
assert_file "#{ember_path}/router.#{engine_to_extension(engine)}"
assert_file "#{ember_path}/adapters/application.#{engine_to_extension(engine)}"
assert_file "#{ember_path}/#{application_name.underscore}.#{engine_to_extension(engine)}"
assert_file "#{ember_path}/environment.#{engine_to_extension(engine)}"

assert_file ember_path("router.#{extension}")
assert_file ember_path("adapters/application.#{extension}")
assert_file ember_path("dummy.#{extension}")
assert_file ember_path("environment.#{extension}")

assert_application_file_modified ember_path("application.#{engine}"), 'dummy'
end

test "create bootstrap with #{engine} engine and custom path" do
custom_path = ember_path("custom")
extension = engine_to_extension(engine)
run_generator ["--javascript-engine=#{engine}", "-d", custom_path]
assert_file "#{custom_path}/router.#{engine_to_extension(engine)}"
assert_file "#{custom_path}/adapters/application.#{engine_to_extension(engine)}"
assert_file "#{custom_path}/#{application_name.underscore}.#{engine_to_extension(engine)}"
assert_file "#{custom_path}/environment.#{engine_to_extension(engine)}"

assert_file "#{custom_path}/router.#{extension}"
assert_file "#{custom_path}/adapters/application.#{extension}"
assert_file "#{custom_path}/dummy.#{extension}"
assert_file "#{custom_path}/environment.#{extension}"

assert_application_file_modified "#{custom_path}/application.#{engine}", 'dummy'
end

test "create bootstrap with #{engine} and custom app name" do
extension = engine_to_extension(engine)
run_generator ["--javascript-engine=#{engine}", "-n", "MyApp"]
assert_file "#{ember_path}/router.#{engine_to_extension(engine)}", /MyApp\.Router\.map|Ember\.Router\.extend/
assert_file "#{ember_path}/adapters/application.#{engine_to_extension(engine)}", /MyApp\.ApplicationAdapter|DS\.ActiveModelAdapter\.extend/
assert_file "#{ember_path}/my-app.#{engine_to_extension(engine)}"
assert_file "#{ember_path}/environment.#{engine_to_extension(engine)}"

assert_file ember_path("router.#{extension}"), /MyApp\.Router\.map|Ember\.Router\.extend/
assert_file ember_path("adapters/application.#{extension}"), /MyApp\.ApplicationAdapter|DS\.ActiveModelAdapter\.extend/
assert_file ember_path("my-app.#{extension}")
assert_file ember_path("environment.#{extension}")

assert_application_file_modified ember_path("application.#{engine}"), 'my-app'
end

end

test "adds requires to `application.js`" do
run_generator

assert_application_file_modified
assert_application_file_modified ember_path('application.js'), 'dummy'
end

test "creates `application.js` if it doesn't exist" do
File.delete destination_root + '/app/assets/javascripts/application.js'

run_generator

assert_application_file_modified
assert_application_file_modified ember_path('application.js'), 'dummy'
end

test "modifies `application.js` it's empty" do
File.write(destination_root + '/app/assets/javascripts/application.js', '')

run_generator

assert_application_file_modified
assert_application_file_modified ember_path('application.js'), 'dummy'
end

test "modifies `application.js` if require_tree doesn't exist and there's no new line" do
File.write(destination_root + '/app/assets/javascripts/application.js', '//= require jquery')

run_generator

assert_application_file_modified
assert_application_file_modified ember_path('application.js'), 'dummy'
end

test "Uses config.ember.app_name as the app name" do
Expand Down Expand Up @@ -118,10 +130,10 @@ def prepare_destination

private

def assert_application_file_modified(application_file = ember_path('application.js'))
assert_file application_file, %r{//= require ember}
assert_file application_file, %r{//= require ember-data}
assert_file application_file, %r{//= require ./#{application_name.underscore}}
def assert_application_file_modified(application_file, application_name)
assert_file application_file, %r{(?://|#)= require ember}
assert_file application_file, %r{(?://|#)= require ember-data}
assert_file application_file, %r{(?://|#)= require \./#{application_name}}
end

def assert_invoked_generators_files(options = {})
Expand Down