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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/Gemfile +3 -6
  4. data/Gemfile.lock +39 -39
  5. data/README.md +2 -2
  6. data/lib/locomotive/steam/adapters/filesystem/sanitizers/section.rb +62 -16
  7. data/lib/locomotive/steam/adapters/filesystem/sanitizers/site.rb +15 -1
  8. data/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb +30 -9
  9. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +1 -1
  10. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb +1 -1
  11. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/section.rb +14 -2
  12. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/site.rb +1 -1
  13. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/translation.rb +1 -1
  14. data/lib/locomotive/steam/adapters/mongodb.rb +1 -1
  15. data/lib/locomotive/steam/entities/content_entry.rb +0 -1
  16. data/lib/locomotive/steam/entities/site.rb +4 -0
  17. data/lib/locomotive/steam/errors.rb +54 -18
  18. data/lib/locomotive/steam/liquid/drops/content_entry.rb +1 -1
  19. data/lib/locomotive/steam/liquid/drops/content_entry_collection.rb +1 -1
  20. data/lib/locomotive/steam/liquid/drops/content_types.rb +1 -1
  21. data/lib/locomotive/steam/liquid/drops/inherited_block.rb +28 -0
  22. data/lib/locomotive/steam/liquid/drops/metafields.rb +2 -2
  23. data/lib/locomotive/steam/liquid/drops/params.rb +1 -1
  24. data/lib/locomotive/steam/liquid/drops/section.rb +10 -2
  25. data/lib/locomotive/steam/liquid/drops/section_content_proxy.rb +13 -2
  26. data/lib/locomotive/steam/liquid/drops/section_editor_setting_data.rb +1 -1
  27. data/lib/locomotive/steam/liquid/drops/session_proxy.rb +1 -1
  28. data/lib/locomotive/steam/liquid/file_system.rb +46 -0
  29. data/lib/locomotive/steam/liquid/filters/array.rb +61 -0
  30. data/lib/locomotive/steam/liquid/filters/misc.rb +12 -2
  31. data/lib/locomotive/steam/liquid/filters/number.rb +13 -12
  32. data/lib/locomotive/steam/liquid/filters/text.rb +4 -0
  33. data/lib/locomotive/steam/liquid/patches.rb +58 -19
  34. data/lib/locomotive/steam/liquid/tags/alt_page_links.rb +9 -5
  35. data/lib/locomotive/steam/liquid/tags/concerns/attributes.rb +47 -0
  36. data/lib/locomotive/steam/liquid/tags/concerns/path.rb +18 -31
  37. data/lib/locomotive/steam/liquid/tags/concerns/section.rb +22 -11
  38. data/lib/locomotive/steam/liquid/tags/consume.rb +26 -33
  39. data/lib/locomotive/steam/liquid/tags/csrf.rb +2 -2
  40. data/lib/locomotive/steam/liquid/tags/editable/base.rb +30 -20
  41. data/lib/locomotive/steam/liquid/tags/editable/control.rb +2 -2
  42. data/lib/locomotive/steam/liquid/tags/editable/file.rb +11 -11
  43. data/lib/locomotive/steam/liquid/tags/editable/text.rb +5 -5
  44. data/lib/locomotive/steam/liquid/tags/extends.rb +56 -8
  45. data/lib/locomotive/steam/liquid/tags/global_section.rb +6 -6
  46. data/lib/locomotive/steam/liquid/tags/google_analytics.rb +16 -6
  47. data/lib/locomotive/steam/liquid/tags/hybrid.rb +8 -4
  48. data/lib/locomotive/steam/liquid/tags/inherited_block.rb +90 -13
  49. data/lib/locomotive/steam/liquid/tags/inline_editor.rb +4 -4
  50. data/lib/locomotive/steam/liquid/tags/link_to.rb +2 -1
  51. data/lib/locomotive/steam/liquid/tags/locale_switcher.rb +25 -21
  52. data/lib/locomotive/steam/liquid/tags/model_form.rb +38 -17
  53. data/lib/locomotive/steam/liquid/tags/nav.rb +4 -4
  54. data/lib/locomotive/steam/liquid/tags/page_not_found.rb +19 -0
  55. data/lib/locomotive/steam/liquid/tags/paginate.rb +13 -7
  56. data/lib/locomotive/steam/liquid/tags/path_to.rb +1 -0
  57. data/lib/locomotive/steam/liquid/tags/redirect_to.rb +34 -0
  58. data/lib/locomotive/steam/liquid/tags/section.rb +34 -33
  59. data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +1 -1
  60. data/lib/locomotive/steam/liquid/tags/seo.rb +2 -4
  61. data/lib/locomotive/steam/liquid/tags/session_assign.rb +1 -0
  62. data/lib/locomotive/steam/liquid/tags/snippet.rb +21 -29
  63. data/lib/locomotive/steam/liquid/tags/with_scope.rb +61 -27
  64. data/lib/locomotive/steam/liquid.rb +3 -1
  65. data/lib/locomotive/steam/middlewares/cache.rb +117 -0
  66. data/lib/locomotive/steam/middlewares/concerns/helpers.rb +22 -8
  67. data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +5 -1
  68. data/lib/locomotive/steam/middlewares/concerns/rendering.rb +53 -0
  69. data/lib/locomotive/steam/middlewares/impersonated_entry.rb +4 -0
  70. data/lib/locomotive/steam/middlewares/locale.rb +2 -2
  71. data/lib/locomotive/steam/middlewares/locale_redirection.rb +1 -1
  72. data/lib/locomotive/steam/middlewares/logging.rb +1 -0
  73. data/lib/locomotive/steam/middlewares/page_not_found.rb +37 -0
  74. data/lib/locomotive/steam/middlewares/redirection.rb +1 -1
  75. data/lib/locomotive/steam/middlewares/renderer.rb +4 -26
  76. data/lib/locomotive/steam/middlewares/thread_safe.rb +0 -4
  77. data/lib/locomotive/steam/models/pager.rb +1 -0
  78. data/lib/locomotive/steam/server.rb +3 -1
  79. data/lib/locomotive/steam/services/action_service.rb +5 -0
  80. data/lib/locomotive/steam/services/auth_service.rb +9 -9
  81. data/lib/locomotive/steam/services/cookie_service.rb +1 -0
  82. data/lib/locomotive/steam/services/external_api_service.rb +5 -0
  83. data/lib/locomotive/steam/services/liquid_parser_service.rb +4 -2
  84. data/lib/locomotive/steam/services/page_finder_service.rb +1 -1
  85. data/lib/locomotive/steam/services/recaptcha_service.rb +4 -2
  86. data/lib/locomotive/steam/version.rb +1 -1
  87. data/lib/locomotive/steam.rb +5 -1
  88. data/locomotivecms_steam.gemspec +4 -4
  89. data/spec/fixtures/default/app/views/pages/basic.liquid.haml +1 -0
  90. data/spec/fixtures/default/app/views/pages/music.liquid.haml +6 -0
  91. data/spec/fixtures/default/app/views/sections/carousel.liquid +15 -16
  92. data/spec/fixtures/default/app/views/sections/footer.liquid +37 -3
  93. data/spec/fixtures/default/app/views/sections/header.liquid +47 -10
  94. data/spec/fixtures/default/app/views/sections/misc/hero.liquid +28 -0
  95. data/spec/fixtures/default/config/metafields_schema.yml +3 -0
  96. data/spec/integration/liquid/tags/section_spec.rb +82 -0
  97. data/spec/integration/repositories/content_entry_repository_spec.rb +9 -0
  98. data/spec/integration/server/basic_spec.rb +2 -2
  99. data/spec/integration/server/metafields_spec.rb +1 -0
  100. data/spec/integration/services/content_entry_service_spec.rb +12 -0
  101. data/spec/support/helpers.rb +1 -0
  102. data/spec/support/liquid.rb +32 -2
  103. data/spec/support/mongo.rb +1 -0
  104. data/spec/unit/adapters/filesystem/sanitizers/section_spec.rb +66 -40
  105. data/spec/unit/adapters/filesystem/yaml_loaders/section_spec.rb +25 -0
  106. data/spec/unit/errors_spec.rb +1 -1
  107. data/spec/unit/liquid/drops/content_entry_collection_spec.rb +3 -3
  108. data/spec/unit/liquid/drops/content_entry_spec.rb +4 -4
  109. data/spec/unit/liquid/drops/content_types_spec.rb +2 -2
  110. data/spec/unit/liquid/drops/metafields_spec.rb +8 -8
  111. data/spec/unit/liquid/drops/params_spec.rb +5 -5
  112. data/spec/unit/liquid/drops/section_content_proxy_spec.rb +69 -18
  113. data/spec/unit/liquid/drops/section_spec.rb +1 -1
  114. data/spec/unit/liquid/file_system_spec.rb +25 -0
  115. data/spec/unit/liquid/filters/array_spec.rb +140 -0
  116. data/spec/unit/liquid/filters/misc_spec.rb +21 -3
  117. data/spec/unit/liquid/filters/number_spec.rb +4 -4
  118. data/spec/unit/liquid/filters/text_spec.rb +4 -0
  119. data/spec/unit/liquid/tags/alt_page_links_spec.rb +19 -2
  120. data/spec/unit/liquid/tags/authorize_spec.rb +1 -1
  121. data/spec/unit/liquid/tags/editable/text_spec.rb +32 -4
  122. data/spec/unit/liquid/tags/extends_spec.rb +115 -28
  123. data/spec/unit/liquid/tags/global_section_spec.rb +4 -3
  124. data/spec/unit/liquid/tags/google_analytics_spec.rb +21 -2
  125. data/spec/unit/liquid/tags/inherited_block_spec.rb +18 -4
  126. data/spec/unit/liquid/tags/inline_editor_spec.rb +11 -0
  127. data/spec/unit/liquid/tags/link_to_spec.rb +1 -1
  128. data/spec/unit/liquid/tags/model_form_spec.rb +7 -0
  129. data/spec/unit/liquid/tags/page_not_found_spec.rb +14 -0
  130. data/spec/unit/liquid/tags/redirect_to_spec.rb +171 -0
  131. data/spec/unit/liquid/tags/section_spec.rb +43 -3
  132. data/spec/unit/liquid/tags/sections_dropzone_spec.rb +0 -1
  133. data/spec/unit/liquid/tags/snippet_spec.rb +9 -8
  134. data/spec/unit/liquid/tags/with_scope_spec.rb +80 -60
  135. data/spec/unit/middlewares/cache_spec.rb +186 -0
  136. data/spec/unit/middlewares/impersonated_entry_spec.rb +7 -0
  137. data/spec/unit/middlewares/locale_redirection_spec.rb +7 -0
  138. data/spec/unit/middlewares/locale_spec.rb +8 -1
  139. data/spec/unit/middlewares/page_not_found_spec.rb +46 -0
  140. data/spec/unit/middlewares/redirection_spec.rb +8 -0
  141. data/spec/unit/middlewares/renderer_spec.rb +64 -6
  142. data/spec/unit/middlewares/section_spec.rb +1 -0
  143. data/spec/unit/models/pager_spec.rb +11 -1
  144. data/spec/unit/repositories/section_repository_spec.rb +1 -1
  145. data/spec/unit/services/action_service_spec.rb +23 -3
  146. data/spec/unit/services/page_redirection_service_spec.rb +2 -2
  147. data/spec/unit/services/recaptcha_service_spec.rb +1 -1
  148. metadata +50 -24
@@ -0,0 +1,171 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Steam::Liquid::Tags::RedirectTo do
4
+
5
+ let(:prefix_default) { false }
6
+ let(:assigns) { {} }
7
+ let(:current_locale) { 'en' }
8
+ let(:locales) { ['en'] }
9
+ let(:services) { Locomotive::Steam::Services.build_instance }
10
+ let(:site) { instance_double('Site', locales: locales, default_locale: 'en', prefix_default_locale: prefix_default) }
11
+ let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, site: site, locale: current_locale }) }
12
+
13
+ subject { render_template(source, context) }
14
+
15
+ before { allow(services).to receive(:current_site).and_return(site) }
16
+
17
+ describe 'parsing' do
18
+
19
+ let(:source) { '{% redirect_to %}' }
20
+ it { expect { subject }.to raise_error('Valid syntax: redirect_to <page|page_handle|content_entry|external_url>(, locale: [fr|de|...], with: <page_handle>, permanent: [true|false]') }
21
+
22
+ end
23
+
24
+ describe 'external url' do
25
+
26
+ let(:source) { '{% redirect_to "https://www.locomotivecms.com" %}' }
27
+
28
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to https://www.locomotivecms.com (301)') }
29
+
30
+ context 'non permanent redirection' do
31
+
32
+ let(:source) { '{% redirect_to "https://www.locomotivecms.com", permanent: false %}' }
33
+
34
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to https://www.locomotivecms.com (302)') }
35
+
36
+ end
37
+
38
+ end
39
+
40
+ describe 'unknown page' do
41
+
42
+ let(:source) { '{% redirect_to index %}' }
43
+
44
+ before do
45
+ expect(services.page_finder).to receive(:by_handle).with('index').and_return(nil)
46
+ end
47
+
48
+ it { is_expected.to eq '' }
49
+
50
+ end
51
+
52
+ describe 'from a handle of a page' do
53
+
54
+ let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(page) }
55
+ let(:page) { liquid_instance_double('Index', title: 'Index', handle: 'index', fullpath: fullpath, localized_attributes: { fullpath: true }, templatized?: false) }
56
+ let(:fullpath) { { en: 'index', fr: 'index' } }
57
+ let(:source) { '{% redirect_to index %}' }
58
+
59
+ before do
60
+ expect(services.page_finder).to receive(:by_handle).with('index').and_return(page)
61
+ allow(page).to receive(:to_liquid).and_return(drop)
62
+ end
63
+
64
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to / (301)') }
65
+
66
+ context 'and a different locale' do
67
+
68
+ let(:source) { "{% redirect_to index, locale: 'fr' %}" }
69
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /fr (301)') }
70
+
71
+ end
72
+
73
+ context 'the current locale in session is different from the requested locale' do
74
+
75
+ let(:current_locale) { 'fr' }
76
+ let(:locales) { ['en', 'fr'] }
77
+ let(:source) { "{% redirect_to index, locale: 'en' %}" }
78
+
79
+ before do
80
+ services.url_builder.current_locale = current_locale
81
+ end
82
+
83
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /en (301)') }
84
+
85
+ context 'prefix_default_locale is true' do
86
+
87
+ let(:prefix_default) { true }
88
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /en (301)') }
89
+
90
+ end
91
+
92
+ end
93
+
94
+ context 'prefix_default_locale is true' do
95
+
96
+ let(:prefix_default) { true }
97
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /en (301)') }
98
+
99
+ end
100
+
101
+ end
102
+
103
+ describe 'from a page (drop) itself' do
104
+
105
+ let(:assigns) { { 'about_us' => drop } }
106
+ let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(page) }
107
+ let(:page) { liquid_instance_double('AboutUs', title: 'About us', handle: 'index', localized_attributes: { fullpath: true }, fullpath: fullpath, templatized?: false) }
108
+ let(:fullpath) { { en: 'about-us', fr: 'a-notre-sujet' } }
109
+ let(:source) { '{% redirect_to about_us %}' }
110
+
111
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /about-us (301)') }
112
+
113
+ context 'and a different locale' do
114
+
115
+ let(:source) { "{% redirect_to about_us, locale: 'fr' %}" }
116
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /fr/a-notre-sujet (301)') }
117
+
118
+ context 'locale is a variable' do
119
+
120
+ let(:assigns) { { 'about_us' => drop, 'language' => 'fr' } }
121
+ let(:source) { "{% redirect_to about_us, locale: language %}" }
122
+
123
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /fr/a-notre-sujet (301)') }
124
+
125
+ end
126
+
127
+ end
128
+
129
+ end
130
+
131
+ describe 'from a content entry (drop)' do
132
+
133
+ let(:assigns) { { 'article' => entry_drop } }
134
+ let(:entry_drop) { Locomotive::Steam::Liquid::Drops::ContentEntry.new(entry) }
135
+ let(:entry) { liquid_instance_double('Article', localized_attributes: { _slug: true }, _slug: { en: 'hello-world', fr: 'bonjour-monde' }) }
136
+ let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(page) }
137
+ let(:page) { liquid_instance_double('ArticleTemplate', title: 'Template of an article', handle: 'article', localized_attributes: { fullpath: true }, fullpath: { en: 'my-articles/content_type_template', fr: 'mes-articles/content_type_template' }, content_entry: entry_drop.send(:_source), templatized?: true) }
138
+ let(:source) { '{% redirect_to article %}' }
139
+
140
+ before do
141
+ allow(services.repositories.page).to receive(:template_for).with(entry, nil).and_return(page)
142
+ allow(page).to receive(:to_liquid).and_return(drop)
143
+ end
144
+
145
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /my-articles/hello-world (301)') }
146
+
147
+ context 'and a different locale' do
148
+
149
+ let(:source) { "{% redirect_to article, locale: 'fr' %}" }
150
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /fr/mes-articles/bonjour-monde (301)') }
151
+
152
+ end
153
+
154
+ context 'and a different template' do
155
+
156
+ let(:archive) { liquid_instance_double('ArticleTemplate', title: 'Template of an article', handle: 'article', localized_attributes: { fullpath: true }, fullpath: { en: 'my-archives/content_type_template', fr: 'mes-archives/content_type_template' }, content_entry: entry_drop.send(:_source), templatized?: true) }
157
+ let(:drop) { Locomotive::Steam::Liquid::Drops::Page.new(archive) }
158
+
159
+ before do
160
+ allow(services.repositories.page).to receive(:template_for).with(entry, 'archives').and_return(archive)
161
+ allow(archive).to receive(:to_liquid).and_return(drop)
162
+ end
163
+
164
+ let(:source) { "{% redirect_to article, with: archives, locale: fr %}" }
165
+ it { expect { subject }.to raise_error(Locomotive::Steam::RedirectionException, 'Redirect to /fr/mes-archives/bonjour-monde (301)') }
166
+
167
+ end
168
+
169
+ end
170
+
171
+ end
@@ -9,9 +9,10 @@ describe Locomotive::Steam::Liquid::Tags::Section do
9
9
  let(:live_editing) { true }
10
10
  let(:content) { {} }
11
11
  let(:alt_content) { nil }
12
+ let(:file_system) { Locomotive::Steam::Liquid::FileSystem.new(section_finder: finder) }
12
13
  let(:page) { liquid_instance_double('Page', sections_content: content)}
13
14
  let(:assigns) { { 'page' => page } }
14
- let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, live_editing: live_editing, _section_content: alt_content }) }
15
+ let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, live_editing: live_editing, _section_content: alt_content, file_system: file_system }, rethrow_errors: true) }
15
16
 
16
17
  describe 'parsing' do
17
18
 
@@ -98,6 +99,22 @@ describe Locomotive::Steam::Liquid::Tags::Section do
98
99
 
99
100
  end
100
101
 
102
+ context 'including the link_to liquid tag' do
103
+
104
+ let(:liquid_source) { 'go to {% link_to home %}' }
105
+
106
+ before { expect_any_instance_of(Locomotive::Steam::Liquid::Tags::LinkTo).to receive(:render) { 'HOME' } }
107
+
108
+ it { is_expected.to eq 'Locomotive'\
109
+ ' <div id="locomotive-section-page-header"'\
110
+ ' class="locomotive-section my-awesome-header"'\
111
+ ' data-locomotive-section-type="header">'\
112
+ '<span id="page-header-section"></span>'\
113
+ 'go to HOME'\
114
+ '</div>' }
115
+
116
+ end
117
+
101
118
  context 'without the live editing feature enabled' do
102
119
 
103
120
  let(:live_editing) { false }
@@ -112,6 +129,20 @@ describe Locomotive::Steam::Liquid::Tags::Section do
112
129
 
113
130
  end
114
131
 
132
+ context 'the developer wants to wrap herself/himself the section' do
133
+
134
+ let(:liquid_source) { '<section class="section-header" id="{{ section.anchor_id }}" {{ section.locomotive_attributes }}>Hello world</section>' }
135
+
136
+ it { is_expected.to eq 'Locomotive '\
137
+ '<section class="section-header"'\
138
+ ' id="page-header-section"'\
139
+ ' data-locomotive-section-id="page-header"'\
140
+ ' data-locomotive-section-type="header">'\
141
+ 'Hello world'\
142
+ '</section>' }
143
+
144
+ end
145
+
115
146
  end
116
147
 
117
148
  context 'with blocks' do
@@ -219,6 +250,15 @@ describe Locomotive::Steam::Liquid::Tags::Section do
219
250
  end
220
251
  end
221
252
 
253
+ context 'the section has a syntax error inside its liquid template' do
254
+
255
+ let(:liquid_source) { %(built by <a>\n\t<strong>{{ section.settings.brand }}{% if %}</strong></a>) }
256
+
257
+ it 'raises a LiquidError' do
258
+ expect { subject }.to raise_exception(Locomotive::Steam::LiquidError)
259
+ end
260
+
261
+ end
222
262
 
223
263
  context 'rendering error (action) found in the section' do
224
264
 
@@ -230,8 +270,8 @@ describe Locomotive::Steam::Liquid::Tags::Section do
230
270
  definition: { settings: [], blocks: [] }
231
271
  )}
232
272
 
233
- it 'raises ParsingRenderingError' do
234
- expect { subject }.to raise_exception(Locomotive::Steam::ParsingRenderingError)
273
+ it 'raises a TemplateError' do
274
+ expect { subject }.to raise_exception(Locomotive::Steam::TemplateError)
235
275
  end
236
276
  end
237
277
 
@@ -68,7 +68,6 @@ describe Locomotive::Steam::Liquid::Tags::SectionsDropzone do
68
68
  end
69
69
 
70
70
  it 'renders the list of sections' do
71
- puts is_expected.inspect
72
71
  is_expected.to eq <<-HTML
73
72
  <div class="locomotive-sections">
74
73
  <div id="locomotive-section-dropzone-0" class="locomotive-section" data-locomotive-section-type="hero">
@@ -2,11 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe Locomotive::Steam::Liquid::Tags::Snippet do
4
4
 
5
- let(:request) { instance_double('Request', env: {}) }
6
- let(:services) { Locomotive::Steam::Services.build_instance(request) }
7
- let(:finder) { services.snippet_finder }
8
- let(:snippet) { instance_double('Snippet', template: nil, :template= => nil, liquid_source: 'built by NoCoffee') }
9
- let(:source) { 'Locomotive {% include footer %}' }
5
+ let(:request) { instance_double('Request', env: {}) }
6
+ let(:services) { Locomotive::Steam::Services.build_instance(request) }
7
+ let(:finder) { services.snippet_finder }
8
+ let(:file_system) { Locomotive::Steam::Liquid::FileSystem.new(snippet_finder: finder) }
9
+ let(:snippet) { instance_double('Snippet', template: nil, :template= => nil, liquid_source: 'built by NoCoffee') }
10
+ let(:source) { 'Locomotive {% include footer %}' }
10
11
 
11
12
  before { allow(finder).to receive(:find).and_return(snippet) }
12
13
 
@@ -32,7 +33,7 @@ describe Locomotive::Steam::Liquid::Tags::Snippet do
32
33
 
33
34
  describe 'rendering' do
34
35
 
35
- let(:context) { ::Liquid::Context.new({}, {}, { services: services }) }
36
+ let(:context) { ::Liquid::Context.new({}, {}, { services: services, file_system: file_system }) }
36
37
 
37
38
  subject { render_template(source, context) }
38
39
 
@@ -42,8 +43,8 @@ describe Locomotive::Steam::Liquid::Tags::Snippet do
42
43
 
43
44
  let(:snippet) { instance_double('Snippet', template: nil, :template= => nil, liquid_source: '{% action "Hello world" %}a.b(+}{% endaction %}') }
44
45
 
45
- it 'raises ParsingRenderingError' do
46
- expect { subject }.to raise_exception(Locomotive::Steam::ParsingRenderingError)
46
+ it 'raises a TemplateError' do
47
+ expect { subject }.to raise_exception(Locomotive::Steam::TemplateError)
47
48
  end
48
49
 
49
50
  end
@@ -1,110 +1,130 @@
1
1
  require 'spec_helper'
2
+ require 'origin'
2
3
 
3
4
  describe Locomotive::Steam::Liquid::Tags::WithScope do
4
5
 
5
6
  let(:assigns) { {} }
6
7
  let(:context) { ::Liquid::Context.new(assigns, {}, {}) }
7
- let!(:output) { render_template(source, context) }
8
+ let(:output) { render_template(source, context) }
8
9
  let(:conditions) { context['conditions'] }
9
10
 
10
- describe 'store the conditions in the context' do
11
+ describe 'no attributes' do
11
12
 
12
- let(:source) { "{% with_scope active: true, price: 42, title: 'foo', hidden: false %}{% assign conditions = with_scope %}{% assign content_type = with_scope_content_type %}{% endwith_scope %}" }
13
-
14
- it { expect(context['conditions'].keys).to eq(%w(active price title hidden)) }
15
- it { expect(context['content_type']).to eq false }
13
+ let(:source) { '{% with_scope %}42{% endwith_scope %}'}
14
+ it { expect { output }.to raise_error("Liquid syntax error (line 1): Syntax Error in 'with_scope' - Valid syntax: with_scope <name_1>: <value_1>, ..., <name_n>: <value_n>") }
16
15
 
17
16
  end
18
17
 
19
- describe 'decode basic options (boolean, integer, ...)' do
18
+ describe 'valid syntax' do
20
19
 
21
- let(:source) { "{% with_scope active: true, price: 42, title: 'foo', hidden: false %}{% assign conditions = with_scope %}{% endwith_scope %}" }
20
+ before { output }
22
21
 
23
- it { expect(conditions['active']).to eq true }
24
- it { expect(conditions['price']).to eq 42 }
25
- it { expect(conditions['title']).to eq 'foo' }
26
- it { expect(conditions['hidden']).to eq false }
22
+ describe 'renders basic stuff' do
23
+ let(:source) { '{% with_scope a: 1 %}42{% endwith_scope %}' }
24
+ it { expect(output).to eq '42' }
25
+ end
27
26
 
28
- end
27
+ describe 'store the conditions in the context' do
29
28
 
30
- describe 'decode regexps' do
29
+ let(:source) { "{% with_scope active: true, price: 42, title: 'foo', hidden: false %}{% assign conditions = with_scope %}{% assign content_type = with_scope_content_type %}{% endwith_scope %}" }
31
30
 
32
- let(:source) { "{% with_scope title: /Like this one|or this one/ %}{% assign conditions = with_scope %}{% endwith_scope %}" }
33
- it { expect(conditions['title']).to eq(/Like this one|or this one/) }
31
+ it { expect(context['conditions'].keys).to eq(%w(active price title hidden)) }
32
+ it { expect(context['content_type']).to eq false }
34
33
 
35
- end
34
+ end
36
35
 
37
- describe 'decode regexps with case-insensitive' do
36
+ describe 'decode basic options (boolean, integer, ...)' do
38
37
 
39
- let(:source) { "{% with_scope title: /like this/ix %}{% assign conditions = with_scope %}{% endwith_scope %}" }
40
- it { expect(conditions['title']).to eq(/like this/ix) }
38
+ let(:source) { "{% with_scope active: true, price: 42, title: 'foo', hidden: false %}{% assign conditions = with_scope %}{% endwith_scope %}" }
41
39
 
42
- end
40
+ it { expect(conditions['active']).to eq true }
41
+ it { expect(conditions['price']).to eq 42 }
42
+ it { expect(conditions['title']).to eq 'foo' }
43
+ it { expect(conditions['hidden']).to eq false }
43
44
 
44
- describe 'decode content entry' do
45
+ end
45
46
 
46
- let(:entry) {
47
- instance_double('ContentEntry', _id: 1, _source: 'entity').tap do |_entry|
48
- allow(_entry).to receive(:to_liquid).and_return(_entry)
49
- end }
50
- let(:assigns) { { 'my_project' => entry } }
51
- let(:source) { "{% with_scope project: my_project %}{% assign conditions = with_scope %}{% endwith_scope %}" }
47
+ describe 'decode regexps' do
52
48
 
53
- it { expect(conditions['project']).to eq 'entity' }
49
+ let(:source) { "{% with_scope title: /Like this one|or this one/ %}{% assign conditions = with_scope %}{% endwith_scope %}" }
50
+ it { expect(conditions['title']).to eq(/Like this one|or this one/) }
54
51
 
55
- context 'an array of content entries' do
52
+ end
56
53
 
57
- let(:source) { "{% with_scope project: [my_project, my_project, my_project] %}{% assign conditions = with_scope %}{% endwith_scope %}" }
54
+ describe 'decode regexps with case-insensitive' do
58
55
 
59
- it { expect(conditions['project']).to eq ['entity', 'entity', 'entity'] }
56
+ let(:source) { "{% with_scope title: /like this/ix %}{% assign conditions = with_scope %}{% endwith_scope %}" }
57
+ it { expect(conditions['title']).to eq(/like this/ix) }
60
58
 
61
59
  end
62
60
 
63
- end
61
+ describe 'decode content entry' do
64
62
 
65
- describe 'decode context variable' do
63
+ let(:entry) {
64
+ instance_double('ContentEntry', _id: 1, _source: 'entity').tap do |_entry|
65
+ allow(_entry).to receive(:to_liquid).and_return(_entry)
66
+ end }
67
+ let(:assigns) { { 'my_project' => entry } }
68
+ let(:source) { "{% with_scope project: my_project %}{% assign conditions = with_scope %}{% endwith_scope %}" }
66
69
 
67
- let(:assigns) { { 'params' => { 'type' => 'posts' } } }
68
- let(:source) { "{% with_scope category: params.type %}{% assign conditions = with_scope %}{% endwith_scope %}" }
69
- it { expect(conditions['category']).to eq 'posts' }
70
+ it { expect(conditions['project']).to eq 'entity' }
70
71
 
71
- end
72
+ context 'an array of content entries' do
72
73
 
73
- describe 'decode a regexp stored in a context variable' do
74
+ let(:source) { "{% with_scope project: [my_project, my_project, my_project] %}{% assign conditions = with_scope %}{% endwith_scope %}" }
74
75
 
75
- let(:assigns) { { 'my_regexp' => '/^Hello World/' } }
76
- let(:source) { "{% with_scope title: my_regexp %}{% assign conditions = with_scope %}{% endwith_scope %}" }
77
- it { expect(conditions['title']).to eq(/^Hello World/) }
76
+ it { expect(conditions['project']).to eq ['entity', 'entity', 'entity'] }
78
77
 
79
- end
78
+ end
80
79
 
81
- describe 'decode a regexp stored in a context variable, with case-insensitive' do
80
+ end
82
81
 
83
- let(:assigns) { { 'my_regexp' => '/^hello world/ix' } }
84
- let(:source) { "{% with_scope title: my_regexp %}{% assign conditions = with_scope %}{% endwith_scope %}" }
85
- it { expect(conditions['title']).to eq(/^hello world/ix) }
82
+ describe 'decode context variable' do
86
83
 
87
- end
84
+ let(:assigns) { { 'params' => { 'type' => 'posts' } } }
85
+ let(:source) { "{% with_scope category: params.type %}{% assign conditions = with_scope %}{% endwith_scope %}" }
86
+ it { expect(conditions['category']).to eq 'posts' }
88
87
 
89
- describe 'allow order_by option' do
88
+ end
90
89
 
91
- let(:source) { "{% with_scope order_by:\'name DESC\' %}{% assign conditions = with_scope %}{% endwith_scope %}" }
92
- it { expect(conditions['order_by']).to eq 'name DESC' }
90
+ describe 'decode a regexp stored in a context variable' do
93
91
 
94
- end
92
+ let(:assigns) { { 'my_regexp' => '/^Hello World/' } }
93
+ let(:source) { "{% with_scope title: my_regexp %}{% assign conditions = with_scope %}{% endwith_scope %}" }
94
+ it { expect(conditions['title']).to eq(/^Hello World/) }
95
95
 
96
- describe 'replace _permalink by _slug' do
96
+ end
97
97
 
98
- let(:source) { "{% with_scope _permalink: 'foo' %}{% assign conditions = with_scope %}{% endwith_scope %}" }
99
- it { expect(conditions['_slug']).to eq 'foo' }
98
+ describe 'decode a regexp stored in a context variable, with case-insensitive' do
100
99
 
101
- end
100
+ let(:assigns) { { 'my_regexp' => '/^hello world/ix' } }
101
+ let(:source) { "{% with_scope title: my_regexp %}{% assign conditions = with_scope %}{% endwith_scope %}" }
102
+ it { expect(conditions['title']).to eq(/^hello world/ix) }
103
+
104
+ end
105
+
106
+ describe 'allow order_by option' do
107
+
108
+ let(:source) { "{% with_scope order_by:\'name DESC\' %}{% assign conditions = with_scope %}{% endwith_scope %}" }
109
+ it { expect(conditions['order_by']).to eq 'name DESC' }
110
+
111
+ end
112
+
113
+ describe 'replace _permalink by _slug' do
102
114
 
103
- describe 'decode criteria with gt and lt' do
115
+ let(:source) { "{% with_scope _permalink: 'foo' %}{% assign conditions = with_scope %}{% endwith_scope %}" }
116
+ it { expect(conditions['_slug']).to eq 'foo' }
117
+
118
+ end
104
119
 
105
- let(:source) { "{% with_scope price.gt:42.0, price.lt:50 %}{% assign conditions = with_scope %}{% endwith_scope %}" }
106
- it { expect(conditions['price.gt']).to eq 42.0 }
107
- it { expect(conditions['price.lt']).to eq 50 }
120
+ describe 'decode criteria with gt and lt' do
121
+
122
+ let(:source) { "{% with_scope price.gt:42.0, price.lt:50, published_at.lte: '2019-09-10 00:00:00' %}{% assign conditions = with_scope %}{% endwith_scope %}" }
123
+ it { expect(conditions['price.gt']).to eq 42.0 }
124
+ it { expect(conditions['price.lt']).to eq 50 }
125
+ it { expect(conditions['published_at.lte']).to eq '2019-09-10 00:00:00' }
126
+
127
+ end
108
128
 
109
129
  end
110
130