datamapper 0.3.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/Manifest.txt +5 -0
- data/README.txt +11 -0
- data/Rakefile +70 -0
- data/lib/datamapper.rb +8 -0
- metadata +152 -319
- data/CHANGELOG +0 -145
- data/FAQ +0 -96
- data/MIT-LICENSE +0 -22
- data/QUICKLINKS +0 -12
- data/README +0 -105
- data/environment.rb +0 -62
- data/example.rb +0 -156
- data/lib/data_mapper.rb +0 -88
- data/lib/data_mapper/adapters/abstract_adapter.rb +0 -43
- data/lib/data_mapper/adapters/data_object_adapter.rb +0 -480
- data/lib/data_mapper/adapters/mysql_adapter.rb +0 -72
- data/lib/data_mapper/adapters/postgresql_adapter.rb +0 -258
- data/lib/data_mapper/adapters/sql/coersion.rb +0 -134
- data/lib/data_mapper/adapters/sql/commands/load_command.rb +0 -545
- data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +0 -34
- data/lib/data_mapper/adapters/sql/mappings/column.rb +0 -279
- data/lib/data_mapper/adapters/sql/mappings/conditions.rb +0 -172
- data/lib/data_mapper/adapters/sql/mappings/schema.rb +0 -60
- data/lib/data_mapper/adapters/sql/mappings/table.rb +0 -459
- data/lib/data_mapper/adapters/sql/quoting.rb +0 -24
- data/lib/data_mapper/adapters/sqlite3_adapter.rb +0 -159
- data/lib/data_mapper/associations.rb +0 -106
- data/lib/data_mapper/associations/belongs_to_association.rb +0 -160
- data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +0 -437
- data/lib/data_mapper/associations/has_many_association.rb +0 -283
- data/lib/data_mapper/associations/has_n_association.rb +0 -143
- data/lib/data_mapper/associations/reference.rb +0 -47
- data/lib/data_mapper/attributes.rb +0 -73
- data/lib/data_mapper/auto_migrations.rb +0 -36
- data/lib/data_mapper/base.rb +0 -17
- data/lib/data_mapper/callbacks.rb +0 -107
- data/lib/data_mapper/context.rb +0 -112
- data/lib/data_mapper/database.rb +0 -234
- data/lib/data_mapper/dependency_queue.rb +0 -28
- data/lib/data_mapper/embedded_value.rb +0 -145
- data/lib/data_mapper/identity_map.rb +0 -47
- data/lib/data_mapper/is/tree.rb +0 -121
- data/lib/data_mapper/migration.rb +0 -155
- data/lib/data_mapper/persistence.rb +0 -852
- data/lib/data_mapper/property.rb +0 -310
- data/lib/data_mapper/query.rb +0 -164
- data/lib/data_mapper/support/blank.rb +0 -35
- data/lib/data_mapper/support/connection_pool.rb +0 -117
- data/lib/data_mapper/support/enumerable.rb +0 -35
- data/lib/data_mapper/support/errors.rb +0 -16
- data/lib/data_mapper/support/inflector.rb +0 -265
- data/lib/data_mapper/support/object.rb +0 -54
- data/lib/data_mapper/support/serialization.rb +0 -96
- data/lib/data_mapper/support/silence.rb +0 -10
- data/lib/data_mapper/support/string.rb +0 -72
- data/lib/data_mapper/support/struct.rb +0 -7
- data/lib/data_mapper/support/symbol.rb +0 -82
- data/lib/data_mapper/support/typed_set.rb +0 -65
- data/lib/data_mapper/types/base.rb +0 -44
- data/lib/data_mapper/types/string.rb +0 -34
- data/lib/data_mapper/validatable_extensions/errors.rb +0 -12
- data/lib/data_mapper/validatable_extensions/macros.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validatable_instance_methods.rb +0 -62
- data/lib/data_mapper/validatable_extensions/validation_base.rb +0 -18
- data/lib/data_mapper/validatable_extensions/validations/formats/email.rb +0 -43
- data/lib/data_mapper/validatable_extensions/validations/validates_acceptance_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_confirmation_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_each.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_format_of.rb +0 -28
- data/lib/data_mapper/validatable_extensions/validations/validates_length_of.rb +0 -15
- data/lib/data_mapper/validatable_extensions/validations/validates_numericality_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_presence_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_true_for.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb +0 -40
- data/lib/data_mapper/validations.rb +0 -20
- data/lib/data_mapper/validations/number_validator.rb +0 -40
- data/lib/data_mapper/validations/string_validator.rb +0 -20
- data/lib/data_mapper/validations/validator.rb +0 -13
- data/performance.rb +0 -307
- data/plugins/can_has_sphinx/LICENSE +0 -23
- data/plugins/can_has_sphinx/README +0 -4
- data/plugins/can_has_sphinx/REVISION +0 -1
- data/plugins/can_has_sphinx/Rakefile +0 -22
- data/plugins/can_has_sphinx/init.rb +0 -1
- data/plugins/can_has_sphinx/install.rb +0 -1
- data/plugins/can_has_sphinx/lib/acts_as_sphinx.rb +0 -123
- data/plugins/can_has_sphinx/lib/sphinx.rb +0 -460
- data/plugins/can_has_sphinx/scripts/sphinx.sh +0 -47
- data/plugins/can_has_sphinx/tasks/acts_as_sphinx_tasks.rake +0 -41
- data/profile_data_mapper.rb +0 -40
- data/rakefile.rb +0 -159
- data/spec/acts_as_tree_spec.rb +0 -67
- data/spec/adapters/data_object_adapter_spec.rb +0 -31
- data/spec/associations/belongs_to_association_spec.rb +0 -98
- data/spec/associations/has_and_belongs_to_many_association_spec.rb +0 -377
- data/spec/associations/has_many_association_spec.rb +0 -337
- data/spec/attributes_spec.rb +0 -52
- data/spec/auto_migrations_spec.rb +0 -101
- data/spec/callbacks_spec.rb +0 -186
- data/spec/can_has_sphinx.rb +0 -5
- data/spec/coersion_spec.rb +0 -41
- data/spec/column_spec.rb +0 -114
- data/spec/count_command_spec.rb +0 -45
- data/spec/database_spec.rb +0 -18
- data/spec/dataobjects_spec.rb +0 -27
- data/spec/delete_command_spec.rb +0 -11
- data/spec/dependency_spec.rb +0 -29
- data/spec/embedded_value_spec.rb +0 -161
- data/spec/fixtures/animals.yaml +0 -33
- data/spec/fixtures/animals_exhibits.yaml +0 -2
- data/spec/fixtures/careers.yaml +0 -5
- data/spec/fixtures/comments.yaml +0 -1
- data/spec/fixtures/exhibits.yaml +0 -90
- data/spec/fixtures/fruit.yaml +0 -6
- data/spec/fixtures/people.yaml +0 -37
- data/spec/fixtures/posts.yaml +0 -3
- data/spec/fixtures/projects.yaml +0 -13
- data/spec/fixtures/sections.yaml +0 -5
- data/spec/fixtures/serializers.yaml +0 -6
- data/spec/fixtures/tasks.yaml +0 -6
- data/spec/fixtures/tasks_tasks.yaml +0 -2
- data/spec/fixtures/tomatoes.yaml +0 -1
- data/spec/fixtures/users.yaml +0 -1
- data/spec/fixtures/zoos.yaml +0 -24
- data/spec/is_a_tree_spec.rb +0 -149
- data/spec/legacy_spec.rb +0 -16
- data/spec/load_command_spec.rb +0 -322
- data/spec/magic_columns_spec.rb +0 -26
- data/spec/migration_spec.rb +0 -267
- data/spec/mock_adapter.rb +0 -20
- data/spec/models/animal.rb +0 -12
- data/spec/models/candidate.rb +0 -8
- data/spec/models/career.rb +0 -7
- data/spec/models/chain.rb +0 -8
- data/spec/models/comment.rb +0 -6
- data/spec/models/exhibit.rb +0 -14
- data/spec/models/fence.rb +0 -7
- data/spec/models/fruit.rb +0 -8
- data/spec/models/job.rb +0 -8
- data/spec/models/person.rb +0 -30
- data/spec/models/post.rb +0 -14
- data/spec/models/project.rb +0 -41
- data/spec/models/sales_person.rb +0 -5
- data/spec/models/section.rb +0 -8
- data/spec/models/serializer.rb +0 -5
- data/spec/models/task.rb +0 -9
- data/spec/models/tomato.rb +0 -27
- data/spec/models/user.rb +0 -12
- data/spec/models/zoo.rb +0 -13
- data/spec/natural_key_spec.rb +0 -36
- data/spec/paranoia_spec.rb +0 -38
- data/spec/persistence_spec.rb +0 -479
- data/spec/postgres_spec.rb +0 -96
- data/spec/property_spec.rb +0 -151
- data/spec/query_spec.rb +0 -77
- data/spec/save_command_spec.rb +0 -94
- data/spec/schema_spec.rb +0 -8
- data/spec/serialize_spec.rb +0 -19
- data/spec/single_table_inheritance_spec.rb +0 -43
- data/spec/spec_helper.rb +0 -45
- data/spec/support/blank_spec.rb +0 -8
- data/spec/support/inflector_spec.rb +0 -41
- data/spec/support/object_spec.rb +0 -9
- data/spec/support/serialization_spec.rb +0 -61
- data/spec/support/silence_spec.rb +0 -15
- data/spec/support/string_spec.rb +0 -7
- data/spec/support/struct_spec.rb +0 -12
- data/spec/support/typed_set_spec.rb +0 -66
- data/spec/symbolic_operators_spec.rb +0 -27
- data/spec/table_spec.rb +0 -79
- data/spec/types/string.rb +0 -81
- data/spec/validates_confirmation_of_spec.rb +0 -55
- data/spec/validates_format_of_spec.rb +0 -78
- data/spec/validates_length_of_spec.rb +0 -117
- data/spec/validates_uniqueness_of_spec.rb +0 -92
- data/spec/validations/number_validator.rb +0 -59
- data/spec/validations/string_validator.rb +0 -14
- data/spec/validations_spec.rb +0 -141
- data/tasks/fixtures.rb +0 -53
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe 'Single Table Inheritance' do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
fixtures(:people)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should save and load the correct Type" do
|
10
|
-
database do
|
11
|
-
ted = SalesPerson.new(:name => 'Ted')
|
12
|
-
ted.save
|
13
|
-
|
14
|
-
clone = Person.first(:name => 'Ted')
|
15
|
-
ted.should == clone
|
16
|
-
|
17
|
-
clone.class.should eql(SalesPerson)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Since we're not executing within the same database context
|
21
|
-
# this is not the same object instance as the previous ones.
|
22
|
-
clone2 = Person.first(:name => 'Ted')
|
23
|
-
|
24
|
-
clone2.class.should eql(SalesPerson)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "secondary database should inherit the same attributes" do
|
28
|
-
|
29
|
-
database(:mock) do |db|
|
30
|
-
db.table(SalesPerson)[:name].should_not be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should inherit the callbacks of the parent class" do
|
36
|
-
database do
|
37
|
-
adam = SalesPerson.new(:name => 'adam')
|
38
|
-
adam.save
|
39
|
-
adam.reload.notes.should eql("Lorem ipsum dolor sit amet")
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
|
-
ENV['LOG_NAME'] = 'spec'
|
4
|
-
require File.dirname(__FILE__) + '/../environment'
|
5
|
-
|
6
|
-
# Define a fixtures helper method to load up our test data.
|
7
|
-
def fixtures(name)
|
8
|
-
entry = YAML::load_file(File.dirname(__FILE__) + "/fixtures/#{name}.yaml")
|
9
|
-
klass = begin
|
10
|
-
Kernel::const_get(Inflector.classify(Inflector.singularize(name)))
|
11
|
-
rescue
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
|
15
|
-
unless klass.nil?
|
16
|
-
database.logger.debug { "AUTOMIGRATE: #{klass}" }
|
17
|
-
klass.auto_migrate!
|
18
|
-
|
19
|
-
(entry.kind_of?(Array) ? entry : [entry]).each do |hash|
|
20
|
-
if hash['type']
|
21
|
-
Object::const_get(hash['type'])::create(hash)
|
22
|
-
else
|
23
|
-
klass::create(hash)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
else
|
27
|
-
table = database.table(name.to_s)
|
28
|
-
table.create! true
|
29
|
-
table.activate_associations!
|
30
|
-
|
31
|
-
#pp database.schema
|
32
|
-
|
33
|
-
(entry.kind_of?(Array) ? entry : [entry]).each do |hash|
|
34
|
-
table.insert(hash)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def load_database
|
40
|
-
Dir[File.dirname(__FILE__) + "/fixtures/*.yaml"].each do |path|
|
41
|
-
fixtures(File::basename(path).sub(/\.yaml$/, ''))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
load_database
|
data/spec/support/blank_spec.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Support do
|
4
|
-
it "should mark empty objects as blank" do
|
5
|
-
[ nil, false, '', ' ', " \n\t \r ", [], {} ].each { |f| f.should be_blank }
|
6
|
-
[ Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ].each { |t| t.should_not be_blank }
|
7
|
-
end
|
8
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe Inflector do
|
4
|
-
it "should camelize strings" do
|
5
|
-
Inflector.camelize("data_mapper").should == "DataMapper"
|
6
|
-
Inflector.camelize("data_mapper/support").should == "DataMapper::Support"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should pluralize strings" do
|
10
|
-
Inflector.pluralize("post").should == "posts"
|
11
|
-
Inflector.pluralize("octopus").should == "octopi"
|
12
|
-
Inflector.pluralize("sheep").should == "sheep"
|
13
|
-
Inflector.pluralize("word").should == "words"
|
14
|
-
Inflector.pluralize("the blue mailman").should == "the blue mailmen"
|
15
|
-
Inflector.pluralize("CamelOctopus").should == "CamelOctopi"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should singularize strings" do
|
19
|
-
Inflector.singularize("posts").should == "post"
|
20
|
-
Inflector.singularize("octopi").should == "octopus"
|
21
|
-
Inflector.singularize("sheep").should == "sheep"
|
22
|
-
Inflector.singularize("word").should == "word"
|
23
|
-
Inflector.singularize("the blue mailmen").should == "the blue mailman"
|
24
|
-
Inflector.singularize("CamelOctopi").should == "CamelOctopus"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should demodulize strings" do
|
28
|
-
Inflector.demodulize("DataMapper::Support").should == "Support"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should create foreign keys from class names and key names" do
|
32
|
-
Inflector.foreign_key("Animal").should == "animal_id"
|
33
|
-
Inflector.foreign_key("Admin::Post").should == "post_id"
|
34
|
-
Inflector.foreign_key("Animal", "name").should == "animal_name"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should constantize strings" do
|
38
|
-
Inflector.constantize("Class").should == Class
|
39
|
-
lambda { Inflector.constantize("asdf") }.should raise_error
|
40
|
-
end
|
41
|
-
end
|
data/spec/support/object_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Support::Serialization do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
fixtures(:animals)
|
7
|
-
fixtures(:zoos)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should serialize to YAML" do
|
11
|
-
Animal.first(:name => 'Frog').to_yaml.strip.should == <<-EOS.margin
|
12
|
-
---
|
13
|
-
id: 1
|
14
|
-
name: Frog
|
15
|
-
notes: I am a Frog!
|
16
|
-
nice: false
|
17
|
-
EOS
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should serialize to XML" do
|
21
|
-
Animal.first(:name => 'Frog').to_xml.should == <<-EOS.compress_lines(false)
|
22
|
-
<animal id="1">
|
23
|
-
<name>Frog</name>
|
24
|
-
<notes>I am a Frog!</notes>
|
25
|
-
<nice>false</nice>
|
26
|
-
</animal>
|
27
|
-
EOS
|
28
|
-
|
29
|
-
san_diego_zoo = Zoo.first(:name => 'San Diego')
|
30
|
-
san_diego_zoo.to_xml.should == <<-EOS.compress_lines(false)
|
31
|
-
<zoo id="2">
|
32
|
-
<name>San Diego</name>
|
33
|
-
<notes/>
|
34
|
-
<updated_at>#{san_diego_zoo.updated_at.dup}</updated_at>
|
35
|
-
</zoo>
|
36
|
-
EOS
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should serialize to JSON" do
|
40
|
-
|
41
|
-
Animal.first(:name => 'Frog').to_json.should == <<-EOS.compress_lines
|
42
|
-
{
|
43
|
-
"id": 1,
|
44
|
-
"name": "Frog",
|
45
|
-
"notes": "I am a Frog!",
|
46
|
-
"nice": false
|
47
|
-
}
|
48
|
-
EOS
|
49
|
-
|
50
|
-
san_diego_zoo = Zoo.first(:name => 'San Diego')
|
51
|
-
san_diego_zoo.to_json.should == <<-EOS.compress_lines
|
52
|
-
{
|
53
|
-
"id": 2,
|
54
|
-
"name": "San Diego",
|
55
|
-
"notes": null,
|
56
|
-
"updated_at": #{san_diego_zoo.updated_at.dup.to_json}
|
57
|
-
}
|
58
|
-
EOS
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe "Kernel#silence_warnings" do
|
4
|
-
|
5
|
-
it "should not warn" do
|
6
|
-
$VERBOSE.should_not be_nil
|
7
|
-
|
8
|
-
silence_warnings do
|
9
|
-
$VERBOSE.should be_nil
|
10
|
-
end
|
11
|
-
|
12
|
-
$VERBOSE.should_not be_nil
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
data/spec/support/string_spec.rb
DELETED
data/spec/support/struct_spec.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Support::TypedSet do
|
4
|
-
|
5
|
-
it "should accept objects of a defined type, and raise for others" do
|
6
|
-
|
7
|
-
s = DataMapper::Support::TypedSet.new(Zoo, Animal)
|
8
|
-
|
9
|
-
lambda do
|
10
|
-
s << Zoo.new
|
11
|
-
s.size.should == 1
|
12
|
-
end.should_not raise_error(ArgumentError)
|
13
|
-
|
14
|
-
lambda do
|
15
|
-
s << Animal.new
|
16
|
-
s.size.should == 2
|
17
|
-
end.should_not raise_error(ArgumentError)
|
18
|
-
|
19
|
-
lambda do
|
20
|
-
s << Exhibit.new
|
21
|
-
s.size.should == 2
|
22
|
-
end.should raise_error(ArgumentError)
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should be sorted" do
|
27
|
-
|
28
|
-
s = DataMapper::Support::TypedSet.new(Numeric)
|
29
|
-
|
30
|
-
s << 8
|
31
|
-
s << 4
|
32
|
-
s << 9
|
33
|
-
s << 27
|
34
|
-
s << 30
|
35
|
-
s << 1
|
36
|
-
s << 0
|
37
|
-
s << 5
|
38
|
-
s << 3
|
39
|
-
|
40
|
-
s.entries.first.should eql(0)
|
41
|
-
s.entries.last.should eql(30)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should respond to blank?" do
|
45
|
-
s = DataMapper::Support::TypedSet.new(Numeric)
|
46
|
-
s.should be_blank
|
47
|
-
|
48
|
-
s << 4
|
49
|
-
s.should_not be_blank
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return the combined entries for two sets" do
|
53
|
-
a = DataMapper::Support::TypedSet.new(Numeric)
|
54
|
-
b = DataMapper::Support::TypedSet.new(Numeric)
|
55
|
-
|
56
|
-
a << 1 << 2 << 3
|
57
|
-
b << 4 << 5 << 6 << 3
|
58
|
-
|
59
|
-
c = (a + b)
|
60
|
-
c.should have(6).entries
|
61
|
-
c.entries.should == [ 1, 2, 3, 4, 5, 6 ]
|
62
|
-
|
63
|
-
lambda { (c + nil) }.should_not raise_error
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe Symbol::Operator do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
fixtures(:people)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'should use greater_than_or_equal_to to limit results' do
|
10
|
-
Person.all(:age.gte => 28).size.should == 3
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'use an Array for in-clauses' do
|
14
|
-
family = Person.all(:id => [1, 2, 4])
|
15
|
-
family[0].name.should == 'Sam'
|
16
|
-
family[1].name.should == 'Amy'
|
17
|
-
family[2].name.should == 'Josh'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'use "not" for not-equal operations' do
|
21
|
-
Person.all(:name.not => 'Bob').size.should == 4
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'age should not be nil' do
|
25
|
-
Person.all(:age.not => nil).size.should == 5
|
26
|
-
end
|
27
|
-
end
|
data/spec/table_spec.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Adapters::Sql::Mappings::Table do
|
4
|
-
it "should return all columns from the database" do
|
5
|
-
table = database.adapter.schema.database_tables.detect{|table| table.name == "zoos"}
|
6
|
-
columns = table.database_columns
|
7
|
-
columns.size.should == database.schema[Zoo].columns.size
|
8
|
-
columns.each { |column| column.should be_a_kind_of( DataMapper::Adapters::Sql::Mappings::Column ) }
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return the default for a column from the database" do
|
12
|
-
table = database.adapter.schema.database_tables.detect{|table| table.name == "animals"}
|
13
|
-
columns = table.database_columns
|
14
|
-
|
15
|
-
column1 = columns.detect{|column| column.name == :name }
|
16
|
-
column1.default.should == "No Name"
|
17
|
-
|
18
|
-
column2 = columns.detect{|column| column.name == :nice }
|
19
|
-
column2.default.should == nil
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should return the nullability for a column from the database" do
|
23
|
-
table = database.adapter.schema.database_tables.detect{|table| table.name == "animals"}
|
24
|
-
columns = table.database_columns
|
25
|
-
|
26
|
-
column1 = columns.detect{|column| column.name == :id }
|
27
|
-
column1.nullable?.should be_false
|
28
|
-
|
29
|
-
column2 = columns.detect{|column| column.name == :nice }
|
30
|
-
column2.nullable?.should be_true
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should create sql for composite unique indexes" do
|
34
|
-
class Cage #< DataMapper::Base # please do not remove this
|
35
|
-
include DataMapper::Persistence
|
36
|
-
|
37
|
-
property :name, :string
|
38
|
-
property :cage_id, :integer
|
39
|
-
|
40
|
-
index [:name, :cage_id], :unique => true
|
41
|
-
end
|
42
|
-
|
43
|
-
index_sql = database.adapter.table(Cage).to_create_composite_index_sql
|
44
|
-
index_sql[0].should match(/CREATE UNIQUE INDEX cages_name_cage_id_index/)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should create sql for composite indexes" do
|
48
|
-
class Lion #< DataMapper::Base # please do not remove this
|
49
|
-
include DataMapper::Persistence
|
50
|
-
|
51
|
-
property :name, :string
|
52
|
-
property :tamer_id, :integer
|
53
|
-
|
54
|
-
index [:name, :tamer_id]
|
55
|
-
end
|
56
|
-
|
57
|
-
index_sql = database.adapter.table(Lion).to_create_composite_index_sql
|
58
|
-
index_sql[0].should match(/CREATE INDEX lions_name_tamer_id_index/)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should create sql for multiple composite indexes" do
|
62
|
-
class Course #< DataMapper::Base # please do not remove this
|
63
|
-
include DataMapper::Persistence
|
64
|
-
|
65
|
-
property :code, :string
|
66
|
-
property :name, :string
|
67
|
-
property :description, :text
|
68
|
-
property :department_id, :integer
|
69
|
-
property :professor_id, :integer
|
70
|
-
|
71
|
-
index [:code, :name], :unique => true
|
72
|
-
index [:department_id, :professor_id], :unique => true
|
73
|
-
end
|
74
|
-
|
75
|
-
index_sql = database.adapter.table(Course).to_create_composite_index_sql
|
76
|
-
index_sql[0].should match(/CREATE UNIQUE INDEX courses_code_name_index/)
|
77
|
-
index_sql[1].should match(/CREATE UNIQUE INDEX courses_department_id_professor_id_index/)
|
78
|
-
end
|
79
|
-
end
|
data/spec/types/string.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Types::String do
|
4
|
-
it "should look like a String" do
|
5
|
-
DataMapper::Types::String.new("duh").should be_a_kind_of(String)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should answer for :string" do
|
9
|
-
DataMapper::Types::TYPE_MAP[:string].should == DataMapper::Types::String
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should be ready to replace Strings" do
|
13
|
-
DataMapper::Types::TYPE_MAP[String].should == DataMapper::Types::String
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "with validations" do
|
17
|
-
|
18
|
-
it "should catch length errors" do
|
19
|
-
nval = mock("length validator")
|
20
|
-
nval.should_receive(:<)
|
21
|
-
|
22
|
-
DataMapper::Validations::NumberValidator.should_receive(:new).and_return(nval)
|
23
|
-
|
24
|
-
class T < DataMapper::Types::String
|
25
|
-
length < 25
|
26
|
-
end
|
27
|
-
|
28
|
-
inst = T.new("Whatever")
|
29
|
-
|
30
|
-
nval.should_receive(:errors_for).with(inst.length).and_return(["error"])
|
31
|
-
|
32
|
-
inst.should_not be_valid
|
33
|
-
inst.errors.should have_exactly(1).item
|
34
|
-
inst.errors[0].should == "error"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should catch match errors" do
|
38
|
-
sval = mock("match validator")
|
39
|
-
sval.should_receive(:matches)
|
40
|
-
|
41
|
-
DataMapper::Validations::StringValidator.should_receive(:new).and_return(sval)
|
42
|
-
|
43
|
-
class R < DataMapper::Types::String
|
44
|
-
matches /aabb/
|
45
|
-
end
|
46
|
-
|
47
|
-
inst = R.new("Whatever")
|
48
|
-
|
49
|
-
sval.should_receive(:errors_for).with(inst).and_return(["error"])
|
50
|
-
|
51
|
-
inst.should_not be_valid
|
52
|
-
inst.errors.should have_exactly(1).item
|
53
|
-
inst.errors[0].should == "error"
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should be valid" do
|
57
|
-
nval = mock("length validator")
|
58
|
-
nval.should_receive(:<)
|
59
|
-
|
60
|
-
DataMapper::Validations::NumberValidator.should_receive(:new).and_return(nval)
|
61
|
-
|
62
|
-
sval = mock("match validator")
|
63
|
-
sval.should_receive(:matches)
|
64
|
-
|
65
|
-
DataMapper::Validations::StringValidator.should_receive(:new).and_return(sval)
|
66
|
-
|
67
|
-
class Q < DataMapper::Types::String
|
68
|
-
length < 25
|
69
|
-
matches /aabb/
|
70
|
-
end
|
71
|
-
|
72
|
-
inst = Q.new("Whatever")
|
73
|
-
|
74
|
-
nval.should_receive(:errors_for).with(inst.length).and_return([])
|
75
|
-
sval.should_receive(:errors_for).with(inst).and_return([])
|
76
|
-
|
77
|
-
inst.should be_valid
|
78
|
-
inst.errors.should be_empty
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|