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
@@ -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/private_access'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::PrivateAccess do
|
@@ -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/redirection'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::Redirection do
|
@@ -1,7 +1,8 @@
|
|
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
|
+
require_relative '../../../lib/locomotive/steam/middlewares/concerns/liquid_context'
|
5
6
|
require_relative '../../../lib/locomotive/steam/middlewares/renderer'
|
6
7
|
|
7
8
|
describe Locomotive::Steam::Middlewares::Renderer do
|
@@ -0,0 +1,70 @@
|
|
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/section'
|
7
|
+
|
8
|
+
describe Locomotive::Steam::Middlewares::Section do
|
9
|
+
|
10
|
+
let(:app) { ->(env) { [200, env, 'app'] }}
|
11
|
+
let(:url) { 'http://example.com/foo/bar' }
|
12
|
+
let(:env) { env_for(url, 'steam.site' => site) }
|
13
|
+
|
14
|
+
let(:site_drop) { liquid_instance_double('SiteDrop', sections_content: { 'header' => { 'settings' => { 'name' => 'this should not be rendered in middleware' } } }) }
|
15
|
+
let(:page_drop) { liquid_instance_double('PageDrop', sections_content: { 'header' => { 'settings' => { 'name' => 'this should not be rendered in middleware' } } }) }
|
16
|
+
let(:site) { instance_double('Site', default_locale: 'en', locales: ['en'], to_liquid: site_drop) }
|
17
|
+
let(:page) { instance_double('Page', default_locale: 'en', locales: ['en'], to_liquid: page_drop) }
|
18
|
+
let(:section) { instance_double('Section', type: 'header', definition: {}, liquid_source: 'Here some {{ section.settings.name }}') }
|
19
|
+
let(:section_finder) { instance_double('SectionFinderService') }
|
20
|
+
let(:repositories) { instance_double('Repositories')}
|
21
|
+
|
22
|
+
let(:services) { instance_double(
|
23
|
+
'Services',
|
24
|
+
section_finder: section_finder,
|
25
|
+
repositories: repositories,
|
26
|
+
locale: 'en')
|
27
|
+
}
|
28
|
+
|
29
|
+
before do
|
30
|
+
env['steam.page'] = page
|
31
|
+
env['steam.services'] = services
|
32
|
+
env['steam.locale'] = :en
|
33
|
+
env['steam.liquid_assigns'] = {}
|
34
|
+
env['steam.request'] = Rack::Request.new(env)
|
35
|
+
env['steam.request'].add_header('HTTP_LOCOMOTIVE_SECTION_TYPE', 'header')
|
36
|
+
allow(section_finder).to receive(:find).with('header').and_return(section)
|
37
|
+
end
|
38
|
+
|
39
|
+
subject do
|
40
|
+
middleware = described_class.new(app)
|
41
|
+
middleware.call(env)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'renders the HTML code related to the section' do
|
45
|
+
is_expected.to eq [
|
46
|
+
200,
|
47
|
+
{ "Content-Type" => "text/html" },
|
48
|
+
[%(<div id="locomotive-section-page-header" class="locomotive-section" data-locomotive-section-type="header">Here some </div>)]
|
49
|
+
]
|
50
|
+
end
|
51
|
+
|
52
|
+
context "the content of the section is in the request body" do
|
53
|
+
|
54
|
+
before do
|
55
|
+
allow(env['steam.request']).to receive(:body).and_return(StringIO.new(
|
56
|
+
%({ "section_content": { "id": "site-header", "settings": { "name": "modified HTML" } } })
|
57
|
+
))
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'renders the HTML code related to the section' do
|
61
|
+
is_expected.to eq [
|
62
|
+
200,
|
63
|
+
{ "Content-Type" => "text/html" },
|
64
|
+
[%(<div id="locomotive-section-site-header" class="locomotive-section" data-locomotive-section-type="header">Here some modified HTML</div>)]
|
65
|
+
]
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
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/site'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::Site do
|
@@ -1,14 +1,14 @@
|
|
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/sitemap'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::Sitemap do
|
8
8
|
|
9
9
|
let(:site) { instance_double('Site', locales: ['en', 'fr'], default_locale: 'en') }
|
10
10
|
let(:pages) { [] }
|
11
|
-
let(:page_repository) { instance_double('PageRepository', published: pages) }
|
11
|
+
let(:page_repository) { instance_double('PageRepository', published: pages, :locale= => 'en') }
|
12
12
|
let(:app) { ->(env) { [200, env, 'app'] }}
|
13
13
|
let(:middleware) { described_class.new(app) }
|
14
14
|
|
@@ -26,7 +26,7 @@ describe Locomotive::Steam::Middlewares::Sitemap do
|
|
26
26
|
describe 'no pages' do
|
27
27
|
|
28
28
|
it 'renders a blank sitemap' do
|
29
|
-
is_expected.to eq [200, { "Content-Type"=>"text/plain" }, ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
|
29
|
+
is_expected.to eq [200, { "Content-Type"=>"text/plain" }, ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n\n</urlset>\n"]]
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -36,45 +36,7 @@ describe Locomotive::Steam::Middlewares::Sitemap do
|
|
36
36
|
let(:pages) { [instance_double('Page', index?: false, not_found?: false, layout?: true)] }
|
37
37
|
|
38
38
|
it 'renders a blank sitemap' do
|
39
|
-
is_expected.to eq [200, { "Content-Type"=>"text/plain" }, ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#build_templatized_page_xml?' do
|
45
|
-
|
46
|
-
let(:localized) { true }
|
47
|
-
let(:source) { '<h1>{{ post.title }}</h1>' }
|
48
|
-
let(:page) { instance_double('TemplatePage', source: source) }
|
49
|
-
let(:content_type) { instance_double('Post', localized?: localized) }
|
50
|
-
let(:locale) { 'fr' }
|
51
|
-
|
52
|
-
subject { middleware.send(:build_templatized_page_xml?, page, content_type, locale) }
|
53
|
-
|
54
|
-
it { is_expected.to eq true }
|
55
|
-
|
56
|
-
context 'current locale is equals to the site default locale' do
|
57
|
-
|
58
|
-
let(:locale) { 'en' }
|
59
|
-
|
60
|
-
it { is_expected.to eq true }
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'the content type is not localized' do
|
65
|
-
|
66
|
-
let(:localized) { false }
|
67
|
-
|
68
|
-
it { is_expected.to eq true }
|
69
|
-
|
70
|
-
context 'the page has the same liquid template in all the locales' do
|
71
|
-
|
72
|
-
let(:source) { '' }
|
73
|
-
|
74
|
-
it { is_expected.to eq false }
|
75
|
-
|
76
|
-
end
|
77
|
-
|
39
|
+
is_expected.to eq [200, { "Content-Type"=>"text/plain" }, ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n\n</urlset>\n"]]
|
78
40
|
end
|
79
41
|
|
80
42
|
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/url_redirection'
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Middlewares::UrlRedirection do
|
@@ -240,35 +240,35 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
240
240
|
let(:fields) do
|
241
241
|
{
|
242
242
|
title: instance_double('TitleField', name: :title, type: :string),
|
243
|
-
category: instance_double('SelectField', name: :category, type: :select,
|
243
|
+
category: instance_double('SelectField', name: :category, type: :select, localized: true, select_options: [])
|
244
244
|
}
|
245
245
|
end
|
246
|
-
let(:type) { build_content_type('Articles', order_by: '_position asc', label_field_name: :title, localized_names: [:title, :
|
246
|
+
let(:type) { build_content_type('Articles', order_by: '_position asc', label_field_name: :title, localized_names: [:title, :category_id], fields: _fields, fields_by_name: fields, fields_with_default: []) }
|
247
247
|
let(:name) { :category }
|
248
248
|
|
249
249
|
let(:options) {
|
250
250
|
[
|
251
|
-
instance_double('SelectOption1', name: 'cooking'),
|
252
|
-
instance_double('SelectOption2', name: 'wine'),
|
253
|
-
instance_double('SelectOption3', name: 'bread')
|
251
|
+
instance_double('SelectOption1', _id: 0, name: instance_double('I18nField', :[] => 'cooking', translations: { 'en' => 'cooking' })),
|
252
|
+
instance_double('SelectOption2', _id: 1, name: instance_double('I18nField', :[] => 'wine', translations: { 'en' => 'wine' })),
|
253
|
+
instance_double('SelectOption3', _id: 2, name: instance_double('I18nField', :[] => 'bread', translations: { 'en' => 'bread' }))
|
254
254
|
]
|
255
255
|
}
|
256
256
|
|
257
257
|
let(:entries) do
|
258
258
|
[
|
259
|
-
{ content_type_id: 1, _position: 0, _label: 'Recipe #1', category_id: '
|
260
|
-
{ content_type_id: 1, _position: 1, _label: 'Recipe #2', category_id: '
|
261
|
-
{ content_type_id: 1, _position: 2, _label: 'Recipe #3', category_id: '
|
262
|
-
{ content_type_id: 1, _position: 3, _label: 'Recipe #4', category_id: '
|
259
|
+
{ content_type_id: 1, _position: 0, _label: 'Recipe #1', category_id: { 'en' => 0 } },
|
260
|
+
{ content_type_id: 1, _position: 1, _label: 'Recipe #2', category_id: { 'en' => 2 } },
|
261
|
+
{ content_type_id: 1, _position: 2, _label: 'Recipe #3', category_id: { 'en' => 2 } },
|
262
|
+
{ content_type_id: 1, _position: 3, _label: 'Recipe #4', category_id: { 'en' => 42 } } # unknown category
|
263
263
|
]
|
264
264
|
end
|
265
265
|
|
266
266
|
before {
|
267
267
|
allow(content_type_repository).to receive(:select_options).and_return(options)
|
268
|
-
%w(cooking wine bread).each_with_index do |name,
|
269
|
-
allow(fields[:category].select_options).to receive(:find).with(
|
268
|
+
%w(cooking wine bread).each_with_index do |name, position|
|
269
|
+
allow(fields[:category].select_options).to receive(:find).with(position).and_return(options.at(position))
|
270
270
|
end
|
271
|
-
allow(fields[:category].select_options).to receive(:find).with(
|
271
|
+
allow(fields[:category].select_options).to receive(:find).with(42).and_return(nil)
|
272
272
|
}
|
273
273
|
|
274
274
|
it { expect(subject.size).to eq 4 }
|
@@ -384,7 +384,7 @@ describe Locomotive::Steam::ContentEntryRepository do
|
|
384
384
|
|
385
385
|
let(:value) { 'CMS' }
|
386
386
|
let(:option) { instance_double('Option', _id: 42)}
|
387
|
-
let(:options) { instance_double('OptionRepository', by_name: option) }
|
387
|
+
let(:options) { instance_double('OptionRepository', by_name: option, :'locale=' => nil) }
|
388
388
|
let(:field) { instance_double('SelectField', name: 'category', persisted_name: 'category_id', select_options: options) }
|
389
389
|
let(:_fields) { instance_double('Fields', selects: [field], belongs_to: [], many_to_many: [], dates_and_date_times: []) }
|
390
390
|
let(:conditions) { { 'category' => value } }
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../../lib/locomotive/steam/adapters/filesystem.rb'
|
3
|
+
|
4
|
+
describe Locomotive::Steam::SectionRepository do
|
5
|
+
|
6
|
+
#TODO: site_id should not be passed like this
|
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' }] }
|
9
|
+
let(:locale) { :en }
|
10
|
+
let(:site) { instance_double('Site', _id: 1, default_locale: :en, locales: [:en, :fr]) }
|
11
|
+
let(:adapter) { Locomotive::Steam::FilesystemAdapter.new(nil) }
|
12
|
+
let(:repository) { described_class.new(adapter, site, locale) }
|
13
|
+
|
14
|
+
before do
|
15
|
+
allow(adapter).to receive(:collection).and_return(sections)
|
16
|
+
adapter.cache = NoCacheStore.new
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#by_slug' do
|
20
|
+
|
21
|
+
let(:name) { nil }
|
22
|
+
subject { repository.by_slug(name) }
|
23
|
+
|
24
|
+
it { is_expected.to eq nil }
|
25
|
+
|
26
|
+
context 'existing section' do
|
27
|
+
|
28
|
+
let(:name) { 'header' }
|
29
|
+
subject { repository.by_slug(name) }
|
30
|
+
it { expect(subject).to_not be_nil }
|
31
|
+
it { expect(subject.class).to eq Locomotive::Steam::Section }
|
32
|
+
it { expect(subject.name).to eq 'Header' }
|
33
|
+
it { expect(subject[:template_path]).to eq 'spec/fixtures/default/app/views/sections/header.liquid' }
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
3
2
|
require_relative '../../../lib/locomotive/steam/adapters/filesystem.rb'
|
4
3
|
|
5
4
|
describe Locomotive::Steam::SnippetRepository do
|
@@ -31,7 +30,5 @@ describe Locomotive::Steam::SnippetRepository do
|
|
31
30
|
it { expect(subject[:template_path][:fr]).to eq 'simple.yml' }
|
32
31
|
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
|
-
|
37
34
|
end
|
@@ -16,7 +16,8 @@ describe Locomotive::Steam::ActionService do
|
|
16
16
|
let(:params) { {} }
|
17
17
|
let(:assigns) { {} }
|
18
18
|
let(:session) { {} }
|
19
|
-
let(:
|
19
|
+
let(:cookies) { {} }
|
20
|
+
let(:context) { ::Liquid::Context.new(assigns, {}, { session: session, cookies: cookies }) }
|
20
21
|
|
21
22
|
subject { service.run(script, params, context) }
|
22
23
|
|
@@ -112,6 +113,23 @@ describe Locomotive::Steam::ActionService do
|
|
112
113
|
|
113
114
|
end
|
114
115
|
|
116
|
+
describe 'getCookiesProp' do
|
117
|
+
|
118
|
+
let(:cookies) { { 'name' => 'John' } }
|
119
|
+
let(:script) { "return getCookiesProp('name');" }
|
120
|
+
|
121
|
+
it { is_expected.to eq 'John' }
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'sendCookiesProp' do
|
126
|
+
|
127
|
+
let(:script) { "return setCookiesProp('done', true);" }
|
128
|
+
|
129
|
+
it { subject; expect(cookies['done']).to eq 'true' }
|
130
|
+
|
131
|
+
end
|
132
|
+
|
115
133
|
describe 'allEntries' do
|
116
134
|
|
117
135
|
let(:now) { Time.use_zone('America/Chicago') { Time.zone.local(2015, 'mar', 25, 10, 0) } }
|
@@ -66,6 +66,14 @@ describe Locomotive::Steam::AssetHostService do
|
|
66
66
|
|
67
67
|
end
|
68
68
|
|
69
|
+
describe 'but without a trailing /' do
|
70
|
+
|
71
|
+
let(:host) { 'https://storage.googleapis.com/locomotive-station' }
|
72
|
+
let(:source) { '/sites/42/assets/1/banner.png' }
|
73
|
+
it { is_expected.to eq 'https://storage.googleapis.com/sites/42/assets/1/banner.png' }
|
74
|
+
|
75
|
+
end
|
76
|
+
|
69
77
|
end
|
70
78
|
|
71
79
|
describe 'the host is a string' do
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::SectionFinderService do
|
4
|
+
|
5
|
+
let(:repository) { instance_double('SectionRepository') }
|
6
|
+
let(:site) { instance_double('Site', _id: 1, default_locale: :en, locales: [:en, :fr]) }
|
7
|
+
let(:section) { instance_double('Section') }
|
8
|
+
let(:slug) { 'header' }
|
9
|
+
|
10
|
+
let(:finder) { described_class.new(repository) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(repository).to receive(:by_slug).and_return(section)
|
14
|
+
allow(repository).to receive(:locale).and_return(:en)
|
15
|
+
allow(repository).to receive(:site).and_return(site)
|
16
|
+
allow(section).to receive(:localized_attributes).and_return(nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#find' do
|
20
|
+
|
21
|
+
subject { finder.find(slug) }
|
22
|
+
|
23
|
+
it { is_expected.to eq(section) }
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -4,16 +4,16 @@ describe Locomotive::Steam::UrlBuilderService do
|
|
4
4
|
|
5
5
|
let(:prefix_default) { false }
|
6
6
|
let(:mounted_on) { nil }
|
7
|
-
let(:request) { instance_double('Request', env: { 'steam.mounted_on' => mounted_on }) }
|
8
7
|
let(:site) { instance_double('Site', default_locale: 'en', prefix_default_locale: prefix_default) }
|
9
|
-
let(:
|
10
|
-
let(:
|
8
|
+
let(:current_locale) { 'en' }
|
9
|
+
let(:locale) { nil }
|
10
|
+
let(:service) { described_class.new(site, current_locale, mounted_on) }
|
11
11
|
|
12
12
|
describe '#url_for' do
|
13
13
|
|
14
14
|
let(:page) { instance_double('AboutUs', fullpath: 'about-us', templatized?: false) }
|
15
15
|
|
16
|
-
subject { service.url_for(page) }
|
16
|
+
subject { service.url_for(page, locale) }
|
17
17
|
|
18
18
|
it { is_expected.to eq '/about-us' }
|
19
19
|
|
@@ -37,6 +37,16 @@ describe Locomotive::Steam::UrlBuilderService do
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
+
describe 'asking for the index page url in the defaut locale when the current locale is different from the default one' do
|
41
|
+
|
42
|
+
let(:current_locale) { 'fr' }
|
43
|
+
let(:locale) { 'en' }
|
44
|
+
let(:page) { instance_double('index', fullpath: 'index', templatized?: false) }
|
45
|
+
|
46
|
+
it { is_expected.to eq '/en' }
|
47
|
+
|
48
|
+
end
|
49
|
+
|
40
50
|
describe 'no need to put the index slug' do
|
41
51
|
|
42
52
|
let(:page) { instance_double('Index', fullpath: 'index', templatized?: false) }
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::UrlFinderService do
|
4
|
+
|
5
|
+
let(:url_builder) { instance_double('UrlBuilder') }
|
6
|
+
let(:page_finder) { instance_double('PageFinder') }
|
7
|
+
let(:content_entry_finder) { instance_double('ContentEntryFinder') }
|
8
|
+
let(:service) { described_class.new(url_builder, page_finder, content_entry_finder) }
|
9
|
+
|
10
|
+
describe '#url_for' do
|
11
|
+
|
12
|
+
subject { service.url_for(value) }
|
13
|
+
|
14
|
+
context 'value is an url' do
|
15
|
+
|
16
|
+
let(:value) { 'https://www.locomotivecms.com' }
|
17
|
+
it { is_expected.to eq(['https://www.locomotivecms.com', false]) }
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'value is a link to an external site' do
|
22
|
+
|
23
|
+
let(:value) { { 'type' => '_external', 'value' => 'https://www.locomotivecms.com', 'new_window' => true } }
|
24
|
+
it { is_expected.to eq(['https://www.locomotivecms.com', true]) }
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'value is a link to a page' do
|
29
|
+
|
30
|
+
let(:page) { instance_double('Page') }
|
31
|
+
let(:value) { { 'type' => 'page', 'value' => 42, 'new_window' => true } }
|
32
|
+
|
33
|
+
context 'the page exists' do
|
34
|
+
|
35
|
+
before do
|
36
|
+
expect(page_finder).to receive(:find_by_id).with(42).and_return(page)
|
37
|
+
expect(url_builder).to receive(:url_for).with(page).and_return('/')
|
38
|
+
end
|
39
|
+
|
40
|
+
it { is_expected.to eq(['/', true]) }
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
context "the page doesn't exist" do
|
45
|
+
|
46
|
+
before do
|
47
|
+
expect(page_finder).to receive(:find_by_id).with(42).and_return(nil)
|
48
|
+
expect(page_finder).to receive(:find).with('404').and_return(page)
|
49
|
+
expect(url_builder).to receive(:url_for).with(page).and_return('/404')
|
50
|
+
end
|
51
|
+
|
52
|
+
it { is_expected.to eq(['/404', true]) }
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'value is a link to a content entry' do
|
60
|
+
|
61
|
+
let(:entry) { instance_double('Product') }
|
62
|
+
let(:page) { instance_double('Page', :content_entry= => true) }
|
63
|
+
let(:value) { {
|
64
|
+
'type' => 'content_entry',
|
65
|
+
'value' => { 'page_id' => 42, 'content_type_slug' => 'products', 'id' => 1 },
|
66
|
+
'new_window' => true
|
67
|
+
} }
|
68
|
+
|
69
|
+
before do
|
70
|
+
expect(page_finder).to receive(:find_by_id).with(42).and_return(page)
|
71
|
+
expect(content_entry_finder).to receive(:find).with('products', 1).and_return(entry)
|
72
|
+
expect(url_builder).to receive(:url_for).with(page).and_return('/my-product')
|
73
|
+
end
|
74
|
+
|
75
|
+
it { is_expected.to eq(['/my-product', true]) }
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#decode_url_for' do
|
82
|
+
|
83
|
+
let(:value) { 'eyJ0eXBlIjoiX2V4dGVybmFsIiwidmFsdWUiOiJodHRwczovL3d3dy5ub2NvZmZlZS5mciIsImxhYmVsIjpbImV4dGVybmFsIiwiaHR0cHM6Ly93d3cubm9jb2ZmZWUuZnIiXX0=' }
|
84
|
+
subject { service.decode_url_for(value) }
|
85
|
+
|
86
|
+
it { is_expected.to eq(['https://www.nocoffee.fr', false]) }
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#decode_urls_for' do
|
91
|
+
|
92
|
+
let(:value) { 'eyJ0eXBlIjoiX2V4dGVybmFsIiwidmFsdWUiOiJodHRwczovL3d3dy5ub2NvZmZlZS5mciIsImxhYmVsIjpbImV4dGVybmFsIiwiaHR0cHM6Ly93d3cubm9jb2ZmZWUuZnIiXX0=' }
|
93
|
+
let(:text) { %(<a href="//locomotive/_locomotive-link/#{value}">My Link</a>) }
|
94
|
+
subject { service.decode_urls_for(text) }
|
95
|
+
|
96
|
+
it { is_expected.to eq('<a href="https://www.nocoffee.fr">My Link</a>') }
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|