aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG.md14
-rw-r--r--railties/guides/source/active_record_validations_callbacks.textile8
-rw-r--r--railties/guides/source/active_support_core_extensions.textile4
-rw-r--r--railties/guides/source/getting_started.textile2
-rw-r--r--railties/guides/source/performance_testing.textile2
-rw-r--r--railties/lib/rails/application.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb8
-rwxr-xr-xrailties/lib/rails/generators/rails/plugin_new/templates/Rakefile2
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb2
-rw-r--r--railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb45
-rw-r--r--railties/lib/rails/rack/logger.rb39
-rw-r--r--railties/lib/rails/ruby_version_check.rb4
-rw-r--r--railties/lib/rails/version.rb2
-rw-r--r--railties/test/application/assets_test.rb24
-rw-r--r--railties/test/application/initializers/frameworks_test.rb36
-rw-r--r--railties/test/application/rack/logger_test.rb13
-rw-r--r--railties/test/application/rake/dbs_test.rb194
-rw-r--r--railties/test/application/route_inspect_test.rb2
-rw-r--r--railties/test/generators/namespaced_generators_test.rb76
-rw-r--r--railties/test/generators/plugin_new_generator_test.rb6
-rw-r--r--railties/test/generators/scaffold_generator_test.rb2
-rw-r--r--railties/test/generators_test.rb4
22 files changed, 447 insertions, 44 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index f41f91cf22..9110fdc673 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,17 @@
+## Rails 3.2.9 (Nov 12, 2012) ##
+
+* Engines with a dummy app include the rake tasks of dependencies in the app namespace. [Backport: #8262]
+ Fix #8229
+
+ *Yves Senn*
+
+* Add dummy app Rake tasks when --skip-test-unit and --dummy-path is passed to the plugin generator. [Backport #8139]
+ Fix #8121
+
+ *Yves Senn*
+
+* Update supported ruby versions error message in ruby_version_check.rb *Lihan Li*
+
## Rails 3.2.8 (Aug 9, 2012) ##
* ERB scaffold generator use the `:data => { :confirm => "Text" }` syntax instead of `:confirm`.
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 15d24f9ac1..d2a445b508 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -901,8 +901,12 @@ Below is a simple example where we change the Rails behavior to always display t
<ruby>
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
- errors = Array(instance.error_message).join(',')
- %(#{html_tag}<span class="validation-error">&nbsp;#{errors}</span>).html_safe
+ if html_tag =~ /\<label/
+ html_tag
+ else
+ errors = Array(instance.error_message).join(',')
+ %(#{html_tag}<span class="validation-error">&nbsp;#{errors}</span>).html_safe
+ end
end
</ruby>
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index fbccff5005..83e35214a5 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -3615,7 +3615,9 @@ File.atomic_write(joined_asset_path) do |cache|
end
</ruby>
-To accomplish this +atomic_write+ creates a temporary file. That's the file the code in the block actually writes to. On completion, the temporary file is renamed, which is an atomic operation on POSIX systems. If the target file exists +atomic_write+ overwrites it and keeps owners and permissions.
+To accomplish this `atomic_write` creates a temporary file. That's the file the code in the block actually writes to. On completion, the temporary file is renamed, which is an atomic operation on POSIX systems. If the target file exists `atomic_write` overwrites it and keeps owners and permissions. However there are a few cases where `atomic_write` cannot change the file ownership or permissions, this error is caught and skipped over trusting in the user/filesystem to ensure the file is accessible to the processes that need it.
+
+NOTE. Due to the chmod operation `atomic_write` performs, if the target file has an ACL set on it this ACL will be recalculated/modified.
WARNING. Note you can't append with +atomic_write+.
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 0bcd50a1c4..c32a23c50b 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -221,7 +221,7 @@ h3. Creating a New Rails Project
The best way to use this guide is to follow each step as it happens, no code or
step needed to make this example application has been left out, so you can
-literally follow along step by step. You can get the complete code "here":https://github.com/lifo/docrails/tree/master/railties/guides/code/getting_started.
+literally follow along step by step. You can get the complete code "here":https://github.com/rails/rails/tree/3-2-stable/railties/guides/code/getting_started.
By following along with this guide, you'll create a Rails project called <tt>blog</tt>, a
(very) simple weblog. Before you can start building the application, you need to
diff --git a/railties/guides/source/performance_testing.textile b/railties/guides/source/performance_testing.textile
index 958b13cd9e..0cf7d4a4fb 100644
--- a/railties/guides/source/performance_testing.textile
+++ b/railties/guides/source/performance_testing.textile
@@ -447,7 +447,7 @@ h4. Using Ruby-Prof on MRI and REE
Add Ruby-Prof to your applications' Gemfile if you want to benchmark/profile under MRI or REE:
<ruby>
-gem 'ruby-prof', :git => 'git://github.com/wycats/ruby-prof.git'
+gem 'ruby-prof'
</ruby>
Now run +bundle install+ and you're ready to go.
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index c0eb25a290..854ac2cbbc 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -232,6 +232,8 @@ module Rails
end
def default_middleware_stack
+ require 'action_controller/railtie'
+
ActionDispatch::MiddlewareStack.new.tap do |middleware|
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
require "action_dispatch/http/rack_cache"
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
index cd7d51e628..6c53d8bebb 100644
--- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -204,7 +204,7 @@ task :default => :test
end
def create_test_dummy_files
- return if options[:skip_test_unit] && options[:dummy_path] == 'test/dummy'
+ return unless with_dummy_app?
create_dummy_app
end
@@ -242,6 +242,10 @@ task :default => :test
options[:mountable]
end
+ def with_dummy_app?
+ options[:skip_test_unit].blank? || options[:dummy_path] != 'test/dummy'
+ end
+
def self.banner
"rails plugin new #{self.arguments.map(&:usage).join(' ')} [options]"
end
@@ -282,7 +286,7 @@ task :default => :test
dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root)
unless options[:pretend] || !File.exists?(dummy_application_path)
contents = File.read(dummy_application_path)
- contents[(contents.index("module Dummy"))..-1]
+ contents[(contents.index(/module ([\w]+)\n(.*)class Application/m))..-1]
end
end
end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
index 564fda3c49..9b3b8cc03f 100755
--- a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end
-<% if full? && !options[:skip_active_record] && !options[:skip_test_unit] -%>
+<% if full? && !options[:skip_active_record] && with_dummy_app? -%>
APP_RAKEFILE = File.expand_path("../<%= dummy_path -%>/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'
<% end %>
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb b/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb
index 996ea79e67..6cb7e38b56 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/rails/application.rb
@@ -12,7 +12,7 @@ require "active_resource/railtie"
<%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"
<% end -%>
-Bundler.require
+Bundler.require(*Rails.groups)
require "<%= name %>"
<%= application_definition %>
diff --git a/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb b/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb
index 6a5d62803c..f33d56b564 100644
--- a/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb
+++ b/railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb
@@ -1,13 +1,50 @@
module Rails
module Generators
class ResourceRouteGenerator < NamedBase
+
+ # Properly nests namespaces passed into a generator
+ #
+ # $ rails generate resource admin/users/products
+ #
+ # should give you
+ #
+ # namespace :admin do
+ # namespace :users
+ # resources :products
+ # end
+ # end
def add_resource_route
return if options[:actions].present?
- route_config = regular_class_path.collect{ |namespace| "namespace :#{namespace} do " }.join(" ")
- route_config << "resources :#{file_name.pluralize}"
- route_config << " end" * regular_class_path.size
- route route_config
+
+ # iterates over all namespaces and opens up blocks
+ regular_class_path.each_with_index do |namespace, index|
+ write("namespace :#{namespace} do", index + 1)
+ end
+
+ # inserts the primary resource
+ write("resources :#{file_name.pluralize}", route_length + 1)
+
+ # ends blocks
+ regular_class_path.each_index do |index|
+ write("end", route_length - index)
+ end
+
+ # route prepends two spaces onto the front of the string that is passed, this corrects that
+ route route_string[2..-1]
end
+
+ private
+ def route_string
+ @route_string ||= ""
+ end
+
+ def write(str, indent)
+ route_string << "#{" " * indent}#{str}\n"
+ end
+
+ def route_length
+ regular_class_path.length
+ end
end
end
end
diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb
index 89de10c83d..3f59bb8733 100644
--- a/railties/lib/rails/rack/logger.rb
+++ b/railties/lib/rails/rack/logger.rb
@@ -3,35 +3,48 @@ require 'active_support/core_ext/object/blank'
module Rails
module Rack
- # Log the request started and flush all loggers after it.
+ # Sets log tags, logs the request, calls the app, and flushes the logs.
class Logger < ActiveSupport::LogSubscriber
- def initialize(app, tags=nil)
- @app, @tags = app, tags.presence
+ def initialize(app, taggers = nil)
+ @app, @taggers = app, taggers || []
end
def call(env)
- if @tags
- Rails.logger.tagged(compute_tags(env)) { call_app(env) }
+ request = ActionDispatch::Request.new(env)
+
+ if Rails.logger.respond_to?(:tagged)
+ Rails.logger.tagged(compute_tags(request)) { call_app(request, env) }
else
- call_app(env)
+ call_app(request, env)
end
end
protected
- def call_app(env)
- request = ActionDispatch::Request.new(env)
- path = request.filtered_path
- Rails.logger.info "\n\nStarted #{request.request_method} \"#{path}\" for #{request.ip} at #{Time.now.to_default_s}"
+ def call_app(request, env)
+ # Put some space between requests in development logs.
+ if Rails.env.development?
+ Rails.logger.info ''
+ Rails.logger.info ''
+ end
+
+ Rails.logger.info started_request_message(request)
@app.call(env)
ensure
ActiveSupport::LogSubscriber.flush_all!
end
- def compute_tags(env)
- request = ActionDispatch::Request.new(env)
+ # Started GET "/session/new" for 127.0.0.1 at 2012-09-26 14:51:42 -0700
+ def started_request_message(request)
+ 'Started %s "%s" for %s at %s' % [
+ request.request_method,
+ request.filtered_path,
+ request.ip,
+ Time.now.to_default_s ]
+ end
- @tags.collect do |tag|
+ def compute_tags(request)
+ @taggers.collect do |tag|
case tag
when Proc
tag.call(request)
diff --git a/railties/lib/rails/ruby_version_check.rb b/railties/lib/rails/ruby_version_check.rb
index 4d57c5973c..d6c7716c0d 100644
--- a/railties/lib/rails/ruby_version_check.rb
+++ b/railties/lib/rails/ruby_version_check.rb
@@ -2,7 +2,7 @@ if RUBY_VERSION < '1.8.7'
desc = defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})"
abort <<-end_message
- Rails 3 requires Ruby 1.8.7 or 1.9.2.
+ Rails 3 requires Ruby 1.8.7 or >= 1.9.2.
You're running
#{desc}
@@ -14,7 +14,7 @@ elsif RUBY_VERSION > '1.9' and RUBY_VERSION < '1.9.2'
$stderr.puts <<-end_message
Rails 3 doesn't officially support Ruby 1.9.1 since recent stable
- releases have segfaulted the test suite. Please upgrade to Ruby 1.9.2.
+ releases have segfaulted the test suite. Please upgrade to Ruby 1.9.2 or later.
You're running
#{RUBY_DESCRIPTION}
diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb
index 4565e13fc7..a7fe32b920 100644
--- a/railties/lib/rails/version.rb
+++ b/railties/lib/rails/version.rb
@@ -2,7 +2,7 @@ module Rails
module VERSION #:nodoc:
MAJOR = 3
MINOR = 2
- TINY = 8
+ TINY = 9
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb
index 6e638ed85f..9e9702efb6 100644
--- a/railties/test/application/assets_test.rb
+++ b/railties/test/application/assets_test.rb
@@ -122,8 +122,23 @@ module ApplicationTests
app_file "app/assets/javascripts/something/index.js.erb", "alert();"
precompile!
-
assert File.exists?("#{app_path}/public/assets/something.js")
+
+ assets = YAML.load_file("#{app_path}/public/assets/manifest.yml")
+ assert_not_nil assets['something/index.js'], "Expected something/index.js among #{assets.keys.inspect}"
+ assert_not_nil assets['something.js'], "Expected something.js among #{assets.keys.inspect}"
+ end
+
+ test "precompile something/index.js for directory containing index file" do
+ add_to_config "config.assets.precompile = [ 'something/index.js' ]"
+ app_file "app/assets/javascripts/something/index.js.erb", "alert();"
+
+ precompile!
+ assert File.exists?("#{app_path}/public/assets/something/index.js")
+
+ assets = YAML.load_file("#{app_path}/public/assets/manifest.yml")
+ assert_not_nil assets['something/index.js'], "Expected something/index.js among #{assets.keys.inspect}"
+ assert_not_nil assets['something.js'], "Expected something.js among #{assets.keys.inspect}"
end
test "asset pipeline should use a Sprockets::Index when config.assets.digest is true" do
@@ -243,6 +258,7 @@ module ApplicationTests
test "assets raise AssetNotPrecompiledError when manifest file is present and requested file isn't precompiled if digest is disabled" do
app_file "app/views/posts/index.html.erb", "<%= javascript_include_tag 'app' %>"
add_to_config "config.assets.compile = false"
+ add_to_config "config.assets.digest = false"
app_file "config/routes.rb", <<-RUBY
AppTemplate::Application.routes.draw do
@@ -250,14 +266,16 @@ module ApplicationTests
end
RUBY
- ENV["RAILS_ENV"] = "development"
+ ENV["RAILS_ENV"] = "production"
precompile!
# Create file after of precompile
app_file "app/assets/javascripts/app.js", "alert();"
require "#{app_path}/config/environment"
- class ::PostsController < ActionController::Base ; end
+ class ::PostsController < ActionController::Base
+ def show_detailed_exceptions?() true end
+ end
get '/posts'
assert_match(/AssetNotPrecompiledError/, last_response.body)
diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb
index cf6c4d8fc2..b4c9741b05 100644
--- a/railties/test/application/initializers/frameworks_test.rb
+++ b/railties/test/application/initializers/frameworks_test.rb
@@ -193,5 +193,41 @@ module ApplicationTests
require "#{app_path}/config/environment"
assert_nil defined?(ActiveRecord::Base)
end
+
+ test "active record establish_connection uses Rails.env if DATABASE_URL is not set" do
+ begin
+ require "#{app_path}/config/environment"
+ orig_database_url = ENV.delete("DATABASE_URL")
+ orig_rails_env, Rails.env = Rails.env, 'development'
+
+ ActiveRecord::Base.establish_connection
+
+ assert ActiveRecord::Base.connection
+ assert_match /#{ActiveRecord::Base.configurations[Rails.env]['database']}/, ActiveRecord::Base.connection_config[:database]
+ ensure
+ ActiveRecord::Base.remove_connection
+ ENV["DATABASE_URL"] = orig_database_url if orig_database_url
+ Rails.env = orig_rails_env if orig_rails_env
+ end
+ end
+
+ test "active record establish_connection uses DATABASE_URL even if Rails.env is set" do
+ begin
+ require "#{app_path}/config/environment"
+ orig_database_url = ENV.delete("DATABASE_URL")
+ orig_rails_env, Rails.env = Rails.env, 'development'
+ database_url_db_name = "db/database_url_db.sqlite3"
+ ENV["DATABASE_URL"] = "sqlite3://:@localhost/#{database_url_db_name}"
+
+ ActiveRecord::Base.establish_connection
+
+ assert ActiveRecord::Base.connection
+ assert_match /#{database_url_db_name}/, ActiveRecord::Base.connection_config[:database]
+ ensure
+ ActiveRecord::Base.remove_connection
+ ENV["DATABASE_URL"] = orig_database_url if orig_database_url
+ Rails.env = orig_rails_env if orig_rails_env
+ end
+ end
end
end
diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb
index 387eb25525..984d8374fb 100644
--- a/railties/test/application/rack/logger_test.rb
+++ b/railties/test/application/rack/logger_test.rb
@@ -1,6 +1,7 @@
require "isolation/abstract_unit"
require "active_support/log_subscriber/test_helper"
require "rack/test"
+require "mocha/setup"
module ApplicationTests
module RackTests
@@ -21,25 +22,25 @@ module ApplicationTests
end
def logs
- @logs ||= @logger.logged(:info)
+ @logs ||= @logger.logged(:info).join("\n")
end
test "logger logs proper HTTP verb and path" do
get "/blah"
wait
- assert_match(/^Started GET "\/blah"/, logs[0])
+ assert_match 'Started GET "/blah"', logs
end
test "logger logs HTTP verb override" do
- post "/", {:_method => 'put'}
+ post "/", :_method => 'put'
wait
- assert_match(/^Started PUT "\/"/, logs[0])
+ assert_match 'Started PUT "/"', logs
end
test "logger logs HEAD requests" do
- post "/", {:_method => 'head'}
+ post "/", :_method => 'head'
wait
- assert_match(/^Started HEAD "\/"/, logs[0])
+ assert_match 'Started HEAD "/"', logs
end
end
end
diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb
new file mode 100644
index 0000000000..479ed2612b
--- /dev/null
+++ b/railties/test/application/rake/dbs_test.rb
@@ -0,0 +1,194 @@
+require "isolation/abstract_unit"
+
+module ApplicationTests
+ module RakeTests
+ class RakeDbsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+ FileUtils.rm_rf("#{app_path}/config/environments")
+ end
+
+ def teardown
+ teardown_app
+ end
+
+ def database_url_db_name
+ "db/database_url_db.sqlite3"
+ end
+
+ def set_database_url
+ ENV['DATABASE_URL'] = "sqlite3://:@localhost/#{database_url_db_name}"
+ end
+
+ def expected
+ @expected ||= {}
+ end
+
+ def db_create_and_drop
+ Dir.chdir(app_path) do
+ output = `bundle exec rake db:create`
+ assert_equal output, ""
+ assert File.exists?(expected[:database])
+ assert_equal expected[:database],
+ ActiveRecord::Base.connection_config[:database]
+ output = `bundle exec rake db:drop`
+ assert_equal output, ""
+ assert !File.exists?(expected[:database])
+ end
+ end
+
+ test 'db:create and db:drop without database url' do
+ require "#{app_path}/config/environment"
+ expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
+ db_create_and_drop
+ end
+
+ test 'db:create and db:drop with database url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ expected[:database] = database_url_db_name
+ db_create_and_drop
+ end
+
+ def db_migrate_and_status
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `bundle exec rake db:migrate`
+ output = `bundle exec rake db:migrate:status`
+ assert_match(/database:\s+\S*#{expected[:database]}/, output)
+ assert_match(/up\s+\d{14}\s+Create books/, output)
+ end
+ end
+
+ test 'db:migrate and db:migrate:status without database_url' do
+ require "#{app_path}/config/environment"
+ expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
+ db_migrate_and_status
+ end
+
+ test 'db:migrate and db:migrate:status with database_url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ expected[:database] = database_url_db_name
+ db_migrate_and_status
+ end
+
+ def db_schema_dump
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `rake db:migrate`
+ `rake db:schema:dump`
+
+ assert File.exists?("db/schema.rb"), "db/schema.rb doesn't exist"
+
+ schema_dump = File.read("db/schema.rb")
+
+ assert_match(/create_table \"books\"/, schema_dump)
+ end
+ end
+
+ test 'db:schema:dump without database_url' do
+ db_schema_dump
+ end
+
+ test 'db:schema:dump with database_url' do
+ set_database_url
+ db_schema_dump
+ end
+
+ def db_fixtures_load
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `bundle exec rake db:migrate`
+ `bundle exec rake db:fixtures:load`
+ assert_match /#{expected[:database]}/,
+ ActiveRecord::Base.connection_config[:database]
+ require "#{app_path}/app/models/book"
+ assert_equal 2, Book.count
+ end
+ end
+
+ test 'db:fixtures:load without database_url' do
+ require "#{app_path}/config/environment"
+ expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
+ db_fixtures_load
+ end
+
+ test 'db:fixtures:load with database_url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ expected[:database] = database_url_db_name
+ db_fixtures_load
+ end
+
+ def db_structure_dump_and_load
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `bundle exec rake db:create`
+ `bundle exec rake db:migrate`
+ `bundle exec rake db:structure:dump`
+
+ assert File.exists?("db/structure.sql"), "db/structure.sql doesn't exist"
+
+ structure_dump = File.read("db/structure.sql")
+
+ assert_match /CREATE TABLE \"books\"/, structure_dump
+
+ `bundle exec rake db:drop`
+ `bundle exec rake db:structure:load`
+
+ assert_match /#{expected[:database]}/,
+ ActiveRecord::Base.connection_config[:database]
+
+ require "#{app_path}/app/models/book"
+ #if structure is not loaded correctly, exception would be raised
+ assert_equal Book.count, 0
+ end
+ end
+
+ test 'db:structure:dump and db:structure:load without database_url' do
+ require "#{app_path}/config/environment"
+ expected[:database] = ActiveRecord::Base.configurations[Rails.env]['database']
+ db_structure_dump_and_load
+ end
+
+ test 'db:structure:dump and db:structure:load with database_url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ expected[:database] = database_url_db_name
+ db_structure_dump_and_load
+ end
+
+ def db_test_load_structure
+ Dir.chdir(app_path) do
+ `rails generate model book title:string`
+ `bundle exec rake db:migrate`
+ `bundle exec rake db:structure:dump`
+ `bundle exec rake db:test:load_structure`
+ ActiveRecord::Base.configurations = Rails.application.config.database_configuration
+ ActiveRecord::Base.establish_connection 'test'
+ require "#{app_path}/app/models/book"
+
+ #if structure is not loaded correctly, exception would be raised
+ assert_equal Book.count, 0
+ assert_match /#{ActiveRecord::Base.configurations['test']['database']}/,
+ ActiveRecord::Base.connection_config[:database]
+ end
+ end
+
+ test 'db:test:load_structure without database_url' do
+ require "#{app_path}/config/environment"
+ db_test_load_structure
+ end
+
+ test 'db:test:load_structure with database_url' do
+ require "#{app_path}/config/environment"
+ set_database_url
+ db_test_load_structure
+ end
+ end
+ end
+end
diff --git a/railties/test/application/route_inspect_test.rb b/railties/test/application/route_inspect_test.rb
index b897cf15b8..5c920cb33a 100644
--- a/railties/test/application/route_inspect_test.rb
+++ b/railties/test/application/route_inspect_test.rb
@@ -1,5 +1,5 @@
require 'test/unit'
-require 'mocha'
+require 'mocha/setup'
require 'rails/application/route_inspector'
require 'action_controller'
require 'rails/engine'
diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb
index 88415b20e4..1cef42dafa 100644
--- a/railties/test/generators/namespaced_generators_test.rb
+++ b/railties/test/generators/namespaced_generators_test.rb
@@ -297,7 +297,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Route
assert_file "config/routes.rb" do |route|
- assert_match(/namespace :admin do resources :roles end$/, route)
+ assert_match(/^ namespace :admin do\n resources :roles\n end$/, route)
end
# Controller
@@ -339,7 +339,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Route
assert_file "config/routes.rb" do |route|
- assert_no_match(/namespace :admin do resources :roles end$/, route)
+ assert_no_match(/^ namespace :admin do\n resources :roles\n end$$/, route)
end
# Controller
@@ -357,4 +357,76 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
# Stylesheets (should not be removed)
assert_file "app/assets/stylesheets/scaffold.css"
end
+
+ def test_scaffold_with_nested_namespace_on_invoke
+ run_generator [ "admin/user/special/role", "name:string", "description:string" ]
+
+ # Model
+ assert_file "app/models/test_app/admin/user/special.rb", /module TestApp\n module Admin/
+ assert_file "app/models/test_app/admin/user/special/role.rb", /module TestApp\n class Admin::User::Special::Role < ActiveRecord::Base/
+ assert_file "test/unit/test_app/admin/user/special/role_test.rb", /module TestApp\n class Admin::User::Special::RoleTest < ActiveSupport::TestCase/
+ assert_file "test/fixtures/test_app/admin/user/special/roles.yml"
+ assert_migration "db/migrate/create_test_app_admin_user_special_roles.rb"
+
+ # Route
+ assert_file "config/routes.rb" do |route|
+ assert_match(/^ namespace :admin do\n namespace :user do\n namespace :special do\n resources :roles\n end\n end\n end$/, route)
+ end
+
+ # Controller
+ assert_file "app/controllers/test_app/admin/user/special/roles_controller.rb" do |content|
+ assert_match(/module TestApp\n class Admin::User::Special::RolesController < ApplicationController/, content)
+ end
+
+ assert_file "test/functional/test_app/admin/user/special/roles_controller_test.rb",
+ /module TestApp\n class Admin::User::Special::RolesControllerTest < ActionController::TestCase/
+
+ # Views
+ %w(
+ index
+ edit
+ new
+ show
+ _form
+ ).each { |view| assert_file "app/views/test_app/admin/user/special/roles/#{view}.html.erb" }
+ assert_no_file "app/views/layouts/admin/user/special/roles.html.erb"
+
+ # Helpers
+ assert_file "app/helpers/test_app/admin/user/special/roles_helper.rb"
+ assert_file "test/unit/helpers/test_app/admin/user/special/roles_helper_test.rb"
+
+ # Stylesheets
+ assert_file "app/assets/stylesheets/scaffold.css"
+ end
+
+ def test_scaffold_with_nested_namespace_on_revoke
+ run_generator [ "admin/user/special/role", "name:string", "description:string" ]
+ run_generator [ "admin/user/special/role" ], :behavior => :revoke
+
+ # Model
+ assert_file "app/models/test_app/admin/user/special.rb" # ( should not be remove )
+ assert_no_file "app/models/test_app/admin/user/special/role.rb"
+ assert_no_file "test/unit/test_app/admin/user/special/role_test.rb"
+ assert_no_file "test/fixtures/test_app/admin/user/special/roles.yml"
+ assert_no_migration "db/migrate/create_test_app_admin_user_special_roles.rb"
+
+ # Route
+ assert_file "config/routes.rb" do |route|
+ assert_no_match(/^ namespace :admin do\n namespace :user do\n namespace :special do\n resources :roles\n end\n end\n end$/, route)
+ end
+
+ # Controller
+ assert_no_file "app/controllers/test_app/admin/user/special/roles_controller.rb"
+ assert_no_file "test/functional/test_app/admin/user/special/roles_controller_test.rb"
+
+ # Views
+ assert_no_file "app/views/test_app/admin/user/special/roles"
+
+ # Helpers
+ assert_no_file "app/helpers/test_app/admin/user/special/roles_helper.rb"
+ assert_no_file "test/unit/helpers/test_app/admin/user/special/roles_helper_test.rb"
+
+ # Stylesheets (should not be removed)
+ assert_file "app/assets/stylesheets/scaffold.css"
+ end
end
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index dcf4f95194..a33c6b096c 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -65,6 +65,12 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_no_match(/APP_RAKEFILE/, File.read(File.join(destination_root, "Rakefile")))
end
+ def test_generating_adds_dummy_app_rake_tasks_without_unit_test_files
+ run_generator [destination_root, "-T", "--mountable", '--dummy-path', 'my_dummy_app']
+
+ assert_match(/APP_RAKEFILE/, File.read(File.join(destination_root, "Rakefile")))
+ end
+
def test_ensure_that_plugin_options_are_not_passed_to_app_generator
FileUtils.cd(Rails.root)
assert_no_match(/It works from file!.*It works_from_file/, run_generator([destination_root, "-m", "lib/template.rb"]))
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 2710ef7dfd..5891af505a 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -156,7 +156,7 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Route
assert_file "config/routes.rb" do |route|
- assert_match(/namespace :admin do resources :roles end$/, route)
+ assert_match(/^ namespace :admin do\n resources :roles\n end$/, route)
end
# Controller
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 5f9ee220dc..01bd11e1ab 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -1,7 +1,7 @@
require 'generators/generators_test_helper'
require 'rails/generators/rails/model/model_generator'
require 'rails/generators/test_unit/model/model_generator'
-require 'mocha'
+require 'mocha/setup'
class GeneratorsTest < Rails::Generators::TestCase
include GeneratorsTestHelper
@@ -201,7 +201,7 @@ class GeneratorsTest < Rails::Generators::TestCase
mspec = Rails::Generators.find_by_namespace :fixjour
assert mspec.source_paths.include?(File.join(Rails.root, "lib", "templates", "fixjour"))
end
-
+
def test_usage_with_embedded_ruby
require File.expand_path("fixtures/lib/generators/usage_template/usage_template_generator", File.dirname(__FILE__))
output = capture(:stdout) { Rails::Generators.invoke :usage_template, ['--help'] }