Skip to content

Commit

Permalink
Disable identity map by default
Browse files Browse the repository at this point in the history
The identity map was causing more issues than expected:
* #260
* #285
* #302
  • Loading branch information
sferik committed Sep 17, 2012
1 parent 32de4f8 commit c6c5960
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 5 additions & 14 deletions spec/twitter/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
26 changes: 18 additions & 8 deletions spec/twitter/identifiable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c6c5960

Please sign in to comment.