Skip to content
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

set engine's route in the functional test is generated in the engine #20387

Merged
merged 3 commits into from
Jun 2, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

<% module_namespacing do -%>
class <%= class_name %>ControllerTest < ActionController::TestCase
<% if defined?(ENGINE_ROOT) -%>
setup do
@routes = Engine.routes
end

<% end -%>
<% if actions.empty? -%>
# test "the truth" do
# assert true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def create_test_files
File.join("test/controllers", controller_class_path, "#{controller_file_name}_controller_test.rb")
end

def fixture_name
@fixture_name ||=
if defined?(ENGINE_ROOT)
namespaced_path + "_" + table_name
else
table_name
end
end

private

def attributes_hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<% module_namespacing do -%>
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
setup do
@<%= singular_table_name %> = <%= table_name %>(:one)
@<%= singular_table_name %> = <%= fixture_name %>(:one)
<% if defined?(ENGINE_ROOT) -%>
@routes = Engine.routes
<% end -%>
end

test "should get index" do
Expand Down
11 changes: 11 additions & 0 deletions railties/test/generators/scaffold_controller_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,15 @@ def test_model_name_option
end
end
end

def test_controller_tests_pass_by_default_inside_mountable_engine
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --mountable` }

engine_path = File.join(destination_root, "bukkits")

Dir.chdir(engine_path) do
quietly { `bin/rails g controller dashboard foo` }
assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
end
end
end
14 changes: 14 additions & 0 deletions railties/test/generators/scaffold_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,18 @@ def test_scaffold_generator_password_digest
assert_match(/password_digest: <%= BCrypt::Password.create\('secret'\) %>/, content)
end
end

def test_scaffold_tests_pass_by_default_inside_mountable_engine
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --mountable` }

engine_path = File.join(destination_root, "bukkits")

Dir.chdir(engine_path) do
quietly do
`bin/rails g scaffold User name:string age:integer;
bundle exec rake db:migrate`
end
assert_match(/8 runs, 13 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`)
end
end
end