Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make specs & examples JRuby friendly

- use MultiJson interface
- make yajl requires conditional
- use maruku (pure ruby) markdown gem for templates
- maruku autoescapes quotes: drop quotes for consistent tests
  • Loading branch information...
commit 8eba0bec81ad23d484629190c4943f8705576560 1 parent 18fbc85
@igrigorik igrigorik authored
View
7 examples/activerecord/srv.rb
@@ -10,8 +10,8 @@
# insert into users (name, email) values ('dan', 'dj2@everyburning.com'), ('Ilya', 'ilya@igvita.com');
# To start server
-# ruby ./srv.rb
-#
+# ruby ./srv.rb
+#
# Example output:
# curl http://localhost:9000/?id=1
#=> "{\"user\":{\"email\":\"dj2@everyburning.com\",\"id\":1,\"name\":\"dan\"}}"
@@ -22,7 +22,8 @@
require 'goliath'
require 'em-synchrony/activerecord'
-require 'yajl'
+
+require 'yajl' if RUBY_PLATFORM != 'java'
class User < ActiveRecord::Base
end
View
4 examples/async_aroundware_demo.rb
@@ -3,7 +3,7 @@
require 'goliath'
require 'em-synchrony/em-http'
-require 'yajl/json_gem'
+require 'yajl/json_gem' if RUBY_PLATFORM != 'java'
#
# Here's a way to make an asynchronous request in the middleware, and only
@@ -45,7 +45,7 @@
class RemoteRequestBarrier
include Goliath::Rack::BarrierAroundware
attr_accessor :sleep_1
-
+
def pre_process
# Request with delay_1 and drop_1 -- note: 'aget', because we want execution to continue
req = EM::HttpRequest.new(BASE_URL).aget(:query => { :delay => env.params['delay_1'], :drop => env.params['drop_1'] })
View
2  examples/async_upload.rb
@@ -2,7 +2,7 @@
$:<< '../lib' << 'lib'
require 'goliath'
-require 'yajl'
+require 'yajl' if RUBY_PLATFORM != 'java'
class AsyncUpload < Goliath::API
use Goliath::Rack::Params # parse & merge query and body parameters
View
2  examples/auth_and_rate_limit.rb
@@ -5,7 +5,7 @@
require 'em-http'
require 'em-synchrony/em-http'
require 'em-synchrony/em-mongo'
-require 'yajl/json_gem'
+require 'yajl/json_gem' if RUBY_PLATFORM != 'java'
require File.join(File.dirname(__FILE__), 'http_log') # Use the HttpLog as our actual endpoint, but include this in the middleware
View
2  examples/echo.rb
@@ -6,7 +6,7 @@
# Goliath uses multi-json, so pick your favorite JSON serializer
# require 'json'
-require 'yajl'
+require 'yajl' if RUBY_PLATFORM != 'java'
class Echo < Goliath::API
use Goliath::Rack::Tracer # log trace statistics
View
14 examples/grape/server.rb
@@ -31,31 +31,31 @@
require 'goliath'
require 'em-synchrony/activerecord'
-require 'yajl'
+require 'yajl' if RUBY_PLATFORM != 'java'
require 'grape'
class User < ActiveRecord::Base
end
class MyAPI < Grape::API
-
+
version 'v1', :using => :path
format :json
-
+
resource 'users' do
get "/" do
User.all
end
-
- get "/:id" do
+
+ get "/:id" do
User.find(params['id'])
end
-
+
post "/create" do
User.create(params['user'])
end
end
-
+
end
class APIServer < Goliath::API
View
2  examples/gziped.rb
@@ -15,7 +15,7 @@
require 'rack/deflater'
require 'rack/rewrite'
require 'goliath'
-require 'yajl'
+require 'yajl' if RUBY_PLATFORM != 'java'
class Gziped < Goliath::API
# if client requested, compress the response
View
13 examples/template.rb
@@ -11,10 +11,15 @@
# your template's extension must match the engine (foo.markdown, not foo.md)
require 'tilt'
-# use bluecloth as default markdown renderer
-require 'bluecloth'
-Tilt.register 'markdown', Tilt::BlueClothTemplate
-require 'yajl/json_gem'
+
+if RUBY_PLATFORM != 'java'
+ require 'yajl/json_gem'
+ require 'bluecloth' # use bluecloth as default markdown renderer
+ Tilt.register 'markdown', Tilt::BlueClothTemplate
+else
+ require 'maruku'
+ Tilt.register 'markdown', Tilt::MarukuTemplate
+end
require 'goliath'
require 'goliath/rack/templates'
View
8 examples/views/joke.markdown
@@ -3,11 +3,11 @@
Pirate walks into a bar with a steering wheel half-in, half-out of his pants.
-Bartender says
+Bartender says
- "Hey Pirate, What's With The Steering Wheel?"
+ Hey Pirate, What's With The Steering Wheel?
-Pirate says
+Pirate says
- "Arr, I dunno matey -- but it's drivin' me nuts!"
+ Arr, I dunno matey -- but it is driving me nuts!
View
8 goliath.gemspec
@@ -40,16 +40,20 @@ Gem::Specification.new do |s|
s.add_development_dependency 'haml', '>=3.0.25'
s.add_development_dependency 'yard'
- s.add_development_dependency 'guard', '~> 0.8.8'
+ s.add_development_dependency 'guard', '~> 0.8.8'
s.add_development_dependency 'guard-rspec', '~> 0.5.9'
if RUBY_PLATFORM != 'java'
s.add_development_dependency 'yajl-ruby'
s.add_development_dependency 'bluecloth'
+ s.add_development_dependency 'bson_ext'
+ else
+ s.add_development_dependency 'json-jruby'
+ s.add_development_dependency 'maruku'
end
if RUBY_PLATFORM.include?('darwin')
- s.add_development_dependency 'growl', '~> 1.0.3'
+ s.add_development_dependency 'growl', '~> 1.0.3'
s.add_development_dependency 'rb-fsevent'
end
View
2  lib/goliath/test_helper.rb
@@ -17,7 +17,7 @@ module Goliath
# it 'returns the echo param' do
# with_api(Echo) do
# get_request({:query => {:echo => 'test'}}, err) do |c|
- # b = Yajl::Parser.parse(c.response)
+ # b = MultiJson.load(c.response)
# b['response'].should == 'test'
# end
# end
View
2  spec/integration/async_request_processing.rb
@@ -12,7 +12,7 @@
err = Proc.new { fail "API request failed" }
post_request(request_data, err) do |c|
- resp = Yajl::Parser.parse(c.response)
+ resp = MultiJson.load(c.response)
resp['body'].should match('some=data')
resp['head'].should include('X-Upload')
end
View
14 spec/integration/echo_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require File.join(File.dirname(__FILE__), '../../', 'examples/echo')
require 'multipart_body'
-require 'yajl'
+require 'yajl' if RUBY_PLATFORM != 'java'
describe Echo do
let(:err) { Proc.new { fail "API request failed" } }
@@ -9,7 +9,7 @@
it 'returns the echo param' do
with_api(Echo) do
get_request({:query => {:echo => 'test'}}, err) do |c|
- b = Yajl::Parser.parse(c.response)
+ b = MultiJson.load(c.response)
b['response'].should == 'test'
end
end
@@ -18,7 +18,7 @@
it 'returns error without echo' do
with_api(Echo) do
get_request({}, err) do |c|
- b = Yajl::Parser.parse(c.response)
+ b = MultiJson.load(c.response)
b['error'].should_not be_nil
b['error'].should == 'echo identifier missing'
end
@@ -28,7 +28,7 @@
it 'echos POST data' do
with_api(Echo) do
post_request({:body => {'echo' => 'test'}}, err) do |c|
- b = Yajl::Parser.parse(c.response)
+ b = MultiJson.load(c.response)
b['response'].should == 'test'
end
end
@@ -41,7 +41,7 @@
post_request({:body => body.to_s,
:head => head}, err) do |c|
- b = Yajl::Parser.parse(c.response)
+ b = MultiJson.load(c.response)
b['response'].should == 'test'
end
end
@@ -49,12 +49,12 @@
it 'echos application/json POST body data' do
with_api(Echo) do
- body = Yajl::Encoder.encode({'echo' => 'My Echo'})
+ body = MultiJson.dump({'echo' => 'My Echo'})
head = {'content-type' => 'application/json'}
post_request({:body => body.to_s,
:head => head}, err) do |c|
- b = Yajl::Parser.parse(c.response)
+ b = MultiJson.load(c.response)
b['response'].should == 'My Echo'
end
end
View
4 spec/integration/keepalive_spec.rb
@@ -9,13 +9,13 @@
r1.errback { fail }
r1.callback do |c|
- b = Yajl::Parser.parse(c.response)
+ b = MultiJson.load(c.response)
b['response'].should == 'test'
r2 = conn.get(:query => {:echo => 'test2'})
r2.errback { fail }
r2.callback do |c|
- b = Yajl::Parser.parse(c.response)
+ b = MultiJson.load(c.response)
b['response'].should == 'test2'
stop
View
2  spec/integration/template_spec.rb
@@ -27,7 +27,7 @@ def config_file
it 'renders a markdown template with default haml layout' do
with_api(Template, api_options) do
get_request(:path => '/joke') do |c|
- c.response.should =~ %r{<code>"Arr, I dunno matey -- but it's drivin' me nuts!"\s*</code>}m
+ c.response.should =~ %r{<code>Arr, I dunno matey -- but it is driving me nuts!\s*</code>}m
end
end
end
View
6 spec/unit/rack/formatters/json_spec.rb
@@ -30,13 +30,13 @@
@app.should_receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
status, header, body = @js.call({})
- lambda { Yajl::Parser.parse(body.first)['a'].should == 1 }.should_not raise_error
+ lambda { MultiJson.load(body.first)['a'].should == 1 }.should_not raise_error
end
it "doesn't format to json if the type is not application/json" do
@app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
- Yajl::Parser.should_not_receive(:encode)
+ MultiJson.should_not_receive(:dump)
status, header, body = @js.call({})
body[:a].should == 1
end
@@ -44,7 +44,7 @@
it 'returns the status and headers' do
@app.should_receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
- Yajl::Parser.should_not_receive(:encode)
+ MultiJson.should_not_receive(:dump)
status, header, body = @js.call({})
status.should == 200
header.should == {'Content-Type' => 'application/xml'}
Please sign in to comment.
Something went wrong with that request. Please try again.