提交 3b2ee3b2 编写于 作者: J José Valim

Merge pull request #1288 from guilleiguaran/railties-deprecations

Remove Railties deprecated methods
Description:
Stubs out a new plugin at vendor/plugins. Pass the plugin name, either
CamelCased or under_scored, as an argument.
Example:
`rails generate plugin BrowserFilters`
creates a standard browser_filters plugin:
vendor/plugins/browser_filters/README
vendor/plugins/browser_filters/init.rb
vendor/plugins/browser_filters/install.rb
vendor/plugins/browser_filters/lib/browser_filters.rb
vendor/plugins/browser_filters/test/browser_filters_test.rb
require 'rails/generators/rails/generator/generator_generator'
module Rails
module Generators
class PluginGenerator < NamedBase
class_option :tasks, :desc => "When supplied creates tasks base files."
def show_deprecation
return unless behavior == :invoke
message = "Plugin generator is deprecated, please use 'rails plugin new' command to generate plugin structure."
ActiveSupport::Deprecation.warn message
end
check_class_collision
def create_root_files
directory '.', plugin_dir, :recursive => false
end
def create_lib_files
directory 'lib', plugin_dir('lib'), :recursive => false
end
def create_tasks_files
return unless options[:tasks]
directory 'lib/tasks', plugin_dir('lib/tasks')
end
hook_for :generator do |generator|
inside plugin_dir, :verbose => true do
invoke generator, [ name ], :namespace => false
end
end
hook_for :test_framework do |test_framework|
inside plugin_dir, :verbose => true do
invoke test_framework
end
end
protected
def plugin_dir(join=nil)
if join
File.join(plugin_dir, join)
else
"vendor/plugins/#{file_name}"
end
end
end
end
end
Copyright (c) <%= Date.today.year %> [name of plugin creator]
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<%= class_name %>
<%= "=" * class_name.size %>
Introduction goes here.
Example
=======
Example goes here.
Copyright (c) <%= Date.today.year %> [name of plugin creator], released under the MIT license
#!/usr/bin/env rake
require 'rake/testtask'
require 'rdoc/task'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the <%= file_name %> plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the <%= file_name %> plugin.'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = '<%= class_name %>'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
# desc "Explaining what the task does"
# task :<%= file_name %> do
# # Task goes here
# end
......@@ -2,24 +2,6 @@
module Rails
module Paths
module PathParent #:nodoc:
def method_missing(id, *args)
match = id.to_s.match(/^(.*)=$/)
full = [@current, $1 || id].compact.join("/")
ActiveSupport::Deprecation.warn 'config.paths.app.controller API is deprecated in ' <<
'favor of config.paths["app/controller"] API.'
if match || args.any?
@root[full] = Path.new(@root, full, *args)
elsif path = @root[full]
path
else
super
end
end
end
# This object is an extended hash that behaves as root of the Rails::Paths system.
# It allows you to collect information about how you want to structure your application
# paths by a Hash like API. It requires you to give a physical path on initialization.
......@@ -63,7 +45,6 @@ def method_missing(id, *args)
#
# Check the Path documentation for more information.
class Root < ::Hash
include PathParent
attr_accessor :path
def initialize(path)
......@@ -121,8 +102,6 @@ def filter_by(constraint)
end
class Path < Array
include PathParent
attr_reader :path
attr_accessor :glob
......@@ -194,11 +173,6 @@ def existent
expanded.select { |f| File.exists?(f) }
end
def paths
ActiveSupport::Deprecation.warn "paths is deprecated. Please call expand instead."
expanded
end
alias to_a expanded
end
end
......
......@@ -26,11 +26,6 @@ def app_generators
@@app_generators
end
def generators(&block) #:nodoc
ActiveSupport::Deprecation.warn "config.generators in Rails::Railtie is deprecated. Please use config.app_generators instead."
app_generators(&block)
end
# First configurable block to run. Called before any initializers are run.
def before_configuration(&block)
ActiveSupport.on_load(:before_configuration, :yield => true, &block)
......
......@@ -61,7 +61,7 @@ def assert_not_in_load_path(*path)
end
test "environments has a glob equal to the current environment" do
assert_equal "#{Rails.env}.rb", @paths.config.environments.glob
assert_equal "#{Rails.env}.rb", @paths["config/environments"].glob
end
test "load path includes each of the paths in config.paths as long as the directories exist" do
......
require 'generators/generators_test_helper'
require 'rails/generators/rails/plugin/plugin_generator'
class PluginGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper
arguments %w(plugin_fu)
def test_plugin_skeleton_is_created
silence(:stderr) { run_generator }
year = Date.today.year
%w(
vendor/plugins
vendor/plugins/plugin_fu
vendor/plugins/plugin_fu/init.rb
vendor/plugins/plugin_fu/install.rb
vendor/plugins/plugin_fu/uninstall.rb
vendor/plugins/plugin_fu/lib
vendor/plugins/plugin_fu/lib/plugin_fu.rb
vendor/plugins/plugin_fu/Rakefile
).each{ |path| assert_file path }
%w(
vendor/plugins/plugin_fu/README
).each{ |path| assert_file path, /PluginFu/ }
%w(
vendor/plugins/plugin_fu/README
vendor/plugins/plugin_fu/MIT-LICENSE
).each{ |path| assert_file path, /#{year}/ }
end
def test_check_class_collision
content = capture(:stderr){ run_generator ["object"] }
assert_match(/The name 'Object' is either already used in your application or reserved/, content)
end
def test_invokes_default_test_framework
silence(:stderr) { run_generator }
assert_file "vendor/plugins/plugin_fu/test/plugin_fu_test.rb", /class PluginFuTest < ActiveSupport::TestCase/
assert_file "vendor/plugins/plugin_fu/test/test_helper.rb"
end
def test_logs_if_the_test_framework_cannot_be_found
content = nil
silence(:stderr) { content = run_generator ["plugin_fu", "--test-framework=rspec"] }
assert_match(/rspec \[not found\]/, content)
end
def test_creates_tasks_if_required
silence(:stderr) { run_generator ["plugin_fu", "--tasks"] }
assert_file "vendor/plugins/plugin_fu/lib/tasks/plugin_fu_tasks.rake"
end
def test_creates_generator_if_required
silence(:stderr) { run_generator ["plugin_fu", "--generator"] }
assert_file "vendor/plugins/plugin_fu/lib/generators/templates"
assert_file "vendor/plugins/plugin_fu/lib/generators/plugin_fu_generator.rb",
/class PluginFuGenerator < Rails::Generators::NamedBase/
end
def test_plugin_generator_on_revoke
silence(:stderr) { run_generator }
run_generator ["plugin_fu"], :behavior => :revoke
end
def test_deprecation
output = capture(:stderr) { run_generator }
assert_match(/Plugin generator is deprecated, please use 'rails plugin new' command to generate plugin structure./, output)
end
end
......@@ -227,57 +227,4 @@ def setup
assert @root["app"].autoload?
assert_equal ["/app"], @root.autoload_paths
end
# Deprecated API tests
test "reading a root level path with assignment" do
@root.add "app"
assert_deprecated do
assert_equal ["/foo/bar/app"], @root.app.to_a
end
end
test "creating a root level path with assignment" do
assert_deprecated do
@root.app = "/foo/bar"
end
assert_equal ["/foo/bar"], @root["app"].to_a
end
test "creating a root level path without assignment" do
assert_deprecated do
@root.app "/foo/bar"
end
assert_equal ["/foo/bar"], @root["app"].to_a
end
test "reading a nested level path with assignment" do
@root.add "app"
@root.add "app/model"
assert_deprecated do
assert_equal ["/foo/bar/app/model"], @root.app.model.to_a
end
end
test "creating a nested level path with assignment" do
@root.add "app"
assert_deprecated do
@root.app.model = "/foo/bar"
end
assert_equal ["/foo/bar"], @root["app/model"].to_a
end
test "creating a nested level path without assignment" do
@root.add "app"
assert_deprecated do
@root.app.model "/foo/bar"
end
assert_equal ["/foo/bar"], @root["app/model"].to_a
end
test "trying to access a path that does not exist raises NoMethodError" do
assert_deprecated do
assert_raises(NoMethodError) { @root.app }
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册