Add test on Page#path_combinations
Joel AZEMAR
committed Jun 24, 2014
commit 51e31bac1fe7589d6cc55941f0170ba526aa152c
Showing 3
changed files with
40 additions
and 31 deletions
locomotive/steam/middlewares/page.rb b/lib/locomotive/steam/middlewares/page.rb
+1
-4
| @@ | @@ -8,9 +8,7 @@ module Locomotive::Steam |
| def _call(env) | |
| super | |
| - | |
| set_page!(env) | |
| - | |
| app.call(env) | |
| end | |
| @@ | @@ -50,13 +48,12 @@ module Locomotive::Steam |
| def _path_combinations(segments, can_include_template = true) | |
| return nil if segments.empty? | |
| - | |
| segment = segments.shift | |
| (can_include_template ? [segment, '*'] : [segment]).map do |_segment| | |
| if (_combinations = _path_combinations(segments.clone, can_include_template && _segment != '*')) | |
| [*_combinations].map do |_combination| | |
| - | URI.join(_segment, _combination) |
| + | File.join(_segment, _combination) |
| end | |
| else | |
| [_segment] | |
spec/unit/decorators/page_decorator_spec.rb
+8
-8
| @@ | @@ -1,17 +1,17 @@ |
| require 'spec_helper' | |
| describe 'Locomotive::Steam::Decorators::PageDecorator' do | |
| - | |
| let(:locale) { :en } | |
| + | |
| it 'builds an empty decorator' do | |
| build_page.should_not be_nil | |
| end | |
| describe '#safe_fullpath' do | |
| - | let(:index_page) { build_page(fullpath: {en: 'index'}) } |
| - | let(:not_found_page) { build_page(fullpath: {en: '404'}) } |
| - | let(:about_page) { build_page(fullpath: {en: 'about_me'}, parent: index_page) } |
| - | let(:products_page) { build_page(fullpath: {en: 'products'}, parent: index_page, templatized: true) } |
| + | let(:index_page) { build_page(fullpath: { en: 'index' }) } |
| + | let(:not_found_page) { build_page(fullpath: { en: '404' }) } |
| + | let(:about_page) { build_page(fullpath: { en: 'about_me'}, parent: index_page) } |
| + | let(:products_page) { build_page(fullpath: { en: 'products'}, parent: index_page, templatized: true) } |
| context 'not templatized' do | |
| context 'index or 404' do | |
| @@ | @@ -25,17 +25,17 @@ describe 'Locomotive::Steam::Decorators::PageDecorator' do |
| end | |
| context 'templatized' do | |
| - | subject { decorated build_page(fullpath: {en: 'products'}, parent: index_page, templatized: true) } |
| + | subject { decorated build_page(fullpath: { en: 'products' }, parent: index_page, templatized: true) } |
| its(:safe_fullpath) { should eq '*' } | |
| end | |
| context 'templatized with not templatized parent' do | |
| - | subject { decorated build_page(fullpath: {en: 'about_me/contact'}, parent: about_page, templatized: true) } |
| + | subject { decorated build_page(fullpath: { en: 'about_me/contact' }, parent: about_page, templatized: true) } |
| its(:safe_fullpath) { should eq 'about-me/*' } | |
| end | |
| context 'templatized parent' do | |
| - | subject { decorated build_page(fullpath: {en: 'products/detail'}, parent: products_page) } |
| + | subject { decorated build_page(fullpath: { en: 'products/detail' }, parent: products_page) } |
| its(:safe_fullpath) { should eq '*/detail' } | |
| end | |
| end | |
spec/unit/middlewares/page_spec.rb
+31
-19
| @@ | @@ -10,27 +10,39 @@ describe Locomotive::Steam::Middlewares::Page do |
| Locomotive::Steam::Middlewares::Page.new(app) | |
| end | |
| - | let(:page) do |
| - | double(title: 'title', fullpath: 'fullpath') |
| + | context 'rack testing' do |
| + | let(:page) do |
| + | double(title: 'title', fullpath: 'fullpath') |
| + | end |
| + | |
| + | before do |
| + | expect(middleware).to receive(:fetch_page).with('wk') { page } |
| + | expect(Locomotive::Common::Logger).to receive(:info).with("Found page \"title\" [fullpath]") { nil } |
| + | end |
| + | |
| + | subject do |
| + | middleware.call env_for('http://www.example.com', { 'steam.locale' => 'wk' }) |
| + | end |
| + | |
| + | specify 'return 200' do |
| + | code, headers, response = subject |
| + | expect(code).to eq(200) |
| + | end |
| + | |
| + | specify 'set page' do |
| + | code, headers, response = subject |
| + | expect(headers['steam.page']).to eq(page) |
| + | end |
| end | |
| - | before do |
| - | expect(middleware).to receive(:fetch_page).with('wk') { page } |
| - | expect(Locomotive::Common::Logger).to receive(:info).with("Found page \"title\" [fullpath]") { nil } |
| - | end |
| - | |
| - | subject do |
| - | middleware.call env_for('http://www.example.com', { 'steam.locale' => 'wk' }) |
| - | end |
| - | |
| - | specify 'return 200' do |
| - | code, headers, response = subject |
| - | expect(code).to eq(200) |
| - | end |
| - | |
| - | specify 'set page' do |
| - | code, headers, response = subject |
| - | expect(headers['steam.page']).to eq(page) |
| + | context 'test in isolation' do |
| + | describe '#path_combinations' do |
| + | specify do |
| + | expect( |
| + | middleware.send(:path_combinations, 'projects/project-2') |
| + | ).to eq(['projects/project-2', 'projects/*', '*/project-2']) |
| + | end |
| + | end |
| end | |
| def env_for url, opts={} | |