diff options
5 files changed, 34 insertions, 16 deletions
diff --git a/actioncable/lib/rails/generators/channel/channel_generator.rb b/actioncable/lib/rails/generators/channel/channel_generator.rb index 3bcf5f1898..05fd21a954 100644 --- a/actioncable/lib/rails/generators/channel/channel_generator.rb +++ b/actioncable/lib/rails/generators/channel/channel_generator.rb @@ -13,7 +13,9 @@ module Rails template "channel.rb", File.join('app/channels', class_path, "#{file_name}_channel.rb") if options[:assets] - template "assets/cable.js", "app/assets/javascripts/cable.js" + if self.behavior == :invoke + template "assets/cable.js", "app/assets/javascripts/cable.js" + end template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee") end diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 2562e26a11..b54909d38e 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,16 +1,10 @@ -* Add support for database schema comments for tables, columns and indexes - for PostgreSQL and MySQL. - - It allows to specify commentaries for database objects in migrations and - store them in database itself, allowing to see them with DBA tools and - in `db/schema.rb` file and thus automatically documents database schema: - - create_table "pages", force: :cascade, comment: 'Arbitrary content pages' do |t| - # ... - t.string "path", comment: "Path fragment of page URL used for routing" - t.string "locale", comment: "RFC 3066 locale code of website language section" - t.index ["locale", "path"], name: 'page_uri_index' comment: "Main index used to lookup page by it's URI." - # ... +* Database comments. Annotate database objects (tables, columns, indexes) + with comments stored in database metadata. PostgreSQL & MySQL support. + + create_table :pages, force: :cascade, comment: 'CMS content pages' do |t| + t.string :path, comment: 'Path fragment of page URL used for routing' + t.string :locale, comment: 'RFC 3066 locale code of website language section' + t.index [:path, :locale], comment: 'Look up pages by URI' end *Andrey Novikov* diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 3bbd5a9515..ca2539f845 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -788,7 +788,8 @@ module ActiveRecord # [<tt>:type</tt>] # The reference column type. Defaults to +:integer+. # [<tt>:index</tt>] - # Add an appropriate index. Defaults to false. + # Add an appropriate index. Defaults to false. + # See #add_index for usage of this option. # [<tt>:foreign_key</tt>] # Add an appropriate foreign key constraint. Defaults to false. # [<tt>:polymorphic</tt>] @@ -808,6 +809,14 @@ module ActiveRecord # # add_reference(:products, :supplier, polymorphic: true, index: true) # + # ====== Create a supplier_id column with a unique index + # + # add_reference(:products, :supplier, index: { unique: true }) + # + # ====== Create a supplier_id column with a named index + # + # add_reference(:products, :supplier, index: { name: "my_supplier_index" }) + # # ====== Create a supplier_id column and appropriate foreign key # # add_reference(:products, :supplier, foreign_key: true) diff --git a/guides/source/active_record_migrations.md b/guides/source/active_record_migrations.md index c111996b58..2aae35223a 100644 --- a/guides/source/active_record_migrations.md +++ b/guides/source/active_record_migrations.md @@ -246,7 +246,8 @@ class AddUserRefToProducts < ActiveRecord::Migration[5.0] end ``` -This migration will create a `user_id` column and appropriate index. +This migration will create a `user_id` column and appropriate index. +For more `add_reference` options, visit the [API documentation](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_reference). There is also a generator which will produce join tables if `JoinTable` is part of the name: diff --git a/railties/test/generators/channel_generator_test.rb b/railties/test/generators/channel_generator_test.rb index 23d0c7b4a4..d58b54ac24 100644 --- a/railties/test/generators/channel_generator_test.rb +++ b/railties/test/generators/channel_generator_test.rb @@ -46,4 +46,16 @@ class ChannelGeneratorTest < Rails::Generators::TestCase assert_file "app/assets/javascripts/cable.js" end + + def test_channel_on_revoke + run_generator ['chat'] + run_generator ['chat'], behavior: :revoke + + assert_no_file "app/channels/chat_channel.rb" + assert_no_file "app/assets/javascripts/channels/chat.coffee" + + assert_file "app/channels/application_cable/channel.rb" + assert_file "app/channels/application_cable/connection.rb" + assert_file "app/assets/javascripts/cable.js" + end end |