2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
require "generators/generators_test_helper"
|
|
|
|
require "rails/generators/rails/helper/helper_generator"
|
2014-08-05 07:59:41 -04:00
|
|
|
|
|
|
|
ObjectHelper = Class.new
|
|
|
|
AnotherObjectHelperTest = Class.new
|
|
|
|
|
|
|
|
class HelperGeneratorTest < Rails::Generators::TestCase
|
|
|
|
include GeneratorsTestHelper
|
|
|
|
arguments %w(admin)
|
|
|
|
|
|
|
|
def test_helper_skeleton_is_created
|
|
|
|
run_generator
|
|
|
|
assert_file "app/helpers/admin_helper.rb", /module AdminHelper/
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_check_class_collision
|
2016-08-16 03:30:11 -04:00
|
|
|
content = capture(:stderr) { run_generator ["object"] }
|
2014-08-05 07:59:41 -04:00
|
|
|
assert_match(/The name 'ObjectHelper' is either already used in your application or reserved/, content)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_namespaced_and_not_namespaced_helpers
|
|
|
|
run_generator ["products"]
|
|
|
|
|
|
|
|
# We have to require the generated helper to show the problem because
|
|
|
|
# the test helpers just check for generated files and contents but
|
|
|
|
# do not actually load them. But they have to be loaded (as in a real environment)
|
|
|
|
# to make the second generator run fail
|
|
|
|
require "#{destination_root}/app/helpers/products_helper"
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
begin
|
|
|
|
run_generator ["admin::products"]
|
|
|
|
ensure
|
|
|
|
# cleanup
|
|
|
|
Object.send(:remove_const, :ProductsHelper)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|