aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionview/lib/action_view/helpers/url_helper.rb30
-rw-r--r--activerecord/CHANGELOG.md85
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb4
-rw-r--r--activerecord/lib/active_record/locking/pessimistic.rb2
-rw-r--r--activerecord/lib/active_record/reflection.rb15
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb12
-rw-r--r--activerecord/test/cases/reflection_test.rb8
-rw-r--r--guides/rails_guides.rb45
-rw-r--r--guides/source/active_record_basics.md10
-rw-r--r--guides/source/asset_pipeline.md2
-rw-r--r--guides/source/association_basics.md4
-rw-r--r--guides/source/getting_started.md18
-rw-r--r--railties/CHANGELOG.md7
-rw-r--r--railties/lib/rails/generators/actions.rb2
-rw-r--r--railties/lib/rails/generators/rails/resource_route/resource_route_generator.rb6
-rw-r--r--railties/test/generators/actions_test.rb24
16 files changed, 140 insertions, 134 deletions
diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb
index 3dbce0738e..4c436bce25 100644
--- a/actionview/lib/action_view/helpers/url_helper.rb
+++ b/actionview/lib/action_view/helpers/url_helper.rb
@@ -280,9 +280,7 @@ module ActionView
html_options, options = options, name if block_given?
options ||= {}
html_options ||= {}
-
html_options = html_options.stringify_keys
- convert_boolean_attributes!(html_options, %w(disabled))
url = options.is_a?(String) ? options : url_for(options)
remote = html_options.delete('remote')
@@ -576,34 +574,6 @@ module ActionView
html_options["data-method"] = method
end
- # Processes the +html_options+ hash, converting the boolean
- # attributes from true/false form into the form required by
- # HTML/XHTML. (An attribute is considered to be boolean if
- # its name is listed in the given +bool_attrs+ array.)
- #
- # More specifically, for each boolean attribute in +html_options+
- # given as:
- #
- # "attr" => bool_value
- #
- # if the associated +bool_value+ evaluates to true, it is
- # replaced with the attribute's name; otherwise the attribute is
- # removed from the +html_options+ hash. (See the XHTML 1.0 spec,
- # section 4.5 "Attribute Minimization" for more:
- # http://www.w3.org/TR/xhtml1/#h-4.5)
- #
- # Returns the updated +html_options+ hash, which is also modified
- # in place.
- #
- # Example:
- #
- # convert_boolean_attributes!( html_options,
- # %w( checked disabled readonly ) )
- def convert_boolean_attributes!(html_options, bool_attrs)
- bool_attrs.each { |x| html_options[x] = x if html_options.delete(x) }
- html_options
- end
-
def token_tag(token=nil)
if token != false && protect_against_forgery?
token ||= form_authenticity_token
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 07714538fb..82d7ab353d 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Reuse the `CollectionAssociation#reader` cache when the foreign key is
+ available prior to save.
+
+ *Ben Woosley*
+
* Add `config.active_record.dump_schemas` to fix `db:structure:dump`
when using schema_search_path and PostgreSQL extensions.
@@ -24,8 +29,8 @@
*James Cox*
-* Dont enroll records in the transaction if they dont have commit callbacks.
- That was causing a memory grow problem when creating a lot of records inside a transaction.
+* Don't enroll records in the transaction if they don't have commit callbacks.
+ This was causing a memory leak when creating many records inside a transaction.
Fixes #15549.
@@ -38,11 +43,11 @@
*Sean Griffin*
-* Add `SchemaMigration.create_table` support any unicode charsets for MySQL.
+* Add `SchemaMigration.create_table` support for any unicode charsets with MySQL.
*Ryuta Kamizono*
-* PostgreSQL, no longer disables user triggers if system triggers can't be
+* PostgreSQL no longer disables user triggers if system triggers can't be
disabled. Disabling user triggers does not fulfill what the method promises.
Rails currently requires superuser privileges for this method.
@@ -56,12 +61,12 @@
*Toby Ovod-Everett*, *Yves Senn*
-* PostgreSQL, print warning message if `disable_referential_integrity` fails
- due to missing permissions.
+* In PostgreSQL, print a warning message if `disable_referential_integrity`
+ fails due to missing permissions.
*Andrey Nering*, *Yves Senn*
-* Allow `:limit` option for MySQL bigint primary key support.
+* Allow a `:limit` option for MySQL bigint primary key support.
Example:
@@ -84,7 +89,7 @@
*Josef Šimánek*
* Fixed ActiveRecord::Relation#becomes! and changed_attributes issues for type
- column.
+ columns.
Fixes #17139.
@@ -94,7 +99,7 @@
*Ryuta Kamizono*
-* Allow `:precision` option for time type columns.
+* Allow a `:precision` option for time type columns.
*Ryuta Kamizono*
@@ -111,10 +116,10 @@
recipients: commentable.recipients }
end
- That's what you want the bulk of the time. New comment creates a new
- Notification. But there may well be off cases, like copying a commentable
- and its comments, where you don't want that. So you'd have a concern
- something like this:
+ That's what you want the bulk of the time. A new comment creates a new
+ Notification. There may be edge cases where you don't want that, like
+ when copying a commentable and its comments, in which case write a
+ concern with something like this:
module Copyable
def copy_to(destination)
@@ -133,7 +138,7 @@
*Hyonjee Joo*
-* Deprecated passing of `start` value to `find_in_batches` and `find_each`
+* Deprecate passing of `start` value to `find_in_batches` and `find_each`
in favour of `begin_at` value.
*Vipul A M*
@@ -142,9 +147,10 @@
*Tõnis Simo*
-* Use SQL COUNT and LIMIT 1 queries for `none?` and `one?` methods if no block or limit is given,
- instead of loading the entire collection to memory.
- This applies to relations (e.g. `User.all`) as well as associations (e.g. `account.users`)
+* Use SQL COUNT and LIMIT 1 queries for `none?` and `one?` methods
+ if no block or limit is given, instead of loading the entire
+ collection into memory. This applies to relations (e.g. `User.all`)
+ as well as associations (e.g. `account.users`)
# Before:
@@ -193,16 +199,16 @@
*Vipul A M*
-* Fix rounding problem for PostgreSQL timestamp column.
+* Fix a rounding problem for PostgreSQL timestamp columns.
- If timestamp column have the precision, it need to format according to
- the precision of timestamp column.
+ If a timestamp column has a precision specified, it needs to
+ format according to that.
*Ryuta Kamizono*
* Respect the database default charset for `schema_migrations` table.
- The charset of `version` column in `schema_migrations` table is depend
+ The charset of `version` column in `schema_migrations` table depends
on the database default charset and collation rather than the encoding
of the connection.
@@ -210,12 +216,12 @@
* Raise `ArgumentError` when passing `nil` or `false` to `Relation#merge`.
- These are not valid values to merge in a relation so it should warn the users
+ These are not valid values to merge in a relation, so it should warn users
early.
*Rafael Mendonça França*
-* Use `SCHEMA` instead of `DB_STRUCTURE` for specifying structure file.
+* Use `SCHEMA` instead of `DB_STRUCTURE` for specifying a structure file.
This makes the db:structure tasks consistent with test:load_structure.
@@ -227,7 +233,7 @@
*Sean Griffin*
-* Fixed several edge cases which could result in a counter cache updating
+* Fix several edge cases which could result in a counter cache updating
twice or not updating at all for `has_many` and `has_many :through`.
Fixes #10865.
@@ -260,11 +266,13 @@
*Sammy Larbi*
* Change the default error message from `can't be blank` to `must exist` for
- the presence validator of the `:required` option on `belongs_to`/`has_one` associations.
+ the presence validator of the `:required` option on `belongs_to`/`has_one`
+ associations.
*Henrik Nygren*
-* Fixed ActiveRecord::Relation#group method when argument is SQL reserved key word:
+* Fixed ActiveRecord::Relation#group method when an argument is an SQL
+ reserved key word:
Example:
@@ -395,7 +403,7 @@
*Yves Senn*
-* Remove deprecation when modifying a relation with cached arel.
+* Remove deprecation when modifying a relation with cached Arel.
This raises an `ImmutableRelation` error instead.
*Yves Senn*
@@ -485,13 +493,13 @@
*Florian Weingarten*
-* Fixed setting of foreign_key for through associations while building of new record.
+* Fix setting of foreign_key for through associations when building a new record.
Fixes #12698.
*Ivan Antropov*
-* Improve a dump of the primary key support. If it is not a default primary key,
+* Improve dumping of the primary key. If it is not a default primary key,
correctly dump the type and options.
Fixes #14169, #16599.
@@ -509,18 +517,18 @@
*Ryuta Kamizono*
-* Allow precision option for MySQL datetimes.
+* Allow a precision option for MySQL datetimes.
*Ryuta Kamizono*
-* Fixed automatic inverse_of for models nested in module.
+* Fixed automatic `inverse_of` for models nested in a module.
*Andrew McCloud*
* Change `ActiveRecord::Relation#update` behavior so that it can
be called without passing ids of the records to be updated.
- This change allows to update multiple records returned by
+ This change allows updating multiple records returned by
`ActiveRecord::Relation` with callbacks and validations.
# Before
@@ -552,6 +560,13 @@
*Rafael Mendonça França*
+* Fix change detection problem for PostgreSQL bytea type and
+ `ArgumentError: string contains null byte` exception with pg-0.18.
+
+ Fixes #17680.
+
+ *Lars Kanis*
+
* When a table has a composite primary key, the `primary_key` method for
SQLite3 and PostgreSQL adapters was only returning the first field of the key.
Ensures that it will return nil instead, as Active Record doesn't support
@@ -561,7 +576,7 @@
*arthurnn*
-* `validates_size_of` / `validates_length_of` do not count records,
+* `validates_size_of` / `validates_length_of` do not count records
which are `marked_for_destruction?`.
Fixes #7247.
@@ -603,7 +618,7 @@
*Ryuta Kamizono*
-* Support for any type primary key.
+* Support for any type of primary key.
Fixes #14194.
@@ -629,7 +644,7 @@
*Yves Senn*
-* Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
+* Fix bug with 'ActiveRecord::Type::Numeric' that caused negative values to
be marked as having changed when set to the same negative value.
Closes #18161.
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 1e245926e0..88531205a1 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -33,10 +33,10 @@ module ActiveRecord
reload
end
- if owner.new_record?
+ if null_scope?
# Cache the proxy separately before the owner has an id
# or else a post-save proxy will still lack the id
- @new_record_proxy ||= CollectionProxy.create(klass, self)
+ @null_proxy ||= CollectionProxy.create(klass, self)
else
@proxy ||= CollectionProxy.create(klass, self)
end
diff --git a/activerecord/lib/active_record/locking/pessimistic.rb b/activerecord/lib/active_record/locking/pessimistic.rb
index ff7102d35b..3d95c54ef3 100644
--- a/activerecord/lib/active_record/locking/pessimistic.rb
+++ b/activerecord/lib/active_record/locking/pessimistic.rb
@@ -51,7 +51,7 @@ module ActiveRecord
# end
#
# Database-specific information on row locking:
- # MySQL: http://dev.mysql.com/doc/refman/5.1/en/innodb-locking-reads.html
+ # MySQL: http://dev.mysql.com/doc/refman/5.6/en/innodb-locking-reads.html
# PostgreSQL: http://www.postgresql.org/docs/current/interactive/sql-select.html#SQL-FOR-UPDATE-SHARE
module Pessimistic
# Obtain a row lock on this record. Reloads the record to obtain the requested
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index e4704b5b3e..4265afc0a5 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -370,6 +370,12 @@ module ActiveRecord
[self]
end
+ # This is for clearing cache on the reflection. Useful for tests that need to compare
+ # SQL queries on associations.
+ def clear_association_scope_cache # :nodoc:
+ @association_scope_cache.clear
+ end
+
def nested?
false
end
@@ -706,6 +712,15 @@ module ActiveRecord
end
end
+ # This is for clearing cache on the reflection. Useful for tests that need to compare
+ # SQL queries on associations.
+ def clear_association_scope_cache # :nodoc:
+ @chain = nil
+ delegate_reflection.clear_association_scope_cache
+ source_reflection.clear_association_scope_cache
+ through_reflection.clear_association_scope_cache
+ end
+
# Consider the following example:
#
# class Person
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 675bed9bfa..290b2a0d6b 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -532,9 +532,21 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
def test_update_all_on_association_accessed_before_save
firm = Firm.new(name: 'Firm')
+ clients_proxy_id = firm.clients.object_id
firm.clients << Client.first
firm.save!
assert_equal firm.clients.count, firm.clients.update_all(description: 'Great!')
+ assert_not_equal clients_proxy_id, firm.clients.object_id
+ end
+
+ def test_update_all_on_association_accessed_before_save_with_explicit_foreign_key
+ # We can use the same cached proxy object because the id is available for the scope
+ firm = Firm.new(name: 'Firm', id: 100)
+ clients_proxy_id = firm.clients.object_id
+ firm.clients << Client.first
+ firm.save!
+ assert_equal firm.clients.count, firm.clients.update_all(description: 'Great!')
+ assert_equal clients_proxy_id, firm.clients.object_id
end
def test_belongs_to_sanity
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb
index 06bc70c172..7b47c80331 100644
--- a/activerecord/test/cases/reflection_test.rb
+++ b/activerecord/test/cases/reflection_test.rb
@@ -284,8 +284,14 @@ class ReflectionTest < ActiveRecord::TestCase
drink = department.chefs.create!(employable: DrinkDesigner.create!)
Recipe.create!(chef_id: drink.id, hotel_id: hotel.id)
+ expected_sql = capture_sql { hotel.recipes.to_a }
+
+ Hotel.reflect_on_association(:recipes).clear_association_scope_cache
+ hotel.reload
hotel.drink_designers.to_a
- assert_sql(/^(?!.*employable_type).*$/) { hotel.recipes.to_a }
+ loaded_sql = capture_sql { hotel.recipes.to_a }
+
+ assert_equal expected_sql, loaded_sql
end
def test_nested?
diff --git a/guides/rails_guides.rb b/guides/rails_guides.rb
index f184cff3e8..367ed0b12e 100644
--- a/guides/rails_guides.rb
+++ b/guides/rails_guides.rb
@@ -1,13 +1,6 @@
pwd = File.dirname(__FILE__)
$:.unshift pwd
-# This is a predicate useful for the doc:guides task of applications.
-def bundler?
- # Note that rake sets the cwd to the one that contains the Rakefile
- # being executed.
- File.exist?('Gemfile')
-end
-
begin
# Guides generation in the Rails repo.
as_lib = File.join(pwd, "../activesupport/lib")
@@ -20,43 +13,5 @@ rescue LoadError
gem "actionpack", '>= 3.0'
end
-begin
- require 'redcarpet'
-rescue LoadError
- # This can happen if doc:guides is executed in an application.
- $stderr.puts('Generating guides requires Redcarpet 3.2.2+.')
- $stderr.puts(<<ERROR) if bundler?
-Please add
-
- gem 'redcarpet', '~> 3.2.2'
-
-to the Gemfile, run
-
- bundle install
-
-and try again.
-ERROR
- exit 1
-end
-
-begin
- require 'nokogiri'
-rescue LoadError
- # This can happen if doc:guides is executed in an application.
- $stderr.puts('Generating guides requires Nokogiri.')
- $stderr.puts(<<ERROR) if bundler?
-Please add
-
- gem 'nokogiri'
-
-to the Gemfile, run
-
- bundle install
-
-and try again.
-ERROR
- exit 1
-end
-
require "rails_guides/generator"
RailsGuides::Generator.new.generate
diff --git a/guides/source/active_record_basics.md b/guides/source/active_record_basics.md
index 150f4c0f14..6551ba0389 100644
--- a/guides/source/active_record_basics.md
+++ b/guides/source/active_record_basics.md
@@ -173,18 +173,18 @@ name that should be used:
```ruby
class Product < ActiveRecord::Base
- self.table_name = "PRODUCT"
+ self.table_name = "my_products"
end
```
If you do so, you will have to define manually the class name that is hosting
-the fixtures (class_name.yml) using the `set_fixture_class` method in your test
+the fixtures (my_products.yml) using the `set_fixture_class` method in your test
definition:
```ruby
-class FunnyJoke < ActiveSupport::TestCase
- set_fixture_class funny_jokes: Joke
- fixtures :funny_jokes
+class ProductTest < ActiveSupport::TestCase
+ set_fixture_class my_products: Product
+ fixtures :my_products
...
end
```
diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md
index c9ae256c83..816bff3784 100644
--- a/guides/source/asset_pipeline.md
+++ b/guides/source/asset_pipeline.md
@@ -974,7 +974,7 @@ http://mycdnsubdomain.fictional-cdn.com/assets/smile.png
If the CDN has a copy of `smile.png` it will serve it to the browser and your
server doesn't even know it was requested. If the CDN does not have a copy it
-will try to find it a the "origin" `example.com/assets/smile.png` and then store
+will try to find it at the "origin" `example.com/assets/smile.png` and then store
it for future use.
If you want to serve only some assets from your CDN, you can use custom `:host`
diff --git a/guides/source/association_basics.md b/guides/source/association_basics.md
index 280c3008e9..ec6017ff73 100644
--- a/guides/source/association_basics.md
+++ b/guides/source/association_basics.md
@@ -933,7 +933,7 @@ Passing `true` to the `:polymorphic` option indicates that this is a polymorphic
##### `:touch`
-If you set the `:touch` option to `:true`, then the `updated_at` or `updated_on` timestamp on the associated object will be set to the current time whenever this object is saved or destroyed:
+If you set the `:touch` option to `true`, then the `updated_at` or `updated_on` timestamp on the associated object will be set to the current time whenever this object is saved or destroyed:
```ruby
class Order < ActiveRecord::Base
@@ -1496,7 +1496,7 @@ While Rails uses intelligent defaults that will work well in most situations, th
```ruby
class Customer < ActiveRecord::Base
- has_many :orders, dependent: :delete_all, validate: :false
+ has_many :orders, dependent: :delete_all, validate: false
end
```
diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md
index 7cce9c72cb..fe01088b2e 100644
--- a/guides/source/getting_started.md
+++ b/guides/source/getting_started.md
@@ -321,9 +321,9 @@ root 'welcome#index'
application to the welcome controller's index action and `get 'welcome/index'`
tells Rails to map requests to <http://localhost:3000/welcome/index> to the
welcome controller's index action. This was created earlier when you ran the
-controller generator (`rails generate controller welcome index`).
+controller generator (`bin/rails generate controller welcome index`).
-Launch the web server again if you stopped it to generate the controller (`rails
+Launch the web server again if you stopped it to generate the controller (`bin/rails
server`) and navigate to <http://localhost:3000> in your browser. You'll see the
"Hello, Rails!" message you put into `app/views/welcome/index.html.erb`,
indicating that this new route is indeed going to `WelcomeController`'s `index`
@@ -356,7 +356,7 @@ Rails.application.routes.draw do
end
```
-If you run `rake routes`, you'll see that it has defined routes for all the
+If you run `bin/rake routes`, you'll see that it has defined routes for all the
standard RESTful actions. The meaning of the prefix column (and other columns)
will be seen later, but for now notice that Rails has inferred the
singular form `article` and makes meaningful use of the distinction.
@@ -556,7 +556,7 @@ this:
In this example, the `articles_path` helper is passed to the `:url` option.
To see what Rails will do with this, we look back at the output of
-`rake routes`:
+`bin/rake routes`:
```bash
$ bin/rake routes
@@ -666,7 +666,7 @@ models, as that will be done automatically by Active Record.
### Running a Migration
-As we've just seen, `rails generate model` created a _database migration_ file
+As we've just seen, `bin/rails generate model` created a _database migration_ file
inside the `db/migrate` directory. Migrations are Ruby classes that are
designed to make it simple to create and modify database tables. Rails uses
rake commands to run migrations, and it's possible to undo a migration after
@@ -719,7 +719,7 @@ NOTE. Because you're working in the development environment by default, this
command will apply to the database defined in the `development` section of your
`config/database.yml` file. If you would like to execute migrations in another
environment, for instance in production, you must explicitly pass it when
-invoking the command: `rake db:migrate RAILS_ENV=production`.
+invoking the command: `bin/rake db:migrate RAILS_ENV=production`.
### Saving data in the controller
@@ -806,7 +806,7 @@ If you submit the form again now, Rails will complain about not finding the
`show` action. That's not very useful though, so let's add the `show` action
before proceeding.
-As we have seen in the output of `rake routes`, the route for `show` action is
+As we have seen in the output of `bin/rake routes`, the route for `show` action is
as follows:
```
@@ -868,7 +868,7 @@ Visit <http://localhost:3000/articles/new> and give it a try!
### Listing all articles
We still need a way to list all our articles, so let's do that.
-The route for this as per output of `rake routes` is:
+The route for this as per output of `bin/rake routes` is:
```
articles GET /articles(.:format) articles#index
@@ -1363,7 +1363,7 @@ Then do the same for the `app/views/articles/edit.html.erb` view:
We're now ready to cover the "D" part of CRUD, deleting articles from the
database. Following the REST convention, the route for
-deleting articles as per output of `rake routes` is:
+deleting articles as per output of `bin/rake routes` is:
```ruby
DELETE /articles/:id(.:format) articles#destroy
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md
index b538c81428..f4a8cf86b6 100644
--- a/railties/CHANGELOG.md
+++ b/railties/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Add a new-line to the end of route method generated code.
+
+ We need to add a `\n`, because we cannot have two routes
+ in the same line.
+
+ *arthurnn*
+
* Add `rake initializer`
This task prints out initializers for an application. It is useful to
diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb
index c1bc646c65..70a20801a0 100644
--- a/railties/lib/rails/generators/actions.rb
+++ b/railties/lib/rails/generators/actions.rb
@@ -221,7 +221,7 @@ module Rails
sentinel = /\.routes\.draw do\s*\n/m
in_root do
- inject_into_file 'config/routes.rb', " #{routing_code}", { after: sentinel, verbose: false, force: true }
+ inject_into_file 'config/routes.rb', " #{routing_code}\n", { after: sentinel, verbose: false, force: true }
end
end
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 e4a2bc2b0f..c986f95e67 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
@@ -29,8 +29,10 @@ module Rails
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]
+ # route prepends two spaces onto the front of the string that is passed, this corrects that.
+ # Also it adds a \n to the end of each line, as route already adds that
+ # we need to correct that too.
+ route route_string[2..-2]
end
private
diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb
index c6de2c1fb9..c0b88089b3 100644
--- a/railties/test/generators/actions_test.rb
+++ b/railties/test/generators/actions_test.rb
@@ -219,6 +219,30 @@ class ActionsTest < Rails::Generators::TestCase
assert_file 'config/routes.rb', /#{Regexp.escape(route_command)}/
end
+ def test_route_should_add_data_with_an_new_line
+ run_generator
+ action :route, "root 'welcome#index'"
+ route_path = File.expand_path("config/routes.rb", destination_root)
+ content = File.read(route_path)
+
+ # Remove all of the comments and blank lines from the routes file
+ content.gsub!(/^ \#.*\n/, '')
+ content.gsub!(/^\n/, '')
+
+ File.open(route_path, "wb") { |file| file.write(content) }
+ assert_file "config/routes.rb", /\.routes\.draw do\n root 'welcome#index'\nend\n\z/
+
+ action :route, "resources :product_lines"
+
+ routes = <<-F
+Rails.application.routes.draw do
+ resources :product_lines
+ root 'welcome#index'
+end
+F
+ assert_file "config/routes.rb", routes
+ end
+
def test_readme
run_generator
Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root)