From c6c5960bea998abdc3e82cbb8dd68766a2df52e1 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Thu, 6 Sep 2012 18:45:57 -0700 Subject: [PATCH] Disable identity map by default The identity map was causing more issues than expected: * #260 * #285 * #302 --- README.md | 2 +- lib/twitter/default.rb | 2 +- spec/twitter/base_spec.rb | 19 +++++-------------- spec/twitter/identifiable_spec.rb | 26 ++++++++++++++++++-------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 5c6f7e9f0..843ff331c 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ Here are some fun facts about the 3.0 release: * The entire library is implemented in just 2,000 lines of code * With over 5,000 lines of specs, the spec-to-code ratio is over 2.5:1 -* The spec suite contains 674 examples and runs in under 2 seconds on a MacBook +* The spec suite contains 668 examples and runs in under 2 seconds on a MacBook * This project has 100% C0 code coverage (the tests execute every line of source code at least once) * At the time of release, this library is comprehensive: you can request all diff --git a/lib/twitter/default.rb b/lib/twitter/default.rb index 516a47167..888a176d8 100644 --- a/lib/twitter/default.rb +++ b/lib/twitter/default.rb @@ -22,7 +22,7 @@ module Default :ssl => {:verify => false}, :timeout => 10, } unless defined? CONNECTION_OPTIONS - IDENTITY_MAP = Twitter::IdentityMap unless defined? IDENTITY_MAP + IDENTITY_MAP = false unless defined? IDENTITY_MAP MIDDLEWARE = Faraday::Builder.new( &Proc.new do |builder| # Convert file uploads to Faraday::UploadIO objects diff --git a/spec/twitter/base_spec.rb b/spec/twitter/base_spec.rb index b5f6a2f33..48bebe23b 100644 --- a/spec/twitter/base_spec.rb +++ b/spec/twitter/base_spec.rb @@ -4,10 +4,15 @@ context 'identity map enabled' do before do + Twitter.identity_map = Twitter::IdentityMap object = Twitter::Base.new(:id => 1) @base = Twitter::Base.store(object) end + after do + Twitter.identity_map = false + end + describe '.identity_map' do it 'returns an instance of the identity map' do Twitter::Base.identity_map.should be_a Twitter::IdentityMap @@ -105,18 +110,4 @@ end end - context 'custom identity map enabled' do - after(:all) do - Twitter.identity_map = Twitter::IdentityMap - end - - describe '.identity_map' do - it 'returns an instance of the custom identity map' do - Twitter::Base.identity_map.should be_a Twitter::IdentityMap - Twitter.identity_map = Hash - Twitter::Base.identity_map.should_not be_a Twitter::IdentityMap - end - end - end - end diff --git a/spec/twitter/identifiable_spec.rb b/spec/twitter/identifiable_spec.rb index 1d47b14c7..09e5fccda 100644 --- a/spec/twitter/identifiable_spec.rb +++ b/spec/twitter/identifiable_spec.rb @@ -10,16 +10,26 @@ end end - describe '.fetch' do - it 'returns existing objects' do - Twitter::Identity.store(Twitter::Identity.new(:id => 1)) - Twitter::Identity.fetch(:id => 1).should be + context 'identity map enabled' do + before do + Twitter.identity_map = Twitter::IdentityMap end - it "raises an error on objects that don't exist" do - lambda { - Twitter::Identity.fetch(:id => 6) - }.should raise_error(Twitter::Error::IdentityMapKeyError) + after do + Twitter.identity_map = false + end + + describe '.fetch' do + it 'returns existing objects' do + Twitter::Identity.store(Twitter::Identity.new(:id => 1)) + Twitter::Identity.fetch(:id => 1).should be + end + + it "raises an error on objects that don't exist" do + lambda { + Twitter::Identity.fetch(:id => 6) + }.should raise_error(Twitter::Error::IdentityMapKeyError) + end end end