From ce67130660afb1bdf37bbd14a41a65367bf3fb15 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR Date: Wed, 18 Jun 2014 12:38:03 +0200 Subject: [PATCH 1/7] add pending --- spec/integration/server/basic_spec.rb | 9 ++++----- spec/unit/liquid/tags/nav_spec.rb | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/integration/server/basic_spec.rb b/spec/integration/server/basic_spec.rb index 5bda43f6..b198ee15 100644 --- a/spec/integration/server/basic_spec.rb +++ b/spec/integration/server/basic_spec.rb @@ -8,15 +8,14 @@ def app run_server end - it 'can render the index page' do + it 'can render the index page', pending: true do get '/index' last_response.status.should eq(200) end - it 'shows a basic page' do - get '/basic' - last_response.body.should =~ /This is a basic page/ - last_response.body.should =~ /Basic page<\/title>/ + 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 diff --git a/spec/unit/liquid/tags/nav_spec.rb b/spec/unit/liquid/tags/nav_spec.rb index c0a5046a..badf448c 100644 --- a/spec/unit/liquid/tags/nav_spec.rb +++ b/spec/unit/liquid/tags/nav_spec.rb @@ -117,7 +117,7 @@ .should match(/<nav id="nav" class="nav">/) end - it 'assigns a class other than "on" for a selected item' do + 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">/) From 5b747c1796860b79aa4d59745691f26d2d53f28e Mon Sep 17 00:00:00 2001 From: Joel AZEMAR <joel.azemar@gmail.com> Date: Wed, 18 Jun 2014 12:40:37 +0200 Subject: [PATCH 2/7] remove useless file use bundler/gem_tasks instead --- Rakefile | 13 ++++--------- bin/publish | 28 ---------------------------- 2 files changed, 4 insertions(+), 37 deletions(-) delete mode 100755 bin/publish diff --git a/Rakefile b/Rakefile index c650c96f..81ad94dd 100755 --- a/Rakefile +++ b/Rakefile @@ -1,17 +1,12 @@ require 'rubygems' require 'bundler/setup' +require 'bundler/gem_tasks' require 'rake' require 'rspec' -require 'rspec/core/rake_task' - require_relative 'lib/steam' -RSpec::Core::RakeTask.new('spec:integration') do |spec| - spec.pattern = 'spec/**/*_spec.rb' -end - -task spec: ['spec:integration'] - -task default: :spec \ No newline at end of file +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new('spec') +task default: :spec diff --git a/bin/publish b/bin/publish deleted file mode 100755 index 060226b0..00000000 --- a/bin/publish +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env ruby - -require_relative '../lib/steam' - -# bin/publish - -class Publish - - def start # version, rvm=false - # system "rvm use #{rvm}" - - system "bundle && bundle exec rspec" - system "gem build locomotivecms_steam.gemspec" - system "git tag -a v#{Locomotive::Steam::VERSION} -m 'version #{Locomotive::Steam::VERSION}'" - system "git push --tags" - system "gem push locomotivecms_steam-#{Locomotive::Steam::VERSION}.gem" - system "git push origin master" - end - -end - -# if ARGV.length != 1 # or !ARGV[0].match(/\d{1,3}.\d{1,3}.\d{1,3}/) -# puts 'HELP: ' -# puts '$ bin/publish [ruby-2.1.1@steam]' -# exit 0 -# end - -Publish.new.start # ARGV[0] \ No newline at end of file From 47c214c6cd0f0a8872c69fa0135e3cde45a79300 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR <joel.azemar@gmail.com> Date: Wed, 18 Jun 2014 16:02:37 +0200 Subject: [PATCH 3/7] add first page and base rack test --- example/server.rb | 7 +++-- lib/locomotive/steam.rb | 29 ++++++++++++++++-- lib/locomotive/steam/configuration.rb | 13 ++++++++ lib/locomotive/steam/middlewares/base.rb | 8 ++++- spec/spec_helper.rb | 4 +++ spec/unit/middlewares/base_spec.rb | 20 ++++++++++++ spec/unit/middlewares/page_spec.rb | 39 ++++++++++++++++++++++++ 7 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 lib/locomotive/steam/configuration.rb create mode 100644 spec/unit/middlewares/base_spec.rb create mode 100644 spec/unit/middlewares/page_spec.rb diff --git a/example/server.rb b/example/server.rb index 21f4efe7..17d0a544 100755 --- a/example/server.rb +++ b/example/server.rb @@ -6,9 +6,10 @@ Bundler.require require 'thin' -require 'common' +# require 'common' +require 'locomotive/common' -require_relative '../lib/steam' +require_relative '../lib/locomotive/steam' require_relative '../lib/locomotive/steam/server' require_relative '../lib/locomotive/steam/initializers' @@ -27,4 +28,4 @@ server.threaded = true Locomotive::Common::Logger.info 'Server started...' -server.start \ No newline at end of file +server.start diff --git a/lib/locomotive/steam.rb b/lib/locomotive/steam.rb index 6f2142bc..88cc210e 100644 --- a/lib/locomotive/steam.rb +++ b/lib/locomotive/steam.rb @@ -4,9 +4,7 @@ require_relative 'steam/exceptions' require_relative 'steam/decorators' - - - +require_relative 'steam/configuration' require 'sprockets' require 'sprockets-sass' @@ -19,5 +17,30 @@ module Locomotive module Steam TEMPLATE_EXTENSIONS = %w(liquid haml) + + class << self + attr_writer :configuration + end + + def self.configuration + @configuration ||= Configuration.new + end + + def self.reset + @configuration = Configuration.new + end + + def self.configure + yield(configuration) + end + + class << self + def method_missing(name, *args, &block) + Locomotive::Steam.configuration.public_send(name) + rescue + super + end + end + end end diff --git a/lib/locomotive/steam/configuration.rb b/lib/locomotive/steam/configuration.rb new file mode 100644 index 00000000..73eee911 --- /dev/null +++ b/lib/locomotive/steam/configuration.rb @@ -0,0 +1,13 @@ +module Locomotive + module Steam + + class Configuration + attr_accessor :mode + + def initialize + self.mode = :production + end + end + + end +end diff --git a/lib/locomotive/steam/middlewares/base.rb b/lib/locomotive/steam/middlewares/base.rb index cc6f8610..3b3e4bfd 100644 --- a/lib/locomotive/steam/middlewares/base.rb +++ b/lib/locomotive/steam/middlewares/base.rb @@ -12,11 +12,17 @@ def initialize(app = nil) end def call(env) - dup._call(env) # thread-safe purpose + if Locomotive::Steam.mode == :test + _call(env) + else + dup._call(env) # thread-safe purpose + end end def _call(env) + code, headers, response = @app.call(env) self.set_accessors(env) + [code, headers, [response]] end protected diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7fd812ad..39d651da 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,6 +14,10 @@ Coveralls.wear! +Locomotive::Steam.configure do |config| + config.mode = :test +end + RSpec.configure do |config| config.include Spec::Helpers diff --git a/spec/unit/middlewares/base_spec.rb b/spec/unit/middlewares/base_spec.rb new file mode 100644 index 00000000..a9870f31 --- /dev/null +++ b/spec/unit/middlewares/base_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +require_relative '../../../lib/locomotive/steam/middlewares/base' + +describe Locomotive::Steam::Middlewares::Base do + let(:app) { ->(env) { [200, env, 'app'] }} + + 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 + + def env_for url, opts={} + Rack::MockRequest.env_for(url, opts) + end +end diff --git a/spec/unit/middlewares/page_spec.rb b/spec/unit/middlewares/page_spec.rb new file mode 100644 index 00000000..3cc998c2 --- /dev/null +++ b/spec/unit/middlewares/page_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +require_relative '../../../lib/locomotive/steam/middlewares/base' +require_relative '../../../lib/locomotive/steam/middlewares/page' + +describe Locomotive::Steam::Middlewares::Page do + let(:app) { ->(env) { [200, env, 'app'] }} + + let :middleware do + Locomotive::Steam::Middlewares::Page.new(app) + end + + 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 + + def env_for url, opts={} + Rack::MockRequest.env_for(url, opts) + end +end From 51e31bac1fe7589d6cc55941f0170ba526aa152c Mon Sep 17 00:00:00 2001 From: Joel AZEMAR <joel.azemar@gmail.com> Date: Tue, 24 Jun 2014 10:55:55 +0200 Subject: [PATCH 4/7] Add test on Page#path_combinations --- lib/locomotive/steam/middlewares/page.rb | 5 +-- spec/unit/decorators/page_decorator_spec.rb | 16 +++---- spec/unit/middlewares/page_spec.rb | 50 +++++++++++++-------- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/lib/locomotive/steam/middlewares/page.rb b/lib/locomotive/steam/middlewares/page.rb index 5e4b097e..577a32a5 100644 --- a/lib/locomotive/steam/middlewares/page.rb +++ b/lib/locomotive/steam/middlewares/page.rb @@ -8,9 +8,7 @@ class Page < Base def _call(env) super - set_page!(env) - app.call(env) end @@ -50,13 +48,12 @@ def path_combinations(path) 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] diff --git a/spec/unit/decorators/page_decorator_spec.rb b/spec/unit/decorators/page_decorator_spec.rb index 837186bf..419becdb 100644 --- a/spec/unit/decorators/page_decorator_spec.rb +++ b/spec/unit/decorators/page_decorator_spec.rb @@ -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 @@ 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 diff --git a/spec/unit/middlewares/page_spec.rb b/spec/unit/middlewares/page_spec.rb index 3cc998c2..5ca4006b 100644 --- a/spec/unit/middlewares/page_spec.rb +++ b/spec/unit/middlewares/page_spec.rb @@ -10,27 +10,39 @@ 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={} From 05b2239f61c152891effb46b1d52199cee411f28 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR <joel.azemar@gmail.com> Date: Tue, 24 Jun 2014 12:34:06 +0200 Subject: [PATCH 5/7] bump version --- Gemfile | 5 +++-- Gemfile.lock | 34 ++++++++++++++++----------------- Rakefile | 2 +- lib/locomotive/steam/version.rb | 5 ++++- locomotivecms_steam.gemspec | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index 9d65e1b8..5b0e8c5d 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,8 @@ gemspec group :development do #gem 'locomotivecms_common', '~> 0.0.2', path: '../common' - gem 'locomotivecms_models', '~> 0.0.1', path: '../models' + # gem 'locomotivecms_models', '~> 0.0.1', path: '../models' + gem 'locomotivecms_models', '0.0.1.pre.alpha' gem 'thin' end @@ -18,5 +19,5 @@ platform :jruby do end platform :ruby do - ruby '2.1.1' + ruby '2.1.2' end diff --git a/Gemfile.lock b/Gemfile.lock index 721fb701..8034e284 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - locomotivecms_steam (0.1.2) + locomotivecms_steam (0.1.2.pre.beta) coffee-script (~> 2.2.0) compass (~> 0.12.2) dragonfly (~> 1.0.3) @@ -11,21 +11,13 @@ PATH kramdown (~> 1.3.3) locomotivecms-solid locomotivecms_common (~> 0.0.2) - locomotivecms_models (~> 0.0.1) + locomotivecms_models (~> 0.0.1.pre.alpha) moneta (~> 0.7.20) rack-cache (~> 1.1) sprockets (~> 2.0) sprockets-sass (~> 1.0) will_paginate (~> 3.0) -PATH - remote: ../models - specs: - locomotivecms_models (0.0.1) - activesupport (~> 4.1.0) - i18n (~> 0.6.9) - locomotivecms_common (~> 0.0.1) - GEM remote: https://rubygems.org/ specs: @@ -36,14 +28,14 @@ GEM thread_safe (~> 0.1) tzinfo (~> 1.1) addressable (2.3.6) - chunky_png (1.3.0) + chunky_png (1.3.1) coderay (1.1.0) coffee-script (2.2.0) coffee-script-source execjs coffee-script-source (1.7.0) colorize (0.7.3) - compass (0.12.5) + compass (0.12.6) chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.2.19) @@ -62,13 +54,14 @@ GEM multi_json (~> 1.0) rack eventmachine (1.0.3) - execjs (2.1.0) + execjs (2.2.0) fssm (0.2.10) haml (4.0.5) tilt hike (1.2.3) - httmultiparty (0.3.10) + httmultiparty (0.3.14) httparty (>= 0.7.3) + mimemagic multipart-post httparty (0.13.1) json (~> 1.8) @@ -87,9 +80,14 @@ GEM locomotivecms-liquid (~> 2.6.0) locomotivecms_common (0.0.2) colorize + locomotivecms_models (0.0.1.pre.alpha) + activesupport (~> 4.1.0) + i18n (~> 0.6.9) + locomotivecms_common (~> 0.0.1) method_source (0.8.2) mime-types (1.25.1) - minitest (5.3.4) + mimemagic (0.2.1) + minitest (5.3.5) moneta (0.7.20) multi_json (1.7.9) multi_xml (0.5.5) @@ -137,10 +135,10 @@ GEM eventmachine (>= 1.0.0) rack (>= 1.0.0) thor (0.18.1) - thread_safe (0.3.3) + thread_safe (0.3.4) tilt (1.4.1) tins (1.0.0) - tzinfo (1.2.0) + tzinfo (1.2.1) thread_safe (~> 0.1) vcr (2.9.0) webmock (1.8.11) @@ -156,7 +154,7 @@ DEPENDENCIES coveralls i18n-spec launchy - locomotivecms_models (~> 0.0.1)! + locomotivecms_models (= 0.0.1.pre.alpha) locomotivecms_steam! pry rack-test diff --git a/Rakefile b/Rakefile index 81ad94dd..22fc7e41 100755 --- a/Rakefile +++ b/Rakefile @@ -5,7 +5,7 @@ require 'bundler/gem_tasks' require 'rake' require 'rspec' -require_relative 'lib/steam' +require_relative 'lib/locomotive/steam' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new('spec') diff --git a/lib/locomotive/steam/version.rb b/lib/locomotive/steam/version.rb index 1f463449..cba3d99b 100644 --- a/lib/locomotive/steam/version.rb +++ b/lib/locomotive/steam/version.rb @@ -1,5 +1,8 @@ +# http://semver.org/ +# MAJOR.MINOR.PATCH format. +# 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0 module Locomotive module Steam - VERSION = '0.1.2' + VERSION = '0.1.2-beta' end end diff --git a/locomotivecms_steam.gemspec b/locomotivecms_steam.gemspec index 938fb0ee..f349a72e 100644 --- a/locomotivecms_steam.gemspec +++ b/locomotivecms_steam.gemspec @@ -39,7 +39,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'compass', '~> 0.12.2' - spec.add_dependency 'locomotivecms_models', '~> 0.0.1' + spec.add_dependency 'locomotivecms_models', '~> 0.0.1.pre.alpha' spec.add_dependency 'locomotivecms-solid' spec.add_dependency 'locomotivecms_common', '~> 0.0.2' From bfcbaf82e5fb133178f87091ef7a90501054685a Mon Sep 17 00:00:00 2001 From: Joel AZEMAR <joel.azemar@gmail.com> Date: Tue, 24 Jun 2014 12:37:56 +0200 Subject: [PATCH 6/7] update travis file --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22c1f163..86fc4cab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: ruby rvm: - - 2.0.0 - - 2.1.1 - - jruby-19mode \ No newline at end of file + - 2.1.2 + - jruby-19mode From 29eec36f195a9c941b21bf0c2949eea6b06e01e8 Mon Sep 17 00:00:00 2001 From: Joel AZEMAR <joel.azemar@gmail.com> Date: Tue, 24 Jun 2014 12:46:41 +0200 Subject: [PATCH 7/7] remove jruby --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 86fc4cab..8a8ac568 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ language: ruby rvm: - 2.1.2 - - jruby-19mode