fix the broken specs
Didier Lafforgue
committed May 23, 2018
commit 57f98d30c4113d3d67aa41fe1711ab2ea2f1ab27
Showing 4
changed files with
14 additions
and 10 deletions
locomotive/steam/liquid/tags/section.rb b/lib/locomotive/steam/liquid/tags/section.rb
+1
-1
| @@ | @@ -20,7 +20,7 @@ module Locomotive |
| section = find_section(context) | |
| # 3. since it's considered as static, get the content from the current site. | |
| - | section_content = context['site']&.sections_content&.fetch(@section_type, nil) |
| + | section_content = context.registers[:site]&.sections_content&.fetch(@section_type, nil) |
| # 4. enhance the context by setting the "section" variable | |
| context['section'] = Locomotive::Steam::Liquid::Drops::Section.new( | |
locomotive/steam/middlewares/concerns/liquid_context.rb b/lib/locomotive/steam/middlewares/concerns/liquid_context.rb
+6
-4
| @@ | @@ -2,6 +2,8 @@ module Locomotive::Steam |
| module Middlewares | |
| module Concerns::LiquidContext | |
| + | private |
| + | |
| def liquid_context | |
| ::Liquid::Context.new(liquid_assigns, {}, liquid_registers, true) | |
| end | |
| @@ | @@ -42,13 +44,13 @@ module Locomotive::Steam |
| def _steam_liquid_assigns | |
| { | |
| - | 'site' => nil, |
| - | 'page' => nil, |
| + | 'site' => site.to_liquid, |
| + | 'page' => page.to_liquid, |
| 'models' => Locomotive::Steam::Liquid::Drops::ContentTypes.new, | |
| 'contents' => Locomotive::Steam::Liquid::Drops::ContentTypes.new, | |
| 'current_user' => {}, | |
| 'session' => Locomotive::Steam::Liquid::Drops::SessionProxy.new, | |
| - | } |
| + | }.merge(env['steam.liquid_assigns']) |
| end | |
| def _locale_liquid_assigns | |
| @@ | @@ -86,4 +88,4 @@ module Locomotive::Steam |
| end | |
| end | |
| - | end |
| \ No newline at end of file | |
| + | end |
locomotive/steam/server.rb b/lib/locomotive/steam/server.rb
+1
-0
| @@ | @@ -54,6 +54,7 @@ module Locomotive::Steam |
| [ | |
| Middlewares::DefaultEnv, | |
| Middlewares::Site, | |
| + | Middlewares::Section, |
| Middlewares::Logging, | |
| Middlewares::UrlRedirection, | |
| Middlewares::Robots, | |
spec/unit/middlewares/section_spec.rb
+6
-5
| @@ | @@ -11,7 +11,7 @@ describe Locomotive::Steam::Middlewares::Section do |
| let(:url) { 'http://example.com/_sections/header' } | |
| let(:env) { env_for(url, 'steam.site' => site) } | |
| - | let(:site) { instance_double('Site', default_locale: 'en', locales: ['en'], to_liquid: '') } |
| + | let(:site) { instance_double('Site', default_locale: 'en', locales: ['en'], sections_content: {}, to_liquid: '') } |
| let(:section) { instance_double('Section', type: 'fancy_section', definition: {}, liquid_source: 'Here some HTML') } | |
| let(:section_finder) { instance_double('SectionFinderService') } | |
| let(:repositories) { instance_double('Repositories')} | |
| @@ | @@ -24,10 +24,11 @@ describe Locomotive::Steam::Middlewares::Section do |
| } | |
| before do | |
| - | env['steam.page'] = nil |
| - | env['steam.services'] = services |
| - | env['steam.locale'] = :en |
| - | env['steam.request'] = Rack::Request.new(env) |
| + | env['steam.page'] = nil |
| + | env['steam.services'] = services |
| + | env['steam.locale'] = :en |
| + | env['steam.request'] = Rack::Request.new(env) |
| + | env['steam.liquid_assigns'] = {} |
| allow(section_finder).to receive(:find).with('header').and_return(section) | |
| end | |