FEATURE: add ability to clear previously set mobile_view with mobile_view=auto

FEATURE: add ability to clear previously set mobile_view with mobile_view=auto

diff --git a/app/assets/javascripts/discourse/lib/mobile.js.es6 b/app/assets/javascripts/discourse/lib/mobile.js.es6
index c05fd2c..df164b0 100644
--- a/app/assets/javascripts/discourse/lib/mobile.js.es6
+++ b/app/assets/javascripts/discourse/lib/mobile.js.es6
@@ -23,6 +23,9 @@ const Mobile = {
       if (window.location.search.match(/mobile_view=0/)) {
         localStorage.mobileView = false;
       }
+      if (window.location.search.match(/mobile_view=auto/)) {
+        localStorage.removeItem("mobileView");
+      }
       if (localStorage.mobileView) {
         var savedValue = localStorage.mobileView === "true";
         if (savedValue !== this.mobileView) {
diff --git a/lib/mobile_detection.rb b/lib/mobile_detection.rb
index a9e2702..fe8d747 100644
--- a/lib/mobile_detection.rb
+++ b/lib/mobile_detection.rb
@@ -8,6 +8,7 @@ module MobileDetection
     return false unless SiteSetting.enable_mobile_theme
 
     session[:mobile_view] = params[:mobile_view] if params && params.has_key?(:mobile_view)
+    session[:mobile_view] = nil if params && params.has_key?(:mobile_view) && params[:mobile_view] == 'auto'
 
     if session && session[:mobile_view]
       session[:mobile_view] == '1'
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 0ddf281..650b245 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -80,6 +80,24 @@ describe ApplicationHelper do
         expect(helper.mobile_view?).to eq(false)
       end
 
+      context "mobile_view session is cleared" do
+        before do
+          params[:mobile_view] = 'auto'
+        end
+
+        it "is false if user agent is not mobile" do
+          session[:mobile_view] = '1'
+          controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36')
+          expect(helper.mobile_view?).to be_falsey
+        end
+
+        it "is true for iPhone" do
+          session[:mobile_view] = '0'
+          controller.request.stubs(:user_agent).returns('Mozilla/5.0 (iPhone; CPU iPhone OS 9_2_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13D15 Safari/601.1')
+          expect(helper.mobile_view?).to eq(true)
+        end
+      end
+
       context "mobile_view is not set" do
         it "is false if user agent is not mobile" do
           controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36')

GitHub sha: 8be78786