diff options
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/rack_process.rb | 42 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/prototype_helper.rb | 10 | ||||
-rw-r--r-- | actionpack/test/controller/rack_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/template/prototype_helper_test.rb | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 17 | ||||
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/string_inquirer.rb | 11 | ||||
-rw-r--r-- | activesupport/lib/active_support/string_questioneer.rb | 9 | ||||
-rw-r--r-- | activesupport/test/string_inquirer_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/string_questioneer_test.rb | 15 | ||||
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 2 | ||||
-rw-r--r-- | railties/lib/tasks/rails.rb | 2 | ||||
-rw-r--r-- | railties/test/plugin_loader_test.rb | 8 | ||||
-rw-r--r-- | railties/test/rails_info_controller_test.rb | 4 |
17 files changed, 78 insertions, 78 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 861597701c..66af5fd745 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *Edge* +* Added page.reload functionality. Resolves #277. [Sean Huber] + * Fixed Request#remote_ip to only raise hell if the HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR doesn't match (not just if they're both present) [Mark Imbriaco, Bradford Folkens] * Allow caches_action to accept a layout option [José Valim] diff --git a/actionpack/lib/action_controller/rack_process.rb b/actionpack/lib/action_controller/rack_process.rb index d5fb78c44d..37b56dabca 100644 --- a/actionpack/lib/action_controller/rack_process.rb +++ b/actionpack/lib/action_controller/rack_process.rb @@ -49,21 +49,12 @@ module ActionController #:nodoc: def cookies return {} unless @env["HTTP_COOKIE"] - if @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"] - @env["rack.request.cookie_hash"] - else + unless @env["rack.request.cookie_string"] == @env["HTTP_COOKIE"] @env["rack.request.cookie_string"] = @env["HTTP_COOKIE"] - # According to RFC 2109: - # If multiple cookies satisfy the criteria above, they are ordered in - # the Cookie header such that those with more specific Path attributes - # precede those with less specific. Ordering with respect to other - # attributes (e.g., Domain) is unspecified. - @env["rack.request.cookie_hash"] = - parse_query(@env["rack.request.cookie_string"], ';,').inject({}) { |h, (k,v)| - h[k] = Array === v ? v.first : v - h - } + @env["rack.request.cookie_hash"] = CGI::Cookie::parse(@env["rack.request.cookie_string"]) end + + @env["rack.request.cookie_hash"] end def host_with_port_without_standard_port_handling @@ -170,31 +161,6 @@ end_msg def session_options_with_string_keys @session_options_with_string_keys ||= DEFAULT_SESSION_OPTIONS.merge(@session_options).stringify_keys end - - # From Rack::Utils - def parse_query(qs, d = '&;') - params = {} - (qs || '').split(/[#{d}] */n).inject(params) { |h,p| - k, v = unescape(p).split('=',2) - if cur = params[k] - if cur.class == Array - params[k] << v - else - params[k] = [cur, v] - end - else - params[k] = v - end - } - - return params - end - - def unescape(s) - s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){ - [$1.delete('%')].pack('H*') - } - end end class RackResponse < AbstractResponse #:nodoc: diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index ed2abba17a..a7c3b9ddc3 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -868,6 +868,16 @@ module ActionView record "window.location.href = #{url.inspect}" end + # Reloads the browser's current +location+ using JavaScript + # + # Examples: + # + # # Generates: window.location.reload(); + # page.reload + def reload + record 'window.location.reload()' + end + # Calls the JavaScript +function+, optionally with the given +arguments+. # # If a block is given, the block will be passed to a new JavaScriptGenerator; diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb index 026b0195d1..856f24bbdb 100644 --- a/actionpack/test/controller/rack_test.rb +++ b/actionpack/test/controller/rack_test.rb @@ -33,10 +33,10 @@ class BaseRackTest < Test::Unit::TestCase "REDIRECT_STATUS" => "200", "REQUEST_METHOD" => "GET" } + @request = ActionController::RackRequest.new(@env) # some Nokia phone browsers omit the space after the semicolon separator. # some developers have grown accustomed to using comma in cookie values. - @alt_cookie_fmt_request_hash = {"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"} - @request = ActionController::RackRequest.new(@env) + @alt_cookie_fmt_request = ActionController::RackRequest.new(@env.merge({"HTTP_COOKIE"=>"_session_id=c84ace847,96670c052c6ceb2451fb0f2;is_admin=yes"})) end def default_test; end @@ -100,11 +100,11 @@ class RackRequestTest < BaseRackTest end def test_cookie_syntax_resilience - cookies = CGI::Cookie::parse(@env["HTTP_COOKIE"]); + cookies = @request.cookies assert_equal ["c84ace84796670c052c6ceb2451fb0f2"], cookies["_session_id"], cookies.inspect assert_equal ["yes"], cookies["is_admin"], cookies.inspect - alt_cookies = CGI::Cookie::parse(@alt_cookie_fmt_request_hash["HTTP_COOKIE"]); + alt_cookies = @alt_cookie_fmt_request.cookies assert_equal ["c84ace847,96670c052c6ceb2451fb0f2"], alt_cookies["_session_id"], alt_cookies.inspect assert_equal ["yes"], alt_cookies["is_admin"], alt_cookies.inspect end diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index dd6f6ab741..3f5ec07214 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -347,6 +347,11 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest @generator.redirect_to("http://www.example.com/welcome?a=b&c=d") end + def test_reload + assert_equal 'window.location.reload();', + @generator.reload + end + def test_delay @generator.delay(20) do @generator.hide('foo') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 67d70b3886..55f67995d1 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -331,15 +331,26 @@ module ActiveRecord end def assume_migrated_upto_version(version) + version = version.to_i sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name) + migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i) versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename| filename.split('/').last.split('_').first.to_i end - execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')" unless migrated.include?(version.to_i) - (versions - migrated).select { |v| v < version.to_i }.each do |v| - execute "INSERT INTO #{sm_table} (version) VALUES ('#{v}')" + unless migrated.include?(version) + execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')" + end + + inserted = Set.new + (versions - migrated).each do |v| + if inserted.include?(v) + raise "Duplicate migration #{v}. Please renumber your migrations to resolve the conflict." + elsif v < version + execute "INSERT INTO #{sm_table} (version) VALUES ('#{v}')" + inserted << v + end end end diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 894b43928f..c7739fd7e0 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -4,7 +4,7 @@ * Namespace Inflector, Dependencies, OrderedOptions, and TimeZone under ActiveSupport [Josh Peek] -* Added StringQuestioneer for doing things like StringQuestioneer.new("production").production? # => true and StringQuestioneer.new("production").development? # => false [DHH] +* Added StringInquirer for doing things like StringInquirer.new("production").production? # => true and StringInquirer.new("production").development? # => false [DHH] * Fixed Date#end_of_quarter to not blow up on May 31st [#289 state:resolved] (Danger) diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 2b418a1bb7..1a8603e892 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -43,7 +43,7 @@ require 'active_support/ordered_hash' require 'active_support/ordered_options' require 'active_support/option_merger' -require 'active_support/string_questioneer' +require 'active_support/string_inquirer' require 'active_support/values/time_zone' require 'active_support/duration' diff --git a/activesupport/lib/active_support/string_inquirer.rb b/activesupport/lib/active_support/string_inquirer.rb new file mode 100644 index 0000000000..65545748df --- /dev/null +++ b/activesupport/lib/active_support/string_inquirer.rb @@ -0,0 +1,11 @@ +module ActiveSupport + class StringInquirer < String + def method_missing(method_name, *arguments) + if method_name.to_s.ends_with?("?") + self == method_name.to_s[0..-2] + else + super + end + end + end +end diff --git a/activesupport/lib/active_support/string_questioneer.rb b/activesupport/lib/active_support/string_questioneer.rb deleted file mode 100644 index 7732f8b401..0000000000 --- a/activesupport/lib/active_support/string_questioneer.rb +++ /dev/null @@ -1,9 +0,0 @@ -class StringQuestioneer < String - def method_missing(method_name, *arguments) - if method_name.to_s.ends_with?("?") - self == method_name.to_s[0..-2] - else - super - end - end -end
\ No newline at end of file diff --git a/activesupport/test/string_inquirer_test.rb b/activesupport/test/string_inquirer_test.rb new file mode 100644 index 0000000000..dda7850e6b --- /dev/null +++ b/activesupport/test/string_inquirer_test.rb @@ -0,0 +1,15 @@ +require 'abstract_unit' + +class StringInquirerTest < Test::Unit::TestCase + def test_match + assert ActiveSupport::StringInquirer.new("production").production? + end + + def test_miss + assert !ActiveSupport::StringInquirer.new("production").development? + end + + def test_missing_question_mark + assert_raises(NoMethodError) { ActiveSupport::StringInquirer.new("production").production } + end +end diff --git a/activesupport/test/string_questioneer_test.rb b/activesupport/test/string_questioneer_test.rb deleted file mode 100644 index ff9d2c17f9..0000000000 --- a/activesupport/test/string_questioneer_test.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'abstract_unit' - -class StringQuestioneerTest < Test::Unit::TestCase - def test_match - assert StringQuestioneer.new("production").production? - end - - def test_miss - assert !StringQuestioneer.new("production").development? - end - - def test_missing_question_mark - assert_raises(NoMethodError) { StringQuestioneer.new("production").production } - end -end
\ No newline at end of file diff --git a/railties/CHANGELOG b/railties/CHANGELOG index abadeb693f..39edc511da 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,6 +1,6 @@ *Edge* -* Wrapped Rails.env in StringQuestioneer so you can do Rails.env.development? [DHH] +* Wrapped Rails.env in StringInquirer so you can do Rails.env.development? [DHH] * Fixed that RailsInfoController wasn't considering all requests local in development mode (Edgard Castro) [#310 state:resolved] diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index dd6a0c66f5..f0b5e3f257 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -37,7 +37,7 @@ module Rails end def env - StringQuestioneer.new(RAILS_ENV) + ActiveSupport::StringInquirer.new(RAILS_ENV) end def cache diff --git a/railties/lib/tasks/rails.rb b/railties/lib/tasks/rails.rb index bfcf5bc493..8c2b7f9bde 100644 --- a/railties/lib/tasks/rails.rb +++ b/railties/lib/tasks/rails.rb @@ -4,5 +4,5 @@ $VERBOSE = nil Dir["#{File.dirname(__FILE__)}/*.rake"].each { |ext| load ext } # Load any custom rakefile extensions -Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext } Dir["#{RAILS_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext } +Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext } diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 41bd6ec7ea..bce4446f79 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -108,8 +108,8 @@ uses_mocha "Plugin Loader Tests" do @loader.add_plugin_load_paths - assert Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) - assert Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) end def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths @@ -117,8 +117,8 @@ uses_mocha "Plugin Loader Tests" do @loader.add_plugin_load_paths - assert Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) - assert Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) end def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 17c7d9deea..e1872ebf33 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -30,6 +30,8 @@ class Rails::InfoControllerTest < Test::Unit::TestCase @controller = Rails::InfoController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + + ActionController::Base.consider_all_requests_local = true end def test_rails_info_properties_table_rendered_for_local_request @@ -41,6 +43,8 @@ class Rails::InfoControllerTest < Test::Unit::TestCase def test_rails_info_properties_error_rendered_for_non_local_request Rails::InfoController.local_request = false + ActionController::Base.consider_all_requests_local = false + get :properties assert_tag :tag => 'p' assert_response 500 |