dm-core 0.9.9 → 0.9.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +10 -0
- data/MIT-LICENSE +1 -1
- data/Rakefile +4 -4
- data/dm-core.gemspec +14 -12
- data/lib/dm-core.rb +1 -1
- data/lib/dm-core/adapters/data_objects_adapter.rb +2 -2
- data/lib/dm-core/adapters/mysql_adapter.rb +1 -1
- data/lib/dm-core/adapters/postgres_adapter.rb +1 -1
- data/lib/dm-core/adapters/sqlite3_adapter.rb +1 -1
- data/lib/dm-core/associations/many_to_one.rb +1 -1
- data/lib/dm-core/associations/one_to_many.rb +18 -18
- data/lib/dm-core/associations/relationship.rb +9 -3
- data/lib/dm-core/associations/relationship_chain.rb +1 -1
- data/lib/dm-core/collection.rb +3 -3
- data/lib/dm-core/model.rb +5 -4
- data/lib/dm-core/resource.rb +11 -5
- data/lib/dm-core/version.rb +1 -1
- data/script/all +3 -4
- data/spec/integration/association_spec.rb +18 -18
- data/spec/integration/association_through_spec.rb +4 -4
- data/spec/integration/associations/many_to_many_spec.rb +9 -9
- data/spec/integration/associations/many_to_one_spec.rb +1 -1
- data/spec/integration/associations/one_to_many_spec.rb +3 -3
- data/spec/integration/collection_spec.rb +2 -2
- data/spec/integration/dependency_queue_spec.rb +1 -1
- data/spec/integration/model_spec.rb +1 -1
- data/spec/integration/mysql_adapter_spec.rb +1 -1
- data/spec/integration/postgres_adapter_spec.rb +16 -16
- data/spec/integration/property_spec.rb +10 -6
- data/spec/integration/query_spec.rb +4 -4
- data/spec/integration/repository_spec.rb +1 -1
- data/spec/integration/sqlite3_adapter_spec.rb +7 -7
- data/spec/integration/sti_spec.rb +6 -6
- data/spec/integration/strategic_eager_loading_spec.rb +14 -11
- data/spec/integration/type_spec.rb +10 -6
- data/spec/lib/logging_helper.rb +11 -11
- data/spec/spec_helper.rb +8 -4
- data/spec/unit/adapters/data_objects_adapter_spec.rb +9 -5
- data/spec/unit/adapters/in_memory_adapter_spec.rb +1 -1
- data/spec/unit/adapters/postgres_adapter_spec.rb +5 -5
- data/spec/unit/associations/many_to_many_spec.rb +2 -2
- data/spec/unit/associations/many_to_one_spec.rb +3 -3
- data/spec/unit/associations/one_to_many_spec.rb +2 -2
- data/spec/unit/associations/relationship_spec.rb +6 -6
- data/spec/unit/associations_spec.rb +21 -21
- data/spec/unit/identity_map_spec.rb +3 -3
- data/spec/unit/is_spec.rb +7 -7
- data/spec/unit/property_spec.rb +7 -7
- data/spec/unit/resource_spec.rb +12 -12
- data/spec/unit/transaction_spec.rb +1 -1
- data/tasks/dm.rb +1 -1
- metadata +6 -6
@@ -8,7 +8,7 @@ if HAS_SQLITE3
|
|
8
8
|
|
9
9
|
@property_class = Struct.new(:name, :type, :nullable, :default, :serial)
|
10
10
|
|
11
|
-
class Book
|
11
|
+
class ::Book
|
12
12
|
include DataMapper::Resource
|
13
13
|
|
14
14
|
property :id, Serial
|
@@ -17,23 +17,23 @@ if HAS_SQLITE3
|
|
17
17
|
property :class_type, Discriminator
|
18
18
|
end
|
19
19
|
|
20
|
-
class Propaganda < Book
|
20
|
+
class ::Propaganda < Book
|
21
21
|
property :marxist, Boolean, :nullable => false, :default => false
|
22
22
|
end
|
23
23
|
|
24
|
-
class Fiction < Book
|
24
|
+
class ::Fiction < Book
|
25
25
|
property :series, String
|
26
26
|
end
|
27
27
|
|
28
|
-
class ShortStory < Fiction
|
28
|
+
class ::ShortStory < Fiction
|
29
29
|
property :moral, String
|
30
30
|
end
|
31
31
|
|
32
|
-
class ScienceFiction < Fiction
|
32
|
+
class ::ScienceFiction < Fiction
|
33
33
|
property :aliens, Boolean
|
34
34
|
end
|
35
35
|
|
36
|
-
class SpaceWestern < ScienceFiction
|
36
|
+
class ::SpaceWestern < ScienceFiction
|
37
37
|
property :cowboys, Boolean
|
38
38
|
end
|
39
39
|
end
|
@@ -4,7 +4,7 @@ describe "Strategic Eager Loading" do
|
|
4
4
|
include LoggingHelper
|
5
5
|
|
6
6
|
before :all do
|
7
|
-
class Zoo
|
7
|
+
class ::Zoo
|
8
8
|
include DataMapper::Resource
|
9
9
|
def self.default_repository_name; ADAPTER end
|
10
10
|
|
@@ -14,7 +14,7 @@ describe "Strategic Eager Loading" do
|
|
14
14
|
has n, :exhibits
|
15
15
|
end
|
16
16
|
|
17
|
-
class Exhibit
|
17
|
+
class ::Exhibit
|
18
18
|
include DataMapper::Resource
|
19
19
|
def self.default_repository_name; ADAPTER end
|
20
20
|
|
@@ -26,7 +26,7 @@ describe "Strategic Eager Loading" do
|
|
26
26
|
has n, :animals
|
27
27
|
end
|
28
28
|
|
29
|
-
class Animal
|
29
|
+
class ::Animal
|
30
30
|
include DataMapper::Resource
|
31
31
|
def self.default_repository_name; ADAPTER end
|
32
32
|
|
@@ -67,11 +67,12 @@ describe "Strategic Eager Loading" do
|
|
67
67
|
logger do |log|
|
68
68
|
dallas.exhibits.entries # load all exhibits for zoos in identity_map
|
69
69
|
dallas.exhibits.size.should == 1
|
70
|
+
|
70
71
|
log.readlines.size.should == 1
|
71
|
-
end
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
repository.identity_map(Zoo).keys.sort.should == zoo_ids
|
74
|
+
repository.identity_map(Exhibit).keys.sort.should == exhibit_ids
|
75
|
+
end
|
75
76
|
|
76
77
|
logger do |log|
|
77
78
|
zoos.each { |zoo| zoo.exhibits.entries } # issues no queries
|
@@ -97,16 +98,17 @@ describe "Strategic Eager Loading" do
|
|
97
98
|
logger do |log|
|
98
99
|
reptiles = dallas.exhibits(:name => 'Reptiles')
|
99
100
|
reptiles.size.should == 1
|
101
|
+
|
100
102
|
log.readlines.size.should == 1
|
101
103
|
end
|
102
104
|
|
103
105
|
logger do |log|
|
104
106
|
primates = dallas.exhibits(:name => 'Primates')
|
105
107
|
primates.size.should == 1
|
108
|
+
primates.should_not == reptiles
|
109
|
+
|
106
110
|
log.readlines.size.should == 1
|
107
111
|
end
|
108
|
-
|
109
|
-
primates.should_not == reptiles
|
110
112
|
end
|
111
113
|
end
|
112
114
|
|
@@ -121,11 +123,12 @@ describe "Strategic Eager Loading" do
|
|
121
123
|
|
122
124
|
logger do |log|
|
123
125
|
bear.exhibit
|
126
|
+
|
127
|
+
repository.identity_map(Animal).keys.sort.should == animal_ids
|
128
|
+
repository.identity_map(Exhibit).keys.sort.should == exhibit_ids
|
129
|
+
|
124
130
|
log.readlines.size.should == 1
|
125
131
|
end
|
126
|
-
|
127
|
-
repository.identity_map(Animal).keys.sort.should == animal_ids
|
128
|
-
repository.identity_map(Exhibit).keys.sort.should == exhibit_ids
|
129
132
|
end
|
130
133
|
end
|
131
134
|
|
@@ -1,10 +1,14 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
|
-
|
4
|
-
require '
|
3
|
+
if RUBY_VERSION >= '1.9.0'
|
4
|
+
require 'csv'
|
5
|
+
else
|
6
|
+
gem 'fastercsv', '~>1.4.0'
|
7
|
+
require 'fastercsv'
|
8
|
+
end
|
5
9
|
|
6
10
|
if ADAPTER
|
7
|
-
module TypeTests
|
11
|
+
module ::TypeTests
|
8
12
|
class Impostor < DataMapper::Type
|
9
13
|
primitive String
|
10
14
|
end
|
@@ -25,7 +29,7 @@ if ADAPTER
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
class Lemon
|
32
|
+
class ::Lemon
|
29
33
|
include DataMapper::Resource
|
30
34
|
|
31
35
|
def self.default_repository_name
|
@@ -37,7 +41,7 @@ if ADAPTER
|
|
37
41
|
property :deleted_at, DataMapper::Types::ParanoidDateTime
|
38
42
|
end
|
39
43
|
|
40
|
-
class Lime
|
44
|
+
class ::Lime
|
41
45
|
include DataMapper::Resource
|
42
46
|
|
43
47
|
def self.default_repository_name
|
@@ -199,7 +203,7 @@ if ADAPTER
|
|
199
203
|
DataMapper::Repository.adapters[:alternate_paranoid] = repository(ADAPTER).adapter.dup
|
200
204
|
|
201
205
|
Object.send(:remove_const, :Orange) if defined?(Orange)
|
202
|
-
class Orange
|
206
|
+
class ::Orange
|
203
207
|
include DataMapper::Resource
|
204
208
|
|
205
209
|
def self.default_repository_name
|
data/spec/lib/logging_helper.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module LoggingHelper
|
2
|
-
def logger
|
3
|
-
|
4
|
-
|
2
|
+
def logger
|
3
|
+
class << DataMapper.logger
|
4
|
+
attr_writer :log
|
5
|
+
end
|
6
|
+
|
7
|
+
old_log = DataMapper.logger.log
|
5
8
|
|
6
|
-
log_path = File.join(SPEC_ROOT, "tmp.log")
|
7
|
-
handle = File.open(log_path, "a+")
|
8
|
-
current_adapter.logger = DataObjects::Logger.new(log_path, 0)
|
9
9
|
begin
|
10
|
-
|
10
|
+
StringIO.new('') do |io|
|
11
|
+
DataMapper.logger.log = io
|
12
|
+
yield io
|
13
|
+
end
|
11
14
|
ensure
|
12
|
-
|
13
|
-
handle.close
|
14
|
-
current_adapter.logger = old_logger
|
15
|
-
File.delete(log_path)
|
15
|
+
DataMapper.logger.log = old_log
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,12 +8,11 @@ SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
|
|
8
8
|
require SPEC_ROOT.parent + 'lib/dm-core'
|
9
9
|
|
10
10
|
# Load the various helpers for the spec suite
|
11
|
-
Dir[DataMapper.root / 'spec' / 'lib' / '*.rb'].each do |file|
|
11
|
+
Dir[(DataMapper.root / 'spec' / 'lib' / '*.rb').to_s].each do |file|
|
12
12
|
require file
|
13
13
|
end
|
14
14
|
|
15
15
|
# setup mock adapters
|
16
|
-
DataMapper.setup(:default, "sqlite3::memory:")
|
17
16
|
DataMapper.setup(:default2, "sqlite3::memory:")
|
18
17
|
|
19
18
|
[ :mock, :legacy, :west_coast, :east_coast ].each do |repository_name|
|
@@ -30,8 +29,13 @@ end
|
|
30
29
|
#
|
31
30
|
def setup_adapter(name, default_uri)
|
32
31
|
begin
|
33
|
-
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
34
|
-
|
32
|
+
adapter = DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
33
|
+
|
34
|
+
if name.to_s == ENV['ADAPTER']
|
35
|
+
Object.const_set('ADAPTER', ENV['ADAPTER'].to_sym)
|
36
|
+
DataMapper::Repository.adapters[:default] = adapter
|
37
|
+
end
|
38
|
+
|
35
39
|
true
|
36
40
|
rescue Exception => e
|
37
41
|
if name.to_s == ENV['ADAPTER']
|
@@ -7,7 +7,7 @@ require DataMapper.root / 'spec' / 'unit' / 'adapters' / 'adapter_shared_spec'
|
|
7
7
|
|
8
8
|
describe DataMapper::Adapters::DataObjectsAdapter do
|
9
9
|
before :all do
|
10
|
-
class Cheese
|
10
|
+
class ::Cheese
|
11
11
|
include DataMapper::Resource
|
12
12
|
property :id, Serial
|
13
13
|
property :name, String, :nullable => false
|
@@ -26,7 +26,7 @@ describe DataMapper::Adapters::DataObjectsAdapter do
|
|
26
26
|
describe "#find_by_sql" do
|
27
27
|
|
28
28
|
before do
|
29
|
-
class Plupp
|
29
|
+
class ::Plupp
|
30
30
|
include DataMapper::Resource
|
31
31
|
property :id, Integer, :key => true
|
32
32
|
property :name, String
|
@@ -34,7 +34,7 @@ describe DataMapper::Adapters::DataObjectsAdapter do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should be added to DataMapper::Model" do
|
37
|
-
DataMapper::Model.instance_methods.include?("find_by_sql").should == true
|
37
|
+
DataMapper::Model.instance_methods.map { |m| m.to_s }.include?("find_by_sql").should == true
|
38
38
|
Plupp.should respond_to(:find_by_sql)
|
39
39
|
end
|
40
40
|
|
@@ -73,7 +73,11 @@ describe DataMapper::Adapters::DataObjectsAdapter do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should accept a Query argument with or without options hash" do
|
76
|
-
|
76
|
+
if ADAPTER == :mysql
|
77
|
+
@connection.should_receive(:create_command).twice.with('SELECT `name` FROM `plupps` WHERE (`name` = ?) ORDER BY `id`').and_return(@command)
|
78
|
+
else
|
79
|
+
@connection.should_receive(:create_command).twice.with('SELECT "name" FROM "plupps" WHERE ("name" = ?) ORDER BY "id"').and_return(@command)
|
80
|
+
end
|
77
81
|
@command.should_receive(:execute_reader).twice.with('my pretty plur').and_return(@reader)
|
78
82
|
Plupp.should_receive(:repository).any_number_of_times.and_return(@repository)
|
79
83
|
Plupp.should_receive(:repository).any_number_of_times.with(:plupp_repo).and_return(@repository)
|
@@ -573,7 +577,7 @@ describe DataMapper::Adapters::DataObjectsAdapter do
|
|
573
577
|
|
574
578
|
result = @adapter.query('SQL STRING')
|
575
579
|
|
576
|
-
result.first.members.should == %w
|
580
|
+
result.first.members.map { |m| m.to_s }.should == %w[ id user_name age ]
|
577
581
|
end
|
578
582
|
|
579
583
|
it 'should convert each row into the struct' do
|
@@ -25,7 +25,7 @@ if HAS_POSTGRES
|
|
25
25
|
@adapter.stub!(:query).and_return([ 0 ])
|
26
26
|
|
27
27
|
@original_method = @adapter.class.superclass.instance_method(:upgrade_model_storage)
|
28
|
-
@adapter.class.superclass.send(:define_method, :upgrade_model_storage) {}
|
28
|
+
@adapter.class.superclass.send(:define_method, :upgrade_model_storage) { |repository, model| }
|
29
29
|
end
|
30
30
|
|
31
31
|
after do
|
@@ -49,7 +49,7 @@ if HAS_POSTGRES
|
|
49
49
|
|
50
50
|
it 'should execute the superclass upgrade_model_storage' do
|
51
51
|
rv = mock('inside super')
|
52
|
-
@adapter.class.superclass.send(:define_method, :upgrade_model_storage) { rv }
|
52
|
+
@adapter.class.superclass.send(:define_method, :upgrade_model_storage) { |repository, model| rv }
|
53
53
|
@adapter.upgrade_model_storage(@repository, @model).should == rv
|
54
54
|
end
|
55
55
|
end
|
@@ -91,7 +91,7 @@ if HAS_POSTGRES
|
|
91
91
|
|
92
92
|
it 'should execute the superclass upgrade_model_storage' do
|
93
93
|
rv = mock('inside super')
|
94
|
-
@adapter.class.superclass.send(:define_method, :create_table_statement) { rv }
|
94
|
+
@adapter.class.superclass.send(:define_method, :create_table_statement) { |repository, model| rv }
|
95
95
|
@adapter.create_table_statement(@repository, @model).should == rv
|
96
96
|
end
|
97
97
|
end
|
@@ -117,13 +117,13 @@ if HAS_POSTGRES
|
|
117
117
|
|
118
118
|
it 'should not execute the superclass destroy_model_storage if the storage does not exist' do
|
119
119
|
rv = mock('inside super')
|
120
|
-
@adapter.class.superclass.send(:define_method, :destroy_model_storage) { rv }
|
120
|
+
@adapter.class.superclass.send(:define_method, :destroy_model_storage) { |repository, model| rv }
|
121
121
|
@adapter.destroy_model_storage(@repository, @model).should_not == rv
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'should execute the superclass destroy_model_storage if the storage exists' do
|
125
125
|
rv = mock('inside super')
|
126
|
-
@adapter.class.superclass.send(:define_method, :destroy_model_storage) { rv }
|
126
|
+
@adapter.class.superclass.send(:define_method, :destroy_model_storage) { |repository, model| rv }
|
127
127
|
@adapter.stub!(:storage_exists?).and_return(true)
|
128
128
|
|
129
129
|
@adapter.destroy_model_storage(@repository, @model).should == rv
|
@@ -6,7 +6,7 @@ describe DataMapper::Associations::ManyToMany do
|
|
6
6
|
|
7
7
|
it 'should allow a declaration' do
|
8
8
|
lambda do
|
9
|
-
class Supplier
|
9
|
+
class ::Supplier
|
10
10
|
has n, :manufacturers, :through => Resource
|
11
11
|
end
|
12
12
|
end.should_not raise_error
|
@@ -14,7 +14,7 @@ describe DataMapper::Associations::ManyToMany do
|
|
14
14
|
|
15
15
|
it 'should handle models inside modules' do
|
16
16
|
lambda do
|
17
|
-
module Content
|
17
|
+
module ::Content
|
18
18
|
class Dialect
|
19
19
|
has n, :locales, :through => Resource, :class_name => "Language::Locale"
|
20
20
|
end
|
@@ -6,7 +6,7 @@ describe DataMapper::Associations::ManyToOne do
|
|
6
6
|
|
7
7
|
it 'should allow a declaration' do
|
8
8
|
lambda do
|
9
|
-
class Vehicle
|
9
|
+
class ::Vehicle
|
10
10
|
belongs_to :manufacturer
|
11
11
|
end
|
12
12
|
end.should_not raise_error
|
@@ -102,7 +102,7 @@ describe DataMapper::Associations::ManyToOne::Proxy do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should save the parent' do
|
105
|
-
@relationship.should_receive(:with_repository).and_yield
|
105
|
+
@relationship.should_receive(:with_repository).and_yield
|
106
106
|
@parent.should_receive(:save).with(no_args)
|
107
107
|
@association.save
|
108
108
|
end
|
@@ -112,7 +112,7 @@ describe DataMapper::Associations::ManyToOne::Proxy do
|
|
112
112
|
child_key.should_receive(:set).and_return(true)
|
113
113
|
parent_key = mock("parent_key")
|
114
114
|
parent_key.should_receive(:get).and_return(1)
|
115
|
-
@relationship.should_receive(:with_repository).and_yield
|
115
|
+
@relationship.should_receive(:with_repository).and_yield
|
116
116
|
@relationship.should_receive(:child_key).and_return(child_key)
|
117
117
|
@relationship.should_receive(:parent_key).and_return(parent_key)
|
118
118
|
save_results = mock('save results')
|
@@ -85,11 +85,11 @@ describe DataMapper::Associations::OneToMany do
|
|
85
85
|
|
86
86
|
describe 'proxy accessor' do
|
87
87
|
before :all do
|
88
|
-
class User
|
88
|
+
class ::User
|
89
89
|
include DataMapper::Resource
|
90
90
|
end
|
91
91
|
|
92
|
-
class Order
|
92
|
+
class ::Order
|
93
93
|
include DataMapper::Resource
|
94
94
|
end
|
95
95
|
end
|
@@ -8,8 +8,8 @@ describe DataMapper::Associations::Relationship do
|
|
8
8
|
belongs_to = DataMapper::Associations::Relationship.new(
|
9
9
|
:manufacturer,
|
10
10
|
:mock,
|
11
|
-
|
12
|
-
|
11
|
+
Vehicle,
|
12
|
+
Manufacturer,
|
13
13
|
{ :child_key => [ :manufacturer_id ] }
|
14
14
|
)
|
15
15
|
|
@@ -23,8 +23,8 @@ describe DataMapper::Associations::Relationship do
|
|
23
23
|
belongs_to = DataMapper::Associations::Relationship.new(
|
24
24
|
:manufacturer,
|
25
25
|
:mock,
|
26
|
-
|
27
|
-
|
26
|
+
Vehicle,
|
27
|
+
Manufacturer,
|
28
28
|
{ :child_key => [ :manufacturer_id ], :parent_key => [ :id ] }
|
29
29
|
)
|
30
30
|
|
@@ -44,8 +44,8 @@ describe DataMapper::Associations::Relationship do
|
|
44
44
|
has_many = DataMapper::Associations::Relationship.new(
|
45
45
|
:models,
|
46
46
|
:mock,
|
47
|
-
|
48
|
-
|
47
|
+
Vehicle,
|
48
|
+
Manufacturer,
|
49
49
|
{ :child_key => [:model_id] }
|
50
50
|
)
|
51
51
|
|
@@ -13,7 +13,7 @@ describe "DataMapper::Associations" do
|
|
13
13
|
|
14
14
|
describe "#many_to_one_relationships" do
|
15
15
|
before :all do
|
16
|
-
module MTORelationships
|
16
|
+
module ::MTORelationships
|
17
17
|
class A
|
18
18
|
include DataMapper::Resource
|
19
19
|
def self.default_repository_name
|
@@ -46,11 +46,11 @@ describe "DataMapper::Associations" do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
describe ".relationships" do
|
49
|
-
class B
|
49
|
+
class ::B
|
50
50
|
include DataMapper::Resource
|
51
51
|
end
|
52
52
|
|
53
|
-
class C
|
53
|
+
class ::C
|
54
54
|
include DataMapper::Resource
|
55
55
|
|
56
56
|
repository(:mock) do
|
@@ -58,15 +58,15 @@ describe "DataMapper::Associations" do
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
class D
|
61
|
+
class ::D
|
62
62
|
include DataMapper::Resource
|
63
63
|
has 1, :b
|
64
64
|
end
|
65
65
|
|
66
|
-
class E < D
|
66
|
+
class ::E < D
|
67
67
|
end
|
68
68
|
|
69
|
-
class F < D
|
69
|
+
class ::F < D
|
70
70
|
has 1, :a
|
71
71
|
end
|
72
72
|
|
@@ -92,7 +92,7 @@ describe "DataMapper::Associations" do
|
|
92
92
|
|
93
93
|
it "should allow a declaration" do
|
94
94
|
lambda do
|
95
|
-
class Manufacturer
|
95
|
+
class ::Manufacturer
|
96
96
|
has 1, :halo_car
|
97
97
|
end
|
98
98
|
end.should_not raise_error
|
@@ -100,7 +100,7 @@ describe "DataMapper::Associations" do
|
|
100
100
|
|
101
101
|
it "should not allow a constraint that is not an Integer, Range or Infinity" do
|
102
102
|
lambda do
|
103
|
-
class Manufacturer
|
103
|
+
class ::Manufacturer
|
104
104
|
has '1', :halo_car
|
105
105
|
end
|
106
106
|
end.should raise_error(ArgumentError)
|
@@ -108,7 +108,7 @@ describe "DataMapper::Associations" do
|
|
108
108
|
|
109
109
|
it "should not allow a constraint where the min is larger than the max" do
|
110
110
|
lambda do
|
111
|
-
class Manufacturer
|
111
|
+
class ::Manufacturer
|
112
112
|
has 1..0, :halo_car
|
113
113
|
end
|
114
114
|
end.should raise_error(ArgumentError)
|
@@ -119,7 +119,7 @@ describe "DataMapper::Associations" do
|
|
119
119
|
with(:vehicles, Manufacturer, { :min => 1, :max => 2 }).
|
120
120
|
and_return(@relationship)
|
121
121
|
|
122
|
-
class Manufacturer
|
122
|
+
class ::Manufacturer
|
123
123
|
has(1..2, :vehicles, :min => 5, :max => 10).should == mock_relationship
|
124
124
|
end
|
125
125
|
end
|
@@ -130,7 +130,7 @@ describe "DataMapper::Associations" do
|
|
130
130
|
with(:halo_car, Manufacturer, { :min => 1, :max => 1 }).
|
131
131
|
and_return(@relationship)
|
132
132
|
|
133
|
-
class Manufacturer
|
133
|
+
class ::Manufacturer
|
134
134
|
has(1, :halo_car).should == mock_relationship
|
135
135
|
end
|
136
136
|
end
|
@@ -140,7 +140,7 @@ describe "DataMapper::Associations" do
|
|
140
140
|
with(:halo_car, Manufacturer, { :min => 0, :max => 1 }).
|
141
141
|
and_return(@relationship)
|
142
142
|
|
143
|
-
class Manufacturer
|
143
|
+
class ::Manufacturer
|
144
144
|
has(0..1, :halo_car).should == mock_relationship
|
145
145
|
end
|
146
146
|
end
|
@@ -150,7 +150,7 @@ describe "DataMapper::Associations" do
|
|
150
150
|
with(:halo_car, Manufacturer, { :min => 1, :max => 1, :class_name => 'Car' }).
|
151
151
|
and_return(@relationship)
|
152
152
|
|
153
|
-
class Manufacturer
|
153
|
+
class ::Manufacturer
|
154
154
|
has(1, :halo_car, :class_name => 'Car').should == mock_relationship
|
155
155
|
end
|
156
156
|
end
|
@@ -162,7 +162,7 @@ describe "DataMapper::Associations" do
|
|
162
162
|
with(:vehicles, Manufacturer, { :min => 0, :max => @n }).
|
163
163
|
and_return(@relationship)
|
164
164
|
|
165
|
-
class Manufacturer
|
165
|
+
class ::Manufacturer
|
166
166
|
has(n, :vehicles).should == mock_relationship
|
167
167
|
end
|
168
168
|
end
|
@@ -172,7 +172,7 @@ describe "DataMapper::Associations" do
|
|
172
172
|
with(:vehicles, Manufacturer, { :min => 4, :max => 4 }).
|
173
173
|
and_return(@relationship)
|
174
174
|
|
175
|
-
class Manufacturer
|
175
|
+
class ::Manufacturer
|
176
176
|
has(4, :vehicles).should == mock_relationship
|
177
177
|
end
|
178
178
|
end
|
@@ -182,7 +182,7 @@ describe "DataMapper::Associations" do
|
|
182
182
|
with(:vehicles, Manufacturer, { :min => 2, :max => 4 }).
|
183
183
|
and_return(@relationship)
|
184
184
|
|
185
|
-
class Manufacturer
|
185
|
+
class ::Manufacturer
|
186
186
|
has(2..4, :vehicles).should == mock_relationship
|
187
187
|
end
|
188
188
|
end
|
@@ -192,7 +192,7 @@ describe "DataMapper::Associations" do
|
|
192
192
|
with(:vehicles, Manufacturer, { :min => 1, :max => @n, :class_name => 'Car' }).
|
193
193
|
and_return(@relationship)
|
194
194
|
|
195
|
-
class Manufacturer
|
195
|
+
class ::Manufacturer
|
196
196
|
has(1..n, :vehicles, :class_name => 'Car').should == mock_relationship
|
197
197
|
end
|
198
198
|
end
|
@@ -200,7 +200,7 @@ describe "DataMapper::Associations" do
|
|
200
200
|
# do not remove or change this spec.
|
201
201
|
it "should raise an exception when n..n is used for the cardinality" do
|
202
202
|
lambda do
|
203
|
-
class Manufacturer
|
203
|
+
class ::Manufacturer
|
204
204
|
has n..n, :subsidiaries, :class_name => 'Manufacturer'
|
205
205
|
end
|
206
206
|
end.should raise_error(ArgumentError)
|
@@ -211,7 +211,7 @@ describe "DataMapper::Associations" do
|
|
211
211
|
with(:suppliers, Vehicle, { :min => 0, :max => @n, :through => :manufacturers }).
|
212
212
|
and_return(@relationship)
|
213
213
|
|
214
|
-
class Vehicle
|
214
|
+
class ::Vehicle
|
215
215
|
has(n, :suppliers, :through => :manufacturers).should == mock_relationship
|
216
216
|
end
|
217
217
|
end
|
@@ -224,7 +224,7 @@ describe "DataMapper::Associations" do
|
|
224
224
|
with(:vehicle, Manufacturer, {}).
|
225
225
|
and_return(@relationship)
|
226
226
|
|
227
|
-
class Manufacturer
|
227
|
+
class ::Manufacturer
|
228
228
|
belongs_to(:vehicle).should == mock_relationship
|
229
229
|
end
|
230
230
|
end
|
@@ -234,7 +234,7 @@ describe "DataMapper::Associations" do
|
|
234
234
|
with(:vehicle, Manufacturer, { :class_name => 'Car' }).
|
235
235
|
and_return(@relationship)
|
236
236
|
|
237
|
-
class Manufacturer
|
237
|
+
class ::Manufacturer
|
238
238
|
belongs_to(:vehicle, :class_name => 'Car').should == mock_relationship
|
239
239
|
end
|
240
240
|
end
|