vidibus-service 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Service::ControllerValidations" do
4
- it "should be spec'd"
5
- end
@@ -1,226 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Service::Mongoid" do
4
- let(:realm) { "12ab69f099a4012d4df558b035f038ab" }
5
- let(:this) { Service.create!(:function => "manager", :url => "http://manager.local", :uuid => "344b4b8088fb012dd3e558b035f038ab", :secret => "EaDai5nz16DbQTWQuuFdd4WcAiZYRPDwZTn2IQeXbPE4yBg3rr", :realm_uuid => nil, :this => true) }
6
- let(:connector) { Service.create!(:function => "connector", :url => "http://connector.local", :uuid => "60dfef509a8e012d599558b035f038ab", :secret => nil, :realm_uuid => nil) }
7
- let(:uploader) { Service.create!(:function => "uploader", :url => "http://uploader.local", :uuid => "c0861d609247012d0a8b58b035f038ab", :secret => "A7q8Vzxgrk9xrw2FCnvV4bv01UP/LBUUM0lIGDmMcB2GsBTIqx", :realm_uuid => realm) }
8
- let(:client_mock) { this; mock.any_instance_of(Vidibus::Service::Client) }
9
-
10
- describe "validation" do
11
- it "should pass with valid attributes" do
12
- this.should be_valid
13
- end
14
-
15
- it "should fail without a valid URL" do
16
- this.url = "something"
17
- this.should be_invalid
18
- end
19
-
20
- it "should fail without a function" do
21
- this.function = ""
22
- this.should be_invalid
23
- this.errors[:function].should have(1).error
24
- end
25
-
26
- it "should pass with arbitrary functions" do
27
- this.function = :something
28
- this.should be_valid
29
- end
30
-
31
- it "should fail if a secret is given for Connector" do
32
- connector.secret = "something"
33
- connector.should be_invalid
34
- connector.errors[:secret].should have(1).error
35
- connector.errors[:secret].first.should eql("is not allowed for a Connector")
36
- end
37
-
38
- it "should pass with empty secret for Connector" do
39
- connector.secret = nil
40
- connector.should be_valid
41
- end
42
-
43
- it "should fail without a secret for services except Connector" do
44
- uploader.secret = nil
45
- uploader.should be_invalid
46
- uploader.errors[:secret].should have(1).error
47
- end
48
-
49
- it "should fail without a realm_uuid for services except Connector and this" do
50
- uploader.realm_uuid = nil
51
- uploader.should be_invalid
52
- uploader.errors[:realm_uuid].should have(1).error
53
- end
54
-
55
- it "should pass with empty realm_uuid for Connector" do
56
- connector.realm_uuid = nil
57
- connector.should be_valid
58
- end
59
-
60
- it "should pass if realm_uuid is given for Connector" do
61
- connector.realm_uuid = realm
62
- connector.should be_valid
63
- end
64
-
65
- it "should pass if a realm_uuid is given for this" do
66
- this.realm_uuid = realm
67
- this.should be_valid
68
- end
69
-
70
- it "should fail for duplicate UUIDs within same realm" do
71
- duplicate_service = Service.new(:uuid => uploader.uuid, :realm_uuid => realm)
72
- duplicate_service.should be_invalid
73
- duplicate_service.errors[:uuid].should have(1).error
74
- end
75
- end
76
-
77
- describe "#url" do
78
- it "should be set without trailing slash" do
79
- this.url = "http://manager.local/"
80
- this.url.should eql("http://manager.local")
81
- end
82
-
83
- it "should be stored without trailing slash" do
84
- this.update_attributes(:url => "http://manager.local/")
85
- this.reload.url.should eql("http://manager.local")
86
- end
87
- end
88
-
89
- describe "#domain" do
90
- it "should return the url without protocol" do
91
- this.domain.should eql(this.url.gsub(/https?:\/\//, ""))
92
- end
93
- end
94
-
95
- describe "#connector?" do
96
- it "should return true if service is a Connector" do
97
- connector.connector?.should be_true
98
- end
99
-
100
- it "should return false if service is not a Connector" do
101
- uploader.connector?.should be_false
102
- end
103
- end
104
-
105
- describe "#get" do
106
- it "should trigger a GET request" do
107
- client_mock.get("/something", :query => { :gotta => "give" })
108
- uploader.get("/something", :query => { :gotta => "give" })
109
- end
110
- end
111
-
112
- describe "#post" do
113
- it "should trigger a POST request" do
114
- client_mock.post("/something", :query => { :do => "it" })
115
- uploader.post("/something", :query => { :do => "it" })
116
- end
117
- end
118
-
119
- describe "#put" do
120
- it "should trigger a PUT request" do
121
- client_mock.put("/something", :query => { :new => "stuff" })
122
- uploader.put("/something", :query => { :new => "stuff" })
123
- end
124
- end
125
-
126
- describe "#delete" do
127
- it "should trigger a DELETE request" do
128
- client_mock.delete("/something/else", {})
129
- uploader.delete("/something/else")
130
- end
131
- end
132
-
133
- describe ".this" do
134
- it "should return this service" do
135
- this
136
- Service.this.should eql(this)
137
- end
138
-
139
- it "should raise an error if this service has not been configured yet" do
140
- expect {Service.this}.to raise_error(Service::ConfigurationError)
141
- end
142
- end
143
-
144
- describe ".connector" do
145
- it "should return the Connector" do
146
- connector
147
- Service.connector.should eql(connector)
148
- end
149
-
150
- it "should raise an error if the Connector has not been configured yet" do
151
- expect {Service.connector}.to raise_error(Service::ConfigurationError)
152
- end
153
- end
154
-
155
- describe ".local" do
156
- before {uploader}
157
-
158
- it "should return a service matching given function without a realm" do
159
- connector
160
- Service.local(:connector).should eql(connector)
161
- end
162
-
163
- it "should return a service matching given function and realm" do
164
- Service.local(:uploader, realm).should eql(uploader)
165
- end
166
-
167
- it "should return no service if it does not match given realm" do
168
- Service.local(:uploader).should be_nil
169
- end
170
-
171
- it "should return no service if it does not match given function" do
172
- Service.local(:connector, realm).should be_nil
173
- end
174
-
175
- it "should return a service matching given UUID and realm" do
176
- Service.local(uploader.uuid, realm).should eql(uploader)
177
- end
178
-
179
- it "should return no service if it does not match given function" do
180
- Service.local("123", realm).should be_nil
181
- end
182
- end
183
-
184
- describe ".discover" do
185
- it "should first try to find a local service" do
186
- uploader
187
- mock(Service).local(:uploader, realm) {uploader}
188
- dont_allow(Service).remote(:uploader, realm)
189
- Service.discover(:uploader, realm).should eql(uploader)
190
- end
191
-
192
- it "if no local service can be found a remote one should be fetched" do
193
- mock(Service).local(:uploader, realm) {nil}
194
- mock(Service).remote(:uploader, realm) {uploader}
195
- Service.discover(:uploader, realm).should eql(uploader)
196
- end
197
- end
198
-
199
- describe ".remote" do
200
- it "should require a realm" do
201
- expect {Service.remote(:uploader, nil)}.to raise_error(ArgumentError)
202
- end
203
-
204
- it "should fetch service data from Connector and create a local service object" do
205
- connector and this
206
- stub_http_request(:get, "http://connector.local/services/uploader").
207
- with(:query => {:realm => "12ab69f099a4012d4df558b035f038ab", :service => "344b4b8088fb012dd3e558b035f038ab", :sign => "d27be37e9440765d38789f9000a5b3a86c741b3954c88f7b1769e4067ac9fbd0"}).
208
- to_return(:status => 200, :body => %({"uuid":"c0861d609247012d0a8b58b035f038ab", "url":"http://uploader.local", "function":"uploader", "secret":"kjO8AjgX68Yp7OQ1XF8dTfPBE5GCuCnd/OPko+A9yCaw8qnj9xoyMGZEXQpf\niVBOUcux1qlW8hfT6UPKGoVfYA==\n"}))
209
- Service.remote(:uploader, realm)
210
-
211
- uploader = Service.local(:uploader, realm)
212
- uploader.uuid.should eql("c0861d609247012d0a8b58b035f038ab")
213
- uploader.function.should eql("uploader")
214
- uploader.url.should eql("http://uploader.local")
215
- uploader.secret.should eql(Vidibus::Secure.decrypt("kjO8AjgX68Yp7OQ1XF8dTfPBE5GCuCnd/OPko+A9yCaw8qnj9xoyMGZEXQpf\niVBOUcux1qlW8hfT6UPKGoVfYA==\n", this.secret))
216
- end
217
-
218
- it "should raise an error requested service has already been stored" do
219
- connector and this and uploader
220
- stub_http_request(:get, "http://connector.local/services/uploader").
221
- with(:query => {:realm => "e75234809111012d05ac58b035f038ab", :service => "973a8710926e012d0a8c58b035f038ab", :sign => "a93d3a1a0124e969f97d68feab37638ec8737b1d8ddc582cd204fbb228ad7e2b"}).
222
- to_return(:status => 200, :body => %({"uuid":"c0861d609247012d0a8b58b035f038ab", "url":"http://uploader.local", "function":"uploader", "secret":"kjO8AjgX68Yp7OQ1XF8dTfPBE5GCuCnd/OPko+A9yCaw8qnj9xoyMGZEXQpf\niVBOUcux1qlW8hfT6UPKGoVfYA==\n"}))
223
- expect { Service.remote(:uploader, realm) }.to raise_error
224
- end
225
- end
226
- end
@@ -1,14 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Service::Error" do
4
- it "should be derived from StandardError" do
5
- Vidibus::Service::Error.superclass.should eql(StandardError)
6
- end
7
- end
8
-
9
- describe "Service" do
10
- it "should be a shorthand for Service.discover" do
11
- mock(Service).discover(:uploader, "realm")
12
- Service(:uploader, "realm")
13
- end
14
- end
@@ -1,106 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{vidibus-service}
8
- s.version = "0.1.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Andre Pankratz"]
12
- s.date = %q{2011-05-04}
13
- s.description = %q{Description...}
14
- s.email = %q{andre@vidibus.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".bundle/config",
21
- ".document",
22
- ".rspec",
23
- "Gemfile",
24
- "LICENSE",
25
- "README.rdoc",
26
- "Rakefile",
27
- "VERSION",
28
- "app/models/service.rb",
29
- "config/locales/en.yml",
30
- "config/routes.rb",
31
- "lib/vidibus-service.rb",
32
- "lib/vidibus/service.rb",
33
- "lib/vidibus/service/client.rb",
34
- "lib/vidibus/service/connector_app.rb",
35
- "lib/vidibus/service/controller_validations.rb",
36
- "lib/vidibus/service/mongoid.rb",
37
- "spec/spec_helper.rb",
38
- "spec/vidibus/service/client_spec.rb",
39
- "spec/vidibus/service/connector_app_spec.rb",
40
- "spec/vidibus/service/controller_validations_spec.rb",
41
- "spec/vidibus/service/mongoid_spec.rb",
42
- "spec/vidibus/service_spec.rb",
43
- "vidibus-service.gemspec"
44
- ]
45
- s.homepage = %q{http://github.com/vidibus/vidibus-service}
46
- s.require_paths = ["lib"]
47
- s.rubygems_version = %q{1.6.2}
48
- s.summary = %q{Provides tools for Vidibus services}
49
- s.test_files = [
50
- "spec/spec_helper.rb",
51
- "spec/vidibus/service/client_spec.rb",
52
- "spec/vidibus/service/connector_app_spec.rb",
53
- "spec/vidibus/service/controller_validations_spec.rb",
54
- "spec/vidibus/service/mongoid_spec.rb",
55
- "spec/vidibus/service_spec.rb"
56
- ]
57
-
58
- if s.respond_to? :specification_version then
59
- s.specification_version = 3
60
-
61
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
- s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0"])
63
- s.add_runtime_dependency(%q<vidibus-core_extensions>, [">= 0"])
64
- s.add_runtime_dependency(%q<vidibus-secure>, [">= 0"])
65
- s.add_runtime_dependency(%q<vidibus-uuid>, [">= 0"])
66
- s.add_runtime_dependency(%q<vidibus-validate_uri>, [">= 0"])
67
- s.add_runtime_dependency(%q<httparty>, [">= 0"])
68
- s.add_runtime_dependency(%q<json>, [">= 0"])
69
- s.add_development_dependency(%q<jeweler>, [">= 0"])
70
- s.add_development_dependency(%q<rake>, [">= 0"])
71
- s.add_development_dependency(%q<rspec>, ["~> 2.0.0"])
72
- s.add_development_dependency(%q<rr>, [">= 0"])
73
- s.add_development_dependency(%q<relevance-rcov>, [">= 0"])
74
- s.add_development_dependency(%q<webmock>, [">= 0"])
75
- else
76
- s.add_dependency(%q<mongoid>, ["~> 2.0.0"])
77
- s.add_dependency(%q<vidibus-core_extensions>, [">= 0"])
78
- s.add_dependency(%q<vidibus-secure>, [">= 0"])
79
- s.add_dependency(%q<vidibus-uuid>, [">= 0"])
80
- s.add_dependency(%q<vidibus-validate_uri>, [">= 0"])
81
- s.add_dependency(%q<httparty>, [">= 0"])
82
- s.add_dependency(%q<json>, [">= 0"])
83
- s.add_dependency(%q<jeweler>, [">= 0"])
84
- s.add_dependency(%q<rake>, [">= 0"])
85
- s.add_dependency(%q<rspec>, ["~> 2.0.0"])
86
- s.add_dependency(%q<rr>, [">= 0"])
87
- s.add_dependency(%q<relevance-rcov>, [">= 0"])
88
- s.add_dependency(%q<webmock>, [">= 0"])
89
- end
90
- else
91
- s.add_dependency(%q<mongoid>, ["~> 2.0.0"])
92
- s.add_dependency(%q<vidibus-core_extensions>, [">= 0"])
93
- s.add_dependency(%q<vidibus-secure>, [">= 0"])
94
- s.add_dependency(%q<vidibus-uuid>, [">= 0"])
95
- s.add_dependency(%q<vidibus-validate_uri>, [">= 0"])
96
- s.add_dependency(%q<httparty>, [">= 0"])
97
- s.add_dependency(%q<json>, [">= 0"])
98
- s.add_dependency(%q<jeweler>, [">= 0"])
99
- s.add_dependency(%q<rake>, [">= 0"])
100
- s.add_dependency(%q<rspec>, ["~> 2.0.0"])
101
- s.add_dependency(%q<rr>, [">= 0"])
102
- s.add_dependency(%q<relevance-rcov>, [">= 0"])
103
- s.add_dependency(%q<webmock>, [">= 0"])
104
- end
105
- end
106
-