aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application/finisher.rb2
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/index.html.erb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/boot.rb3
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt2
-rw-r--r--railties/lib/rails/generators/rails/controller/controller_generator.rb8
-rw-r--r--railties/lib/rails/generators/testing/assertions.rb2
-rw-r--r--railties/lib/rails/test_unit/sub_test_task.rb4
-rw-r--r--railties/test/application/configuration_test.rb62
-rw-r--r--railties/test/application/mailer_previews_test.rb14
-rw-r--r--railties/test/application/rake/migrations_test.rb15
-rw-r--r--railties/test/application/test_test.rb91
-rw-r--r--railties/test/generators/controller_generator_test.rb7
-rw-r--r--railties/test/generators/scaffold_controller_generator_test.rb8
13 files changed, 121 insertions, 99 deletions
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 5b8509b2e9..7a1bb1e25c 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -22,8 +22,6 @@ module Rails
initializer :add_builtin_route do |app|
if Rails.env.development?
app.routes.append do
- get '/rails/mailers' => "rails/mailers#index"
- get '/rails/mailers/*path' => "rails/mailers#preview"
get '/rails/info/properties' => "rails/info#properties"
get '/rails/info/routes' => "rails/info#routes"
get '/rails/info' => "rails/info#index"
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
index 025b1d8699..5e194783ff 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
@@ -1,3 +1,5 @@
+<p id="notice"><%%= notice %></p>
+
<h1>Listing <%= plural_table_name.titleize %></h1>
<table>
diff --git a/railties/lib/rails/generators/rails/app/templates/config/boot.rb b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
index 5e5f0c1fac..6b750f00b1 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/boot.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/boot.rb
@@ -1,4 +1,3 @@
-# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
-require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
+require 'bundler/setup' # Set up gems listed in the Gemfile.
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index a2aa7c09db..5e52f97249 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -33,7 +33,7 @@ Rails.application.configure do
# Generate digests for assets URLs.
config.assets.digest = true
- # `config.assets.precompile` has moved to config/initializers/assets.rb
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
<%- end -%>
# Specifies the header that your server uses for sending files.
diff --git a/railties/lib/rails/generators/rails/controller/controller_generator.rb b/railties/lib/rails/generators/rails/controller/controller_generator.rb
index 7588a558e7..fbecab1823 100644
--- a/railties/lib/rails/generators/rails/controller/controller_generator.rb
+++ b/railties/lib/rails/generators/rails/controller/controller_generator.rb
@@ -2,6 +2,8 @@ module Rails
module Generators
class ControllerGenerator < NamedBase # :nodoc:
argument :actions, type: :array, default: [], banner: "action action"
+ class_option :skip_routes, type: :boolean, desc: "Dont' add routes to config/routes.rb."
+
check_class_collision suffix: "Controller"
def create_controller_files
@@ -9,8 +11,10 @@ module Rails
end
def add_routes
- actions.reverse.each do |action|
- route generate_routing_code(action)
+ unless options[:skip_routes]
+ actions.reverse.each do |action|
+ route generate_routing_code(action)
+ end
end
end
diff --git a/railties/lib/rails/generators/testing/assertions.rb b/railties/lib/rails/generators/testing/assertions.rb
index 2e877f8762..bd069e4bd0 100644
--- a/railties/lib/rails/generators/testing/assertions.rb
+++ b/railties/lib/rails/generators/testing/assertions.rb
@@ -1,3 +1,5 @@
+require 'shellwords'
+
module Rails
module Generators
module Testing
diff --git a/railties/lib/rails/test_unit/sub_test_task.rb b/railties/lib/rails/test_unit/sub_test_task.rb
index d9bffba4d7..6fa96d2ced 100644
--- a/railties/lib/rails/test_unit/sub_test_task.rb
+++ b/railties/lib/rails/test_unit/sub_test_task.rb
@@ -7,7 +7,7 @@ module Rails
#
# This class takes a TestInfo class and defines the appropriate rake task
# based on the information, then invokes it.
- class TestCreator
+ class TestCreator # :nodoc:
def initialize(info)
@info = info
end
@@ -41,7 +41,7 @@ module Rails
# to test files (or can be transformed into test files). Calling <tt>files</tt>
# provides the set of test files and is used when initializing tests after
# a call to <tt>rake test</tt>.
- class TestInfo
+ class TestInfo # :nodoc:
def initialize(tasks)
@tasks = tasks
@files = nil
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 207a0c7e86..2e056be561 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -714,6 +714,44 @@ module ApplicationTests
assert_match "We're sorry, but something went wrong", last_response.body
end
+ test "config.action_controller.always_permitted_parameters are: controller, action by default" do
+ require "#{app_path}/config/environment"
+ assert_equal %w(controller action), ActionController::Parameters.always_permitted_parameters
+ end
+
+ test "config.action_controller.always_permitted_parameters = ['controller', 'action', 'format']" do
+ add_to_config <<-RUBY
+ config.action_controller.always_permitted_parameters = %w( controller action format )
+ RUBY
+ require "#{app_path}/config/environment"
+ assert_equal %w( controller action format ), ActionController::Parameters.always_permitted_parameters
+ end
+
+ test "config.action_controller.always_permitted_parameters = ['controller','action','format'] does not raise exeception" do
+ app_file 'app/controllers/posts_controller.rb', <<-RUBY
+ class PostsController < ActionController::Base
+ def create
+ render text: params.permit(post: [:title])
+ end
+ end
+ RUBY
+
+ add_to_config <<-RUBY
+ routes.prepend do
+ resources :posts
+ end
+ config.action_controller.always_permitted_parameters = %w( controller action format )
+ config.action_controller.action_on_unpermitted_parameters = :raise
+ RUBY
+
+ require "#{app_path}/config/environment"
+
+ assert_equal :raise, ActionController::Parameters.action_on_unpermitted_parameters
+
+ post "/posts", {post: {"title" =>"zomg"}, format: "json"}
+ assert_equal 200, last_response.status
+ end
+
test "config.action_controller.action_on_unpermitted_parameters is :log by default on development" do
ENV["RAILS_ENV"] = "development"
@@ -927,5 +965,29 @@ module ApplicationTests
assert db_config.is_a?(Hash)
end
+
+ test 'config.action_mailer.show_previews defaults to true in development' do
+ Rails.env = "development"
+ require "#{app_path}/config/environment"
+
+ assert Rails.application.config.action_mailer.show_previews
+ end
+
+ test 'config.action_mailer.show_previews defaults to false in production' do
+ Rails.env = "production"
+ require "#{app_path}/config/environment"
+
+ assert_equal Rails.application.config.action_mailer.show_previews, false
+ end
+
+ test 'config.action_mailer.show_previews can be set in the configuration file' do
+ Rails.env = "production"
+ add_to_config <<-RUBY
+ config.action_mailer.show_previews = true
+ RUBY
+ require "#{app_path}/config/environment"
+
+ assert_equal Rails.application.config.action_mailer.show_previews, true
+ end
end
end
diff --git a/railties/test/application/mailer_previews_test.rb b/railties/test/application/mailer_previews_test.rb
index c588fd7012..8b91a1171f 100644
--- a/railties/test/application/mailer_previews_test.rb
+++ b/railties/test/application/mailer_previews_test.rb
@@ -26,6 +26,20 @@ module ApplicationTests
assert_equal 404, last_response.status
end
+ test "/rails/mailers is accessible with correct configuraiton" do
+ add_to_config "config.action_mailer.show_previews = true"
+ app("production")
+ get "/rails/mailers"
+ assert_equal 200, last_response.status
+ end
+
+ test "/rails/mailers is not accessible with show_previews = false" do
+ add_to_config "config.action_mailer.show_previews = false"
+ app("development")
+ get "/rails/mailers"
+ assert_equal 404, last_response.status
+ end
+
test "mailer previews are loaded from the default preview_path" do
mailer 'notifier', <<-RUBY
class Notifier < ActionMailer::Base
diff --git a/railties/test/application/rake/migrations_test.rb b/railties/test/application/rake/migrations_test.rb
index a6900a57c4..a3819b93b2 100644
--- a/railties/test/application/rake/migrations_test.rb
+++ b/railties/test/application/rake/migrations_test.rb
@@ -184,6 +184,21 @@ module ApplicationTests
assert_match(/create_table "books"/, structure_dump)
end
end
+
+ test 'test migration status migrated file is deleted' do
+ Dir.chdir(app_path) do
+ `rails generate model user username:string password:string;
+ rails generate migration add_email_to_users email:string;
+ rake db:migrate
+ rm db/migrate/*email*.rb`
+
+ output = `rake db:migrate:status`
+ File.write('test.txt', output)
+
+ assert_match(/up\s+\d{14}\s+Create users/, output)
+ assert_match(/up\s+\d{14}\s+\** NO FILE \**/, output)
+ end
+ end
end
end
end
diff --git a/railties/test/application/test_test.rb b/railties/test/application/test_test.rb
index c724c867ec..a223180169 100644
--- a/railties/test/application/test_test.rb
+++ b/railties/test/application/test_test.rb
@@ -67,7 +67,7 @@ module ApplicationTests
assert_match %r{/app/test/unit/failing_test\.rb}, output
end
- test "ruby schema migrations" do
+ test "migrations" do
output = script('generate model user name:string')
version = output.match(/(\d+)_create_users\.rb/)[1]
@@ -104,95 +104,6 @@ module ApplicationTests
assert !result.include?("create_table(:users)")
end
- test "sql structure migrations" do
- output = script('generate model user name:string')
- version = output.match(/(\d+)_create_users\.rb/)[1]
-
- app_file 'test/models/user_test.rb', <<-RUBY
- require 'test_helper'
-
- class UserTest < ActiveSupport::TestCase
- test "user" do
- User.create! name: "Jon"
- end
- end
- RUBY
-
- app_file 'db/structure.sql', ''
- app_file 'config/initializers/enable_sql_schema_format.rb', <<-RUBY
- Rails.application.config.active_record.schema_format = :sql
- RUBY
-
- assert_unsuccessful_run "models/user_test.rb", "Migrations are pending"
-
- app_file 'db/structure.sql', <<-SQL
- CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
- CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
- CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255));
- INSERT INTO schema_migrations (version) VALUES ('#{version}');
- SQL
-
- app_file 'config/initializers/disable_maintain_test_schema.rb', <<-RUBY
- Rails.application.config.active_record.maintain_test_schema = false
- RUBY
-
- assert_unsuccessful_run "models/user_test.rb", "Could not find table 'users'"
-
- File.delete "#{app_path}/config/initializers/disable_maintain_test_schema.rb"
-
- assert_successful_test_run('models/user_test.rb')
- end
-
- test "sql structure migrations when adding column to existing table" do
- output_1 = script('generate model user name:string')
- version_1 = output_1.match(/(\d+)_create_users\.rb/)[1]
-
- app_file 'test/models/user_test.rb', <<-RUBY
- require 'test_helper'
- class UserTest < ActiveSupport::TestCase
- test "user" do
- User.create! name: "Jon"
- end
- end
- RUBY
-
- app_file 'config/initializers/enable_sql_schema_format.rb', <<-RUBY
- Rails.application.config.active_record.schema_format = :sql
- RUBY
-
- app_file 'db/structure.sql', <<-SQL
- CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
- CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
- CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255));
- INSERT INTO schema_migrations (version) VALUES ('#{version_1}');
- SQL
-
- assert_successful_test_run('models/user_test.rb')
-
- output_2 = script('generate migration add_email_to_users')
- version_2 = output_2.match(/(\d+)_add_email_to_users\.rb/)[1]
-
- app_file 'test/models/user_test.rb', <<-RUBY
- require 'test_helper'
-
- class UserTest < ActiveSupport::TestCase
- test "user" do
- User.create! name: "Jon", email: "jon@doe.com"
- end
- end
- RUBY
-
- app_file 'db/structure.sql', <<-SQL
- CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL);
- CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
- CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255));
- INSERT INTO schema_migrations (version) VALUES ('#{version_1}');
- INSERT INTO schema_migrations (version) VALUES ('#{version_2}');
- SQL
-
- assert_successful_test_run('models/user_test.rb')
- end
-
private
def assert_unsuccessful_run(name, message)
result = run_test_file(name)
diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb
index 4b2f8539d0..28b527cb0e 100644
--- a/railties/test/generators/controller_generator_test.rb
+++ b/railties/test/generators/controller_generator_test.rb
@@ -70,6 +70,13 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
assert_file "config/routes.rb", /get 'account\/foo'/, /get 'account\/bar'/
end
+ def test_skip_routes
+ run_generator ["account", "foo", "--skip-routes"]
+ assert_file "config/routes.rb" do |routes|
+ assert_no_match(/get 'account\/foo'/, routes)
+ end
+ end
+
def test_invokes_default_template_engine_even_with_no_action
run_generator ["account"]
assert_file "app/views/account"
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb
index 3c1123b53d..46eacd2845 100644
--- a/railties/test/generators/scaffold_controller_generator_test.rb
+++ b/railties/test/generators/scaffold_controller_generator_test.rb
@@ -93,6 +93,14 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
assert_no_file "app/views/layouts/users.html.erb"
end
+ def test_index_page_have_notice
+ run_generator
+
+ %w(index show).each do |view|
+ assert_file "app/views/users/#{view}.html.erb", /notice/
+ end
+ end
+
def test_functional_tests
run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}"]