Skip to content

Commit

Permalink
Merge pull request #27 from locomotivecms/rack_test
Browse files Browse the repository at this point in the history
Rack test
  • Loading branch information
joel committed Jun 24, 2014
2 parents 7b98a84 + 29eec36 commit 18978f3
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 88 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
language: ruby
rvm:
- 2.0.0
- 2.1.1
- jruby-19mode
- 2.1.2
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -18,5 +19,5 @@ platform :jruby do
end

platform :ruby do
ruby '2.1.1'
ruby '2.1.2'
end
34 changes: 16 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
15 changes: 5 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
require_relative 'lib/locomotive/steam'

task spec: ['spec:integration']

task default: :spec
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new('spec')
task default: :spec
28 changes: 0 additions & 28 deletions bin/publish

This file was deleted.

7 changes: 4 additions & 3 deletions example/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -27,4 +28,4 @@
server.threaded = true

Locomotive::Common::Logger.info 'Server started...'
server.start
server.start
29 changes: 26 additions & 3 deletions lib/locomotive/steam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

require_relative 'steam/exceptions'
require_relative 'steam/decorators'



require_relative 'steam/configuration'

require 'sprockets'
require 'sprockets-sass'
Expand All @@ -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
13 changes: 13 additions & 0 deletions lib/locomotive/steam/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Locomotive
module Steam

class Configuration
attr_accessor :mode

def initialize
self.mode = :production
end
end

end
end
8 changes: 7 additions & 1 deletion lib/locomotive/steam/middlewares/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions lib/locomotive/steam/middlewares/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ class Page < Base

def _call(env)
super

set_page!(env)

app.call(env)
end

Expand Down Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion lib/locomotive/steam/version.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion locomotivecms_steam.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
9 changes: 4 additions & 5 deletions spec/integration/server/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =~ /<title>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
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

Coveralls.wear!

Locomotive::Steam.configure do |config|
config.mode = :test
end

RSpec.configure do |config|
config.include Spec::Helpers

Expand Down
16 changes: 8 additions & 8 deletions spec/unit/decorators/page_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 18978f3

Please sign in to comment.