locomotivecms_steam 1.5.0.rc0 → 1.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Gemfile +3 -6
- data/Gemfile.lock +39 -39
- data/README.md +2 -2
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +62 -16
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +15 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb +30 -9
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +1 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb +1 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb +14 -2
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/site.rb +1 -1
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/translation.rb +1 -1
- data/lib/locomotive/steam/adapters/mongodb.rb +1 -1
- data/lib/locomotive/steam/entities/content_entry.rb +0 -1
- data/lib/locomotive/steam/entities/site.rb +4 -0
- data/lib/locomotive/steam/errors.rb +54 -18
- data/lib/locomotive/steam/liquid/drops/content_entry.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/content_entry_collection.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/content_types.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/inherited_block.rb +28 -0
- data/lib/locomotive/steam/liquid/drops/metafields.rb +2 -2
- data/lib/locomotive/steam/liquid/drops/params.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/section.rb +10 -2
- data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +13 -2
- data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +1 -1
- data/lib/locomotive/steam/liquid/drops/session_proxy.rb +1 -1
- data/lib/locomotive/steam/liquid/file_system.rb +46 -0
- data/lib/locomotive/steam/liquid/filters/array.rb +61 -0
- data/lib/locomotive/steam/liquid/filters/misc.rb +12 -2
- data/lib/locomotive/steam/liquid/filters/number.rb +13 -12
- data/lib/locomotive/steam/liquid/filters/text.rb +4 -0
- data/lib/locomotive/steam/liquid/patches.rb +58 -19
- data/lib/locomotive/steam/liquid/tags/alt_page_links.rb +9 -5
- data/lib/locomotive/steam/liquid/tags/concerns/attributes.rb +47 -0
- data/lib/locomotive/steam/liquid/tags/concerns/path.rb +18 -31
- data/lib/locomotive/steam/liquid/tags/concerns/section.rb +22 -11
- data/lib/locomotive/steam/liquid/tags/consume.rb +26 -33
- data/lib/locomotive/steam/liquid/tags/csrf.rb +2 -2
- data/lib/locomotive/steam/liquid/tags/editable/base.rb +30 -20
- data/lib/locomotive/steam/liquid/tags/editable/control.rb +2 -2
- data/lib/locomotive/steam/liquid/tags/editable/file.rb +11 -11
- data/lib/locomotive/steam/liquid/tags/editable/text.rb +5 -5
- data/lib/locomotive/steam/liquid/tags/extends.rb +56 -8
- data/lib/locomotive/steam/liquid/tags/global_section.rb +6 -6
- data/lib/locomotive/steam/liquid/tags/google_analytics.rb +16 -6
- data/lib/locomotive/steam/liquid/tags/hybrid.rb +8 -4
- data/lib/locomotive/steam/liquid/tags/inherited_block.rb +90 -13
- data/lib/locomotive/steam/liquid/tags/inline_editor.rb +4 -4
- data/lib/locomotive/steam/liquid/tags/link_to.rb +2 -1
- data/lib/locomotive/steam/liquid/tags/locale_switcher.rb +25 -21
- data/lib/locomotive/steam/liquid/tags/model_form.rb +38 -17
- data/lib/locomotive/steam/liquid/tags/nav.rb +4 -4
- data/lib/locomotive/steam/liquid/tags/page_not_found.rb +19 -0
- data/lib/locomotive/steam/liquid/tags/paginate.rb +13 -7
- data/lib/locomotive/steam/liquid/tags/path_to.rb +1 -0
- data/lib/locomotive/steam/liquid/tags/redirect_to.rb +34 -0
- data/lib/locomotive/steam/liquid/tags/section.rb +34 -33
- data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +1 -1
- data/lib/locomotive/steam/liquid/tags/seo.rb +2 -4
- data/lib/locomotive/steam/liquid/tags/session_assign.rb +1 -0
- data/lib/locomotive/steam/liquid/tags/snippet.rb +21 -29
- data/lib/locomotive/steam/liquid/tags/with_scope.rb +61 -27
- data/lib/locomotive/steam/liquid.rb +3 -1
- data/lib/locomotive/steam/middlewares/cache.rb +117 -0
- data/lib/locomotive/steam/middlewares/concerns/helpers.rb +22 -8
- data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +5 -1
- data/lib/locomotive/steam/middlewares/concerns/rendering.rb +53 -0
- data/lib/locomotive/steam/middlewares/impersonated_entry.rb +4 -0
- data/lib/locomotive/steam/middlewares/locale.rb +2 -2
- data/lib/locomotive/steam/middlewares/locale_redirection.rb +1 -1
- data/lib/locomotive/steam/middlewares/logging.rb +1 -0
- data/lib/locomotive/steam/middlewares/page_not_found.rb +37 -0
- data/lib/locomotive/steam/middlewares/redirection.rb +1 -1
- data/lib/locomotive/steam/middlewares/renderer.rb +4 -26
- data/lib/locomotive/steam/middlewares/thread_safe.rb +0 -4
- data/lib/locomotive/steam/models/pager.rb +1 -0
- data/lib/locomotive/steam/server.rb +3 -1
- data/lib/locomotive/steam/services/action_service.rb +5 -0
- data/lib/locomotive/steam/services/auth_service.rb +9 -9
- data/lib/locomotive/steam/services/cookie_service.rb +1 -0
- data/lib/locomotive/steam/services/external_api_service.rb +5 -0
- data/lib/locomotive/steam/services/liquid_parser_service.rb +4 -2
- data/lib/locomotive/steam/services/page_finder_service.rb +1 -1
- data/lib/locomotive/steam/services/recaptcha_service.rb +4 -2
- data/lib/locomotive/steam/version.rb +1 -1
- data/lib/locomotive/steam.rb +5 -1
- data/locomotivecms_steam.gemspec +4 -4
- data/spec/fixtures/default/app/views/pages/basic.liquid.haml +1 -0
- data/spec/fixtures/default/app/views/pages/music.liquid.haml +6 -0
- data/spec/fixtures/default/app/views/sections/carousel.liquid +15 -16
- data/spec/fixtures/default/app/views/sections/footer.liquid +37 -3
- data/spec/fixtures/default/app/views/sections/header.liquid +47 -10
- data/spec/fixtures/default/app/views/sections/misc/hero.liquid +28 -0
- data/spec/fixtures/default/config/metafields_schema.yml +3 -0
- data/spec/integration/liquid/tags/section_spec.rb +82 -0
- data/spec/integration/repositories/content_entry_repository_spec.rb +9 -0
- data/spec/integration/server/basic_spec.rb +2 -2
- data/spec/integration/server/metafields_spec.rb +1 -0
- data/spec/integration/services/content_entry_service_spec.rb +12 -0
- data/spec/support/helpers.rb +1 -0
- data/spec/support/liquid.rb +32 -2
- data/spec/support/mongo.rb +1 -0
- data/spec/unit/adapters/filesystem/sanitizers/section_spec.rb +66 -40
- data/spec/unit/adapters/filesystem/yaml_loaders/section_spec.rb +25 -0
- data/spec/unit/errors_spec.rb +1 -1
- data/spec/unit/liquid/drops/content_entry_collection_spec.rb +3 -3
- data/spec/unit/liquid/drops/content_entry_spec.rb +4 -4
- data/spec/unit/liquid/drops/content_types_spec.rb +2 -2
- data/spec/unit/liquid/drops/metafields_spec.rb +8 -8
- data/spec/unit/liquid/drops/params_spec.rb +5 -5
- data/spec/unit/liquid/drops/section_content_proxy_spec.rb +69 -18
- data/spec/unit/liquid/drops/section_spec.rb +1 -1
- data/spec/unit/liquid/file_system_spec.rb +25 -0
- data/spec/unit/liquid/filters/array_spec.rb +140 -0
- data/spec/unit/liquid/filters/misc_spec.rb +21 -3
- data/spec/unit/liquid/filters/number_spec.rb +4 -4
- data/spec/unit/liquid/filters/text_spec.rb +4 -0
- data/spec/unit/liquid/tags/alt_page_links_spec.rb +19 -2
- data/spec/unit/liquid/tags/authorize_spec.rb +1 -1
- data/spec/unit/liquid/tags/editable/text_spec.rb +32 -4
- data/spec/unit/liquid/tags/extends_spec.rb +115 -28
- data/spec/unit/liquid/tags/global_section_spec.rb +4 -3
- data/spec/unit/liquid/tags/google_analytics_spec.rb +21 -2
- data/spec/unit/liquid/tags/inherited_block_spec.rb +18 -4
- data/spec/unit/liquid/tags/inline_editor_spec.rb +11 -0
- data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
- data/spec/unit/liquid/tags/model_form_spec.rb +7 -0
- data/spec/unit/liquid/tags/page_not_found_spec.rb +14 -0
- data/spec/unit/liquid/tags/redirect_to_spec.rb +171 -0
- data/spec/unit/liquid/tags/section_spec.rb +43 -3
- data/spec/unit/liquid/tags/sections_dropzone_spec.rb +0 -1
- data/spec/unit/liquid/tags/snippet_spec.rb +9 -8
- data/spec/unit/liquid/tags/with_scope_spec.rb +80 -60
- data/spec/unit/middlewares/cache_spec.rb +186 -0
- data/spec/unit/middlewares/impersonated_entry_spec.rb +7 -0
- data/spec/unit/middlewares/locale_redirection_spec.rb +7 -0
- data/spec/unit/middlewares/locale_spec.rb +8 -1
- data/spec/unit/middlewares/page_not_found_spec.rb +46 -0
- data/spec/unit/middlewares/redirection_spec.rb +8 -0
- data/spec/unit/middlewares/renderer_spec.rb +64 -6
- data/spec/unit/middlewares/section_spec.rb +1 -0
- data/spec/unit/models/pager_spec.rb +11 -1
- data/spec/unit/repositories/section_repository_spec.rb +1 -1
- data/spec/unit/services/action_service_spec.rb +23 -3
- data/spec/unit/services/page_redirection_service_spec.rb +2 -2
- data/spec/unit/services/recaptcha_service_spec.rb +1 -1
- metadata +50 -24
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
|
+
require_relative '../../../lib/locomotive/steam/middlewares/cache'
|
6
|
+
|
7
|
+
describe Locomotive::Steam::Middlewares::Cache do
|
8
|
+
|
9
|
+
let(:now) { DateTime.parse('2015/09/26 22:00:00') }
|
10
|
+
let(:method) { 'GET' }
|
11
|
+
let(:code) { 200 }
|
12
|
+
let(:live_editing) { nil }
|
13
|
+
let(:published) { true }
|
14
|
+
let(:etag) { nil }
|
15
|
+
let(:modified_at) { nil }
|
16
|
+
let(:url) { 'http://models.example.com' }
|
17
|
+
let(:path) { 'hello-world' }
|
18
|
+
let(:page) { instance_double('Page') }
|
19
|
+
let(:cache) { instance_double('CacheService', ) }
|
20
|
+
let(:app) { ->(env) { [code, {}, ['Hello world!']] } }
|
21
|
+
let(:middleware) { described_class.new(app) }
|
22
|
+
|
23
|
+
subject do
|
24
|
+
env = send_request[:env]
|
25
|
+
[env['steam.cache_control'], env['steam.cache_vary']]
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'caching is disabled for the site' do
|
29
|
+
|
30
|
+
let(:site) { instance_double('Site', cache_enabled: false) }
|
31
|
+
|
32
|
+
it 'tells the the CDN to not cache the page' do
|
33
|
+
is_expected.to eq ['max-age=0, private, must-revalidate', nil]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'caching is disabled for the page' do
|
39
|
+
|
40
|
+
let(:site) { instance_double('Site', cache_enabled: true) }
|
41
|
+
let(:page) { instance_double('Page', cache_enabled: false) }
|
42
|
+
|
43
|
+
it 'tells the the CDN to not cache the page' do
|
44
|
+
is_expected.to eq ['max-age=0, private, must-revalidate', nil]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'the caching is enabled for the page' do
|
50
|
+
|
51
|
+
let(:site) { instance_double('Site', _id: 42, last_modified_at: now, cache_enabled: true, cache_control: '', cache_vary: nil) }
|
52
|
+
let(:page) { instance_double('Page', cache_enabled: true) }
|
53
|
+
|
54
|
+
context 'the request is a GET' do
|
55
|
+
|
56
|
+
let(:response) { nil }
|
57
|
+
|
58
|
+
before { expect(cache).to receive(:read).with('a31217f79aba42b0e1c98f7a6bb593fd').and_return(response) }
|
59
|
+
|
60
|
+
context 'the cache is empty' do
|
61
|
+
|
62
|
+
before { expect(cache).to receive(:write).with('a31217f79aba42b0e1c98f7a6bb593fd', Marshal.dump([200, {}, ["Hello world!"]])) }
|
63
|
+
|
64
|
+
it 'tells the CDN to cache the page and also cache it internally' do
|
65
|
+
is_expected.to eq ['max-age=0, s-maxage=3600, public, must-revalidate', 'Accept-Language']
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'ETag' do
|
69
|
+
|
70
|
+
subject { send_request[:env]['steam.cache_etag'] }
|
71
|
+
|
72
|
+
it { is_expected.to eq 'a31217f79aba42b0e1c98f7a6bb593fd' }
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'the site administrator sets a custom cache control and vary' do
|
77
|
+
|
78
|
+
let(:site) { instance_double('Site', _id: 42, last_modified_at: now, cache_enabled: true, cache_control: 'max-age=600, s-maxage=600, public, must-revalidate', cache_vary: 'Cookie') }
|
79
|
+
|
80
|
+
it 'tells the CDN to cache the page with the custom cache control' do
|
81
|
+
is_expected.to eq ['max-age=600, s-maxage=600, public, must-revalidate', 'Cookie']
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'the cache contains the response' do
|
89
|
+
|
90
|
+
let(:response) { Marshal.dump([200, {}, ["Hello world!"]]) }
|
91
|
+
|
92
|
+
it 'tells the CDN to cache the page' do
|
93
|
+
expect(cache).not_to receive(:write)
|
94
|
+
is_expected.to eq ['max-age=0, s-maxage=3600, public, must-revalidate', 'Accept-Language']
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'the page has not been modified for a while' do
|
102
|
+
|
103
|
+
subject { [send_request[:code], send_request[:headers]] }
|
104
|
+
|
105
|
+
context 'based on the ETag' do
|
106
|
+
|
107
|
+
let(:etag) { 'a31217f79aba42b0e1c98f7a6bb593fd' }
|
108
|
+
|
109
|
+
it 'returns a 304 (Not modified) without no cache headers' do
|
110
|
+
expect(subject.first).to eq 304
|
111
|
+
expect(subject.last['Cache-Control']).to eq nil
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'based on the Last-Modified' do
|
117
|
+
|
118
|
+
let(:modified_at) { now }
|
119
|
+
|
120
|
+
it 'returns a 304 (Not modified) without no cache headers' do
|
121
|
+
expect(subject.first).to eq 304
|
122
|
+
expect(subject.last['Cache-Control']).to eq nil
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'the request is a POST' do
|
130
|
+
|
131
|
+
let(:method) { 'POST' }
|
132
|
+
|
133
|
+
it 'tells the the CDN to not cache the page' do
|
134
|
+
is_expected.to eq ['max-age=0, private, must-revalidate', nil]
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'the response is a redirection (302)' do
|
140
|
+
|
141
|
+
let(:code) { 302 }
|
142
|
+
|
143
|
+
before do
|
144
|
+
allow(cache).to receive(:read).and_return(nil)
|
145
|
+
allow(cache).to receive(:write).and_return(true)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'tells the the CDN to not cache the page' do
|
149
|
+
is_expected.to eq ['max-age=0, private, must-revalidate', nil]
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'the live editing mode is on' do
|
155
|
+
|
156
|
+
let(:live_editing) { true }
|
157
|
+
|
158
|
+
it 'tells the the CDN to not cache the page' do
|
159
|
+
is_expected.to eq ['max-age=0, private, must-revalidate', nil]
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
def send_request
|
167
|
+
env = env_for(url,
|
168
|
+
method: method,
|
169
|
+
'HTTP_IF_NONE_MATCH' => etag,
|
170
|
+
'HTTP_IF_MODIFIED_SINCE' => modified_at,
|
171
|
+
'steam.site' => site,
|
172
|
+
'steam.page' => page,
|
173
|
+
'steam.path' => path,
|
174
|
+
'steam.locale' => 'en',
|
175
|
+
'steam.live_editing' => live_editing,
|
176
|
+
'steam.services' => instance_double('Services', cache: cache)
|
177
|
+
)
|
178
|
+
|
179
|
+
env['steam.request'] = Rack::Request.new(env)
|
180
|
+
|
181
|
+
code, headers, body = middleware.call(env)
|
182
|
+
|
183
|
+
{ env: env, code: code, headers: headers }
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
@@ -14,6 +14,8 @@ describe Locomotive::Steam::Middlewares::ImpersonatedEntry do
|
|
14
14
|
let(:session) { {} }
|
15
15
|
let(:params) { {} }
|
16
16
|
let(:middleware) { described_class.new(app) }
|
17
|
+
let(:auth_service) { instance_double('Auth') }
|
18
|
+
let(:services) { instance_double('Services', :auth => auth_service) }
|
17
19
|
|
18
20
|
subject do
|
19
21
|
code, env, body = call
|
@@ -55,6 +57,10 @@ describe Locomotive::Steam::Middlewares::ImpersonatedEntry do
|
|
55
57
|
[code, env['steam.impersonating_authenticated_entry'], env['Location']]
|
56
58
|
end
|
57
59
|
|
60
|
+
before do
|
61
|
+
expect(auth_service).to receive(:notify).with(:signed_out, any_args).and_return(nil)
|
62
|
+
end
|
63
|
+
|
58
64
|
it { is_expected.to eq [302, nil, '/'] }
|
59
65
|
|
60
66
|
it "resets the session variable used to tell if we're in the impersonating mode" do
|
@@ -74,6 +80,7 @@ describe Locomotive::Steam::Middlewares::ImpersonatedEntry do
|
|
74
80
|
env['steam.request'] = Rack::Request.new(env)
|
75
81
|
env['steam.liquid_assigns'] = {}
|
76
82
|
env['steam.authenticated_entry'] = entry
|
83
|
+
env['steam.services'] = services
|
77
84
|
middleware.call(env)
|
78
85
|
end
|
79
86
|
|
@@ -50,6 +50,13 @@ describe Locomotive::Steam::Middlewares::LocaleRedirection do
|
|
50
50
|
let(:url) { 'http://models.example.com/de/hello' }
|
51
51
|
it { is_expected.to eq [301, '/hello'] }
|
52
52
|
|
53
|
+
context 'pass the query string to the redirection' do
|
54
|
+
|
55
|
+
let(:url) { 'http://models.example.com/de/hello?name=John' }
|
56
|
+
it { is_expected.to eq [301, '/hello?name=John'] }
|
57
|
+
|
58
|
+
end
|
59
|
+
|
53
60
|
end
|
54
61
|
|
55
62
|
end
|
@@ -6,7 +6,7 @@ require_relative '../../../lib/locomotive/steam/middlewares/locale'
|
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::Locale do
|
8
8
|
|
9
|
-
let(:site) { instance_double('Site', default_locale: :de, locales: [:de, :fr, :en]) }
|
9
|
+
let(:site) { instance_double('Site', bypass_browser_locale: false, default_locale: :de, locales: [:de, :fr, :en]) }
|
10
10
|
let(:url) { 'http://models.example.com' }
|
11
11
|
let(:app) { ->(env) { [200, env, 'app'] } }
|
12
12
|
let(:cookie_lang) { nil }
|
@@ -70,6 +70,13 @@ describe Locomotive::Steam::Middlewares::Locale do
|
|
70
70
|
|
71
71
|
it { is_expected.to eq [:fr, '/'] }
|
72
72
|
|
73
|
+
context 'the site is set up to bypass the browser locale' do
|
74
|
+
|
75
|
+
let(:site) { instance_double('Site', default_locale: :de, locales: [:de, :fr, :en], bypass_browser_locale: true) }
|
76
|
+
it { is_expected.to eq [:de, '/'] }
|
77
|
+
|
78
|
+
end
|
79
|
+
|
73
80
|
context 'with url path' do
|
74
81
|
|
75
82
|
let(:url) { 'http://models.example.com/werkzeug' }
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/liquid_context'
|
6
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/rendering'
|
7
|
+
require_relative '../../../lib/locomotive/steam/middlewares/page_not_found'
|
8
|
+
|
9
|
+
describe Locomotive::Steam::Middlewares::PageNotFound do
|
10
|
+
|
11
|
+
let(:site) { instance_double('Site', asset_host: nil) }
|
12
|
+
let(:url) { 'http://models.example.com/about-us' }
|
13
|
+
let(:page_finder) { instance_double('PageFinder') }
|
14
|
+
let(:locomotive_path) { nil }
|
15
|
+
let(:app) { ->(env) { [200, env, ['Hello world']] } }
|
16
|
+
let(:middleware) { described_class.new(app) }
|
17
|
+
|
18
|
+
subject do
|
19
|
+
env = env_for(url, 'steam.site' => site)
|
20
|
+
env['steam.request'] = Rack::Request.new(env)
|
21
|
+
env['steam.services'] = instance_double('Services', page_finder: page_finder)
|
22
|
+
env['locomotive.path'] = locomotive_path
|
23
|
+
code, _, body = middleware.call(env)
|
24
|
+
[code, body]
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'no page not found exception raised' do
|
28
|
+
|
29
|
+
it { is_expected.to eq [200, ['Hello world']] }
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'page not found exception raised' do
|
34
|
+
|
35
|
+
let(:page) { instance_double('PageNotFound',not_found?: true, response_type: 'text/html') }
|
36
|
+
let(:app) { ->(env) { raise Locomotive::Steam::PageNotFoundException.new } }
|
37
|
+
|
38
|
+
it 'renders the 404 error page' do
|
39
|
+
expect(page_finder).to receive(:find).with('404').and_return(page)
|
40
|
+
expect_any_instance_of(described_class).to receive(:parse_and_render_liquid).and_return("We're sorry")
|
41
|
+
is_expected.to eq [404, ["We're sorry"]]
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -32,6 +32,14 @@ describe Locomotive::Steam::Middlewares::Redirection do
|
|
32
32
|
|
33
33
|
it { is_expected.to eq [302, '/sign_in'] }
|
34
34
|
|
35
|
+
context 'permanent' do
|
36
|
+
|
37
|
+
let(:app) { ->(env) { raise Locomotive::Steam::RedirectionException.new('/sign_in', permanent: true) } }
|
38
|
+
|
39
|
+
it { is_expected.to eq [301, '/sign_in'] }
|
40
|
+
|
41
|
+
end
|
42
|
+
|
35
43
|
end
|
36
44
|
|
37
45
|
end
|
@@ -7,15 +7,13 @@ require_relative '../../../lib/locomotive/steam/middlewares/renderer'
|
|
7
7
|
|
8
8
|
describe Locomotive::Steam::Middlewares::Renderer do
|
9
9
|
|
10
|
-
let(:
|
11
|
-
|
12
|
-
let(:
|
10
|
+
let(:locale) { 'en' }
|
11
|
+
let(:site) { instance_double('Site', default_locale: 'en') }
|
12
|
+
let(:app) { ->(env) { [200, env, 'app'] }}
|
13
|
+
let(:middleware) { described_class.new(app) }
|
13
14
|
|
14
15
|
describe 'missing 404 page' do
|
15
16
|
|
16
|
-
let(:locale) { 'en' }
|
17
|
-
let(:site) { instance_double('Site', default_locale: 'en') }
|
18
|
-
|
19
17
|
subject do
|
20
18
|
middleware.call env_for('http://www.example.com', { 'steam.page' => nil, 'steam.locale' => locale, 'steam.site' => site })
|
21
19
|
end
|
@@ -40,4 +38,64 @@ describe Locomotive::Steam::Middlewares::Renderer do
|
|
40
38
|
|
41
39
|
end
|
42
40
|
|
41
|
+
describe 'rewriting of the asset urls' do
|
42
|
+
|
43
|
+
let(:env) {
|
44
|
+
env_for('http://www.example.com', {
|
45
|
+
'steam.page' => instance_double('Page', redirect?: false, not_found?: false, response_type: 'text/html'),
|
46
|
+
'steam.locale' => locale,
|
47
|
+
'steam.site' => site
|
48
|
+
})
|
49
|
+
}
|
50
|
+
let(:site) { instance_double('Site', default_locale: 'en', asset_host: asset_host) }
|
51
|
+
let(:content) { <<-HTML
|
52
|
+
<html>
|
53
|
+
<meta content="https://cdn.locomotive.works/sites/42/theme/images/logo.png" property='og:image' />
|
54
|
+
<script src="/sites/42/theme/javascripts/application.css"></script>
|
55
|
+
<body>
|
56
|
+
<img src="https://cdn.locomotive.works/steam/dynamic/42/abc/banner.png" />
|
57
|
+
<a href='https://cdn.locomotive.works/sites/42/pages/1/assets/brochure.pdf'>My brochure</a>
|
58
|
+
<p>https://cdn.locomotive.works/steam/dynamic/42/abc/banner.png</p>
|
59
|
+
</body>
|
60
|
+
</html>
|
61
|
+
HTML
|
62
|
+
}
|
63
|
+
|
64
|
+
before { allow_any_instance_of(described_class).to receive(:parse_and_render_liquid).and_return(content) }
|
65
|
+
|
66
|
+
subject { _, _, response = middleware.call(env); response.first }
|
67
|
+
|
68
|
+
context 'no asset host defined by the site' do
|
69
|
+
|
70
|
+
let(:asset_host) { nil }
|
71
|
+
|
72
|
+
it "doesn't rewrite the asset urls" do
|
73
|
+
is_expected.to eq(content)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'the site owns a custom asset host' do
|
79
|
+
|
80
|
+
let(:asset_host) { 'https://cdn.mysite.dev' }
|
81
|
+
|
82
|
+
it 'rewrites the asset urls' do
|
83
|
+
is_expected.to eq(<<-HTML
|
84
|
+
<html>
|
85
|
+
<meta content="https://cdn.mysite.dev/sites/42/theme/images/logo.png" property='og:image' />
|
86
|
+
<script src="https://cdn.mysite.dev/sites/42/theme/javascripts/application.css"></script>
|
87
|
+
<body>
|
88
|
+
<img src="https://cdn.mysite.dev/steam/dynamic/42/abc/banner.png" />
|
89
|
+
<a href='https://cdn.mysite.dev/sites/42/pages/1/assets/brochure.pdf'>My brochure</a>
|
90
|
+
<p>https://cdn.locomotive.works/steam/dynamic/42/abc/banner.png</p>
|
91
|
+
</body>
|
92
|
+
</html>
|
93
|
+
HTML
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
43
101
|
end
|
@@ -23,7 +23,7 @@ describe Locomotive::Steam::Models::Pager do
|
|
23
23
|
it { is_expected.to eq ['MongoDB'] }
|
24
24
|
end
|
25
25
|
|
26
|
-
describe 'per_page is
|
26
|
+
describe 'per_page is greater than the number of total entries' do
|
27
27
|
let(:per_page) { 10 }
|
28
28
|
it { is_expected.to eq ['MongoDB', 'Rails', 'Liquid', 'Rack', 'Devise'] }
|
29
29
|
end
|
@@ -33,6 +33,16 @@ describe Locomotive::Steam::Models::Pager do
|
|
33
33
|
it { is_expected.to eq [] }
|
34
34
|
end
|
35
35
|
|
36
|
+
describe 'page is a negative number' do
|
37
|
+
let(:page) { -3 }
|
38
|
+
it { is_expected.to eq ['MongoDB', 'Rails'] }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'page is a string' do
|
42
|
+
let(:page) { ''.to_i }
|
43
|
+
it { is_expected.to eq ['MongoDB', 'Rails'] }
|
44
|
+
end
|
45
|
+
|
36
46
|
end
|
37
47
|
|
38
48
|
describe '#previous_page' do
|
@@ -5,7 +5,7 @@ describe Locomotive::Steam::SectionRepository do
|
|
5
5
|
|
6
6
|
#TODO: site_id should not be passed like this
|
7
7
|
#TODO: template_path should be shorter
|
8
|
-
let(:sections) { [{ name: 'Header', slug: 'header', site_id: 1, template_path: 'spec/fixtures/default/app/views/sections/header.liquid' }] }
|
8
|
+
let(:sections) { [{ name: 'Header', slug: 'header', site_id: 1, definition: {}, template_path: 'spec/fixtures/default/app/views/sections/header.liquid' }] }
|
9
9
|
let(:locale) { :en }
|
10
10
|
let(:site) { instance_double('Site', _id: 1, default_locale: :en, locales: [:en, :fr]) }
|
11
11
|
let(:adapter) { Locomotive::Steam::FilesystemAdapter.new(nil) }
|
@@ -24,6 +24,15 @@ describe Locomotive::Steam::ActionService do
|
|
24
24
|
|
25
25
|
it { is_expected.to eq 2.0 }
|
26
26
|
|
27
|
+
describe 'deal with dates (since EPOCH in milliseconds) from a param' do
|
28
|
+
|
29
|
+
let(:params) { { 'api' => { 'title' => 'Hello world', 'sent_at' => 1536598528930 } } }
|
30
|
+
let(:script) { "return params.api.sent_at;" }
|
31
|
+
|
32
|
+
it { is_expected.to eq 1536598528930 }
|
33
|
+
|
34
|
+
end
|
35
|
+
|
27
36
|
describe 'deal with exceptions' do
|
28
37
|
|
29
38
|
context 'wrong syntax' do
|
@@ -31,7 +40,7 @@ describe Locomotive::Steam::ActionService do
|
|
31
40
|
let(:script) { 'a +/ b * var;' }
|
32
41
|
|
33
42
|
it 'raises a meaningful exception' do
|
34
|
-
expect { subject }.to raise_error(Locomotive::Steam::ActionError, "
|
43
|
+
expect { subject }.to raise_error(Locomotive::Steam::ActionError, "Action error - unterminated regexp (line 2)")
|
35
44
|
end
|
36
45
|
|
37
46
|
end
|
@@ -41,7 +50,7 @@ describe Locomotive::Steam::ActionService do
|
|
41
50
|
let(:script) { 'a.b' }
|
42
51
|
|
43
52
|
it 'raises a meaningful exception' do
|
44
|
-
expect { subject }.to raise_error(Locomotive::Steam::ActionError, "identifier 'a' undefined")
|
53
|
+
expect { subject }.to raise_error(Locomotive::Steam::ActionError, "Action error - identifier 'a' undefined")
|
45
54
|
end
|
46
55
|
|
47
56
|
end
|
@@ -136,6 +145,17 @@ describe Locomotive::Steam::ActionService do
|
|
136
145
|
|
137
146
|
end
|
138
147
|
|
148
|
+
describe 'log' do
|
149
|
+
|
150
|
+
let(:script) { "log('Hello world!');" }
|
151
|
+
|
152
|
+
it 'should call the internal logger to output the log message' do
|
153
|
+
expect(Locomotive::Common::Logger).to receive(:info).with('Hello world!')
|
154
|
+
is_expected.to eq(nil)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
139
159
|
describe 'allEntries' do
|
140
160
|
|
141
161
|
let(:now) { Time.use_zone('America/Chicago') { Time.zone.local(2015, 'mar', 25, 10, 0) } }
|
@@ -241,7 +261,7 @@ describe Locomotive::Steam::ActionService do
|
|
241
261
|
|
242
262
|
it 'stops the rendering process and redirects the user to another page' do
|
243
263
|
expect(redirection_service).to receive(:redirect_to).with('about-us', nil).and_raise(Locomotive::Steam::RedirectionException.new('/about-us'))
|
244
|
-
expect { subject }.to raise_exception(Locomotive::Steam::RedirectionException, 'Redirect to /about-us')
|
264
|
+
expect { subject }.to raise_exception(Locomotive::Steam::RedirectionException, 'Redirect to /about-us (302)')
|
245
265
|
end
|
246
266
|
|
247
267
|
end
|
@@ -18,7 +18,7 @@ describe Locomotive::Steam::PageRedirectionService do
|
|
18
18
|
|
19
19
|
it 'raises an PageRedirectionException that will caught the appropriate middleware' do
|
20
20
|
expect(url_builder).to receive(:url_for).with(page, nil).and_return('/about-us')
|
21
|
-
expect { subject }.to raise_exception(Locomotive::Steam::RedirectionException, 'Redirect to /about-us')
|
21
|
+
expect { subject }.to raise_exception(Locomotive::Steam::RedirectionException, 'Redirect to /about-us (302)')
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'passing a locale' do
|
@@ -27,7 +27,7 @@ describe Locomotive::Steam::PageRedirectionService do
|
|
27
27
|
|
28
28
|
it 'raises an PageRedirectionException that will caught the appropriate middleware' do
|
29
29
|
expect(url_builder).to receive(:url_for).with(page, 'fr').and_return('/a-notre-sujet')
|
30
|
-
expect { subject }.to raise_exception(Locomotive::Steam::RedirectionException, 'Redirect to /a-notre-sujet')
|
30
|
+
expect { subject }.to raise_exception(Locomotive::Steam::RedirectionException, 'Redirect to /a-notre-sujet (302)')
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -4,7 +4,7 @@ describe Locomotive::Steam::RecaptchaService do
|
|
4
4
|
|
5
5
|
let(:api_url) { nil }
|
6
6
|
let(:secret) { 'asecretkey' }
|
7
|
-
let(:site) { instance_double('Site', metafields: { google: { recaptcha_api_url: api_url, recaptcha_secret
|
7
|
+
let(:site) { instance_double('Site', metafields: { google: { recaptcha_api_url: api_url, 'recaptcha_secret' => secret } }) }
|
8
8
|
let(:request) { instance_double('Request', ip: '127.0.0.1') }
|
9
9
|
let(:service) { described_class.new(site, request) }
|
10
10
|
|