Skip to content
This repository has been archived by the owner on Jul 28, 2018. It is now read-only.

Commit

Permalink
Rails 3.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibaut committed Mar 7, 2015
1 parent ce2f5a0 commit 465b429
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 28 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sudo: false
script: bundle exec rake test

gemfile:
- Gemfile.rails32
- Gemfile.rails40
- Gemfile.rails41
- Gemfile.rails42
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.rails32
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'
gemspec

gem 'rails', '~> 3.2.0'
gem 'test-unit'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Turbolinks is designed to work with any browser that fully supports pushState an

Do note that existing JavaScript libraries may not all be compatible with Turbolinks out of the box due to the change in instantiation cycle. You might very well have to modify them to work with Turbolinks' new set of events. For help with this, check out the [Turbolinks Compatibility](http://reed.github.io/turbolinks-compatibility) project.

Turbolinks works with Rails 4.0 and newer.
Turbolinks works with Rails 3.2 and newer.


Installation
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end

namespace :test do
task :all do
%w(rails40 rails41 rails42).each do |gemfile|
%w(rails32 rails40 rails41 rails42).each do |gemfile|
sh "BUNDLE_GEMFILE='Gemfile.#{gemfile}' bundle --quiet"
sh "BUNDLE_GEMFILE='Gemfile.#{gemfile}' bundle exec rake test"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/turbolinks/redirection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def redirect_via_turbolinks_to(url = {}, response_status = {})
private
def _extract_turbolinks_options!(options)
turbolinks = options.delete(:turbolinks)
options = options.extract!(:keep, :change, :flush)
options = options.extract!(:keep, :change, :flush).delete_if { |_, value| value.nil? }
raise ArgumentError, "cannot combine :keep, :change and :flush options" if options.size > 1
[turbolinks, options]
end
Expand Down
8 changes: 4 additions & 4 deletions test/turbolinks/redirection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def test_redirect_to_url_string_via_xhr_and_post_redirects_via_turbolinks
assert_turbolinks_visit 'http://example.com'
end

def test_redirect_to_url_hash_via_xhr_and_patch_redirects_via_turbolinks
xhr :patch, :redirect_to_url_hash
def test_redirect_to_url_hash_via_xhr_and_put_redirects_via_turbolinks
xhr :put, :redirect_to_url_hash
assert_turbolinks_visit 'http://test.host/redirect/action'
end

Expand All @@ -116,8 +116,8 @@ def test_redirect_to_via_post_and_not_xhr_does_normal_redirect
assert_redirected_to 'http://test.host/redirect/action'
end

def test_redirect_to_via_patch_and_not_xhr_does_normal_redirect
patch :redirect_to_url_string
def test_redirect_to_via_put_and_not_xhr_does_normal_redirect
put :redirect_to_url_string
assert_redirected_to 'http://example.com'
end

Expand Down
8 changes: 4 additions & 4 deletions test/turbolinks/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def test_render_action_via_post
assert_normal_render 'content'
end

def test_render_action_via_xhr_and_patch
def test_render_action_via_xhr_and_put
@request.env['HTTP_ACCEPT'] = Mime::HTML
xhr :patch, :render_action
xhr :put, :render_action
assert_normal_render 'content'
end

Expand Down Expand Up @@ -103,8 +103,8 @@ def test_render_via_xhr_and_post_with_single_change_option_renders_via_turbolink
assert_turbolinks_replace 'content', "{ change: ['foo'] }"
end

def test_render_via_xhr_and_patch_with_multiple_change_option_renders_via_turbolinks
xhr :patch, :render_with_multiple_change_option
def test_render_via_xhr_and_put_with_multiple_change_option_renders_via_turbolinks
xhr :put, :render_with_multiple_change_option
assert_turbolinks_replace 'content', "{ change: ['foo', 'bar'] }"
end

Expand Down
5 changes: 2 additions & 3 deletions test/turbolinks/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'action_controller'
require 'turbolinks'

require 'active_support/testing/autorun'
require 'active_support/testing/autorun' if Rails.version >= '4'
require 'active_support/test_case'
ActiveSupport::TestCase.test_order = :random if ActiveSupport::TestCase.respond_to?(:test_order=)

Expand All @@ -26,9 +26,8 @@ class Base
end

class TestCase
def before_setup
setup do
@routes = TestApplication.routes
super
end
end
end
28 changes: 14 additions & 14 deletions test/turbolinks/turbolinks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,36 @@ class TurbolinksTest < ActionController::TestCase
tests TurbolinksController

def test_request_referer_returns_xhr_referer_or_standard_referer
@request.headers['Referer'] = 'referer'
@request.env['HTTP_REFERER'] = 'referer'
assert_equal 'referer', @request.referer

@request.headers['X-XHR-Referer'] = 'xhr-referer'
@request.env['HTTP_X_XHR_REFERER'] = 'xhr-referer'
assert_equal 'xhr-referer', @request.referer
end

def test_url_for_with_back_uses_xhr_referer_when_available
@request.headers['Referer'] = 'referer'
@request.env['HTTP_REFERER'] = 'referer'
assert_equal 'referer', @controller.view_context.url_for(:back)

@request.headers['X-XHR-Referer'] = 'xhr-referer'
@request.env['HTTP_X_XHR_REFERER'] = 'xhr-referer'
assert_equal 'xhr-referer', @controller.view_context.url_for(:back)
end

def test_redirect_to_back_uses_xhr_referer_when_available
@request.headers['Referer'] = 'http://test.host/referer'
@request.env['HTTP_REFERER'] = 'http://test.host/referer'
get :redirect_to_back
assert_redirected_to 'http://test.host/referer'

@request.headers['X-XHR-Referer'] = 'http://test.host/xhr-referer'
@request.env['HTTP_X_XHR_REFERER'] = 'http://test.host/xhr-referer'
get :redirect_to_back
assert_redirected_to 'http://test.host/xhr-referer'
end

def test_sets_request_method_cookie_on_non_get_requests
post :simple_action
assert_equal 'POST', cookies[:request_method]
patch :simple_action
assert_equal 'PATCH', cookies[:request_method]
put :simple_action
assert_equal 'PUT', cookies[:request_method]
end

def test_pops_request_method_cookie_on_get_request
Expand All @@ -73,9 +73,9 @@ def test_sets_xhr_redirected_to_header_on_redirect_requests_coming_from_turbolin
get :simple_action
assert_nil @response.headers['X-XHR-Redirected-To']

@request.headers['X-XHR-Referer'] = 'http://test.host/'
@request.env['HTTP_X_XHR_REFERER'] = 'http://test.host/'
get :redirect_to_same_origin
@request.headers['X-XHR-Referer'] = nil
@request.env['HTTP_X_XHR_REFERER'] = nil
get :simple_action
assert_equal 'http://test.host/path', @response.headers['X-XHR-Redirected-To']
end
Expand All @@ -87,7 +87,7 @@ def test_changes_status_to_403_on_turbolinks_requests_redirecting_to_different_o
get :redirect_to_different_protocol
assert_response :redirect

@request.headers['X-XHR-Referer'] = 'http://test.host'
@request.env['HTTP_X_XHR_REFERER'] = 'http://test.host'

get :redirect_to_different_host
assert_response :forbidden
Expand All @@ -100,19 +100,19 @@ def test_changes_status_to_403_on_turbolinks_requests_redirecting_to_different_o
end

def test_handles_invalid_xhr_referer_on_redirection
@request.headers['X-XHR-Referer'] = ':'
@request.env['HTTP_X_XHR_REFERER'] = ':'
get :redirect_to_same_origin
assert_response :redirect
end

def test_handles_unescaped_same_origin_location_on_redirection
@request.headers['X-XHR-Referer'] = 'http://test.host/'
@request.env['HTTP_X_XHR_REFERER'] = 'http://test.host/'
get :redirect_to_unescaped_path
assert_response :redirect
end

def test_handles_unescaped_different_origin_location_on_redirection
@request.headers['X-XHR-Referer'] = 'https://test.host/'
@request.env['HTTP_X_XHR_REFERER'] = 'https://test.host/'
get :redirect_to_unescaped_path
assert_response :forbidden
end
Expand Down

0 comments on commit 465b429

Please sign in to comment.