From 1ebf84ac2ead038b99e1c982c24f73ffedf07c87 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 1 Sep 2011 11:49:49 -0700 Subject: [PATCH 01/67] Edited activesupport/lib/active_support/core_ext/time/calculations.rb via GitHub --- activesupport/lib/active_support/core_ext/time/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index a15a06d0e4cae..372dd69212666 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -9,7 +9,7 @@ class Time class << self # Overriding case equality method so that it returns true for ActiveSupport::TimeWithZone instances def ===(other) - other.is_a?(::Time) + super || (self == Time && other.is_a?(ActiveSupport::TimeWithZone)) end # Return the number of days in the given month. From da8f00a55c55bd4af152150b71823627a55bba5b Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 7 Sep 2011 10:09:04 -0700 Subject: [PATCH 02/67] Add tests for fixes to Time.=== --- activesupport/test/core_ext/time_ext_test.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index c4c4381957b7d..ab9be4b18b01e 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -764,7 +764,10 @@ def test_time_created_with_local_constructor_cannot_represent_times_during_hour_ def test_case_equality assert Time === Time.utc(2000) assert Time === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) + assert Time === Class.new(Time).utc(2000) assert_equal false, Time === DateTime.civil(2000) + assert_equal false, Class.new(Time) === Time.utc(2000) + assert_equal false, Class.new(Time) === ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) end def test_all_day From 1bd88fdafd9cd0c1c83e8bf41020d0c251cb3108 Mon Sep 17 00:00:00 2001 From: Alexey Vakhov Date: Tue, 27 Sep 2011 23:39:52 +0400 Subject: [PATCH 03/67] add missing require to html sanitizer --- .../lib/action_controller/vendor/html-scanner/html/sanitizer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb index eaefdc0f15c4e..af06bffa1632b 100644 --- a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +++ b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb @@ -1,4 +1,5 @@ require 'set' +require 'cgi' require 'active_support/core_ext/class/attribute' module HTML From c612183ad19f2c11eb58e4393a759a1016ce4c05 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 27 Sep 2011 13:50:49 -0700 Subject: [PATCH 04/67] partial pass over the asset pipeline --- railties/guides/source/asset_pipeline.textile | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index b343e8d01d6ed..c5bbe3226aa64 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -152,15 +152,15 @@ Images can also be organized into subdirectories if required, and they can be ac h5. CSS and ERB -If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then helpers like +image_path+ are available in your CSS rules: +If you add an +erb+ extension to a CSS asset, making it something such as +application.css.erb+, then helpers like +asset_path+ are available in your CSS rules: -.class { background-image: url(<%= image_path 'image.png' %>) } +.class { background-image: url(<%= asset_path 'image.png' %>) } This writes the path to the particular asset being referenced. In this example, it would make sense to have an image in one of the asset load paths, such as +app/assets/images/image.png+, which would be referenced here. If this image is already available in +public/assets+ as a fingerprinted file, then that path is referenced. -If you want to use a "css data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper. +If you want to use a "data URI":http://en.wikipedia.org/wiki/Data_URI_scheme -- a method of embedding the image data directly into the CSS file -- you can use the +asset_data_uri+ helper. #logo { background: url(<%= asset_data_uri 'logo.png' %>) } @@ -186,27 +186,28 @@ h5. JavaScript/CoffeeScript and ERB If you add an +erb+ extension to a JavaScript asset, making it something such as +application.js.erb+, then you can use the +asset_path+ helper in your JavaScript code: - + $('#logo').attr({ src: "<%= asset_path('logo.png') %>" }); - + This writes the path to the particular asset being referenced. -Similarly, you can use the +asset_path+ helper in CoffeeScript files with +erb+ extension (eg. application.js.coffee.erb): +Similarly, you can use the +asset_path+ helper in CoffeeScript files with +erb+ extension (eg. +application.js.coffee.erb+): -$('#logo').attr src: "<% asset_path('logo.png') %>" +$('#logo').attr src: "<%= asset_path('logo.png') %>" h4. Manifest Files and Directives -Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make. +Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is true). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make. For example, in the default Rails application there's a +app/assets/javascripts/application.js+ file which contains the following lines: +// ... //= require jquery //= require jquery_ujs //= require_tree . @@ -214,9 +215,11 @@ For example, in the default Rails application there's a +app/assets/javascripts/ In JavaScript files, the directives begin with +//=+. In this case, the file is using the +require+ and the +require_tree+ directives. The +require+ directive is used to tell Sprockets the files that you wish to require. Here, you are requiring the files +jquery.js+ and +jquery_ujs.js+ that are available somewhere in the search path for Sprockets. You need not supply the extensions explicitly. Sprockets assumes you are requiring a +.js+ file when done from within a +.js+ file. -NOTE. In Rails 3.1, the +jquery.js+ and +jquery_ujs.js+ files are located inside the +vendor/assets/javascripts+ directory contained within the +jquery-rails+ gem. +NOTE. In Rails 3.1 the +jquery-rails+ gem provides the +jquery.js+ and +jquery_ujs.js+ files via the asset pipeline. You won't see them in the application tree. + +The +require_tree+ directive tells Sprockets to recursively include _all_ JavaScript files in this directory into the output. Only a path relative to the manifest file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting). -The +require_tree .+ directive tells Sprockets to include _all_ JavaScript files in this directory into the output. Only a path relative to the file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting). +Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unespecified. You should not rely on any particular among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output. There's also a default +app/assets/stylesheets/application.css+ file which contains these lines: @@ -233,7 +236,7 @@ In this example +require_self+ is used. This puts the CSS contained within the f You can have as many manifest files as you need. For example the +admin.css+ and +admin.js+ manifest could contain the JS and CSS files that are used for the admin section of an application. -For some assets (like CSS) the compiled order is important. You can specify individual files and they are compiled in the order specified: +The same remarks about ordering made above apply. In particular, you can specify individual files and they are compiled in the order specified: /* ... @@ -246,13 +249,13 @@ For some assets (like CSS) the compiled order is important. You can specify indi h4. Preprocessing -The file extensions used on an asset determine what preprocessing is applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file are generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and a +app/assets/stylesheets/projects.css.scss+ file. +The file extensions used on an asset determine what preprocessing is applied. When a controller or a scaffold is generated with the default Rails gemset, a CoffeeScript file and a SCSS file are generated in place of a regular JavaScript and CSS file. The example used before was a controller called "projects", which generated an +app/assets/javascripts/projects.js.coffee+ and an +app/assets/stylesheets/projects.css.scss+ file. When these files are requested, they are processed by the processors provided by the +coffee-script+ and +sass-rails+ gems and then sent back to the browser as JavaScript and CSS respectively. -Additional layers of pre-processing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ is first processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file -- +app/assets/javascripts/projects.js.coffee.erb+ is processed as ERB, CoffeeScript and served as JavaScript. +Additional layers of preprocessing can be requested by adding other extensions, where each extension is processed in a right-to-left manner. These should be used in the order the processing should be applied. For example, a stylesheet called +app/assets/stylesheets/projects.css.scss.erb+ is first processed as ERB, then SCSS and finally served as CSS. The same applies to a JavaScript file -- +app/assets/javascripts/projects.js.coffee.erb+ is processed as ERB, CoffeeScript, and served as JavaScript. -Keep in mind that the order of these pre-processors is important. For example, if you called your JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it is processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore you would run into problems. +Keep in mind that the order of these preprocessors is important. For example, if you called your JavaScript file +app/assets/javascripts/projects.js.erb.coffee+ then it would be processed with the CoffeeScript interpreter first, which wouldn't understand ERB and therefore you would run into problems. h3. In Development From 41c8277a9b04dda40972bbafa2dbfc00c5c238fb Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 27 Sep 2011 13:55:41 -0700 Subject: [PATCH 05/67] the infamous detail only spotted in GitHub diffs no matter how careful you were before pushing --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index c5bbe3226aa64..8a15618eb2ad4 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -219,7 +219,7 @@ NOTE. In Rails 3.1 the +jquery-rails+ gem provides the +jquery.js+ and +jquery_u The +require_tree+ directive tells Sprockets to recursively include _all_ JavaScript files in this directory into the output. Only a path relative to the manifest file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting). -Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unespecified. You should not rely on any particular among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output. +Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unespecified. You should not rely on any particular order among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output. There's also a default +app/assets/stylesheets/application.css+ file which contains these lines: From aefc40324df3c98a278f05eee4980845fbeedbef Mon Sep 17 00:00:00 2001 From: Rocky Jaiswal Date: Wed, 28 Sep 2011 11:57:34 +0530 Subject: [PATCH 06/67] Fixed failed test under 1.8.7 as map.keys order in indeterminable --- .../associations/has_and_belongs_to_many_associations_test.rb | 2 +- .../test/cases/associations/has_many_associations_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index d1d02c25d5713..34d90cc395b46 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -651,7 +651,7 @@ def test_habtm_respects_select end def test_habtm_selects_all_columns_by_default - assert_equal Project.column_names, developers(:david).projects.first.attributes.keys + assert_equal Project.column_names.sort, developers(:david).projects.first.attributes.keys.sort end def test_habtm_respects_select_query_method diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index fdfbcbefacb6e..cddd2a6f8cc8a 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -486,7 +486,7 @@ def test_find_scoped_grouped_having end def test_default_select - assert_equal Comment.column_names, posts(:welcome).comments.first.attributes.keys + assert_equal Comment.column_names.sort, posts(:welcome).comments.first.attributes.keys.sort end def test_select_query_method From f3b8cd9d364934795ee4ec63a2d8852b3dde1aa8 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 28 Sep 2011 13:35:46 +0530 Subject: [PATCH 07/67] fixing typo in assets guide --- railties/guides/source/asset_pipeline.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 8a15618eb2ad4..152f42f4eb987 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -219,7 +219,7 @@ NOTE. In Rails 3.1 the +jquery-rails+ gem provides the +jquery.js+ and +jquery_u The +require_tree+ directive tells Sprockets to recursively include _all_ JavaScript files in this directory into the output. Only a path relative to the manifest file can be specified. There is also a +require_directory+ directive which includes all JavaScript files only in the directory specified (no nesting). -Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unespecified. You should not rely on any particular order among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output. +Directives are processed top to bottom, but the order in which files are included by +require_tree+ is unspecified. You should not rely on any particular order among those. If you need to ensure some particular JavaScript ends up above some other, require it before in the manifest. Note that the family of +require+ directives prevents files from being included twice in the output. There's also a default +app/assets/stylesheets/application.css+ file which contains these lines: From 3058d13a06d5472d25d89b55960565d6ba57f1ec Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Thu, 29 Sep 2011 01:40:15 +0800 Subject: [PATCH 08/67] Make button_to helper support "form" option which is the form attributes. --- .../lib/action_view/helpers/url_helper.rb | 20 ++++++++++++++----- actionpack/test/template/url_helper_test.rb | 4 ++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index acd5e46e3355d..0c2e1aa3a9962 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -279,6 +279,7 @@ def link_to(*args, &block) # processed normally, otherwise no action is taken. # * :remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the # submit behavior. By default this behavior is an ajax submit. + # * :form - This hash will be form attributes # * :form_class - This controls the class of the form within which the submit button will # be placed # @@ -295,6 +296,12 @@ def link_to(*args, &block) # # " # # + # <%= button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } %> + # # => "
+ # #
+ # #
" + # + # # <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, # :confirm => "Are you sure?", :method => :delete %> # # => "
@@ -324,10 +331,11 @@ def button_to(name, options = {}, html_options = {}) end form_method = method.to_s == 'get' ? 'get' : 'post' - form_class = html_options.delete('form_class') || 'button_to' - + form_options = html_options.delete('form') || {} + form_options[:class] ||= html_options.delete('form_class') || 'button_to' + remote = html_options.delete('remote') - + request_token_tag = '' if form_method == 'post' && protect_against_forgery? request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) @@ -340,8 +348,10 @@ def button_to(name, options = {}, html_options = {}) html_options.merge!("type" => "submit", "value" => name) - ("
" + - method_tag + tag("input", html_options) + request_token_tag + "
").html_safe + form_options.merge!(:method => form_method, :action => url) + form_options.merge!("data-remote" => "true") if remote + + "#{tag(:form, form_options, true)}
#{method_tag}#{tag("input", html_options)}#{request_token_tag}
".html_safe end diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index dbac2e1fc0d67..bc45fabf34885 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -88,6 +88,10 @@ def test_button_to_with_javascript_disable_with ) end + def test_button_to_with_remote_and_form_options + assert_dom_equal "
", button_to("Hello", "http://www.example.com", :remote => true, :form => { :class => "custom-class", "data-type" => "json" } ) + end + def test_button_to_with_remote_and_javascript_confirm assert_dom_equal( "
", From cba3c00831a7c5bb25bc785e856984705ca2077c Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 28 Sep 2011 13:48:23 -0700 Subject: [PATCH 09/67] partial pass over the assets guide --- railties/guides/source/asset_pipeline.textile | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile index 152f42f4eb987..a0af018d30d84 100644 --- a/railties/guides/source/asset_pipeline.textile +++ b/railties/guides/source/asset_pipeline.textile @@ -261,7 +261,7 @@ h3. In Development In development mode assets are served as separate files in the order they are specified in the manifest file. -This manifest +application.js+: +This manifest +app/assets/javascripts/application.js+: //= require core @@ -272,45 +272,42 @@ This manifest +application.js+: would generate this HTML: - - - + + + The +body+ param is required by Sprockets. h4. Turning Debugging off -You can turn off debug mode by updating +development.rb+ to include: +You can turn off debug mode by updating +config/environments/development.rb+ to include: - + config.assets.debug = false - + -When debug mode is off Sprockets will concatenate and run the necessary preprocessors on all files, generating the following HTML: +When debug mode is off Sprockets concatenates and runs the necessary preprocessors on all files. With debug mode turned off the manifest above would generate instead: - + -Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-revalidate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (not-modified) response. +Assets are compiled and cached on the first request after the server is started. Sprockets sets a +must-revalidate+ Cache-Control HTTP header to reduce request overhead on subsequent requests -- on these the browser gets a 304 (Not Modified) response. If any of the files in the manifest have changed between requests, the server responds with a new compiled file. -You can put +?debug_assets=true+ or +?debug_assets=1+ at the end of a URL to enable debug mode on-demand, and this will render individual tags for each file. This is useful for tracking down exact line numbers when debugging. - -Debug can also be set in the Rails helper methods: +Debug mode can also be enabled in the Rails helper methods: <%= stylesheet_link_tag "application", :debug => true %> <%= javascript_include_tag "application", :debug => true %> -The +:debug+ option is ignored if the debug mode is off. +The +:debug+ option is redundant if debug mode is on. You could potentially also enable compression in development mode as a sanity check, and disable it on-demand as required for debugging. - h3. In Production In the production environment Rails uses the fingerprinting scheme outlined above. By default it is assumed that assets have been precompiled and will be served as static assets by your web server. From 41365a8275dcb6d2e2fbe21ae2b2dfc52db19c1f Mon Sep 17 00:00:00 2001 From: Colin Shield & Ian Lesperance Date: Wed, 28 Sep 2011 15:23:47 -0700 Subject: [PATCH 10/67] Fixed digest authentication for requests with a query string [#3158] --- activeresource/lib/active_resource/connection.rb | 5 ++++- activeresource/test/cases/authorization_test.rb | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index d923204ddefdc..592fca96a4725 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -238,8 +238,11 @@ def authorization_header(http_method, uri) def digest_auth_header(http_method, uri) params = extract_params_from_response + request_uri = uri.path + request_uri << "?#{uri.query}" if uri.query + ha1 = Digest::MD5.hexdigest("#{@user}:#{params['realm']}:#{@password}") - ha2 = Digest::MD5.hexdigest("#{http_method.to_s.upcase}:#{uri.path}") + ha2 = Digest::MD5.hexdigest("#{http_method.to_s.upcase}:#{request_uri}") params.merge!('cnonce' => client_nonce) request_digest = Digest::MD5.hexdigest([ha1, params['nonce'], "0", params['cnonce'], params['qop'], ha2].join(":")) diff --git a/activeresource/test/cases/authorization_test.rb b/activeresource/test/cases/authorization_test.rb index 69ef9a2821104..17cd9b30fc91a 100644 --- a/activeresource/test/cases/authorization_test.rb +++ b/activeresource/test/cases/authorization_test.rb @@ -131,6 +131,12 @@ def test_authorization_header_if_credentials_supplied_and_auth_type_is_digest assert_equal blank_digest_auth_header("/people/2.json", "fad396f6a34aeba28e28b9b96ddbb671"), authorization_header['Authorization'] end + def test_authorization_header_with_query_string_if_auth_type_is_digest + @authenticated_conn.auth_type = :digest + authorization_header = @authenticated_conn.__send__(:authorization_header, :get, URI.parse('/people/2.json?only=name')) + assert_equal blank_digest_auth_header("/people/2.json?only=name", "f8457b0b5d21b6b80737a386217afb24"), authorization_header['Authorization'] + end + def test_get david = decode(@authenticated_conn.get("/people/2.json")) assert_equal "David", david["name"] From 64b0c8888b908ede5372e0a70cb4cb8731d372ba Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 28 Sep 2011 20:13:24 -0300 Subject: [PATCH 11/67] javascript_path and stylesheet_path should honor the asset pipelining --- .../lib/sprockets/helpers/rails_helper.rb | 10 ++++++++++ .../test/template/sprockets_helper_test.rb | 20 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index c8c6c3ddd9eef..e1d8fccf0439c 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -65,6 +65,16 @@ def image_path(source) end alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route + def javascript_path(source) + asset_path(source) + end + alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with an javascript_path named route + + def stylesheet_path(source) + asset_path(source) + end + alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with an stylesheet_path named route + private def debug_assets? compile_assets? && (Rails.application.config.assets.debug || params[:debug_assets]) diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index b1e6db7b34a63..fd3e01ec03254 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -134,6 +134,22 @@ def url_for(*args) path_to_image("logo.png") end + test "javascript_path" do + assert_match %r{/assets/application-[0-9a-f]+.js}, + javascript_path("application.js") + + assert_match %r{/assets/application-[0-9a-f]+.js}, + path_to_javascript("application.js") + end + + test "stylesheet_path" do + assert_match %r{/assets/application-[0-9a-f]+.css}, + stylesheet_path("application.css") + + assert_match %r{/assets/application-[0-9a-f]+.css}, + path_to_stylesheet("application.css") + end + test "stylesheets served without a controller in do not use asset hosts when the default protocol is :request" do @controller = nil @config.action_controller.asset_host = "assets-%d.example.com" @@ -157,7 +173,7 @@ def url_for(*args) asset_path("/images/logo.gif") end - test "javascript path" do + test "javascript path through asset_path" do assert_match %r{/assets/application-[0-9a-f]+.js}, asset_path(:application, :ext => "js") @@ -202,7 +218,7 @@ def url_for(*args) javascript_include_tag(:application) end - test "stylesheet path" do + test "stylesheet path through asset_path" do assert_match %r{/assets/application-[0-9a-f]+.css}, asset_path(:application, :ext => "css") assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", :ext => "css") From 148e4a541361f140f13aa35bb43b3d57c95831d6 Mon Sep 17 00:00:00 2001 From: Dmitriy Kiriyenko Date: Thu, 29 Sep 2011 15:35:25 +0300 Subject: [PATCH 12/67] Honour RAILS_ENV environment variable when running rake. --- railties/lib/rails/generators/actions.rb | 2 +- railties/test/generators/actions_test.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 575f4bb106b03..5af5d3b856c59 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -252,7 +252,7 @@ def generate(what, *args) # def rake(command, options={}) log :rake, command - env = options[:env] || 'development' + env = options[:env] || ENV["RAILS_ENV"] || 'development' sudo = options[:sudo] && RbConfig::CONFIG['host_os'] !~ /mswin|mingw/ ? 'sudo ' : '' in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) } end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 94e9abb3ccca9..e621f7f6f7d36 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -189,6 +189,22 @@ def test_rake_with_env_option_should_run_rake_command_in_env action :rake, 'log:clear', :env => 'production' end + def test_rake_with_rails_env_variable_should_run_rake_command_in_env + generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false) + old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "production" + action :rake, 'log:clear' + ensure + ENV["RAILS_ENV"] = old_env + end + + def test_env_option_should_win_over_rails_env_variable_when_running_rake + generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false) + old_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "staging" + action :rake, 'log:clear', :env => 'production' + ensure + ENV["RAILS_ENV"] = old_env + end + def test_rake_with_sudo_option_should_run_rake_command_with_sudo generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', :verbose => false) action :rake, 'log:clear', :sudo => true From adb8ac153f8e9e497eaecf62165c0bd53c18149a Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 29 Sep 2011 17:59:40 +0100 Subject: [PATCH 13/67] Don't call self.class unless necessary. Closes #3171. --- activerecord/lib/active_record/reflection.rb | 4 ++-- activerecord/test/cases/reflection_test.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 1929a808ed82a..120ff0cac69f4 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -212,8 +212,8 @@ def association_foreign_key end # klass option is necessary to support loading polymorphic associations - def association_primary_key(klass = self.klass) - options[:primary_key] || klass.primary_key + def association_primary_key(klass = nil) + options[:primary_key] || (klass || self.klass).primary_key end def active_record_primary_key diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index 0a48f418b102b..ca9d88fbd58e3 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -244,6 +244,7 @@ def test_association_primary_key # Normal association assert_equal "id", Author.reflect_on_association(:posts).association_primary_key.to_s assert_equal "name", Author.reflect_on_association(:essay).association_primary_key.to_s + assert_equal "name", Essay.reflect_on_association(:writer).association_primary_key.to_s # Through association (uses the :primary_key option from the source reflection) assert_equal "nick", Author.reflect_on_association(:subscribers).association_primary_key.to_s From d2888de5985c7018a5be23d44143ec3c6cef9032 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 29 Sep 2011 16:07:59 -0300 Subject: [PATCH 14/67] Add CHANGELOG entries --- actionpack/CHANGELOG | 40 ++++++++++++++++++++++++++++++++++++++++ activerecord/CHANGELOG | 26 +++++++++++++++++++++++++- railties/CHANGELOG | 2 ++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index c3ff677529aef..e8c619723fbe0 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -56,6 +56,46 @@ *Rails 3.1.1 (unreleased)* +* javascript_path and stylesheet_path now refer to /assets if asset pipelining +is on. [Santiago Pastorino] + +* button_to support form option. Now you're able to pass for example +'data-type' => 'json'. [ihower] + +* image_path and image_tag should use /assets if asset pipelining is turned +on. Closes #3126 [Santiago Pastorino and christos] + +* Avoid use of existing precompiled assets during rake assets:precompile run. +Closes #3119 [Guillermo Iguaran] + +* Copy assets to nondigested filenames too [Santiago Pastorino] + +* Give precedence to `config.digest = false` over the existence of +manifest.yml asset digests [christos] + +* escape options for the stylesheet_link_tag method [Alexey Vakhov] + +* Re-launch assets:precompile task using (Rake.)ruby instead of Kernel.exec so +it works on Windows [cablegram] + +* env var passed to process shouldn't be modified in process method. [Santiago +Pastorino] + +* `rake assets:precompile` loads the application but does not initialize +it. + + To the app developer, this means configuration add in + config/initializers/* will not be executed. + + Plugins developers need to special case their initializers that are + meant to be run in the assets group by adding :group => :assets. [José Valim] + +* Sprockets uses config.assets.prefix for asset_path [asee] + +* FileStore key_file_path properly limit filenames to 255 characters. [phuibonhoa] + +* Fix Hash#to_query edge case with html_safe strings. [brainopia] + * Allow asset tag helper methods to accept :digest => false option in order to completely avoid the digest generation. Useful for linking assets from static html files or from emails when the user could probably look at an older html email with an older asset. [Santiago Pastorino] diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index a54526dd417ca..f974b5d237c4c 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,4 +1,28 @@ -Wed Sep 7 15:25:02 2011 Aaron Patterson +*Rails 3.1.1 (unreleased)* + +* Add deprecation for the preload_associations method. Fixes #3022. + + [Jon Leighton] + +* Don't require a DB connection when loading a model that uses set_primary_key. GH #2807. + + [Jon Leighton] + +* Fix using select() with a habtm association, e.g. Person.friends.select(:name). GH #3030 and + #2923. + + [Hendy Tanata] + +* Fix belongs_to polymorphic with custom primary key on target. GH #3104. + + [Jon Leighton] + +* CollectionProxy#replace should change the DB records rather than just mutating the array. + Fixes #3020. + + [Jon Leighton] + +* LRU cache in mysql and sqlite are now per-process caches. * lib/active_record/connection_adapters/mysql_adapter.rb: LRU cache keys are per process id. diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 54eef0473cf8f..992519ee9295b 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -13,6 +13,8 @@ *Rails 3.1.1 +* Add jquery-rails to Gemfile of plugins, test/dummy app needs it. Closes #3091. [Santiago Pastorino] + * `rake assets:precompile` loads the application but does not initialize it. To the app developer, this means configuration add in From 0baa8f8604e7766ce627120dfe572e09c247ef8c Mon Sep 17 00:00:00 2001 From: Philippe Huibonhoa Date: Thu, 29 Sep 2011 18:59:40 -0700 Subject: [PATCH 15/67] Added fix so that file store does not raise an exception when cache dir does not exist yet. This can happen if a delete_matched is called before anything is saved in the cache. --- activesupport/lib/active_support/cache/file_store.rb | 1 + activesupport/test/caching_test.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index 3f516d4808588..b431041b76a1d 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -161,6 +161,7 @@ def ensure_cache_path(path) end def search_dir(dir, &callback) + return if !File.exist?(dir) Dir.foreach(dir) do |d| next if d == "." || d == ".." name = File.join(dir, d) diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index b692a4131200e..793e62a74a598 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -566,6 +566,13 @@ def test_key_transformation_max_filename_size assert path.split('/').all? { |dir_name| dir_name.size <= ActiveSupport::Cache::FileStore::FILENAME_MAX_SIZE} assert_equal 'B', File.basename(path) end + + def test_search_dir_when_directory_does_not_exist + ActiveSupport::Cache::FileStore.new('test').send(:search_dir, 'dir_does_not_exist') do |path| + flunk "search_dir yielded but should have done nothing" + end + assert true + end end class MemoryStoreTest < ActiveSupport::TestCase From da914fa35c014b7753e609e25c6a45d3cda11274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Hock=20Isaza?= Date: Thu, 29 Sep 2011 20:07:19 -0500 Subject: [PATCH 16/67] Fixing `as_json` method for ActiveRecord models. When you've got an AR Model and you override the `as_json` method, you should be able to add default options to the renderer, like this: class User < ActiveRecord::Base def as_json(options = {}) super(options.merge(:except => [:password_digest])) end end This was not possible before this commit. See the added test case. --- .../test/cases/serializers/json_serialization_test.rb | 10 ++++++++++ .../lib/active_support/core_ext/object/to_json.rb | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb index 40fdcf20cacf2..a754d610b95ef 100644 --- a/activemodel/test/cases/serializers/json_serialization_test.rb +++ b/activemodel/test/cases/serializers/json_serialization_test.rb @@ -206,4 +206,14 @@ def @contact.as_json(options); { :name => name, :created_at => created_at }; end assert_no_match %r{"preferences":}, json end + test "custom as_json options should be extendible" do + def @contact.as_json(options = {}); super(options.merge(:only => [:name])); end + json = @contact.to_json + + assert_match %r{"name":"Konata Izumi"}, json + assert_no_match %r{"created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))}}, json + assert_no_match %r{"awesome":}, json + assert_no_match %r{"preferences":}, json + end + end diff --git a/activesupport/lib/active_support/core_ext/object/to_json.rb b/activesupport/lib/active_support/core_ext/object/to_json.rb index 14ef27340e1d2..82e232070d63e 100644 --- a/activesupport/lib/active_support/core_ext/object/to_json.rb +++ b/activesupport/lib/active_support/core_ext/object/to_json.rb @@ -12,7 +12,7 @@ [Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass| klass.class_eval <<-RUBY, __FILE__, __LINE__ # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info. - def to_json(options = nil) + def to_json(options = {}) ActiveSupport::JSON.encode(self, options) end RUBY From e81c427fe8a5bba8e5c8dd4b2a57c5e20b1c5fd0 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 30 Sep 2011 14:12:43 +0530 Subject: [PATCH 17/67] possibly useless use of :: in void context Warning removed --- railties/test/application/configuration_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 448982f9deac1..97ad47ac14060 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -306,7 +306,7 @@ def index require "#{app_path}/config/environment" require "mail" - ActionMailer::Base + _ = ActionMailer::Base assert_equal [::MyMailInterceptor], ::Mail.send(:class_variable_get, "@@delivery_interceptors") end @@ -319,7 +319,7 @@ def index require "#{app_path}/config/environment" require "mail" - ActionMailer::Base + _ = ActionMailer::Base assert_equal [::MyMailInterceptor, ::MyOtherMailInterceptor], ::Mail.send(:class_variable_get, "@@delivery_interceptors") end @@ -332,7 +332,7 @@ def index require "#{app_path}/config/environment" require "mail" - ActionMailer::Base + _ = ActionMailer::Base assert_equal [::MyMailObserver], ::Mail.send(:class_variable_get, "@@delivery_notification_observers") end @@ -345,7 +345,7 @@ def index require "#{app_path}/config/environment" require "mail" - ActionMailer::Base + _ = ActionMailer::Base assert_equal [::MyMailObserver, ::MyOtherMailObserver], ::Mail.send(:class_variable_get, "@@delivery_notification_observers") end From b0b436ebcea8206015b3f52bb5915a7bba7cc5a9 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Fri, 30 Sep 2011 15:56:38 +0530 Subject: [PATCH 18/67] warning removed : '&' interpreted as argument prefix --- railties/lib/rails/generators/actions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index 5af5d3b856c59..b26839644e263 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -90,7 +90,7 @@ def gem_group(*names, &block) append_file "Gemfile", "\ngroup #{name} do\n", :force => true @in_group = true - instance_eval &block + instance_eval(&block) @in_group = false append_file "Gemfile", "end\n", :force => true From 37b9594a8e08916e1e9ae9a6aaffc13ef516ad11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Sep 2011 12:45:36 +0200 Subject: [PATCH 19/67] Set the default options value for as_json in the encoder object. --- activesupport/lib/active_support/core_ext/object/to_json.rb | 2 +- activesupport/lib/active_support/json/encoding.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/to_json.rb b/activesupport/lib/active_support/core_ext/object/to_json.rb index 82e232070d63e..14ef27340e1d2 100644 --- a/activesupport/lib/active_support/core_ext/object/to_json.rb +++ b/activesupport/lib/active_support/core_ext/object/to_json.rb @@ -12,7 +12,7 @@ [Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].each do |klass| klass.class_eval <<-RUBY, __FILE__, __LINE__ # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info. - def to_json(options = {}) + def to_json(options = nil) ActiveSupport::JSON.encode(self, options) end RUBY diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 67698c1cff82f..469ae6925856d 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -38,7 +38,7 @@ class Encoder attr_reader :options def initialize(options = nil) - @options = options + @options = options || {} @seen = Set.new end @@ -59,7 +59,7 @@ def as_json(value) def options_for(value) if value.is_a?(Array) || value.is_a?(Hash) # hashes and arrays need to get encoder in the options, so that they can detect circular references - (options || {}).merge(:encoder => self) + options.merge(:encoder => self) else options end From d4457dc32b4d5dc9fde6c852f55a0d43ee021282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Sep 2011 14:20:41 +0200 Subject: [PATCH 20/67] Provide read_attribute_for_serialization as the API to serialize attributes. --- activemodel/lib/active_model/serialization.rb | 25 +++++++++++++++++-- activemodel/test/cases/serialization_test.rb | 6 ++--- activeresource/lib/active_resource/base.rb | 4 +++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb index a756b9f2053e8..7bc3f997b5b7c 100644 --- a/activemodel/lib/active_model/serialization.rb +++ b/activemodel/lib/active_model/serialization.rb @@ -78,7 +78,8 @@ def serializable_hash(options = nil) attribute_names -= Array.wrap(except).map(&:to_s) end - hash = attributes.slice(*attribute_names) + hash = {} + attribute_names.each { |n| hash[n] = read_attribute_for_serialization(n) } method_names = Array.wrap(options[:methods]).select { |n| respond_to?(n) } method_names.each { |n| hash[n] = send(n) } @@ -95,13 +96,33 @@ def serializable_hash(options = nil) end private + + # Hook method defining how an attribute value should be retrieved for + # serialization. By default this is assumed to be an instance named after + # the attribute. Override this method in subclasses should you need to + # retrieve the value for a given attribute differently: + # + # class MyClass + # include ActiveModel::Validations + # + # def initialize(data = {}) + # @data = data + # end + # + # def read_attribute_for_serialization(key) + # @data[key] + # end + # end + # + alias :read_attribute_for_serialization :send + # Add associations specified via the :include option. # # Expects a block that takes as arguments: # +association+ - name of the association # +records+ - the association record(s) to be serialized # +opts+ - options for the association records - def serializable_add_includes(options = {}) + def serializable_add_includes(options = {}) #:nodoc: return unless include = options[:include] unless include.is_a?(Hash) diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb index 29bcdeae6753d..1ec915d245869 100644 --- a/activemodel/test/cases/serialization_test.rb +++ b/activemodel/test/cases/serialization_test.rb @@ -77,12 +77,12 @@ def test_should_not_call_methods_that_dont_respond assert_equal expected , @user.serializable_hash(:methods => [:bar]) end - def test_should_not_call_methods_for_attributes - def @user.name + def test_should_use_read_attribute_for_serialization + def @user.read_attribute_for_serialization(n) "Jon" end - expected = { "name" => "David" } + expected = { "name" => "Jon" } assert_equal expected, @user.serializable_hash(:only => :name) end diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index 1ffd83b91d765..03c4cc5b9e0a3 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -1384,6 +1384,10 @@ def collection_path(options = nil) private + def read_attribute_for_serialization(n) + attributes[n] + end + # Determine whether the response is allowed to have a body per HTTP 1.1 spec section 4.4.1 def response_code_allows_body?(c) !((100..199).include?(c) || [204,304].include?(c)) From 44791a2bc6611b755b418f1db3ca93f9edec0908 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Fri, 30 Sep 2011 12:05:53 -0400 Subject: [PATCH 21/67] Modified how to handle if ActiveRecord is defined. --- railties/lib/rails/test_help.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb index 68f566274df7f..8d0d8cacac1d5 100644 --- a/railties/lib/rails/test_help.rb +++ b/railties/lib/rails/test_help.rb @@ -24,7 +24,7 @@ end end -if defined?(ActiveRecord) +if defined?(ActiveRecord::Base) require 'active_record/test_case' class ActiveSupport::TestCase From b30ffbbfd6da4547449c5cea81ec7627762259c6 Mon Sep 17 00:00:00 2001 From: Arun Agrawal Date: Sat, 1 Oct 2011 14:27:12 +0530 Subject: [PATCH 22/67] Use of :: in void context Warning removed --- actionpack/lib/sprockets/assets.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index e29661e4e71d1..bb5cf6740a737 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -17,7 +17,7 @@ namespace :assets do end # Ensure that action view is loaded and the appropriate sprockets hooks get executed - ActionView::Base + _ = ActionView::Base config = Rails.application.config config.assets.compile = true From 7039def6e116b12ccab8142cec7f7feabc264220 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 31 Jul 2011 16:17:37 -0500 Subject: [PATCH 23/67] Read extra args for 'rails new' from ~/.railsrc --- railties/lib/rails/commands/application.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index 1cf23a8b92116..dcd4c7a529ee0 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -9,6 +9,13 @@ ARGV[0] = "--help" else ARGV.shift + railsrc = File.join(File.expand_path("~"), ".railsrc") + if File.exist?(railsrc) + extra_args_string = File.open(railsrc).read + extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten + ARGV << extra_args + ARGV.flatten! + end end require 'rubygems' if ARGV.include?("--dev") From 101fb42106db4e7e8221a3fec252e51dd84e0bb4 Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Sun, 2 Oct 2011 01:06:39 -0500 Subject: [PATCH 24/67] Print information about .railsrc to users --- railties/lib/rails/commands/application.rb | 1 + railties/lib/rails/generators/rails/app/USAGE | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb index dcd4c7a529ee0..60d1aed73a562 100644 --- a/railties/lib/rails/commands/application.rb +++ b/railties/lib/rails/commands/application.rb @@ -13,6 +13,7 @@ if File.exist?(railsrc) extra_args_string = File.open(railsrc).read extra_args = extra_args_string.split(/\n+/).map {|l| l.split}.flatten + puts "Using #{extra_args.join(" ")} from #{railsrc}" ARGV << extra_args ARGV.flatten! end diff --git a/railties/lib/rails/generators/rails/app/USAGE b/railties/lib/rails/generators/rails/app/USAGE index 9e7a78d132c8c..691095f33fb8f 100644 --- a/railties/lib/rails/generators/rails/app/USAGE +++ b/railties/lib/rails/generators/rails/app/USAGE @@ -2,6 +2,12 @@ Description: The 'rails new' command creates a new Rails application with a default directory structure and configuration at the path you specify. + You can specify extra command-line arguments to be used every time + 'rails new' runs in the .railsrc configuration file in your home directory. + + Note that the arguments specified in the .railsrc file don't affect the + defaults values shown above in this help message. + Example: rails new ~/Code/Ruby/weblog From 119a484e808898a7ff55a27326ad49d8d493eb59 Mon Sep 17 00:00:00 2001 From: Philippe Huibonhoa Date: Sun, 2 Oct 2011 01:39:52 -0700 Subject: [PATCH 25/67] Improved testing so that it tests the real functionality and not the private method. --- activesupport/test/caching_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 793e62a74a598..cb5362525f984 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -567,11 +567,12 @@ def test_key_transformation_max_filename_size assert_equal 'B', File.basename(path) end - def test_search_dir_when_directory_does_not_exist - ActiveSupport::Cache::FileStore.new('test').send(:search_dir, 'dir_does_not_exist') do |path| - flunk "search_dir yielded but should have done nothing" + # If nothing has been stored in the cache, there is a chance the cache directory does not yet exist + # Ensure delete_matched gracefully handles this case + def test_delete_matched_when_cache_directory_does_not_exist + assert_nothing_raised(Exception) do + ActiveSupport::Cache::FileStore.new('/test/cache/directory').delete_matched(/does_not_exist/) end - assert true end end From 63f6da050acb1108a3f22c2bd393a8c2c05caeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 2 Oct 2011 11:17:06 +0200 Subject: [PATCH 26/67] Update CHANGELOG. --- railties/CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 992519ee9295b..160ea0f600762 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.2.0 (unreleased)* +* Default options to `rails new` can be set in ~/.railsrc [Guillermo Iguaran] + * Added destroy alias to Rails engines. [Guillermo Iguaran] * Added destroy alias for Rails command line. This allows the following: `rails d model post`. [Andrey Ognevsky] From 6e8fe1bf021139a2fbd06a10778ad2c6b67930ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 2 Oct 2011 11:28:48 +0200 Subject: [PATCH 27/67] TestCase should respect the view_assigns API instead of pulling variables on its own. --- .../lib/abstract_controller/rendering.rb | 4 ++-- .../action_dispatch/testing/test_process.rb | 7 +------ actionpack/test/controller/test_test.rb | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index ab2c532859361..41fdc1119643d 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -120,8 +120,6 @@ def _render_template(options) #:nodoc: view_renderer.render(view_context, options) end - private - DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w( @_action_name @_response_body @_formats @_prefixes @_config @_view_context_class @_view_renderer @_lookup_context @@ -139,6 +137,8 @@ def view_assigns hash end + private + # Normalize args and options. # :api: private def _normalize_render(*args, &block) diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb index f668b81b452e6..b08ff41950e43 100644 --- a/actionpack/lib/action_dispatch/testing/test_process.rb +++ b/actionpack/lib/action_dispatch/testing/test_process.rb @@ -5,12 +5,7 @@ module ActionDispatch module TestProcess def assigns(key = nil) - assigns = {}.with_indifferent_access - @controller.instance_variable_names.each do |ivar| - next if ActionController::Base.protected_instance_variables.include?(ivar) - assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar) - end - + assigns = @controller.view_assigns.with_indifferent_access key.nil? ? assigns : assigns[key] end diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index cba3aded2fc96..ca87cda2a3991 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -146,6 +146,17 @@ def setup end end + class ViewAssignsController < ActionController::Base + def test_assigns + @foo = "foo" + render :nothing => true + end + + def view_assigns + { "bar" => "bar" } + end + end + def test_raw_post_handling params = ActiveSupport::OrderedHash[:page, {:name => 'page name'}, 'some key', 123] post :render_raw_post, params.dup @@ -256,6 +267,15 @@ def test_assigns assert_equal "foo", assigns["foo"] end + def test_view_assigns + @controller = ViewAssignsController.new + process :test_assigns + assert_equal nil, assigns(:foo) + assert_equal nil, assigns[:foo] + assert_equal "bar", assigns(:bar) + assert_equal "bar", assigns[:bar] + end + def test_assert_tag_tag process :test_html_output From 753424079e497d8ab7bc611093a34194200e3c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 2 Oct 2011 12:14:31 +0200 Subject: [PATCH 28/67] Provide initialize_on_precompile which, when set to false, does not initialize the app for precompilation. Defaults to true. --- actionpack/lib/sprockets/assets.rake | 8 ++++-- railties/CHANGELOG | 3 ++- .../lib/rails/application/configuration.rb | 27 ++++++++++--------- railties/test/application/assets_test.rb | 23 ++++++++++++++++ 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index bb5cf6740a737..7b86d84a271a0 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -54,7 +54,11 @@ namespace :assets do end task :environment do - Rails.application.initialize!(:assets) - Sprockets::Bootstrap.new(Rails.application).run + if Rails.application.config.assets.initialize_on_precompile + Rake::Task["environment"].invoke + else + Rails.application.initialize!(:assets) + Sprockets::Bootstrap.new(Rails.application).run + end end end diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 160ea0f600762..187dd2428fcd0 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -17,7 +17,8 @@ * Add jquery-rails to Gemfile of plugins, test/dummy app needs it. Closes #3091. [Santiago Pastorino] -* `rake assets:precompile` loads the application but does not initialize it. +* Add config.assets.initialize_on_precompile which, when set to false, forces + `rake assets:precompile` to load the application but does not initialize it. To the app developer, this means configuration add in config/initializers/* will not be executed. diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index c363e53c1057c..448521d2f0276 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -37,19 +37,20 @@ def initialize(*) @cache_store = [ :file_store, "#{root}/tmp/cache/" ] @assets = ActiveSupport::OrderedOptions.new - @assets.enabled = false - @assets.paths = [] - @assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, - /(?:\/|\\|\A)application\.(css|js)$/ ] - @assets.prefix = "/assets" - @assets.version = '' - @assets.debug = false - @assets.compile = true - @assets.digest = false - @assets.manifest = nil - @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] - @assets.js_compressor = nil - @assets.css_compressor = nil + @assets.enabled = false + @assets.paths = [] + @assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css']) }, + /(?:\/|\\|\A)application\.(css|js)$/ ] + @assets.prefix = "/assets" + @assets.version = '' + @assets.debug = false + @assets.compile = true + @assets.digest = false + @assets.manifest = nil + @assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/" ] + @assets.js_compressor = nil + @assets.css_compressor = nil + @assets.initialize_on_precompile = true end def compiled_asset_path diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 118ffff44bb69..7bace25fef8ec 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -395,7 +395,30 @@ class ::PostsController < ActionController::Base ; end assert_match(/