From 30a0ebb3eb9fd4c8e4401bcaa4887eb1ce95defa Mon Sep 17 00:00:00 2001 From: Sean Huber Date: Thu, 29 May 2008 10:49:38 -0700 Subject: Add RJS#page.reload. [#277 state:resolved] Signed-off-by: Pratik Naik --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/prototype_helper.rb | 10 ++++++++++ actionpack/test/template/prototype_helper_test.rb | 5 +++++ 3 files changed, 17 insertions(+) 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_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 602832e470..5a1012954e 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/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index 53a250f9d5..b63d8a368c 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') -- cgit v1.2.3 From e66005547223d11365f249a87ab8fcc1deeb5def Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 4 Jun 2008 12:06:55 -0700 Subject: Give a nice message if there are duplicate migrations instead of raising a strange insert error --- .../connection_adapters/abstract/schema_statements.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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 -- cgit v1.2.3 From 1e4fae42d49256c925c43ea109a16a86961d47bd Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 4 Jun 2008 15:00:21 -0500 Subject: Fixed deprecated call to Dependencies in plugin loader test. --- railties/test/plugin_loader_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 -- cgit v1.2.3 From 6e85f14817cddb53875e572770bf3739f82e155f Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 4 Jun 2008 15:02:51 -0500 Subject: Namespaced StringQuestioneer under ActiveSupport. --- activesupport/lib/active_support/string_questioneer.rb | 16 +++++++++------- activesupport/test/string_questioneer_test.rb | 6 +++--- railties/lib/initializer.rb | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/activesupport/lib/active_support/string_questioneer.rb b/activesupport/lib/active_support/string_questioneer.rb index 7732f8b401..666f3c6018 100644 --- a/activesupport/lib/active_support/string_questioneer.rb +++ b/activesupport/lib/active_support/string_questioneer.rb @@ -1,9 +1,11 @@ -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 +module ActiveSupport + 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 -end \ No newline at end of file +end diff --git a/activesupport/test/string_questioneer_test.rb b/activesupport/test/string_questioneer_test.rb index ff9d2c17f9..51a7e399e7 100644 --- a/activesupport/test/string_questioneer_test.rb +++ b/activesupport/test/string_questioneer_test.rb @@ -2,14 +2,14 @@ require 'abstract_unit' class StringQuestioneerTest < Test::Unit::TestCase def test_match - assert StringQuestioneer.new("production").production? + assert ActiveSupport::StringQuestioneer.new("production").production? end def test_miss - assert !StringQuestioneer.new("production").development? + assert !ActiveSupport::StringQuestioneer.new("production").development? end def test_missing_question_mark - assert_raises(NoMethodError) { StringQuestioneer.new("production").production } + assert_raises(NoMethodError) { ActiveSupport::StringQuestioneer.new("production").production } end end \ No newline at end of file diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index dd6a0c66f5..5c927ceddf 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::StringQuestioneer.new(RAILS_ENV) end def cache -- cgit v1.2.3 From 5fe28789731fd521d5a250ac7be21da45dae147d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 4 Jun 2008 15:06:32 -0500 Subject: Renamed StringQuestioneer to StringInquirer. --- activesupport/CHANGELOG | 2 +- activesupport/lib/active_support.rb | 2 +- activesupport/lib/active_support/string_inquirer.rb | 11 +++++++++++ activesupport/lib/active_support/string_questioneer.rb | 11 ----------- activesupport/test/string_inquirer_test.rb | 15 +++++++++++++++ activesupport/test/string_questioneer_test.rb | 15 --------------- railties/CHANGELOG | 2 +- railties/lib/initializer.rb | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 activesupport/lib/active_support/string_inquirer.rb delete mode 100644 activesupport/lib/active_support/string_questioneer.rb create mode 100644 activesupport/test/string_inquirer_test.rb delete mode 100644 activesupport/test/string_questioneer_test.rb 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 666f3c6018..0000000000 --- a/activesupport/lib/active_support/string_questioneer.rb +++ /dev/null @@ -1,11 +0,0 @@ -module ActiveSupport - 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 -end 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 51a7e399e7..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 ActiveSupport::StringQuestioneer.new("production").production? - end - - def test_miss - assert !ActiveSupport::StringQuestioneer.new("production").development? - end - - def test_missing_question_mark - assert_raises(NoMethodError) { ActiveSupport::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 5c927ceddf..f0b5e3f257 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -37,7 +37,7 @@ module Rails end def env - ActiveSupport::StringQuestioneer.new(RAILS_ENV) + ActiveSupport::StringInquirer.new(RAILS_ENV) end def cache -- cgit v1.2.3 From c4d570c2eb6b7bd0a529e20a1055754183d50c23 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 4 Jun 2008 22:32:09 -0500 Subject: Use CGI::Cookie::parse for request cookies until we officially deprecated CGI. --- actionpack/lib/action_controller/rack_process.rb | 42 +++--------------------- actionpack/test/controller/rack_test.rb | 8 ++--- 2 files changed, 8 insertions(+), 42 deletions(-) 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/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 -- cgit v1.2.3 From ed0cb91a830f317e3a8192a90294c1005f6156c2 Mon Sep 17 00:00:00 2001 From: Ryan Kinderman Date: Mon, 26 May 2008 22:15:57 -0500 Subject: Ensure plugins' rake tasks are loaded before application's rake tasks. [#259 state:resolved] Signed-off-by: Pratik Naik --- railties/lib/tasks/rails.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 } -- cgit v1.2.3 From df8154c845f8fb251c58f1fd882cc221cfdcbbc2 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 5 Jun 2008 20:41:22 +0100 Subject: Fix that Rails::InfoController tests --- railties/test/rails_info_controller_test.rb | 4 ++++ 1 file changed, 4 insertions(+) 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 -- cgit v1.2.3