Browse files

setting the force_canonical cookie

  • Loading branch information...
1 parent 1ea26be commit 66802e1e09d96d78dae5a9443e920f59785e3086 @matthewrobertson committed Jan 29, 2013
Showing with 11 additions and 4 deletions.
  1. +8 −1 lib/ress/controller_additions.rb
  2. +2 −2 spec/ress/controller_additions_spec.rb
  3. +1 −1 vendor/assets/javascripts/ress.js
View
9 lib/ress/controller_additions.rb
@@ -6,9 +6,16 @@ module ControllerAdditions
def self.included(base)
base.helper_method :canonical_request?
base.helper_method :force_canonical_url
+ base.before_filter :set_force_canonical_cookie
base.before_filter :prepend_alternate_view_path
end
+ def set_force_canonical_cookie
+ if params[:force_canonical]
+ cookies[:force_canonical] = 1
+ end
+ end
+
def prepend_alternate_view_path
Ress.alternate_versions.each do |cat|
prepend_view_path(cat.view_path) if cat.matches?(request.subdomain)
@@ -24,7 +31,7 @@ def force_canonical_url
url = Ress.canonical_version.url(request.protocol, path, request.subdomain)
sep = url.include?('?') ? '&' : '?'
- "#{url}#{sep}force=1"
+ "#{url}#{sep}force_canonical=1"
end
end
View
4 spec/ress/controller_additions_spec.rb
@@ -84,12 +84,12 @@ def self.helper_method(*splat) ; end
it 'appends params to the current url properly if there are no GET params' do
@request.stub(:fullpath => '/some_place')
- controller.force_canonical_url.should == 'http://bar.com/some_place?force=1'
+ controller.force_canonical_url.should == 'http://bar.com/some_place?force_canonical=1'
end
it 'appends params to the current url properly when there are GET params' do
@request.stub(:fullpath => '/some_place?param=something')
- controller.force_canonical_url.should == 'http://bar.com/some_place?param=something&force=1'
+ controller.force_canonical_url.should == 'http://bar.com/some_place?param=something&force_canonical=1'
end
end
View
2 vendor/assets/javascripts/ress.js
@@ -5,7 +5,7 @@
(function(exports) {
var MQ_TOUCH = /\(touch-enabled: (.*?)\)/;
- var FORCE_COOKIE = 'force-cannonical';
+ var FORCE_COOKIE = 'force_canonical';
/**
* Class responsible for deciding which version of the application to

0 comments on commit 66802e1

Please sign in to comment.