pebblebed 0.0.41 → 0.0.42

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -58,6 +58,51 @@ Other helper methods provided by this extension:
58
58
  require_god # Halts with 403 if the current user is not a god
59
59
  require_parameters(parameters, *keys) # Halts with 409 if the at least one of the provided keys is not in the params-hash
60
60
 
61
+ ### Testing Sinatra APIs
62
+
63
+ To use the handy (but very, very dirty) helpers for the Pebbles Checkpoint authorization,
64
+ you must require `pebblebed/rspec_helper` (this is not included by default in the pebblebed gem)
65
+ and include `Pebblebed::RSpecHelper` in your test context:
66
+
67
+
68
+ ```ruby
69
+ require 'pebblebed/rspec_helper'
70
+
71
+ describe Something do
72
+ include Pebblebed::RSpecHelper
73
+ end
74
+ ```
75
+
76
+ You can set the current identity to be either god, a regular logged in user, or a guest user.
77
+
78
+ If you call either `god!` or `user!`, the sinatra app's
79
+ current session defaults to the string 'validsession'.
80
+ The current realm defaults to the string 'testrealm'.
81
+
82
+ You can override default values for :id or :session or :realm,
83
+ or add additional identity values on god or user by passing them in:
84
+
85
+ ```ruby
86
+ user!(:id => 7, :session => 'abc', :realm => 'area51', :profile => {:a => 'b'})
87
+ ```
88
+
89
+ There are two convenience methods that are added to the context:
90
+ ```ruby
91
+ current_identity # => the god or user, or nil if you've called guest!
92
+ another_identity # => a non-god user with an id of (current_user.id + 1)
93
+ ```
94
+
95
+ ```ruby
96
+ context "when god" do
97
+ before(:each) { god! }
98
+ it "has stuff in the test context" do
99
+ current_identity.god # => true
100
+ current_identity.id # => 1
101
+
102
+ other_identity.id # => 2
103
+ end
104
+ end
105
+ ```
61
106
 
62
107
  Not Sinatra
63
108
  ===========
@@ -14,6 +14,8 @@ describe Pebblebed::River do
14
14
  after(:each) do
15
15
  subject.send(:bunny).queues.each do |name, queue|
16
16
  queue.purge
17
+ # If you don't delete the queue, the subscription will not
18
+ # change, even if you give it a new one.
17
19
  queue.delete
18
20
  end
19
21
  subject.disconnect
@@ -90,14 +92,19 @@ describe Pebblebed::River do
90
92
  end
91
93
 
92
94
  it "subscribes" do
93
- queue = subject.queue(:name => 'alltestivore', :path => 'rspec|testunit', :klass => 'thing')
95
+ queue = subject.queue(:name => 'alltestivore', :path => 'area51.rspec|area51.testunit|area52.*|area53.**', :klass => 'thing', :event => 'smile')
94
96
 
95
97
  queue.message_count.should eq(0)
96
- subject.publish(:event => 'smile', :uid => 'thing:rspec$1', :attributes => {:a => 'b'})
97
- subject.publish(:event => 'frown', :uid => 'thing:rspec$2', :attributes => {:a => 'b'})
98
- subject.publish(:event => 'laugh', :uid => 'thing:testunit$3', :attributes => {:a => 'b'})
98
+ subject.publish(:event => 'smile', :uid => 'thing:area51.rspec$1', :attributes => {:a => 'b'})
99
+ subject.publish(:event => 'smile', :uid => 'thing:area51.testunit$2', :attributes => {:a => 'b'})
100
+ subject.publish(:event => 'smile', :uid => 'thing:area51.whatever$3', :attributes => {:a => 'b'}) # doesn't match path
101
+ subject.publish(:event => 'frown', :uid => 'thing:area51.rspec$4', :attributes => {:a => 'b'}) # doesn't match event
102
+ subject.publish(:event => 'smile', :uid => 'thing:area52.one.two.three$5', :attributes => {:a => 'b'}) # doesn't match wildcard path
103
+ subject.publish(:event => 'smile', :uid => 'thing:area52.one$6', :attributes => {:a => 'b'}) # matches wildcard path
104
+ subject.publish(:event => 'smile', :uid => 'thing:area53.one.two.three$7', :attributes => {:a => 'b'}) # matches wildcard path
105
+
99
106
  sleep(0.1)
100
- queue.message_count.should eq(3)
107
+ queue.message_count.should eq(4)
101
108
  end
102
109
 
103
110
  it "is a durable queue" do
@@ -0,0 +1,58 @@
1
+ require 'deepstruct'
2
+
3
+ module Pebblebed
4
+ module RSpecHelper
5
+ def god!(options = {})
6
+ options.delete(:god)
7
+ stub_current_identity(options.merge(:id => 1, :god => true))
8
+ end
9
+
10
+ def user!(options = {})
11
+ options.delete(:god)
12
+ stub_current_identity(options.merge(:id => 1, :god => false))
13
+ end
14
+
15
+ def guest!
16
+ stub_current_identity
17
+ end
18
+
19
+ def current_identity
20
+ @current_identity
21
+ end
22
+
23
+ def another_identity
24
+ id = current_identity ? (current_identity.id + 1) : 1
25
+ DeepStruct.wrap(default_identity_options.merge(:id => id, :god => false))
26
+ end
27
+
28
+ private
29
+ def stub_current_identity(options = {})
30
+ guest = options.empty?
31
+
32
+ identity = nil
33
+ unless guest
34
+ identity = default_identity_options.merge(options)
35
+ end
36
+
37
+ @current_identity = DeepStruct.wrap(identity)
38
+
39
+ checkpoint = stub(:get => DeepStruct.wrap(:identity => identity), :service_url => 'http://example.com')
40
+ Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
41
+
42
+ unless guest
43
+ session = options.fetch(:session) { 'validsession' }
44
+ stub_current_session session
45
+ end
46
+ end
47
+
48
+ def default_identity_options
49
+ {:realm => 'testrealm'}
50
+ end
51
+
52
+ def stub_current_session(session)
53
+ app.any_instance.stub(:current_session).and_return session
54
+ end
55
+
56
+ end
57
+ end
58
+
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.0.41"
2
+ VERSION = "0.0.42"
3
3
  end
data/spec/sinatra_spec.rb CHANGED
@@ -4,6 +4,7 @@ require 'pebblebed/sinatra'
4
4
  require 'sinatra/base'
5
5
  require 'rack/test'
6
6
  require 'spec_helper'
7
+ require 'pebblebed/rspec_helper'
7
8
 
8
9
  class TestApp < Sinatra::Base
9
10
  register Sinatra::Pebblebed
@@ -36,31 +37,16 @@ end
36
37
 
37
38
  describe Sinatra::Pebblebed do
38
39
  include Rack::Test::Methods
40
+ include Pebblebed::RSpecHelper
39
41
 
40
42
  def app
41
43
  TestApp
42
44
  end
43
45
 
44
- let(:guest) { DeepStruct.wrap({}) }
45
- let(:alice) { DeepStruct.wrap(:identity => {:id => 1, :god => false}) }
46
- let(:odin) { DeepStruct.wrap(:identity => {:id => 2, :god => true}) }
47
-
48
- let(:checkpoint) { stub(:get => identity, :service_url => 'http://example.com') }
49
-
50
- before :each do
51
- TestApp.any_instance.stub(:current_session).and_return "validsessionyesyesyes"
52
- Pebblebed::Connector.any_instance.stub(:checkpoint).and_return checkpoint
53
- end
54
-
55
46
  let(:random_session) { rand(36**128).to_s(36) }
56
47
 
57
- before :each do
58
- # Make sure the app get an uniqie session key for every received request
59
- TestApp.any_instance.stub(:current_session) { random_session }
60
- end
61
-
62
48
  context "a guest" do
63
- let(:identity) { guest }
49
+ before(:each) { guest! }
64
50
 
65
51
  specify "can see public endpoint" do
66
52
  get '/public'
@@ -84,7 +70,7 @@ describe Sinatra::Pebblebed do
84
70
  end
85
71
 
86
72
  context "as a user" do
87
- let(:identity) { alice }
73
+ before(:each) { user! }
88
74
 
89
75
  specify "can see public endpoint" do
90
76
  get '/public'
@@ -103,7 +89,7 @@ describe Sinatra::Pebblebed do
103
89
  end
104
90
 
105
91
  context "as a god" do
106
- let(:identity) { odin }
92
+ before(:each) { god!(:session => random_session) }
107
93
 
108
94
  specify "can see public endpoint" do
109
95
  get '/public'
@@ -122,11 +108,13 @@ describe Sinatra::Pebblebed do
122
108
  end
123
109
 
124
110
  describe "error handling" do
125
- let(:identity) { guest }
111
+ before(:each) { guest! }
112
+
126
113
  it "Adds graceful handling of HttpNotFoundError exceptions" do
127
114
  get '/nonexistant'
128
115
  last_response.status.should == 404
129
116
  end
117
+
130
118
  it "Gives the error message of HttpNotFoundError as response body" do
131
119
  get '/nonexistant'
132
120
  last_response.status.should == 404
@@ -134,33 +122,36 @@ describe Sinatra::Pebblebed do
134
122
  end
135
123
  end
136
124
 
137
- describe "current identity caching" do
138
- let(:identity) { alice }
139
-
140
- it "will not cache current_identity by default" do
141
- checkpoint.should_receive(:get).twice
142
- get '/private'
143
- get '/private'
144
- end
145
-
146
- it "can be configured to cache current identity" do
147
- session = random_session
148
- app.set :cache_current_identity, true
149
- checkpoint.should_receive(:get).once
150
- get '/private'
151
- get '/private'
125
+ describe "identity caching" do
126
+
127
+ context "with logged in user" do
128
+ before(:each) { user!(:session => random_session) }
129
+ let(:checkpoint) { Pebblebed::Connector.new.checkpoint }
130
+
131
+ it "is not turned on by default" do
132
+ checkpoint.should_receive(:get).twice
133
+ get '/private'
134
+ get '/private'
135
+ end
136
+
137
+ it "can be turned on" do
138
+ app.set :cache_current_identity, true
139
+ checkpoint.should_receive(:get).once
140
+ get '/private'
141
+ get '/private'
142
+ end
143
+
144
+ context "with guest user" do
145
+ before(:each) { guest! }
146
+
147
+ it "is disabled" do
148
+ app.set :cache_current_identity, true
149
+ checkpoint.should_receive(:get).twice
150
+ get '/private'
151
+ get '/private'
152
+ end
153
+ end
152
154
  end
153
- end
154
-
155
- describe "identity caching disabled when no current user" do
156
- let(:identity) { {} }
157
155
 
158
- it "will not cache identity when there is no current identity" do
159
- identity = nil
160
- app.set :cache_current_identity, true
161
- checkpoint.should_receive(:get).twice
162
- get '/private'
163
- get '/private'
164
- end
165
156
  end
166
157
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebblebed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.41
4
+ version: 0.0.42
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-03 00:00:00.000000000 Z
13
+ date: 2013-01-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &70269360765760 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,15 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: '0'
25
+ version_requirements: *70269360765760
31
26
  - !ruby/object:Gem::Dependency
32
27
  name: rake
33
- requirement: !ruby/object:Gem::Requirement
28
+ requirement: &70269360765140 !ruby/object:Gem::Requirement
34
29
  none: false
35
30
  requirements:
36
31
  - - ! '>='
@@ -38,15 +33,10 @@ dependencies:
38
33
  version: '0'
39
34
  type: :development
40
35
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
36
+ version_requirements: *70269360765140
47
37
  - !ruby/object:Gem::Dependency
48
38
  name: simplecov
49
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &70269360764520 !ruby/object:Gem::Requirement
50
40
  none: false
51
41
  requirements:
52
42
  - - ! '>='
@@ -54,15 +44,10 @@ dependencies:
54
44
  version: '0'
55
45
  type: :development
56
46
  prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
47
+ version_requirements: *70269360764520
63
48
  - !ruby/object:Gem::Dependency
64
49
  name: sinatra
65
- requirement: !ruby/object:Gem::Requirement
50
+ requirement: &70269360763860 !ruby/object:Gem::Requirement
66
51
  none: false
67
52
  requirements:
68
53
  - - ! '>='
@@ -70,15 +55,10 @@ dependencies:
70
55
  version: '0'
71
56
  type: :development
72
57
  prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
58
+ version_requirements: *70269360763860
79
59
  - !ruby/object:Gem::Dependency
80
60
  name: rack-test
81
- requirement: !ruby/object:Gem::Requirement
61
+ requirement: &70269360763420 !ruby/object:Gem::Requirement
82
62
  none: false
83
63
  requirements:
84
64
  - - ! '>='
@@ -86,15 +66,10 @@ dependencies:
86
66
  version: '0'
87
67
  type: :development
88
68
  prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
69
+ version_requirements: *70269360763420
95
70
  - !ruby/object:Gem::Dependency
96
71
  name: memcache_mock
97
- requirement: !ruby/object:Gem::Requirement
72
+ requirement: &70269360762920 !ruby/object:Gem::Requirement
98
73
  none: false
99
74
  requirements:
100
75
  - - ! '>='
@@ -102,15 +77,10 @@ dependencies:
102
77
  version: '0'
103
78
  type: :development
104
79
  prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: '0'
80
+ version_requirements: *70269360762920
111
81
  - !ruby/object:Gem::Dependency
112
82
  name: deepstruct
113
- requirement: !ruby/object:Gem::Requirement
83
+ requirement: &70269360778520 !ruby/object:Gem::Requirement
114
84
  none: false
115
85
  requirements:
116
86
  - - ! '>='
@@ -118,15 +88,10 @@ dependencies:
118
88
  version: 0.0.4
119
89
  type: :runtime
120
90
  prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ! '>='
125
- - !ruby/object:Gem::Version
126
- version: 0.0.4
91
+ version_requirements: *70269360778520
127
92
  - !ruby/object:Gem::Dependency
128
93
  name: curb
129
- requirement: !ruby/object:Gem::Requirement
94
+ requirement: &70269360777860 !ruby/object:Gem::Requirement
130
95
  none: false
131
96
  requirements:
132
97
  - - ! '>='
@@ -134,15 +99,10 @@ dependencies:
134
99
  version: 0.7.14
135
100
  type: :runtime
136
101
  prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ! '>='
141
- - !ruby/object:Gem::Version
142
- version: 0.7.14
102
+ version_requirements: *70269360777860
143
103
  - !ruby/object:Gem::Dependency
144
104
  name: yajl-ruby
145
- requirement: !ruby/object:Gem::Requirement
105
+ requirement: &70269360777480 !ruby/object:Gem::Requirement
146
106
  none: false
147
107
  requirements:
148
108
  - - ! '>='
@@ -150,15 +110,10 @@ dependencies:
150
110
  version: '0'
151
111
  type: :runtime
152
112
  prerelease: false
153
- version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
- requirements:
156
- - - ! '>='
157
- - !ruby/object:Gem::Version
158
- version: '0'
113
+ version_requirements: *70269360777480
159
114
  - !ruby/object:Gem::Dependency
160
115
  name: queryparams
161
- requirement: !ruby/object:Gem::Requirement
116
+ requirement: &70269360777020 !ruby/object:Gem::Requirement
162
117
  none: false
163
118
  requirements:
164
119
  - - ! '>='
@@ -166,15 +121,10 @@ dependencies:
166
121
  version: '0'
167
122
  type: :runtime
168
123
  prerelease: false
169
- version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
- requirements:
172
- - - ! '>='
173
- - !ruby/object:Gem::Version
174
- version: '0'
124
+ version_requirements: *70269360777020
175
125
  - !ruby/object:Gem::Dependency
176
126
  name: futurevalue
177
- requirement: !ruby/object:Gem::Requirement
127
+ requirement: &70269360776580 !ruby/object:Gem::Requirement
178
128
  none: false
179
129
  requirements:
180
130
  - - ! '>='
@@ -182,15 +132,10 @@ dependencies:
182
132
  version: '0'
183
133
  type: :runtime
184
134
  prerelease: false
185
- version_requirements: !ruby/object:Gem::Requirement
186
- none: false
187
- requirements:
188
- - - ! '>='
189
- - !ruby/object:Gem::Version
190
- version: '0'
135
+ version_requirements: *70269360776580
191
136
  - !ruby/object:Gem::Dependency
192
137
  name: pathbuilder
193
- requirement: !ruby/object:Gem::Requirement
138
+ requirement: &70269360776120 !ruby/object:Gem::Requirement
194
139
  none: false
195
140
  requirements:
196
141
  - - ! '>='
@@ -198,15 +143,10 @@ dependencies:
198
143
  version: '0'
199
144
  type: :runtime
200
145
  prerelease: false
201
- version_requirements: !ruby/object:Gem::Requirement
202
- none: false
203
- requirements:
204
- - - ! '>='
205
- - !ruby/object:Gem::Version
206
- version: '0'
146
+ version_requirements: *70269360776120
207
147
  - !ruby/object:Gem::Dependency
208
148
  name: nokogiri
209
- requirement: !ruby/object:Gem::Requirement
149
+ requirement: &70269360775660 !ruby/object:Gem::Requirement
210
150
  none: false
211
151
  requirements:
212
152
  - - ! '>='
@@ -214,15 +154,10 @@ dependencies:
214
154
  version: '0'
215
155
  type: :runtime
216
156
  prerelease: false
217
- version_requirements: !ruby/object:Gem::Requirement
218
- none: false
219
- requirements:
220
- - - ! '>='
221
- - !ruby/object:Gem::Version
222
- version: '0'
157
+ version_requirements: *70269360775660
223
158
  - !ruby/object:Gem::Dependency
224
159
  name: i18n
225
- requirement: !ruby/object:Gem::Requirement
160
+ requirement: &70269360775220 !ruby/object:Gem::Requirement
226
161
  none: false
227
162
  requirements:
228
163
  - - ! '>='
@@ -230,15 +165,10 @@ dependencies:
230
165
  version: '0'
231
166
  type: :runtime
232
167
  prerelease: false
233
- version_requirements: !ruby/object:Gem::Requirement
234
- none: false
235
- requirements:
236
- - - ! '>='
237
- - !ruby/object:Gem::Version
238
- version: '0'
168
+ version_requirements: *70269360775220
239
169
  - !ruby/object:Gem::Dependency
240
170
  name: activesupport
241
- requirement: !ruby/object:Gem::Requirement
171
+ requirement: &70269360774760 !ruby/object:Gem::Requirement
242
172
  none: false
243
173
  requirements:
244
174
  - - ! '>='
@@ -246,15 +176,10 @@ dependencies:
246
176
  version: '0'
247
177
  type: :runtime
248
178
  prerelease: false
249
- version_requirements: !ruby/object:Gem::Requirement
250
- none: false
251
- requirements:
252
- - - ! '>='
253
- - !ruby/object:Gem::Version
254
- version: '0'
179
+ version_requirements: *70269360774760
255
180
  - !ruby/object:Gem::Dependency
256
181
  name: bunny
257
- requirement: !ruby/object:Gem::Requirement
182
+ requirement: &70269360774320 !ruby/object:Gem::Requirement
258
183
  none: false
259
184
  requirements:
260
185
  - - ! '>='
@@ -262,12 +187,7 @@ dependencies:
262
187
  version: '0'
263
188
  type: :runtime
264
189
  prerelease: false
265
- version_requirements: !ruby/object:Gem::Requirement
266
- none: false
267
- requirements:
268
- - - ! '>='
269
- - !ruby/object:Gem::Version
270
- version: '0'
190
+ version_requirements: *70269360774320
271
191
  description: Development tools for working with Pebblebed
272
192
  email:
273
193
  - katrina@bengler.no
@@ -293,6 +213,7 @@ files:
293
213
  - lib/pebblebed/parts.rb
294
214
  - lib/pebblebed/river.rb
295
215
  - lib/pebblebed/river/subscription.rb
216
+ - lib/pebblebed/rspec_helper.rb
296
217
  - lib/pebblebed/security/access_data.rb
297
218
  - lib/pebblebed/security/client.rb
298
219
  - lib/pebblebed/security/listener.rb
@@ -326,21 +247,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
326
247
  - - ! '>='
327
248
  - !ruby/object:Gem::Version
328
249
  version: '0'
329
- segments:
330
- - 0
331
- hash: -3749590712618864123
332
250
  required_rubygems_version: !ruby/object:Gem::Requirement
333
251
  none: false
334
252
  requirements:
335
253
  - - ! '>='
336
254
  - !ruby/object:Gem::Version
337
255
  version: '0'
338
- segments:
339
- - 0
340
- hash: -3749590712618864123
341
256
  requirements: []
342
257
  rubyforge_project: pebblebed
343
- rubygems_version: 1.8.24
258
+ rubygems_version: 1.8.15
344
259
  signing_key:
345
260
  specification_version: 3
346
261
  summary: Development tools for working with Pebblebed
@@ -359,3 +274,4 @@ test_files:
359
274
  - spec/sinatra_spec.rb
360
275
  - spec/spec_helper.rb
361
276
  - spec/uid_spec.rb
277
+ has_rdoc: