Skip to content

Instantly share code, notes, and snippets.

@rmw
Last active December 14, 2015 11:59
Show Gist options
  • Select an option

  • Save rmw/5083195 to your computer and use it in GitHub Desktop.

Select an option

Save rmw/5083195 to your computer and use it in GitHub Desktop.
Using mobile_fu
class ApplicationController < ActionController::Base
protect_from_forgery
has_mobile_fu false
protected
def mobile_only_mobile_fu
set_mobile_format if is_mobile_device?
end
end
describe "mobile_fu" do
it "responds to is_mobile_device?" do
controller.should respond_to(:is_mobile_device?)
end
it "responds to is_tablet_device?" do
controller.should respond_to(:is_tablet_device?)
end
describe "#mobile_only_mobile_fu" do
before { controller.stub(:mobile_exempt? => false) }
it "should not set the mobile_view session if tablet_device" do
controller.stub(:is_tablet_device? => true)
controller.send(:mobile_only_mobile_fu)
session[:mobile_view].should be_nil
end
it "should set the mobile_view session if mobile_device" do
controller.stub(:is_mobile_device? => true)
controller.send(:mobile_only_mobile_fu)
session[:mobile_view].should == true
end
it "should not set the mobile_view session if no device" do
controller.send(:mobile_only_mobile_fu)
session[:mobile_view].should be_nil
end
end
end
class ApplicationController < ActionController::Base
protect_from_forgery
has_mobile_fu false
end
class OffersController < ApplicationController
before_filter :mobile_only_mobile_fu, only: :show
end
context "when mobile or table device" do
it "sets mobile_view if mobile_device" do
controller.stub(:is_mobile_device? => true)
get :show, offer: offer
session[:mobile_view].should be_true
end
it "doesn't set tablet_view if table_device" do
controller.stub(:is_tablet_device? => true)
get :show, offer: offer
session[:tablet_view].should_not be_true
end
end
class OffersController < ApplicationController
has_mobile_fu true
has_no_mobile_fu_for :index
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment