pebblebed 0.0.32 → 0.0.33

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,6 +35,7 @@ module Pebblebed
35
35
  end
36
36
 
37
37
  def self.memcached
38
+ raise RuntimeError, "Please set Pebblebed.memcached = <your memcached client>" unless @memcached
38
39
  @memcached
39
40
  end
40
41
 
@@ -37,12 +37,16 @@ module Sinatra
37
37
  return @identity if @identity_checked
38
38
  @identity_checked = true
39
39
  if cache_current_identity?
40
- @identity = ::Pebblebed.memcached.fetch("identity-for-session-#{current_session}", :ttl => 60) do
41
- pebbles.checkpoint.get("/identities/me")[:identity]
42
- end
40
+ cache_key = "identity-for-session-#{current_session}"
41
+ @identity = ::Pebblebed.memcached.get(cache_key)
42
+ return @identity if @identity
43
+ @identity = pebbles.checkpoint.get("/identities/me")[:identity]
44
+ # Cache identity only if there is a current user
45
+ ::Pebblebed.memcached.set(cache_key, @identity, 60) if @identity.id?
43
46
  else
44
47
  @identity = pebbles.checkpoint.get("/identities/me")[:identity]
45
48
  end
49
+ @identity
46
50
  end
47
51
 
48
52
  def cache_current_identity?
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.0.32"
2
+ VERSION = "0.0.33"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -6,15 +6,20 @@ describe Pebblebed do
6
6
  it "has a nice dsl that configures stuff" do
7
7
  Pebblebed.config do
8
8
  host "example.org"
9
- memcached $memcached
9
+ memcached "MemcachedClient"
10
10
  service :checkpoint
11
11
  end
12
12
 
13
13
  Pebblebed.host.should eq "example.org"
14
- Pebblebed.memcached.should eq $memcached
14
+ Pebblebed.memcached.should eq "MemcachedClient"
15
15
  Pebblebed::Connector.instance_methods.should include :checkpoint
16
16
  end
17
17
 
18
+ it "raises an error when memcached is used but not configured" do
19
+ Pebblebed.memcached = nil
20
+ -> {Pebblebed.memcached}.should raise_error RuntimeError
21
+ end
22
+
18
23
  it "can calculate the root uri of any pebble" do
19
24
  Pebblebed.config do
20
25
  service :checkpoint
data/spec/sinatra_spec.rb CHANGED
@@ -3,6 +3,7 @@ require 'pebblebed'
3
3
  require 'pebblebed/sinatra'
4
4
  require 'sinatra/base'
5
5
  require 'rack/test'
6
+ require 'spec_helper'
6
7
 
7
8
  class TestApp < Sinatra::Base
8
9
  register Sinatra::Pebblebed
@@ -47,6 +48,7 @@ describe Sinatra::Pebblebed do
47
48
  let(:checkpoint) { stub(:get => identity, :service_url => 'http://example.com') }
48
49
 
49
50
  before :each do
51
+ TestApp.any_instance.stub(:current_session).and_return "validsessionyesyesyes"
50
52
  Pebblebed::Connector.any_instance.stub(:checkpoint).and_return checkpoint
51
53
  end
52
54
 
@@ -149,4 +151,16 @@ describe Sinatra::Pebblebed do
149
151
  get '/private'
150
152
  end
151
153
  end
154
+
155
+ describe "identity caching disabled when no current user" do
156
+ let(:identity) { {} }
157
+
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
+ end
152
166
  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.32
4
+ version: 0.0.33
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-22 00:00:00.000000000 Z
13
+ date: 2012-11-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -328,7 +328,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
328
328
  version: '0'
329
329
  segments:
330
330
  - 0
331
- hash: 2532469361834301007
331
+ hash: -222285177429713152
332
332
  required_rubygems_version: !ruby/object:Gem::Requirement
333
333
  none: false
334
334
  requirements:
@@ -337,7 +337,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
337
337
  version: '0'
338
338
  segments:
339
339
  - 0
340
- hash: 2532469361834301007
340
+ hash: -222285177429713152
341
341
  requirements: []
342
342
  rubyforge_project: pebblebed
343
343
  rubygems_version: 1.8.24