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
@@ -6,60 +6,86 @@ require_relative '../../../../../lib/locomotive/steam/errors.rb'
|
|
6
6
|
|
7
7
|
describe Locomotive::Steam::Adapters::Filesystem::Sanitizers::Section do
|
8
8
|
|
9
|
-
let(:
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
|
14
|
-
|
15
|
-
before(:each) do
|
16
|
-
sanitizer.setup(scope);
|
17
|
-
end
|
9
|
+
let(:entity) { instance_double('SectionEntity', definition: definition) }
|
10
|
+
let(:site) { instance_double('Site', _id: 1) }
|
11
|
+
let(:scope) { instance_double('Scope', site: site) }
|
12
|
+
let(:sanitizer) { described_class.new }
|
13
|
+
|
14
|
+
before(:each) { sanitizer.setup(scope) }
|
18
15
|
|
19
16
|
describe '#apply_to_entity' do
|
17
|
+
|
18
|
+
before { expect(entity).to receive(:[]=).with(:site_id, 1) }
|
19
|
+
|
20
20
|
subject { sanitizer.apply_to_entity(entity) }
|
21
21
|
|
22
|
-
describe '
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
<ul>
|
29
|
-
{% for block in section.blocks %}
|
30
|
-
<li>
|
31
|
-
<a href="{{ block.settings.url }}" target="{% if block.settings.new_tab %}_blank{% endif %}">
|
32
|
-
{{ block.settings.label }}
|
33
|
-
</a>
|
34
|
-
</li>
|
35
|
-
{% endfor %}
|
36
|
-
</ul>
|
37
|
-
LIQUID
|
38
|
-
).gsub /^$\n/, '')
|
39
|
-
expect(entity).to receive(:[]=).with(:site_id, 1)
|
40
|
-
subject
|
22
|
+
describe 'aliases' do
|
23
|
+
|
24
|
+
let(:definition) { load_section_definition('carousel', :yaml) }
|
25
|
+
|
26
|
+
it 'allows to alias presets' do
|
27
|
+
expect(subject.definition).to match(hash_including({ 'presets' => [{ 'name' => 'Carousel', 'category' => 'Content', 'settings' => { 'brand' => 'Acme' }, 'blocks' => [] }] }))
|
41
28
|
end
|
29
|
+
|
42
30
|
end
|
43
|
-
describe 'errors' do
|
44
|
-
before(:each) do
|
45
|
-
allow(entity).to receive(:[]=)
|
46
|
-
end
|
47
31
|
|
48
|
-
|
49
|
-
|
32
|
+
describe 'fill_presets / set_default_values' do
|
33
|
+
|
34
|
+
context 'global content (global section)' do
|
35
|
+
|
36
|
+
let(:definition) { load_section_definition('footer') }
|
50
37
|
|
51
|
-
it '
|
52
|
-
expect
|
38
|
+
it 'allows to alias default' do
|
39
|
+
expect(subject.definition).to match(hash_including({ 'default' =>
|
40
|
+
{ 'settings' => { 'brand' => 'MY COMPANY', 'copyright' => '(c) NoCoffee' }, 'blocks' => [
|
41
|
+
{ 'type' => 'link', 'settings' => { 'label' => 'Link #1', 'url' => 'https://www.nocoffee.fr', 'new_tab' => true } },
|
42
|
+
{ 'type' => 'link', 'settings' => { 'label' => 'Link #2', 'url' => 'https://www.nocoffee.fr', 'new_tab' => true } },
|
43
|
+
{ 'type' => 'link', 'settings' => { 'label' => 'Link', 'url' => 'https://www.locomotivecms.com', 'new_tab' => true } }
|
44
|
+
]}
|
45
|
+
}))
|
53
46
|
end
|
47
|
+
|
54
48
|
end
|
55
49
|
|
56
|
-
|
57
|
-
|
50
|
+
context 'default (global) used also for dropzone_presets (DRY)' do
|
51
|
+
|
52
|
+
let(:definition) { load_section_definition('header') }
|
58
53
|
|
59
|
-
it '
|
60
|
-
expect
|
54
|
+
it 'copies the default settings to any dropzone preset' do
|
55
|
+
expect(subject.definition).to match(hash_including({
|
56
|
+
'presets' => [
|
57
|
+
{
|
58
|
+
'name' => 'Default header',
|
59
|
+
'category' => 'Header',
|
60
|
+
'settings' => { 'brand' => 'MY COMPANY' },
|
61
|
+
'blocks' => [
|
62
|
+
{ 'type' => 'link', 'settings' => { 'label' => 'Link #1', 'url' => 'https://www.nocoffee.fr', 'new_tab' => true } },
|
63
|
+
{ 'type' => 'link', 'settings' => { 'label' => 'Link #2', 'url' => 'https://www.nocoffee.fr', 'new_tab' => true } },
|
64
|
+
{ 'type' => 'link', 'settings' => { 'label' => 'Link', 'url' => 'https://www.locomotivecms.com', 'new_tab' => true } }
|
65
|
+
]
|
66
|
+
}
|
67
|
+
]
|
68
|
+
}))
|
61
69
|
end
|
70
|
+
|
62
71
|
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def load_section_definition(slug, format = :json)
|
78
|
+
filepath = File.join(default_fixture_site_path, 'app', 'views', 'sections', "#{slug}.liquid")
|
79
|
+
content = File.read(filepath)
|
80
|
+
|
81
|
+
case format
|
82
|
+
when :json
|
83
|
+
match = content.match(Locomotive::Steam::JSON_FRONTMATTER_REGEXP)
|
84
|
+
MultiJson.load(match[:json])
|
85
|
+
when :yaml
|
86
|
+
match = content.match(Locomotive::Steam::YAML_FRONTMATTER_REGEXP)
|
87
|
+
YAML.load(match[:yaml])
|
63
88
|
end
|
64
89
|
end
|
90
|
+
|
65
91
|
end
|
@@ -24,4 +24,29 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Section do
|
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
|
+
describe '#load_file' do
|
28
|
+
|
29
|
+
subject { loader.send(:load_file, filepath) }
|
30
|
+
|
31
|
+
describe 'error in the json header' do
|
32
|
+
|
33
|
+
let(:filepath) { File.join(default_fixture_site_path, '..', 'errors', 'section_bad_json_header.liquid') }
|
34
|
+
|
35
|
+
it 'should throw an error' do
|
36
|
+
expect { subject }.to raise_error(Locomotive::Steam::TemplateError)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'json content' do
|
42
|
+
|
43
|
+
let(:filepath) { File.join(default_fixture_site_path, '..', 'errors', 'section_bad_json_content.liquid') }
|
44
|
+
|
45
|
+
it 'should throw an error' do
|
46
|
+
expect { subject }.to raise_error(Locomotive::Steam::JsonParsingError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
27
52
|
end
|
data/spec/unit/errors_spec.rb
CHANGED
@@ -85,7 +85,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntryCollection do
|
|
85
85
|
expect(services.repositories.content_type).to receive(:select_options).with(content_type, 'category').and_return([option_a, option_b])
|
86
86
|
end
|
87
87
|
|
88
|
-
it { expect(drop.
|
88
|
+
it { expect(drop.liquid_method_missing(:category_options)).to eq ['a', 'b'] }
|
89
89
|
|
90
90
|
end
|
91
91
|
|
@@ -95,13 +95,13 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntryCollection do
|
|
95
95
|
expect(services.repositories.content_entry).to receive(:group_by_select_option).with('category').and_return([['a', [1, 2]]])
|
96
96
|
end
|
97
97
|
|
98
|
-
it { expect(drop.
|
98
|
+
it { expect(drop.liquid_method_missing(:group_by_category)).to eq [['a', [1, 2]]] }
|
99
99
|
|
100
100
|
end
|
101
101
|
|
102
102
|
describe 'unknown method' do
|
103
103
|
|
104
|
-
it { expect(drop.
|
104
|
+
it { expect(drop.liquid_method_missing(:foo)).to eq nil }
|
105
105
|
|
106
106
|
end
|
107
107
|
|
@@ -24,10 +24,10 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntry do
|
|
24
24
|
expect(subject.updated_at).to eq 1
|
25
25
|
end
|
26
26
|
|
27
|
-
describe '#
|
27
|
+
describe '#liquid_method_missing (dynamic attributes)' do
|
28
28
|
|
29
29
|
describe 'simple ones' do
|
30
|
-
it { expect(subject.
|
30
|
+
it { expect(subject.liquid_method_missing(:title)).to eq 'Hello world' }
|
31
31
|
end
|
32
32
|
|
33
33
|
describe 'relationship field' do
|
@@ -38,7 +38,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntry do
|
|
38
38
|
|
39
39
|
before { allow(authors).to receive(:dup).and_return(authors) }
|
40
40
|
|
41
|
-
it { expect(subject.
|
41
|
+
it { expect(subject.liquid_method_missing(:authors).first).to eq 'john' }
|
42
42
|
|
43
43
|
end
|
44
44
|
|
@@ -93,7 +93,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntry do
|
|
93
93
|
let(:entry) { instance_double('Article', content_type: type, localized_attributes: { title: true }, title: { en: 'Hello world', fr: 'Bonjour monde' }) }
|
94
94
|
let(:drop) { described_class.new(entry).tap { |d| d.context = context } }
|
95
95
|
|
96
|
-
subject { drop.
|
96
|
+
subject { drop.liquid_method_missing(:title) }
|
97
97
|
|
98
98
|
it { is_expected.to eq 'Hello world' }
|
99
99
|
|
@@ -10,7 +10,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentTypes do
|
|
10
10
|
allow(services.repositories.content_type).to receive(:by_slug).with('articles').and_return(true)
|
11
11
|
end
|
12
12
|
|
13
|
-
it { expect(drop.
|
13
|
+
it { expect(drop.liquid_method_missing('articles')).not_to eq nil }
|
14
14
|
|
15
15
|
context 'content type not found' do
|
16
16
|
|
@@ -18,7 +18,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentTypes do
|
|
18
18
|
allow(services.repositories.content_type).to receive(:by_slug).with('articles').and_return(nil)
|
19
19
|
end
|
20
20
|
|
21
|
-
it { expect(drop.
|
21
|
+
it { expect(drop.liquid_method_missing('articles')).to eq nil }
|
22
22
|
|
23
23
|
end
|
24
24
|
|
@@ -10,7 +10,7 @@ describe Locomotive::Steam::Liquid::Drops::Metafields do
|
|
10
10
|
|
11
11
|
describe 'fields' do
|
12
12
|
|
13
|
-
let(:namespace) { drop.
|
13
|
+
let(:namespace) { drop.liquid_method_missing(:my_namespace).tap { |d| d.context = context } }
|
14
14
|
|
15
15
|
it 'gives the number of the fields' do
|
16
16
|
expect(namespace.size).to eq 4
|
@@ -28,7 +28,7 @@ describe Locomotive::Steam::Liquid::Drops::Metafields do
|
|
28
28
|
|
29
29
|
context 'unknown namespace' do
|
30
30
|
|
31
|
-
subject { drop.
|
31
|
+
subject { drop.liquid_method_missing(:unknown_namespace) }
|
32
32
|
|
33
33
|
it { is_expected.to eq nil }
|
34
34
|
|
@@ -36,11 +36,11 @@ describe Locomotive::Steam::Liquid::Drops::Metafields do
|
|
36
36
|
|
37
37
|
context 'existing namespace' do
|
38
38
|
|
39
|
-
let(:namespace) { drop.
|
39
|
+
let(:namespace) { drop.liquid_method_missing(:my_namespace).tap { |d| d.context = context } }
|
40
40
|
|
41
41
|
context 'unknown field' do
|
42
42
|
|
43
|
-
subject { namespace.
|
43
|
+
subject { namespace.liquid_method_missing(:unknown_field) }
|
44
44
|
|
45
45
|
it { is_expected.to eq nil }
|
46
46
|
|
@@ -51,7 +51,7 @@ describe Locomotive::Steam::Liquid::Drops::Metafields do
|
|
51
51
|
let(:boolean) { true }
|
52
52
|
let(:metafields) { { 'my_namespace' => { 'visible' => { 'default' => boolean } } } }
|
53
53
|
|
54
|
-
subject { namespace.
|
54
|
+
subject { namespace.liquid_method_missing(:visible) }
|
55
55
|
|
56
56
|
it { is_expected.to eq true }
|
57
57
|
|
@@ -81,7 +81,7 @@ describe Locomotive::Steam::Liquid::Drops::Metafields do
|
|
81
81
|
|
82
82
|
context 'the value exists' do
|
83
83
|
|
84
|
-
subject { namespace.
|
84
|
+
subject { namespace.liquid_method_missing(:analytics_id) }
|
85
85
|
|
86
86
|
it { is_expected.to eq '42' }
|
87
87
|
|
@@ -96,7 +96,7 @@ describe Locomotive::Steam::Liquid::Drops::Metafields do
|
|
96
96
|
|
97
97
|
context "the value doesn't exist" do
|
98
98
|
|
99
|
-
subject { namespace.
|
99
|
+
subject { namespace.liquid_method_missing(:country) }
|
100
100
|
|
101
101
|
it { is_expected.to eq nil }
|
102
102
|
|
@@ -106,7 +106,7 @@ describe Locomotive::Steam::Liquid::Drops::Metafields do
|
|
106
106
|
|
107
107
|
context 'localized field' do
|
108
108
|
|
109
|
-
subject { namespace.
|
109
|
+
subject { namespace.liquid_method_missing(:street) }
|
110
110
|
|
111
111
|
it { is_expected.to eq '7 Albert Camus Alley' }
|
112
112
|
|
@@ -5,9 +5,9 @@ describe Locomotive::Steam::Liquid::Drops::Params do
|
|
5
5
|
let(:params) { { 'foo' => '42' } }
|
6
6
|
let(:drop) { described_class.new(params) }
|
7
7
|
|
8
|
-
it { expect(drop.
|
8
|
+
it { expect(drop.liquid_method_missing('bar').to_s).to eq '' }
|
9
9
|
|
10
|
-
it { expect(drop.
|
10
|
+
it { expect(drop.liquid_method_missing('foo').to_s).to eq '42' }
|
11
11
|
|
12
12
|
describe 'prevent XSS attack' do
|
13
13
|
|
@@ -15,11 +15,11 @@ describe Locomotive::Steam::Liquid::Drops::Params do
|
|
15
15
|
|
16
16
|
let(:params) { { 'foo' => 'Hello<script>alert(document.cookie)</script>' } }
|
17
17
|
|
18
|
-
it { expect(drop.
|
18
|
+
it { expect(drop.liquid_method_missing('foo').to_s).to eq 'Hello<script>alert(document.cookie)</script>' }
|
19
19
|
|
20
20
|
context 'security is disabled' do
|
21
21
|
|
22
|
-
it { expect(drop.
|
22
|
+
it { expect(drop.liquid_method_missing('foo').html_safe).to eq 'Hello<script>alert(document.cookie)</script>' }
|
23
23
|
|
24
24
|
end
|
25
25
|
|
@@ -29,7 +29,7 @@ describe Locomotive::Steam::Liquid::Drops::Params do
|
|
29
29
|
|
30
30
|
let(:params) { { 'foo' => "'+alert(document.cookie)+'" } }
|
31
31
|
|
32
|
-
it { expect(drop.
|
32
|
+
it { expect(drop.liquid_method_missing('foo').to_s).to eq ''+alert(document.cookie)+'' }
|
33
33
|
|
34
34
|
end
|
35
35
|
|
@@ -13,13 +13,40 @@ describe Locomotive::Steam::Liquid::Drops::SectionContentProxy do
|
|
13
13
|
let(:settings) { [{ 'id' => 'title', 'type' => 'text' }] }
|
14
14
|
let(:content) { { 'title' => %(Click <a href="//locomotive/_locomotive-link/aaaa">here</a>) } }
|
15
15
|
|
16
|
-
subject { drop.
|
16
|
+
subject { drop.liquid_method_missing(:title) }
|
17
17
|
|
18
18
|
it 'calls the url_finder_service to transform encoded links to existing urls' do
|
19
19
|
expect(url_finder_service).to receive(:decode_urls_for).with(%(Click <a href="//locomotive/_locomotive-link/aaaa">here</a>)).and_return('done')
|
20
20
|
is_expected.to eq 'done'
|
21
21
|
end
|
22
22
|
|
23
|
+
context 'the text is nil' do
|
24
|
+
|
25
|
+
let(:content) { { 'title' => nil } }
|
26
|
+
it { is_expected.to eq nil }
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'integer type setting' do
|
33
|
+
|
34
|
+
let(:settings) { [{ 'id' => 'number', 'type' => 'integer' }] }
|
35
|
+
let(:content) { { 'number' => '42' } }
|
36
|
+
|
37
|
+
subject { drop.liquid_method_missing(:number) }
|
38
|
+
|
39
|
+
it 'converts the number into an integer' do
|
40
|
+
is_expected.to eq 42
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'the number is nil' do
|
44
|
+
|
45
|
+
let(:content) { { 'number' => nil } }
|
46
|
+
it { is_expected.to eq nil }
|
47
|
+
|
48
|
+
end
|
49
|
+
|
23
50
|
end
|
24
51
|
|
25
52
|
describe 'url type setting' do
|
@@ -28,29 +55,43 @@ describe Locomotive::Steam::Liquid::Drops::SectionContentProxy do
|
|
28
55
|
let(:content) { { 'link' => { 'type' => 'page', 'value' => 42, 'new_window' => true } } }
|
29
56
|
let(:page) { instance_double('Page') }
|
30
57
|
|
31
|
-
|
32
|
-
|
33
|
-
|
58
|
+
context 'the link is not nil' do
|
59
|
+
|
60
|
+
before do
|
61
|
+
expect(url_finder_service).to receive(:url_for).with({ 'type' => 'page', 'value' => 42, 'new_window' => true }).and_return(['/foo/bar', true])
|
62
|
+
end
|
34
63
|
|
35
|
-
|
64
|
+
subject { drop.liquid_method_missing(:link).to_s }
|
36
65
|
|
37
|
-
|
38
|
-
|
39
|
-
|
66
|
+
it 'returns the url to the page' do
|
67
|
+
is_expected.to eq '/foo/bar'
|
68
|
+
end
|
40
69
|
|
41
|
-
|
70
|
+
context 'it knows if the link has to be opened in a new window or not' do
|
42
71
|
|
43
|
-
|
72
|
+
subject { drop.liquid_method_missing(:link).new_window }
|
44
73
|
|
45
|
-
|
74
|
+
it { is_expected.to eq true }
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'it outputs the target="_blank" A attribute if new window is true' do
|
79
|
+
|
80
|
+
subject { drop.liquid_method_missing(:link).new_window_attribute }
|
81
|
+
|
82
|
+
it { is_expected.to eq('target="_blank"') }
|
83
|
+
|
84
|
+
end
|
46
85
|
|
47
86
|
end
|
48
87
|
|
49
|
-
context '
|
88
|
+
context 'the link is nil' do
|
89
|
+
|
90
|
+
let(:content) { { 'link' => nil } }
|
50
91
|
|
51
|
-
subject { drop.
|
92
|
+
subject { drop.liquid_method_missing(:link) }
|
52
93
|
|
53
|
-
it { is_expected.to eq
|
94
|
+
it { is_expected.to eq nil }
|
54
95
|
|
55
96
|
end
|
56
97
|
|
@@ -62,13 +103,13 @@ describe Locomotive::Steam::Liquid::Drops::SectionContentProxy do
|
|
62
103
|
let(:value) { nil }
|
63
104
|
let(:content) { { 'image' => value } }
|
64
105
|
let(:page) { instance_double('Page') }
|
65
|
-
let(:image_drop) { drop.
|
106
|
+
let(:image_drop) { drop.liquid_method_missing(:image) }
|
66
107
|
|
67
108
|
subject { image_drop.to_s }
|
68
109
|
|
69
|
-
it { is_expected.to eq
|
110
|
+
it { is_expected.to eq '' }
|
70
111
|
|
71
|
-
context 'the
|
112
|
+
context 'the image is a string' do
|
72
113
|
|
73
114
|
let(:value) { 'banner.jpg' }
|
74
115
|
|
@@ -76,7 +117,7 @@ describe Locomotive::Steam::Liquid::Drops::SectionContentProxy do
|
|
76
117
|
|
77
118
|
end
|
78
119
|
|
79
|
-
context 'the
|
120
|
+
context 'the image is a hash' do
|
80
121
|
|
81
122
|
let(:value) { { source: 'awesome_banner.jpg', cropped: 'cropped_awesome_banner.jpg', width: 42, height: 30 } }
|
82
123
|
|
@@ -91,6 +132,16 @@ describe Locomotive::Steam::Liquid::Drops::SectionContentProxy do
|
|
91
132
|
|
92
133
|
end
|
93
134
|
|
135
|
+
context 'the image is nil' do
|
136
|
+
|
137
|
+
let(:value) { nil }
|
138
|
+
|
139
|
+
subject { image_drop }
|
140
|
+
|
141
|
+
it { is_expected.to eq nil }
|
142
|
+
|
143
|
+
end
|
144
|
+
|
94
145
|
end
|
95
146
|
|
96
147
|
end
|
@@ -15,7 +15,7 @@ describe Locomotive::Steam::Liquid::Drops::Section do
|
|
15
15
|
|
16
16
|
before { expect(drop.settings).to receive(:url_finder).and_return(url_finder) }
|
17
17
|
|
18
|
-
subject { drop.settings.
|
18
|
+
subject { drop.settings.liquid_method_missing(:title) }
|
19
19
|
|
20
20
|
it 'returns the value of the text setting' do
|
21
21
|
is_expected.to eq 'Hello world'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Steam::Liquid::FileSystem do
|
4
|
+
|
5
|
+
let(:section_finder) { instance_double('SectionFinder') }
|
6
|
+
let(:snippet_finder) { instance_double('SnippetFinder') }
|
7
|
+
let(:instance) { described_class.new(section_finder: section_finder, snippet_finder: snippet_finder) }
|
8
|
+
|
9
|
+
describe '#read_template_file' do
|
10
|
+
|
11
|
+
let(:template_path) { nil }
|
12
|
+
|
13
|
+
subject { instance.read_template_file(template_path) }
|
14
|
+
|
15
|
+
context 'unknown type' do
|
16
|
+
|
17
|
+
let(:template_path) { 'unknown_template' }
|
18
|
+
|
19
|
+
it { expect { subject }.to raise_error('Liquid error: This liquid context does not allow unknown_template.') }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Locomotive::Steam::Liquid::Filters::Array' do
|
4
|
+
|
5
|
+
include ::Liquid::StandardFilters
|
6
|
+
include Locomotive::Steam::Liquid::Filters::Base
|
7
|
+
include Locomotive::Steam::Liquid::Filters::Array
|
8
|
+
|
9
|
+
describe '#pop' do
|
10
|
+
|
11
|
+
let(:array) { ['a', 'b', 'c'] }
|
12
|
+
|
13
|
+
subject { pop(array) }
|
14
|
+
|
15
|
+
it { is_expected.to eq(['a', 'b']) }
|
16
|
+
|
17
|
+
context 'removing last n elements' do
|
18
|
+
|
19
|
+
subject { pop(array, 2) }
|
20
|
+
|
21
|
+
it { is_expected.to eq(['a']) }
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'passing a non array input' do
|
26
|
+
|
27
|
+
let(:array) { 'Hello world' }
|
28
|
+
it { is_expected.to eq('Hello world') }
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#push' do
|
35
|
+
|
36
|
+
let(:array) { ['a', 'b', 'c'] }
|
37
|
+
|
38
|
+
subject { push(array, 'd') }
|
39
|
+
|
40
|
+
it { is_expected.to eq(['a', 'b', 'c', 'd']) }
|
41
|
+
|
42
|
+
context 'passing a non array input' do
|
43
|
+
|
44
|
+
let(:array) { 'Hello world' }
|
45
|
+
it { is_expected.to eq('Hello world') }
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#shift' do
|
52
|
+
|
53
|
+
let(:array) { ['a', 'b', 'c'] }
|
54
|
+
|
55
|
+
subject { shift(array) }
|
56
|
+
|
57
|
+
it { is_expected.to eq(['b', 'c']) }
|
58
|
+
|
59
|
+
context 'removing n first elements' do
|
60
|
+
|
61
|
+
subject { shift(array, 2) }
|
62
|
+
|
63
|
+
it { is_expected.to eq(['c']) }
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'passing a non array input' do
|
68
|
+
|
69
|
+
let(:array) { 'Hello world' }
|
70
|
+
it { is_expected.to eq('Hello world') }
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#unshift' do
|
77
|
+
|
78
|
+
let(:array) { ['a', 'b', 'c'] }
|
79
|
+
|
80
|
+
subject { unshift(array, '1') }
|
81
|
+
|
82
|
+
it { is_expected.to eq(['1', 'a', 'b', 'c']) }
|
83
|
+
|
84
|
+
context 'adding n elements' do
|
85
|
+
|
86
|
+
subject { unshift(array, ['1', '2']) }
|
87
|
+
|
88
|
+
it { is_expected.to eq(['1', '2', 'a', 'b', 'c']) }
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'passing a non array input' do
|
93
|
+
|
94
|
+
let(:array) { 'Hello world' }
|
95
|
+
it { is_expected.to eq('Hello world') }
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#in_groups_of' do
|
102
|
+
|
103
|
+
let(:array) { (1..10).to_a }
|
104
|
+
|
105
|
+
subject { in_groups_of(array, '3') }
|
106
|
+
|
107
|
+
it { is_expected.to eq([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, nil, nil]]) }
|
108
|
+
|
109
|
+
context 'passing fill_with argument: nil' do
|
110
|
+
subject { in_groups_of(array, '3', nil) }
|
111
|
+
it { is_expected.to eq([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, nil, nil]]) }
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'passing fill_with argument: value' do
|
115
|
+
subject { in_groups_of(array, '3', 'foo') }
|
116
|
+
it { is_expected.to eq([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 'foo', 'foo']]) }
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'passing fill_with argument: false' do
|
120
|
+
subject { in_groups_of(array, '3', false) }
|
121
|
+
it { is_expected.to eq([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]) }
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'passing a non array input' do
|
125
|
+
let(:array) { 'Hello world' }
|
126
|
+
it { is_expected.to eq('Hello world') }
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'passing a ContentEntryCollection input' do
|
130
|
+
let(:array) { Locomotive::Steam::Liquid::Drops::ContentEntryCollection.new('blog_posts') }
|
131
|
+
|
132
|
+
it 'groups entries' do
|
133
|
+
expect(array).to receive(:all).and_return((1..10).to_a)
|
134
|
+
is_expected.to eq([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, nil, nil]])
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|