1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/test/generators/plugin_test_helper.rb
Jonathan Hefner 330becbdd0 Fix asset pipeline errors for plugin dummy apps
To fix #43920, f292daad70 added
`sprockets-rails` to the generated `Gemfile` for engine plugins because
their dummy apps use Sprockets.  However, non-engine plugins exhibit the
same issue because their dummy apps also use Sprockets.

This commit forces `skip_asset_pipeline` to be true when a plugin is not
an engine, and fixes several tests that failed to detect these issues
because they were accidentally using the `rails/rails` `Gemfile` instead
of the generated plugin `Gemfile`.
2022-01-05 15:50:43 -06:00

37 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require "abstract_unit"
require "tmpdir"
module PluginTestHelper
def create_test_file(name, pass: true)
plugin_file "test/#{name}_test.rb", <<-RUBY
require "test_helper"
class #{name.camelize}Test < ActiveSupport::TestCase
def test_truth
puts "#{name.camelize}Test"
assert #{pass}, 'wups!'
end
end
RUBY
end
def plugin_file(path, contents, mode: "w")
FileUtils.mkdir_p File.dirname("#{plugin_path}/#{path}")
File.open("#{plugin_path}/#{path}", mode) do |f|
f.puts contents
end
end
def fill_in_gemspec_fields(gemspec_path = "#{plugin_path}/#{File.basename plugin_path}.gemspec")
# Some fields must be a valid URL.
filled_in = File.read(gemspec_path).gsub(/"TODO.*"/, "http://example.com".inspect)
File.write(gemspec_path, filled_in)
end
def resolve_rails_gem_to_repository(gemfile_path = "#{plugin_path}/Gemfile")
repository_path = File.expand_path("../../..", __dir__)
File.write(gemfile_path, "gem 'rails', path: #{repository_path.inspect}\n", mode: "a")
end
end