mobylette 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +83 -0
- data/Rakefile +37 -0
- data/lib/mobylette.rb +12 -0
- data/lib/mobylette/controllers/helpers.rb +52 -0
- data/lib/mobylette/controllers/respond_to_mobile_requests.rb +86 -0
- data/lib/mobylette/helmet.rb +41 -0
- data/lib/mobylette/helmet/faker.rb +19 -0
- data/lib/mobylette/helmet/helpers.rb +34 -0
- data/lib/mobylette/railtie.rb +10 -0
- data/lib/mobylette/version.rb +3 -0
- data/lib/tasks/mobylette_tasks.rake +4 -0
- data/spec/controllers/actioncontroller_base_spec.rb +16 -0
- data/spec/controllers/default_fallback_controller_spec.rb +36 -0
- data/spec/controllers/desktop_only_controller_spec.rb +17 -0
- data/spec/controllers/force_fallback_controller_spec.rb +41 -0
- data/spec/controllers/home_controller_spec.rb +89 -0
- data/spec/controllers/no_fallback_controller_spec.rb +56 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/javascripts/application_mobile.js +9 -0
- data/spec/dummy/app/assets/javascripts/default_fallback.js +2 -0
- data/spec/dummy/app/assets/javascripts/desktop_only.js +2 -0
- data/spec/dummy/app/assets/javascripts/fallbacks.js +2 -0
- data/spec/dummy/app/assets/javascripts/force_fallback.js +2 -0
- data/spec/dummy/app/assets/javascripts/home.js +2 -0
- data/spec/dummy/app/assets/javascripts/no_fallback.js +2 -0
- data/spec/dummy/app/assets/javascripts/testing.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +11 -0
- data/spec/dummy/app/assets/stylesheets/application_mobile.css +11 -0
- data/spec/dummy/app/assets/stylesheets/default_fallback.css +4 -0
- data/spec/dummy/app/assets/stylesheets/desktop_only.css +4 -0
- data/spec/dummy/app/assets/stylesheets/fallbacks.css +4 -0
- data/spec/dummy/app/assets/stylesheets/force_fallback.css +4 -0
- data/spec/dummy/app/assets/stylesheets/home.css +4 -0
- data/spec/dummy/app/assets/stylesheets/no_fallback.css +4 -0
- data/spec/dummy/app/assets/stylesheets/testing.css +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/default_fallback_controller.rb +13 -0
- data/spec/dummy/app/controllers/desktop_only_controller.rb +2 -0
- data/spec/dummy/app/controllers/fallbacks_controller.rb +7 -0
- data/spec/dummy/app/controllers/force_fallback_controller.rb +13 -0
- data/spec/dummy/app/controllers/home_controller.rb +19 -0
- data/spec/dummy/app/controllers/no_fallback_controller.rb +13 -0
- data/spec/dummy/app/controllers/testing_controller.rb +9 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/default_fallback_helper.rb +2 -0
- data/spec/dummy/app/helpers/desktop_only_helper.rb +2 -0
- data/spec/dummy/app/helpers/fallbacks_helper.rb +2 -0
- data/spec/dummy/app/helpers/force_fallback_helper.rb +2 -0
- data/spec/dummy/app/helpers/home_helper.rb +2 -0
- data/spec/dummy/app/helpers/no_fallback_helper.rb +2 -0
- data/spec/dummy/app/helpers/testing_helper.rb +2 -0
- data/spec/dummy/app/views/default_fallback/index.html.erb +1 -0
- data/spec/dummy/app/views/default_fallback/index.js.erb +1 -0
- data/spec/dummy/app/views/default_fallback/index.mobile.erb +1 -0
- data/spec/dummy/app/views/default_fallback/test.html.erb +1 -0
- data/spec/dummy/app/views/default_fallback/test.js.erb +1 -0
- data/spec/dummy/app/views/fallbacks/index.html.erb +2 -0
- data/spec/dummy/app/views/fallbacks/index.js.erb +1 -0
- data/spec/dummy/app/views/fallbacks/index.mobile.erb +0 -0
- data/spec/dummy/app/views/fallbacks/index.xml.erb +0 -0
- data/spec/dummy/app/views/fallbacks/no_mobile.html.erb +0 -0
- data/spec/dummy/app/views/force_fallback/index.html.erb +1 -0
- data/spec/dummy/app/views/force_fallback/index.js.erb +1 -0
- data/spec/dummy/app/views/force_fallback/index.mobile.erb +1 -0
- data/spec/dummy/app/views/force_fallback/test.html.erb +1 -0
- data/spec/dummy/app/views/force_fallback/test.js.erb +1 -0
- data/spec/dummy/app/views/home/desktop.html.erb +1 -0
- data/spec/dummy/app/views/home/index.html.erb +7 -0
- data/spec/dummy/app/views/home/index.mobile.erb +7 -0
- data/spec/dummy/app/views/home/mobile.mobile.erb +1 -0
- data/spec/dummy/app/views/home/no_mobile_view.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/app/views/layouts/application.mobile.erb +16 -0
- data/spec/dummy/app/views/no_fallback/index.html.erb +1 -0
- data/spec/dummy/app/views/no_fallback/index.js.erb +1 -0
- data/spec/dummy/app/views/no_fallback/index.mobile.erb +1 -0
- data/spec/dummy/app/views/no_fallback/test.html.erb +1 -0
- data/spec/dummy/app/views/no_fallback/test.js.erb +1 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +46 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +33 -0
- data/spec/dummy/config/environments/production.rb +51 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +16 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +32 -0
- data/spec/dummy/log/test.log +1537 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/cache/assets/C82/3E0/sprockets%2F48eb4ac616538f8f36870451073315da +0 -0
- data/spec/dummy/tmp/cache/assets/CE4/1C0/sprockets%2F18d93e1533d585b2f64ec90b33176ac9 +0 -0
- data/spec/dummy/tmp/cache/assets/CED/A70/sprockets%2F621683d8791730a9cc7ce45e17a7e46d +0 -0
- data/spec/dummy/tmp/cache/assets/CFC/200/sprockets%2F716f89d85d4855706b8a9abec1969c62 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D54/ED0/sprockets%2F71c9fa01091d432b131da3bb73faf3d4 +0 -0
- data/spec/dummy/tmp/cache/assets/D84/210/sprockets%2Fabd0103ccec2b428ac62c94e4c40b384 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/helpers/mobylette_helpers_spec.rb +59 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/mobylette_spec.rb +7 -0
- data/spec/spec_helper.rb +35 -0
- metadata +320 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DesktopOnlyController do
|
|
4
|
+
|
|
5
|
+
it "should not have the :handle_mobile method" do
|
|
6
|
+
@controller.private_methods.include?(:handle_mobile).should_not be_true
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should have the :is_mobile_request? method" do
|
|
10
|
+
|
|
11
|
+
# Works on ruby 1.9.2 but not on 1.8.7:
|
|
12
|
+
#@controller.private_methods.include?(:is_mobile_request?).should be_true
|
|
13
|
+
|
|
14
|
+
@controller.send(:is_mobile_request?).should be_nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ForceFallbackController do
|
|
4
|
+
render_views
|
|
5
|
+
|
|
6
|
+
it "should find the correct view (mobile) when it exists" do
|
|
7
|
+
force_mobile_request_agent
|
|
8
|
+
get :index
|
|
9
|
+
response.should render_template(:index)
|
|
10
|
+
response.body.should contain("MOBILE VIEW")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should find the correct view (html) when it exists" do
|
|
14
|
+
reset_test_request_agent
|
|
15
|
+
get :index
|
|
16
|
+
response.should render_template(:index)
|
|
17
|
+
response.body.should contain("HTML VIEW")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should fall back to the JS format when it doesnt have mobile" do
|
|
21
|
+
force_mobile_request_agent
|
|
22
|
+
get :test
|
|
23
|
+
response.should render_template(:test)
|
|
24
|
+
response.body.should contain("JS VIEW")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should fall back to the JS format when it doesnt have mobile" do
|
|
28
|
+
force_mobile_request_agent
|
|
29
|
+
get :test, :format => :html
|
|
30
|
+
response.should render_template(:test)
|
|
31
|
+
response.body.should contain("JS VIEW")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should fall back to the JS format when it doesnt (js)" do
|
|
35
|
+
force_mobile_request_agent
|
|
36
|
+
get :test, :format => :js
|
|
37
|
+
response.should render_template(:test)
|
|
38
|
+
response.body.should contain("JS VIEW")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe HomeController do
|
|
4
|
+
render_views
|
|
5
|
+
|
|
6
|
+
it "should have the :handle_mobile method" do
|
|
7
|
+
#
|
|
8
|
+
# Works on ruby 1.9.2 but not on 1.8.7
|
|
9
|
+
# @controller.private_methods.include?(:handle_mobile).should be_true
|
|
10
|
+
# this is a hack, not perfect, but if it didnt have the method it would
|
|
11
|
+
# throw an error, and the test would fail
|
|
12
|
+
@controller.send(:handle_mobile).should be_nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should render the index view" do
|
|
16
|
+
get :index
|
|
17
|
+
response.should render_template(:index)
|
|
18
|
+
response.body.should contain("this is the html view")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should have the Rails Testing request type by default" do
|
|
22
|
+
get :index
|
|
23
|
+
request.user_agent.should == "Rails Testing"
|
|
24
|
+
@controller.send(:is_mobile_request?).should be_false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should have respond to mobile requests" do
|
|
28
|
+
force_mobile_request_agent("Android")
|
|
29
|
+
get :index
|
|
30
|
+
request.user_agent.should == "Android"
|
|
31
|
+
@controller.send(:is_mobile_request?).should be_true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "reset_test_request_agent should reset the user_agent to Rails Testing" do
|
|
35
|
+
force_mobile_request_agent("Iphone")
|
|
36
|
+
reset_test_request_agent
|
|
37
|
+
get :index
|
|
38
|
+
request.user_agent.should == "Rails Testing"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should have the mobile mime_type" do
|
|
42
|
+
force_mobile_request_agent
|
|
43
|
+
get :index
|
|
44
|
+
@controller.send(:is_mobile_request?).should be_true
|
|
45
|
+
response.body.should contain("this is the mobile view")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should render desktop view on non mobile request" do
|
|
49
|
+
reset_test_request_agent
|
|
50
|
+
get :respond_to_test
|
|
51
|
+
response.should render_template(:desktop)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should render mobile view on mobile request" do
|
|
55
|
+
force_mobile_request_agent("Android")
|
|
56
|
+
get :respond_to_test
|
|
57
|
+
response.should render_template(:mobile)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should render mobile view on mobile request when .mobile" do
|
|
61
|
+
get :respond_to_test, :format => "mobile"
|
|
62
|
+
response.should render_template(:mobile)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should display THIS A MOBILE DEVICE on index from mobile" do
|
|
66
|
+
force_mobile_request_agent("Android")
|
|
67
|
+
get :index
|
|
68
|
+
response.body.should contain("THIS A MOBILE DEVICE")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should not display THIS IS NOT A MOBILE DEVICE on index from mobile" do
|
|
72
|
+
force_mobile_request_agent("Android")
|
|
73
|
+
get :index
|
|
74
|
+
response.body.should_not contain("THIS IS NOT A MOBILE DEVICE")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should not display THIS A MOBILE DEVICE on index from non mobile" do
|
|
78
|
+
reset_test_request_agent
|
|
79
|
+
get :index
|
|
80
|
+
response.body.should_not contain("THIS A MOBILE DEVICE")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should display THIS IS NOT A MOBILE DEVICE on index from non mobile" do
|
|
84
|
+
reset_test_request_agent
|
|
85
|
+
get :index
|
|
86
|
+
response.body.should contain("THIS IS NOT A MOBILE DEVICE")
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe NoFallbackController do
|
|
4
|
+
render_views
|
|
5
|
+
|
|
6
|
+
it "should find the correct view when it exists" do
|
|
7
|
+
force_mobile_request_agent
|
|
8
|
+
get :index
|
|
9
|
+
response.should render_template(:index)
|
|
10
|
+
response.body.should contain("MOBILE VIEW")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should find the correct view when it exists" do
|
|
14
|
+
reset_test_request_agent
|
|
15
|
+
get :index
|
|
16
|
+
response.should render_template(:index)
|
|
17
|
+
response.body.should contain("HTML VIEW")
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should give an error when there is no mobile view (original format -> html)" do
|
|
21
|
+
force_mobile_request_agent
|
|
22
|
+
was_error = false
|
|
23
|
+
begin
|
|
24
|
+
get(:test)
|
|
25
|
+
rescue ActionView::MissingTemplate => e
|
|
26
|
+
was_error = true
|
|
27
|
+
ensure
|
|
28
|
+
was_error.should be_true
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should give an error when there is no mobile view (original format -> html - param)" do
|
|
33
|
+
force_mobile_request_agent
|
|
34
|
+
was_error = false
|
|
35
|
+
begin
|
|
36
|
+
get(:test, :format => :html)
|
|
37
|
+
rescue ActionView::MissingTemplate => e
|
|
38
|
+
was_error = true
|
|
39
|
+
ensure
|
|
40
|
+
was_error.should be_true
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should give an error when there is no mobile view (original format -> js)" do
|
|
45
|
+
force_mobile_request_agent
|
|
46
|
+
was_error = false
|
|
47
|
+
begin
|
|
48
|
+
get(:test)
|
|
49
|
+
rescue ActionView::MissingTemplate => e
|
|
50
|
+
was_error = true
|
|
51
|
+
ensure
|
|
52
|
+
was_error.should be_true
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
data/spec/dummy/Rakefile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
4
|
+
|
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
|
6
|
+
|
|
7
|
+
Dummy::Application.load_tasks
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
|
+
// the compiled file.
|
|
6
|
+
//
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
alert("HTML JS");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
5
|
+
// the compiled file.
|
|
6
|
+
//
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
alert("MOBILE JS");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
|
5
|
+
*= require_self
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
body {
|
|
10
|
+
background-color: blue;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class HomeController < ApplicationController
|
|
2
|
+
|
|
3
|
+
respond_to_mobile_requests
|
|
4
|
+
|
|
5
|
+
def index
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def respond_to_test
|
|
9
|
+
respond_to do |format|
|
|
10
|
+
format.html {render :action => "desktop"}
|
|
11
|
+
format.mobile {render :action => "mobile"}
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def no_mobile_view
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|