Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved unit specifications into spec/unit

* spec/unit/* specs should specify the behaviour of the associated
  code with no external dependencies.
* Updated autotest rules to match file layout change
* Updated require paths within the unit specs
  • Loading branch information...
commit 81d2787c0e427c0e805d15be69190c80a8c21b2d 1 parent 19d6c98
Dan Kubb authored
Showing with 304 additions and 294 deletions.
  1. +19 −15 .autotest
  2. +0 −1  spec/integration/type_spec.rb
  3. +1 −1  spec/spec.opts
  4. +2 −0  spec/spec_helper.rb
  5. +10 −10 spec/{ → unit}/adapters/abstract_adapter_spec.rb
  6. +0 −1  spec/{ → unit/adapters}/adapter_shared_spec.rb
  7. +39 −39 spec/{ → unit}/adapters/data_objects_adapter_spec.rb
  8. +6 −6 spec/{ → unit}/associations/many_to_many_spec.rb
  9. +1 −1  spec/{ → unit}/associations/many_to_one_spec.rb
  10. +3 −3 spec/{ → unit}/associations/one_to_many_spec.rb
  11. +3 −2 spec/{ → unit}/associations/one_to_one_spec.rb
  12. +20 −20 spec/{ → unit}/associations/relationship_spec.rb
  13. +23 −24 spec/{ → unit}/cli_spec.rb
  14. +9 −9 spec/{ → unit}/dependency_spec.rb
  15. +40 −37 spec/{ → unit}/hook_spec.rb
  16. +38 −39 spec/{ → unit}/identity_map_spec.rb
  17. +4 −4 spec/{ → unit}/loaded_set_spec.rb
  18. +2 −2 spec/{ → unit}/naming_conventions_spec.rb
  19. +1 −1  spec/{ → unit}/property_set_spec.rb
  20. +3 −3 spec/{ → unit}/property_spec.rb
  21. +1 −1  spec/{ → unit}/query_spec.rb
  22. +8 −8 spec/{ → unit}/repository_spec.rb
  23. +3 −3 spec/{ → unit}/resource_spec.rb
  24. +1 −1  spec/{ → unit}/scope_spec.rb
  25. +38 −36 spec/{ → unit}/support/aliasinghash_spec.rb
  26. +1 −1  spec/{ → unit}/support/blank_spec.rb
  27. +1 −1  spec/{ → unit/support}/inflection_spec.rb
  28. +4 −4 spec/{ → unit}/support/object_spec.rb
  29. +2 −2 spec/{ → unit}/support/string_spec.rb
  30. +6 −6 spec/{ → unit}/support/struct_spec.rb
  31. +15 −13 spec/{ → unit}/type_spec.rb
View
34 .autotest
@@ -1,22 +1,26 @@
Autotest.add_hook :initialize do |at|
- ignore = %w{.git burn www log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE PERFORMANCE QUICKLINKS README}
+ ignore = %w[ .git burn www log plugins script tasks bin CHANGELOG FAQ MIT-LICENSE PERFORMANCE QUICKLINKS README ]
+
unless ENV['AUTOTEST'] == 'integration'
ignore << 'spec/integration'
end
-
- ignore.each do |exception|
+
+ ignore.each do |exception|
at.add_exception(exception)
end
-
+
at.clear_mappings
- at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
- filename
- }
- at.add_mapping(%r%^lib/data_mapper/(.*)\.rb$%) { |_, m|
- ["spec/#{m[1]}_spec.rb"]
- }
- at.add_mapping(%r%^spec/spec_helper.rb$%) {
- at.files_matching %r%^spec/.*_spec\.rb$%
- }
-
-end
+
+ at.add_mapping(%r{^spec/.+_spec\.rb$}) do |filename,_|
+ filename
+ end
+
+ at.add_mapping(%r{^lib/data_mapper/(.+)\.rb$}) do |_,match|
+ [ "spec/unit/#{match[1]}_spec.rb" ] +
+ at.files_matching(%r{^spec/integration/.+_spec\.rb$})
+ end
+
+ at.add_mapping(%r{^spec/spec_helper\.rb$}) do
+ at.files_matching(%r{^spec/.+_spec\.rb$})
+ end
+end
View
1  spec/integration/type_spec.rb
@@ -49,7 +49,6 @@ class Coconut
coconut = TypeTests::Coconut.new(:faked => 'bob', :document => @document, :stuff => @stuff)
coconut.faked.should == 'bob'
coconut.document.should be_a_kind_of(Array)
- p coconut.stuff
coconut.stuff.should be_a_kind_of(Hash)
end
View
2  spec/spec.opts
@@ -1 +1 @@
---require spec/spec_helper
+
View
2  spec/spec_helper.rb
@@ -10,6 +10,8 @@
require __DIR__.parent + 'environment'
require __DIR__ + 'mock_adapter'
+ROOT_DIR = __DIR__.parent
+
class Article
include DataMapper::Resource
View
20 spec/adapters/abstract_adapter_spec.rb → spec/unit/adapters/abstract_adapter_spec.rb
@@ -1,8 +1,8 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper/adapters/abstract_adapter'
-require __DIR__.parent + 'adapter_shared_spec'
+require ROOT_DIR + 'lib/data_mapper/adapters/abstract_adapter'
+require __DIR__ + 'adapter_shared_spec'
describe DataMapper::Adapters::AbstractAdapter do
before do
@@ -10,31 +10,31 @@
end
it_should_behave_like 'a DataMapper Adapter'
-
+
it "should raise NotImplementedError when #create is called" do
lambda { @adapter.create(:repository, :instance) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #read is called" do
lambda { @adapter.read(:repository, :resource, [:key]) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #update is called" do
lambda { @adapter.update(:repository, :instance) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #delete is called" do
lambda { @adapter.delete(:repository, :instance) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #read_one is called" do
lambda { @adapter.read_one(:repository, :query) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #read_set is called" do
lambda { @adapter.read_set(:repository, :query) }.should raise_error(NotImplementedError)
end
-
+
it "should raise NotImplementedError when #delete_set is called" do
lambda { @adapter.delete_set(:repository, :query) }.should raise_error(NotImplementedError)
end
View
1  spec/adapter_shared_spec.rb → spec/unit/adapters/adapter_shared_spec.rb
@@ -13,4 +13,3 @@
end
end
-
View
78 spec/adapters/data_objects_adapter_spec.rb → spec/unit/adapters/data_objects_adapter_spec.rb
@@ -1,9 +1,9 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper'
-require __DIR__.parent.parent + 'lib/data_mapper/adapters/data_objects_adapter'
-require __DIR__.parent + 'adapter_shared_spec'
+require ROOT_DIR + 'lib/data_mapper'
+require ROOT_DIR + 'lib/data_mapper/adapters/data_objects_adapter'
+require __DIR__ + 'adapter_shared_spec'
describe DataMapper::Adapters::DataObjectsAdapter do
before do
@@ -18,7 +18,7 @@
@mock_db = mock('DB Connection', :create_command => @mock_command, :close => true)
@adapter.stub!(:create_connection).and_return(@mock_db)
- end
+ end
it 'should #create_command from the sql passed' do
@mock_db.should_receive(:create_command).with('SQL STRING').and_return(@mock_command)
@@ -54,7 +54,7 @@
describe '#query' do
before do
- @mock_reader = mock('Reader', :fields => ['id', 'UserName', 'AGE'],
+ @mock_reader = mock('Reader', :fields => ['id', 'UserName', 'AGE'],
:values => [1, 'rando', 27],
:close => true)
@mock_command = mock('Command', :execute_reader => @mock_reader)
@@ -63,7 +63,7 @@
#make the while loop run exactly once
@mock_reader.stub!(:next!).and_return(true, nil)
@adapter.stub!(:create_connection).and_return(@mock_db)
- end
+ end
it 'should #create_command from the sql passed' do
@mock_db.should_receive(:create_command).with('SQL STRING').and_return(@mock_command)
@@ -140,7 +140,7 @@
describe DataMapper::Adapters::DataObjectsAdapter::SQL, "creating, reading, updating, deleting statements" do
before do
@adapter = DataMapper::Adapters::DataObjectsAdapter.new(:default, URI.parse('mock://localhost'))
-
+
class Cheese
include DataMapper::Resource
property :id, Fixnum, :serial => true
@@ -148,7 +148,7 @@ class Cheese
property :color, String
property :notes, String, :lazy => true
end
-
+
class LittleBox
include DataMapper::Resource
property :street, String, :key => true
@@ -157,14 +157,14 @@ class LittleBox
property :notes, String, :lazy => true
end
end
-
+
describe "#create_statement" do
- it 'should generate a SQL statement for all fields' do
+ it 'should generate a SQL statement for all fields' do
@adapter.create_statement(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("name", "color") VALUES (?, ?)
EOS
end
-
+
it "should generate a SQL statement for only dirty fields" do
@adapter.create_statement(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("name") VALUES (?)
@@ -175,30 +175,30 @@ class LittleBox
EOS
end
end
-
+
describe "#create_statement_with_returning" do
-
- it 'should generate a SQL statement for all fields' do
+
+ it 'should generate a SQL statement for all fields' do
@adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("name", "color") VALUES (?, ?) RETURNING "id"
EOS
end
-
- it "should generate a SQL statement for only dirty fields" do
+
+ it "should generate a SQL statement for only dirty fields" do
@adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("name") VALUES (?) RETURNING "id"
EOS
-
+
@adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:color)).should == <<-EOS.compress_lines
INSERT INTO "cheeses" ("color") VALUES (?) RETURNING "id"
EOS
end
end
-
+
describe "#update_statement" do
-
- it 'should generate a SQL statement for all fields' do
+
+ it 'should generate a SQL statement for all fields' do
@adapter.update_statement(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
UPDATE "cheeses" SET
"name" = ?,
@@ -206,8 +206,8 @@ class LittleBox
WHERE "id" = ?
EOS
end
-
- it "should generate a SQL statement for only dirty fields" do
+
+ it "should generate a SQL statement for only dirty fields" do
@adapter.update_statement(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
UPDATE "cheeses" SET "name" = ? WHERE "id" = ?
EOS
@@ -216,43 +216,43 @@ class LittleBox
UPDATE "cheeses" SET "color" = ? WHERE "id" = ?
EOS
end
-
+
it "should generate a SQL statement that includes a Composite Key" do
@adapter.update_statement(LittleBox, LittleBox.properties(@adapter.name).slice(:hillside)).should == <<-EOS.compress_lines
UPDATE "little_boxes" SET "hillside" = ? WHERE "street" = ? AND "color" = ?
EOS
-
+
@adapter.update_statement(LittleBox, LittleBox.properties(@adapter.name).slice(:color, :hillside)).should == <<-EOS.compress_lines
UPDATE "little_boxes" SET "color" = ?, "hillside" = ? WHERE "street" = ? AND "color" = ?
EOS
end
end
-
+
describe "#delete_statement" do
-
- it 'should generate a SQL statement for a serial Key' do
+
+ it 'should generate a SQL statement for a serial Key' do
@adapter.delete_statement(Cheese).should == <<-EOS.compress_lines
DELETE FROM "cheeses" WHERE "id" = ?
EOS
end
-
+
it "should generate a SQL statement for a Composite Key" do
@adapter.delete_statement(LittleBox).should == <<-EOS.compress_lines
DELETE FROM "little_boxes" WHERE "street" = ? AND "color" = ?
EOS
end
-
+
end
-
+
describe "#read_statement (without lazy attributes)" do
- it 'should generate a SQL statement for a serial Key' do
+ it 'should generate a SQL statement for a serial Key' do
@adapter.read_statement(Cheese, [1]).should == <<-EOS.compress_lines
SELECT "id", "name", "color" FROM "cheeses" WHERE "id" = ?
EOS
end
-
- it "should generate a SQL statement that includes a Composite Key" do
+
+ it "should generate a SQL statement that includes a Composite Key" do
@adapter.read_statement(LittleBox, ['Shady Drive', 'Blue']).should == <<-EOS.compress_lines
SELECT "street", "color", "hillside" FROM "little_boxes" WHERE "street" = ? AND "color" = ?
EOS
@@ -261,7 +261,7 @@ class LittleBox
end
describe '#uri options' do
- it 'should transform a fully specified option hash into a URI' do
+ it 'should transform a fully specified option hash into a URI' do
options = {
:adapter => 'mysql',
:host => 'davidleal.com',
@@ -271,18 +271,18 @@ class LittleBox
:database => 'you_can_call_me_al',
:socket => 'nosock'
}
-
+
adapter = DataMapper::Adapters::DataObjectsAdapter.allocate
- adapter.uri(options).should ==
+ adapter.uri(options).should ==
URI.parse("mysql://me:mypass@davidleal.com:5000/you_can_call_me_al?socket=nosock")
end
-
+
it 'should transform a minimal options hash into a URI' do
options = {
:adapter => 'mysql',
:database => 'you_can_call_me_al'
}
-
+
adapter = DataMapper::Adapters::DataObjectsAdapter.allocate
adapter.uri(options).should == URI.parse("mysql:///you_can_call_me_al")
end
View
12 spec/associations/many_to_many_spec.rb → spec/unit/associations/many_to_many_spec.rb
@@ -1,21 +1,21 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe "DataMapper::Associations::ManyToMany" do
before do
@adapter = DataMapper::Repository.adapters[:relationship_spec] || DataMapper.setup(:relationship_spec, 'mock://localhost')
end
-
+
it "should allow a declaration" do
-
+
lambda do
class Supplier
many_to_many :manufacturers
end
end.should_not raise_error
end
-
+
describe DataMapper::Associations::ManyToMany::Instance do
before do
@this = mock("this")
@@ -23,7 +23,7 @@ class Supplier
@relationship = mock("relationship")
@association = DataMapper::Associations::ManyToMany::Instance.new(@relationship, @that, nil)
end
-
+
end
-
+
end
View
2  spec/associations/many_to_one_spec.rb → spec/unit/associations/many_to_one_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe "DataMapper::Associations::ManyToOne" do
View
6 spec/associations/one_to_many_spec.rb → spec/unit/associations/one_to_many_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe "DataMapper::Associations::OneToMany" do
@@ -8,12 +8,12 @@
end
it "should allow a declaration" do
-
+
lambda do
class Manufacturer
one_to_many :vehicles
end
end.should_not raise_error
end
-
+
end
View
5 spec/associations/one_to_one_spec.rb → spec/unit/associations/one_to_one_spec.rb
@@ -1,6 +1,7 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent.parent + 'lib/data_mapper/associations/one_to_one'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
+
+require ROOT_DIR + 'lib/data_mapper/associations/one_to_one'
describe "DataMapper::Associations::OneToOne" do
View
40 spec/associations/relationship_spec.rb → spec/unit/associations/relationship_spec.rb
@@ -1,12 +1,12 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe DataMapper::Associations::Relationship do
before do
@adapter = DataMapper::Repository.adapters[:relationship_spec] || DataMapper.setup(:relationship_spec, 'mock://localhost')
end
-
+
it "should describe an association" do
belongs_to = DataMapper::Associations::Relationship.new(
:manufacturer,
@@ -22,7 +22,7 @@
belongs_to.should respond_to(:child_key)
belongs_to.should respond_to(:parent_key)
end
-
+
it "should map properties explicitly when an association method passes them in its options" do
repository_name = :relationship_spec
@@ -37,14 +37,14 @@
belongs_to.name.should == :manufacturer
belongs_to.repository_name.should == repository_name
-
+
belongs_to.child_key.should be_a_kind_of(DataMapper::PropertySet)
belongs_to.parent_key.should be_a_kind_of(DataMapper::PropertySet)
belongs_to.child_key.to_a.should == Vehicle.properties(repository_name).slice(:manufacturer_id)
belongs_to.parent_key.to_a.should == Manufacturer.properties(repository_name).key
end
-
+
it "should infer properties when options aren't passed" do
repository_name = :relationship_spec
@@ -56,17 +56,17 @@
'Manufacturer',
nil
)
-
+
has_many.name.should == :models
has_many.repository_name.should == repository_name
-
+
has_many.child_key.should be_a_kind_of(DataMapper::PropertySet)
has_many.parent_key.should be_a_kind_of(DataMapper::PropertySet)
has_many.child_key.to_a.should == Vehicle.properties(repository_name).slice(:models_id)
has_many.parent_key.to_a.should == Manufacturer.properties(repository_name).key
end
-
+
it "should generate child properties with a safe subset of the parent options" do
pending
# For example, :size would be an option you'd want a generated child Property to copy,
@@ -83,7 +83,7 @@ def initialize(*args, &b)
super(*args)
@on_demand_loader = b
end
-
+
def each
@on_demand_loader[self]
class << self
@@ -91,7 +91,7 @@ def each
super
end
end
-
+
super
end
@@ -102,25 +102,25 @@ def each
command = connection.create_command("SELECT id, name, notes FROM zoos")
command.set_types([Fixnum, String, String])
reader = command.execute_reader
-
+
while(reader.next!)
lls.load(reader.values)
end
- reader.close
+ reader.close
connection.close
end
class AssociationSet
-
+
def initialize(relationship)
@relationship = relationship
end
-
+
def each
# load some stuff
end
-
+
def <<(value)
# add some stuff and track it.
end
@@ -128,15 +128,15 @@ def <<(value)
class Vehicle
belongs_to :manufacturer
-
+
def manufacturer
manufacturer_association_set.first
end
-
+
def manufacturer=(value)
manufacturer_association_set.set(value)
end
-
+
private
# This is all class-evaled code defined by belongs_to:
def manufacturer_association_set
@@ -147,9 +147,9 @@ def manufacturer_association_set
# Parent is the Array of PK properties remember.
resource = set.relationship.parent.first.resource
-
+
resource.all(resource.key => self.loaded_set.keys)
end
end
-
+
end
View
47 spec/cli_spec.rb → spec/unit/cli_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
describe DataMapper::CLI do
@@ -10,10 +10,10 @@
describe "-m or --models" do
it "should " do
-
+
end
end
-
+
# Entire configuration structure, useful for testing scenarios.
describe "-c or --config" do
it "should " do
@@ -21,49 +21,49 @@
# arg = ["c"]
# cli = DataMapper::CLI.new
# cli.parse_args(arg)
-
+
end
end
-
+
# database connection configuration yaml file.
describe "-y or --yaml" do
it "should " do
-
+
end
end
-
+
# logfile
describe "-l or --log" do
it "should " do
-
+
end
end
-
+
# environment to use with database yaml file.
describe "-e, --environment" do
it "should " do
-
+
end
end
-
+
# Loads Merb app settings: config/database.yml, app/models
# Loads Rails app settings: config/database.yml, app/models
describe "--merb, --rails" do
it "should " do
-
+
end
end
describe "database options" do
-
+
# adapter {mysql, pgsql, etc...}
describe "-a, --adapter" do
it "should support mysql" do
end
-
+
it "should support pgsql" do
end
-
+
it "should support sqlite" do
end
end
@@ -71,48 +71,47 @@
# database name
describe "-d, --database" do
it "should set options[:database]" do
-
+
end
end
# user name
describe "-u, --username" do
it "should set options[:username]" do
-
+
end
end
# password
describe "-p, --password" do
it "should set options[:password]" do
-
+
end
end
# host
describe "-h, --host" do
it "should set options[:host]" do
-
+
end
end
# socket
describe "-s, --socket" do
it "should set options[:socket]" do
-
+
end
end
-
+
# port
describe "-o, --port" do
it "should " do
-
+
end
end
-
+
end
end
end
-
View
18 spec/dependency_spec.rb → spec/unit/dependency_spec.rb
@@ -1,29 +1,29 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
# Can't describe DataMapper::Persistable because
# rspec will include it for some crazy reason!
describe "DataMapper::Persistable" do
-
+
it "should be able to add a dependency for a class not yet defined" do
-
+
$happy_cow_defined = false
-
+
DataMapper::Resource.dependencies.add('HappyCow') do |klass|
klass.should eql(Object.const_get('HappyCow'))
klass.key(:default).first.name.should eql(:name)
$happy_cow_defined = true
end
-
+
class HappyCow #< DataMapper::Base # please do not remove this
include DataMapper::Resource
-
+
property :name, String, :key => true
end
-
+
DataMapper::Resource.dependencies.resolve!
-
+
raise 'Dependency not called for HappyCow :-(' unless $happy_cow_defined
end
-
+
end
View
77 spec/hook_spec.rb → spec/unit/hook_spec.rb
@@ -1,4 +1,7 @@
-require File.join(File.dirname(__FILE__), '..', 'lib', 'data_mapper', 'hook')
+require 'pathname'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+
+require ROOT_DIR + 'lib/data_mapper/hook'
describe "DataMapper::Hook" do
before(:each) do
@@ -20,12 +23,12 @@ def yet_another(a, *heh)p
[a, *heh]
end
end
-
+
@class.args_for(@class.instance_method(:a_method)).should == ""
@class.args_for(@class.instance_method(:some_method)).should == "_1, _2, _3"
@class.args_for(@class.instance_method(:yet_another)).should == "_1, *args"
end
-
+
it 'should install the block under the appropriate hook' do
@class.class_eval do
def a_hook
@@ -36,20 +39,20 @@ def a_hook
@class.hooks.should have_key(:a_hook)
@class.hooks[:a_hook][:before].should have(1).item
end
-
+
it 'should run an advice block' do
@class.class_eval do
- def hook
+ def hook
end
-
+
before :hook do
hi_mom!
end
end
-
+
inst = @class.new
inst.should_receive(:hi_mom!)
-
+
inst.hook
end
@@ -57,31 +60,31 @@ def hook
@class.class_eval do
def hook
end
-
+
def before_method()
hi_mom!
end
before :hook, :before_method
end
-
+
inst = @class.new
inst.should_receive(:hi_mom!)
-
+
inst.hook
end
-
+
describe "using before hook" do
it "should install the advice block under the appropriate hook" do
c = lambda { 1 }
-
+
@class.should_receive(:install_hook).with(:before, :a_method, nil, &c)
-
+
@class.class_eval do
before :a_method, &c
end
- end
-
+ end
+
it 'should install the advice method under the appropriate hook' do
@class.class_eval do
def a_hook
@@ -97,45 +100,45 @@ def a_hook
tester = mock("tester")
tester.should_receive(:one).ordered
tester.should_receive(:two).ordered
-
+
@class.send(:define_method, :a_method) do
tester.two
end
-
+
@class.before :a_method do
tester.one
end
-
+
@class.new.a_method
end
-
+
it 'should execute all advices once' do
tester = mock("tester")
tester.should_receive(:before1).once
tester.should_receive(:before2).once
-
+
@class.before :a_method do
tester.before1
end
-
+
@class.before :a_method do
tester.before2
end
-
+
@class.new.a_method
end
end
-
+
describe 'using after hook' do
it "should install the advice block under the appropriate hook" do
c = lambda { 1 }
@class.should_receive(:install_hook).with(:after, :a_method, nil, &c)
-
+
@class.class_eval do
after :a_method, &c
end
- end
-
+ end
+
it 'should install the advice method under the appropriate hook' do
@class.class_eval do
def a_hook
@@ -152,19 +155,19 @@ def a_hook
tester.should_receive(:one).ordered
tester.should_receive(:two).ordered
tester.should_receive(:three).ordered
-
+
@class.send(:define_method, :a_method) do
tester.one
end
-
+
@class.after :a_method do
tester.two
end
-
+
@class.after :a_method do
tester.three
end
-
+
@class.new.a_method
end
@@ -172,15 +175,15 @@ def a_hook
tester = mock("tester")
tester.should_receive(:after1).once
tester.should_receive(:after2).once
-
+
@class.after :a_method do
tester.after1
end
-
+
@class.after :a_method do
tester.after2
end
-
+
@class.new.a_method
end end
@@ -189,7 +192,7 @@ def a_hook
tester.should_receive(:before).ordered.once
tester.should_receive(:method).ordered.once
tester.should_receive(:after).ordered.once
-
+
@class.class_eval do
define_method :a_method do
tester.method
@@ -198,12 +201,12 @@ def a_hook
before :a_method do
tester.before
end
-
+
after :a_method do
tester.after
end
end
-
+
@class.new.a_method
end
end
View
77 spec/identity_map_spec.rb → spec/unit/identity_map_spec.rb
@@ -1,6 +1,5 @@
-
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
describe "DataMapper::IdentityMap" do
before(:all) do
@@ -8,71 +7,71 @@ class Cow
include DataMapper::Resource
property :id, Fixnum, :key => true
property :name, String
- end
+ end
- class Chicken
+ class Chicken
include DataMapper::Resource
property :name, String
- end
+ end
class Pig
include DataMapper::Resource
property :id, Fixnum, :key => true
property :composite, Fixnum, :key => true
property :name, String
- end
+ end
end
-
+
it "should use a second level cache if created with on"
-
- it "should return nil on #get when it does not find the requested instance" do
+
+ it "should return nil on #get when it does not find the requested instance" do
map = DataMapper::IdentityMap.new
- map.get(Cow,[23]).nil?.should == true
+ map.get(Cow,[23]).nil?.should == true
end
-
+
it "should return an instance on #get when it finds the requested instance" do
betsy = Cow.new({:id=>23,:name=>'Betsy'})
map = DataMapper::IdentityMap.new
- map.set(betsy)
- map.get(Cow,[23]).should == betsy
- end
-
+ map.set(betsy)
+ map.get(Cow,[23]).should == betsy
+ end
+
it "should store an instance on #set" do
betsy = Cow.new({:id=>23,:name=>'Betsy'})
map = DataMapper::IdentityMap.new
- map.set(betsy)
+ map.set(betsy)
map.get(Cow,[23]).should == betsy
end
-
+
it "should raise ArgumentError on #set if there is no key property" do
cluck = Chicken.new({:name => 'Cluck'})
map = DataMapper::IdentityMap.new
lambda{map.set(cluck)}.should raise_error(ArgumentError)
end
-
+
it "should raise ArgumentError on #set if the key property is nil" do
betsy = Cow.new({:name=>'Betsy'})
map = DataMapper::IdentityMap.new
- lambda{ map.set(betsy)}.should raise_error(ArgumentError)
+ lambda{ map.set(betsy)}.should raise_error(ArgumentError)
end
-
+
it "should store instances with composite keys on #set" do
pig = Pig.new({:id=>1,:composite=>1,:name=> 'Pig'})
piggy = Pig.new({:id=>1,:composite=>2,:name=>'Piggy'})
-
+
map = DataMapper::IdentityMap.new
map.set(pig)
map.set(piggy)
-
+
map.get(Pig,[1,1]).should == pig
map.get(Pig,[1,2]).should == piggy
end
-
+
it "should remove an instance on #delete" do
betsy = Cow.new({:id=>23,:name=>'Betsy'})
map = DataMapper::IdentityMap.new
- map.set(betsy)
- map.delete(Cow,[23])
+ map.set(betsy)
+ map.delete(Cow,[23])
map.get(Cow,[23]).nil?.should == true
end
@@ -80,7 +79,7 @@ class Pig
betsy = Cow.new({:id=>23,:name=>'Betsy'})
bert = Cow.new({:id=>24,:name=>'Bert'})
piggy = Pig.new({:id=>1,:composite=>2,:name=>'Piggy'})
-
+
map = DataMapper::IdentityMap.new
map.set(betsy)
map.set(bert)
@@ -90,17 +89,17 @@ class Pig
map.get(Cow,[24]).nil?.should == true
map.get(Pig,[1,2]).should == piggy
end
-
-
-
+
+
+
end
describe "Second Level Caching" do
-
+
it "should expose a standard API" do
-
+
cache = Class.new do
-
+
# Retrieve an instance by it's type and key.
#
# +klass+ is the type you want to retrieve. Should
@@ -119,7 +118,7 @@ class Pig
# +return+ nil when a matching instance isn't found,
# or the matching instance when present.
def get(type, key); nil end
-
+
# Store an instance in the map.
#
# +instance+ is the instance you want to store. The cache should
@@ -128,24 +127,24 @@ def get(type, key); nil end
# The instance must also respond to #key, to return it's key. If key returns nil
# or an empty Array, then #set should raise an error.
def set(instance); instance end
-
+
# Clear should flush the entire cache.
- #
+ #
# +type+ if an optional type argument is passed, then
# only the storage for that type should be cleared.
def clear!(type = nil); nil end
-
+
# Allows you to remove a specific instance from the cache.
#
# +instance+ should respond to the same +resource_class+ and +key+ methods #set does.
def delete(instance); nil end
end.new
-
+
cache.should respond_to(:get)
cache.should respond_to(:set)
cache.should respond_to(:clear!)
cache.should respond_to(:delete)
-
+
end
-
+
end
View
8 spec/loaded_set_spec.rb → spec/unit/loaded_set_spec.rb
@@ -1,9 +1,9 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent + 'lib/data_mapper/repository'
-require __DIR__.parent + 'lib/data_mapper/resource'
-require __DIR__.parent + 'lib/data_mapper/loaded_set'
+require ROOT_DIR + 'lib/data_mapper/repository'
+require ROOT_DIR + 'lib/data_mapper/resource'
+require ROOT_DIR + 'lib/data_mapper/loaded_set'
describe "DataMapper::LoadedSet" do
View
4 spec/naming_conventions_spec.rb → spec/unit/naming_conventions_spec.rb
@@ -1,7 +1,7 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
-require __DIR__.parent + 'lib/data_mapper/naming_conventions'
+require ROOT_DIR + 'lib/data_mapper/naming_conventions'
describe "DataMapper::NamingConventions" do
it "should coerce a string into the Underscored convention" do
View
2  spec/property_set_spec.rb → spec/unit/property_set_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
class Icon
include DataMapper::Resource
View
6 spec/property_spec.rb → spec/unit/property_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
describe DataMapper::Property do
@@ -129,7 +129,7 @@ class Tomahto
tomato.class.properties(:default)[:id].set(2, tomato)
tomato.id.should == 2
end
-
+
it 'should respond to custom?' do
DataMapper::Property.new(Zoo, :name, Name, { :size => 50 }).should be_custom
DataMapper::Property.new(Zoo, :state, String, { :size => 2 }).should_not be_custom
@@ -139,7 +139,7 @@ class Tomahto
DataMapper::Property.new(Zoo, :species, String, {}).field.should == 'species'
DataMapper::Property.new(Tomato, :genetic_history, DataMapper::Types::Text, {}).field.should == "genetic_history"
end
-
+
it "should provide the primitive mapping" do
DataMapper::Property.new(Zoo, :poverty, String, {}).primitive.should == String
DataMapper::Property.new(Zoo, :fortune, DataMapper::Types::Text, {}).primitive.should == String
View
2  spec/query_spec.rb → spec/unit/query_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
describe DataMapper::Query do
GOOD_OPTIONS = [
View
16 spec/repository_spec.rb → spec/unit/repository_spec.rb
@@ -1,20 +1,20 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
describe DataMapper::Repository do
before do
@adapter = DataMapper::Repository.adapters[:repository_spec] || DataMapper.setup(:repository_spec, 'mock://localhost')
-
+
class Vegetable
include DataMapper::Resource
-
+
property :id, Fixnum, :serial => true
property :name, String
-
+
end
end
-
+
it "should provide persistance methods" do
repository.should respond_to(:get)
repository.should respond_to(:first)
@@ -26,7 +26,7 @@ class Vegetable
it 'should call #create when #save is called on a new record' do
repository = repository(:repository_spec)
instance = Vegetable.new({:id => 1, :name => 'Potato'})
-
+
@adapter.should_receive(:create).with(repository, instance).and_return(instance)
repository.save(instance)
@@ -36,10 +36,10 @@ class Vegetable
repository = repository(:repository_spec)
instance = Vegetable.new(:name => 'Potato')
instance.instance_variable_set('@new_record', false)
-
+
@adapter.should_receive(:update).with(repository, instance).and_return(instance)
repository.save(instance)
end
-
+
end
View
6 spec/resource_spec.rb → spec/unit/resource_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
# rSpec completely FUBARs everything if you give it a Module here.
# So we give it a String of the module name instead.
@@ -21,7 +21,7 @@ class Planet
include DataMapper::Resource
resource_names[:legacy] = "dying_planets"
-
+
property :id, Fixnum, :key => true
property :name, String, :lock => true
property :age, Fixnum
@@ -38,7 +38,7 @@ class Planet
it "should return an instance of the created object" do
Planet.create(:name => 'Venus', :age => 1_000_000, :core => nil, :id => 42).should be_a_kind_of(Planet)
end
-
+
it "should provide persistance methods" do
Planet.should respond_to(:get)
Planet.should respond_to(:first)
View
2  spec/scope_spec.rb → spec/unit/scope_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
describe DataMapper::Scope do
after do
View
74 spec/support/aliasinghash_spec.rb → spec/unit/support/aliasinghash_spec.rb
@@ -1,142 +1,144 @@
-require __DIR__.parent + 'spec_helper'
-require __DIR__.parent.parent + "lib/data_mapper/support/aliasinghash.rb"
+require 'pathname'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
+
+require ROOT_DIR + 'lib/data_mapper/support/aliasinghash.rb'
describe DataMapper::Support::AliasingHash do
-
+
before(:all) do
end
-
+
it 'should have key_aliases initialized as empty hash' do
hash = AliasingHash.new()
-
+
hash.aliases.should == {}
end
-
+
it 'should have key_aliases initialized as empty hash' do
hash = AliasingHash[]
-
+
hash.aliases.should == {}
end
-
+
it 'should read keys as regular hash' do
hash = AliasingHash[:a => "test a", :b => "test b"]
-
+
hash[:a].should == "test a"
hash[:b].should == "test b"
end
-
+
it 'should fetch keys like regular hash' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.alias!(:a, :a1)
-
+
hash.fetch(:a).should == "test a"
hash.fetch(:a1).should == "test a"
hash.fetch(:b).should == "test b"
end
-
+
it 'should return keys including aliases' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.alias!(:a, :a1)
-
+
(hash.keys - [:a, :a1, :b]).size.should == 0
end
-
+
it 'should acceps aliases in has_key?' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.alias!(:a, :a1)
-
+
hash.has_key?(:a).should == true
hash.has_key?(:a1).should == true
hash.has_key?(:b).should == true
hash.has_key?(:c).should == false
end
-
+
it 'should read keys as regular hash even with aliases present' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.alias!(:a, :a1)
hash.alias!(:a, :a2)
hash.alias!(:b, :b1)
-
+
hash[:a].should == "test a"
hash[:a1].should == "test a"
-
+
hash[:b].should == "test b"
hash[:b1].should == "test b"
end
-
+
it 'should be able to alias any time' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash[:a].should == "test a"
-
+
hash.alias!(:a, :a1)
hash[:a].should == "test a"
hash[:a1].should == "test a"
hash[:b].should == "test b"
-
+
hash.alias!(:a, :a2)
hash[:a].should == "test a"
hash[:a1].should == "test a"
- hash[:a2].should == "test a"
-
+ hash[:a2].should == "test a"
+
hash.alias!(:b, :b1)
hash[:a].should == "test a"
hash[:a1].should == "test a"
hash[:b].should == "test b"
hash[:b1].should == "test b"
end
-
+
it 'should assign values like a regular hash' do
hash = AliasingHash[:a => "test a", :b => "test b"]
-
+
hash[:a] = "a test"
hash[:a].should == "a test"
end
-
+
it 'should assign values through aliases' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.alias!(:a, :a1)
hash[:a1] = "a test"
-
+
hash[:a].should == "a test"
end
-
+
it 'should return list of aliases for a key' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.alias!(:a, :a1)
hash.alias!(:a, :a2)
hash.alias!(:b, :b1)
-
+
(hash.key_aliases(:a) - [:a1, :a2]).size.should == 0
end
-
+
it "should return an empty array if specified key doesn't exist" do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.key_aliases(:c).should == []
end
-
+
it 'should raise CantAliasAliasesException if there is an attempt to alias an alias' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.alias!(:a, :a1)
lambda { hash.alias!(:a1, :a2) }.should raise_error(DataMapper::Support::AliasingHash::CantAliasAliasesException)
end
-
+
it 'should raise AliasAlreadyExistsException if there is an attempt to alias an alias' do
hash = AliasingHash[:a => "test a", :b => "test b"]
hash.alias!(:a, :a1)
lambda { hash.alias!(:b, :a1) }.should raise_error(DataMapper::Support::AliasingHash::AliasAlreadyExistsException)
end
-
+
it 'should raise KeyAlreadyExistsException if there is an attempt to alias an alias' do
hash = AliasingHash[:a => "test a", :b => "test b"]
lambda { hash.alias!(:a, :b) }.should raise_error(DataMapper::Support::AliasingHash::KeyAlreadyExistsException)
end
-
+
it 'shold be able to handle arbitrary object aliases' do
hash = AliasingHash[:a => 1, :b => 2]
hash.alias!(:a, "3")
hash["3"] = 2
-
+
hash["3"].should == 2
end
-end
+end
View
2  spec/support/blank_spec.rb → spec/unit/support/blank_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe DataMapper::Support do
it "should mark empty objects as blank" do
View
2  spec/inflection_spec.rb → spec/unit/support/inflection_spec.rb
@@ -1,5 +1,5 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe DataMapper::Inflection do
View
8 spec/support/object_spec.rb → spec/unit/support/object_spec.rb
@@ -1,15 +1,15 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe DataMapper::Support::Object do
-
+
it "should be able to get a recursive constant" do
Object.recursive_const_get('DataMapper::Support::String').should == DataMapper::Support::String
end
-
+
it "should not cache unresolvable class string" do
lambda { Object.recursive_const_get('Foo::Bar::Baz') }.should raise_error(NameError)
Object.instance_variable_get(:@nested_constants).has_key?('Foo::Bar::Baz').should == false
end
-
+
end
View
4 spec/support/string_spec.rb → spec/unit/support/string_spec.rb
@@ -1,8 +1,8 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe DataMapper::Support::String do
-
+
it "should translate" do
"%s is great!".t('DataMapper').should eql("DataMapper is great!")
end
View
12 spec/support/struct_spec.rb → spec/unit/support/struct_spec.rb
@@ -1,13 +1,13 @@
require 'pathname'
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
describe Struct do
-
+
it "should have attributes" do
-
+
s = Struct.new(:name).new('bob')
s.attributes.should == { :name => 'bob' }
-
+
end
-
-end
+
+end
View
28 spec/type_spec.rb → spec/unit/type_spec.rb
@@ -1,5 +1,7 @@
-require File.join(File.dirname(__FILE__), 'spec_helper')
-require __DIR__.parent + 'lib/data_mapper/property'
+require 'pathname'
+require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
+
+require ROOT_DIR + 'lib/data_mapper/property'
describe DataMapper::Type do
@@ -8,47 +10,47 @@ class TestType < DataMapper::Type
primitive String
size 10
end
-
+
class TestType2 < DataMapper::Type
primitive String
size 10
-
+
def self.load(value)
value.reverse
end
-
+
def self.dump(value)
value.reverse
end
end
end
-
+
it "should have the same PROPERTY_OPTIONS aray as DataMapper::Property" do
# pending("currently there is no way to read PROPERTY_OPTIONS and aliases from DataMapper::Property. Also, some properties need to be defined as aliases instead of being listed in the PROPERTY_OPTIONS array")
DataMapper::Type::PROPERTY_OPTIONS.should == DataMapper::Property::PROPERTY_OPTIONS
end
-
+
it "should create a new type based on String primitive" do
TestType.primitive.should == String
end
-
+
it "should have size of 10" do
TestType.size.should == 10
end
-
+
it "should have options hash exactly equal to options specified in custom type" do
#ie. it should not include null elements
TestType.options.should == { :size => 10, :length => 10 }
end
-
+
it "should have length aliased to size" do
TestType.length.should == TestType.size
end
-
+
it "should pass through the value if load wasn't overriden" do
TestType.load("test").should == "test"
end
-
+
it "should pass through the value if dump wasn't overriden" do
TestType.dump("test").should == "test"
end
@@ -56,7 +58,7 @@ def self.dump(value)
it "should not raise NotImplmenetedException if load was overriden" do
TestType2.dump("helo").should == "oleh"
end
-
+
it "should not raise NotImplmenetedException if dump was overriden" do
TestType2.load("oleh").should == "helo"
end
Please sign in to comment.
Something went wrong with that request. Please try again.