anmo 0.0.12 → 0.0.13
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/features/api.feature +16 -0
- data/features/step_definitions/api_steps.rb +30 -0
- data/lib/anmo/application.rb +34 -13
- data/lib/anmo/version.rb +1 -1
- data/test/anmo/application_test.rb +41 -2
- metadata +21 -21
data/features/api.feature
CHANGED
@@ -194,3 +194,19 @@ Feature: API
|
|
194
194
|
@result = Anmo.running?
|
195
195
|
"""
|
196
196
|
Then I see that the anmo server is running
|
197
|
+
|
198
|
+
Scenario: Anmo requests are different depending on the host
|
199
|
+
Given an anmo server
|
200
|
+
And I request the path "/hello1" on the host "http://example1.org"
|
201
|
+
And I request the path "/hello2" on the host "http://example2.org"
|
202
|
+
And I request the path "/hello3" on the host "http://example3.org"
|
203
|
+
When I list requests on the host "http://example2.org"
|
204
|
+
Then I should see the request with the path "/hello2"
|
205
|
+
|
206
|
+
Scenario: Anmo objects are different depending on the host
|
207
|
+
Given an anmo server
|
208
|
+
And I save an object to the host "http://example.org"
|
209
|
+
And I save an object to the host "http://another.org"
|
210
|
+
And I save an object to the host "http://sample.org"
|
211
|
+
When I request the object from the host "http://another.org"
|
212
|
+
Then I see the object saved to the host "http://another.org"
|
@@ -81,3 +81,33 @@ end
|
|
81
81
|
Then /^I see that the anmo server is running$/ do
|
82
82
|
@result.should == true
|
83
83
|
end
|
84
|
+
|
85
|
+
Given /^I save an object to the host "([^"]*)"$/ do |host|
|
86
|
+
HTTParty.post("http://localhost:8787/__CREATE_OBJECT__", {
|
87
|
+
:body => {:path => "/lulz", :body => host}.to_json,
|
88
|
+
:headers => {"Host" => host}
|
89
|
+
})
|
90
|
+
end
|
91
|
+
|
92
|
+
When /^I request the object from the host "([^"]*)"$/ do |host|
|
93
|
+
@response = HTTParty.get("http://localhost:8787/lulz", :headers => {"Host" => host})
|
94
|
+
end
|
95
|
+
|
96
|
+
Then /^I see the object saved to the host "([^"]*)"$/ do |host|
|
97
|
+
@response.body.should == host
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
Given /^I request the path "([^"]*)" on the host "([^"]*)"$/ do |path, host|
|
102
|
+
@response = HTTParty.get("http://localhost:8787#{path}", :headers => {"Host" => host})
|
103
|
+
end
|
104
|
+
|
105
|
+
When /^I list requests on the host "([^"]*)"$/ do |host|
|
106
|
+
json = HTTParty.get("http://localhost:8787/__REQUESTS__", :headers => {"Host" => host}).body
|
107
|
+
@requests = JSON.parse(json)
|
108
|
+
end
|
109
|
+
|
110
|
+
Then /^I should see the request with the path "([^"]*)"$/ do |path|
|
111
|
+
@requests.size.should == 1
|
112
|
+
@requests.first["PATH_INFO"].should == path
|
113
|
+
end
|
data/lib/anmo/application.rb
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
module Anmo
|
2
2
|
class ApplicationDataStore
|
3
3
|
class << self
|
4
|
-
|
4
|
+
def reset_requests!
|
5
|
+
@stored_requests = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def reset_stored_objects!
|
9
|
+
@stored_objects = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def stored_requests host
|
13
|
+
@stored_requests ||= {}
|
14
|
+
@stored_requests[host] ||= []
|
15
|
+
@stored_requests[host]
|
16
|
+
end
|
17
|
+
|
18
|
+
def stored_objects host
|
19
|
+
@stored_objects ||= {}
|
20
|
+
@stored_objects[host] ||= []
|
21
|
+
@stored_objects[host]
|
22
|
+
end
|
5
23
|
end
|
6
24
|
end
|
7
25
|
|
8
26
|
class Application
|
9
|
-
def initialize
|
10
|
-
ApplicationDataStore.stored_objects ||= []
|
11
|
-
ApplicationDataStore.stored_requests ||= []
|
12
|
-
end
|
13
|
-
|
14
27
|
def call env
|
15
28
|
request = Rack::Request.new(env)
|
16
29
|
|
@@ -30,23 +43,31 @@ module Anmo
|
|
30
43
|
|
31
44
|
private
|
32
45
|
|
46
|
+
def stored_requests request
|
47
|
+
ApplicationDataStore.stored_requests(request.host)
|
48
|
+
end
|
49
|
+
|
50
|
+
def stored_objects request
|
51
|
+
ApplicationDataStore.stored_objects(request.host)
|
52
|
+
end
|
53
|
+
|
33
54
|
def alive request
|
34
55
|
[200, {"Content-Type" => "text/html"}, ["<h1>anmo is alive</h1>"]]
|
35
56
|
end
|
36
57
|
|
37
58
|
def create_object request
|
38
59
|
request_info = JSON.parse(read_request_body(request))
|
39
|
-
|
60
|
+
stored_objects(request).unshift(request_info)
|
40
61
|
[201, {"Content-Type" => "text/html"}, [""]]
|
41
62
|
end
|
42
63
|
|
43
64
|
def delete_all_objects request
|
44
|
-
ApplicationDataStore.
|
65
|
+
ApplicationDataStore.reset_stored_objects!
|
45
66
|
[200, {"Content-Type" => "text/html"}, [""]]
|
46
67
|
end
|
47
68
|
|
48
69
|
def process_normal_request request
|
49
|
-
|
70
|
+
stored_requests(request) << request.env
|
50
71
|
|
51
72
|
if found_request = find_stored_request(request)
|
52
73
|
[Integer(found_request["status"]||200), {"Content-Type" => "text/html"}, [found_request["body"]]]
|
@@ -56,16 +77,16 @@ module Anmo
|
|
56
77
|
end
|
57
78
|
|
58
79
|
def requests request
|
59
|
-
[200, {"Content-Type" => "application/json"}, [(
|
80
|
+
[200, {"Content-Type" => "application/json"}, [stored_requests(request).to_json]]
|
60
81
|
end
|
61
82
|
|
62
83
|
def delete_all_requests request
|
63
|
-
ApplicationDataStore.
|
84
|
+
ApplicationDataStore.reset_requests!
|
64
85
|
[200, {"Content-Type" => "text/html"}, ""]
|
65
86
|
end
|
66
87
|
|
67
88
|
def objects request
|
68
|
-
[200, {"Content-Type" => "application/json"}, [
|
89
|
+
[200, {"Content-Type" => "application/json"}, [stored_objects(request).to_json]]
|
69
90
|
end
|
70
91
|
|
71
92
|
def find_stored_request actual_request
|
@@ -74,7 +95,7 @@ module Anmo
|
|
74
95
|
actual_request_url << "?" + actual_request.query_string
|
75
96
|
end
|
76
97
|
|
77
|
-
found_request =
|
98
|
+
found_request = stored_objects(actual_request).find {|r| r["path"] == actual_request_url}
|
78
99
|
if found_request
|
79
100
|
if found_request["method"]
|
80
101
|
if actual_request.request_method != found_request["method"].upcase
|
data/lib/anmo/version.rb
CHANGED
@@ -14,8 +14,8 @@ module Anmo
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def setup
|
17
|
-
ApplicationDataStore.
|
18
|
-
ApplicationDataStore.
|
17
|
+
ApplicationDataStore.reset_requests!
|
18
|
+
ApplicationDataStore.reset_stored_objects!
|
19
19
|
end
|
20
20
|
|
21
21
|
def save_object path, body, status, required_headers, method
|
@@ -176,5 +176,44 @@ module Anmo
|
|
176
176
|
assert last_response.ok?
|
177
177
|
assert_equal "<h1>anmo is alive</h1>", last_response.body
|
178
178
|
end
|
179
|
+
|
180
|
+
def test_returns_different_requests_depending_on_http_host
|
181
|
+
1.upto(3) do |number|
|
182
|
+
with_host "example#{number}.org" do
|
183
|
+
get "/lulz#{number}"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
with_host "example2.org" do
|
188
|
+
get "/__REQUESTS__"
|
189
|
+
end
|
190
|
+
|
191
|
+
json = JSON.parse(last_response.body)
|
192
|
+
assert_equal 1, json.size
|
193
|
+
assert_equal "/lulz2", json.first["PATH_INFO"]
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_returns_different_objects_depending_on_http_host
|
197
|
+
1.upto(3) do |number|
|
198
|
+
with_host "host#{number}.org" do
|
199
|
+
save_object "/path", "body#{number}", nil, nil, nil
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
with_host "host2.org" do
|
204
|
+
get "/path"
|
205
|
+
end
|
206
|
+
assert_equal "body2", last_response.body
|
207
|
+
end
|
208
|
+
|
209
|
+
private
|
210
|
+
|
211
|
+
def with_host(host)
|
212
|
+
previous_host = Rack::Test::DEFAULT_HOST.dup
|
213
|
+
Rack::Test::DEFAULT_HOST.replace host
|
214
|
+
yield
|
215
|
+
ensure
|
216
|
+
Rack::Test::DEFAULT_HOST.replace previous_host
|
217
|
+
end
|
179
218
|
end
|
180
219
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anmo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-21 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70120926224000 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70120926224000
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: thin
|
27
|
-
requirement: &
|
27
|
+
requirement: &70120926223580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70120926223580
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: httparty
|
38
|
-
requirement: &
|
38
|
+
requirement: &70120926223120 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70120926223120
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70120926222580 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70120926222580
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: minitest
|
60
|
-
requirement: &
|
60
|
+
requirement: &70120926222060 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70120926222060
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack-test
|
71
|
-
requirement: &
|
71
|
+
requirement: &70120926221640 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70120926221640
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: cucumber
|
82
|
-
requirement: &
|
82
|
+
requirement: &70120926221120 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70120926221120
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70120926213720 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70120926213720
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: guard
|
104
|
-
requirement: &
|
104
|
+
requirement: &70120926213180 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70120926213180
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: guard-shell
|
115
|
-
requirement: &
|
115
|
+
requirement: &70120926212640 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70120926212640
|
124
124
|
description: ''
|
125
125
|
email:
|
126
126
|
- andrew.vos@gmail.com
|