Last active
December 14, 2015 11:59
-
-
Save rmw/5083195 to your computer and use it in GitHub Desktop.
Using mobile_fu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| protect_from_forgery | |
| has_mobile_fu false | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class OffersController < ApplicationController | |
| before_filter :mobile_only_mobile_fu, only: :show | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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