Sha256: 41a1cd2a9ad81353bf070d715170d87d8da23139adec0627165804771e541b14

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module CouchRestRails
  module Tests

    extend self
    mattr_accessor :fixtures_loaded
    self.fixtures_loaded = Set.new

    def setup(database="*")
      ENV['RAILS_ENV'] = CouchRestRails.test_environment
      unless fixtures_loaded.include?(database)
        CouchRestRails::Database.delete(database)
        CouchRestRails::Database.create(database)
        CouchRestRails::Fixtures.load(database)
        fixtures_loaded << database
      end
    end

    def reset_fixtures
      CouchRestRails::Database.delete("*") unless fixtures_loaded.empty?
      fixtures_loaded.clear
    end

    def teardown(database="*")
      ENV['RAILS_ENV'] = CouchRestRails.test_environment
      CouchRestRails::Database.delete(database)
      CouchRestRails::Database.create(database)
      fixtures_loaded.delete(database)
    end
  end
end
module Test
  module Unit #:nodoc:
    class TestCase #:nodoc:
      setup :setup_couchdb_fixtures
      teardown :teardown_couchdb_fixtures

      superclass_delegating_accessor :database
      self.database = nil

      class << self
        def couchdb_fixtures(*databases)
          self.database = databases.map { |d| d.to_s }
        end
      end
      def setup_couchdb_fixtures
        CouchRestRails::Tests.setup(self.database) unless self.database.nil?
      end
      def teardown_couchdb_fixtures
        CouchRestRails::Tests.teardown(self.database) unless self.database.nil?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
therealadam-couchrest-rails-0.1.1 lib/couch_rest_rails/tests.rb