Browse files

Moved mock_adapter into spec/lib

  • Loading branch information...
1 parent 81d2787 commit cef28042782d6c0800ee5f568e184600d3fd64c5 Dan Kubb committed Apr 10, 2008
View
10 environment.rb
@@ -2,26 +2,26 @@
# Require the DataMapper, and a Mock Adapter.
require 'pathname'
require Pathname(__FILE__).dirname.expand_path + 'lib/data_mapper'
- require __DIR__ + 'spec/mock_adapter'
+ require __DIR__ + 'spec/lib/mock_adapter'
require 'fileutils'
adapter = ENV["ADAPTER"] || "sqlite3"
-
+
repository_uri = URI.parse case ENV["ADAPTER"]
when 'mysql' then "mysql://localhost/data_mapper_1"
when 'postgres' then "postgres://localhost/data_mapper_1"
else "sqlite3://#{Dir.getwd}/data_mapper_1.db"
end
DataMapper.setup(:default, "mock://localhost")
-
+
# Determine log path.
ENV['_'] =~ /(\w+)/
log_path = __DIR__ + "log/#{$1 == 'opt' ? 'spec' : $1}.log"
-
+
FileUtils::mkdir_p(File.dirname(log_path))
# FileUtils::rm(log_path) if File.exists?(log_path)
-
+
DataMapper::Logger.new(log_path, 0)
at_exit { DataMapper.logger.close }
View
2 spec/integration/association_spec.rb
@@ -1,7 +1,7 @@
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper'
+require ROOT_DIR + 'lib/data_mapper'
begin
require 'do_sqlite3'
View
6 spec/integration/mysql_adapter_spec.rb
@@ -1,17 +1,17 @@
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper'
+require ROOT_DIR + 'lib/data_mapper'
begin
require 'do_mysql'
DataMapper.setup(:mysql, "mysql://localhost/dm_integration_test")
-
+
rescue LoadError => e
describe 'do_mysql' do
it 'should be required' do
fail "MySQL integration specs not run! Could not load do_mysql: #{e}"
end
end
-end
+end
View
2 spec/integration/postgres_adapter_spec.rb
@@ -1,7 +1,7 @@
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper'
+require ROOT_DIR + 'lib/data_mapper'
begin
require 'do_postgres'
View
24 spec/integration/property_spec.rb
@@ -8,11 +8,11 @@
describe DataMapper::Property do
describe" tracking strategies" do
-
+
before do
class Actor
include DataMapper::Resource
-
+
property :id, Fixnum, :serial => true
property :name, String, :lock => true
property :notes, DataMapper::Types::Text, :track => false
@@ -23,7 +23,7 @@ class Actor
property :agent, String, :track => :hash # :track only Object#hash value on :load.
# Potentially faster, but less safe, so use judiciously, when the odds of a hash-collision are low.
end
-
+
@adapter = DataMapper::Repository.adapters[:sqlite3] || DataMapper.setup(:sqlite3, "sqlite3://#{__DIR__}/integration_test.db")
@adapter.execute <<-EOS.compress_lines
CREATE TABLE actors (
@@ -38,52 +38,52 @@ class Actor
)
EOS
end
-
+
it "false" do
pending("Implementation...")
DataMapper::Resource::DIRTY.should_not be_nil
bob = Actor.new(:name => 'bob')
bob.original_attributes.should have_key(:name)
bob.original_attributes[:name].should == DataMapper::Resource::DIRTY
end
-
+
it ":load" do
pending("Implementation...")
DataMapper::Resource::DIRTY.should_not be_nil
bob = Actor.new(:name => 'bob')
bob.original_attributes.should have_key(:name)
bob.original_attributes[:name].should == DataMapper::Resource::DIRTY
end
-
+
it ":hash" do
pending("Implementation...")
DataMapper::Resource::DIRTY.should_not be_nil
bob = Actor.new(:name => 'bob')
bob.original_attributes.should have_key(:name)
bob.original_attributes[:name].should == DataMapper::Resource::DIRTY
end
-
+
it ":get" do
pending("Implementation...")
DataMapper::Resource::DIRTY.should_not be_nil
bob = Actor.new(:name => 'bob')
bob.original_attributes.should have_key(:name)
bob.original_attributes[:name].should == DataMapper::Resource::DIRTY
end
-
+
it ":set" do
pending("Implementation...")
DataMapper::Resource::DIRTY.should_not be_nil
bob = Actor.new(:name => 'bob')
bob.original_attributes.should have_key(:name)
bob.original_attributes[:name].should == DataMapper::Resource::DIRTY
end
-
+
after do
@adapter.execute("DROP TABLE actors")
end
end
-
+
describe "lazy loading" do
before do
@adapter = DataMapper::Repository.adapters[:sqlite3] || DataMapper.setup(:sqlite3, "sqlite3://#{__DIR__}/integration_test.db")
@@ -137,10 +137,10 @@ def property_by_name(name)
@adapter.execute('DROP TABLE "sail_boats"')
end
- end
+ end
end
-
+
rescue LoadError
warn "integration/property_spec not run! Could not load do_sqlite3."
end
View
26 spec/integration/query_spec.rb
@@ -1,7 +1,7 @@
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper'
+require ROOT_DIR + 'lib/data_mapper'
begin
require 'do_sqlite3'
@@ -261,29 +261,29 @@ class Vehicle
DataMapper::Query.new(Vehicle,:links=>[:sailing])
}.should raise_error(ArgumentError)
end
-
+
it 'should create an n-level query path' do
Vehicle.factory.region.model.should == Region
Vehicle.factory.region.name.property.should == Region.properties(Region.repository.name)[:name]
end
-
- it 'should accept a DM::QueryPath as the key to a condition' do
+
+ it 'should accept a DM::QueryPath as the key to a condition' do
repository(:sqlite3) do
vehicle = Vehicle.first(Vehicle.factory.region.name => 'North West')
vehicle.name.should == '10 ton delivery truck'
- end
+ end
end
-
-
- it 'should auto generate the link if a DM::Property from a different resource is in the :fields option'
+
+
+ it 'should auto generate the link if a DM::Property from a different resource is in the :fields option'
it 'should create links with composite keys'
-
-
+
+
it 'should eager load associations' do
repository(:sqlite3) do
- vehicle = Vehicle.first(:includes => [Vehicle.factory])
- end
- end
+ vehicle = Vehicle.first(:includes => [Vehicle.factory])
+ end
+ end
after do
@adapter.execute('DROP TABLE "regions"')
View
4 spec/integration/repository_spec.rb
@@ -1,7 +1,7 @@
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper'
+require ROOT_DIR + 'lib/data_mapper'
begin
@@ -73,4 +73,4 @@ class SerialFinderSpec
end
rescue LoadError
warn "integration/repository_spec not run! Could not load do_sqlite3."
-end
+end
View
4 spec/integration/sqlite3_adapter_spec.rb
@@ -1,7 +1,7 @@
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper'
+require ROOT_DIR + 'lib/data_mapper'
begin
require 'do_sqlite3'
@@ -221,7 +221,7 @@ class BankCustomer
after do
@adapter.execute('DROP TABLE "bank_customers"')
end
- end
+ end
end
rescue LoadError => e
describe 'do_sqlite3' do
View
39 spec/integration/type_spec.rb
@@ -2,92 +2,91 @@
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
require 'faster_csv'
-
begin
require 'do_sqlite3'
-
+
DataMapper.setup(:sqlite3, "sqlite3://#{__DIR__}/integration_test.db") unless DataMapper::Repository.adapters[:sqlite3]
describe DataMapper::Type do
before do
-
+
@adapter = repository(:sqlite3).adapter
@adapter.execute("CREATE TABLE coconuts (id INTEGER PRIMARY KEY, faked TEXT, document TEXT, stuff TEXT)")
-
- module TypeTests
+
+ module TypeTests
class Impostor < DataMapper::Type
primitive String
end
-
+
class Coconut
include DataMapper::Resource
-
+
resource_names[:sqlite3] = 'coconuts'
-
+
property :id, Fixnum, :serial => true
property :faked, Impostor
property :document, DM::Csv
property :stuff, DM::Yaml
end
end
-
+
@document = <<-EOS.margin
NAME, RATING, CONVENIENCE
Freebird's, 3, 3
Whataburger, 1, 5
Jimmy John's, 3, 4
Mignon, 5, 2
Fuzi Yao's, 5, 1
- Blue Goose, 5, 1
+ Blue Goose, 5, 1
EOS
-
+
@stuff = YAML::dump({ 'Happy Cow!' => true, 'Sad Cow!' => false })
end
-
+
it "should instantiate an object with custom types" do
coconut = TypeTests::Coconut.new(:faked => 'bob', :document => @document, :stuff => @stuff)
coconut.faked.should == 'bob'
coconut.document.should be_a_kind_of(Array)
coconut.stuff.should be_a_kind_of(Hash)
end
-
+
it "should CRUD an object with custom types" do
repository(:sqlite3) do
coconut = TypeTests::Coconut.new(:faked => 'bob', :document => @document, :stuff => @stuff)
coconut.save.should be_true
coconut.id.should_not be_nil
-
+
fred = TypeTests::Coconut[coconut.id]
fred.faked.should == 'bob'
fred.document.should be_a_kind_of(Array)
fred.stuff.should be_a_kind_of(Hash)
texadelphia = ["Texadelphia", "5", "3"]
-
+
# Figure out how to track these... possibly proxies? :-p
document = fred.document.dup
document << texadelphia
fred.document = document
-
+
stuff = fred.stuff.dup
stuff['Manic Cow!'] = :maybe
fred.stuff = stuff
-
+
fred.save.should be_true
-
+
# Can't call coconut.reload! since coconut.loaded_set isn't setup.
mac = TypeTests::Coconut[fred.id]
mac.document.last.should == texadelphia
mac.stuff['Manic Cow!'].should == :maybe
end
end
-
+
after do
@adapter = repository(:sqlite3).adapter
@adapter.execute("DROP TABLE coconuts")
end
end
rescue LoadError
warn "integration/type_spec not run! Could not load do_sqlite3."
-end
+end
View
10 spec/mock_adapter.rb → spec/lib/mock_adapter.rb
@@ -1,15 +1,13 @@
-require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
-require __DIR__.parent + 'lib/data_mapper/adapters/data_objects_adapter'
+require ROOT_DIR + 'lib/data_mapper/adapters/data_objects_adapter'
module DataMapper
module Adapters
class MockAdapter < DataMapper::Adapters::DataObjectsAdapter
-
+
def create(repository, instance)
instance
end
-
+
end
end
-end
+end
View
14 spec/spec_helper.rb
@@ -6,12 +6,12 @@
# for __DIR__
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/data_mapper/support/kernel'
-ENV['LOG_NAME'] = 'spec'
-require __DIR__.parent + 'environment'
-require __DIR__ + 'mock_adapter'
-
ROOT_DIR = __DIR__.parent
+ENV['LOG_NAME'] = 'spec'
+require ROOT_DIR + 'environment'
+require __DIR__ + 'lib/mock_adapter'
+
class Article
include DataMapper::Resource
@@ -40,21 +40,21 @@ class NormalClass
# Used for Association specs
class Vehicle
include DataMapper::Resource
-
+
property :id, Fixnum, :serial => true
property :name, String
end
class Manufacturer
include DataMapper::Resource
-
+
property :id, Fixnum, :serial => true
property :name, String
end
class Supplier
include DataMapper::Resource
-
+
property :id, Fixnum, :serial => true
property :name, String
end

0 comments on commit cef2804

Please sign in to comment.