rails_amp 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +14 -0
- data/MIT-LICENSE +20 -0
- data/README.md +370 -0
- data/Rakefile +23 -0
- data/gemfiles/Gemfile-rails.4.1.x +4 -0
- data/gemfiles/Gemfile-rails.4.2.x +4 -0
- data/lib/generators/rails_amp/install_generator.rb +23 -0
- data/lib/generators/rails_amp/templates/rails_amp.yml +39 -0
- data/lib/generators/rails_amp/templates/rails_amp_application.amp.erb +34 -0
- data/lib/rails_amp/config.rb +106 -0
- data/lib/rails_amp/overrider.rb +44 -0
- data/lib/rails_amp/railtie.rb +17 -0
- data/lib/rails_amp/version.rb +3 -0
- data/lib/rails_amp/view_helpers/action_view.rb +68 -0
- data/lib/rails_amp/view_helpers/image_tag_helper.rb +57 -0
- data/lib/rails_amp.rb +95 -0
- data/rails_amp.gemspec +23 -0
- data/spec/controllers/application_controller_spec.rb +142 -0
- data/spec/dummy/.rspec +2 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +4 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/home_controller.rb +17 -0
- data/spec/dummy/app/controllers/users_controller.rb +25 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/views/home/_amp_info.html.erb +19 -0
- data/spec/dummy/app/views/home/about.html.erb +2 -0
- data/spec/dummy/app/views/home/help.html.erb +2 -0
- data/spec/dummy/app/views/home/index.html.erb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/app/views/layouts/rails_amp_application.amp.erb +34 -0
- data/spec/dummy/app/views/users/index.html.erb +11 -0
- data/spec/dummy/app/views/users/show.html.erb +7 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +9 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +86 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/rails_amp.yml +39 -0
- data/spec/dummy/config/routes.rb +10 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/migrate/20170130074559_create_users.rb +10 -0
- data/spec/dummy/db/schema.rb +22 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/rails_amp_spec.rb +242 -0
- data/spec/rails_helper.rb +66 -0
- data/spec/spec_helper.rb +99 -0
- data/spec/support/config/amp_format.yml +4 -0
- data/spec/support/config/controller_actions.yml +5 -0
- data/spec/support/config/controller_all.yml +3 -0
- data/spec/support/config/disable_all.yml +2 -0
- data/spec/support/config/enable_all.yml +3 -0
- data/spec/support/config/enable_analytics.yml +2 -0
- data/spec/support/config/various.yml +12 -0
- data/spec/utilities.rb +5 -0
- data/spec/view_helpers/action_view_spec.rb +37 -0
- metadata +287 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rails secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: 35372676bdd25cac1026ad001a118b67b3c99c32362ee7e5c58aa2946e92f500d5d8dbeb4744a89b8e956591cb723ea47e667f86160caaa24685c383359a8e5a
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: f117c9869d454579acfa1dbe21365ff60fb272ea3f6ff2637a47cc5095eabb589e91c3d6eb4b05515e33e851007ed733cd361ec01b460fedb9f0f41ad2599159
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 20170130074559) do
|
14
|
+
|
15
|
+
create_table "users", force: :cascade do |t|
|
16
|
+
t.string "name"
|
17
|
+
t.string "email"
|
18
|
+
t.datetime "created_at", null: false
|
19
|
+
t.datetime "updated_at", null: false
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,242 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe RailsAmp do
|
4
|
+
it 'returns config directory for test' do
|
5
|
+
expect(config_dir).to match( %r(/support/config\z) )
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'converts correct controller and key' do
|
9
|
+
expect(RailsAmp.controller_to_key(UsersController)).to eq 'users'
|
10
|
+
expect(RailsAmp.controller_to_key(HomeController)).to eq 'home'
|
11
|
+
expect(RailsAmp.key_to_controller('users')).to eq UsersController
|
12
|
+
expect(RailsAmp.key_to_controller('home')).to eq HomeController
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Config do
|
16
|
+
it 'returns correct config default values' do
|
17
|
+
expect(RailsAmp.config_file).to eq "#{Rails.root}/config/rails_amp.yml"
|
18
|
+
expect(RailsAmp.default_format).to eq :amp
|
19
|
+
expect(RailsAmp.targets).to eq({ 'users' => ['index', 'show'] })
|
20
|
+
expect(RailsAmp.analytics).to eq ''
|
21
|
+
end
|
22
|
+
|
23
|
+
specify 'RailsAmp.var equals to RailsAmp.config.var' do
|
24
|
+
expect(RailsAmp.format).to eq RailsAmp.config.format
|
25
|
+
expect(RailsAmp.config_file).to eq RailsAmp.config.config_file
|
26
|
+
expect(RailsAmp.default_format).to eq RailsAmp.config.default_format
|
27
|
+
expect(RailsAmp.targets).to eq RailsAmp.config.targets
|
28
|
+
expect(RailsAmp.analytics).to eq RailsAmp.config.analytics
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when using default /config/rails_amp.yml' do
|
33
|
+
it 'returns correct config values' do
|
34
|
+
expect(RailsAmp.targets).to eq({ 'users' => ['index', 'show'] })
|
35
|
+
expect(RailsAmp.target_actions(UsersController)).to eq ['index', 'show']
|
36
|
+
expect(RailsAmp.target_actions(HomeController)).to eq []
|
37
|
+
expect(RailsAmp.target?('users', 'index')).to eq true
|
38
|
+
expect(RailsAmp.target?('users', 'show')).to eq true
|
39
|
+
expect(RailsAmp.target?('home', 'index')).to eq false
|
40
|
+
expect(RailsAmp.target?('home', 'help')).to eq false
|
41
|
+
expect(RailsAmp.target?('home', 'about')).to eq false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when changing amp default format' do
|
46
|
+
before(:each) do
|
47
|
+
RailsAmp.config_file = "#{config_dir}/amp_format.yml"
|
48
|
+
RailsAmp.reload_config!
|
49
|
+
end
|
50
|
+
|
51
|
+
after(:each) do
|
52
|
+
RailsAmp.config_file = "#{Rails.root}/config/rails_amp.yml"
|
53
|
+
RailsAmp.reload_config!
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns correct config values' do
|
57
|
+
expect(RailsAmp.config_file).to eq "#{config_dir}/amp_format.yml"
|
58
|
+
expect(RailsAmp.default_format).to eq :mobile
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when using amp on some controller actions' do
|
63
|
+
before(:each) do
|
64
|
+
RailsAmp.config_file = "#{config_dir}/controller_actions.yml"
|
65
|
+
RailsAmp.reload_config!
|
66
|
+
end
|
67
|
+
|
68
|
+
after(:each) do
|
69
|
+
RailsAmp.config_file = "#{Rails.root}/config/rails_amp.yml"
|
70
|
+
RailsAmp.reload_config!
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns correct config values' do
|
74
|
+
expect(RailsAmp.config_file).to eq "#{config_dir}/controller_actions.yml"
|
75
|
+
expect(RailsAmp.targets).to eq({ 'home' => ['about', 'help'], 'users' => ['show'] })
|
76
|
+
expect(RailsAmp.disable_all?).to eq false
|
77
|
+
expect(RailsAmp.enable_all?).to eq false
|
78
|
+
expect(RailsAmp.controller_all?('home')).to eq false
|
79
|
+
expect(RailsAmp.controller_all?('users')).to eq false
|
80
|
+
expect(RailsAmp.controller_actions?('home')).to eq true
|
81
|
+
expect(RailsAmp.controller_actions?('users')).to eq true
|
82
|
+
expect(RailsAmp.target_actions(UsersController)).to eq ['show']
|
83
|
+
expect(RailsAmp.target_actions(HomeController)).to eq ['about', 'help']
|
84
|
+
expect(RailsAmp.target?('users', 'index')).to eq false
|
85
|
+
expect(RailsAmp.target?('users', 'show')).to eq true
|
86
|
+
expect(RailsAmp.target?('home', 'index')).to eq false
|
87
|
+
expect(RailsAmp.target?('home', 'help')).to eq true
|
88
|
+
expect(RailsAmp.target?('home', 'about')).to eq true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when using amp on controller all actions' do
|
93
|
+
before(:each) do
|
94
|
+
RailsAmp.config_file = "#{config_dir}/controller_all.yml"
|
95
|
+
RailsAmp.reload_config!
|
96
|
+
end
|
97
|
+
|
98
|
+
after(:each) do
|
99
|
+
RailsAmp.config_file = "#{Rails.root}/config/rails_amp.yml"
|
100
|
+
RailsAmp.reload_config!
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns correct config values' do
|
104
|
+
expect(RailsAmp.config_file).to eq "#{config_dir}/controller_all.yml"
|
105
|
+
expect(RailsAmp.targets).to eq({ 'home' => [] })
|
106
|
+
expect(RailsAmp.disable_all?).to eq false
|
107
|
+
expect(RailsAmp.enable_all?).to eq false
|
108
|
+
expect(RailsAmp.controller_all?('home')).to eq true
|
109
|
+
expect(RailsAmp.controller_actions?('home')).to eq false
|
110
|
+
expect(RailsAmp.target_actions(UsersController)).to eq []
|
111
|
+
expect(RailsAmp.target_actions(HomeController)).to eq ['index', 'help', 'about']
|
112
|
+
expect(RailsAmp.target?('users', 'index')).to eq false
|
113
|
+
expect(RailsAmp.target?('users', 'show')).to eq false
|
114
|
+
expect(RailsAmp.target?('home', 'index')).to eq true
|
115
|
+
expect(RailsAmp.target?('home', 'help')).to eq true
|
116
|
+
expect(RailsAmp.target?('home', 'about')).to eq true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when not using amp on all controllers actions' do
|
121
|
+
before(:each) do
|
122
|
+
RailsAmp.config_file = "#{config_dir}/disable_all.yml"
|
123
|
+
RailsAmp.reload_config!
|
124
|
+
end
|
125
|
+
|
126
|
+
after(:each) do
|
127
|
+
RailsAmp.config_file = "#{Rails.root}/config/rails_amp.yml"
|
128
|
+
RailsAmp.reload_config!
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'returns correct config values' do
|
132
|
+
expect(RailsAmp.config_file).to eq "#{config_dir}/disable_all.yml"
|
133
|
+
expect(RailsAmp.targets).to eq({})
|
134
|
+
expect(RailsAmp.disable_all?).to eq true
|
135
|
+
expect(RailsAmp.enable_all?).to eq false
|
136
|
+
expect(RailsAmp.target_actions(UsersController)).to eq []
|
137
|
+
expect(RailsAmp.target_actions(HomeController)).to eq []
|
138
|
+
expect(RailsAmp.target?('users', 'index')).to eq false
|
139
|
+
expect(RailsAmp.target?('users', 'show')).to eq false
|
140
|
+
expect(RailsAmp.target?('home', 'index')).to eq false
|
141
|
+
expect(RailsAmp.target?('home', 'help')).to eq false
|
142
|
+
expect(RailsAmp.target?('home', 'about')).to eq false
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'when using amp on all controllers actions' do
|
147
|
+
before(:each) do
|
148
|
+
RailsAmp.config_file = "#{config_dir}/enable_all.yml"
|
149
|
+
RailsAmp.reload_config!
|
150
|
+
end
|
151
|
+
|
152
|
+
after(:each) do
|
153
|
+
RailsAmp.config_file = "#{Rails.root}/config/rails_amp.yml"
|
154
|
+
RailsAmp.reload_config!
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'returns correct config values' do
|
158
|
+
expect(RailsAmp.config_file).to eq "#{config_dir}/enable_all.yml"
|
159
|
+
expect(RailsAmp.targets).to eq({ 'application' => 'all' })
|
160
|
+
expect(RailsAmp.disable_all?).to eq false
|
161
|
+
expect(RailsAmp.enable_all?).to eq true
|
162
|
+
expect(RailsAmp.target_actions(UsersController)).to eq ['index', 'show']
|
163
|
+
expect(RailsAmp.target_actions(HomeController)).to eq ['index', 'help', 'about']
|
164
|
+
expect(RailsAmp.target?('users', 'index')).to eq true
|
165
|
+
expect(RailsAmp.target?('users', 'show')).to eq true
|
166
|
+
expect(RailsAmp.target?('home', 'index')).to eq true
|
167
|
+
expect(RailsAmp.target?('home', 'help')).to eq true
|
168
|
+
expect(RailsAmp.target?('home', 'about')).to eq true
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when using google analytics' do
|
173
|
+
before(:each) do
|
174
|
+
RailsAmp.config_file = "#{config_dir}/enable_analytics.yml"
|
175
|
+
RailsAmp.reload_config!
|
176
|
+
end
|
177
|
+
|
178
|
+
after(:each) do
|
179
|
+
RailsAmp.config_file = "#{Rails.root}/config/rails_amp.yml"
|
180
|
+
RailsAmp.reload_config!
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'returns correct config values' do
|
184
|
+
expect(RailsAmp.config_file).to eq "#{config_dir}/enable_analytics.yml"
|
185
|
+
expect(RailsAmp.analytics).to eq 'UA-12345-6'
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when using various configs' do
|
190
|
+
before(:each) do
|
191
|
+
RailsAmp.config_file = "#{config_dir}/various.yml"
|
192
|
+
RailsAmp.reload_config!
|
193
|
+
end
|
194
|
+
|
195
|
+
after(:each) do
|
196
|
+
RailsAmp.config_file = "#{Rails.root}/config/rails_amp.yml"
|
197
|
+
RailsAmp.reload_config!
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'returns correct config values' do
|
201
|
+
expect(RailsAmp.config_file).to eq "#{config_dir}/various.yml"
|
202
|
+
expect(RailsAmp.default_format).to eq :amphtml
|
203
|
+
expect(RailsAmp.targets).to eq({ 'home' => ['index', 'about'], 'users' => ['index'] })
|
204
|
+
expect(RailsAmp.analytics).to eq 'UA-12345-6'
|
205
|
+
expect(RailsAmp.disable_all?).to eq false
|
206
|
+
expect(RailsAmp.enable_all?).to eq false
|
207
|
+
expect(RailsAmp.controller_all?('home')).to eq false
|
208
|
+
expect(RailsAmp.controller_all?('users')).to eq false
|
209
|
+
expect(RailsAmp.controller_actions?('home')).to eq true
|
210
|
+
expect(RailsAmp.controller_actions?('users')).to eq true
|
211
|
+
expect(RailsAmp.target_actions(UsersController)).to eq ['index']
|
212
|
+
expect(RailsAmp.target_actions(HomeController)).to eq ['index', 'about']
|
213
|
+
expect(RailsAmp.target?('users', 'index')).to eq true
|
214
|
+
expect(RailsAmp.target?('users', 'show')).to eq false
|
215
|
+
expect(RailsAmp.target?('home', 'index')).to eq true
|
216
|
+
expect(RailsAmp.target?('home', 'help')).to eq false
|
217
|
+
expect(RailsAmp.target?('home', 'about')).to eq true
|
218
|
+
expect(RailsAmp.amp_format?).to eq false
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'with amp render' do
|
222
|
+
before(:each) do
|
223
|
+
RailsAmp.format = RailsAmp.default_format.to_s
|
224
|
+
end
|
225
|
+
|
226
|
+
after(:each) do
|
227
|
+
RailsAmp.format = ''
|
228
|
+
RailsAmp.config_file = "#{Rails.root}/config/rails_amp.yml"
|
229
|
+
RailsAmp.reload_config!
|
230
|
+
end
|
231
|
+
|
232
|
+
it 'should be rendrabale with amp' do
|
233
|
+
expect(RailsAmp.amp_format?).to eq true
|
234
|
+
expect(RailsAmp.amp_renderable?('users', 'index')).to eq true
|
235
|
+
expect(RailsAmp.amp_renderable?('users', 'show')).to eq false
|
236
|
+
expect(RailsAmp.amp_renderable?('home', 'index')).to eq true
|
237
|
+
expect(RailsAmp.amp_renderable?('home', 'help')).to eq false
|
238
|
+
expect(RailsAmp.amp_renderable?('home', 'about')).to eq true
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
3
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
4
|
+
# Prevent database truncation if the environment is production
|
5
|
+
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
6
|
+
require 'spec_helper'
|
7
|
+
require 'rspec/rails'
|
8
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
9
|
+
require File.expand_path('../utilities', __FILE__)
|
10
|
+
require 'rails_amp/view_helpers/action_view'
|
11
|
+
require 'rails_amp/view_helpers/image_tag_helper'
|
12
|
+
|
13
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
14
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
15
|
+
# run as spec files by default. This means that files in spec/support that end
|
16
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
17
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
18
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
19
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
20
|
+
#
|
21
|
+
# The following line is provided for convenience purposes. It has the downside
|
22
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
23
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
24
|
+
# require only the support files necessary.
|
25
|
+
#
|
26
|
+
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
27
|
+
|
28
|
+
# Checks for pending migration and applies them before tests are run.
|
29
|
+
# If you are not using ActiveRecord, you can remove this line.
|
30
|
+
ActiveRecord::Migration.maintain_test_schema!
|
31
|
+
|
32
|
+
RSpec.configure do |config|
|
33
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
34
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
35
|
+
|
36
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
37
|
+
# examples within a transaction, remove the following line or assign false
|
38
|
+
# instead of true.
|
39
|
+
config.use_transactional_fixtures = true
|
40
|
+
|
41
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
42
|
+
# based on their file location, for example enabling you to call `get` and
|
43
|
+
# `post` in specs under `spec/controllers`.
|
44
|
+
#
|
45
|
+
# You can disable this behaviour by removing the line below, and instead
|
46
|
+
# explicitly tag your specs with their type, e.g.:
|
47
|
+
#
|
48
|
+
# RSpec.describe UsersController, :type => :controller do
|
49
|
+
# # ...
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# The different available types are documented in the features, such as in
|
53
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
54
|
+
config.infer_spec_type_from_file_location!
|
55
|
+
|
56
|
+
# Filter lines from Rails gems in backtraces.
|
57
|
+
config.filter_rails_from_backtrace!
|
58
|
+
# arbitrary gems may also be filtered via:
|
59
|
+
# config.filter_gems_from_backtrace("gem name")
|
60
|
+
|
61
|
+
# Include modules
|
62
|
+
config.include Utilities
|
63
|
+
config.include ActionView::Helpers::AssetTagHelper
|
64
|
+
config.include RailsAmp::ViewHelpers::ImageTagHelper
|
65
|
+
config.include RailsAmp::ViewHelpers::ActionView
|
66
|
+
end
|