Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Mingo.db is nil when not connected

  • Loading branch information...
commit 8be69b2c41e3ba6873eeff278a4561d8f5863074 1 parent fd37f38
Mislav Marohnić authored

Showing 2 changed files with 21 additions and 2 deletions. Show diff stats Hide diff stats

  1. +5 1 lib/mingo/connection.rb
  2. +16 1 spec/mingo_spec.rb
6 lib/mingo/connection.rb
@@ -3,7 +3,11 @@ module Connection
3 3 attr_writer :db, :collection
4 4
5 5 def db
6   - @db || superclass.db
  6 + (defined?(@db) && @db) or superclass.respond_to?(:db) ? superclass.db : nil
  7 + end
  8 +
  9 + def connected?
  10 + !!db
7 11 end
8 12
9 13 def connect(dbname_or_uri)
17 spec/mingo_spec.rb
@@ -16,7 +16,22 @@ def age=(value)
16 16 before :all do
17 17 User.collection.remove
18 18 end
19   -
  19 +
  20 + it "has connection" do
  21 + Mingo.should be_connected
  22 + User.should be_connected
  23 +
  24 + old_db = Mingo.db
  25 + Mingo.db = nil
  26 + begin
  27 + Mingo.should_not be_connected
  28 + User.should_not be_connected
  29 + User.db.should be_nil
  30 + ensure
  31 + Mingo.db = old_db
  32 + end
  33 + end
  34 +
20 35 it "obtains an ID by saving" do
21 36 user = build :name => 'Mislav'
22 37 user.should_not be_persisted

0 comments on commit 8be69b2

Please sign in to comment.
Something went wrong with that request. Please try again.