visionmedia-swarm 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +5 -0
- data/Manifest +39 -0
- data/Rakefile +18 -0
- data/Readme.md +69 -0
- data/bin/swarm +30 -0
- data/jspec/server.rb +4 -0
- data/jspec/spec.dom.html +27 -0
- data/jspec/spec.rhino.js +8 -0
- data/jspec/spec.safe.js +12 -0
- data/jspec/spec.server.html +16 -0
- data/jspec/spec.swarm.js +35 -0
- data/lib/public/images/chrome.png +0 -0
- data/lib/public/images/chrome.sm.png +0 -0
- data/lib/public/images/gecko.png +0 -0
- data/lib/public/images/gecko.sm.png +0 -0
- data/lib/public/images/konqueror.png +0 -0
- data/lib/public/images/konqueror.sm.png +0 -0
- data/lib/public/images/msie.png +0 -0
- data/lib/public/images/msie.sm.png +0 -0
- data/lib/public/images/presto.png +0 -0
- data/lib/public/images/presto.sm.png +0 -0
- data/lib/public/images/webkit.png +0 -0
- data/lib/public/images/webkit.sm.png +0 -0
- data/lib/public/jquery.js +19 -0
- data/lib/public/jquery.rest.js +27 -0
- data/lib/public/jquery.smart-poll.js +40 -0
- data/lib/public/safe.js +2 -0
- data/lib/public/swarm.css +0 -0
- data/lib/public/swarm.html +28 -0
- data/lib/public/swarm.js +92 -0
- data/lib/swarm.rb +31 -0
- data/lib/swarm/agent.rb +78 -0
- data/lib/swarm/job.rb +68 -0
- data/lib/swarm/swarm.rb +185 -0
- data/spec/agent_spec.rb +57 -0
- data/spec/job_spec.rb +45 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/swarm_spec.rb +142 -0
- data/swarm.gemspec +47 -0
- metadata +170 -0
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
+
ENV['RACK_ENV'] = 'testing'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'swarm'
|
7
|
+
require 'rack/test'
|
8
|
+
|
9
|
+
DataMapper.setup :default, 'sqlite3::memory:'
|
10
|
+
DataMapper.auto_migrate!
|
11
|
+
|
12
|
+
Spec::Runner.configure do |conf|
|
13
|
+
conf.include Rack::Test::Methods
|
14
|
+
end
|
data/spec/swarm_spec.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
describe Swarm do
|
6
|
+
def app
|
7
|
+
Swarm
|
8
|
+
end
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
DataMapper.auto_migrate!
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "routes" do
|
15
|
+
before :each do
|
16
|
+
$stderr = StringIO.new
|
17
|
+
@chrome = 'Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.202.2 Safari/532.0'
|
18
|
+
end
|
19
|
+
|
20
|
+
def last_response_should_be_invalid_as_json
|
21
|
+
last_response.should be_ok
|
22
|
+
last_response['Content-Type'].should == 'application/json'
|
23
|
+
last_response.body.should include('"status":0')
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "POST /job" do
|
27
|
+
it "should create a job and respond with it's JSON" do
|
28
|
+
post '/job', { :source => 'stuff here' }, 'REMOTE_ADDR' => '127.0.0.1'
|
29
|
+
last_response['Content-Type'].should == 'application/json'
|
30
|
+
last_response.body.should include(%("id":#{Job.last.id}))
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should respond with invalid json response when :source is not present" do
|
34
|
+
post '/job', {}, 'REMOTE_ADDR' => '127.0.0.1', 'ACCEPT' => 'application/json'
|
35
|
+
last_response_should_be_invalid_as_json
|
36
|
+
last_response.body.should include(':source required')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "PUT /job/:id" do
|
41
|
+
before :each do
|
42
|
+
@agent = Agent.create :address => '127.0.0.1', :string => @chrome, :busy => true
|
43
|
+
@job = Job.create :address => '127.0.0.1', :source => 'foo', :active => true
|
44
|
+
put "/job/#{@job.id}", { :passes => 10 }, 'REMOTE_ADDR' => '127.0.0.1', 'HTTP_USER_AGENT' => @chrome
|
45
|
+
@agent.reload
|
46
|
+
@job.reload
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should update a job with params as the result" do
|
50
|
+
last_response.should be_ok
|
51
|
+
@job.results.should == [{ 'passes' => '10', 'id' => @job.id }]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should add the job update to the current agent" do
|
55
|
+
@agent.jobs.should == [@job]
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should mark the agent as being no longer busy" do
|
59
|
+
@agent.should_not be_busy
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "GET /public/*" do
|
64
|
+
it "should transfer the file" do
|
65
|
+
get '/public/jquery.js'
|
66
|
+
last_response.should be_ok
|
67
|
+
last_response['Content-Type'].should == 'application/javascript'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "GET /job/:id.json" do
|
72
|
+
it "should return a job's JSON" do
|
73
|
+
job = Job.create :address => '127.0.0.1', :source => 'foo', :active => true
|
74
|
+
get "/job/#{job.id}.json"
|
75
|
+
last_response.should be_ok
|
76
|
+
last_response['Content-Type'].should == 'application/json'
|
77
|
+
last_response.body.should include(%("id":#{job.id}))
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should respond with invalid json response when job present" do
|
81
|
+
get '/job/999.json', {}, 'ACCEPT' => 'application/json'
|
82
|
+
last_response_should_be_invalid_as_json
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "GET /job" do
|
87
|
+
it "should find an active job for the current agent, responding with its JSON" do
|
88
|
+
agent = Agent.create :address => '127.0.0.1', :string => @chrome
|
89
|
+
job = Job.create :address => '127.0.0.1', :source => 'foo', :active => true
|
90
|
+
get '/job', {}, 'HTTP_USER_AGENT' => @chrome, 'REMOTE_ADDR' => '127.0.0.1'
|
91
|
+
last_response.should be_ok
|
92
|
+
last_response['Content-Type'].should == 'application/json'
|
93
|
+
last_response.body.should include('"id":1')
|
94
|
+
agent.jobs.should == [job]
|
95
|
+
agent.should be_busy
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should respond with invalid json response when no active job is found" do
|
99
|
+
Job.all.destroy
|
100
|
+
get '/job', {}, 'ACCEPT' => 'application/json'
|
101
|
+
last_response_should_be_invalid_as_json
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "GET /bind" do
|
106
|
+
it "should create an Agent" do
|
107
|
+
get '/bind', {}, 'HTTP_USER_AGENT' => @chrome, 'REMOTE_ADDR' => '127.0.0.1'
|
108
|
+
last_response.should be_ok
|
109
|
+
Agent.first.name.should == :Chrome
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should tranfser swarm.html" do
|
113
|
+
get '/bind', {}, 'HTTP_USER_AGENT' => @chrome, 'REMOTE_ADDR' => '127.0.0.1'
|
114
|
+
last_response.should be_ok
|
115
|
+
last_response.body.should include('<html')
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should respond with 404 when the agent is not created" do
|
119
|
+
get '/bind'
|
120
|
+
last_response.should_not be_ok
|
121
|
+
last_response.body.should include('invalid user agent')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe ".agents_for" do
|
127
|
+
before :each do
|
128
|
+
@safari = Agent.create :string => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en) AppleWebKit/526.9 (KHTML, like Gecko) Version/4.0dp1 Safari/526.8', :address => '127.0.0.1'
|
129
|
+
@chrome = Agent.create :string => 'Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/4.0.202.2 Safari/532.0', :address => '127.0.0.1'
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should return unique agents related to the browser names passed" do
|
133
|
+
Swarm.agents_for(:Safari).should == [@safari]
|
134
|
+
Swarm.agents_for(:Safari, :Chrome).should == [@safari, @chrome]
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should allow lowercase" do
|
138
|
+
Swarm.agents_for('safari').should == [@safari]
|
139
|
+
Swarm.agents_for('safari', 'chrome').should == [@safari, @chrome]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/swarm.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{swarm}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["TJ Holowaychuk"]
|
9
|
+
s.date = %q{2009-09-20}
|
10
|
+
s.default_executable = %q{swarm}
|
11
|
+
s.description = %q{Ruby TestSwarm implementation}
|
12
|
+
s.email = %q{tj@vision-media.ca}
|
13
|
+
s.executables = ["swarm"]
|
14
|
+
s.extra_rdoc_files = ["bin/swarm", "lib/public/images/chrome.png", "lib/public/images/chrome.sm.png", "lib/public/images/gecko.png", "lib/public/images/gecko.sm.png", "lib/public/images/konqueror.png", "lib/public/images/konqueror.sm.png", "lib/public/images/msie.png", "lib/public/images/msie.sm.png", "lib/public/images/presto.png", "lib/public/images/presto.sm.png", "lib/public/images/webkit.png", "lib/public/images/webkit.sm.png", "lib/public/jquery.js", "lib/public/jquery.rest.js", "lib/public/jquery.smart-poll.js", "lib/public/safe.js", "lib/public/swarm.css", "lib/public/swarm.html", "lib/public/swarm.js", "lib/swarm.rb", "lib/swarm/agent.rb", "lib/swarm/job.rb", "lib/swarm/swarm.rb"]
|
15
|
+
s.files = ["History.md", "Rakefile", "Readme.md", "bin/swarm", "jspec/server.rb", "jspec/spec.dom.html", "jspec/spec.rhino.js", "jspec/spec.safe.js", "jspec/spec.server.html", "jspec/spec.swarm.js", "lib/public/images/chrome.png", "lib/public/images/chrome.sm.png", "lib/public/images/gecko.png", "lib/public/images/gecko.sm.png", "lib/public/images/konqueror.png", "lib/public/images/konqueror.sm.png", "lib/public/images/msie.png", "lib/public/images/msie.sm.png", "lib/public/images/presto.png", "lib/public/images/presto.sm.png", "lib/public/images/webkit.png", "lib/public/images/webkit.sm.png", "lib/public/jquery.js", "lib/public/jquery.rest.js", "lib/public/jquery.smart-poll.js", "lib/public/safe.js", "lib/public/swarm.css", "lib/public/swarm.html", "lib/public/swarm.js", "lib/swarm.rb", "lib/swarm/agent.rb", "lib/swarm/job.rb", "lib/swarm/swarm.rb", "spec/agent_spec.rb", "spec/job_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/swarm_spec.rb", "Manifest", "swarm.gemspec"]
|
16
|
+
s.homepage = %q{}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Swarm", "--main", "Readme.md"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{swarm}
|
20
|
+
s.rubygems_version = %q{1.3.5}
|
21
|
+
s.summary = %q{Ruby TestSwarm implementation}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
29
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.4"])
|
30
|
+
s.add_runtime_dependency(%q<dm-core>, [">= 0.10.0"])
|
31
|
+
s.add_runtime_dependency(%q<dm-validations>, [">= 0.10.0"])
|
32
|
+
s.add_runtime_dependency(%q<visionmedia-user-agent>, [">= 0"])
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<json>, [">= 0"])
|
35
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
36
|
+
s.add_dependency(%q<dm-core>, [">= 0.10.0"])
|
37
|
+
s.add_dependency(%q<dm-validations>, [">= 0.10.0"])
|
38
|
+
s.add_dependency(%q<visionmedia-user-agent>, [">= 0"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<json>, [">= 0"])
|
42
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.4"])
|
43
|
+
s.add_dependency(%q<dm-core>, [">= 0.10.0"])
|
44
|
+
s.add_dependency(%q<dm-validations>, [">= 0.10.0"])
|
45
|
+
s.add_dependency(%q<visionmedia-user-agent>, [">= 0"])
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visionmedia-swarm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TJ Holowaychuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-20 00:00:00 -07:00
|
13
|
+
default_executable: swarm
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sinatra
|
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.4
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: dm-core
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.10.0
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: dm-validations
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.10.0
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: visionmedia-user-agent
|
57
|
+
type: :runtime
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
description: Ruby TestSwarm implementation
|
66
|
+
email: tj@vision-media.ca
|
67
|
+
executables:
|
68
|
+
- swarm
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- bin/swarm
|
73
|
+
- lib/public/images/chrome.png
|
74
|
+
- lib/public/images/chrome.sm.png
|
75
|
+
- lib/public/images/gecko.png
|
76
|
+
- lib/public/images/gecko.sm.png
|
77
|
+
- lib/public/images/konqueror.png
|
78
|
+
- lib/public/images/konqueror.sm.png
|
79
|
+
- lib/public/images/msie.png
|
80
|
+
- lib/public/images/msie.sm.png
|
81
|
+
- lib/public/images/presto.png
|
82
|
+
- lib/public/images/presto.sm.png
|
83
|
+
- lib/public/images/webkit.png
|
84
|
+
- lib/public/images/webkit.sm.png
|
85
|
+
- lib/public/jquery.js
|
86
|
+
- lib/public/jquery.rest.js
|
87
|
+
- lib/public/jquery.smart-poll.js
|
88
|
+
- lib/public/safe.js
|
89
|
+
- lib/public/swarm.css
|
90
|
+
- lib/public/swarm.html
|
91
|
+
- lib/public/swarm.js
|
92
|
+
- lib/swarm.rb
|
93
|
+
- lib/swarm/agent.rb
|
94
|
+
- lib/swarm/job.rb
|
95
|
+
- lib/swarm/swarm.rb
|
96
|
+
files:
|
97
|
+
- History.md
|
98
|
+
- Rakefile
|
99
|
+
- Readme.md
|
100
|
+
- bin/swarm
|
101
|
+
- jspec/server.rb
|
102
|
+
- jspec/spec.dom.html
|
103
|
+
- jspec/spec.rhino.js
|
104
|
+
- jspec/spec.safe.js
|
105
|
+
- jspec/spec.server.html
|
106
|
+
- jspec/spec.swarm.js
|
107
|
+
- lib/public/images/chrome.png
|
108
|
+
- lib/public/images/chrome.sm.png
|
109
|
+
- lib/public/images/gecko.png
|
110
|
+
- lib/public/images/gecko.sm.png
|
111
|
+
- lib/public/images/konqueror.png
|
112
|
+
- lib/public/images/konqueror.sm.png
|
113
|
+
- lib/public/images/msie.png
|
114
|
+
- lib/public/images/msie.sm.png
|
115
|
+
- lib/public/images/presto.png
|
116
|
+
- lib/public/images/presto.sm.png
|
117
|
+
- lib/public/images/webkit.png
|
118
|
+
- lib/public/images/webkit.sm.png
|
119
|
+
- lib/public/jquery.js
|
120
|
+
- lib/public/jquery.rest.js
|
121
|
+
- lib/public/jquery.smart-poll.js
|
122
|
+
- lib/public/safe.js
|
123
|
+
- lib/public/swarm.css
|
124
|
+
- lib/public/swarm.html
|
125
|
+
- lib/public/swarm.js
|
126
|
+
- lib/swarm.rb
|
127
|
+
- lib/swarm/agent.rb
|
128
|
+
- lib/swarm/job.rb
|
129
|
+
- lib/swarm/swarm.rb
|
130
|
+
- spec/agent_spec.rb
|
131
|
+
- spec/job_spec.rb
|
132
|
+
- spec/spec.opts
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- spec/swarm_spec.rb
|
135
|
+
- Manifest
|
136
|
+
- swarm.gemspec
|
137
|
+
has_rdoc: false
|
138
|
+
homepage: ""
|
139
|
+
licenses:
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options:
|
142
|
+
- --line-numbers
|
143
|
+
- --inline-source
|
144
|
+
- --title
|
145
|
+
- Swarm
|
146
|
+
- --main
|
147
|
+
- Readme.md
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: "0"
|
155
|
+
version:
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: "1.2"
|
161
|
+
version:
|
162
|
+
requirements: []
|
163
|
+
|
164
|
+
rubyforge_project: swarm
|
165
|
+
rubygems_version: 1.3.5
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: Ruby TestSwarm implementation
|
169
|
+
test_files: []
|
170
|
+
|