diff options
Diffstat (limited to 'railties')
59 files changed, 522 insertions, 216 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 21666103de..c465b08594 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.1.0 (unreleased)* +* Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn] + * Fixed database tasks for jdbc* adapters #jruby [Rashmi Yadav] @@ -28,7 +30,7 @@ by the prototype-rails gem. [fxn] * jQuery is the new default JavaScript library. [fxn] -* Changed scaffold and app generator to create Ruby 1.9 style hash when running on Ruby 1.9 [Prem Sichanugrist] +* Changed scaffold, application, and mailer generator to create Ruby 1.9 style hash when running on Ruby 1.9 [Prem Sichanugrist] So instead of creating something like: @@ -74,10 +76,42 @@ by the prototype-rails gem. [fxn] * Include all helpers from plugins and shared engines in application [Piotr Sarnacki] + +*Rails 3.0.7 (April 18, 2011)* + +*No changes. + + +*Rails 3.0.6 (April 5, 2011) + +* No changes. + + +*Rails 3.0.5 (February 26, 2011)* + +* No changes. + + +*Rails 3.0.4 (February 8, 2011)* + +* No changes. + + +*Rails 3.0.3 (November 16, 2010)* + +* No changes. + + +*Rails 3.0.2 (November 15, 2010)* + +* No changes. + + *Rails 3.0.1 (October 15, 2010)* * No Changes, just a version bump. + *Rails 3.0.0 (August 29, 2010)* * Application generation: --skip-testunit and --skip-activerecord become --skip-test-unit and --skip-active-record respectively. [fxn] diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 154355cac1..14d671c8f3 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -38,9 +38,10 @@ # Note that if you are working on a guide generation will by default process # only that one, so ONLY is rarely used nowadays. # -# LANGUAGE -# Use LANGUAGE when you want to generate translated guides in <tt>source/<LANGUAGE></tt> -# folder (such as <tt>source/es</tt>). Ignore it when generating English guides. +# GUIDES_LANGUAGE +# Use GUIDES_LANGUAGE when you want to generate translated guides in +# <tt>source/<GUIDES_LANGUAGE></tt> folder (such as <tt>source/es</tt>). +# Ignore it when generating English guides. # # EDGE # Set to "1" to indicate generated guides should be marked as edge. This @@ -67,7 +68,7 @@ module RailsGuides GUIDES_RE = /\.(?:textile|html\.erb)$/ def initialize(output=nil) - @lang = ENV['LANGUAGE'] + @lang = ENV['GUIDES_LANGUAGE'] initialize_dirs(output) create_output_dir_if_needed set_flags_from_environment diff --git a/railties/guides/source/action_controller_overview.textile b/railties/guides/source/action_controller_overview.textile index 3a1a4ee66e..891bae3d5e 100644 --- a/railties/guides/source/action_controller_overview.textile +++ b/railties/guides/source/action_controller_overview.textile @@ -110,6 +110,32 @@ When this form is submitted, the value of +params[:client]+ will be <tt>{"name" Note that the +params+ hash is actually an instance of +HashWithIndifferentAccess+ from Active Support, which acts like a hash that lets you use symbols and strings interchangeably as keys. +h4. JSON/XML parameters + +If you're writing a web service application, you might find yourself more comfortable on accepting parameters in JSON or XML format. Rails will automatically convert your parameters into +params+ hash, which you'll be able to access like you would normally do with form data. + +So for example, if you are sending this JSON parameter: + +<pre> +{ "company": { "name": "acme", "address": "123 Carrot Street" } } +</pre> + +You'll get <tt>params[:company]</tt> as <tt>{ :name => "acme", "address" => "123 Carrot Street" }</tt>. + +Also, if you've turned on +config.wrap_parameters+ in your initializer or calling +wrap_parameters+ in your controller, you can safely omit the root element in the JSON/XML parameter. The parameters will be cloned and wrapped in the key according to your controller's name by default. So the above parameter can be written as: + +<pre> +{ "name": "acme", "address": "123 Carrot Street" } +</pre> + +And assume that you're sending the data to +CompaniesController+, it would then be wrapped in +:company+ key like this: + +<ruby> +{ :name => "acme", :address => "123 Carrot Street", :company => { :name => "acme", :address => "123 Carrot Street" }} +</ruby> + +You can customize the name of the key or specific parameters you want to wrap by consulting the "API documentation":http://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html + h4. Routing Parameters The +params+ hash will always contain the +:controller+ and +:action+ keys, but you should use the methods +controller_name+ and +action_name+ instead to access these values. Any other parameters defined by the routing, such as +:id+ will also be available. As an example, consider a listing of clients where the list can show either active or inactive clients. We can add a route which captures the +:status+ parameter in a "pretty" URL: diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index f2170e120b..66869b4eeb 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -417,6 +417,14 @@ silence_stream(STDOUT) do end </ruby> +The +quietly+ method addresses the common use case where you want to silence STDOUT and STDERR, even in subprocesses: + +<ruby> +quietly { system 'bundle install' } +</ruby> + +For example, the railties test suite uses that one in a few places to prevent command messages from being echoed intermixed with the progress status. + Silencing exceptions is also possible with +suppress+. This method receives an arbitrary number of exception classes. If an exception is raised during the execution of the block and is +kind_of?+ any of the arguments, +suppress+ captures it and returns silently. Otherwise the exception is reraised: <ruby> @@ -1833,6 +1841,8 @@ The method +ordinalize+ returns the ordinal string corresponding to the receiver 2.ordinalize # => "2nd" 53.ordinalize # => "53rd" 2009.ordinalize # => "2009th" +-21.ordinalize # => "-21st" +-134.ordinalize # => "-134th" </ruby> NOTE: Defined in +active_support/core_ext/integer/inflections.rb+. diff --git a/railties/guides/source/association_basics.textile b/railties/guides/source/association_basics.textile index 94dce1b97b..458bfefad8 100644 --- a/railties/guides/source/association_basics.textile +++ b/railties/guides/source/association_basics.textile @@ -342,9 +342,9 @@ In designing a data model, you will sometimes find a model that should have a re <ruby> class Employee < ActiveRecord::Base - has_many :subordinates, :class_name => "Employee", + has_many :subordinates, :class_name => "Employee" + belongs_to :manager, :class_name => "Employee", :foreign_key => "manager_id" - belongs_to :manager, :class_name => "Employee" end </ruby> diff --git a/railties/guides/source/caching_with_rails.textile b/railties/guides/source/caching_with_rails.textile index 799339e674..91827fd493 100644 --- a/railties/guides/source/caching_with_rails.textile +++ b/railties/guides/source/caching_with_rails.textile @@ -98,7 +98,7 @@ You can also use +:if+ (or +:unless+) to pass a Proc that specifies when the act You can modify the default action cache path by passing a +:cache_path+ option. This will be passed directly to +ActionCachePath.path_for+. This is handy for actions with multiple possible routes that should be cached differently. If a block is given, it is called with the current controller instance. -Finally, if you are using memcached, you can also pass +:expires_in+. In fact, all parameters not used by +caches_action+ are sent to the underlying cache store. +Finally, if you are using memcached or Ehcache, you can also pass +:expires_in+. In fact, all parameters not used by +caches_action+ are sent to the underlying cache store. INFO: Action caching runs in an after filter. Thus, invalid requests won't generate spurious cache entries as long as you halt them. Typically, a redirection in some before filter that checks request preconditions does the job. @@ -304,6 +304,35 @@ The +write+ and +fetch+ methods on this cache accept two additional options that ActionController::Base.cache_store = :mem_cache_store, "cache-1.example.com", "cache-2.example.com" </ruby> +h4. ActiveSupport::Cache::EhcacheStore + +If you are using JRuby you can use Terracotta's Ehcache as the cache store for your application. Ehcache is an open source Java cache that also offers an enterprise version with increased scalability, management, and commercial support. You must first install the jruby-ehcache-rails3 gem (version 1.1.0 or later) to use this cache store. + +<ruby> +ActionController::Base.cache_store = :ehcache_store +</ruby> + +When initializing the cache, you may use the +:ehcache_config+ option to specify the Ehcache config file to use (where the default is "ehcache.xml" in your Rails config directory), and the :cache_name option to provide a custom name for your cache (the default is rails_cache). + +In addition to the standard +:expires_in+ option, the +write+ method on this cache can also accept the additional +:unless_exist+ option, which will cause the cache store to use Ehcache's +putIfAbsent+ method instead of +put+, and therefore will not overwrite an existing entry. Additionally, the +write+ method supports all of the properties exposed by the "Ehcache Element class":http://ehcache.org/apidocs/net/sf/ehcache/Element.html , including: + +|_. Property |_. Argument Type |_. Description | +| elementEvictionData | ElementEvictionData | Sets this element's eviction data instance. | +| eternal | boolean | Sets whether the element is eternal. | +| timeToIdle, tti | int | Sets time to idle | +| timeToLive, ttl, expires_in | int | Sets time to Live | +| version | long | Sets the version attribute of the ElementAttributes object. | + +These options are passed to the +write+ method as Hash options using either camelCase or underscore notation, as in the following examples: + +<ruby> +Rails.cache.write('key', 'value', :time_to_idle => 60.seconds, :timeToLive => 600.seconds) +caches_action :index, :expires_in => 60.seconds, :unless_exist => true +</ruby> + +For more information about Ehcache, see "http://ehcache.org/":http://ehcache.org/ . +For more information about Ehcache for JRuby and Rails, see "http://ehcache.org/documentation/jruby.html":http://ehcache.org/documentation/jruby.html + h4. Custom Cache Stores You can create your own custom cache store by simply extending +ActiveSupport::Cache::Store+ and implementing the appropriate methods. In this way, you can swap in any number of caching technologies into your Rails application. diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile index d7069b31fc..fbe3d46367 100644 --- a/railties/guides/source/configuring.textile +++ b/railties/guides/source/configuring.textile @@ -9,37 +9,38 @@ endprologue. h3. Locations for Initialization Code -Rails offers (at least) four good spots to place initialization code: +Rails offers four standard spots to place initialization code: -* application.rb -* Environment-specific Configuration Files +* +config/application.rb+ +* Environment-specific configuration files * Initializers -* After-Initializers +* After-initializers h3. Running Code Before Rails -To run some code before Rails itself is loaded, simply put it above the call to -+require 'rails/all'+ in your +application.rb+. +In the rare event that your application needs to run some code before Rails itself is loaded, put it above the call to +require 'rails/all'+ in your +config/application.rb+. h3. Configuring Rails Components -In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The +application.rb+ and environment-specific configuration files (such as +config/environments/production.rb+) allow you to specify the various settings that you want to pass down to all of the components. For example, the default Rails 3.0 +application.rb+ file includes this setting: +In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file +config/application.rb+ and environment-specific configuration files (such as +config/environments/production.rb+) allow you to specify the various settings that you want to pass down to all of the components. + +For example, the default +config/application.rb+ file includes this setting: <ruby> - config.filter_parameters += [:password] +config.filter_parameters += [:password] </ruby> -This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same +config+ object: +This is a setting for Rails itself. If you want to pass settings to individual Rails components, you can do so via the same +config+ object in +config/application.rb+: <ruby> - config.active_record.timestamped_migrations = false +config.active_record.observers = [:hotel_observer, :review_observer] </ruby> Rails will use that particular setting to configure Active Record. h4. Rails General Configuration -* +config.after_initialize+ takes a block which will be ran _after_ Rails has finished initializing. Useful for configuring values set up by other initializers: +* +config.after_initialize+ takes a block which will be ran _after_ Rails has finished initializing the application. That includes the initialization of the framework itself, plugins, engines, and all the application's initializers in +config/initializers+. Useful for configuring values set up by other initializers: <ruby> config.after_initialize do @@ -47,71 +48,63 @@ config.after_initialize do end </ruby> -* +config.allow_concurrency+ should be set to +true+ to allow concurrent (threadsafe) action processing. Set to +false+ by default. You probably don't want to call this one directly, though, because a series of other adjustments need to be made for threadsafe mode to work properly. Can also be enabled with +threadsafe!+. +* +config.allow_concurrency+ should be true to allow concurrent (threadsafe) action processing. False by default. You probably don't want to call this one directly, though, because a series of other adjustments need to be made for threadsafe mode to work properly. Can also be enabled with +threadsafe!+. -* +config.asset_host+ sets the host for the assets. Useful when CDNs are used for hosting assets rather than the application server itself. Shorter version of +config.action_controller.asset_host+. +* +config.asset_host+ sets the host for the assets. Useful when CDNs are used for hosting assets, or when you want to work around the concurrency constraints builtin in browsers using different domain aliases. Shorter version of +config.action_controller.asset_host+. -* +config.asset_path+ takes a block which configures where assets can be found. Shorter version of +config.action_controller.asset_path+. +* +config.asset_path+ can take a callable, a string, or be +nil+. Default is +nil+. If set, this configuration parameter let's you decorate asset paths. For example, the normal path for +blog.js+ would be +/javascripts/blog.js+, let that absolute path be +path+. If +config.asset_path+ is a callable, Rails calls it when generating asset paths passing +path+ as argument. If +config.asset_path+ is a string, it is expected to be a +sprintf+ format string with a +%s+ where +path+ will get inserted. In either case, Rails outputs the decorated path. *This option is ignored if the asset pipeline is enabled, which is by default*. Shorter version of +config.action_controller.asset_path+. <ruby> - config.asset_path = proc { |asset_path| "assets/#{asset_path}" } +config.asset_path = proc { |path| "/blog/public#{path}" } </ruby> -* +config.autoload_once_paths+ accepts an array of paths from which Rails will automatically load from only once. All elements of this array must also be in +autoload_paths+. - -* +config.autoload_paths+ accepts an array of additional paths to prepend to the load path. By default, all app, lib, vendor and mock paths are included in this list. +* +config.autoload_once_paths+ accepts an array of paths from which Rails will autoload constants that won't be wiped per request. Relevant if +config.cache_classes+ is false, which is the case in development mode by default. Otherwise, all autoloading happens only once. All elements of this array must also be in +autoload_paths+. Default is an empty array. -* +config.cache_classes+ controls whether or not application classes should be reloaded on each request. Defaults to _true_ in development, _false_ in test and production. Can also be enabled with +threadsafe!+. +* +config.autoload_paths+ accepts an array of paths from which Rails will autoload constants. Default is all directories under +app+. -* +config.action_view.cache_template_loading+ controls whether or not templates should be reloaded on each request. Defaults to whatever is set for config.cache_classes. +* +config.cache_classes+ controls whether or not application classes and modules should be reloaded on each request. Defaults to true in development mode, and false in test and production modes. Can also be enabled with +threadsafe!+. -* +config.cache_store+ configures which cache store to use for Rails caching. Options include +:memory_store+, +:file_store+, +:mem_cache_store+ or the name of your own custom class. Defaults to +:file_store+. +* +config.action_view.cache_template_loading+ controls whether or not templates should be reloaded on each request. Defaults to whatever is set for +config.cache_classes+. -* +config.colorize_logging+ specifies whether or not to use ANSI color codes when logging information. Defaults to _true_. +* +config.cache_store+ configures which cache store to use for Rails caching. Options include one of the symbols +:memory_store+, +:file_store+, +:mem_cache_store+, or an object that implements the cache API. Defaults to +:file_store+ if the directory +tmp/cache+ exists, and to +:memory_store+ otherwise. -* +config.consider_all_requests_local+ is generally set to +true+ during development and +false+ during production; if it is set to +true+, then any error will cause detailed debugging information to be dumped in the HTTP response. For finer-grained control, set this to +false+ and implement +local_request?+ in controllers to specify which requests should provide debugging information on errors. +* +config.colorize_logging+ specifies whether or not to use ANSI color codes when logging information. Defaults to true. -* +config.controller_paths+ configures where Rails can find controllers for this application. +* +config.consider_all_requests_local+ is a flag. If true then any error will cause detailed debugging information to be dumped in the HTTP response, and the +Rails::Info+ controller will show the application runtime context in +/rails/info/properties+. True by default in development and test environments, and false in production mode. For finer-grained control, set this to false and implement +local_request?+ in controllers to specify which requests should provide debugging information on errors. -* +config.dependency_loading+ enables or disables dependency loading during the request cycle. Setting dependency_loading to _true_ will allow new classes to be loaded during a request and setting it to _false_ will disable this behavior. Can also be enabled with +threadsafe!+. +* +config.dependency_loading+ is a flag that allows you to disable constant autoloading setting it to false. It only has effect if +config.cache_classes+ is true, which it is by default in production mode. This flag is set to false by +config.threadsafe!+. -* +config.eager_load_paths+ accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the +app+ directory of the application. All elements of this array must also be in +load_paths+. +* +config.eager_load_paths+ accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the +app+ directory of the application. * +config.encoding+ sets up the application-wide encoding. Defaults to UTF-8. * +config.filter_parameters+ used for filtering out the parameters that you don't want shown in the logs, such as passwords or credit card numbers. -* +config.force_ssl+ forcing all requests to be under HTTPS protocol by using +Rack::SSL+ middleware. This will secure your application from a session hijack attempt. - -* +config.helper_paths+ configures where Rails can find helpers for this application. +* +config.force_ssl+ forces all requests to be under HTTPS protocol by using +Rack::SSL+ middleware. -* +config.log_level+ defines the verbosity of the Rails logger. In production mode, this defaults to +:info+. In development mode, it defaults to +:debug+. +* +config.log_level+ defines the verbosity of the Rails logger. This option defaults to +:debug+ for all modes except production, where it defaults to +:info+. -* +config.log_path+ overrides the path to the log file to use. Defaults to +log/#{environment}.log+ (e.g. log/development.log or log/production.log). +* +config.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ +Logger+ class. Defaults to an instance of +ActiveSupport::BufferedLogger+, with auto flushing off in production mode. -* +config.logger+ accepts a logger conforming to the interface of Log4r or the default Ruby 1.8+ Logger class, which is then used to log information from Action Controller. Set to nil to disable logging. +* +config.middleware+ allows you to configure the application's middleware. This is covered in depth in the "Configuring Middleware":configuring-middleware section below. -* +config.middleware+ allows you to configure the application's middleware. This is covered in depth in the "Configuring Middleware" section below. +* +config.plugins+ accepts the list of plugins to load. If this is set to +nil+, default, all plugins will be loaded. If this is set to +[]+, no plugins will be loaded. Otherwise, plugins will be loaded in the order specified. This option let's you enforce some particular loading order, useful when dependencies between plugins require it. For that use case, put first the plugins you want to be loaded in a certain order, and then the special symbol +:all+ to have the rest loaded without the need to specify them. -* +config.plugins+ accepts the list of plugins to load. If this is set to nil, all plugins will be loaded. If this is set to [], no plugins will be loaded. Otherwise, plugins will be loaded in the order specified. +* +config.preload_frameworks+ enables or disables preloading all frameworks at startup. Enabled by +config.threadsafe!+. Defaults to +nil+, so is disabled. -* +config.preload_frameworks+ enables or disables preloading all frameworks at startup. Can also be enabled with +threadsafe!+. Defaults to +nil+, so is disabled. +* +config.reload_plugins+ enables or disables plugin reloading. Defaults to false. -* +config.reload_plugins+ enables or disables plugin reloading. +* +config.secret_token+ used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get +config.secret_token+ initialized to a random key in +config/initializers/secret_token.rb+. -* +config.root+ configures the root path of the application. +* +config.serve_static_assets+ configures Rails to serve static assets. Defaults to true, but in the production environment is turned off. The server software used to run the application should be used to serve the assets instead. -* +config.secret_token+ used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. - -* +config.serve_static_assets+ configures Rails to serve static assets. Defaults to _true_, but in the production environment is turned off. The server software used to run the application should be used to serve the assets instead. - -* +config.session_store+ is usually set up in +config/initializers/session_store.rb+ and specifies what class to use to store the session. Custom session stores can be specified like so: +* +config.session_store+ is usually set up in +config/initializers/session_store.rb+ and specifies what class to use to store the session. Possible values are +:cookie_store+, default, +:mem_cache_store+, and +:disabled+. The last one tells Rails not to deal with sessions. Custom session stores can also be specified like so: <ruby> - config.session_store = :my_custom_store +config.session_store :my_custom_store </ruby> -This custom store must be defined as +ActionDispatch::Session::MyCustomStore+. +This custom store must be defined as +ActionDispatch::Session::MyCustomStore+. In addition to symbols, they can also be objects implementing a certain API, like +ActiveRecord::SessionStore+, in which case no special namespace is required. * +config.threadsafe!+ enables +allow_concurrency+, +cache_classes+, +dependency_loading+ and +preload_frameworks+ to make the application threadsafe. @@ -119,7 +112,9 @@ WARNING: Threadsafe operation is incompatible with the normal workings of develo * +config.time_zone+ sets the default time zone for the application and enables time zone awareness for Active Record. -* +config.whiny_nils+ enables or disables warnings when any methods of nil are invoked. Defaults to _true_ in development and test environments. +* +config.whiny_nils+ enables or disables warnings when a certain set of methods are invoked on +nil+ and it does not respond to them. Defaults to true in development and test environments. + +* +config.assets.enabled+ a flag that controls whether the asset pipeline is enabled. It is explicitly initialized in +config/application.rb+. h4. Configuring Generators diff --git a/railties/guides/source/contributing_to_ruby_on_rails.textile b/railties/guides/source/contributing_to_ruby_on_rails.textile index cb09b180a2..5eb925d7d2 100644 --- a/railties/guides/source/contributing_to_ruby_on_rails.textile +++ b/railties/guides/source/contributing_to_ruby_on_rails.textile @@ -232,11 +232,11 @@ You can also help out by examining pull requests that have been submitted to Rub $ git checkout -b testing_branch </shell> -Then you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to the master branch located at https://github.com/JohnSmith/rails. +Then you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to the topic branch located at https://github.com/JohnSmith/rails. <shell> $ git remote add JohnSmith git://github.com/JohnSmith/rails.git -$ git pull JohnSmith master +$ git pull JohnSmith topic </shell> After applying their branch, test it out! Here are some things to think about: @@ -300,10 +300,16 @@ h4. Follow the Coding Conventions Rails follows a simple set of coding style conventions. -* Two spaces, no tabs -* Prefer +&&+/+||+ over +and+/+or+ -* +MyClass.my_method(my_arg)+ not +my_method( my_arg )+ or +my_method my_arg+ -* Follow the conventions you see used in the source already +* Two spaces, no tabs. +* No trailing whitespace. Blank lines should not have any space. +* Indent after private/protected. +* Prefer +&&+/+||+ over +and+/+or+. +* Prefer class << self block over self.method for class methods. +* +MyClass.my_method(my_arg)+ not +my_method( my_arg )+ or +my_method my_arg+. +* a = b and not a=b. +* Follow the conventions you see used in the source already. + +These are some guidelines and please use your best judgement in using them. h4. Sanity Check @@ -344,20 +350,22 @@ Navigate to the Rails "GitHub repository":https://github.com/rails/rails and pre Add the new remote to your local repository on your local machine: <shell> -$ git remote add mine https://<your user name>@github.com/<your user name>/rails.git +$ git remote add mine https://<your user name>@github.com/<your user name>/rails.git </shell> Push to your remote: <shell> -$ git push mine master +$ git push mine my_new_branch </shell> h4. Issue a Pull Request -Navigate to the Rails repository you just pushed to (e.g. https://github.com/<your user name>/rails) and press "Pull Request" in the upper right hand corner. - -Ensure the changesets you introduced are included in the "Commits" tab and that the "Files Changed" incorporate all of your changes. +Navigate to the Rails repository you just pushed to (e.g. https://github.com/<your user name>/rails) and press "Pull Request" in the upper right hand corner. + +Write your branch name in branch field (is filled with master by default) and press "Update Commit Range" + +Ensure the changesets you introduced are included in the "Commits" tab and that the "Files Changed" incorporate all of your changes. Fill in some details about your potential patch including a meaningful title. When finished, press "Send pull request." Rails Core will be notified about your submission. @@ -377,6 +385,7 @@ All contributions, either via master or docrails, get credit in "Rails Contribut h3. Changelog +* May 12, 2011: Modified to prefer topic branches instead of master branch for users contributions by "Guillermo Iguaran":http://quillarb.org * April 29, 2011: Reflect GitHub Issues and Pull Request workflow by "Dan Pickett":http://www.enlightsolutions.com * April 14, 2011: Modified Contributing to the Rails Code section to add '[#ticket_number state:commited]' on patches commit messages by "Sebastian Martinez":http://wyeworks.com * December 28, 2010: Complete revision by "Xavier Noria":credits.html#fxn diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile index ac709968d9..a3181b9ac5 100644 --- a/railties/guides/source/generators.textile +++ b/railties/guides/source/generators.textile @@ -111,7 +111,6 @@ In order to understand what a generator template means, let's create the file +l <ruby> # Add initialization content here - </ruby> And now let's change the generator to copy this template when invoked: @@ -286,8 +285,8 @@ end Now, when the helper generator is invoked and TestUnit is configured as the test framework, it will try to invoke both +Rails::TestUnitGenerator+ and +TestUnit::MyHelperGenerator+. Since none of those are defined, we can tell our generator to invoke +TestUnit::Generators::HelperGenerator+ instead, which is defined since it's a Rails generator. To do that, we just need to add: <ruby> - # Search for :helper instead of :my_helper - hook_for :test_framework, :as => :helper +# Search for :helper instead of :my_helper +hook_for :test_framework, :as => :helper </ruby> And now you can re-run scaffold for another resource and see it generating tests as well! @@ -412,7 +411,7 @@ h4. +plugin+ +plugin+ will install a plugin into the current application. <ruby> - plugin("dynamic-form", :git => "git://github.com/rails/dynamic-form.git") +plugin("dynamic-form", :git => "git://github.com/rails/dynamic-form.git") </ruby> Available options are: @@ -441,13 +440,13 @@ Available options are: Any additional options passed to this method are put on the end of the line: <ruby> - gem("devise", :git => "git://github.com/plataformatec/devise", :branch => "master") +gem("devise", :git => "git://github.com/plataformatec/devise", :branch => "master") </ruby> The above code will put the following line into +Gemfile+: <ruby> - gem "devise", :git => "git://github.com/plataformatec/devise", :branch => "master" +gem "devise", :git => "git://github.com/plataformatec/devise", :branch => "master" </ruby> @@ -456,7 +455,7 @@ h4. +add_source+ Adds a specified source to +Gemfile+: <ruby> - add_source "http://gems.github.com" +add_source "http://gems.github.com" </ruby> h4. +application+ @@ -464,7 +463,7 @@ h4. +application+ Adds a line to +config/application.rb+ directly after the application class definition. <ruby> - application "config.asset_host = 'http://example.com'" +application "config.asset_host = 'http://example.com'" </ruby> This method can also take a block: @@ -490,10 +489,10 @@ h4. +git+ Runs the specified git command: <ruby> - git :init - git :add => "." - git :commit => "-m First commit!" - git :add => "onefile.rb", :rm => "badfile.cxx" +git :init +git :add => "." +git :commit => "-m First commit!" +git :add => "onefile.rb", :rm => "badfile.cxx" </ruby> The values of the hash here being the arguments or options passed to the specific git command. As per the final example shown here, multiple git commands can be specified at a time, but the order of their running is not guaranteed to be the same as the order that they were specified in. @@ -503,15 +502,15 @@ h4. +vendor+ Places a file into +vendor+ which contains the specified code. <ruby> - vendor("sekrit.rb", '#top secret stuff') +vendor("sekrit.rb", '#top secret stuff') </ruby> This method also takes a block: <ruby> - vendor("seeds.rb") do - "puts 'in ur app, seeding ur database'" - end +vendor("seeds.rb") do + "puts 'in ur app, seeding ur database'" +end </ruby> h4. +lib+ @@ -519,7 +518,7 @@ h4. +lib+ Places a file into +lib+ which contains the specified code. <ruby> - lib("special.rb", 'p Rails.root') +lib("special.rb", 'p Rails.root') </ruby> This method also takes a block: @@ -535,7 +534,7 @@ h4. +rakefile+ Creates a Rake file in the +lib/tasks+ directory of the application. <ruby> - rakefile("test.rake", 'hello there') +rakefile("test.rake", 'hello there') </ruby> This method also takes a block: @@ -555,7 +554,7 @@ h4. +initializer+ Creates an initializer in the +config/initializers+ directory of the application: <ruby> - initializer("begin.rb", "puts 'this is the beginning'") +initializer("begin.rb", "puts 'this is the beginning'") </ruby> This method also takes a block: @@ -571,7 +570,7 @@ h4. +generate+ Runs the specified generator where the first argument is the generator name and the remaining arguments are passed directly to the generator. <ruby> - generate("scaffold", "forums title:string description:text") +generate("scaffold", "forums title:string description:text") </ruby> @@ -580,7 +579,7 @@ h4. +rake+ Runs the specified Rake task. <ruby> - rake("db:migrate") +rake("db:migrate") </ruby> Available options are: @@ -593,7 +592,7 @@ h4. +capify!+ Runs the +capify+ command from Capistrano at the root of the application which generates Capistrano configuration. <ruby> - capify! +capify! </ruby> h4. +route+ @@ -601,7 +600,7 @@ h4. +route+ Adds text to the +config/routes.rb+ file: <ruby> - route("resources :people") +route("resources :people") </ruby> h4. +readme+ @@ -609,7 +608,7 @@ h4. +readme+ Output the contents of a file in the template's +source_path+, usually a README. <ruby> - readme("README") +readme("README") </ruby> h3. Changelog diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index a826a33120..1c66115d44 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1450,14 +1450,14 @@ Two very common sources of data that are not UTF-8: h3. Changelog -* April 26, 2011: Changed migration code from +up+, +down+ pair to +change+ method "Prem Sichanugrist":"http://sikachu.com" -* April 11, 2011: Changed scaffold_controller generator to create format block for JSON instead of XML "Sebastian Martinez":http://www.wyeworks.com +* April 26, 2011: Change migration code from +up+, +down+ pair to +change+ method by "Prem Sichanugrist":http://sikachu.com +* April 11, 2011: Change scaffold_controller generator to create format block for JSON instead of XML by "Sebastian Martinez":http://www.wyeworks.com * August 30, 2010: Minor editing after Rails 3 release by "Joost Baaij":http://www.spacebabies.nl * July 12, 2010: Fixes, editing and updating of code samples by "Jaime Iniesta":http://jaimeiniesta.com * May 16, 2010: Added a section on configuration gotchas to address common encoding problems that people might have by "Yehuda Katz":http://www.yehudakatz.com * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com -* April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits.html#raasdnil -* April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com +* April 25, 2010: Couple of more minor fixups by "Mikel Lindsaar":credits.html#raasdnil +* April 1, 2010: Fixed document to validate XHTML 1.0 Strict by "Jaime Iniesta":http://jaimeiniesta.com * February 8, 2010: Full re-write for Rails 3.0-beta, added helpers and before_filters, refactored code by "Mikel Lindsaar":credits.html#raasdnil * January 24, 2010: Re-write for Rails 3.0 by "Mikel Lindsaar":credits.html#raasdnil * July 18, 2009: Minor cleanup in anticipation of Rails 2.3.3 by "Mike Gunderloy":credits.html#mgunderloy diff --git a/railties/guides/source/rails_on_rack.textile b/railties/guides/source/rails_on_rack.textile index b1db2942dd..aa53aa6db6 100644 --- a/railties/guides/source/rails_on_rack.textile +++ b/railties/guides/source/rails_on_rack.textile @@ -117,8 +117,6 @@ You can add a new middleware to the middleware stack using any of the following * +config.middleware.insert_after(existing_middleware, new_middleware, args)+ - Adds the new middleware after the specified existing middleware in the middleware stack. -<strong>Example:</strong> - <ruby> # config/environment.rb @@ -134,8 +132,6 @@ h5. Swapping a Middleware You can swap an existing middleware in the middleware stack using +config.middleware.swap+. -<strong>Example:</strong> - <ruby> # config/environment.rb @@ -173,8 +169,6 @@ h4. Customizing Internal Middleware Stack It's possible to replace the entire middleware stack with a custom stack using +ActionController::Dispatcher.middleware=+. -<strong>Example:</strong> - Put the following in an initializer: <ruby> diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile index 8c408ec06b..e0ccc7a6e6 100644 --- a/railties/guides/source/security.textile +++ b/railties/guides/source/security.textile @@ -372,7 +372,7 @@ def signup end </ruby> -Mass-assignment saves you much work, because you don't have to set each value individually. Simply pass a hash to the new() method, or assign attributes=(attributes) a hash value, to set the model's attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the URL like this: +Mass-assignment saves you much work, because you don't have to set each value individually. Simply pass a hash to the +new+ method, or +assign_attributes=+ a hash value, to set the model's attributes to the values in the hash. The problem is that it is often used in conjunction with the parameters (params) hash available in the controller, which may be manipulated by an attacker. He may do so by changing the URL like this: <pre> "name":http://www.example.com/user/signup?user[name]=ow3ned&user[admin]=1 @@ -386,7 +386,7 @@ params[:user] # => {:name => “ow3ned”, :admin => true} So if you create a new user using mass-assignment, it may be too easy to become an administrator. -Note that this vulnerability is not restricted to database columns. Any setter method, unless explicitly protected, is accessible via the <tt>attributes=</tt> method. In fact, this vulnerability is extended even further with the introduction of nested mass assignment (and nested object forms) in Rails 2.3. The +accepts_nested_attributes_for+ declaration provides us the ability to extend mass assignment to model associations (+has_many+, +has_one+, +has_and_belongs_to_many+). For example: +Note that this vulnerability is not restricted to database columns. Any setter method, unless explicitly protected, is accessible via the <tt>attributes=</tt> method. In fact, this vulnerability is extended even further with the introduction of nested mass assignment (and nested object forms) in Rails 2.3+. The +accepts_nested_attributes_for+ declaration provides us the ability to extend mass assignment to model associations (+has_many+, +has_one+, +has_and_belongs_to_many+). For example: <ruby> class Person < ActiveRecord::Base @@ -410,7 +410,7 @@ To avoid this, Rails provides two class methods in your Active Record class to c attr_protected :admin </ruby> -+attr_protected+ also optionally takes a scope option using :as which allows you to define multiple mass-assignment groupings. If no scope is defined then attributes will be added to the default group. ++attr_protected+ also optionally takes a role option using :as which allows you to define multiple mass-assignment groupings. If no role is defined then attributes will be added to the :default role. <ruby> attr_protected :last_login, :as => :admin @@ -433,7 +433,7 @@ params[:user] # => {:name => "ow3ned", :admin => true} @user.admin # => true </ruby> -When assigning attributes in Active Record using +attributes=+, or +update_attributes+ the :default scope will be used. To assign attributes using different scopes you should use +assign_attributes+ which accepts an optional :as options parameter. If no :as option is provided then the :default scope will be used. You can also bypass mass-assignment security by using the +:without_protection+ option. Here is an example: +When assigning attributes in Active Record using +attributes=+ the :default role will be used. To assign attributes using different roles you should use +assign_attributes+ which accepts an optional :as options parameter. If no :as option is provided then the :default role will be used. You can also bypass mass-assignment security by using the +:without_protection+ option. Here is an example: <ruby> @user = User.new @@ -451,7 +451,7 @@ When assigning attributes in Active Record using +attributes=+, or +update_attri @user.is_admin # => true </ruby> -In a similar way, +new+, +create+ and <tt>create!</tt> methods respect mass-assignment security and accepts either +:as+ or +:without_protection+ options. For example: +In a similar way, +new+, +create+, <tt>create!</tt>, +update_attributes+, and +update_attributes!+ methods all respect mass-assignment security and accept either +:as+ or +:without_protection+ options. For example: <ruby> @user = User.new({ :name => 'Sebastian', :is_admin => true }, :as => :admin) diff --git a/railties/guides/source/testing.textile b/railties/guides/source/testing.textile index efa2bbdca6..7a93c3a1e6 100644 --- a/railties/guides/source/testing.textile +++ b/railties/guides/source/testing.textile @@ -38,7 +38,7 @@ When you do end up destroying your testing database (and it will happen, trust m h4. Rails Sets up for Testing from the Word Go -Rails creates a +test+ folder for you as soon as you create a Rails project using +rails _application_name_+. If you list the contents of this folder then you shall see: +Rails creates a +test+ folder for you as soon as you create a Rails project using +rails new+ _application_name_. If you list the contents of this folder then you shall see: <shell> $ ls -F test/ @@ -54,7 +54,7 @@ For good tests, you'll need to give some thought to setting up test data. In Rai h5. What are Fixtures? -_Fixtures_ is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and assume one of two formats: *YAML* or *CSV*. In this guide, we will use *YAML*, which is the preferred format. +_Fixtures_ is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run. Fixtures are database independent and assume a single format: *YAML*. You'll find fixtures under your +test/fixtures+ directory. When you run +rails generate model+ to create a new model, fixture stubs will be automatically created and placed in this directory. @@ -81,7 +81,7 @@ Each fixture is given a name followed by an indented list of colon-separated key h5. ERB'in It Up -ERB allows you to embed ruby code within templates. Both the YAML and CSV fixture formats are pre-processed with ERB when you load fixtures. This allows you to use Ruby to help you generate some sample data. +ERB allows you to embed ruby code within templates. YAML fixture format is pre-processed with ERB when you load fixtures. This allows you to use Ruby to help you generate some sample data. <erb> <% earth_size = 20 %> diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index dd01bbab1d..1e4d25f18c 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -157,7 +157,8 @@ module Rails middleware.use ::Rack::Lock unless config.allow_concurrency middleware.use ::Rack::Runtime - middleware.use ::Rails::Rack::Logger + middleware.use ::Rack::MethodOverride + middleware.use ::Rails::Rack::Logger # must come after Rack::MethodOverride to properly log overridden methods middleware.use ::ActionDispatch::ShowExceptions, config.consider_all_requests_local middleware.use ::ActionDispatch::RemoteIp, config.action_dispatch.ip_spoofing_check, config.action_dispatch.trusted_proxies middleware.use ::Rack::Sendfile, config.action_dispatch.x_sendfile_header @@ -171,7 +172,6 @@ module Rails end middleware.use ::ActionDispatch::ParamsParser - middleware.use ::Rack::MethodOverride middleware.use ::ActionDispatch::Head middleware.use ::Rack::ConditionalGet middleware.use ::Rack::ETag, "no-cache" @@ -199,4 +199,4 @@ module Rails require "rails/console/helpers" end end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 29b9c27a13..3b74de690a 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -34,7 +34,7 @@ module Rails @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false @assets.paths = [] - @assets.precompile = [ /\w+\.(?!js|css)$/, "application.js", "application.css" ] + @assets.precompile = [ /\w+\.(?!js|css).+/, "application.js", "application.css" ] @assets.prefix = "/assets" @assets.js_compressor = nil diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 4182757346..4a082aedb8 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -6,7 +6,8 @@ aliases = { "g" => "generate", "c" => "console", "s" => "server", - "db" => "dbconsole" + "db" => "dbconsole", + "r" => "runner" } command = ARGV.shift diff --git a/railties/lib/rails/commands/runner.rb b/railties/lib/rails/commands/runner.rb index ddd08a32ee..f8b00e7249 100644 --- a/railties/lib/rails/commands/runner.rb +++ b/railties/lib/rails/commands/runner.rb @@ -25,7 +25,7 @@ ARGV.clone.options do |opts| opts.separator "-------------------------------------------------------------" opts.separator "#!/usr/bin/env #{File.expand_path($0)} runner" opts.separator "" - opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }" + opts.separator "Product.all.each { |p| p.price *= 2 ; p.save! }" opts.separator "-------------------------------------------------------------" end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 2015a944f0..6a125685d0 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -523,6 +523,7 @@ module Rails initializer :append_assets_path do |app| app.config.assets.paths.unshift *paths["vendor/assets"].existent + app.config.assets.paths.unshift *paths["lib/assets"].existent app.config.assets.paths.unshift *paths["app/assets"].existent end diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 241db4b0a9..f424492bb4 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -47,6 +47,7 @@ module Rails paths.add "app/mailers", :eager_load => true paths.add "app/views" paths.add "lib", :load_path => true + paths.add "lib/assets", :glob => "*" paths.add "lib/tasks", :glob => "**/*.rake" paths.add "config" paths.add "config/environments", :glob => "#{Rails.env}.rb" diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index e8709b2ddd..a5743762e5 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -28,6 +28,9 @@ module Rails class_option :skip_gemfile, :type => :boolean, :default => false, :desc => "Don't create a Gemfile" + class_option :skip_bundle, :type => :boolean, :default => false, + :desc => "Don't run bundle install" + class_option :skip_git, :type => :boolean, :aliases => "-G", :default => false, :desc => "Skip Git ignores and keeps" @@ -184,13 +187,18 @@ module Rails "gem '#{options[:javascript]}-rails'" unless options[:skip_javascript] end - def bundle_if_dev_or_edge - bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') - run "#{bundle_command} install" if dev_or_edge? + def bundle_command(command) + require 'bundler' + require 'bundler/cli' + + say_status :run, "bundle #{command}" + Bundler::CLI.new.send(command) + rescue + say_status :failure, "bundler raised an exception, are you offline?", :red end - def dev_or_edge? - options.dev? || options.edge? + def run_bundle + bundle_command('install') unless options[:skip_gemfile] || options[:skip_bundle] end def empty_directory_with_gitkeep(destination, config = {}) diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index 8d03cb911b..1f6a7a2f59 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -117,8 +117,8 @@ module Rails # # ==== Switches # - # All hooks come with switches for user interface. If the user don't want - # to use any test framework, he can do: + # All hooks come with switches for user interface. If you do not want + # to use any test framework, you can do: # # rails generate controller Account --skip-test-framework # diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index b26161f1d0..9450894b05 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -13,12 +13,13 @@ module Rails def field_type @field_type ||= case type - when :integer, :float, :decimal then :text_field - when :time then :time_select - when :datetime, :timestamp then :datetime_select - when :date then :date_select - when :text then :text_area - when :boolean then :check_box + when :integer then :number_field + when :float, :decimal then :text_field + when :time then :time_select + when :datetime, :timestamp then :datetime_select + when :date then :date_select + when :text then :text_area + when :boolean then :check_box else :text_field end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index d79f76c799..5f9fb9685c 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -9,11 +9,20 @@ module Rails @options = generator.options end - private + private + %w(template copy_file directory empty_directory inside + empty_directory_with_gitkeep create_file chmod shebang).each do |method| + class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def #{method}(*args, &block) + @generator.send(:#{method}, *args, &block) + end + RUBY + end - def method_missing(meth, *args, &block) - @generator.send(meth, *args, &block) - end + # TODO: Remove once this is fully in place + def method_missing(meth, *args, &block) + @generator.send(meth, *args, &block) + end end # The application builder allows you to override elements of the application @@ -21,7 +30,7 @@ module Rails # generator. # # This allows you to override entire operations, like the creation of the - # Gemfile, README, or javascript files, without needing to know exactly + # Gemfile, README, or JavaScript files, without needing to know exactly # what those operations do so you can create another template action. class AppBuilder def rakefile @@ -215,7 +224,7 @@ module Rails build(:leftovers) end - public_task :apply_rails_template, :bundle_if_dev_or_edge + public_task :apply_rails_template, :run_bundle protected diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index a69efdf29d..20bd9db624 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -9,7 +9,7 @@ source 'http://rubygems.org' <%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%> gem 'sass' gem 'coffee-script' -gem 'uglifier' +# gem 'uglifier' <%= gem_for_javascript %> @@ -22,4 +22,4 @@ gem 'uglifier' # To use debugger # <%= gem_for_ruby_debugger %> -<%= gem_for_turn -%>
\ No newline at end of file +<%= gem_for_turn -%> diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt index 612c614f2e..19294b3478 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt @@ -1,5 +1,8 @@ -// FIXME: Tell people that this is a manifest file, real code should go into discrete files -// FIXME: Tell people how Sprockets and CoffeeScript works +// This is a manifest file that'll be compiled into including all the files listed below. +// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically +// be included in the compiled file accessible from http://example.com/assets/application.js +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. // <% unless options[:skip_javascript] -%> //= require <%= options[:javascript] %> diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css index f4b082ccc0..fc25b5723f 100644 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css @@ -1,5 +1,7 @@ /* - * FIXME: Introduce SCSS & Sprockets + * This is a manifest file that'll automatically include all the stylesheets available in this directory + * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at + * the top of the compiled file, but it's generally better to create a new file per style scope. *= require_self *= require_tree . */
\ No newline at end of file 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 e1946807b0..8ff80c6fd3 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/application.rb +++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb @@ -56,11 +56,6 @@ module <%= app_const_base %> # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] -<% unless options[:skip_active_record] -%> - # Enable IdentityMap for Active Record, to disable set to false or remove the line below. - config.active_record.identity_map = true -<% end -%> - # Enable the asset pipeline config.assets.enabled = true end diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml index c0c3588be1..4807986333 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml @@ -2,7 +2,10 @@ # # Get the bindings: # gem install ruby-frontbase - +# +# Configure Using Gemfile +# gem 'ruby-frontbase' +# development: adapter: frontbase host: localhost diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml index df5ef33064..3d689a110a 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml @@ -28,6 +28,9 @@ # On Windows: # Issue the command: gem install ibm_db # +# Configure Using Gemfile +# gem 'ibm_db' +# # For more details on the installation and the connection parameters below, # please refer to the latest documents at http://rubyforge.org/docman/?group_id=2361 diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml index ca807c9f3f..6bf83e86a5 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml @@ -3,6 +3,9 @@ # Install the MySQL driver: # gem install activerecord-jdbcmysql-adapter # +# Configure Using Gemfile +# gem 'activerecord-jdbcmysql-adapter' +# # And be sure to use new-style password hashing: # http://dev.mysql.com/doc/refman/5.0/en/old-client.html development: 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 a228aca5d2..0c7f45322b 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 @@ -8,6 +8,10 @@ # gem install pg # Choose the win32 build. # Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'activerecord-jdbcpostgresql-adapter' + development: adapter: jdbcpostgresql encoding: unicode diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml index 30776b3b4e..6d241d57ae 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml @@ -1,6 +1,9 @@ # SQLite version 3.x # gem 'activerecord-jdbcsqlite3-adapter' - +# +# Configure Using Gemfile +# gem 'activerecord-jdbcsqlite3-adapter' +# development: adapter: jdbcsqlite3 database: db/development.sqlite3 diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml index 5d28c7c312..62dc7b2c48 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/mysql.yml @@ -1,7 +1,7 @@ # MySQL. Versions 4.1 and 5.0 are recommended. # -# Install the MySQL driver: -# gem install mysql2 +# Ensure the MySQL gem is defined in your Gemfile +# gem 'mysql2' # # And be sure to use new-style password hashing: # http://dev.mysql.com/doc/refman/5.0/en/old-client.html 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 4e6391e3d6..467dfc3956 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 @@ -8,6 +8,10 @@ # gem install pg # Choose the win32 build. # Install PostgreSQL and put its /bin directory on your path. +# +# Configure Using Gemfile +# gem 'pg' +# development: adapter: postgresql encoding: unicode diff --git a/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml b/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml index 90d87cc295..5989eaf9dd 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +++ b/railties/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml @@ -1,5 +1,6 @@ # SQLite version 3.x -# gem install sqlite3 +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' development: adapter: sqlite3 database: db/development.sqlite3 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 41b2374eda..066aa54862 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 @@ -22,4 +22,3 @@ # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin 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 9553f3bdde..1c3dc1117f 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 @@ -31,7 +31,7 @@ # Use a different cache store in production # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and javascripts from an asset server + # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 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 32ffbee7a1..e56195da80 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 @@ -4,7 +4,7 @@ # which will be enabled by default in the upcoming version of Ruby on Rails. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActionController::Base.wrap_parameters :format => [:json] +ActionController::Base.wrap_parameters <%= key_value :format, "[:json]" %> # Disable root element in JSON by default. if defined?(ActiveRecord) diff --git a/railties/lib/rails/generators/rails/app/templates/db/seeds.rb.tt b/railties/lib/rails/generators/rails/app/templates/db/seeds.rb.tt index 9a2efa68a7..f75c5dd941 100644 --- a/railties/lib/rails/generators/rails/app/templates/db/seeds.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/db/seeds.rb.tt @@ -4,4 +4,4 @@ # Examples: # # cities = City.create([{ <%= key_value :name, "'Chicago'" %> }, { <%= key_value :name, "'Copenhagen'" %> }]) -# Mayor.create(<%= key_value :name, "'Daley'" %>, <%= key_value :city, "cities.first" %>) +# Mayor.create(<%= key_value :name, "'Emanuel'" %>, <%= key_value :city, "cities.first" %>) diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index f0fa30c536..923b697662 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -2,3 +2,4 @@ db/*.sqlite3 log/*.log tmp/ +.sass-cache/ diff --git a/railties/lib/rails/generators/rails/assets/USAGE b/railties/lib/rails/generators/rails/assets/USAGE index adebfd7e6f..c5375cdc06 100644 --- a/railties/lib/rails/generators/rails/assets/USAGE +++ b/railties/lib/rails/generators/rails/assets/USAGE @@ -1,8 +1,8 @@ Description: - Stubs out a new asset placeholders. Pass the asset name, either CamelCased + Stubs out new asset placeholders. Pass the asset name, either CamelCased or under_scored. - To create assets within a folder, specify the assets name as a + To create an asset within a folder, specify the asset's name as a path like 'parent/name'. This generates a JavaScript stub in app/assets/javascripts and a stylesheet @@ -15,6 +15,6 @@ Example: `rails generate assets posts` Posts assets. - Javascript: app/assets/javascripts/posts.js + JavaScript: app/assets/javascripts/posts.js Stylesheet: app/assets/stylesheets/posts.css diff --git a/railties/lib/rails/generators/rails/assets/assets_generator.rb b/railties/lib/rails/generators/rails/assets/assets_generator.rb index 80beb7abfe..2d52da77eb 100644 --- a/railties/lib/rails/generators/rails/assets/assets_generator.rb +++ b/railties/lib/rails/generators/rails/assets/assets_generator.rb @@ -1,11 +1,11 @@ module Rails module Generators class AssetsGenerator < NamedBase - class_option :javascripts, :type => :boolean, :desc => "Generate javascripts" - class_option :stylesheets, :type => :boolean, :desc => "Generate stylesheets" + class_option :javascripts, :type => :boolean, :desc => "Generate JavaScripts" + class_option :stylesheets, :type => :boolean, :desc => "Generate Stylesheets" - class_option :javascript_engine, :desc => "Engine for javascripts" - class_option :stylesheet_engine, :desc => "Engine for stylesheets" + class_option :javascript_engine, :desc => "Engine for JavaScripts" + class_option :stylesheet_engine, :desc => "Engine for Stylesheets" def create_javascript_files return unless options.javascripts? 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 6201595308..939c0cd727 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 @@ -209,7 +209,7 @@ task :default => :test build(:leftovers) end - public_task :apply_rails_template, :bundle_if_dev_or_edge + public_task :apply_rails_template, :run_bundle protected diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index 6eef0dbe5b..aa9b45c5a5 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -6,8 +6,8 @@ module Rails remove_hook_for :resource_controller remove_class_option :actions - class_option :stylesheets, :type => :boolean, :desc => "Generate stylesheets" - class_option :stylesheet_engine, :desc => "Engine for stylesheets" + class_option :stylesheets, :type => :boolean, :desc => "Generate Stylesheets" + class_option :stylesheet_engine, :desc => "Engine for Stylesheets" hook_for :scaffold_controller, :required => true diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 5222b7bf50..77a5c4dc6c 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -1,6 +1,6 @@ namespace :rails do - desc "Update both configs and public/javascripts from Rails (or use just update:javascripts or update:configs)" - task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ] + desc "Update configs and some other initially generated files (or use just update:configs, update:scripts, or update:application_controller)" + task :update => [ "update:configs", "update:scripts", "update:application_controller" ] desc "Applies the template supplied by LOCATION=/path/to/template" task :template do @@ -58,11 +58,6 @@ namespace :rails do invoke_from_app_generator :create_config_files end - # desc "Update Prototype javascripts from your current rails install" - task :javascripts do - invoke_from_app_generator :create_javascript_files - end - # desc "Adds new scripts to the application script/ directory" task :scripts do invoke_from_app_generator :create_script_files diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb new file mode 100644 index 0000000000..624dd2a23f --- /dev/null +++ b/railties/test/application/assets_test.rb @@ -0,0 +1,58 @@ +require 'isolation/abstract_unit' +require 'rack/test' + +module ApplicationTests + class RoutingTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + include Rack::Test::Methods + + def setup + build_app + boot_rails + end + + def app + @app ||= Rails.application + end + + test "assets routes have higher priority" do + app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + match '*path', :to => lambda { |env| [200, { "Content-Type" => "text/html" }, "Not an asset"] } + end + RUBY + + get "/assets/demo.js" + assert_match "alert()", last_response.body + end + + test "does not stream session cookies back" do + puts "PENDING SPROCKETS AND RACK RELEASE" + # app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" + # + # app_file "config/routes.rb", <<-RUBY + # AppTemplate::Application.routes.draw do + # match '/omg', :to => "omg#index" + # end + # RUBY + # + # require "#{app_path}/config/environment" + # + # class ::OmgController < ActionController::Base + # def index + # flash[:cool_story] = true + # render :text => "ok" + # end + # end + # + # get "/omg" + # assert_equal 'ok', last_response.body + # + # get "/assets/demo.js" + # assert_match "alert()", last_response.body + # assert_equal nil, last_response.headers["Set-Cookie"] + end + end +end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 6193e72625..0e27c9606d 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -225,8 +225,6 @@ module ApplicationTests make_basic_app class ::OmgController < ActionController::Base - protect_from_forgery - def index render :inline => "<%= csrf_meta_tags %>" end @@ -236,6 +234,21 @@ module ApplicationTests assert last_response.body =~ /csrf\-param/ end + test "request forgery token param can be changed" do + make_basic_app do + app.config.action_controller.request_forgery_protection_token = '_xsrf_token_here' + end + + class ::OmgController < ActionController::Base + def index + render :inline => "<%= csrf_meta_tags %>" + end + end + + get "/" + assert last_response.body =~ /_xsrf_token_here/ + end + test "config.action_controller.perform_caching = true" do make_basic_app do |app| app.config.action_controller.perform_caching = true @@ -439,7 +452,7 @@ module ApplicationTests app_file 'app/models/post.rb', <<-RUBY class Post - def self.column_names + def self.attribute_names %w(title) end end diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 19311a7fa0..196d121c14 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -166,7 +166,7 @@ module ApplicationTests require "#{app_path}/config/environment" - expects = [ActiveRecord::IdentityMap::Middleware, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] + expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] middleware = Rails.application.config.middleware.map { |m| m.klass } assert_equal expects, middleware & expects end diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 01e6c49d9c..8bfde00af5 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -23,20 +23,19 @@ module ApplicationTests "Rack::Lock", "ActiveSupport::Cache::Strategy::LocalCache", "Rack::Runtime", - "Rails::Rack::Logger", + "Rack::MethodOverride", + "Rails::Rack::Logger", # must come after Rack::MethodOverride to properly log overridden methods "ActionDispatch::ShowExceptions", "ActionDispatch::RemoteIp", "Rack::Sendfile", "ActionDispatch::Reloader", "ActionDispatch::Callbacks", - "ActiveRecord::IdentityMap::Middleware", "ActiveRecord::ConnectionAdapters::ConnectionManagement", "ActiveRecord::QueryCache", "ActionDispatch::Cookies", "ActionDispatch::Session::CookieStore", "ActionDispatch::Flash", "ActionDispatch::ParamsParser", - "Rack::MethodOverride", "ActionDispatch::Head", "Rack::ConditionalGet", "Rack::ETag", @@ -121,6 +120,7 @@ module ApplicationTests end test "identity map is inserted" do + add_to_config "config.active_record.identity_map = true" boot! assert middleware.include?("ActiveRecord::IdentityMap::Middleware") end diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb new file mode 100644 index 0000000000..a29244357c --- /dev/null +++ b/railties/test/application/rack/logger_test.rb @@ -0,0 +1,40 @@ +require "isolation/abstract_unit" +require "active_support/log_subscriber/test_helper" +require "rack/test" + +module ApplicationTests + module RackTests + class LoggerTest < Test::Unit::TestCase + include ActiveSupport::LogSubscriber::TestHelper + include Rack::Test::Methods + + def setup + build_app + require "#{app_path}/config/environment" + super + end + + def logs + @logs ||= @logger.logged(:info) + end + + test "logger logs proper HTTP verb and path" do + get "/blah" + wait + assert_match /^Started GET "\/blah"/, logs[0] + end + + test "logger logs HTTP verb override" do + post "/", {:_method => 'put'} + wait + assert_match /^Started PUT "\/"/, logs[0] + end + + test "logger logs HEAD requests" do + post "/", {:_method => 'head'} + wait + assert_match /^Started HEAD "\/"/, logs[0] + end + end + end +end diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 62589c998d..e3a7f8a63c 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -1,14 +1,14 @@ require 'isolation/abstract_unit' +require 'rack/test' module ApplicationTests class RoutingTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation + include Rack::Test::Methods def setup build_app boot_rails - require 'rack/test' - extend Rack::Test::Methods end test "rails/info/properties in development" do diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index cc0bd53639..9e1d47cd2f 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -66,8 +66,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_application_new_exits_with_non_zero_code_on_invalid_application_name - # TODO: Suppress the output of this (it's because of a Thor::Error) - `rails new test` + quietly { system 'rails new test' } assert_equal false, $?.success? end @@ -97,7 +96,7 @@ class AppGeneratorTest < Rails::Generators::TestCase generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, :destination_root => app_moved_root, :shell => @shell generator.send(:app_const) - silence(:stdout){ generator.send(:create_config_files) } + quietly { generator.send(:create_config_files) } assert_file "myapp_moved/config/environment.rb", /Myapp::Application\.initialize!/ assert_file "myapp_moved/config/initializers/session_store.rb", /_myapp_session/ end @@ -112,7 +111,7 @@ class AppGeneratorTest < Rails::Generators::TestCase generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true }, :destination_root => app_root, :shell => @shell generator.send(:app_const) - silence(:stdout){ generator.send(:create_config_files) } + quietly { generator.send(:create_config_files) } assert_file "myapp/config/initializers/session_store.rb", /_myapp_session/ end @@ -259,7 +258,7 @@ class AppGeneratorTest < Rails::Generators::TestCase protected def action(*args, &block) - silence(:stdout){ generator.send(*args, &block) } + silence(:stdout) { generator.send(*args, &block) } end end @@ -285,6 +284,6 @@ protected end def action(*args, &block) - silence(:stdout){ generator.send(*args, &block) } + silence(:stdout) { generator.send(*args, &block) } end end diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index 064546a3f3..0d2e624f44 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -4,8 +4,12 @@ require 'rails/generators/generated_attribute' class GeneratedAttributeTest < Rails::Generators::TestCase include GeneratorsTestHelper + def test_field_type_returns_number_field + assert_field_type :integer, :number_field + end + def test_field_type_returns_text_field - %w(integer float decimal string).each do |attribute_type| + %w(float decimal string).each do |attribute_type| assert_field_type attribute_type, :text_field end end diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index f4fdc46328..bf1cfe5305 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -10,7 +10,11 @@ class MailerGeneratorTest < Rails::Generators::TestCase run_generator assert_file "app/mailers/notifier.rb" do |mailer| assert_match /class Notifier < ActionMailer::Base/, mailer - assert_match /default :from => "from@example.com"/, mailer + if RUBY_VERSION < "1.9" + assert_match /default :from => "from@example.com"/, mailer + else + assert_match /default from: "from@example.com"/, mailer + end end end @@ -73,15 +77,33 @@ class MailerGeneratorTest < Rails::Generators::TestCase assert_file "app/mailers/notifier.rb" do |mailer| assert_instance_method :foo, mailer do |foo| - assert_match /mail :to => "to@example.org"/, foo + if RUBY_VERSION < "1.9" + assert_match /mail :to => "to@example.org"/, foo + else + assert_match /mail to: "to@example.org"/, foo + end assert_match /@greeting = "Hi"/, foo end assert_instance_method :bar, mailer do |bar| - assert_match /mail :to => "to@example.org"/, bar + if RUBY_VERSION < "1.9" + assert_match /mail :to => "to@example.org"/, bar + else + assert_match /mail to: "to@example.org"/, bar + end assert_match /@greeting = "Hi"/, bar end end + end + def test_force_old_style_hash + run_generator ["notifier", "foo", "--old-style-hash"] + assert_file "app/mailers/notifier.rb" do |mailer| + assert_match /default :from => "from@example.com"/, mailer + + assert_instance_method :foo, mailer do |foo| + assert_match /mail :to => "to@example.org"/, foo + end + end end end diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb index eb56e8d1a4..38f024f061 100644 --- a/railties/test/generators/namespaced_generators_test.rb +++ b/railties/test/generators/namespaced_generators_test.rb @@ -163,7 +163,11 @@ class NamespacedMailerGeneratorTest < NamespacedGeneratorTestCase assert_file "app/mailers/test_app/notifier.rb" do |mailer| assert_match /module TestApp/, mailer assert_match /class Notifier < ActionMailer::Base/, mailer - assert_match /default :from => "from@example.com"/, mailer + if RUBY_VERSION < "1.9" + assert_match /default :from => "from@example.com"/, mailer + else + assert_match /default from: "from@example.com"/, mailer + end end end diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index f637a6a17e..2af728e766 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -119,17 +119,17 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])) end - def test_ensure_that_tests_works + def test_ensure_that_tests_work run_generator FileUtils.cd destination_root - `bundle install` + quietly { system 'bundle install' } assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`) end def test_ensure_that_tests_works_in_full_mode run_generator [destination_root, "--full", "--skip_active_record"] FileUtils.cd destination_root - `bundle install` + quietly { system 'bundle install' } assert_match(/1 tests, 1 assertions, 0 failures, 0 errors/, `bundle exec rake test`) end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 03fd64ca38..be9aef8a41 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -6,7 +6,6 @@ module SharedGeneratorTests Rails.application = TestApp::Application super Rails::Generators::AppGenerator.instance_variable_set('@desc', nil) - @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') Kernel::silence_warnings do Thor::Base.shell.send(:attr_accessor, :always_force) @@ -24,7 +23,12 @@ module SharedGeneratorTests def test_skeleton_is_created run_generator - default_files.each{ |path| assert_file path } + default_files.each { |path| assert_file path } + end + + def test_generation_runs_bundle_install + generator([destination_root]).expects(:bundle_command).with('install').once + quietly { generator.invoke_all } end def test_plugin_new_generate_pretend @@ -84,20 +88,7 @@ module SharedGeneratorTests template.instance_eval "def read; self; end" # Make the string respond to read generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) - assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) - end - - def test_dev_option - generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install") - silence(:stdout){ generator.invoke_all } - rails_path = File.expand_path('../../..', Rails.root) - assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/ - end - - def test_edge_option - generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install") - silence(:stdout){ generator.invoke_all } - assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$} + assert_match(/It works!/, capture(:stdout) { generator.invoke_all }) end def test_template_raises_an_error_with_invalid_path @@ -112,7 +103,7 @@ module SharedGeneratorTests template.instance_eval "def read; self; end" # Make the string respond to read generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) - assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) + assert_match(/It works!/, capture(:stdout) { generator.invoke_all }) end def test_template_is_executed_when_supplied_an_https_path @@ -121,21 +112,36 @@ module SharedGeneratorTests template.instance_eval "def read; self; end" # Make the string respond to read generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) - assert_match(/It works!/, silence(:stdout){ generator.invoke_all }) + assert_match(/It works!/, capture(:stdout) { generator.invoke_all }) end def test_dev_option - generator([destination_root], :dev => true).expects(:run).with("#{@bundle_command} install") - silence(:stdout){ generator.invoke_all } + generator([destination_root], :dev => true).expects(:bundle_command).with('install').once + quietly { generator.invoke_all } rails_path = File.expand_path('../../..', Rails.root) assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:path\s+=>\s+["']#{Regexp.escape(rails_path)}["']$/ end def test_edge_option - generator([destination_root], :edge => true).expects(:run).with("#{@bundle_command} install") - silence(:stdout){ generator.invoke_all } + generator([destination_root], :edge => true).expects(:bundle_command).with('install').once + quietly { generator.invoke_all } assert_file 'Gemfile', %r{^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$} end + + def test_skip_gemfile + generator([destination_root], :skip_gemfile => true).expects(:bundle_command).never + quietly { generator.invoke_all } + assert_no_file 'Gemfile' + end + + def test_skip_bundle + generator([destination_root], :skip_bundle => true).expects(:bundle_command).never + quietly { generator.invoke_all } + + # skip_bundle is only about running bundle install, ensure the Gemfile is still + # generated. + assert_file 'Gemfile' + end end module SharedCustomGeneratorTests @@ -143,7 +149,6 @@ module SharedCustomGeneratorTests Rails.application = TestApp::Application super Rails::Generators::AppGenerator.instance_variable_set('@desc', nil) - @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') end def teardown @@ -191,7 +196,7 @@ module SharedCustomGeneratorTests template.instance_eval "def read; self; end" # Make the string respond to read generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) - capture(:stdout) { generator.invoke_all } + quietly { generator.invoke_all } default_files.each{ |path| assert_no_file(path) } end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 0c588ba773..b5b21f9ebe 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -93,6 +93,34 @@ module RailtiesTest assert_equal "HELLO WORLD", last_response.body end + test "pass the value of the segment" do + controller "foo", <<-RUBY + class FooController < ActionController::Base + def index + render :text => params[:username] + end + end + RUBY + + @plugin.write "config/routes.rb", <<-RUBY + Bukkits::Engine.routes.draw do + root :to => "foo#index" + end + RUBY + + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + mount(Bukkits::Engine => "/:username") + end + RUBY + + boot_rails + + get("/arunagw") + assert_equal "arunagw", last_response.body + + end + test "it provides routes as default endpoint" do @plugin.write "lib/bukkits.rb", <<-RUBY class Bukkits diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index e975950b85..e5debf29ae 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -15,11 +15,10 @@ module RailtiesTest boot_rails require 'rack/test' - require 'coffee_script' extend Rack::Test::Methods get "/assets/engine.js" - assert_match "alert();", last_response.body + assert_match "alert()", last_response.body end def test_copying_migrations |