locomotivecms_steam 1.4.1 → 1.5.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +31 -25
- data/Rakefile +2 -2
- data/config/locales/pt-BR.yml +43 -13
- data/lib/locomotive/steam.rb +9 -4
- data/lib/locomotive/steam/adapters/filesystem.rb +2 -7
- data/lib/locomotive/steam/adapters/filesystem/sanitizer.rb +0 -2
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +11 -0
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +37 -0
- data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +18 -0
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +4 -3
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_type.rb +4 -3
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb +40 -0
- data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb +0 -1
- data/lib/locomotive/steam/adapters/memory.rb +1 -1
- data/lib/locomotive/steam/entities/content_entry.rb +15 -3
- data/lib/locomotive/steam/entities/content_type.rb +2 -1
- data/lib/locomotive/steam/entities/page.rb +21 -19
- data/lib/locomotive/steam/entities/section.rb +24 -0
- data/lib/locomotive/steam/entities/site.rb +3 -1
- data/lib/locomotive/steam/liquid.rb +2 -0
- data/lib/locomotive/steam/liquid/drops/page.rb +4 -2
- data/lib/locomotive/steam/liquid/drops/params.rb +51 -0
- data/lib/locomotive/steam/liquid/drops/section.rb +56 -0
- data/lib/locomotive/steam/liquid/drops/section_block.rb +47 -0
- data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +97 -0
- data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +65 -0
- data/lib/locomotive/steam/liquid/drops/site.rb +2 -1
- data/lib/locomotive/steam/liquid/errors.rb +2 -0
- data/lib/locomotive/steam/liquid/filters/base.rb +3 -3
- data/lib/locomotive/steam/liquid/filters/date.rb +1 -1
- data/lib/locomotive/steam/liquid/filters/html.rb +7 -2
- data/lib/locomotive/steam/liquid/filters/json.rb +3 -1
- data/lib/locomotive/steam/liquid/tags/action.rb +2 -2
- data/lib/locomotive/steam/liquid/tags/alt_page_links.rb +63 -0
- data/lib/locomotive/steam/liquid/tags/concerns/i18n_page.rb +1 -1
- data/lib/locomotive/steam/liquid/tags/concerns/section.rb +117 -0
- data/lib/locomotive/steam/liquid/tags/global_section.rb +32 -0
- data/lib/locomotive/steam/liquid/tags/model_form.rb +1 -1
- data/lib/locomotive/steam/liquid/tags/section.rb +87 -0
- data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +56 -0
- data/lib/locomotive/steam/liquid/tags/snippet.rb +3 -2
- data/lib/locomotive/steam/liquid/template.rb +0 -5
- data/lib/locomotive/steam/middlewares.rb +1 -1
- data/lib/locomotive/steam/middlewares/auth.rb +29 -13
- data/lib/locomotive/steam/middlewares/concerns/helpers.rb +59 -0
- data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +94 -0
- data/lib/locomotive/steam/middlewares/encoded_link_redirection.rb +45 -0
- data/lib/locomotive/steam/middlewares/entry_submission.rb +1 -1
- data/lib/locomotive/steam/middlewares/favicon.rb +1 -1
- data/lib/locomotive/steam/middlewares/locale.rb +63 -15
- data/lib/locomotive/steam/middlewares/locale_redirection.rb +18 -6
- data/lib/locomotive/steam/middlewares/logging.rb +1 -1
- data/lib/locomotive/steam/middlewares/page.rb +35 -6
- data/lib/locomotive/steam/middlewares/path.rb +1 -1
- data/lib/locomotive/steam/middlewares/private_access.rb +1 -1
- data/lib/locomotive/steam/middlewares/redirection.rb +1 -1
- data/lib/locomotive/steam/middlewares/renderer.rb +2 -82
- data/lib/locomotive/steam/middlewares/robots.rb +1 -1
- data/lib/locomotive/steam/middlewares/section.rb +56 -0
- data/lib/locomotive/steam/middlewares/site.rb +1 -1
- data/lib/locomotive/steam/middlewares/sitemap.rb +58 -45
- data/lib/locomotive/steam/middlewares/templatized_page.rb +1 -1
- data/lib/locomotive/steam/middlewares/thread_safe.rb +85 -2
- data/lib/locomotive/steam/middlewares/timezone.rb +1 -1
- data/lib/locomotive/steam/middlewares/url_redirection.rb +1 -1
- data/lib/locomotive/steam/models/entity.rb +0 -2
- data/lib/locomotive/steam/models/mapper.rb +5 -3
- data/lib/locomotive/steam/models/scope.rb +8 -0
- data/lib/locomotive/steam/repositories.rb +4 -0
- data/lib/locomotive/steam/repositories/content_entry_repository.rb +6 -2
- data/lib/locomotive/steam/repositories/page_repository.rb +4 -1
- data/lib/locomotive/steam/repositories/section_repository.rb +14 -0
- data/lib/locomotive/steam/repositories/site_repository.rb +1 -1
- data/lib/locomotive/steam/repositories/snippet_repository.rb +0 -3
- data/lib/locomotive/steam/server.rb +3 -1
- data/lib/locomotive/steam/services.rb +17 -1
- data/lib/locomotive/steam/services/action_service.rb +10 -0
- data/lib/locomotive/steam/services/concerns/decorator.rb +0 -2
- data/lib/locomotive/steam/services/image_resizer_service.rb +1 -1
- data/lib/locomotive/steam/services/page_finder_service.rb +6 -0
- data/lib/locomotive/steam/services/section_finder_service.rb +17 -0
- data/lib/locomotive/steam/services/url_builder_service.rb +31 -17
- data/lib/locomotive/steam/services/url_finder_service.rb +87 -0
- data/lib/locomotive/steam/version.rb +2 -2
- data/locomotivecms_steam.gemspec +1 -1
- data/spec/fixtures/default/app/views/pages/tags/section.liquid.haml +11 -0
- data/spec/fixtures/default/app/views/sections/carousel.liquid +20 -0
- data/spec/fixtures/default/app/views/sections/footer.liquid +48 -0
- data/spec/fixtures/default/app/views/sections/header.liquid +54 -0
- data/spec/fixtures/default/config/deploy.yml +1 -1
- data/spec/fixtures/errors/section_bad_json_content.liquid +9 -0
- data/spec/fixtures/errors/section_bad_json_header.liquid +8 -0
- data/spec/fixtures/mongodb/locomotive_accounts.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_accounts.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_activities.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_activities.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_content_assets.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_content_assets.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_content_entries.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_content_entries.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_content_types.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_content_types.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_pages.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_pages.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_sections.bson +0 -0
- data/spec/fixtures/mongodb/{sessions.metadata.json → locomotive_sections.metadata.json} +1 -1
- data/spec/fixtures/mongodb/locomotive_sites.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_sites.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_snippets.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_snippets.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_theme_assets.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_theme_assets.metadata.json +1 -1
- data/spec/fixtures/mongodb/locomotive_translations.bson +0 -0
- data/spec/fixtures/mongodb/locomotive_translations.metadata.json +1 -1
- data/spec/integration/repositories/content_entry_repository_spec.rb +1 -1
- data/spec/integration/repositories/page_repository_spec.rb +1 -1
- data/spec/integration/repositories/theme_asset_repository_spec.rb +1 -1
- data/spec/integration/server/auth_spec.rb +0 -4
- data/spec/integration/server/basic_spec.rb +8 -0
- data/spec/integration/server/contact_form_spec.rb +15 -2
- data/spec/integration/server/sitemap_spec.rb +5 -3
- data/spec/integration/services/content_entry_service_spec.rb +1 -1
- data/spec/support/helpers.rb +3 -3
- data/spec/unit/adapters/filesystem/sanitizers/section_spec.rb +65 -0
- data/spec/unit/adapters/filesystem/sanitizers/site_spec.rb +28 -2
- data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +8 -4
- data/spec/unit/adapters/filesystem/yaml_loaders/content_type_spec.rb +2 -2
- data/spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +1 -1
- data/spec/unit/adapters/filesystem/yaml_loaders/section_spec.rb +27 -0
- data/spec/unit/entities/section_spec.rb +29 -0
- data/spec/unit/liquid/drops/params_spec.rb +38 -0
- data/spec/unit/liquid/drops/section_content_proxy_spec.rb +88 -0
- data/spec/unit/liquid/drops/section_spec.rb +26 -0
- data/spec/unit/liquid/filters/html_spec.rb +198 -170
- data/spec/unit/liquid/filters/json_spec.rb +7 -0
- data/spec/unit/liquid/tags/action_spec.rb +12 -2
- data/spec/unit/liquid/tags/alt_page_links_spec.rb +58 -0
- data/spec/unit/liquid/tags/global_section_spec.rb +130 -0
- data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
- data/spec/unit/liquid/tags/locale_switcher_spec.rb +1 -1
- data/spec/unit/liquid/tags/model_form_spec.rb +8 -0
- data/spec/unit/liquid/tags/path_to_spec.rb +26 -3
- data/spec/unit/liquid/tags/section_spec.rb +231 -0
- data/spec/unit/liquid/tags/sections_dropzone_spec.rb +107 -0
- data/spec/unit/middlewares/auth_spec.rb +9 -2
- data/spec/unit/middlewares/encoded_link_redirection_spec.rb +73 -0
- data/spec/unit/middlewares/entry_submission_spec.rb +1 -1
- data/spec/unit/middlewares/helpers_spec.rb +3 -64
- data/spec/unit/middlewares/locale_redirection_spec.rb +13 -2
- data/spec/unit/middlewares/locale_spec.rb +52 -10
- data/spec/unit/middlewares/page_spec.rb +57 -16
- data/spec/unit/middlewares/private_access_spec.rb +1 -1
- data/spec/unit/middlewares/redirection_spec.rb +1 -1
- data/spec/unit/middlewares/renderer_spec.rb +2 -1
- data/spec/unit/middlewares/section_spec.rb +70 -0
- data/spec/unit/middlewares/site_spec.rb +1 -1
- data/spec/unit/middlewares/sitemap_spec.rb +4 -42
- data/spec/unit/middlewares/url_redirection_spec.rb +1 -1
- data/spec/unit/repositories/content_entry_repository_spec.rb +13 -13
- data/spec/unit/repositories/section_repository_spec.rb +38 -0
- data/spec/unit/repositories/snippet_repository_spec.rb +0 -3
- data/spec/unit/services/action_service_spec.rb +19 -1
- data/spec/unit/services/asset_host_service_spec.rb +8 -0
- data/spec/unit/services/parent_finder_service_spec.rb +1 -2
- data/spec/unit/services/section_finder_service_spec.rb +28 -0
- data/spec/unit/services/url_builder_service_spec.rb +14 -4
- data/spec/unit/services/url_finder_service_spec.rb +100 -0
- data/spec/unit/services_spec.rb +34 -20
- metadata +72 -11
- data/lib/locomotive/steam/middlewares/helpers.rb +0 -140
- data/spec/fixtures/mongodb/sessions.bson +0 -0
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::Liquid::Tags::SectionsDropzone do
|
4
|
+
|
5
|
+
let(:services) { Locomotive::Steam::Services.build_instance(nil) }
|
6
|
+
let(:finder) { services.section_finder }
|
7
|
+
let(:source) { '{% sections_dropzone %}' }
|
8
|
+
let(:live_editing) { true }
|
9
|
+
let(:page) { liquid_instance_double('Page', sections_dropzone_content: content) }
|
10
|
+
let(:assigns) { { 'page' => page } }
|
11
|
+
let(:registers) { { services: services, live_editing: live_editing } }
|
12
|
+
let(:context) { ::Liquid::Context.new(assigns, {}, registers) }
|
13
|
+
|
14
|
+
describe 'rendering' do
|
15
|
+
|
16
|
+
subject { render_template(source, context) }
|
17
|
+
|
18
|
+
context 'no sections' do
|
19
|
+
|
20
|
+
let(:content) { [] }
|
21
|
+
|
22
|
+
it 'renders an empty string' do
|
23
|
+
is_expected.to eq '<div class="locomotive-sections"></div>'
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with sections' do
|
29
|
+
|
30
|
+
let(:content) { [
|
31
|
+
{
|
32
|
+
type: 'hero',
|
33
|
+
settings: { title: 'Hello world' },
|
34
|
+
blocks: []
|
35
|
+
}.deep_stringify_keys,
|
36
|
+
{
|
37
|
+
type: 'slideshow',
|
38
|
+
settings: {},
|
39
|
+
blocks: [{ settings: { title: 'Slide 1' } }, { settings: { title: 'Slide 2' } }]
|
40
|
+
}.deep_stringify_keys
|
41
|
+
] }
|
42
|
+
|
43
|
+
let(:hero_source) { %(<h1>{{ section.settings.title }}</h1>) }
|
44
|
+
let(:slideshow_source) { %({% for block in section.blocks %}<div {{ block.locomotive_attributes }}><p>{{ block.settings.title }}</p></div>{% endfor %}) }
|
45
|
+
|
46
|
+
let(:hero_section) {
|
47
|
+
instance_double('Hero',
|
48
|
+
slug: 'hero',
|
49
|
+
type: 'hero',
|
50
|
+
definition: { settings: [{ id: 'title', type: 'text' }], blocks: [] }.deep_stringify_keys,
|
51
|
+
liquid_source: hero_source)
|
52
|
+
}
|
53
|
+
let(:slideshow_section) {
|
54
|
+
instance_double('Slideshow',
|
55
|
+
slug: 'slideshow',
|
56
|
+
type: 'slideshow',
|
57
|
+
definition: {
|
58
|
+
settings: [],
|
59
|
+
blocks: [{ settings: [{ id: 'title', type: 'text' }] }]
|
60
|
+
}.deep_stringify_keys,
|
61
|
+
liquid_source: slideshow_source) }
|
62
|
+
|
63
|
+
before do
|
64
|
+
allow(finder).to receive(:find).with('hero').and_return(hero_section)
|
65
|
+
allow(finder).to receive(:find).with('slideshow').and_return(slideshow_section)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'renders the list of sections' do
|
69
|
+
is_expected.to eq <<-HTML
|
70
|
+
<div class="locomotive-sections">
|
71
|
+
<div id="locomotive-section-dropzone-0" class="locomotive-section" data-locomotive-section-type="hero">
|
72
|
+
<h1 data-locomotive-editor-setting="section-dropzone-0.title">Hello world</h1>
|
73
|
+
</div>
|
74
|
+
<div id="locomotive-section-dropzone-1" class="locomotive-section" data-locomotive-section-type="slideshow">
|
75
|
+
<div data-locomotive-block="section-dropzone-1-block-0"><p data-locomotive-editor-setting="section-dropzone-1-block.0.title">Slide 1</p></div>
|
76
|
+
<div data-locomotive-block="section-dropzone-1-block-1"><p data-locomotive-editor-setting="section-dropzone-1-block.1.title">Slide 2</p></div>
|
77
|
+
</div>
|
78
|
+
</div>
|
79
|
+
HTML
|
80
|
+
.strip.gsub(/\n\s+/, '')
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'live editing is off' do
|
84
|
+
|
85
|
+
let(:live_editing) { false }
|
86
|
+
|
87
|
+
it 'renders the list of sections' do
|
88
|
+
is_expected.to eq <<-HTML
|
89
|
+
<div class="locomotive-sections">
|
90
|
+
<div id="locomotive-section-dropzone-0" class="locomotive-section" data-locomotive-section-type="hero">
|
91
|
+
<h1>Hello world</h1>
|
92
|
+
</div>
|
93
|
+
<div id="locomotive-section-dropzone-1" class="locomotive-section" data-locomotive-section-type="slideshow">
|
94
|
+
<div ><p>Slide 1</p></div>
|
95
|
+
<div ><p>Slide 2</p></div>
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
HTML
|
99
|
+
.strip.gsub(/\n\s+/, '')
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
|
-
require_relative '../../../lib/locomotive/steam/middlewares/helpers'
|
4
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
5
|
require_relative '../../../lib/locomotive/steam/middlewares/auth'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::Auth::AuthOptions do
|
@@ -16,7 +16,14 @@ describe Locomotive::Steam::Middlewares::Auth::AuthOptions do
|
|
16
16
|
|
17
17
|
subject { options.smtp }
|
18
18
|
|
19
|
-
it { is_expected.to eq(
|
19
|
+
it { is_expected.to eq(
|
20
|
+
address: '127.0.0.1',
|
21
|
+
user_name: 'John',
|
22
|
+
password: 'doe',
|
23
|
+
port: 25,
|
24
|
+
authentication: 'plain',
|
25
|
+
enable_starttls_auto: false,
|
26
|
+
) }
|
20
27
|
|
21
28
|
context 'no smtp metafields' do
|
22
29
|
|
@@ -0,0 +1,73 @@
|
|
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/encoded_link_redirection'
|
6
|
+
|
7
|
+
describe Locomotive::Steam::Middlewares::EncodedLinkRedirection do
|
8
|
+
|
9
|
+
let(:url_finder) { instance_double('UrlFinder') }
|
10
|
+
let(:services) { instance_double('Services', url_finder: url_finder) }
|
11
|
+
let(:site) { instance_double('Site') }
|
12
|
+
let(:url) { 'http://models.example.com' }
|
13
|
+
let(:mounted_on) { nil }
|
14
|
+
let(:locomotive_path) { nil }
|
15
|
+
let(:app) { ->(env) { [200, env, 'app'] } }
|
16
|
+
let(:middleware) { described_class.new(app) }
|
17
|
+
|
18
|
+
subject do
|
19
|
+
env = env_for(url, 'PATH_INFO' => locomotive_path, 'steam.site' => site)
|
20
|
+
env['steam.request'] = Rack::Request.new(env)
|
21
|
+
env['steam.mounted_on'] = mounted_on
|
22
|
+
env['steam.services'] = services
|
23
|
+
env['locomotive.path'] = locomotive_path
|
24
|
+
code, env = middleware.call(env)
|
25
|
+
[code, env['Location']]
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'no redirections' do
|
29
|
+
|
30
|
+
it { is_expected.to eq [200, nil] }
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'valid encoded link' do
|
35
|
+
|
36
|
+
let(:encoded_link) { 'eyJ0eXBlIjoiX2V4dGVybmFsIiwidmFsdWUiOiJodHRwczovL3d3dy5ub2NvZmZlZS5mciIsImxhYmVsIjpbImV4dGVybmFsIiwiaHR0cHM6Ly93d3cubm9jb2ZmZWUuZnIiXX0' }
|
37
|
+
let(:locomotive_path) { "/_locomotive-link/#{encoded_link}" }
|
38
|
+
|
39
|
+
context 'external url' do
|
40
|
+
|
41
|
+
it 'redirects (302) to the url stored in the encoded link' do
|
42
|
+
expect(url_finder).to receive(:decode_link).with('eyJ0eXBlIjoiX2V4dGVybmFsIiwidmFsdWUiOiJodHRwczovL3d3dy5ub2NvZmZlZS5mciIsImxhYmVsIjpbImV4dGVybmFsIiwiaHR0cHM6Ly93d3cubm9jb2ZmZWUuZnIiXX0').and_return({
|
43
|
+
'type' => 'external',
|
44
|
+
'value' => 'https://www.nocoffee.fr',
|
45
|
+
'locale' => 'fr'
|
46
|
+
})
|
47
|
+
expect(services).to receive(:locale=).with('fr')
|
48
|
+
allow(url_finder).to receive(:url_for).and_return(['https://www.nocoffee.fr', false])
|
49
|
+
is_expected.to eq [302, 'https://www.nocoffee.fr']
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'local page' do
|
55
|
+
|
56
|
+
let(:mounted_on) { '/my_app' }
|
57
|
+
|
58
|
+
it 'redirects (302) to the page stored in the encoded link' do
|
59
|
+
expect(url_finder).to receive(:decode_link).with('eyJ0eXBlIjoiX2V4dGVybmFsIiwidmFsdWUiOiJodHRwczovL3d3dy5ub2NvZmZlZS5mciIsImxhYmVsIjpbImV4dGVybmFsIiwiaHR0cHM6Ly93d3cubm9jb2ZmZWUuZnIiXX0').and_return({
|
60
|
+
'type' => 'page',
|
61
|
+
'value' => '42',
|
62
|
+
'locale' => 'fr'
|
63
|
+
})
|
64
|
+
expect(services).to receive(:locale=).with('fr')
|
65
|
+
allow(url_finder).to receive(:url_for).and_return(['/about-us', false])
|
66
|
+
is_expected.to eq [302, '/my_app/about-us']
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
|
-
require_relative '../../../lib/locomotive/steam/middlewares/helpers'
|
4
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
5
|
require_relative '../../../lib/locomotive/steam/middlewares/entry_submission'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::EntrySubmission do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
require_relative '../../../lib/locomotive/steam/middlewares/helpers'
|
3
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
4
4
|
|
5
|
-
describe Locomotive::Steam::Middlewares::Helpers do
|
5
|
+
describe Locomotive::Steam::Middlewares::Concerns::Helpers do
|
6
6
|
|
7
|
-
let(:middleware) { Class.new { include Locomotive::Steam::Middlewares::Helpers } }
|
7
|
+
let(:middleware) { Class.new { include Locomotive::Steam::Middlewares::Concerns::Helpers } }
|
8
8
|
let(:instance) { middleware.new }
|
9
9
|
|
10
10
|
describe '#make_local_path' do
|
@@ -58,65 +58,4 @@ describe Locomotive::Steam::Middlewares::Helpers do
|
|
58
58
|
|
59
59
|
end
|
60
60
|
|
61
|
-
describe '#params' do
|
62
|
-
|
63
|
-
let(:url) { 'http://models.example.com' }
|
64
|
-
let(:app) { ->(env) { [200, env, 'app'] } }
|
65
|
-
let(:options) { {} }
|
66
|
-
|
67
|
-
before do
|
68
|
-
env = env_for(url, options)
|
69
|
-
env['steam.request'] = Rack::Request.new(env)
|
70
|
-
allow(instance).to receive(:app).and_return(app)
|
71
|
-
allow(instance).to receive(:env).and_return(env)
|
72
|
-
end
|
73
|
-
|
74
|
-
subject { instance.params }
|
75
|
-
|
76
|
-
context 'from a GET' do
|
77
|
-
|
78
|
-
let(:url) { 'http://models.example.com?foo=bar' }
|
79
|
-
|
80
|
-
it { is_expected.to eq('foo' => 'bar') }
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'from a GET (JSON)' do
|
85
|
-
|
86
|
-
let(:url) { 'http://models.example.com/api.json?foo=bar' }
|
87
|
-
|
88
|
-
it { is_expected.to eq('foo' => 'bar') }
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'from the body of JSON POST request' do
|
93
|
-
|
94
|
-
let(:input) { '{"foo": { "bar": 42 } }' }
|
95
|
-
|
96
|
-
let(:options) { {
|
97
|
-
method: 'POST',
|
98
|
-
input: input,
|
99
|
-
'CONTENT_TYPE' => 'application/json'
|
100
|
-
} }
|
101
|
-
|
102
|
-
it { is_expected.to eq('foo' => { 'bar' => 42 }) }
|
103
|
-
|
104
|
-
it 'builds a hash with indifferent access' do
|
105
|
-
expect(subject[:foo][:bar]).to eq 42
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'the JSON is invalid' do
|
109
|
-
|
110
|
-
let(:input) { '{ a: 2 }' }
|
111
|
-
|
112
|
-
it 'returns an empty hash' do
|
113
|
-
is_expected.to eq({})
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
61
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
|
-
require_relative '../../../lib/locomotive/steam/middlewares/helpers'
|
4
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
5
|
require_relative '../../../lib/locomotive/steam/middlewares/locale_redirection'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::LocaleRedirection do
|
@@ -32,6 +32,17 @@ describe Locomotive::Steam::Middlewares::LocaleRedirection do
|
|
32
32
|
let(:locale_in_path) { false }
|
33
33
|
it { is_expected.to eq [200, nil] }
|
34
34
|
|
35
|
+
context 'the lang elected is not the default lang' do
|
36
|
+
let(:locale) { 'fr' }
|
37
|
+
it { is_expected.to eq [302, '/fr'] }
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'locale is part of the path' do
|
43
|
+
let(:url) { 'http://models.example.com/fr' }
|
44
|
+
let(:locale) { 'fr' }
|
45
|
+
it { is_expected.to eq [200, nil] }
|
35
46
|
end
|
36
47
|
|
37
48
|
describe 'for seo purpose redirect to the path without the locale' do
|
@@ -53,7 +64,7 @@ describe Locomotive::Steam::Middlewares::LocaleRedirection do
|
|
53
64
|
|
54
65
|
describe 'add default locale to root path' do
|
55
66
|
let(:url) { 'http://models.example.com/' }
|
56
|
-
it { is_expected.to eq [
|
67
|
+
it { is_expected.to eq [302, '/de'] }
|
57
68
|
end
|
58
69
|
|
59
70
|
describe 'add default locale to long path' do
|
@@ -1,23 +1,67 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
|
-
require_relative '../../../lib/locomotive/steam/middlewares/helpers'
|
4
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
5
|
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:
|
9
|
+
let(:site) { instance_double('Site', 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(:services) { instance_double('Services', :locale= => 'en') }
|
13
13
|
let(:middleware) { Locomotive::Steam::Middlewares::Locale.new(app) }
|
14
|
+
let(:session) { {} }
|
15
|
+
let(:accept_language) { '' }
|
14
16
|
|
15
17
|
subject do
|
16
|
-
env = env_for(
|
18
|
+
env = env_for(
|
19
|
+
url,
|
20
|
+
'steam.site' => site,
|
21
|
+
'rack.session' => session,
|
22
|
+
'HTTP_ACCEPT_LANGUAGE' => accept_language)
|
17
23
|
env['steam.request'] = Rack::Request.new(env)
|
18
24
|
env['steam.services'] = services
|
19
25
|
code, env = middleware.call(env)
|
20
|
-
env['steam.locale']
|
26
|
+
[env['steam.locale'], session['steam-locale']&.to_sym]
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'no locale defined in the path' do
|
30
|
+
|
31
|
+
describe 'first connexion' do
|
32
|
+
|
33
|
+
context 'without accept-language header' do
|
34
|
+
|
35
|
+
it { is_expected.to eq [:de, :de] }
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with accept-language header' do
|
40
|
+
|
41
|
+
let(:accept_language) { 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7' }
|
42
|
+
|
43
|
+
it { is_expected.to eq [:fr, :fr] }
|
44
|
+
|
45
|
+
context 'with url path' do
|
46
|
+
|
47
|
+
let(:url) { 'http://models.example.com/werkzeug' }
|
48
|
+
|
49
|
+
it { is_expected.to eq [:de, :de] }
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'user with session, use it' do
|
58
|
+
|
59
|
+
let(:session) { {'steam-locale' => 'en'} }
|
60
|
+
|
61
|
+
it { is_expected.to eq [:en, :en] }
|
62
|
+
|
63
|
+
end
|
64
|
+
|
21
65
|
end
|
22
66
|
|
23
67
|
describe 'locale asked in the request params' do
|
@@ -26,15 +70,15 @@ describe Locomotive::Steam::Middlewares::Locale do
|
|
26
70
|
|
27
71
|
let(:url) { 'http://models.example.com?locale=' }
|
28
72
|
|
29
|
-
it { is_expected.to eq :de }
|
73
|
+
it { is_expected.to eq [:de, :de] }
|
30
74
|
|
31
75
|
end
|
32
76
|
|
33
77
|
context 'the locale exists' do
|
34
78
|
|
35
|
-
let(:url) { 'http://models.example.com?locale=
|
79
|
+
let(:url) { 'http://models.example.com?locale=en' }
|
36
80
|
|
37
|
-
it { is_expected.to eq
|
81
|
+
it { is_expected.to eq [:en, :en] }
|
38
82
|
|
39
83
|
end
|
40
84
|
|
@@ -42,11 +86,9 @@ describe Locomotive::Steam::Middlewares::Locale do
|
|
42
86
|
|
43
87
|
let(:url) { 'http://models.example.com?locale=onload' }
|
44
88
|
|
45
|
-
it { is_expected.to eq :de }
|
89
|
+
it { is_expected.to eq [:de, :de] }
|
46
90
|
|
47
91
|
end
|
48
92
|
|
49
|
-
|
50
93
|
end
|
51
|
-
|
52
94
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
require_relative '../../../lib/locomotive/steam/middlewares/thread_safe'
|
4
|
-
require_relative '../../../lib/locomotive/steam/middlewares/helpers'
|
4
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/helpers'
|
5
5
|
require_relative '../../../lib/locomotive/steam/middlewares/page'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::Page do
|
@@ -11,20 +11,22 @@ describe Locomotive::Steam::Middlewares::Page do
|
|
11
11
|
let(:page_not_found) { instance_double('PageNotFound', not_found?: true) }
|
12
12
|
let(:page) { instance_double('Page', title: 'Hello world', fullpath: 'hello-world', not_found?: false, published?: published) }
|
13
13
|
let(:pages) { [page] }
|
14
|
-
let(:site) { instance_double('Site', default_locale: 'en') }
|
14
|
+
let(:site) { instance_double('Site', default_locale: 'en', routes: routes) }
|
15
15
|
let(:service) { instance_double('PageFinder', match: pages) }
|
16
|
+
let(:routes) { {} }
|
16
17
|
let(:url) { 'http://models.example.com' }
|
18
|
+
let(:path) { 'hello-world' }
|
17
19
|
let(:app) { ->(env) { [200, env, 'app'] } }
|
18
20
|
let(:middleware) { described_class.new(app) }
|
19
21
|
|
20
22
|
subject do
|
21
23
|
env = env_for(url, 'steam.site' => site)
|
22
|
-
env['steam.path'] =
|
24
|
+
env['steam.path'] = path
|
23
25
|
env['steam.locale'] = 'en'
|
24
|
-
env['steam.request'] = Rack::Request.new(env)
|
25
26
|
env['steam.live_editing'] = live_editing
|
27
|
+
env['steam.request'] = Rack::Request.new(env)
|
26
28
|
code, env = middleware.call(env)
|
27
|
-
env['steam.page']
|
29
|
+
[env['steam.page'], env['steam.request'].params]
|
28
30
|
end
|
29
31
|
|
30
32
|
before do
|
@@ -32,28 +34,67 @@ describe Locomotive::Steam::Middlewares::Page do
|
|
32
34
|
allow(service).to receive(:find).with('404').and_return(page_not_found)
|
33
35
|
end
|
34
36
|
|
35
|
-
|
37
|
+
describe 'named route' do
|
38
|
+
|
39
|
+
let(:path) { 'posts/2018/09' }
|
40
|
+
let(:routes) { [{ 'route' => '/posts/:year', 'page_handle' => 'posts' }, { 'route' => '/posts/:year/:month', 'page_handle' => 'posts' }] }
|
41
|
+
|
42
|
+
it 'returns the page based on the handle returned by the routing hash' do
|
43
|
+
expect(service).to receive(:by_handle).with('posts', false).and_return(page)
|
44
|
+
is_expected.to eq([page, { 'year' => '2018', 'month' => '09' }])
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'wrong route syntax' do
|
36
48
|
|
37
|
-
|
49
|
+
let(:routes) { [{ 'route' => '/posts/:_year/:month', 'page_handle' => 'posts' }] }
|
38
50
|
|
39
|
-
|
51
|
+
it "doesn't match the route" do
|
52
|
+
is_expected.to eq([page, {}])
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
40
56
|
|
41
|
-
|
57
|
+
describe 'path with a dash' do
|
58
|
+
|
59
|
+
let(:path) { 'resources/hello-world' }
|
60
|
+
let(:routes) { [{ 'route' => '/resources/:slug', 'page_handle' => 'resources' }] }
|
61
|
+
|
62
|
+
it 'returns the page based on the handle returned by the routing hash' do
|
63
|
+
expect(service).to receive(:by_handle).with('resources', false).and_return(page)
|
64
|
+
is_expected.to eq([page, { 'slug' => 'hello-world' }])
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
end
|
42
69
|
|
43
70
|
end
|
44
71
|
|
45
|
-
|
72
|
+
describe 'a page outside the site routes' do
|
73
|
+
|
74
|
+
it { is_expected.to eq([page, {}]) }
|
75
|
+
|
76
|
+
context "page doesn't exist" do
|
77
|
+
|
78
|
+
let(:pages) { [] }
|
79
|
+
|
80
|
+
it { is_expected.to eq([page_not_found, {}]) }
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'page is unpublished' do
|
85
|
+
|
86
|
+
let(:published) { false }
|
46
87
|
|
47
|
-
|
88
|
+
it { is_expected.to eq([page_not_found, {}]) }
|
48
89
|
|
49
|
-
|
90
|
+
context 'the live editing mode is on' do
|
50
91
|
|
51
|
-
|
92
|
+
let(:live_editing) { true }
|
52
93
|
|
53
|
-
|
94
|
+
it 'has to display it' do
|
95
|
+
is_expected.to eq([page, {}])
|
96
|
+
end
|
54
97
|
|
55
|
-
it 'has to display it' do
|
56
|
-
is_expected.to eq page
|
57
98
|
end
|
58
99
|
|
59
100
|
end
|