diff options
Diffstat (limited to 'railties/lib/rails/generators')
34 files changed, 200 insertions, 80 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 5838c9fc38..383bea9e54 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -140,14 +140,14 @@ module Rails gem 'rails', path: '#{Rails::Generators::RAILS_DEV_PATH}' gem 'journey', github: 'rails/journey' gem 'arel', github: 'rails/arel' - gem 'active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders' + gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders' GEMFILE elsif options.edge? <<-GEMFILE.strip_heredoc gem 'rails', github: 'rails/rails' gem 'journey', github: 'rails/journey' gem 'arel', github: 'rails/arel' - gem 'active_record_deprecated_finders', github: 'rails/active_record_deprecated_finders' + gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders' GEMFILE else <<-GEMFILE.strip_heredoc diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 28d7680669..a3f8ebf476 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -8,7 +8,6 @@ rescue LoadError end require 'rails/generators/actions' -require 'active_support/core_ext/object/inclusion' module Rails module Generators @@ -20,6 +19,7 @@ module Rails include Rails::Generators::Actions add_runtime_options! + strict_args_position! # Returns the source root for this generator using default_source_root as default. def self.source_root(path=nil) @@ -170,7 +170,7 @@ module Rails names.each do |name| defaults = if options[:type] == :boolean { } - elsif default_value_for_option(name, options).in?([true, false]) + elsif [true, false].include?(default_value_for_option(name, options)) { :banner => "" } else { :desc => "#{name.to_s.humanize} to be invoked", :banner => "NAME" } 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 d78d97b2b4..f5182bcc50 100644 --- a/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb +++ b/railties/lib/rails/generators/erb/scaffold/templates/index.html.erb @@ -19,7 +19,7 @@ <% end -%> <td><%%= link_to 'Show', <%= singular_table_name %> %></td> <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>) %></td> - <td><%%= link_to 'Destroy', <%= singular_table_name %>, confirm: 'Are you sure?', method: :delete %></td> + <td><%%= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' } %></td> <%% end %> </tbody> </table> diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index 25d0161e4c..d2c2abf40c 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -8,6 +8,7 @@ module Rails attr_accessor :name, :type attr_reader :attr_options + attr_writer :index_name class << self def parse(column_definition) @@ -35,7 +36,7 @@ module Rails private - # parse possible attribute options like :limit for string/text/binary/integer or :precision/:scale for decimals + # parse possible attribute options like :limit for string/text/binary/integer, :precision/:scale for decimals or :polymorphic for references/belongs_to # when declaring options curly brackets should be used def parse_type_and_options(type) case type @@ -43,6 +44,8 @@ module Rails return $1, :limit => $2.to_i when /decimal\{(\d+)[,.-](\d+)\}/ return :decimal, :precision => $1.to_i, :scale => $2.to_i + when /(references|belongs_to)\{polymorphic\}/ + return $1, :polymorphic => true else return type, {} end @@ -87,18 +90,34 @@ module Rails end end + def plural_name + name.sub(/_id$/, '').pluralize + end + def human_name - name.to_s.humanize + name.humanize end def index_name - reference? ? "#{name}_id" : name + @index_name ||= if reference? + polymorphic? ? %w(id type).map { |t| "#{name}_#{t}" } : "#{name}_id" + else + name + end + end + + def foreign_key? + !!(name =~ /_id$/) end def reference? self.class.reference?(type) end + def polymorphic? + self.attr_options.has_key?(:polymorphic) + end + def has_index? @has_index end diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 63703176de..b61a5fc69d 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -84,10 +84,11 @@ module Rails end def namespaced_class_path - @namespaced_class_path ||= begin - namespace_path = namespace.name.split("::").map {|m| m.underscore } - namespace_path + @class_path - end + @namespaced_class_path ||= [namespaced_path] + @class_path + end + + def namespaced_path + @namespaced_path ||= namespace.name.split("::").map {|m| m.underscore }[0] end def class_name @@ -134,7 +135,7 @@ module Rails end def route_url - @route_url ||= class_path.collect{|dname| "/" + dname }.join('') + "/" + plural_file_name + @route_url ||= class_path.collect {|dname| "/" + dname }.join + "/" + plural_file_name end # Tries to retrieve the application name or simple return application. diff --git a/railties/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt b/railties/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt index 3ddc86ae0a..6c0ef31725 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/controllers/application_controller.rb.tt @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :reset_session instead. - protect_from_forgery :with => :exception -end
\ No newline at end of file + protect_from_forgery with: :exception +end diff --git a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt index bba96a7431..e0539aa8bb 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt @@ -2,7 +2,7 @@ <html> <head> <title><%= camelized %></title> - <%%= stylesheet_link_tag "application", :media => "all" %> + <%%= stylesheet_link_tag "application", media: "all" %> <%%= javascript_include_tag "application" %> <%%= csrf_meta_tags %> </head> diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb index d816f973e6..1ac0248bcf 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -13,7 +13,7 @@ require "action_mailer/railtie" if defined?(Bundler) # If you precompile assets before deploying to production, use this line. - Bundler.require(*Rails.groups(:assets => %w(development test))) + Bundler.require(*Rails.groups(assets: %w(development test))) # If you want your assets lazily compiled in production, use this line. # Bundler.require(:default, :assets, Rails.env) end @@ -27,9 +27,6 @@ module <%= app_const_base %> # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) - # Activate observers that should always be running. - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' @@ -54,11 +51,6 @@ module <%= app_const_base %> # in your app. As such, your models will need to explicitly whitelist or blacklist accessible # parameters by using an attr_accessible or attr_protected declaration. <%= comment_if :skip_active_record %>config.active_record.whitelist_attributes = true - - # Specifies whether or not has_many or has_one association option :dependent => :restrict raises - # an exception. If set to true, then an ActiveRecord::DeleteRestrictionError exception would be - # raised. If set to false, then an error will be added on the model instead. - <%= comment_if :skip_active_record %>config.active_record.dependent_restrict_raises = false <% unless options.skip_sprockets? -%> # Enable the asset pipeline. @@ -67,5 +59,8 @@ module <%= app_const_base %> # Version of your assets, change this if you want to expire all your assets. config.assets.version = '1.0' <% end -%> + + # Enable app-wide asynchronous ActionMailer. + # config.action_mailer.async = true end end diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml index fe9466b366..e1a00d076f 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml @@ -22,8 +22,8 @@ development: # Minimum log levels, in increasing order: # debug5, debug4, debug3, debug2, debug1, # log, notice, warning, error, fatal, and panic - # The server defaults to notice. - #min_messages: warning + # Defaults to warning. + #min_messages: notice # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml index 467a4e725f..07223a71c9 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml @@ -35,8 +35,8 @@ development: # Minimum log levels, in increasing order: # debug5, debug4, debug3, debug2, debug1, # log, notice, warning, error, fatal, and panic - # The server defaults to notice. - #min_messages: warning + # Defaults to warning. + #min_messages: notice # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". diff --git a/railties/lib/rails/generators/rails/app/templates/config/environment.rb b/railties/lib/rails/generators/rails/app/templates/config/environment.rb index 1684986a59..e080ebd74e 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environment.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/environment.rb @@ -1,5 +1,5 @@ -# Load the rails application +# Load the rails application. require File.expand_path('../application', __FILE__) -# Initialize the rails application +# Initialize the rails application. <%= app_const %>.initialize! diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 24bcec854c..122e7e2b34 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -6,6 +6,9 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false + # Do not eager load code on boot. + config.eager_load = false + # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false @@ -26,16 +29,19 @@ # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL). config.active_record.auto_explain_threshold_in_seconds = 0.5 + + # Raise an error on page load if there are pending migrations + config.active_record.migration_error = :page_load <%- end -%> <%- unless options.skip_sprockets? -%> # Do not compress assets. config.assets.compress = false - # Expands the lines which load the assets. + # Debug mode disables concatenation and preprocessing of assets. config.assets.debug = true <%- end -%> - # In development, use an in-memory queue for queueing + # In development, use an in-memory queue for queueing. config.queue = Rails::Queueing::Queue end 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 072aa8355d..a627636089 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 @@ -4,6 +4,12 @@ # Code is not reloaded between requests. config.cache_classes = true + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both thread web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true @@ -20,9 +26,6 @@ # Generate digests for assets URLs. config.assets.digest = true - - # Defaults to nil and saved in location specified by config.assets.prefix - # config.assets.manifest = YOUR_PATH <%- end -%> # Specifies the header that your server uses for sending files. @@ -74,10 +77,10 @@ # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false - # Use default logging formatter so that PID and timestamp are not suppressed + # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Default the production mode queue to an in-memory queue. You will probably - # want to replace this with an out-of-process queueing solution + # want to replace this with an out-of-process queueing solution. config.queue = Rails::Queueing::Queue end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index b27b88a3c6..8ab27eb6e1 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -7,6 +7,11 @@ # and recreated between test runs. Don't rely on the data there! config.cache_classes = true + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + # Configure static asset server for tests with Cache-Control for performance. config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" @@ -34,6 +39,6 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Use the testing queue + # Use the testing queue. config.queue = Rails::Queueing::TestQueue end diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb b/railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb index 5d8d9be237..9262c3379f 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/inflections.rb @@ -1,8 +1,9 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format -# (all these examples are active by default): -# ActiveSupport::Inflector.inflections do |inflect| +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' @@ -10,6 +11,6 @@ # end # # These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections do |inflect| +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym 'RESTful' # end diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt index ade0c4f78c..ff676280cb 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt @@ -4,5 +4,5 @@ # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information -# (create the session table with "rails generate session_migration") +# (create the session table with "rails generate session_migration"). # <%= app_const %>.config.session_store :active_record_store diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt index 19cbf0e4f1..280f777cc0 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/wrap_parameters.rb.tt @@ -9,8 +9,8 @@ ActiveSupport.on_load(:action_controller) do end <%- unless options.skip_active_record? -%> -# Disable root element in JSON by default. -ActiveSupport.on_load(:active_record) do - self.include_root_in_json = false -end +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end <%- end -%> diff --git a/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml b/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml index 179c14ca52..0653957166 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/locales/en.yml @@ -1,5 +1,23 @@ -# Sample localization file for English. Add more files in this directory for other locales. -# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" diff --git a/railties/lib/rails/generators/rails/app/templates/config/routes.rb b/railties/lib/rails/generators/rails/app/templates/config/routes.rb index 303e47877f..f6b1ef1feb 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/routes.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/routes.rb @@ -1,18 +1,18 @@ <%= app_const %>.routes.draw do # The priority is based upon order of creation: # first created -> highest priority. - + # You can have the root of your site routed with "root" # just remember to delete public/index.html. - # root :to => 'welcome#index' + # root to: 'welcome#index' # Sample of regular route: # get 'products/:id' => 'catalog#view' - # Keep in mind you can assign values other than :controller and :action + # Keep in mind you can assign values other than :controller and :action. # Sample of named route: - # get 'products/:id/purchase' => 'catalog#purchase', :as => :purchase - # This route can be invoked with purchase_url(:id => product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + # This route can be invoked with purchase_url(id: product.id). # Sample resource route (maps HTTP verbs to controller actions automatically): # resources :products @@ -35,11 +35,11 @@ # resource :seller # end - # Sample resource route with more complex sub-resources + # Sample resource route with more complex sub-resources: # resources :products do # resources :comments # resources :sales do - # get 'recent', :on => :collection + # get 'recent', on: :collection # end # end @@ -51,5 +51,5 @@ # end - # See how all your routes lay out with "rake routes" -end
\ No newline at end of file + # See how all your routes lay out with "rake routes". +end diff --git a/railties/lib/rails/generators/rails/app/templates/public/404.html b/railties/lib/rails/generators/rails/app/templates/public/404.html index 276c8c1c6a..3d875c342e 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/404.html +++ b/railties/lib/rails/generators/rails/app/templates/public/404.html @@ -22,5 +22,6 @@ <h1>The page you were looking for doesn't exist.</h1> <p>You may have mistyped the address or the page may have moved.</p> </div> + <p>If you are the application owner check the logs for more information.</p> </body> </html> diff --git a/railties/lib/rails/generators/rails/app/templates/public/500.html b/railties/lib/rails/generators/rails/app/templates/public/500.html index dfdb7d0b05..012977d3d2 100644 --- a/railties/lib/rails/generators/rails/app/templates/public/500.html +++ b/railties/lib/rails/generators/rails/app/templates/public/500.html @@ -21,5 +21,6 @@ <div class="dialog"> <h1>We're sorry, but something went wrong.</h1> </div> + <p>If you are the application owner check the logs for more information.</p> </body> </html> diff --git a/railties/lib/rails/generators/rails/app/templates/public/humans.txt.tt b/railties/lib/rails/generators/rails/app/templates/public/humans.txt.tt deleted file mode 100644 index f081e08b6c..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/public/humans.txt.tt +++ /dev/null @@ -1,7 +0,0 @@ -# See more about this file at: http://humanstxt.org/ -# For format suggestions, see: http://humanstxt.org/Standard.html -/* TEAM */ - -/* APP */ - Name: <%= app_const_base %> - Software: Ruby on Rails diff --git a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb index 2a849b7f2b..d09ce5ad34 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/performance/browsing_test.rb @@ -3,10 +3,10 @@ require 'rails/performance_test_help' class BrowsingTest < ActionDispatch::PerformanceTest # Refer to the documentation for all available options - # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory], - # :output => 'tmp/performance', :formats => [:flat] } + # self.profile_options = { runs: 5, metrics: [:wall_time, :memory], + # output: 'tmp/performance', formats: [:flat] } - def test_homepage + test "homepage" do get '/' end end diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb index a8f7aeac7d..9afda2d0df 100644 --- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb @@ -4,7 +4,9 @@ require 'rails/test_help' class ActiveSupport::TestCase <% unless options[:skip_active_record] -%> - # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. + ActiveRecord::Migration.check_pending! + + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integration tests # -- they do not yet inherit this setting diff --git a/railties/lib/rails/generators/rails/controller/templates/controller.rb b/railties/lib/rails/generators/rails/controller/templates/controller.rb index 4053113b4b..633e0b3177 100644 --- a/railties/lib/rails/generators/rails/controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/controller/templates/controller.rb @@ -1,5 +1,5 @@ <% if namespaced? -%> -require_dependency "<%= namespaced_file_path %>/application_controller" +require_dependency "<%= namespaced_path %>/application_controller" <% end -%> <% module_namespacing do -%> diff --git a/railties/lib/rails/generators/rails/model/USAGE b/railties/lib/rails/generators/rails/model/USAGE index 67f76aad01..c46c86076e 100644 --- a/railties/lib/rails/generators/rails/model/USAGE +++ b/railties/lib/rails/generators/rails/model/USAGE @@ -19,6 +19,55 @@ Description: then the generator will create a module with a table_name_prefix method to prefix the model's table name with the module name (e.g. admin_account) +Available field types: + + Just after the field name you can specify a type like text or boolean. + It will generate the column with the associated SQL type. For instance: + + `rails generate model post title:string body:text` + + will generate a title column with a varchar type and a body column with a text + type. You can use the following types: + + integer + primary_key + decimal + float + boolean + binary + string + text + date + time + datetime + timestamp + + You can also consider `references` as a kind of type. For instance, if you run: + + `rails generate model photo title:string album:references` + + It will generate an album_id column. You should generate this kind of fields when + you will use a `belongs_to` association for instance. `references` also support + the polymorphism, you could enable the polymorphism like this: + + `rails generate model product supplier:references{polymorphic}` + + You can also specify some options just after the field type. You can use the + following options: + + limit Set the maximum size of the field giving a number between curly braces + default Set a default value for the field + precision Defines the precision for the decimal fields + scale Defines the scale for the decimal fields + uniq Defines the field values as unique + index Will add an index on the field + + Examples: + + `rails generate model user pseudo:string{30}` + `rails generate model user pseudo:string:uniq` + + Examples: `rails generate model account` 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 ab0e440bc4..4f937ad65a 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 @@ -155,7 +155,7 @@ task :default => :test :desc => "Create dummy application at given path" class_option :full, :type => :boolean, :default => false, - :desc => "Generate rails engine with integration tests" + :desc => "Generate a rails engine with bundled Rails application for testing" class_option :mountable, :type => :boolean, :default => false, :desc => "Generate mountable isolated application" diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec index 82ffeebb86..568ed653b7 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec +++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec @@ -22,6 +22,8 @@ Gem::Specification.new do |s| <% if full? && !options[:skip_javascript] -%> # s.add_dependency "<%= "#{options[:javascript]}-rails" %>" <% end -%> +<% unless options[:skip_active_record] -%> s.add_development_dependency "<%= gem_for_database %>" +<% end -%> end diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile index 9399c9cb77..7448b386c5 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile @@ -1,17 +1,32 @@ source "http://rubygems.org" +<% if options[:skip_gemspec] -%> +<%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails::VERSION::STRING %>" +<% if full? && !options[:skip_javascript] -%> +# gem "<%= "#{options[:javascript]}-rails" %>" +<% end -%> +<% else -%> # Declare your gem's dependencies in <%= name %>.gemspec. # Bundler will treat runtime dependencies like base dependencies, and # development dependencies will be added by default to the :development group. gemspec +<% end -%> +<% unless options[:javascript] == 'jquery' -%> # jquery-rails is used by the dummy application gem "jquery-rails" +<% end -%> +<% if options[:skip_gemspec] -%> +group :development do + gem "<%= gem_for_database %>" +end +<% else -%> # Declare any dependencies that are still in development here instead of in # your gemspec. These might include edge Rails or gems from your path or # Git. Remember to move these dependencies to your gemspec before releasing # your gem to rubygems.org. +<% end -%> <% if options.dev? || options.edge? -%> # Your gem is dependent on dev or edge Rails. Once you can lock this diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile index 743036362e..1369140537 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile @@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('lib/**/*.rb') end -<% if full? && !options[:skip_active_record] -%> +<% if full? && !options[:skip_active_record] && !options[:skip_test_unit] -%> 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/gitignore b/railties/lib/rails/generators/rails/plugin_new/templates/gitignore index 458b2c662e..086d87818a 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/gitignore +++ b/railties/lib/rails/generators/rails/plugin_new/templates/gitignore @@ -1,8 +1,10 @@ .bundle/ log/*.log pkg/ +<% unless options[:skip_test_unit] && options[:dummy_path] == 'test/dummy' -%> <%= dummy_path %>/db/*.sqlite3 <%= dummy_path %>/db/*.sqlite3-journal <%= dummy_path %>/log/*.log <%= dummy_path %>/tmp/ <%= dummy_path %>/.sass-cache +<% end -%>
\ No newline at end of file diff --git a/railties/lib/rails/generators/rails/scaffold_controller/USAGE b/railties/lib/rails/generators/rails/scaffold_controller/USAGE index 673f69bc81..5cd51b62d4 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/USAGE +++ b/railties/lib/rails/generators/rails/scaffold_controller/USAGE @@ -1,8 +1,7 @@ Description: - Stubs out a scaffolded controller and its views. Pass the model name, - either CamelCased or under_scored, and a list of views as arguments. - The controller name is retrieved as a pluralized version of the model - name. + Stubs out a scaffolded controller, its seven RESTful actions and related + views. Pass the model name, either CamelCased or under_scored. The + controller name is retrieved as a pluralized version of the model name. To create a controller within a module, specify the model name as a path like 'parent_module/controller_name'. diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index ff9cf0087e..2ff340755a 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -37,8 +37,16 @@ module Rails self.current_path = File.expand_path(Dir.pwd) self.default_arguments = [] - setup :destination_root_is_set?, :ensure_current_path - teardown :ensure_current_path + def setup + destination_root_is_set? + ensure_current_path + super + end + + def teardown + ensure_current_path + super + end # Sets which generator should be tested: # diff --git a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb index 370750a175..2f25dcf832 100644 --- a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb +++ b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb @@ -6,7 +6,7 @@ class <%= class_name %>Test < ActionDispatch::PerformanceTest # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory], # :output => 'tmp/performance', :formats => [:flat] } - def test_homepage + test "homepage" do get '/' end end |