add specs for the snippet liquid tag (+ refactoring) + disable specs which prevented SimpleCov to process all the ruby code
did
committed Feb 03, 2015
commit bce18593f72bf57886239c5a0e1d8ac240386457
Showing 33
changed files with
695 additions
and 674 deletions
Gemfile
+3
-2
| @@ | @@ -17,9 +17,10 @@ group :test do |
| # gem 'mocha', require: false | |
| gem 'pry' | |
| - | gem 'coveralls', require: false |
| - | gem 'codeclimate-test-reporter', require: nil |
| + | # gem 'coveralls', require: false |
| + | # gem 'codeclimate-test-reporter', require: nil |
| + | gem 'simplecov', require: false |
| end | |
| # platform :jruby do | |
Gemfile.lock
+2
-18
| @@ | @@ -13,6 +13,7 @@ PATH |
| kramdown (~> 1.5.0) | |
| locomotivecms-solid (~> 4.0.0.alpha1) | |
| locomotivecms_common (~> 0.0.2) | |
| + | mime-types (~> 2.4.3) |
| mimetype-fu (~> 0.1.2) | |
| moneta (~> 0.8.0) | |
| morphine (~> 0.1.1) | |
| @@ | @@ -47,8 +48,6 @@ GEM |
| addressable (2.3.6) | |
| builder (3.2.2) | |
| chunky_png (1.3.3) | |
| - | codeclimate-test-reporter (0.4.6) |
| - | simplecov (>= 0.7.1, < 1.0.0) |
| coderay (1.1.0) | |
| coffee-script (2.3.0) | |
| coffee-script-source | |
| @@ | @@ -67,12 +66,6 @@ GEM |
| sass (>= 3.3.0, < 3.5) | |
| compass-import-once (1.0.5) | |
| sass (>= 3.2, < 3.5) | |
| - | coveralls (0.7.3) |
| - | multi_json (~> 1.10) |
| - | rest-client (~> 1.7) |
| - | simplecov (~> 0.9.1) |
| - | term-ansicolor (~> 1.3) |
| - | thor (~> 0.19.1) |
| diff-lcs (1.2.5) | |
| docile (1.1.5) | |
| dragonfly (1.0.7) | |
| @@ | @@ -117,7 +110,6 @@ GEM |
| morphine (0.1.1) | |
| multi_json (1.10.1) | |
| multi_xml (0.5.5) | |
| - | netrc (0.10.2) |
| nokogiri (1.6.6.2) | |
| mini_portile (~> 0.6.0) | |
| pry (0.10.1) | |
| @@ | @@ -143,9 +135,6 @@ GEM |
| rb-fsevent (0.9.4) | |
| rb-inotify (0.9.5) | |
| ffi (>= 0.5.0) | |
| - | rest-client (1.7.2) |
| - | mime-types (>= 1.16, < 3.0) |
| - | netrc (~> 0.7) |
| rspec (3.1.0) | |
| rspec-core (~> 3.1.0) | |
| rspec-expectations (~> 3.1.0) | |
| @@ | @@ -173,12 +162,8 @@ GEM |
| sprockets-sass (1.3.1) | |
| sprockets (~> 2.0) | |
| tilt (~> 1.1) | |
| - | term-ansicolor (1.3.0) |
| - | tins (~> 1.0) |
| - | thor (0.19.1) |
| thread_safe (0.3.4) | |
| tilt (1.4.1) | |
| - | tins (1.3.3) |
| tzinfo (1.2.2) | |
| thread_safe (~> 0.1) | |
| @@ | @@ -187,11 +172,10 @@ PLATFORMS |
| DEPENDENCIES | |
| bundler (~> 1.7) | |
| - | codeclimate-test-reporter |
| - | coveralls |
| i18n-spec (~> 0.6.0) | |
| json_spec (~> 1.1.4) | |
| locomotivecms_steam! | |
| pry | |
| rake (~> 10.4.2) | |
| rspec (~> 3.1.0) | |
| + | simplecov |
Rakefile
+2
-2
| @@ | @@ -8,8 +8,8 @@ require 'rspec' |
| # === Gems install tasks === | |
| Bundler::GemHelper.install_tasks | |
| - | require 'coveralls/rake/task' |
| - | Coveralls::RakeTask.new |
| + | # require 'coveralls/rake/task' |
| + | # Coveralls::RakeTask.new |
| require_relative 'lib/locomotive/steam' | |
locomotive/steam.rb b/lib/locomotive/steam.rb
+1
-1
| @@ | @@ -4,7 +4,7 @@ require 'locomotive/common' |
| require_relative 'steam/core_ext' | |
| require_relative 'steam/exceptions' | |
| - | require_relative 'steam/decorators' |
| + | # require_relative 'steam/decorators' |
| require_relative 'steam/configuration' | |
| require_relative 'steam/liquid' | |
locomotive/steam/decorators.rb b/lib/locomotive/steam/decorators.rb
+1
-1
| @@ | @@ -1 +1 @@ |
| - | require_relative 'decorators/page_decorator' |
| + | # require_relative 'decorators/page_decorator' |
locomotive/steam/liquid/errors.rb b/lib/locomotive/steam/liquid/errors.rb
+2
-0
| @@ | @@ -3,6 +3,8 @@ module Locomotive |
| module Liquid | |
| class PageNotFound < ::Liquid::Error; end | |
| + | class SnippetNotFound < ::Liquid::Error; end |
| + | |
| class PageNotTranslated < ::Liquid::Error; end | |
| end | |
| end | |
locomotive/steam/liquid/tags/consume.rb b/lib/locomotive/steam/liquid/tags/consume.rb
+1
-1
| @@ | @@ -98,7 +98,7 @@ module Locomotive |
| end | |
| - | ::Liquid::Template.register_tag('consume', Consume) |
| + | ::Liquid::Template.register_tag('consume'.freeze, Consume) |
| end | |
| end | |
| end | |
locomotive/steam/liquid/tags/csrf.rb b/lib/locomotive/steam/liquid/tags/csrf.rb
+2
-2
| @@ | @@ -34,8 +34,8 @@ module Locomotive |
| end | |
| - | ::Liquid::Template.register_tag('csrf_param', Csrf::Param) |
| - | ::Liquid::Template.register_tag('csrf_meta', Csrf::Meta) |
| + | ::Liquid::Template.register_tag('csrf_param'.freeze, Csrf::Param) |
| + | ::Liquid::Template.register_tag('csrf_meta'.freeze, Csrf::Meta) |
| end | |
| end | |
locomotive/steam/liquid/tags/extends.rb b/lib/locomotive/steam/liquid/tags/extends.rb
+1
-1
| @@ | @@ -22,7 +22,7 @@ module Locomotive |
| end | |
| - | ::Liquid::Template.register_tag('extends', Extends) |
| + | ::Liquid::Template.register_tag('extends'.freeze, Extends) |
| end | |
| end | |
| end | |
locomotive/steam/liquid/tags/fetch_page.rb b/lib/locomotive/steam/liquid/tags/fetch_page.rb
+1
-1
| @@ | @@ -31,7 +31,7 @@ module Locomotive |
| end | |
| end | |
| - | ::Liquid::Template.register_tag('fetch_page', FetchPage) |
| + | ::Liquid::Template.register_tag('fetch_page'.freeze, FetchPage) |
| end | |
| end | |
| end | |
locomotive/steam/liquid/tags/inherited_block.rb b/lib/locomotive/steam/liquid/tags/inherited_block.rb
+1
-1
| @@ | @@ -32,7 +32,7 @@ module Locomotive |
| end | |
| - | ::Liquid::Template.register_tag('block', InheritedBlock) |
| + | ::Liquid::Template.register_tag('block'.freeze, InheritedBlock) |
| end | |
| end | |
| end | |
locomotive/steam/liquid/tags/path_to.rb b/lib/locomotive/steam/liquid/tags/path_to.rb
+1
-1
| @@ | @@ -16,7 +16,7 @@ module Locomotive |
| end | |
| - | ::Liquid::Template.register_tag('path_to', PathTo) |
| + | ::Liquid::Template.register_tag('path_to'.freeze, PathTo) |
| end | |
| end | |
| end | |
locomotive/steam/liquid/tags/seo.rb b/lib/locomotive/steam/liquid/tags/seo.rb
+3
-3
| @@ | @@ -65,9 +65,9 @@ module Locomotive |
| end | |
| - | ::Liquid::Template.register_tag('seo', SEO::Base) |
| - | ::Liquid::Template.register_tag('seo_title', SEO::Title) |
| - | ::Liquid::Template.register_tag('seo_metadata', SEO::Metadata) |
| + | ::Liquid::Template.register_tag('seo'.freeze, SEO::Base) |
| + | ::Liquid::Template.register_tag('seo_title'.freeze, SEO::Title) |
| + | ::Liquid::Template.register_tag('seo_metadata'.freeze, SEO::Metadata) |
| end | |
| end | |
| end | |
locomotive/steam/liquid/tags/session_assign.rb b/lib/locomotive/steam/liquid/tags/session_assign.rb
+1
-1
| @@ | @@ -32,7 +32,7 @@ module Locomotive |
| end | |
| - | ::Liquid::Template.register_tag('session_assign', SessionAssign) |
| + | ::Liquid::Template.register_tag('session_assign'.freeze, SessionAssign) |
| end | |
| end | |
| end | |
locomotive/steam/liquid/tags/snippet.rb b/lib/locomotive/steam/liquid/tags/snippet.rb
+15
-53
| @@ | @@ -5,72 +5,34 @@ module Locomotive |
| class Snippet < ::Liquid::Include | |
| - | attr_accessor :slug |
| - | attr_accessor :partial |
| + | def parse(tokens) |
| + | if listener = options[:events_listener] |
| + | listener.emit(:include, page: options[:page], name: @template_name) |
| - | def initialize(tag_name, markup, tokens, context) |
| - | super |
| - | |
| - | @slug = @template_name.gsub(/['"]/o, '') |
| - | |
| - | if @context[:snippets].present? |
| - | (@context[:snippets] << @slug).uniq! |
| - | else |
| - | @context[:snippets] = [@slug] |
| - | end |
| - | |
| - | if @context[:site].present? |
| - | snippet = @context[:site].snippets.where(slug: @slug).first |
| - | self.refresh(snippet) if snippet |
| + | # look for editable elements |
| + | if snippet = find_snippet(options[:repositories].snippet, @template_name) |
| + | ::Liquid::Template.parse(snippet, options.merge(snippet: @template_name)) |
| + | end |
| end | |
| end | |
| - | def render(context) |
| - | return '' if @partial.nil? |
| - | |
| - | variable = context[@variable_name || @template_name[1..-2]] |
| + | private |
| - | context.stack do |
| - | @attributes.each do |key, value| |
| - | context[key] = context[value] |
| - | end |
| - | |
| - | output = (if variable.is_a?(Array) |
| - | variable.collect do |variable| |
| - | context[@template_name[1..-2]] = variable |
| - | @partial.render(context) |
| - | end |
| - | else |
| - | context[@template_name[1..-2]] = variable |
| - | @partial.render(context) |
| - | end) |
| + | def read_template_from_file_system(context) |
| + | snippet = find_snippet(context.registers[:repositories].snippet, @template_name) |
| - | output |
| - | end |
| - | end |
| + | raise SnippetNotFound.new("Snippet with slug '#{@template_name}' was not found") if snippet.nil? |
| - | def refresh(snippet, context = {}) |
| - | if snippet.destroyed? |
| - | @snippet_id = nil |
| - | @partial = nil |
| - | else |
| - | @snippet_id = snippet.id |
| - | @partial = ::Liquid::Template.parse(snippet.template, context.merge(@context)) |
| - | @partial.root.context.clear |
| - | end |
| + | snippet.source |
| end | |
| - | def nodelist |
| - | if @partial |
| - | @partial.root.nodelist |
| - | else |
| - | [] |
| - | end |
| + | def find_snippet(repository, slug) |
| + | repository.by_slug(slug) |
| end | |
| end | |
| - | ::Liquid::Template.register_tag('include', Snippet) |
| + | ::Liquid::Template.register_tag('include'.freeze, Snippet) |
| end | |
| end | |
| end | |
locomotive/steam/middlewares/page.rb b/lib/locomotive/steam/middlewares/page.rb
+2
-2
| @@ | @@ -37,8 +37,8 @@ module Locomotive::Steam |
| def decorated(locale) | |
| entity = yield | |
| unless entity.nil? | |
| - | Locomotive::Steam::Decorators::PageDecorator.new( |
| - | Locomotive::Decorators::I18nDecorator.new(entity, locale)) |
| + | # Locomotive::Steam::Decorators::PageDecorator.new( |
| + | # Locomotive::Decorators::I18nDecorator.new(entity, locale)) |
| end | |
| end | |
locomotive/steam/repositories.rb b/lib/locomotive/steam/repositories.rb
+5
-1
| @@ | @@ -19,7 +19,11 @@ module Locomotive |
| end | |
| register :page do | |
| - | Repositories::Page.new |
| + | Repositories::Page.new(current_site) |
| + | end |
| + | |
| + | register :snippet do |
| + | Repositories::Snippet.new(current_site) |
| end | |
| register :theme_asset do | |
locomotive/steam/repositories/snippet.rb b/lib/locomotive/steam/repositories/snippet.rb
+15
-0
| @@ | @@ -0,0 +1,15 @@ |
| + | module Locomotive |
| + | module Steam |
| + | module Repositories |
| + | |
| + | class Snippet < Struct.new(:site) |
| + | |
| + | def by_slug(slug) |
| + | site.snippets.where(slug: slug).first |
| + | end |
| + | |
| + | end |
| + | |
| + | end |
| + | end |
| + | end |
locomotivecms_steam.gemspec
+2
-0
| @@ | @@ -39,6 +39,8 @@ Gem::Specification.new do |spec| |
| spec.add_dependency 'RedCloth', '~> 4.2.9' | |
| spec.add_dependency 'haml', '~> 4.0.6' | |
| spec.add_dependency 'mimetype-fu', '~> 0.1.2' | |
| + | spec.add_dependency 'mime-types', '~> 2.4.3' |
| + | |
| # spec.add_dependency 'locomotivecms_models', '~> 0.0.1.pre.alpha' | |
| spec.add_dependency 'locomotivecms-solid', '~> 4.0.0.alpha1' | |
spec/integration/server/basic_spec.rb
+118
-118
| @@ | @@ -1,169 +1,169 @@ |
| - | require File.dirname(__FILE__) + '/../integration_helper' |
| - | |
| - | describe Locomotive::Steam::Server do |
| - | |
| - | include Rack::Test::Methods |
| + | # require File.dirname(__FILE__) + '/../integration_helper' |
| + | |
| + | # describe Locomotive::Steam::Server do |
| + | |
| + | # include Rack::Test::Methods |
| - | def app |
| - | run_server |
| - | end |
| + | # def app |
| + | # run_server |
| + | # end |
| - | it 'can render the index page', pending: true do |
| - | get '/index' |
| - | last_response.status.should eq(200) |
| - | end |
| + | # it 'can render the index page', pending: true do |
| + | # get '/index' |
| + | # last_response.status.should eq(200) |
| + | # end |
| - | it 'shows the index page', pending: true do |
| - | get '/index' |
| - | last_response.body.should =~ /Upcoming events/ |
| - | end |
| + | # it 'shows the index page', pending: true do |
| + | # get '/index' |
| + | # last_response.body.should =~ /Upcoming events/ |
| + | # end |
| - | it 'shows the 404 page', pending: true do |
| - | get '/void' |
| - | last_response.status.should eq(404) |
| - | last_response.body.should =~ /page not found/ |
| - | end |
| + | # it 'shows the 404 page', pending: true do |
| + | # get '/void' |
| + | # last_response.status.should eq(404) |
| + | # last_response.body.should =~ /page not found/ |
| + | # end |
| - | it 'shows the 404 page with 200 status code when its called explicitly', pending: true do |
| - | get '/404' |
| - | last_response.status.should eq(200) |
| - | last_response.body.should =~ /page not found/ |
| - | end |
| + | # it 'shows the 404 page with 200 status code when its called explicitly', pending: true do |
| + | # get '/404' |
| + | # last_response.status.should eq(200) |
| + | # last_response.body.should =~ /page not found/ |
| + | # end |
| - | it 'shows content', pending: true do |
| - | get '/about-us/jane-doe' |
| - | last_response.body.should =~ /Lorem ipsum dolor sit amet/ |
| - | end |
| + | # it 'shows content', pending: true do |
| + | # get '/about-us/jane-doe' |
| + | # last_response.body.should =~ /Lorem ipsum dolor sit amet/ |
| + | # end |
| - | it 'shows a content type template', pending: true do |
| - | get '/songs/song-number-1' |
| - | last_response.body.should =~ /Song #1/ |
| - | end |
| + | # it 'shows a content type template', pending: true do |
| + | # get '/songs/song-number-1' |
| + | # last_response.body.should =~ /Song #1/ |
| + | # end |
| - | it 'renders a page under a templatized one', pending: true do |
| - | get '/songs/song-number-1/band' |
| - | last_response.body.should =~ /Song #1/ |
| - | last_response.body.should =~ /Leader: Eddie/ |
| - | end |
| + | # it 'renders a page under a templatized one', pending: true do |
| + | # get '/songs/song-number-1/band' |
| + | # last_response.body.should =~ /Song #1/ |
| + | # last_response.body.should =~ /Leader: Eddie/ |
| + | # end |
| - | it 'translates strings', pending: true do |
| - | get '/en' |
| - | last_response.body.should =~ /Powered by/ |
| - | get '/fr' |
| - | last_response.body.should =~ /Propulsé par/ |
| - | get '/nb' |
| - | last_response.body.should_not =~ /Powered by/ |
| - | end |
| + | # it 'translates strings', pending: true do |
| + | # get '/en' |
| + | # last_response.body.should =~ /Powered by/ |
| + | # get '/fr' |
| + | # last_response.body.should =~ /Propulsé par/ |
| + | # get '/nb' |
| + | # last_response.body.should_not =~ /Powered by/ |
| + | # end |
| - | it 'provides translation in scopes', pending: true do |
| - | get '/' |
| - | last_response.body.should =~ /scoped_translation=.French./ |
| - | end |
| + | # it 'provides translation in scopes', pending: true do |
| + | # get '/' |
| + | # last_response.body.should =~ /scoped_translation=.French./ |
| + | # end |
| - | it 'translates a page with link_to tags inside', pending: true do |
| - | get '/fr/notre-musique' |
| - | last_response.body.should =~ /<h3><a href="\/fr\/songs\/song-number-8">Song #8<\/a><\/h3>/ |
| - | last_response.body.should =~ /Propulsé par/ |
| - | end |
| + | # it 'translates a page with link_to tags inside', pending: true do |
| + | # get '/fr/notre-musique' |
| + | # last_response.body.should =~ /<h3><a href="\/fr\/songs\/song-number-8">Song #8<\/a><\/h3>/ |
| + | # last_response.body.should =~ /Propulsé par/ |
| + | # end |
| - | it 'returns all the pages', pending: true do |
| - | get '/all' |
| - | last_response.body.should =~ /Home page/ |
| - | last_response.body.should =~ /<li>Home page<\/li>/ |
| - | last_response.body.should =~ /<li>John-doe<\/li>/ |
| - | last_response.body.should =~ /<li>Songs<\/li>/ |
| - | last_response.body.should =~ /<li>A song template<\/li>/ |
| - | end |
| + | # it 'returns all the pages', pending: true do |
| + | # get '/all' |
| + | # last_response.body.should =~ /Home page/ |
| + | # last_response.body.should =~ /<li>Home page<\/li>/ |
| + | # last_response.body.should =~ /<li>John-doe<\/li>/ |
| + | # last_response.body.should =~ /<li>Songs<\/li>/ |
| + | # last_response.body.should =~ /<li>A song template<\/li>/ |
| + | # end |
| - | describe 'snippets', pending: true do |
| + | # describe 'snippets', pending: true do |
| - | it 'includes a basic snippet' do |
| - | get '/' |
| - | last_response.body.should =~ /All photos are licensed under Creative Commons\./ |
| - | end |
| + | # it 'includes a basic snippet' do |
| + | # get '/' |
| + | # last_response.body.should =~ /All photos are licensed under Creative Commons\./ |
| + | # end |
| - | it 'includes a snippet whose name is composed of dash' do |
| - | get '/' |
| - | last_response.body.should =~ /<p>A complicated one name indeed.<\/p>/ |
| - | end |
| + | # it 'includes a snippet whose name is composed of dash' do |
| + | # get '/' |
| + | # last_response.body.should =~ /<p>A complicated one name indeed.<\/p>/ |
| + | # end |
| - | end |
| + | # end |
| - | describe 'nav', pending: true do |
| + | # describe 'nav', pending: true do |
| - | subject { get '/all'; last_response.body } |
| + | # subject { get '/all'; last_response.body } |
| - | it { should_not match(/<nav id="nav">/) } |
| + | # it { should_not match(/<nav id="nav">/) } |
| - | it { should match(/<li id="about-us-link" class="link first"><a href="\/about-us">About Us<\/a><\/li>/) } |
| + | # it { should match(/<li id="about-us-link" class="link first"><a href="\/about-us">About Us<\/a><\/li>/) } |
| - | it { should match(/<li id="music-link" class="link"><a href="\/music">Music<\/a><\/li>/) } |
| + | # it { should match(/<li id="music-link" class="link"><a href="\/music">Music<\/a><\/li>/) } |
| - | it { should match(/<li id="store-link" class="link"><a href="\/store">Store<\/a><\/li>/) } |
| + | # it { should match(/<li id="store-link" class="link"><a href="\/store">Store<\/a><\/li>/) } |
| - | it { should match(/<li id="contact-link" class="link last"><a href="\/contact">Contact Us<\/a><\/li>/) } |
| + | # it { should match(/<li id="contact-link" class="link last"><a href="\/contact">Contact Us<\/a><\/li>/) } |
| - | it { should_not match(/<li id="events-link" class="link"><a href="\/events">Events<\/a><\/li>/) } |
| + | # it { should_not match(/<li id="events-link" class="link"><a href="\/events">Events<\/a><\/li>/) } |
| - | describe 'with wrapper' do |
| + | # describe 'with wrapper' do |
| - | subject { get '/tags/nav'; last_response.body } |
| + | # subject { get '/tags/nav'; last_response.body } |
| - | it { should match(/<nav id="nav">/) } |
| + | # it { should match(/<nav id="nav">/) } |
| - | end |
| + | # end |
| - | describe 'very deep' do |
| + | # describe 'very deep' do |
| - | subject { get '/tags/nav_in_deep'; last_response.body } |
| + | # subject { get '/tags/nav_in_deep'; last_response.body } |
| - | it { should match(/<li id=\"john-doe-link\" class=\"link first last\">/) } |
| + | # it { should match(/<li id=\"john-doe-link\" class=\"link first last\">/) } |
| - | end |
| + | # end |
| - | end |
| + | # end |
| - | describe 'contents with_scope', pending: true do |
| - | subject { get '/grunge_bands'; last_response.body } |
| + | # describe 'contents with_scope', pending: true do |
| + | # subject { get '/grunge_bands'; last_response.body } |
| - | it { should match(/Layne/)} |
| - | it { should_not match(/Peter/) } |
| - | end |
| + | # it { should match(/Layne/)} |
| + | # it { should_not match(/Peter/) } |
| + | # end |
| - | describe 'pages with_scope', pending: true do |
| - | subject { get '/unlisted_pages'; last_response.body } |
| - | it { subject.should match(/Page to test the nav tag/)} |
| - | it { should_not match(/About Us/)} |
| - | end |
| + | # describe 'pages with_scope', pending: true do |
| + | # subject { get '/unlisted_pages'; last_response.body } |
| + | # it { subject.should match(/Page to test the nav tag/)} |
| + | # it { should_not match(/About Us/)} |
| + | # end |
| - | describe 'theme assets', pending: true do |
| + | # describe 'theme assets', pending: true do |
| - | subject { get '/all'; last_response.body } |
| + | # subject { get '/all'; last_response.body } |
| - | it { should match(/<link href="\/stylesheets\/application.css" media="screen" rel="stylesheet" type="text\/css" \/>/) } |
| + | # it { should match(/<link href="\/stylesheets\/application.css" media="screen" rel="stylesheet" type="text\/css" \/>/) } |
| - | it { should match(/<script src="\/javascripts\/application.js" type='text\/javascript'><\/script>/) } |
| + | # it { should match(/<script src="\/javascripts\/application.js" type='text\/javascript'><\/script>/) } |
| - | it { should match(/<link rel="alternate" type="application\/atom\+xml" title="A title" href="\/foo\/bar" \/>/) } |
| + | # it { should match(/<link rel="alternate" type="application\/atom\+xml" title="A title" href="\/foo\/bar" \/>/) } |
| - | end |
| + | # end |
| - | describe 'session', pending: true do |
| + | # describe 'session', pending: true do |
| - | subject { get '/contest'; last_response.body } |
| + | # subject { get '/contest'; last_response.body } |
| - | it { should match(/Your code is: HELLO WORLD/) } |
| - | it { should_not match(/You've already participated to that contest ! Come back later./) } |
| + | # it { should match(/Your code is: HELLO WORLD/) } |
| + | # it { should_not match(/You've already participated to that contest ! Come back later./) } |
| - | describe 'assign tag' do |
| + | # describe 'assign tag' do |
| - | subject { 2.times { get '/contest' }; last_response.body } |
| + | # subject { 2.times { get '/contest' }; last_response.body } |
| - | it { should_not match(/Your code is: HELLO WORLD/) } |
| - | it { should match(/You've already participated to that contest ! Come back later./) } |
| + | # it { should_not match(/Your code is: HELLO WORLD/) } |
| + | # it { should match(/You've already participated to that contest ! Come back later./) } |
| - | end |
| + | # end |
| - | end |
| + | # end |
| - | end |
| + | # end |
spec/integration/server/contact_form_spec.rb
+70
-70
| @@ | @@ -1,107 +1,107 @@ |
| - | require File.dirname(__FILE__) + '/../integration_helper' |
| + | # require File.dirname(__FILE__) + '/../integration_helper' |
| - | describe 'ContactForm', pending: true do |
| + | # describe 'ContactForm', pending: true do |
| - | include Rack::Test::Methods |
| + | # include Rack::Test::Methods |
| - | def app |
| - | run_server |
| - | end |
| + | # def app |
| + | # run_server |
| + | # end |
| - | it 'renders the form' do |
| - | get '/contact' |
| - | last_response.body.should =~ /\/entry_submissions\/messages.json/ |
| - | end |
| + | # it 'renders the form' do |
| + | # get '/contact' |
| + | # last_response.body.should =~ /\/entry_submissions\/messages.json/ |
| + | # end |
| - | describe '#submit' do |
| + | # describe '#submit' do |
| - | let(:params) { { |
| - | 'entry' => { 'name' => 'John', 'email' => 'j@doe.net', 'message' => 'Bla bla' }, |
| - | 'success_callback' => '/events', |
| - | 'error_callback' => '/contact' } } |
| - | let(:response) { post_contact_form(params, false) } |
| - | let(:status) { response.status } |
| + | # let(:params) { { |
| + | # 'entry' => { 'name' => 'John', 'email' => 'j@doe.net', 'message' => 'Bla bla' }, |
| + | # 'success_callback' => '/events', |
| + | # 'error_callback' => '/contact' } } |
| + | # let(:response) { post_contact_form(params, false) } |
| + | # let(:status) { response.status } |
| - | describe 'with json request' do |
| + | # describe 'with json request' do |
| - | let(:response) { post_contact_form(params, true) } |
| - | let(:entry) { JSON.parse(response.body)['message'] } |
| + | # let(:response) { post_contact_form(params, true) } |
| + | # let(:entry) { JSON.parse(response.body)['message'] } |
| - | context 'when not valid' do |
| + | # context 'when not valid' do |
| - | let(:params) { {} } |
| + | # let(:params) { {} } |
| - | it 'returns an error status' do |
| - | response.status.should == 422 |
| - | end |
| + | # it 'returns an error status' do |
| + | # response.status.should == 422 |
| + | # end |
| - | describe 'errors' do |
| + | # describe 'errors' do |
| - | subject { entry['errors'] } |
| + | # subject { entry['errors'] } |
| - | it { should have_key_with_value('name', "can't not be blank") } |
| + | # it { should have_key_with_value('name', "can't not be blank") } |
| - | it { should have_key_with_value('email', "can't not be blank") } |
| + | # it { should have_key_with_value('email', "can't not be blank") } |
| - | it { should have_key_with_value('message', "can't not be blank") } |
| + | # it { should have_key_with_value('message', "can't not be blank") } |
| - | end |
| + | # end |
| - | end |
| + | # end |
| - | context 'when valid' do |
| + | # context 'when valid' do |
| - | it 'returns a success status' do |
| - | response.status.should == 200 |
| - | end |
| + | # it 'returns a success status' do |
| + | # response.status.should == 200 |
| + | # end |
| - | end |
| + | # end |
| - | end |
| + | # end |
| - | describe 'with html request' do |
| + | # describe 'with html request' do |
| - | context 'when not valid' do |
| + | # context 'when not valid' do |
| - | let(:params) { { 'error_callback' => '/contact' } } |
| + | # let(:params) { { 'error_callback' => '/contact' } } |
| - | it 'returns a success status' do |
| - | response.status.should == 200 |
| - | end |
| + | # it 'returns a success status' do |
| + | # response.status.should == 200 |
| + | # end |
| - | it 'displays errors' do |
| - | response.body.to_s.should =~ /can't not be blank/ |
| - | end |
| + | # it 'displays errors' do |
| + | # response.body.to_s.should =~ /can't not be blank/ |
| + | # end |
| - | end |
| + | # end |
| - | context 'when valid' do |
| + | # context 'when valid' do |
| - | let(:response) { post_contact_form(params, false, true) } |
| + | # let(:response) { post_contact_form(params, false, true) } |
| - | it 'returns a success status' do |
| - | response.status.should == 200 |
| - | end |
| + | # it 'returns a success status' do |
| + | # response.status.should == 200 |
| + | # end |
| - | it 'displays a success message' do |
| - | response.body.should =~ /Thank you John/ |
| - | end |
| + | # it 'displays a success message' do |
| + | # response.body.should =~ /Thank you John/ |
| + | # end |
| - | end |
| + | # end |
| - | end |
| + | # end |
| - | end |
| + | # end |
| - | def post_contact_form(params, json = false, follow_redirect = false) |
| - | url = '/entry_submissions/messages' |
| - | url += '.json' if json |
| - | params = params.symbolize_keys if json |
| - | post url, params |
| - | if follow_redirect |
| - | follow_redirect! |
| - | end |
| - | last_response |
| - | end |
| + | # def post_contact_form(params, json = false, follow_redirect = false) |
| + | # url = '/entry_submissions/messages' |
| + | # url += '.json' if json |
| + | # params = params.symbolize_keys if json |
| + | # post url, params |
| + | # if follow_redirect |
| + | # follow_redirect! |
| + | # end |
| + | # last_response |
| + | # end |
| - | end |
| + | # end |
spec/integration/server/liquid_spec.rb
+66
-66
| @@ | @@ -1,87 +1,87 @@ |
| - | require File.dirname(__FILE__) + '/../integration_helper' |
| + | # require File.dirname(__FILE__) + '/../integration_helper' |
| - | describe Locomotive::Steam::Server, pending: true do |
| + | # describe Locomotive::Steam::Server, pending: true do |
| - | include Rack::Test::Methods |
| + | # include Rack::Test::Methods |
| - | def app |
| - | run_server |
| - | end |
| + | # def app |
| + | # run_server |
| + | # end |
| - | it "converts {{ page.templatized? }} => true on templatized page" do |
| - | get '/songs/song-number-1' |
| - | last_response.body.should =~ /templatized=.true./ |
| - | end |
| + | # it "converts {{ page.templatized? }} => true on templatized page" do |
| + | # get '/songs/song-number-1' |
| + | # last_response.body.should =~ /templatized=.true./ |
| + | # end |
| - | it "converts {{ page.templatized? }} => false on regular page" do |
| - | get '/index' |
| - | last_response.body.should =~ /templatized=.false./ |
| - | end |
| + | # it "converts {{ page.templatized? }} => false on regular page" do |
| + | # get '/index' |
| + | # last_response.body.should =~ /templatized=.false./ |
| + | # end |
| - | it "converts {{ page.listed? }} => true on listed page" do |
| - | get '/music' |
| - | last_response.body.should =~ /listed=.true./ |
| - | end |
| + | # it "converts {{ page.listed? }} => true on listed page" do |
| + | # get '/music' |
| + | # last_response.body.should =~ /listed=.true./ |
| + | # end |
| - | it "provides an access to page's content_type collection" do |
| - | get '/songs/song-number-1' |
| - | last_response.body.should =~ /content_type_size=.8./ |
| - | end |
| + | # it "provides an access to page's content_type collection" do |
| + | # get '/songs/song-number-1' |
| + | # last_response.body.should =~ /content_type_size=.8./ |
| + | # end |
| - | it "provides count alias on collections" do |
| - | get '/songs/song-number-1' |
| - | last_response.body.should =~ /content_type_count=.8./ |
| - | end |
| + | # it "provides count alias on collections" do |
| + | # get '/songs/song-number-1' |
| + | # last_response.body.should =~ /content_type_count=.8./ |
| + | # end |
| - | describe '.link_to' do |
| + | # describe '.link_to' do |
| - | it "writes a link to a page" do |
| - | get '/events' |
| - | last_response.body.should =~ /Discover: <a href="\/music">Music<\/a>/ |
| - | end |
| + | # it "writes a link to a page" do |
| + | # get '/events' |
| + | # last_response.body.should =~ /Discover: <a href="\/music">Music<\/a>/ |
| + | # end |
| - | it "writes a localized a link" do |
| - | get '/events' |
| - | last_response.body.should =~ /Plus à notre sujet: <a href="\/fr\/a-notre-sujet">Qui sommes nous \?<\/a>/ |
| - | end |
| + | # it "writes a localized a link" do |
| + | # get '/events' |
| + | # last_response.body.should =~ /Plus à notre sujet: <a href="\/fr\/a-notre-sujet">Qui sommes nous \?<\/a>/ |
| + | # end |
| - | it "writes a link to a page with a custom label" do |
| - | get '/events' |
| - | last_response.body.should =~ /More about us: <a href="\/about-us">Who are we \?<\/a>/ |
| - | end |
| + | # it "writes a link to a page with a custom label" do |
| + | # get '/events' |
| + | # last_response.body.should =~ /More about us: <a href="\/about-us">Who are we \?<\/a>/ |
| + | # end |
| - | it "writes a link to a templatized page" do |
| - | get '/events' |
| - | last_response.body.should =~ /<a href="\/songs\/song-number-1">Song #1<\/a>/ |
| - | end |
| + | # it "writes a link to a templatized page" do |
| + | # get '/events' |
| + | # last_response.body.should =~ /<a href="\/songs\/song-number-1">Song #1<\/a>/ |
| + | # end |
| - | it "writes a link to a templatized page with a different handle" do |
| - | get '/events' |
| - | last_response.body.should =~ /<a href="\/songs\/song-number-8">Song #8<\/a>/ |
| - | end |
| + | # it "writes a link to a templatized page with a different handle" do |
| + | # get '/events' |
| + | # last_response.body.should =~ /<a href="\/songs\/song-number-8">Song #8<\/a>/ |
| + | # end |
| - | end |
| + | # end |
| - | describe 'scope & assigns' do |
| + | # describe 'scope & assigns' do |
| - | it "evaluates collection when called all inside of scope" do |
| - | get '/music' |
| - | last_response.body.should =~ /<p class=.scoped_song.>Song #3/ |
| - | last_response.body.should =~ /<p class=.scoped_song_link.>\s+<a href=.\/songs\/song-number-3.>Song #3/m |
| - | end |
| + | # it "evaluates collection when called all inside of scope" do |
| + | # get '/music' |
| + | # last_response.body.should =~ /<p class=.scoped_song.>Song #3/ |
| + | # last_response.body.should =~ /<p class=.scoped_song_link.>\s+<a href=.\/songs\/song-number-3.>Song #3/m |
| + | # end |
| - | it "size of evaluated unscoped collection equal to unevaluated one" do |
| - | get '/music' |
| - | last_response.body.should =~ /class=.collection_equality.>8=8/ |
| - | end |
| + | # it "size of evaluated unscoped collection equal to unevaluated one" do |
| + | # get '/music' |
| + | # last_response.body.should =~ /class=.collection_equality.>8=8/ |
| + | # end |
| - | end |
| + | # end |
| - | describe 'html helpers' do |
| - | it 'bypass url for css resource' do |
| - | get '/' |
| - | last_response.body.should =~ /<link href=("|')http:\/\/fonts\.googleapis\.com\/css\?family=Open\+Sans:400,700("|')/ |
| - | end |
| - | end |
| + | # describe 'html helpers' do |
| + | # it 'bypass url for css resource' do |
| + | # get '/' |
| + | # last_response.body.should =~ /<link href=("|')http:\/\/fonts\.googleapis\.com\/css\?family=Open\+Sans:400,700("|')/ |
| + | # end |
| + | # end |
| - | end |
| + | # end |
spec/integration/server/with_scope_spec.rb
+11
-11
| @@ | @@ -1,16 +1,16 @@ |
| - | require File.dirname(__FILE__) + '/../integration_helper' |
| + | # require File.dirname(__FILE__) + '/../integration_helper' |
| - | describe 'Complex with_scope conditions', pending: true do |
| + | # describe 'Complex with_scope conditions', pending: true do |
| - | include Rack::Test::Methods |
| + | # include Rack::Test::Methods |
| - | def app |
| - | run_server |
| - | end |
| + | # def app |
| + | # run_server |
| + | # end |
| - | it 'returns the right number of events' do |
| - | get '/filtered' |
| - | last_response.body.should =~ /events=1./ |
| - | end |
| + | # it 'returns the right number of events' do |
| + | # get '/filtered' |
| + | # last_response.body.should =~ /events=1./ |
| + | # end |
| - | end |
| + | # end |
spec/locales/locales_spec.rb
+7
-7
| @@ | @@ -9,13 +9,13 @@ describe "#locales" do |
| end | |
| end | |
| - | unless locale_file == 'config/locales/en.yml' |
| - | describe "#{locale_file}", pending: 'need to be fixed' do |
| - | it_behaves_like 'complete translation of' do |
| - | let(:locale_target) { locale_file } |
| - | end |
| - | end |
| - | end |
| + | # unless locale_file == 'config/locales/en.yml' |
| + | # describe "#{locale_file}" do |
| + | # it_behaves_like 'complete translation of' do |
| + | # let(:locale_target) { locale_file } |
| + | # end |
| + | # end |
| + | # end |
| end | |
spec/spec_helper.rb
+15
-9
| @@ | @@ -1,23 +1,29 @@ |
| - | require 'codeclimate-test-reporter' |
| - | CodeClimate::TestReporter.start |
| + | # require 'codeclimate-test-reporter' |
| + | # CodeClimate::TestReporter.start |
| + | |
| + | require 'simplecov' |
| + | SimpleCov.start do |
| + | add_filter 'spec/' |
| + | |
| + | add_group "Liquid Filters", "lib/locomotive/steam/liquid/filters" |
| + | add_group "Liquid Tags", "lib/locomotive/steam/liquid/tags" |
| + | add_group "Repositories", "lib/locomotive/steam/repositories" |
| + | add_group "Services", "lib/locomotive/steam/services" |
| + | end |
| require 'rubygems' | |
| require 'bundler/setup' | |
| require 'i18n-spec' | |
| - | require 'coveralls' |
| - | Coveralls.wear! |
| + | # require 'coveralls' |
| + | # Coveralls.wear! |
| - | begin |
| - | require 'pry' |
| - | rescue LoadError |
| - | end |
| + | require File.join(File.dirname(__FILE__), '../lib/locomotive/steam/repositories') |
| require_relative '../lib/locomotive/steam' | |
| require_relative 'support' | |
| - | |
| Locomotive::Steam.configure do |config| | |
| config.mode = :test | |
| end | |
spec/support/liquid.rb
+6
-6
| @@ | @@ -1,11 +1,11 @@ |
| - | def render_template(template, context = nil) |
| + | def render_template(source, context = nil) |
| context ||= ::Liquid::Context.new | |
| context.exception_handler = ->(e) { true } | |
| - | ::Liquid::Template.parse(template).render(context) |
| + | ::Liquid::Template.parse(source).render(context) |
| end | |
| - | def parse_template(template, options = nil) |
| - | ::Liquid::Template.parse(template, options || {}) |
| + | def parse_template(source, options = nil) |
| + | ::Liquid::Template.parse(source, options || {}) |
| end | |
| module Liquid | |
| @@ | @@ -14,10 +14,10 @@ module Liquid |
| (@stack ||= []) << [name, options] | |
| end | |
| def event_names | |
| - | @stack.map { |(name, _)| name } |
| + | (@stack || []).map { |(name, _)| name } |
| end | |
| def events | |
| - | @stack |
| + | @stack || [] |
| end | |
| end | |
| end | |
spec/support/pry.rb
+4
-0
| @@ | @@ -0,0 +1,4 @@ |
| + | # begin |
| + | # require 'pry' |
| + | # rescue LoadError |
| + | # end |
spec/unit/decorators/page_decorator_spec.rb
+58
-58
| @@ | @@ -1,58 +1,58 @@ |
| - | require 'spec_helper' |
| - | |
| - | describe 'Locomotive::Steam::Decorators::PageDecorator' do |
| - | |
| - | before { skip } |
| - | |
| - | 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) } |
| - | |
| - | context 'not templatized' do |
| - | context 'index or 404' do |
| - | it { decorated(index_page).safe_fullpath.should eq 'index' } |
| - | it { decorated(not_found_page).safe_fullpath.should eq '404' } |
| - | end |
| - | |
| - | context 'other' do |
| - | it { decorated(about_page).safe_fullpath.should eq 'about-me' } |
| - | end |
| - | end |
| - | |
| - | context 'templatized' do |
| - | 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) } |
| - | # its(:safe_fullpath) { should eq 'about-me/*' } |
| - | end |
| - | |
| - | context 'templatized parent' do |
| - | subject { decorated build_page(fullpath: { en: 'products/detail' }, parent: products_page) } |
| - | # its(:safe_fullpath) { should eq '*/detail' } |
| - | end |
| - | end |
| - | |
| - | def decorated(page) |
| - | Locomotive::Steam::Decorators::PageDecorator.new( |
| - | Locomotive::Decorators::I18nDecorator.new( |
| - | page, locale |
| - | ) |
| - | ) |
| - | end |
| - | |
| - | def build_page(attributes = {}) |
| - | Locomotive::Steam::Entities::Page.new(attributes) |
| - | end |
| - | |
| - | end |
| + | # require 'spec_helper' |
| + | |
| + | # describe 'Locomotive::Steam::Decorators::PageDecorator' do |
| + | |
| + | # before { skip } |
| + | |
| + | # 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) } |
| + | |
| + | # context 'not templatized' do |
| + | # context 'index or 404' do |
| + | # it { decorated(index_page).safe_fullpath.should eq 'index' } |
| + | # it { decorated(not_found_page).safe_fullpath.should eq '404' } |
| + | # end |
| + | |
| + | # context 'other' do |
| + | # it { decorated(about_page).safe_fullpath.should eq 'about-me' } |
| + | # end |
| + | # end |
| + | |
| + | # context 'templatized' do |
| + | # 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) } |
| + | # # its(:safe_fullpath) { should eq 'about-me/*' } |
| + | # end |
| + | |
| + | # context 'templatized parent' do |
| + | # subject { decorated build_page(fullpath: { en: 'products/detail' }, parent: products_page) } |
| + | # # its(:safe_fullpath) { should eq '*/detail' } |
| + | # end |
| + | # end |
| + | |
| + | # def decorated(page) |
| + | # Locomotive::Steam::Decorators::PageDecorator.new( |
| + | # Locomotive::Decorators::I18nDecorator.new( |
| + | # page, locale |
| + | # ) |
| + | # ) |
| + | # end |
| + | |
| + | # def build_page(attributes = {}) |
| + | # Locomotive::Steam::Entities::Page.new(attributes) |
| + | # end |
| + | |
| + | # end |
spec/unit/liquid/tags/nav_spec.rb
+161
-161
| @@ | @@ -1,161 +1,161 @@ |
| - | require 'spec_helper' |
| - | |
| - | describe 'Locomotive::Steam::Liquid::Tags::Nav' do |
| - | |
| - | before { skip } |
| - | |
| - | subject { Locomotive::Steam::Liquid::Tags::Nav } |
| - | let(:entity_class) { Locomotive::Steam::Entities::Page } |
| - | let(:site_class) { Locomotive::Steam::Entities::Site } |
| - | let(:home) { new_page fullpath: { en: 'index' }} |
| - | let(:site) { site_class.new locales: %w(en fr) } |
| - | |
| - | before do |
| - | home_children = [ |
| - | new_page(title: { en: 'Child #1' }, fullpath: { en: 'child_1' }, slug: { en: 'child_1' }, published: true, listed: true), |
| - | new_page(title: { en: 'Child #2' }, fullpath: { en: 'child_2' }, slug: { en: 'child_2' }, published: true, listed: true) |
| - | ] |
| - | home.stub(children: home_children) |
| - | |
| - | other_children = [ |
| - | new_page(title: { en: 'Child #2.1' }, fullpath: { en: 'child_2/sub_child_1' }, slug: { en: 'sub_child_1' }, published: true, listed: true), |
| - | new_page(title: { en: 'Child #2.2' }, fullpath: { en: 'child_2/sub_child_2' }, slug: { en: 'sub_child_2' }, published: true, listed: true), |
| - | new_page(title: { en: 'Unpublished #2.2' }, fullpath: { en: 'child_2/sub_child_unpublishd_2' }, slug: { en: 'sub_child_unpublished_2' }, published: false, listed: true), |
| - | new_page(title: { en: 'Templatized #2.3' }, fullpath: { en: 'child_2/sub_child_template_3' }, slug: { en: 'sub_child_template_3' }, published: true, templatized: true, listed: true), |
| - | new_page(title: { en: 'Unlisted #2.4' }, fullpath: { en: 'child_2/sub_child_unlisted_4' }, slug: { en: 'sub_child_unlisted_4' }, published: true, listed: false) |
| - | ] |
| - | home.children.last.stub(children: other_children) |
| - | |
| - | pages = [home] |
| - | Locomotive::Models['pages'].stub(root: pages) |
| - | Locomotive::Models['pages'].stub(all: pages) |
| - | Locomotive::Models['pages'].stub(:[]).with('index').and_return home |
| - | end |
| - | |
| - | context '#rendering' do |
| - | |
| - | it 'renders from site' do |
| - | render_nav.should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/child_2">Child #2</a></li></ul></nav>' |
| - | end |
| - | |
| - | it 'renders from page' do |
| - | render_nav('page').should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/child_2">Child #2</a></li></ul></nav>' |
| - | end |
| - | |
| - | it 'renders from parent' do |
| - | (page = home.children.last.children.first).stub(parent: home.children.last) |
| - | output = render_nav 'parent', { page: page } |
| - | output.should == '<nav id="nav"><ul><li id="sub-child-1-link" class="link on first"><a href="/child_2/sub_child_1">Child #2.1</a></li><li id="sub-child-2-link" class="link last"><a href="/child_2/sub_child_2">Child #2.2</a></li></ul></nav>' |
| - | end |
| - | |
| - | it 'renders children to depth' do |
| - | output = render_nav('site', {}, 'depth: 2') |
| - | |
| - | output.should match(/<nav id="nav">/) |
| - | output.should match(/<ul>/) |
| - | output.should match(/<li id="child-1-link" class="link first">/) |
| - | output.should match(/<\/a><ul id="nav-child-2">/) |
| - | output.should match(/<li id="sub-child-1-link" class="link first">/) |
| - | output.should match(/<li id="sub-child-2-link" class="link last">/) |
| - | output.should match(/<\/a><\/li><\/ul><\/li><\/ul><\/nav>/) |
| - | end |
| - | |
| - | it 'does not render templatized pages' do |
| - | output = render_nav('site', {}, 'depth: 2') |
| - | |
| - | output.should_not match(/sub-child-template-3/) |
| - | end |
| - | |
| - | it 'does not render unpublished pages' do |
| - | output = render_nav('site', {}, 'depth: 2') |
| - | |
| - | output.should_not match(/sub-child-unpublished-3/) |
| - | end |
| - | |
| - | it 'does not render unlisted pages' do |
| - | output = render_nav('site', {}, 'depth: 2') |
| - | |
| - | output.should_not match(/sub-child-unlisted-3/) |
| - | end |
| - | |
| - | it 'does not render nested excluded pages' do |
| - | output = render_nav('site', {}, 'depth: 2, exclude: "child_2/sub_child_2"') |
| - | |
| - | output.should match(/<li id="child-2-link" class="link last">/) |
| - | output.should match(/<li id="sub-child-1-link" class="link first last">/) |
| - | output.should_not match(/sub-child-2/) |
| - | |
| - | output = render_nav('site', {}, 'depth: 2, exclude: "child_2"') |
| - | |
| - | output.should match(/<li id="child-1-link" class="link first last">/) |
| - | output.should_not match(/child-2/) |
| - | output.should_not match(/sub-child/) |
| - | end |
| - | |
| - | it 'adds an icon before the link' do |
| - | render_nav('site', {}, 'icon: true') |
| - | .should match(/<li id="child-1-link" class="link first"><a href="\/child_1"><span><\/span> Child #1<\/a>/) |
| - | render_nav('site', {}, 'icon: before') |
| - | .should match(/<li id="child-1-link" class="link first"><a href="\/child_1"><span><\/span> Child #1<\/a>/) |
| - | end |
| - | |
| - | it 'adds an icon after the link' do |
| - | render_nav('site', {}, 'icon: after') |
| - | .should match(/<li id="child-1-link" class="link first"><a href="\/child_1">Child #1 <span><\/span><\/a><\/li>/) |
| - | end |
| - | |
| - | it 'renders a snippet for the title' do |
| - | render_nav('site', {}, 'snippet: "-{{page.title}} {{ foo.png | theme_image_tag }}-"') |
| - | .should match( /<li id="child-1-link" class="link first"><a href="\/child_1">-Child #1 <img src=\"\" \/>-<\/a><\/li>/) |
| - | end |
| - | |
| - | it 'assigns a different dom id' do |
| - | render_nav('site', {}, 'id: "main-nav"') |
| - | .should match(/<nav id="main-nav">/) |
| - | end |
| - | |
| - | it 'assigns a class' do |
| - | render_nav('site', {}, 'class: "nav"') |
| - | .should match(/<nav id="nav" class="nav">/) |
| - | end |
| - | |
| - | it 'assigns a class other than "on" for a selected item', pending: true do |
| - | (page = @home.children.last.children.first).stubs(:parent).returns(@home.children.last) |
| - | output = render_nav 'parent', { page: page }, 'active_class: "active"' |
| - | output.should match(/<li id="sub-child-1-link" class="link active first">/) |
| - | end |
| - | |
| - | it 'excludes entries based on a regexp' do |
| - | render_nav('page', {}, 'exclude: "child_1"').should == '<nav id="nav"><ul><li id="child-2-link" class="link first last"><a href="/child_2">Child #2</a></li></ul></nav>' |
| - | end |
| - | |
| - | it 'does not render the parent ul' do |
| - | render_nav('site', {}, 'no_wrapper: true') |
| - | .should_not match(/<ul id="nav">/) |
| - | end |
| - | |
| - | it 'localizes the links' do |
| - | I18n.with_locale('fr') do |
| - | render_nav.should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/fr/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/fr/child_2">Child #2</a></li></ul></nav>' |
| - | end |
| - | end |
| - | |
| - | end |
| - | |
| - | def new_page attributes |
| - | Locomotive::Steam::Decorators::PageDecorator.new( |
| - | Locomotive::Decorators::I18nDecorator.new( |
| - | entity_class.new(attributes), :en |
| - | ) |
| - | ) |
| - | end |
| - | |
| - | def render_nav(source = 'site', registers = {}, template_option = '') |
| - | registers = { site: site, page: home }.merge(registers) |
| - | liquid_context = ::Liquid::Context.new({}, {}, registers) |
| - | |
| - | output = Liquid::Template.parse("{% nav #{source} #{template_option} %}").render(liquid_context) |
| - | output.gsub(/\n\s{0,}/, '') |
| - | end |
| - | |
| - | end |
| + | # require 'spec_helper' |
| + | |
| + | # describe 'Locomotive::Steam::Liquid::Tags::Nav' do |
| + | |
| + | # before { skip } |
| + | |
| + | # subject { Locomotive::Steam::Liquid::Tags::Nav } |
| + | # let(:entity_class) { Locomotive::Steam::Entities::Page } |
| + | # let(:site_class) { Locomotive::Steam::Entities::Site } |
| + | # let(:home) { new_page fullpath: { en: 'index' }} |
| + | # let(:site) { site_class.new locales: %w(en fr) } |
| + | |
| + | # before do |
| + | # home_children = [ |
| + | # new_page(title: { en: 'Child #1' }, fullpath: { en: 'child_1' }, slug: { en: 'child_1' }, published: true, listed: true), |
| + | # new_page(title: { en: 'Child #2' }, fullpath: { en: 'child_2' }, slug: { en: 'child_2' }, published: true, listed: true) |
| + | # ] |
| + | # home.stub(children: home_children) |
| + | |
| + | # other_children = [ |
| + | # new_page(title: { en: 'Child #2.1' }, fullpath: { en: 'child_2/sub_child_1' }, slug: { en: 'sub_child_1' }, published: true, listed: true), |
| + | # new_page(title: { en: 'Child #2.2' }, fullpath: { en: 'child_2/sub_child_2' }, slug: { en: 'sub_child_2' }, published: true, listed: true), |
| + | # new_page(title: { en: 'Unpublished #2.2' }, fullpath: { en: 'child_2/sub_child_unpublishd_2' }, slug: { en: 'sub_child_unpublished_2' }, published: false, listed: true), |
| + | # new_page(title: { en: 'Templatized #2.3' }, fullpath: { en: 'child_2/sub_child_template_3' }, slug: { en: 'sub_child_template_3' }, published: true, templatized: true, listed: true), |
| + | # new_page(title: { en: 'Unlisted #2.4' }, fullpath: { en: 'child_2/sub_child_unlisted_4' }, slug: { en: 'sub_child_unlisted_4' }, published: true, listed: false) |
| + | # ] |
| + | # home.children.last.stub(children: other_children) |
| + | |
| + | # pages = [home] |
| + | # Locomotive::Models['pages'].stub(root: pages) |
| + | # Locomotive::Models['pages'].stub(all: pages) |
| + | # Locomotive::Models['pages'].stub(:[]).with('index').and_return home |
| + | # end |
| + | |
| + | # context '#rendering' do |
| + | |
| + | # it 'renders from site' do |
| + | # render_nav.should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/child_2">Child #2</a></li></ul></nav>' |
| + | # end |
| + | |
| + | # it 'renders from page' do |
| + | # render_nav('page').should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/child_2">Child #2</a></li></ul></nav>' |
| + | # end |
| + | |
| + | # it 'renders from parent' do |
| + | # (page = home.children.last.children.first).stub(parent: home.children.last) |
| + | # output = render_nav 'parent', { page: page } |
| + | # output.should == '<nav id="nav"><ul><li id="sub-child-1-link" class="link on first"><a href="/child_2/sub_child_1">Child #2.1</a></li><li id="sub-child-2-link" class="link last"><a href="/child_2/sub_child_2">Child #2.2</a></li></ul></nav>' |
| + | # end |
| + | |
| + | # it 'renders children to depth' do |
| + | # output = render_nav('site', {}, 'depth: 2') |
| + | |
| + | # output.should match(/<nav id="nav">/) |
| + | # output.should match(/<ul>/) |
| + | # output.should match(/<li id="child-1-link" class="link first">/) |
| + | # output.should match(/<\/a><ul id="nav-child-2">/) |
| + | # output.should match(/<li id="sub-child-1-link" class="link first">/) |
| + | # output.should match(/<li id="sub-child-2-link" class="link last">/) |
| + | # output.should match(/<\/a><\/li><\/ul><\/li><\/ul><\/nav>/) |
| + | # end |
| + | |
| + | # it 'does not render templatized pages' do |
| + | # output = render_nav('site', {}, 'depth: 2') |
| + | |
| + | # output.should_not match(/sub-child-template-3/) |
| + | # end |
| + | |
| + | # it 'does not render unpublished pages' do |
| + | # output = render_nav('site', {}, 'depth: 2') |
| + | |
| + | # output.should_not match(/sub-child-unpublished-3/) |
| + | # end |
| + | |
| + | # it 'does not render unlisted pages' do |
| + | # output = render_nav('site', {}, 'depth: 2') |
| + | |
| + | # output.should_not match(/sub-child-unlisted-3/) |
| + | # end |
| + | |
| + | # it 'does not render nested excluded pages' do |
| + | # output = render_nav('site', {}, 'depth: 2, exclude: "child_2/sub_child_2"') |
| + | |
| + | # output.should match(/<li id="child-2-link" class="link last">/) |
| + | # output.should match(/<li id="sub-child-1-link" class="link first last">/) |
| + | # output.should_not match(/sub-child-2/) |
| + | |
| + | # output = render_nav('site', {}, 'depth: 2, exclude: "child_2"') |
| + | |
| + | # output.should match(/<li id="child-1-link" class="link first last">/) |
| + | # output.should_not match(/child-2/) |
| + | # output.should_not match(/sub-child/) |
| + | # end |
| + | |
| + | # it 'adds an icon before the link' do |
| + | # render_nav('site', {}, 'icon: true') |
| + | # .should match(/<li id="child-1-link" class="link first"><a href="\/child_1"><span><\/span> Child #1<\/a>/) |
| + | # render_nav('site', {}, 'icon: before') |
| + | # .should match(/<li id="child-1-link" class="link first"><a href="\/child_1"><span><\/span> Child #1<\/a>/) |
| + | # end |
| + | |
| + | # it 'adds an icon after the link' do |
| + | # render_nav('site', {}, 'icon: after') |
| + | # .should match(/<li id="child-1-link" class="link first"><a href="\/child_1">Child #1 <span><\/span><\/a><\/li>/) |
| + | # end |
| + | |
| + | # it 'renders a snippet for the title' do |
| + | # render_nav('site', {}, 'snippet: "-{{page.title}} {{ foo.png | theme_image_tag }}-"') |
| + | # .should match( /<li id="child-1-link" class="link first"><a href="\/child_1">-Child #1 <img src=\"\" \/>-<\/a><\/li>/) |
| + | # end |
| + | |
| + | # it 'assigns a different dom id' do |
| + | # render_nav('site', {}, 'id: "main-nav"') |
| + | # .should match(/<nav id="main-nav">/) |
| + | # end |
| + | |
| + | # it 'assigns a class' do |
| + | # render_nav('site', {}, 'class: "nav"') |
| + | # .should match(/<nav id="nav" class="nav">/) |
| + | # end |
| + | |
| + | # it 'assigns a class other than "on" for a selected item', pending: true do |
| + | # (page = @home.children.last.children.first).stubs(:parent).returns(@home.children.last) |
| + | # output = render_nav 'parent', { page: page }, 'active_class: "active"' |
| + | # output.should match(/<li id="sub-child-1-link" class="link active first">/) |
| + | # end |
| + | |
| + | # it 'excludes entries based on a regexp' do |
| + | # render_nav('page', {}, 'exclude: "child_1"').should == '<nav id="nav"><ul><li id="child-2-link" class="link first last"><a href="/child_2">Child #2</a></li></ul></nav>' |
| + | # end |
| + | |
| + | # it 'does not render the parent ul' do |
| + | # render_nav('site', {}, 'no_wrapper: true') |
| + | # .should_not match(/<ul id="nav">/) |
| + | # end |
| + | |
| + | # it 'localizes the links' do |
| + | # I18n.with_locale('fr') do |
| + | # render_nav.should == '<nav id="nav"><ul><li id="child-1-link" class="link first"><a href="/fr/child_1">Child #1</a></li><li id="child-2-link" class="link last"><a href="/fr/child_2">Child #2</a></li></ul></nav>' |
| + | # end |
| + | # end |
| + | |
| + | # end |
| + | |
| + | # def new_page attributes |
| + | # # Locomotive::Steam::Decorators::PageDecorator.new( |
| + | # # Locomotive::Decorators::I18nDecorator.new( |
| + | # # entity_class.new(attributes), :en |
| + | # # ) |
| + | # # ) |
| + | # end |
| + | |
| + | # def render_nav(source = 'site', registers = {}, template_option = '') |
| + | # registers = { site: site, page: home }.merge(registers) |
| + | # liquid_context = ::Liquid::Context.new({}, {}, registers) |
| + | |
| + | # output = Liquid::Template.parse("{% nav #{source} #{template_option} %}").render(liquid_context) |
| + | # output.gsub(/\n\s{0,}/, '') |
| + | # end |
| + | |
| + | # end |
spec/unit/liquid/tags/snippet_spec.rb
+41
-0
| @@ | @@ -0,0 +1,41 @@ |
| + | require 'spec_helper' |
| + | |
| + | describe Locomotive::Steam::Liquid::Tags::Snippet do |
| + | |
| + | let(:snippet) { instance_double('Snippet', source: 'built by NoCoffee') } |
| + | let(:source) { 'Locomotive {% include footer %}' } |
| + | let(:repositories) { Locomotive::Steam::Repositories.build_instance(nil) } |
| + | |
| + | before { allow(repositories.snippet).to receive(:by_slug).and_return(snippet) } |
| + | |
| + | describe 'parsing' do |
| + | |
| + | let(:page) { instance_double('Page') } |
| + | let(:listener) { Liquid::SimpleEventsListener.new } |
| + | let(:options) { { events_listener: listener, page: page, repositories: repositories } } |
| + | |
| + | let!(:template) { parse_template(source, options) } |
| + | |
| + | it { expect(listener.event_names.first).to eq :include } |
| + | |
| + | describe 'with an editable_element inside', pending: true do |
| + | |
| + | let(:snippet) { instance_double('Snippet', source: '{% editable_text company %}built by NoCoffee{% endeditable_text %}') } |
| + | |
| + | it { expect(listener.events.size).to eq 2 } |
| + | |
| + | end |
| + | |
| + | end |
| + | |
| + | describe 'rendering' do |
| + | |
| + | let(:context) { ::Liquid::Context.new({}, {}, { repositories: repositories }) } |
| + | |
| + | subject { render_template(source, context) } |
| + | |
| + | it { is_expected.to eq 'Locomotive built by NoCoffee' } |
| + | |
| + | end |
| + | |
| + | end |
spec/unit/middlewares/base_spec.rb
+16
-16
| @@ | @@ -1,23 +1,23 @@ |
| - | require 'spec_helper' |
| + | # require 'spec_helper' |
| - | require_relative '../../../lib/locomotive/steam/middlewares/base' |
| + | # require_relative '../../../lib/locomotive/steam/middlewares/base' |
| - | describe Locomotive::Steam::Middlewares::Base do |
| + | # describe Locomotive::Steam::Middlewares::Base do |
| - | before { skip } |
| + | # before { skip } |
| - | let(:app) { ->(env) { [200, env, 'app'] }} |
| + | # let(:app) { ->(env) { [200, env, 'app'] }} |
| - | let :middleware do |
| - | Locomotive::Steam::Middlewares::Base.new(app) |
| - | end |
| + | # let :middleware do |
| + | # Locomotive::Steam::Middlewares::Base.new(app) |
| + | # end |
| - | specify "return 200" do |
| - | code, headers, response = middleware.call env_for('http://www.example.com', { 'steam.path' => 'my path' }) |
| - | expect(code).to eq(200) |
| - | end |
| + | # specify "return 200" do |
| + | # code, headers, response = middleware.call env_for('http://www.example.com', { 'steam.path' => 'my path' }) |
| + | # expect(code).to eq(200) |
| + | # end |
| - | def env_for url, opts={} |
| - | Rack::MockRequest.env_for(url, opts) |
| - | end |
| - | end |
| + | # def env_for url, opts={} |
| + | # Rack::MockRequest.env_for(url, opts) |
| + | # end |
| + | # end |
spec/unit/middlewares/page_spec.rb
+54
-54
| @@ | @@ -1,54 +1,54 @@ |
| - | require 'spec_helper' |
| - | |
| - | require_relative '../../../lib/locomotive/steam/middlewares/base' |
| - | require_relative '../../../lib/locomotive/steam/middlewares/page' |
| - | |
| - | describe Locomotive::Steam::Middlewares::Page do |
| - | |
| - | before { skip } |
| - | |
| - | let(:app) { ->(env) { [200, env, 'app'] }} |
| - | |
| - | let :middleware do |
| - | Locomotive::Steam::Middlewares::Page.new(app) |
| - | end |
| - | |
| - | 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 |
| - | |
| - | 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={} |
| - | Rack::MockRequest.env_for(url, opts) |
| - | end |
| - | end |
| + | # require 'spec_helper' |
| + | |
| + | # require_relative '../../../lib/locomotive/steam/middlewares/base' |
| + | # require_relative '../../../lib/locomotive/steam/middlewares/page' |
| + | |
| + | # describe Locomotive::Steam::Middlewares::Page do |
| + | |
| + | # before { skip } |
| + | |
| + | # let(:app) { ->(env) { [200, env, 'app'] }} |
| + | |
| + | # let :middleware do |
| + | # Locomotive::Steam::Middlewares::Page.new(app) |
| + | # end |
| + | |
| + | # 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 |
| + | |
| + | # 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={} |
| + | # Rack::MockRequest.env_for(url, opts) |
| + | # end |
| + | # end |
spec/unit/repositories/pages_spec.rb
+7
-7
| @@ | @@ -1,11 +1,11 @@ |
| - | require 'spec_helper' |
| + | # require 'spec_helper' |
| - | describe 'Locomotive::Steam::Repository::PagesRepository' do |
| + | # describe 'Locomotive::Steam::Repository::PagesRepository' do |
| - | describe '#[]' do |
| - | end |
| + | # describe '#[]' do |
| + | # end |
| - | describe '#matching_path' do |
| - | end |
| + | # describe '#matching_path' do |
| + | # end |
| - | end |
| + | # end |