locomotivecms_steam 1.5.0.beta2 → 1.5.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +22 -23
  3. data/lib/locomotive/steam/adapters/filesystem/sanitizers/content_entry.rb +14 -0
  4. data/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +2 -2
  5. data/lib/locomotive/steam/adapters/memory/query.rb +1 -0
  6. data/lib/locomotive/steam/liquid/drops/params.rb +4 -0
  7. data/lib/locomotive/steam/liquid/drops/section.rb +4 -0
  8. data/lib/locomotive/steam/liquid/tags/concerns/section.rb +2 -1
  9. data/lib/locomotive/steam/liquid/tags/sections_dropzone.rb +1 -1
  10. data/lib/locomotive/steam/middlewares/concerns/helpers.rb +7 -1
  11. data/lib/locomotive/steam/middlewares/concerns/liquid_context.rb +1 -1
  12. data/lib/locomotive/steam/middlewares/locale.rb +1 -1
  13. data/lib/locomotive/steam/middlewares/page.rb +1 -1
  14. data/lib/locomotive/steam/middlewares/robots.rb +3 -5
  15. data/lib/locomotive/steam/repositories/content_entry_repository.rb +16 -0
  16. data/lib/locomotive/steam/repositories/translation_repository.rb +7 -0
  17. data/lib/locomotive/steam/services/translator_service.rb +5 -1
  18. data/lib/locomotive/steam/services/url_finder_service.rb +15 -4
  19. data/lib/locomotive/steam/version.rb +1 -1
  20. data/locomotivecms_steam.gemspec +1 -2
  21. data/spec/integration/liquid/filters/translate_spec.rb +2 -2
  22. data/spec/integration/repositories/content_entry_repository_spec.rb +20 -0
  23. data/spec/integration/repositories/translation_repository_spec.rb +7 -0
  24. data/spec/integration/services/external_api_service_spec.rb +18 -10
  25. data/spec/unit/liquid/drops/params_spec.rb +16 -0
  26. data/spec/unit/liquid/tags/global_section_spec.rb +7 -7
  27. data/spec/unit/liquid/tags/section_spec.rb +9 -0
  28. data/spec/unit/liquid/tags/sections_dropzone_spec.rb +5 -0
  29. data/spec/unit/middlewares/locale_spec.rb +16 -8
  30. data/spec/unit/middlewares/section_spec.rb +2 -2
  31. data/spec/unit/middlewares/url_redirection_spec.rb +9 -0
  32. data/spec/unit/repositories/content_entry_repository_spec.rb +7 -0
  33. data/spec/unit/services/translator_service_spec.rb +11 -11
  34. data/spec/unit/services/url_finder_service_spec.rb +17 -4
  35. metadata +4 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 612050310b274060e06a38a72ec026c69b071f3166d6453e2d7f4a8242a3cda1
4
- data.tar.gz: 5d92a727d6a162872eddd102d560e0c7840a7fc5142a12907f19411e07793955
3
+ metadata.gz: bd4a12f87c87fc5603766c1b2358615b820c4c74a1de3808afc1446289883337
4
+ data.tar.gz: e1c94bb3d492bd893409cd491fb74093666958286544a6f7bea749d5786ae508
5
5
  SHA512:
6
- metadata.gz: e9be228b111d043a33b745dcc7bdf7408cf3651d377183394d7c779067186c0e064f0fed97e66cceceeb791b8b1eeebc61af4e959342b0c6975e5720cf8a7ea7
7
- data.tar.gz: cc472030e4d96fcd1ca0ef278fb8f9d4a58a502db6a06fad8d1ea1f733272329e057cbe57effa8d18cdb78ffa3bc14d1113181d7ed276d8266d97a65885ffd29
6
+ metadata.gz: 4413660fd7eb9284d6c92b88830864e7507d8757f1edc198628131c889d48c5373c68e54749b6c15b1964d19536215d7e7247344bd8784cd1aae7c48f48f5afc
7
+ data.tar.gz: 2ef38c06b49efc2a5e3923db8935c5483618baf62f0f38699139aa339b29dbc05995eecbb7333ccca32ae20f1954dd9d535ee14cffab5fa0907516d2a3987295
@@ -12,14 +12,14 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- locomotivecms_steam (1.5.0.beta2)
15
+ locomotivecms_steam (1.5.0.beta3)
16
16
  RedCloth (~> 4.3.2)
17
17
  autoprefixer-rails (~> 8.0.0)
18
18
  bcrypt (~> 3.1.11)
19
19
  chronic (~> 0.10.2)
20
20
  coffee-script (~> 2.4.1)
21
21
  compass (~> 1.0.3)
22
- dragonfly (~> 1.1.4)
22
+ dragonfly (~> 1.2.0)
23
23
  duktape (~> 1.6.1.0)
24
24
  httparty (~> 0.16.0)
25
25
  kramdown (~> 1.16.2)
@@ -44,18 +44,18 @@ GEM
44
44
  remote: https://rubygems.org/
45
45
  specs:
46
46
  RedCloth (4.3.2)
47
- activesupport (5.2.1)
47
+ activesupport (5.2.2)
48
48
  concurrent-ruby (~> 1.0, >= 1.0.2)
49
49
  i18n (>= 0.7, < 2)
50
50
  minitest (~> 5.1)
51
51
  tzinfo (~> 1.1)
52
- addressable (2.5.2)
52
+ addressable (2.6.0)
53
53
  public_suffix (>= 2.0.2, < 4.0)
54
54
  attr_extras (5.2.0)
55
55
  autoprefixer-rails (8.0.0)
56
56
  execjs
57
57
  bcrypt (3.1.12)
58
- bson (4.3.0)
58
+ bson (4.4.2)
59
59
  chronic (0.10.2)
60
60
  chunky_png (1.3.11)
61
61
  codeclimate-test-reporter (0.4.8)
@@ -77,7 +77,7 @@ GEM
77
77
  sass (>= 3.3.0, < 3.5)
78
78
  compass-import-once (1.0.5)
79
79
  sass (>= 3.2, < 3.5)
80
- concurrent-ruby (1.0.5)
80
+ concurrent-ruby (1.1.4)
81
81
  coveralls (0.8.22)
82
82
  json (>= 1.8, < 3)
83
83
  simplecov (~> 0.16.1)
@@ -87,27 +87,27 @@ GEM
87
87
  crass (1.0.4)
88
88
  diff-lcs (1.3)
89
89
  docile (1.3.1)
90
- dragonfly (1.1.5)
90
+ dragonfly (1.2.0)
91
91
  addressable (~> 2.3)
92
92
  multi_json (~> 1.0)
93
93
  rack (>= 1.3)
94
94
  duktape (1.6.1.0)
95
95
  execjs (2.7.0)
96
- ffi (1.9.25)
96
+ ffi (1.10.0)
97
97
  flamegraph (0.9.5)
98
98
  haml (5.0.4)
99
99
  temple (>= 0.8.0)
100
100
  tilt
101
- httparty (0.16.3)
101
+ httparty (0.16.4)
102
102
  mime-types (~> 3.0)
103
103
  multi_xml (>= 0.5.2)
104
- i18n (1.1.0)
104
+ i18n (1.5.3)
105
105
  concurrent-ruby (~> 1.0)
106
106
  i18n-spec (0.6.0)
107
107
  iso
108
108
  iso (0.2.2)
109
109
  i18n
110
- json (2.1.0)
110
+ json (2.2.0)
111
111
  json_spec (1.1.5)
112
112
  multi_json (~> 1.0)
113
113
  rspec (>= 2.0, < 4.0)
@@ -117,7 +117,7 @@ GEM
117
117
  locomotivecms-liquid (~> 4.0.0)
118
118
  mail (2.7.1)
119
119
  mini_mime (>= 0.1.1)
120
- memory_profiler (0.9.11)
120
+ memory_profiler (0.9.12)
121
121
  mime-types (3.1)
122
122
  mime-types-data (~> 3.2015)
123
123
  mime-types-data (3.2018.0812)
@@ -136,11 +136,11 @@ GEM
136
136
  nokogumbo (1.5.0)
137
137
  nokogiri
138
138
  origin (2.3.1)
139
- pony (1.12)
139
+ pony (1.13)
140
140
  mail (>= 2.0)
141
141
  public_suffix (3.0.3)
142
142
  puma (3.12.0)
143
- rack (2.0.5)
143
+ rack (2.0.6)
144
144
  rack-cache (1.7.2)
145
145
  rack (>= 0.4)
146
146
  rack-mini-profiler (0.10.7)
@@ -150,10 +150,10 @@ GEM
150
150
  rack (>= 1.0, < 3)
151
151
  rack_csrf (2.6.0)
152
152
  rack (>= 1.1.0)
153
- rake (12.3.1)
153
+ rake (12.3.2)
154
154
  rb-fsevent (0.10.3)
155
- rb-inotify (0.9.10)
156
- ffi (>= 0.5.0, < 2)
155
+ rb-inotify (0.10.0)
156
+ ffi (~> 1.0)
157
157
  rspec (3.7.0)
158
158
  rspec-core (~> 3.7.0)
159
159
  rspec-expectations (~> 3.7.0)
@@ -181,15 +181,15 @@ GEM
181
181
  concurrent-ruby (~> 1.0)
182
182
  rack (> 1, < 3)
183
183
  stackprof (0.2.12)
184
- stringex (2.8.4)
184
+ stringex (2.8.5)
185
185
  temple (0.8.0)
186
- term-ansicolor (1.6.0)
186
+ term-ansicolor (1.7.1)
187
187
  tins (~> 1.0)
188
188
  thor (0.19.4)
189
189
  thread_safe (0.3.6)
190
- tilt (2.0.8)
190
+ tilt (2.0.9)
191
191
  timecop (0.9.1)
192
- tins (1.16.3)
192
+ tins (1.20.2)
193
193
  tzinfo (1.2.5)
194
194
  thread_safe (~> 0.1)
195
195
  uglifier (4.1.20)
@@ -199,7 +199,6 @@ PLATFORMS
199
199
  ruby
200
200
 
201
201
  DEPENDENCIES
202
- bundler (~> 1.16.1)
203
202
  codeclimate-test-reporter (~> 0.4.7)
204
203
  coveralls (~> 0.8.1)
205
204
  flamegraph
@@ -223,4 +222,4 @@ RUBY VERSION
223
222
  ruby 2.5.0p0
224
223
 
225
224
  BUNDLED WITH
226
- 1.16.1
225
+ 1.17.3
@@ -10,6 +10,10 @@ module Locomotive::Steam
10
10
  def apply_to_entity(entity)
11
11
  super
12
12
  add_label(entity)
13
+
14
+ locales.each do |locale|
15
+ set_automatic_translations(entity, locale)
16
+ end
13
17
  end
14
18
 
15
19
  def apply_to_dataset(dataset)
@@ -23,6 +27,7 @@ module Locomotive::Steam
23
27
  # Note: this statement attaches the site to the entity
24
28
  apply_to_entity(entity)
25
29
 
30
+
26
31
  # make sure it gets an unique slug and an _id + set default values
27
32
  _apply_to_dataset(entity, dataset)
28
33
  end
@@ -57,6 +62,15 @@ module Locomotive::Steam
57
62
  end
58
63
  end
59
64
 
65
+ def set_automatic_translations(entity, locale)
66
+ return if locale == default_locale
67
+
68
+ entity.localized_attributes.each do |(name, _)|
69
+ next if entity[name].blank?
70
+ entity[name][locale] ||= entity[name][default_locale]
71
+ end
72
+ end
73
+
60
74
  def set_default_values(entity)
61
75
  each_field_with_default(entity) do |field|
62
76
  name = field.type == 'select' ? "#{field.name}_id" : field.name
@@ -10,7 +10,7 @@ module Locomotive::Steam
10
10
  def setup(scope)
11
11
  super.tap do
12
12
  @ids, @parent_ids, @templatized_ids = {}, {}, {}
13
- @localized = locales.inject({}) { |m, l| m[l] = {}; m }
13
+ @localized = locales.inject({}) { |m, l| m[l] = {}; m }
14
14
  end
15
15
  end
16
16
 
@@ -91,7 +91,7 @@ module Locomotive::Steam
91
91
  end
92
92
 
93
93
  def set_automatic_translations(page, locale)
94
- return if locale == self.locale
94
+ return if locale == default_locale
95
95
 
96
96
  if page[:template_path][locale].blank?
97
97
  %i(
@@ -38,6 +38,7 @@ module Locomotive::Steam
38
38
 
39
39
  def order_by(*args)
40
40
  @sorting = Order.new(*args)
41
+ self
41
42
  end
42
43
 
43
44
  def limit(num)
@@ -13,6 +13,10 @@ module Locomotive
13
13
  Param.new(@_params[meth.to_s])
14
14
  end
15
15
 
16
+ def unsafe
17
+ @_params
18
+ end
19
+
16
20
  def as_json
17
21
  @_params.as_json
18
22
  end
@@ -38,6 +38,10 @@ module Locomotive
38
38
  @section.definition['class']
39
39
  end
40
40
 
41
+ def anchor
42
+ @content['anchor'] || id
43
+ end
44
+
41
45
  def blocks
42
46
  (@content['blocks'] || []).each_with_index.map do |block, index|
43
47
  SectionBlock.new(@section, block, index)
@@ -36,11 +36,12 @@ module Locomotive::Steam::Liquid::Tags::Concerns
36
36
  # we need the section_css_class once
37
37
  context.scopes.last.delete('section_css_class')
38
38
 
39
+ anchor_id = %(id="#{section.anchor}-section")
39
40
  tag_id = %(id="locomotive-section-#{section.id}")
40
41
  tag_class = %(class="#{['locomotive-section', section.css_class, css_class].compact.join(' ')}")
41
42
  tag_data = %(data-locomotive-section-type="#{section.type}")
42
43
 
43
- %(<div #{tag_id} #{tag_class} #{tag_data}>#{html}</div>)
44
+ %(<div #{tag_id} #{tag_class} #{tag_data}><span #{anchor_id}></span>#{html}</div>)
44
45
  end
45
46
 
46
47
  # in order to enable string/text synchronization with the editor:
@@ -21,7 +21,7 @@ module Locomotive
21
21
 
22
22
  next if section.nil? # the section doesn't exist anymore?
23
23
 
24
- # assign a new dom_id to the section
24
+ # assign a new dom_id to the section if it doesn't have one
25
25
  content['id'] = "dropzone-#{index}"
26
26
 
27
27
  # parse the template of the section
@@ -14,7 +14,13 @@ module Locomotive::Steam
14
14
  end
15
15
 
16
16
  def render_response(content, code = 200, type = nil)
17
- @next_response = [code, { 'Content-Type' => type || 'text/html' }, [content]]
17
+ _headers = env['steam.headers'] || {}
18
+
19
+ @next_response = [
20
+ code,
21
+ { 'Content-Type' => type || 'text/html' }.merge(_headers),
22
+ [content]
23
+ ]
18
24
  end
19
25
 
20
26
  def redirect_to(location, type = 301)
@@ -80,7 +80,7 @@ module Locomotive::Steam
80
80
 
81
81
  def _http_actions_liquid_assigns
82
82
  {
83
- 'head?' => request.head?,
83
+ 'head?' => request.head?,
84
84
  'get?' => request.get?,
85
85
  'post?' => request.post?,
86
86
  'put?' => request.put?,
@@ -57,7 +57,7 @@ module Locomotive::Steam
57
57
  locale = $1
58
58
 
59
59
  # no need to keep the locale in the path used to fetch the page
60
- env['steam.path'] = path.gsub($1 + $2, '')
60
+ env['steam.path'] = path.gsub(/^\/#{$1 + $2}/, '/')
61
61
  env['steam.locale_in_path'] = true
62
62
 
63
63
  log 'Locale extracted from the path'
@@ -16,7 +16,7 @@ module Locomotive::Steam
16
16
  log "Found page \"#{page.title}\" [#{page.fullpath}]"
17
17
  else
18
18
  ActiveSupport::Notifications.instrument('steam.render.page_not_found', path: path, locale: locale, default_locale: default_locale)
19
- log "Page not found, rendering the 404 page.".magenta
19
+ log "Page not found (#{path.inspect}), rendering the 404 page.".magenta
20
20
  end
21
21
  end
22
22
 
@@ -1,18 +1,16 @@
1
1
  module Locomotive::Steam
2
2
  module Middlewares
3
3
 
4
- class Robots
4
+ class Robots < ThreadSafe
5
5
 
6
6
  include Concerns::Helpers
7
7
 
8
- attr_accessor_initialize :app
9
-
10
- def call(env)
8
+ def _call
11
9
  if env['PATH_INFO'] == '/robots.txt'
12
10
  site = env['steam.site']
13
11
  render_response(site[:robots_txt] || '', 200, 'text/plain')
14
12
  else
15
- app.call(env)
13
+ self.next
16
14
  end
17
15
  end
18
16
 
@@ -61,6 +61,14 @@ module Locomotive
61
61
  first { where(conditions) }
62
62
  end
63
63
 
64
+ def first(&block)
65
+ all({}, &block).first
66
+ end
67
+
68
+ def last(&block)
69
+ all({}, &block).last
70
+ end
71
+
64
72
  def exists?(conditions = {})
65
73
  conditions, _ = conditions_without_order_by(conditions)
66
74
  query { where(conditions) }.all.size > 0
@@ -214,6 +222,12 @@ module Locomotive
214
222
  end
215
223
 
216
224
  def prepare
225
+ # _id (primary key)
226
+ _prepare([Locomotive::Steam::ContentTypeField.new(name: '_id')]) do |_, value|
227
+ @target_repository.adapter.make_id(value)
228
+ end
229
+
230
+ # select
217
231
  _prepare(@fields.selects) do |field, value|
218
232
  # FIXME: [only in Wagon], if the user changes the locale, since all content is stored in memory,
219
233
  # we have to change the locale in the repository used to fetch the select options.
@@ -278,6 +292,8 @@ module Locomotive
278
292
  end
279
293
 
280
294
  def slug_to_id(slug, target_id)
295
+ return nil if slug.blank?
296
+
281
297
  if _repository = @target_repository.with(target_id)
282
298
  _entry = _repository.first { where(_slug: slug).only(:_id) }
283
299
  _entry.try(:_id)
@@ -8,6 +8,13 @@ module Locomotive
8
8
  # Entity mapping
9
9
  mapping :translations, entity: Translation
10
10
 
11
+ def group_by_key
12
+ all { only(:key, :values) }.inject({}) do |memo, translation|
13
+ memo[translation.key] = translation.values
14
+ memo
15
+ end
16
+ end
17
+
11
18
  def by_key(key)
12
19
  first { where(key: key) }
13
20
  end
@@ -19,7 +19,7 @@ module Locomotive
19
19
  if scope.blank?
20
20
  input = "#{input}_#{pluralize_prefix(options['count'])}" if options['count']
21
21
 
22
- values = repository.by_key(input).try(:values) || {}
22
+ values = find_values_by_key(input)
23
23
 
24
24
  # FIXME: important to check if the returned value is nil (instead of nil + false)
25
25
  # false being reserved for an existing key but without provided translation)
@@ -37,6 +37,10 @@ module Locomotive
37
37
 
38
38
  private
39
39
 
40
+ def find_values_by_key(input)
41
+ (@all_values ||= repository.group_by_key)[input] || {}
42
+ end
43
+
40
44
  def _translate(string, options)
41
45
  ::Liquid::Template.parse(string).render(options)
42
46
  end
@@ -16,10 +16,11 @@ module Locomotive
16
16
  # 'type' => 'page',
17
17
  # 'value' => '42', # id of the home page
18
18
  # 'locale' => 'en',
19
- # 'new_window' => true
19
+ # 'new_window' => true,
20
+ # 'anchor' => 'portfolio'
20
21
  # })
21
22
  #
22
- # will return: ['/', true]
23
+ # will return: ['/#portfolio', true]
23
24
  #
24
25
  def url_for(resource)
25
26
  return [resource, false] if resource.is_a?(String)
@@ -27,8 +28,16 @@ module Locomotive
27
28
  _resource = resource || {}
28
29
  page_or_url = find_page(_resource['type'], _resource['value']) || page_finder.find('404')
29
30
 
31
+ url = if page_or_url.is_a?(String)
32
+ page_or_url
33
+ elsif !page_or_url.not_found?
34
+ [url_builder.url_for(page_or_url), _resource['anchor'].presence].compact.join('#')
35
+ else
36
+ url_builder.url_for(page_or_url)
37
+ end
38
+
30
39
  [
31
- page_or_url.is_a?(String) ? page_or_url : url_builder.url_for(page_or_url),
40
+ url,
32
41
  _resource['new_window'] || false
33
42
  ]
34
43
  end
@@ -59,7 +68,7 @@ module Locomotive
59
68
  # Based on the type of the resource, it returns either:
60
69
  # - a simple page
61
70
  # - a templatized page with its related content entry attached
62
- # - nil if external url
71
+ # - the value itself if external url
63
72
  def find_page(type, value)
64
73
  case type
65
74
  when 'page'
@@ -76,6 +85,8 @@ module Locomotive
76
85
  end
77
86
  when '_external'
78
87
  value
88
+ when 'email'
89
+ "mailto:#{value}"
79
90
  else
80
91
  nil
81
92
  end
@@ -3,6 +3,6 @@
3
3
  # 1.0.0.alpha < 1.0.0.alpha1 < 1.0.0.beta < 1.0.0.beta2 < 1.0.0.beta11 < 1.0.0.rc1 < 1.0.0
4
4
  module Locomotive
5
5
  module Steam
6
- VERSION = '1.5.0.beta2'
6
+ VERSION = '1.5.0.beta3'
7
7
  end
8
8
  end
@@ -15,7 +15,6 @@ Gem::Specification.new do |spec|
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ['lib']
17
17
 
18
- spec.add_development_dependency 'bundler', '~> 1.16.1'
19
18
  spec.add_development_dependency 'rake', '~> 12.3.0'
20
19
 
21
20
  spec.add_development_dependency 'mongo', '~> 2.5.1'
@@ -32,7 +31,7 @@ Gem::Specification.new do |spec|
32
31
  spec.add_dependency 'rack-rewrite', '~> 1.5.1'
33
32
  spec.add_dependency 'rack-cache', '~> 1.7.0'
34
33
  spec.add_dependency 'rack_csrf', '~> 2.6.0'
35
- spec.add_dependency 'dragonfly', '~> 1.1.4'
34
+ spec.add_dependency 'dragonfly', '~> 1.2.0'
36
35
  spec.add_dependency 'moneta', '~> 1.0.0'
37
36
 
38
37
  spec.add_dependency 'sprockets', '~> 3.7.1'
@@ -52,8 +52,8 @@ describe Locomotive::Steam::Liquid::Filters::Translate do
52
52
 
53
53
  describe 'pluralization' do
54
54
 
55
- let(:translation) { instance_double('Translation', values: { 'en' => '{{ name }} has {{ count }} articles' }) }
56
- before { expect(translator.repository).to receive(:by_key).with('post_count_two').and_return(translation) }
55
+ let(:translation) { { 'en' => '{{ name }} has {{ count }} articles' } }
56
+ before { expect(translator.repository).to receive(:group_by_key).and_return({ 'post_count_two' => translation }) }
57
57
 
58
58
  let(:source) { "{{ 'post_count' | translate: count: 2, name: 'John' }}" }
59
59
  it { expect(subject).to eq('John has 2 articles') }
@@ -35,6 +35,16 @@ describe Locomotive::Steam::ContentEntryRepository do
35
35
  it { is_expected.to eq true }
36
36
  end
37
37
 
38
+ describe '#first' do
39
+ subject { repository.first }
40
+ it { expect(subject.name).to eq 'Alice in Chains' }
41
+ end
42
+
43
+ describe '#last' do
44
+ subject { repository.last }
45
+ it { expect(subject.name).to eq 'The who' }
46
+ end
47
+
38
48
  describe '#find' do
39
49
  subject { repository.find(entry_id) }
40
50
  it { expect(subject.name).to eq 'Pearl Jam' }
@@ -52,6 +62,11 @@ describe Locomotive::Steam::ContentEntryRepository do
52
62
  it { expect(subject.name).to eq 'Alice in Chains' }
53
63
  end
54
64
 
65
+ describe 'filter by an _id (string)' do
66
+ subject { repository.all(_id: entry_id.to_s) }
67
+ it { expect(subject.map { |entry| entry[:name] }).to eq(['Pearl Jam']) }
68
+ end
69
+
55
70
  describe 'filter by a select field' do
56
71
  subject { repository.all(kind: 'grunge') }
57
72
  it { expect(subject.map { |entry| entry[:name] }).to eq(['Alice in Chains', 'Pearl Jam']) }
@@ -60,6 +75,11 @@ describe Locomotive::Steam::ContentEntryRepository do
60
75
  describe 'filter by a belongs_to field' do
61
76
  subject { target_repository.all(band: 'the-who') }
62
77
  it { expect(subject.map { |entry| entry[:title] }).to eq(['Song #5', 'Song #6']) }
78
+ context 'looking for a nil value and in a different locale' do
79
+ before { target_repository.scope.locale = :fr }
80
+ subject { target_repository.all(band: nil) }
81
+ it { expect(subject.size).to eq 2 }
82
+ end
63
83
  end
64
84
 
65
85
  describe '#group_by_select_option' do
@@ -16,6 +16,13 @@ describe Locomotive::Steam::TranslationRepository do
16
16
  it { expect(subject.size).to eq 8 }
17
17
  end
18
18
 
19
+ describe '#group_by_key' do
20
+ subject { repository.group_by_key }
21
+ it { expect(subject.keys.size).to eq 8 }
22
+ it { expect(subject['powered_by']).to eq({ 'en' => 'Powered by', 'fr' => 'Propulsé par' }) }
23
+ it { expect(subject['auth_wrong_email']).to eq({ 'en' => "Your email is unknown", 'fr' => "Votre email est inconnu" }) }
24
+ end
25
+
19
26
  describe '#by_key' do
20
27
  subject { repository.by_key('powered_by') }
21
28
  it { expect(subject.values).to eq({ 'en' => 'Powered by', 'fr' => 'Propulsé par' }) }
@@ -4,26 +4,34 @@ describe Locomotive::Steam::ExternalAPIService do
4
4
 
5
5
  pending 'API rate limit exceeded'
6
6
 
7
- let(:service) { described_class.new }
7
+ if ENV['TRAVIS'].blank?
8
8
 
9
- describe '#consume' do
9
+ let(:service) { described_class.new }
10
10
 
11
- let(:url) { 'https://api.github.com/users/did/repos' }
12
- let(:options) { { format: "'json'", with_user_agent: true } }
11
+ describe '#consume' do
13
12
 
14
- subject { service.consume(url, options) }
13
+ let(:url) { 'https://api.github.com/users/did/repos' }
14
+ let(:options) { { format: "'json'", with_user_agent: true } }
15
15
 
16
- it { expect(subject.size).to_not eq 0 }
16
+ subject { service.consume(url, options) }
17
17
 
18
- context 'returns the status too' do
18
+ it { expect(subject.size).to_not eq 0 }
19
19
 
20
- subject { service.consume(url, options, true) }
20
+ context 'returns the status too' do
21
21
 
22
- it { expect(subject[:status]).to eq 200 }
23
- it { expect(subject[:data].size).to_not eq 0 }
22
+ subject { service.consume(url, options, true) }
23
+
24
+ it { expect(subject[:status]).to eq 200 }
25
+ it { expect(subject[:data].size).to_not eq 0 }
26
+
27
+ end
24
28
 
25
29
  end
26
30
 
31
+ else
32
+
33
+ pending 'API not available in Travis'
34
+
27
35
  end
28
36
 
29
37
  end
@@ -35,4 +35,20 @@ describe Locomotive::Steam::Liquid::Drops::Params do
35
35
 
36
36
  end
37
37
 
38
+ describe 'gives access to the Hash object through the unsafe method' do
39
+
40
+ let(:params) { { 'foo' => 'hello', 'bar' => 'world' } }
41
+
42
+ it 'expects to respond to []' do
43
+ expect(drop.unsafe['foo']).to eq('hello')
44
+ end
45
+
46
+ it 'expects to respond to each_pair' do
47
+ memo = []
48
+ drop.unsafe.each_pair { |p| memo << p.last }
49
+ expect(memo.join(' ')).to eq 'hello world'
50
+ end
51
+
52
+ end
53
+
38
54
  end
@@ -49,13 +49,13 @@ describe Locomotive::Steam::Liquid::Tags::GlobalSection do
49
49
 
50
50
  let(:liquid_source) { %(built by <a>\n\t<strong>{{ section.settings.brand }}</strong></a>) }
51
51
 
52
- it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <a>\n\t<strong data-locomotive-editor-setting="section-site-header.brand">NoCoffee</strong></a></div>) }
52
+ it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><span id="site-header-section"></span>built by <a>\n\t<strong data-locomotive-editor-setting="section-site-header.brand">NoCoffee</strong></a></div>) }
53
53
 
54
54
  context 'capturing the setting in a liquid variable' do
55
55
 
56
56
  let(:liquid_source) { %({% capture brand %}<strong class="bold">{{ section.settings.brand }}</strong>{% endcapture %}built by <a>\n\t{{ brand }}</a>) }
57
57
 
58
- it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <a>\n\t<strong class="bold" data-locomotive-editor-setting="section-site-header.brand">NoCoffee</strong></a></div>) }
58
+ it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><span id="site-header-section"></span>built by <a>\n\t<strong class="bold" data-locomotive-editor-setting="section-site-header.brand">NoCoffee</strong></a></div>) }
59
59
 
60
60
  end
61
61
 
@@ -64,7 +64,7 @@ describe Locomotive::Steam::Liquid::Tags::GlobalSection do
64
64
 
65
65
  let(:liquid_source) { 'built by <strong>{{ section.settings.image }}</strong>' }
66
66
 
67
- it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <strong>foo.png</strong></div>' }
67
+ it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><span id="site-header-section"></span>built by <strong>foo.png</strong></div>' }
68
68
 
69
69
  end
70
70
 
@@ -72,7 +72,7 @@ describe Locomotive::Steam::Liquid::Tags::GlobalSection do
72
72
 
73
73
  let(:live_editing) { false }
74
74
 
75
- it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <a>\n\t<strong>NoCoffee</strong></a></div>) }
75
+ it { is_expected.to eq %(Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><span id="site-header-section"></span>built by <a>\n\t<strong>NoCoffee</strong></a></div>) }
76
76
 
77
77
  end
78
78
 
@@ -82,13 +82,13 @@ describe Locomotive::Steam::Liquid::Tags::GlobalSection do
82
82
 
83
83
  let(:liquid_source) { '{% for foo in section.blocks %}<a href="/">{{ foo.settings.title }}</a>{% endfor %}' }
84
84
 
85
- it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><a href="/" data-locomotive-editor-setting="section-site-header-block.42.title">Home</a></div>' }
85
+ it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><span id="site-header-section"></span><a href="/" data-locomotive-editor-setting="section-site-header-block.42.title">Home</a></div>' }
86
86
 
87
87
  context 'with a non text type input' do
88
88
 
89
89
  let(:liquid_source) { '{% for foo in section.blocks %}<a>{{ foo.settings.image }}</a>{% endfor %}' }
90
90
 
91
- it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><a>foo.png</a></div>' }
91
+ it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><span id="site-header-section"></span><a>foo.png</a></div>' }
92
92
 
93
93
  end
94
94
 
@@ -106,7 +106,7 @@ describe Locomotive::Steam::Liquid::Tags::GlobalSection do
106
106
 
107
107
  let(:liquid_source) { 'built by <strong>{{ section.settings.brand }}</strong>' }
108
108
 
109
- it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header">built by <strong data-locomotive-editor-setting="section-site-header.brand">Locomotive</strong></div>' }
109
+ it { is_expected.to eq 'Locomotive <div id="locomotive-section-site-header" class="locomotive-section my-awesome-header" data-locomotive-section-type="header"><span id="site-header-section"></span>built by <strong data-locomotive-editor-setting="section-site-header.brand">Locomotive</strong></div>' }
110
110
 
111
111
  end
112
112
 
@@ -65,6 +65,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
65
65
  ' <div id="locomotive-section-page-header"'\
66
66
  ' class="locomotive-section my-awesome-header"'\
67
67
  ' data-locomotive-section-type="header">'\
68
+ '<span id="page-header-section"></span>'\
68
69
  'built by <a>' + %(\n\t) + '<strong data-locomotive-editor-setting="section-page-header.brand">NoCoffee</strong></a>'\
69
70
  '</div>' }
70
71
 
@@ -76,6 +77,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
76
77
  ' <div id="locomotive-section-page-header"'\
77
78
  ' class="locomotive-section my-awesome-header"'\
78
79
  ' data-locomotive-section-type="header">'\
80
+ '<span id="page-header-section"></span>'\
79
81
  'built by <a>' + %(\n\t) + '<strong class="bold" data-locomotive-editor-setting="section-page-header.brand">NoCoffee</strong></a>'\
80
82
  '</div>' }
81
83
 
@@ -89,6 +91,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
89
91
  ' <div id="locomotive-section-page-header"'\
90
92
  ' class="locomotive-section my-awesome-header"'\
91
93
  ' data-locomotive-section-type="header">'\
94
+ '<span id="page-header-section"></span>'\
92
95
  'built by <strong>foo.png</strong>'\
93
96
  '</div>' }
94
97
 
@@ -102,6 +105,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
102
105
  '<div id="locomotive-section-page-header"'\
103
106
  ' class="locomotive-section my-awesome-header"'\
104
107
  ' data-locomotive-section-type="header">'\
108
+ '<span id="page-header-section"></span>'\
105
109
  'built by <a>' + %(\n\t) + '<strong>NoCoffee</strong></a>'\
106
110
  '</div>' }
107
111
 
@@ -117,6 +121,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
117
121
  ' <div id="locomotive-section-page-header"'\
118
122
  ' class="locomotive-section my-awesome-header"'\
119
123
  ' data-locomotive-section-type="header">'\
124
+ '<span id="page-header-section"></span>'\
120
125
  '<a href="/" data-locomotive-editor-setting="section-page-header-block.42.title">Home</a>'\
121
126
  '</div>' }
122
127
 
@@ -128,6 +133,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
128
133
  ' <div id="locomotive-section-page-header"'\
129
134
  ' class="locomotive-section my-awesome-header"'\
130
135
  ' data-locomotive-section-type="header">'\
136
+ '<span id="page-header-section"></span>'\
131
137
  '<a>foo.png</a>'\
132
138
  '</div>' }
133
139
 
@@ -154,6 +160,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
154
160
  '<div id="locomotive-section-page-header"'\
155
161
  ' class="locomotive-section my-awesome-header"'\
156
162
  ' data-locomotive-section-type="header">'\
163
+ '<span id="page-header-section"></span>'\
157
164
  'built by '\
158
165
  '<strong data-locomotive-editor-setting="section-page-header.brand">'\
159
166
  'Locomotive'\
@@ -177,6 +184,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
177
184
  '<div id="locomotive-section-page-my_header" '\
178
185
  'class="locomotive-section my-awesome-header" '\
179
186
  'data-locomotive-section-type="header">'\
187
+ '<span id="page-my_header-section"></span>'\
180
188
  'built by '\
181
189
  '<strong data-locomotive-editor-setting="section-page-my_header.brand">'\
182
190
  'Locomotive'\
@@ -198,6 +206,7 @@ describe Locomotive::Steam::Liquid::Tags::Section do
198
206
  '<div id="locomotive-section-site-header" '\
199
207
  'class="locomotive-section my-awesome-header" '\
200
208
  'data-locomotive-section-type="header">'\
209
+ '<span id="site-header-section"></span>'\
201
210
  'built by '\
202
211
  '<strong data-locomotive-editor-setting="section-site-header.brand">'\
203
212
  'Locomotive'\
@@ -30,11 +30,13 @@ describe Locomotive::Steam::Liquid::Tags::SectionsDropzone do
30
30
  let(:content) { [
31
31
  {
32
32
  type: 'hero',
33
+ anchor: 'hero-1',
33
34
  settings: { title: 'Hello world' },
34
35
  blocks: []
35
36
  }.deep_stringify_keys,
36
37
  {
37
38
  type: 'slideshow',
39
+ anchor: 'slideshow-1',
38
40
  settings: {},
39
41
  blocks: [{ settings: { title: 'Slide 1' } }, { settings: { title: 'Slide 2' } }]
40
42
  }.deep_stringify_keys
@@ -66,12 +68,15 @@ describe Locomotive::Steam::Liquid::Tags::SectionsDropzone do
66
68
  end
67
69
 
68
70
  it 'renders the list of sections' do
71
+ puts is_expected.inspect
69
72
  is_expected.to eq <<-HTML
70
73
  <div class="locomotive-sections">
71
74
  <div id="locomotive-section-dropzone-0" class="locomotive-section" data-locomotive-section-type="hero">
75
+ <span id="hero-1-section"></span>
72
76
  <h1 data-locomotive-editor-setting="section-dropzone-0.title">Hello world</h1>
73
77
  </div>
74
78
  <div id="locomotive-section-dropzone-1" class="locomotive-section" data-locomotive-section-type="slideshow">
79
+ <span id="slideshow-1-section"></span>
75
80
  <div data-locomotive-block="section-dropzone-1-block-0"><p data-locomotive-editor-setting="section-dropzone-1-block.0.title">Slide 1</p></div>
76
81
  <div data-locomotive-block="section-dropzone-1-block-1"><p data-locomotive-editor-setting="section-dropzone-1-block.1.title">Slide 2</p></div>
77
82
  </div>
@@ -23,7 +23,15 @@ describe Locomotive::Steam::Middlewares::Locale do
23
23
  env['steam.request'] = Rack::Request.new(env)
24
24
  env['steam.services'] = services
25
25
  code, env = middleware.call(env)
26
- [env['steam.locale'], session['steam-locale']&.to_sym]
26
+ [env['steam.locale'], session['steam-locale']&.to_sym, env['steam.path']]
27
+ end
28
+
29
+ describe 'locale defined in the path' do
30
+
31
+ let(:url) { 'http://models.example.com/de/hello-de/foo' }
32
+
33
+ it { is_expected.to eq [:de, :de, '/hello-de/foo'] }
34
+
27
35
  end
28
36
 
29
37
  describe 'no locale defined in the path' do
@@ -32,7 +40,7 @@ describe Locomotive::Steam::Middlewares::Locale do
32
40
 
33
41
  context 'without accept-language header' do
34
42
 
35
- it { is_expected.to eq [:de, :de] }
43
+ it { is_expected.to eq [:de, :de, '/'] }
36
44
 
37
45
  end
38
46
 
@@ -40,13 +48,13 @@ describe Locomotive::Steam::Middlewares::Locale do
40
48
 
41
49
  let(:accept_language) { 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7' }
42
50
 
43
- it { is_expected.to eq [:fr, :fr] }
51
+ it { is_expected.to eq [:fr, :fr, '/'] }
44
52
 
45
53
  context 'with url path' do
46
54
 
47
55
  let(:url) { 'http://models.example.com/werkzeug' }
48
56
 
49
- it { is_expected.to eq [:de, :de] }
57
+ it { is_expected.to eq [:de, :de, '/werkzeug'] }
50
58
 
51
59
  end
52
60
 
@@ -58,7 +66,7 @@ describe Locomotive::Steam::Middlewares::Locale do
58
66
 
59
67
  let(:session) { {'steam-locale' => 'en'} }
60
68
 
61
- it { is_expected.to eq [:en, :en] }
69
+ it { is_expected.to eq [:en, :en, '/'] }
62
70
 
63
71
  end
64
72
 
@@ -70,7 +78,7 @@ describe Locomotive::Steam::Middlewares::Locale do
70
78
 
71
79
  let(:url) { 'http://models.example.com?locale=' }
72
80
 
73
- it { is_expected.to eq [:de, :de] }
81
+ it { is_expected.to eq [:de, :de, '/'] }
74
82
 
75
83
  end
76
84
 
@@ -78,7 +86,7 @@ describe Locomotive::Steam::Middlewares::Locale do
78
86
 
79
87
  let(:url) { 'http://models.example.com?locale=en' }
80
88
 
81
- it { is_expected.to eq [:en, :en] }
89
+ it { is_expected.to eq [:en, :en, '/'] }
82
90
 
83
91
  end
84
92
 
@@ -86,7 +94,7 @@ describe Locomotive::Steam::Middlewares::Locale do
86
94
 
87
95
  let(:url) { 'http://models.example.com?locale=onload' }
88
96
 
89
- it { is_expected.to eq [:de, :de] }
97
+ it { is_expected.to eq [:de, :de, '/'] }
90
98
 
91
99
  end
92
100
 
@@ -45,7 +45,7 @@ describe Locomotive::Steam::Middlewares::Section do
45
45
  is_expected.to eq [
46
46
  200,
47
47
  { "Content-Type" => "text/html" },
48
- [%(<div id="locomotive-section-page-header" class="locomotive-section" data-locomotive-section-type="header">Here some </div>)]
48
+ [%(<div id="locomotive-section-page-header" class="locomotive-section" data-locomotive-section-type="header"><span id="page-header-section"></span>Here some </div>)]
49
49
  ]
50
50
  end
51
51
 
@@ -61,7 +61,7 @@ describe Locomotive::Steam::Middlewares::Section do
61
61
  is_expected.to eq [
62
62
  200,
63
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>)]
64
+ [%(<div id="locomotive-section-site-header" class="locomotive-section" data-locomotive-section-type="header"><span id="site-header-section"></span>Here some modified HTML</div>)]
65
65
  ]
66
66
  end
67
67
 
@@ -54,6 +54,15 @@ describe Locomotive::Steam::Middlewares::UrlRedirection do
54
54
 
55
55
  end
56
56
 
57
+ describe 'and redirecting to an external url' do
58
+
59
+ let(:redirections) { [['/foo.php', 'https://rickandmorty.dev']] }
60
+ let(:url) { 'http://models.example.com/foo.php' }
61
+
62
+ it { is_expected.to eq [301, 'https://rickandmorty.dev'] }
63
+
64
+ end
65
+
57
66
  describe 'url matching a pattern' do
58
67
 
59
68
  let(:redirections) { [['/old_images/:file', '/images/old/:file']] }
@@ -451,6 +451,13 @@ describe Locomotive::Steam::ContentEntryRepository do
451
451
 
452
452
  end
453
453
 
454
+ context 'testing a nil value (field => nil)' do
455
+
456
+ let(:value) { nil }
457
+ it { is_expected.to eq([{ _visible: true, content_type_id: 1, 'person_id' => nil }, nil]) }
458
+
459
+ end
460
+
454
461
  context 'testing a nil value (field.ne => nil)' do
455
462
 
456
463
  let(:conditions) { { 'person.ne' => nil } }
@@ -14,14 +14,14 @@ describe Locomotive::Steam::TranslatorService do
14
14
  let(:interpolation) { {} }
15
15
 
16
16
  before do
17
- allow(repository).to receive(:by_key).with('example_test').and_return(translation)
17
+ allow(repository).to receive(:group_by_key).and_return({ 'example_test' => translation })
18
18
  end
19
19
 
20
20
  subject { service.translate(input, interpolation.merge('locale' => locale, 'scope' => scope)) }
21
21
 
22
22
  describe 'existing translation' do
23
23
 
24
- let(:translation) { instance_double('Translation', values: { 'en' => 'Example text', 'es' => 'Texto de ejemplo' }) }
24
+ let(:translation) { { 'en' => 'Example text', 'es' => 'Texto de ejemplo' } }
25
25
 
26
26
  it { is_expected.to eq 'Example text' }
27
27
 
@@ -55,7 +55,7 @@ describe Locomotive::Steam::TranslatorService do
55
55
  describe 'interpolation' do
56
56
 
57
57
  let(:interpolation) { { 'name' => 'John' } }
58
- let(:translation) { instance_double('Translation', values: { 'en' => 'Hello {{ name }}', 'es' => 'Texto de ejemplo' }) }
58
+ let(:translation) { { 'en' => 'Hello {{ name }}', 'es' => 'Texto de ejemplo' } }
59
59
 
60
60
  it { is_expected.to eq 'Hello John' }
61
61
 
@@ -66,9 +66,9 @@ describe Locomotive::Steam::TranslatorService do
66
66
  context 'zero' do
67
67
 
68
68
  let(:interpolation) { { 'count' => '0' } }
69
- let(:translation) { instance_double('Translation', values: { 'en' => 'No posts' }) }
69
+ let(:translation) { { 'en' => 'No posts' } }
70
70
 
71
- before { expect(repository).to receive(:by_key).with('example_test_zero').and_return(translation) }
71
+ before { expect(repository).to receive(:group_by_key).and_return({ 'example_test_zero' => translation }) }
72
72
 
73
73
  it { is_expected.to eq 'No posts' }
74
74
 
@@ -77,9 +77,9 @@ describe Locomotive::Steam::TranslatorService do
77
77
  context 'one' do
78
78
 
79
79
  let(:interpolation) { { 'count' => '1' } }
80
- let(:translation) { instance_double('Translation', values: { 'en' => '1 post' }) }
80
+ let(:translation) { { 'en' => '1 post' } }
81
81
 
82
- before { expect(repository).to receive(:by_key).with('example_test_one').and_return(translation) }
82
+ before { expect(repository).to receive(:group_by_key).and_return({ 'example_test_one' => translation }) }
83
83
 
84
84
  it { is_expected.to eq '1 post' }
85
85
 
@@ -88,9 +88,9 @@ describe Locomotive::Steam::TranslatorService do
88
88
  context 'two' do
89
89
 
90
90
  let(:interpolation) { { 'count' => 2 } }
91
- let(:translation) { instance_double('Translation', values: { 'en' => '2 posts' }) }
91
+ let(:translation) { { 'en' => '2 posts' } }
92
92
 
93
- before { expect(repository).to receive(:by_key).with('example_test_two').and_return(translation) }
93
+ before { expect(repository).to receive(:group_by_key).and_return({ 'example_test_two' => translation }) }
94
94
 
95
95
  it { is_expected.to eq '2 posts' }
96
96
 
@@ -99,9 +99,9 @@ describe Locomotive::Steam::TranslatorService do
99
99
  context 'other' do
100
100
 
101
101
  let(:interpolation) { { 'count' => 42 } }
102
- let(:translation) { instance_double('Translation', values: { 'en' => '{{ count }} posts' }) }
102
+ let(:translation) { { 'en' => '{{ count }} posts' } }
103
103
 
104
- before { expect(repository).to receive(:by_key).with('example_test_other').and_return(translation) }
104
+ before { expect(repository).to receive(:group_by_key).and_return({ 'example_test_other' => translation }) }
105
105
 
106
106
  it { is_expected.to eq '42 posts' }
107
107
 
@@ -25,10 +25,17 @@ describe Locomotive::Steam::UrlFinderService do
25
25
 
26
26
  end
27
27
 
28
+ context 'value is an email address' do
29
+
30
+ let(:value) { { 'type' => 'email', 'value' => 'jane@doe.net', 'new_window' => false } }
31
+ it { is_expected.to eq(['mailto:jane@doe.net', false]) }
32
+
33
+ end
34
+
28
35
  context 'value is a link to a page' do
29
36
 
30
- let(:page) { instance_double('Page') }
31
- let(:value) { { 'type' => 'page', 'value' => 42, 'new_window' => true } }
37
+ let(:page) { instance_double('Page', not_found?: false) }
38
+ let(:value) { { 'type' => 'page', 'value' => 42, 'new_window' => true, 'anchor' => '' } }
32
39
 
33
40
  context 'the page exists' do
34
41
 
@@ -39,6 +46,13 @@ describe Locomotive::Steam::UrlFinderService do
39
46
 
40
47
  it { is_expected.to eq(['/', true]) }
41
48
 
49
+ context 'pointing to a section' do
50
+
51
+ let(:value) { { 'type' => 'page', 'value' => 42, 'anchor' => 'getting-started' } }
52
+ it { is_expected.to eq(['/#getting-started', false]) }
53
+
54
+ end
55
+
42
56
  end
43
57
 
44
58
  context "the page doesn't exist" do
@@ -53,13 +67,12 @@ describe Locomotive::Steam::UrlFinderService do
53
67
 
54
68
  end
55
69
 
56
-
57
70
  end
58
71
 
59
72
  context 'value is a link to a content entry' do
60
73
 
61
74
  let(:entry) { instance_double('Product') }
62
- let(:page) { instance_double('Page', :content_entry= => true) }
75
+ let(:page) { instance_double('Page', :content_entry= => true, not_found?: false) }
63
76
  let(:value) { {
64
77
  'type' => 'content_entry',
65
78
  'value' => { 'page_id' => 42, 'content_type_slug' => 'products', 'id' => 1 },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locomotivecms_steam
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0.beta2
4
+ version: 1.5.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
@@ -11,22 +11,8 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2018-12-10 00:00:00.000000000 Z
14
+ date: 2019-03-06 00:00:00.000000000 Z
15
15
  dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: bundler
18
- requirement: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: 1.16.1
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: 1.16.1
30
16
  - !ruby/object:Gem::Dependency
31
17
  name: rake
32
18
  requirement: !ruby/object:Gem::Requirement
@@ -215,14 +201,14 @@ dependencies:
215
201
  requirements:
216
202
  - - "~>"
217
203
  - !ruby/object:Gem::Version
218
- version: 1.1.4
204
+ version: 1.2.0
219
205
  type: :runtime
220
206
  prerelease: false
221
207
  version_requirements: !ruby/object:Gem::Requirement
222
208
  requirements:
223
209
  - - "~>"
224
210
  - !ruby/object:Gem::Version
225
- version: 1.1.4
211
+ version: 1.2.0
226
212
  - !ruby/object:Gem::Dependency
227
213
  name: moneta
228
214
  requirement: !ruby/object:Gem::Requirement