should fix the mobile toggle for the case: desktop --to--> mobile #3299
also, (possibly) fix tablet issue #3421, + tests
This commit is contained in:
parent
6868d7e915
commit
1809897aa2
4 changed files with 63 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
# Copyright (c) 2010-2012, Diaspora Inc. This file is
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_filter :set_locale
|
before_filter :set_locale
|
||||||
before_filter :set_git_header if (AppConfig[:git_update] && AppConfig[:git_revision])
|
before_filter :set_git_header if (AppConfig[:git_update] && AppConfig[:git_revision])
|
||||||
before_filter :set_grammatical_gender
|
before_filter :set_grammatical_gender
|
||||||
before_filter :tablet_device_fallback
|
before_filter :mobile_switch
|
||||||
|
|
||||||
inflection_method :grammatical_gender => :gender
|
inflection_method :grammatical_gender => :gender
|
||||||
|
|
||||||
|
|
@ -106,9 +106,15 @@ class ApplicationController < ActionController::Base
|
||||||
@grammatical_gender || nil
|
@grammatical_gender || nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def tablet_device_fallback
|
# use :mobile view for mobile and :html for everything else
|
||||||
|
# (except if explicitly specified, e.g. :json, :xml)
|
||||||
|
def mobile_switch
|
||||||
|
if session[:mobile_view] == true && request.format.html?
|
||||||
|
request.format = :mobile
|
||||||
|
elsif request.format.tablet?
|
||||||
# we currently don't have any special tablet views...
|
# we currently don't have any special tablet views...
|
||||||
request.format = :html if is_tablet_device?
|
request.format = :html
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
def after_sign_in_path_for(resource)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
# Copyright (c) 2010-2012, Diaspora Inc. This file is
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
@ -25,7 +25,14 @@ class HomeController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_mobile
|
def toggle_mobile
|
||||||
|
if session[:mobile_view].nil?
|
||||||
|
# we're most probably not on mobile, but user wants it anyway
|
||||||
|
session[:mobile_view] = true
|
||||||
|
else
|
||||||
|
# switch from mobile to normal html
|
||||||
session[:mobile_view] = !session[:mobile_view]
|
session[:mobile_view] = !session[:mobile_view]
|
||||||
|
end
|
||||||
|
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
# Copyright (c) 2010-2012, Diaspora Inc. This file is
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
@ -33,4 +33,31 @@ describe ApplicationController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#mobile_switch' do
|
||||||
|
it 'sets the format to :mobile' do
|
||||||
|
request.format = :html
|
||||||
|
session[:mobile_view] = true
|
||||||
|
get :index
|
||||||
|
request.format.mobile?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'uses :html for :tablets' do
|
||||||
|
request.format = :tablet
|
||||||
|
session[:tablet_view] = true
|
||||||
|
get :index
|
||||||
|
request.format.html?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't mess up other formats, like json" do
|
||||||
|
get :index, :format => 'json'
|
||||||
|
request.format.json?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't mess up other formats, like xml, even with :mobile session" do
|
||||||
|
session[:mobile_view] = true
|
||||||
|
get :index, :format => 'xml'
|
||||||
|
request.format.xml?.should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
# Copyright (c) 2010-2012, Diaspora Inc. This file is
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
@ -36,4 +36,18 @@ describe HomeController do
|
||||||
response.should redirect_to(person_path(alice.person))
|
response.should redirect_to(person_path(alice.person))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#toggle_mobile' do
|
||||||
|
it 'changes :mobile to :html' do
|
||||||
|
session[:mobile_view] = true
|
||||||
|
get :toggle_mobile
|
||||||
|
session[:mobile_view].should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'changes :html to :mobile' do
|
||||||
|
session[:mobile_view] = nil
|
||||||
|
get :toggle_mobile
|
||||||
|
session[:mobile_view].should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue