json_proxy 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/README.rdoc +66 -0
- data/Rakefile +29 -0
- data/bin/json_proxy +117 -0
- data/bin/json_proxy_worker +28 -0
- data/bin/json_proxy_worker~ +24 -0
- data/bin/json_proxy~ +117 -0
- data/test/functional/server_spec.rb +138 -0
- data/test/functional/server_spec.rb~ +137 -0
- data/test/functional/spec_helper.rb +14 -0
- data/test/functional/spec_helper.rb~ +16 -0
- data/test/functional/test_service.rb +17 -0
- data/test/functional/test_service.rb~ +0 -0
- data/test/spec/handlers/cache_handler_spec.rb +206 -0
- data/test/spec/handlers/cache_handler_spec.rb~ +206 -0
- data/test/spec/handlers/queue_handler_spec.rb +78 -0
- data/test/spec/handlers/route_handler_spec.rb +72 -0
- data/test/spec/handlers/route_handler_spec.rb~ +72 -0
- data/test/spec/json_spec.rb~ +38 -0
- data/test/spec/queue/queue_daemon_spec.rb +21 -0
- data/test/spec/queue/queue_spec.rb +18 -0
- data/test/spec/spec_helper.rb +9 -0
- data/test/spec/spec_helper.rb~ +8 -0
- data/test/spec/utils/json_spec.rb +50 -0
- data/test/spec/utils/json_spec.rb~ +44 -0
- metadata +111 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/queue/queue.rb'
|
4
|
+
require File.dirname(__FILE__) + '/../../../lib/server/handlers/handler.rb'
|
5
|
+
require File.dirname(__FILE__) + '/../../../lib/server/handlers/queue_handler.rb'
|
6
|
+
|
7
|
+
describe "QueueHandler#initialize" do
|
8
|
+
it "should create a queue" do
|
9
|
+
UrlQueue::UrlQueue.should_receive(:new)
|
10
|
+
Server::Handlers::QueueHandler.new mock('name'), mock('namespace'), mock('options')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe "Queue Handler#action" do
|
16
|
+
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@handler = Server::Handlers::QueueHandler.new mock('name'), mock('namespace'), mock('options')
|
20
|
+
@queue = mock("queue")
|
21
|
+
@handler.instance_variable_set("@queue", @queue)
|
22
|
+
@request = mock("request")
|
23
|
+
@response = mock("response")
|
24
|
+
@block_body = mock("block_body")
|
25
|
+
@block_body.stub!(:yielded)
|
26
|
+
end
|
27
|
+
|
28
|
+
def action
|
29
|
+
@handler.action @request, @response do |request, response|
|
30
|
+
@block_body.yielded request, response
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
it "should call request.force?" do
|
36
|
+
@request.should_receive('force?').and_return(true)
|
37
|
+
action
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "with force?" do
|
41
|
+
before(:each) do
|
42
|
+
@request.stub!('force?').and_return(true)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should yield to the next handler" do
|
46
|
+
@request.should_receive('force?').and_return(true)
|
47
|
+
@block_body.should_receive(:yielded).with(@request, @response)
|
48
|
+
action
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "not with force?" do
|
54
|
+
before(:each) do
|
55
|
+
@request.stub!('force?').and_return(false)
|
56
|
+
@request.stub!(:url)
|
57
|
+
@response.stub!(:status=)
|
58
|
+
@response.stub!(:message=)
|
59
|
+
@queue.stub!(:add)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set response status to 202" do
|
63
|
+
@response.should_receive(:status=).with(202)
|
64
|
+
action
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should set response message to 'Processing. Please retry your request shortly'" do
|
68
|
+
@response.should_receive(:message=).with('Processing. Please retry your request shortly')
|
69
|
+
action
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should add the url to the queue" do
|
73
|
+
@request.should_receive(:url).with({:force => true}).and_return(:url)
|
74
|
+
@queue.should_receive(:add).with(:url)
|
75
|
+
action
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe "RouteHandler#action" do
|
5
|
+
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@name = 'name'
|
9
|
+
@namespace = 'namespace'
|
10
|
+
@options = mock("options")
|
11
|
+
|
12
|
+
@block_body = mock("block_body")
|
13
|
+
@block_body.stub!(:yielded)
|
14
|
+
@block_body.stub!(:in_context)
|
15
|
+
|
16
|
+
|
17
|
+
@block = Proc.new { |*args|
|
18
|
+
@block_body.yielded *args
|
19
|
+
@block_body.in_context self
|
20
|
+
:block_return
|
21
|
+
}
|
22
|
+
|
23
|
+
@handler = Server::Handlers::RouteHandler.new @namespace, @name, @options, @block
|
24
|
+
@handler.instance_variable_set(:@block_body, @block_body)
|
25
|
+
|
26
|
+
@request = mock("request")
|
27
|
+
@request.stub!(:args)
|
28
|
+
|
29
|
+
@response = mock("response")
|
30
|
+
@response.stub!(:body=)
|
31
|
+
end
|
32
|
+
|
33
|
+
def action
|
34
|
+
@handler.action @request, @response
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set request instance variable" do
|
38
|
+
action
|
39
|
+
@handler.instance_variable_get(:@request).should be(@request)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set response instance variable" do
|
43
|
+
action
|
44
|
+
@handler.instance_variable_get(:@response).should be(@response)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should execute block with request args" do
|
48
|
+
@request.should_receive(:args).and_return(:request_args)
|
49
|
+
@block_body.should_receive(:yielded).with(:request_args)
|
50
|
+
action
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should execute block in the handlers context" do
|
54
|
+
@block_body.should_receive(:in_context).with(@handler)
|
55
|
+
action
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set the response body to the block return" do
|
59
|
+
@response.should_receive(:body=).with(:block_return)
|
60
|
+
action
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not alter handler2 " do
|
64
|
+
action
|
65
|
+
handler2 = Server::Handlers::RouteHandler.new @namespace, @name, @options, @block
|
66
|
+
handler2.method(:route).should raise_error(NameError)
|
67
|
+
@handler.method(:route).should_not be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe "RouteHandler#action" do
|
5
|
+
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@name = 'name'
|
9
|
+
@namespace = 'namespace'
|
10
|
+
@options = mock("options")
|
11
|
+
|
12
|
+
@block_body = mock("block_body")
|
13
|
+
@block_body.stub!(:yielded)
|
14
|
+
@block_body.stub!(:in_context)
|
15
|
+
|
16
|
+
|
17
|
+
@block = Proc.new { |*args|
|
18
|
+
@block_body.yielded *args
|
19
|
+
@block_body.in_context self
|
20
|
+
:block_return
|
21
|
+
}
|
22
|
+
|
23
|
+
@handler = Server::Handlers::RouteHandler.new @namespace, @name, @options, @block
|
24
|
+
@handler.instance_variable_set(:@block_body, @block_body)
|
25
|
+
|
26
|
+
@request = mock("request")
|
27
|
+
@request.stub!(:args)
|
28
|
+
|
29
|
+
@response = mock("response")
|
30
|
+
@response.stub!(:body=)
|
31
|
+
end
|
32
|
+
|
33
|
+
def action
|
34
|
+
@handler.action @request, @response
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set request instance variable" do
|
38
|
+
action
|
39
|
+
@handler.instance_variable_get(:@request).should be(@request)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should set response instance variable" do
|
43
|
+
action
|
44
|
+
@handler.instance_variable_get(:@response).should be(@response)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should execute block with request args" do
|
48
|
+
@request.should_receive(:args).and_return(:request_args)
|
49
|
+
@block_body.should_receive(:yielded).with(:request_args)
|
50
|
+
action
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should execute block in the handlers context" do
|
54
|
+
@block_body.should_receive(:in_context).with(@handler)
|
55
|
+
action
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set the response body to the block return" do
|
59
|
+
@response.should_receive(:body=).with(:block_return)
|
60
|
+
action
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not alter handler2 " do
|
64
|
+
handler2 = Server::Handlers::RouteHandler.new @namespace, @name, @options, @block
|
65
|
+
action
|
66
|
+
handler2.method(:route).should raise_error(NameError)
|
67
|
+
@handler.method(:route).should_not be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class Dummy
|
4
|
+
attr_accessor :atrr1
|
5
|
+
attr_accessor :atrr2
|
6
|
+
|
7
|
+
def initialize(a1, a2)
|
8
|
+
@attr1 = a1
|
9
|
+
@attr2 = a2
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "JSON" do
|
16
|
+
|
17
|
+
it "should correctly serialize a hash" do
|
18
|
+
test_obj = HashWithIndifferentAccess.new :prop1 => "Blah", :prop2 => 3, :prop4 => nil #Propnames get serialized as strings but we don't care
|
19
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
20
|
+
deserialized_obj.should ==test_obj
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should correctly serialize an object" do
|
24
|
+
test_obj = Dummy.new "blah", 3
|
25
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
26
|
+
deserialized_obj.should == {"attr1" => "blah", "attr2" => 3}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should correctly serialize a hash containing objects" do
|
30
|
+
test_obj = { :objProp => Dummy.new("blah", 3), :otherProp => "woo" }
|
31
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
32
|
+
deserialized_obj.should == {"objProp" => {"attr1" => "blah", "attr2" => 3}, "otherProp" => 3}
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/queue/queue'
|
4
|
+
require File.dirname(__FILE__) + '/../../../lib/queue/queue_daemon'
|
5
|
+
|
6
|
+
describe "QueueDaemon" do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@q = mock("Queue")
|
10
|
+
@urls = ["http://example.com/1", "http://example.com/2"]
|
11
|
+
@daemon = UrlQueue::QueueDaemon.new
|
12
|
+
@daemon.instance_variable_set('@q',@q)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "fetch urls from queue" do
|
16
|
+
@q.should_receive(:get).exactly(3).times.and_return(@urls[0], @urls[1], nil)
|
17
|
+
Net::HTTP.should_receive(:get_response).twice()
|
18
|
+
@daemon.process
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../lib/queue/queue'
|
4
|
+
|
5
|
+
describe "Queue" do
|
6
|
+
|
7
|
+
it "should queue urls" do
|
8
|
+
queue = UrlQueue::UrlQueue.new('test-queue');
|
9
|
+
test_url = "http://localhost/echo?message=blah"
|
10
|
+
queue.get.should be_nil
|
11
|
+
queue.add(test_url)
|
12
|
+
queue.get.should == test_url
|
13
|
+
queue.get.should be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class Dummy
|
4
|
+
attr_accessor :atrr1
|
5
|
+
attr_accessor :atrr2
|
6
|
+
|
7
|
+
def initialize(a1, a2)
|
8
|
+
@attr1 = a1
|
9
|
+
@attr2 = a2
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "JSON" do
|
16
|
+
|
17
|
+
it "should correctly serialize a hash" do
|
18
|
+
test_obj = HashWithIndifferentAccess.new :prop1 => "Blah", :prop2 => 3, :prop4 => nil #Propnames get serialized as strings but we don't care
|
19
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
20
|
+
deserialized_obj.should ==test_obj
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should correctly serialize an object" do
|
24
|
+
test_obj = Dummy.new "blah", 3
|
25
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
26
|
+
deserialized_obj.should == {"attr1" => "blah", "attr2" => 3}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should correctly serialize an array" do
|
30
|
+
test_obj = ["one", "two", "three"]
|
31
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
32
|
+
deserialized_obj.should == test_obj
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should correctly serialize a hash containing an array" do
|
36
|
+
test_obj = HashWithIndifferentAccess.new :prop1 => ["one", "two", "three"]
|
37
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
38
|
+
deserialized_obj.should == test_obj
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should correctly serialize a hash containing objects" do
|
42
|
+
test_obj = { :objProp => Dummy.new("blah", 3), :otherProp => "woo" }
|
43
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
44
|
+
deserialized_obj.should == {"objProp" => {"attr1" => "blah", "attr2" => 3}, "otherProp" => "woo"}
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class Dummy
|
4
|
+
attr_accessor :atrr1
|
5
|
+
attr_accessor :atrr2
|
6
|
+
|
7
|
+
def initialize(a1, a2)
|
8
|
+
@attr1 = a1
|
9
|
+
@attr2 = a2
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "JSON" do
|
16
|
+
|
17
|
+
it "should correctly serialize a hash" do
|
18
|
+
test_obj = HashWithIndifferentAccess.new :prop1 => "Blah", :prop2 => 3, :prop4 => nil #Propnames get serialized as strings but we don't care
|
19
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
20
|
+
deserialized_obj.should ==test_obj
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should correctly serialize an object" do
|
24
|
+
test_obj = Dummy.new "blah", 3
|
25
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
26
|
+
deserialized_obj.should == {"attr1" => "blah", "attr2" => 3}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should correctly serialize an array" do
|
30
|
+
test_obj = ["one", "two", "three"]
|
31
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
32
|
+
deserialized_obj.should == test_obj
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should correctly serialize a hash containing objects" do
|
36
|
+
test_obj = { :objProp => Dummy.new("blah", 3), :otherProp => "woo" }
|
37
|
+
deserialized_obj = JSON.parse test_obj.to_json
|
38
|
+
deserialized_obj.should == {"objProp" => {"attr1" => "blah", "attr2" => 3}, "otherProp" => "woo"}
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_proxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gareth Andrew
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-30 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: starling
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.8
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: activesupport
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.1.0
|
44
|
+
version:
|
45
|
+
description: A JSON webservices DSL/server
|
46
|
+
email: gingerhendrix@gmail.com
|
47
|
+
executables:
|
48
|
+
- json_proxy
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files: []
|
52
|
+
|
53
|
+
files:
|
54
|
+
- History.txt
|
55
|
+
- Rakefile
|
56
|
+
- README.rdoc
|
57
|
+
- bin/json_proxy~
|
58
|
+
- bin/json_proxy
|
59
|
+
- bin/json_proxy_worker
|
60
|
+
- bin/json_proxy_worker~
|
61
|
+
- test/spec
|
62
|
+
- test/spec/spec_helper.rb
|
63
|
+
- test/spec/queue
|
64
|
+
- test/spec/queue/queue_daemon_spec.rb
|
65
|
+
- test/spec/queue/queue_spec.rb
|
66
|
+
- test/spec/handlers
|
67
|
+
- test/spec/handlers/queue_handler_spec.rb
|
68
|
+
- test/spec/handlers/cache_handler_spec.rb
|
69
|
+
- test/spec/handlers/route_handler_spec.rb
|
70
|
+
- test/spec/handlers/cache_handler_spec.rb~
|
71
|
+
- test/spec/handlers/route_handler_spec.rb~
|
72
|
+
- test/spec/utils
|
73
|
+
- test/spec/utils/json_spec.rb
|
74
|
+
- test/spec/utils/json_spec.rb~
|
75
|
+
- test/spec/spec_helper.rb~
|
76
|
+
- test/spec/json_spec.rb~
|
77
|
+
- test/functional
|
78
|
+
- test/functional/server_spec.rb
|
79
|
+
- test/functional/spec_helper.rb
|
80
|
+
- test/functional/test_service.rb
|
81
|
+
- test/functional/server_spec.rb~
|
82
|
+
- test/functional/spec_helper.rb~
|
83
|
+
- test/functional/test_service.rb~
|
84
|
+
has_rdoc: true
|
85
|
+
homepage: http://projects.gandrew.com/json_proxy
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.8.5
|
96
|
+
version:
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "0"
|
102
|
+
version:
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project: json_proxy
|
106
|
+
rubygems_version: 1.3.0
|
107
|
+
signing_key:
|
108
|
+
specification_version: 2
|
109
|
+
summary: A JSON webservices DSL/server
|
110
|
+
test_files: []
|
111
|
+
|