dm-core 0.9.11 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +17 -14
- data/.gitignore +3 -1
- data/FAQ +6 -5
- data/History.txt +5 -50
- data/Manifest.txt +66 -76
- data/QUICKLINKS +1 -1
- data/README.txt +21 -15
- data/Rakefile +6 -7
- data/SPECS +2 -29
- data/TODO +1 -1
- data/deps.rip +2 -0
- data/dm-core.gemspec +11 -15
- data/lib/dm-core.rb +105 -110
- data/lib/dm-core/adapters.rb +135 -16
- data/lib/dm-core/adapters/abstract_adapter.rb +251 -181
- data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
- data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
- data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
- data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
- data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
- data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
- data/lib/dm-core/associations/many_to_many.rb +372 -90
- data/lib/dm-core/associations/many_to_one.rb +220 -73
- data/lib/dm-core/associations/one_to_many.rb +319 -255
- data/lib/dm-core/associations/one_to_one.rb +66 -53
- data/lib/dm-core/associations/relationship.rb +561 -156
- data/lib/dm-core/collection.rb +1101 -379
- data/lib/dm-core/core_ext/kernel.rb +12 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +4 -34
- data/lib/dm-core/migrations.rb +1283 -0
- data/lib/dm-core/model.rb +570 -369
- data/lib/dm-core/model/descendant_set.rb +81 -0
- data/lib/dm-core/model/hook.rb +45 -0
- data/lib/dm-core/model/is.rb +32 -0
- data/lib/dm-core/model/property.rb +247 -0
- data/lib/dm-core/model/relationship.rb +335 -0
- data/lib/dm-core/model/scope.rb +90 -0
- data/lib/dm-core/property.rb +808 -273
- data/lib/dm-core/property_set.rb +141 -98
- data/lib/dm-core/query.rb +1037 -483
- data/lib/dm-core/query/conditions/comparison.rb +872 -0
- data/lib/dm-core/query/conditions/operation.rb +221 -0
- data/lib/dm-core/query/direction.rb +43 -0
- data/lib/dm-core/query/operator.rb +84 -0
- data/lib/dm-core/query/path.rb +138 -0
- data/lib/dm-core/query/sort.rb +45 -0
- data/lib/dm-core/repository.rb +210 -94
- data/lib/dm-core/resource.rb +641 -421
- data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
- data/lib/dm-core/support/chainable.rb +22 -0
- data/lib/dm-core/support/deprecate.rb +12 -0
- data/lib/dm-core/support/logger.rb +13 -0
- data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
- data/lib/dm-core/transaction.rb +333 -92
- data/lib/dm-core/type.rb +98 -60
- data/lib/dm-core/types/boolean.rb +1 -1
- data/lib/dm-core/types/discriminator.rb +34 -20
- data/lib/dm-core/types/object.rb +7 -4
- data/lib/dm-core/types/paranoid_boolean.rb +11 -9
- data/lib/dm-core/types/paranoid_datetime.rb +11 -9
- data/lib/dm-core/types/serial.rb +3 -3
- data/lib/dm-core/types/text.rb +3 -4
- data/lib/dm-core/version.rb +1 -1
- data/script/performance.rb +102 -109
- data/script/profile.rb +169 -38
- data/spec/lib/adapter_helpers.rb +105 -0
- data/spec/lib/collection_helpers.rb +18 -0
- data/spec/lib/counter_adapter.rb +34 -0
- data/spec/lib/pending_helpers.rb +27 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
- data/spec/public/associations/many_to_many_spec.rb +193 -0
- data/spec/public/associations/many_to_one_spec.rb +73 -0
- data/spec/public/associations/one_to_many_spec.rb +77 -0
- data/spec/public/associations/one_to_one_spec.rb +156 -0
- data/spec/public/collection_spec.rb +65 -0
- data/spec/public/migrations_spec.rb +359 -0
- data/spec/public/model/relationship_spec.rb +924 -0
- data/spec/public/model_spec.rb +159 -0
- data/spec/public/property_spec.rb +829 -0
- data/spec/public/resource_spec.rb +71 -0
- data/spec/public/sel_spec.rb +44 -0
- data/spec/public/setup_spec.rb +145 -0
- data/spec/public/shared/association_collection_shared_spec.rb +317 -0
- data/spec/public/shared/collection_shared_spec.rb +1670 -0
- data/spec/public/shared/finder_shared_spec.rb +1619 -0
- data/spec/public/shared/resource_shared_spec.rb +924 -0
- data/spec/public/shared/sel_shared_spec.rb +112 -0
- data/spec/public/transaction_spec.rb +129 -0
- data/spec/public/types/discriminator_spec.rb +130 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
- data/spec/semipublic/associations/relationship_spec.rb +194 -0
- data/spec/semipublic/associations_spec.rb +177 -0
- data/spec/semipublic/collection_spec.rb +142 -0
- data/spec/semipublic/property_spec.rb +61 -0
- data/spec/semipublic/query/conditions_spec.rb +528 -0
- data/spec/semipublic/query/path_spec.rb +443 -0
- data/spec/semipublic/query_spec.rb +2626 -0
- data/spec/semipublic/resource_spec.rb +47 -0
- data/spec/semipublic/shared/condition_shared_spec.rb +9 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +80 -57
- data/tasks/ci.rb +19 -31
- data/tasks/dm.rb +43 -48
- data/tasks/doc.rb +8 -11
- data/tasks/gemspec.rb +5 -5
- data/tasks/hoe.rb +15 -16
- data/tasks/install.rb +8 -10
- metadata +74 -111
- data/lib/dm-core/associations.rb +0 -207
- data/lib/dm-core/associations/relationship_chain.rb +0 -81
- data/lib/dm-core/auto_migrations.rb +0 -105
- data/lib/dm-core/dependency_queue.rb +0 -32
- data/lib/dm-core/hook.rb +0 -11
- data/lib/dm-core/is.rb +0 -16
- data/lib/dm-core/logger.rb +0 -232
- data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
- data/lib/dm-core/migrator.rb +0 -29
- data/lib/dm-core/scope.rb +0 -58
- data/lib/dm-core/support.rb +0 -7
- data/lib/dm-core/support/array.rb +0 -13
- data/lib/dm-core/support/assertions.rb +0 -8
- data/lib/dm-core/support/errors.rb +0 -23
- data/lib/dm-core/support/kernel.rb +0 -11
- data/lib/dm-core/support/symbol.rb +0 -41
- data/lib/dm-core/type_map.rb +0 -80
- data/lib/dm-core/types.rb +0 -19
- data/script/all +0 -4
- data/spec/integration/association_spec.rb +0 -1382
- data/spec/integration/association_through_spec.rb +0 -203
- data/spec/integration/associations/many_to_many_spec.rb +0 -449
- data/spec/integration/associations/many_to_one_spec.rb +0 -163
- data/spec/integration/associations/one_to_many_spec.rb +0 -188
- data/spec/integration/auto_migrations_spec.rb +0 -413
- data/spec/integration/collection_spec.rb +0 -1073
- data/spec/integration/data_objects_adapter_spec.rb +0 -32
- data/spec/integration/dependency_queue_spec.rb +0 -46
- data/spec/integration/model_spec.rb +0 -197
- data/spec/integration/mysql_adapter_spec.rb +0 -85
- data/spec/integration/postgres_adapter_spec.rb +0 -731
- data/spec/integration/property_spec.rb +0 -253
- data/spec/integration/query_spec.rb +0 -514
- data/spec/integration/repository_spec.rb +0 -61
- data/spec/integration/resource_spec.rb +0 -513
- data/spec/integration/sqlite3_adapter_spec.rb +0 -352
- data/spec/integration/sti_spec.rb +0 -273
- data/spec/integration/strategic_eager_loading_spec.rb +0 -156
- data/spec/integration/transaction_spec.rb +0 -75
- data/spec/integration/type_spec.rb +0 -275
- data/spec/lib/logging_helper.rb +0 -18
- data/spec/lib/mock_adapter.rb +0 -27
- data/spec/lib/model_loader.rb +0 -100
- data/spec/lib/publicize_methods.rb +0 -28
- data/spec/models/content.rb +0 -16
- data/spec/models/vehicles.rb +0 -34
- data/spec/models/zoo.rb +0 -48
- data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
- data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
- data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
- data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
- data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
- data/spec/unit/associations/many_to_many_spec.rb +0 -32
- data/spec/unit/associations/many_to_one_spec.rb +0 -159
- data/spec/unit/associations/one_to_many_spec.rb +0 -393
- data/spec/unit/associations/one_to_one_spec.rb +0 -7
- data/spec/unit/associations/relationship_spec.rb +0 -71
- data/spec/unit/associations_spec.rb +0 -242
- data/spec/unit/auto_migrations_spec.rb +0 -111
- data/spec/unit/collection_spec.rb +0 -182
- data/spec/unit/data_mapper_spec.rb +0 -35
- data/spec/unit/identity_map_spec.rb +0 -126
- data/spec/unit/is_spec.rb +0 -80
- data/spec/unit/migrator_spec.rb +0 -33
- data/spec/unit/model_spec.rb +0 -321
- data/spec/unit/naming_conventions_spec.rb +0 -36
- data/spec/unit/property_set_spec.rb +0 -90
- data/spec/unit/property_spec.rb +0 -753
- data/spec/unit/query_spec.rb +0 -571
- data/spec/unit/repository_spec.rb +0 -93
- data/spec/unit/resource_spec.rb +0 -649
- data/spec/unit/scope_spec.rb +0 -142
- data/spec/unit/transaction_spec.rb +0 -493
- data/spec/unit/type_map_spec.rb +0 -114
- data/spec/unit/type_spec.rb +0 -119
@@ -1,156 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe "Strategic Eager Loading" do
|
4
|
-
include LoggingHelper
|
5
|
-
|
6
|
-
before :all do
|
7
|
-
class ::Zoo
|
8
|
-
include DataMapper::Resource
|
9
|
-
def self.default_repository_name; ADAPTER end
|
10
|
-
|
11
|
-
property :id, Serial
|
12
|
-
property :name, String
|
13
|
-
|
14
|
-
has n, :exhibits
|
15
|
-
end
|
16
|
-
|
17
|
-
class ::Exhibit
|
18
|
-
include DataMapper::Resource
|
19
|
-
def self.default_repository_name; ADAPTER end
|
20
|
-
|
21
|
-
property :id, Serial
|
22
|
-
property :name, String
|
23
|
-
property :zoo_id, Integer
|
24
|
-
|
25
|
-
belongs_to :zoo
|
26
|
-
has n, :animals
|
27
|
-
end
|
28
|
-
|
29
|
-
class ::Animal
|
30
|
-
include DataMapper::Resource
|
31
|
-
def self.default_repository_name; ADAPTER end
|
32
|
-
|
33
|
-
property :id, Serial
|
34
|
-
property :name, String
|
35
|
-
property :exhibit_id, Integer
|
36
|
-
|
37
|
-
belongs_to :exhibit
|
38
|
-
end
|
39
|
-
|
40
|
-
[Zoo, Exhibit, Animal].each { |k| k.auto_migrate!(ADAPTER) }
|
41
|
-
|
42
|
-
repository(ADAPTER) do
|
43
|
-
Zoo.create(:name => "Dallas Zoo")
|
44
|
-
Exhibit.create(:name => "Primates", :zoo_id => 1)
|
45
|
-
Animal.create(:name => "Chimpanzee", :exhibit_id => 1)
|
46
|
-
Animal.create(:name => "Orangutan", :exhibit_id => 1)
|
47
|
-
|
48
|
-
Zoo.create(:name => "San Diego")
|
49
|
-
Exhibit.create(:name => "Aviary", :zoo_id => 2)
|
50
|
-
Exhibit.create(:name => "Insectorium", :zoo_id => 2)
|
51
|
-
Exhibit.create(:name => "Bears", :zoo_id => 2)
|
52
|
-
Animal.create(:name => "Bald Eagle", :exhibit_id => 2)
|
53
|
-
Animal.create(:name => "Parakeet", :exhibit_id => 2)
|
54
|
-
Animal.create(:name => "Roach", :exhibit_id => 3)
|
55
|
-
Animal.create(:name => "Brown Bear", :exhibit_id => 4)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should eager load children" do
|
60
|
-
zoo_ids = Zoo.all.map { |z| z.key }
|
61
|
-
exhibit_ids = Exhibit.all.map { |e| e.key }
|
62
|
-
|
63
|
-
repository(ADAPTER) do
|
64
|
-
zoos = Zoo.all.entries # load all zoos
|
65
|
-
dallas = zoos.find { |z| z.name == 'Dallas Zoo' }
|
66
|
-
|
67
|
-
logger do |log|
|
68
|
-
dallas.exhibits.entries # load all exhibits for zoos in identity_map
|
69
|
-
dallas.exhibits.size.should == 1
|
70
|
-
|
71
|
-
log.readlines.size.should == 1
|
72
|
-
|
73
|
-
repository.identity_map(Zoo).keys.sort.should == zoo_ids
|
74
|
-
repository.identity_map(Exhibit).keys.sort.should == exhibit_ids
|
75
|
-
end
|
76
|
-
|
77
|
-
logger do |log|
|
78
|
-
zoos.each { |zoo| zoo.exhibits.entries } # issues no queries
|
79
|
-
log.readlines.should be_empty
|
80
|
-
end
|
81
|
-
|
82
|
-
dallas.exhibits << Exhibit.new(:name => "Reptiles")
|
83
|
-
dallas.exhibits.size.should == 2
|
84
|
-
dallas.save
|
85
|
-
end
|
86
|
-
repository(ADAPTER) do
|
87
|
-
Zoo.first.exhibits.size.should == 2
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should not eager load children when a query is provided" do
|
92
|
-
repository(ADAPTER) do
|
93
|
-
dallas = Zoo.all.entries.find { |z| z.name == 'Dallas Zoo' }
|
94
|
-
exhibits = dallas.exhibits.entries # load all exhibits
|
95
|
-
|
96
|
-
reptiles, primates = nil, nil
|
97
|
-
|
98
|
-
logger do |log|
|
99
|
-
reptiles = dallas.exhibits(:name => 'Reptiles')
|
100
|
-
reptiles.size.should == 1
|
101
|
-
|
102
|
-
log.readlines.size.should == 1
|
103
|
-
end
|
104
|
-
|
105
|
-
logger do |log|
|
106
|
-
primates = dallas.exhibits(:name => 'Primates')
|
107
|
-
primates.size.should == 1
|
108
|
-
primates.should_not == reptiles
|
109
|
-
|
110
|
-
log.readlines.size.should == 1
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should eager load parents" do
|
116
|
-
animal_ids = Animal.all.map { |a| a.key }
|
117
|
-
exhibit_ids = Exhibit.all.map { |e| e.key }.sort
|
118
|
-
exhibit_ids.pop # remove Reptile exhibit, which has no Animals
|
119
|
-
|
120
|
-
repository(ADAPTER) do
|
121
|
-
animals = Animal.all.entries
|
122
|
-
bear = animals.find { |a| a.name == 'Brown Bear' }
|
123
|
-
|
124
|
-
logger do |log|
|
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
|
-
|
130
|
-
log.readlines.size.should == 1
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should not eager load parents when parent is in IM" do
|
136
|
-
repository(ADAPTER) do
|
137
|
-
animal = Animal.first
|
138
|
-
exhibit = Exhibit.get(1) # load exhibit into IM
|
139
|
-
|
140
|
-
logger do |log|
|
141
|
-
animal.exhibit # load exhibit from IM
|
142
|
-
log.readlines.should be_empty
|
143
|
-
end
|
144
|
-
|
145
|
-
repository.identity_map(Exhibit).keys.should == [exhibit.key]
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should return a Collection when no children" do
|
150
|
-
Zoo.create(:name => 'Portland')
|
151
|
-
|
152
|
-
Zoo.all.each do |zoo|
|
153
|
-
zoo.exhibits.should be_kind_of(DataMapper::Collection)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
# transaction capable adapters
|
4
|
-
ADAPTERS = []
|
5
|
-
ADAPTERS << :postgres if HAS_POSTGRES
|
6
|
-
ADAPTERS << :mysql if HAS_MYSQL
|
7
|
-
ADAPTERS << :sqlite3 if HAS_SQLITE3
|
8
|
-
|
9
|
-
if ADAPTERS.any?
|
10
|
-
class Sputnik
|
11
|
-
include DataMapper::Resource
|
12
|
-
|
13
|
-
property :id, Serial
|
14
|
-
property :name, DM::Text
|
15
|
-
end
|
16
|
-
|
17
|
-
describe DataMapper::Transaction do
|
18
|
-
before :all do
|
19
|
-
@repositories = []
|
20
|
-
|
21
|
-
ADAPTERS.each do |name|
|
22
|
-
@repositories << repository(name)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
before :each do
|
27
|
-
ADAPTERS.each do |name|
|
28
|
-
Sputnik.auto_migrate!(name)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should commit changes to all involved adapters on a two phase commit" do
|
33
|
-
DataMapper::Transaction.new(*@repositories) do
|
34
|
-
ADAPTERS.each do |name|
|
35
|
-
repository(name) { Sputnik.create(:name => 'hepp') }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
ADAPTERS.each do |name|
|
40
|
-
repository(name) { Sputnik.all.size.should == 1 }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should not commit any changes if the block raises an exception" do
|
45
|
-
lambda do
|
46
|
-
DataMapper::Transaction.new(*@repositories) do
|
47
|
-
ADAPTERS.each do |name|
|
48
|
-
repository(name) { Sputnik.create(:name => 'hepp') }
|
49
|
-
end
|
50
|
-
raise "plur"
|
51
|
-
end
|
52
|
-
end.should raise_error(Exception, /plur/)
|
53
|
-
|
54
|
-
ADAPTERS.each do |name|
|
55
|
-
repository(name) { Sputnik.all.size.should == 0 }
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should not commit any changes if any of the adapters doesnt prepare properly" do
|
60
|
-
lambda do
|
61
|
-
DataMapper::Transaction.new(*@repositories) do |transaction|
|
62
|
-
ADAPTERS.each do |name|
|
63
|
-
repository(name) { Sputnik.create(:name => 'hepp') }
|
64
|
-
end
|
65
|
-
|
66
|
-
transaction.primitive_for(@repositories.last.adapter).should_receive(:prepare).and_throw(Exception.new("I am the famous test exception"))
|
67
|
-
end
|
68
|
-
end.should raise_error(Exception, /I am the famous test exception/)
|
69
|
-
|
70
|
-
ADAPTERS.each do |name|
|
71
|
-
repository(name) { Sputnik.all.size.should == 0 }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,275 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
# if RUBY_VERSION >= '1.9.0'
|
4
|
-
# require 'csv'
|
5
|
-
# else
|
6
|
-
# gem 'fastercsv', '~>1.4.0'
|
7
|
-
# require 'fastercsv'
|
8
|
-
# end
|
9
|
-
|
10
|
-
if ADAPTER
|
11
|
-
module ::TypeTests
|
12
|
-
class Impostor < DataMapper::Type
|
13
|
-
primitive String
|
14
|
-
end
|
15
|
-
|
16
|
-
class Coconut
|
17
|
-
include DataMapper::Resource
|
18
|
-
|
19
|
-
storage_names[ADAPTER] = 'coconuts'
|
20
|
-
|
21
|
-
def self.default_repository_name
|
22
|
-
ADAPTER
|
23
|
-
end
|
24
|
-
|
25
|
-
property :id, Serial
|
26
|
-
property :faked, Impostor
|
27
|
-
property :active, Boolean
|
28
|
-
property :note, Text
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class ::Lemon
|
33
|
-
include DataMapper::Resource
|
34
|
-
|
35
|
-
def self.default_repository_name
|
36
|
-
ADAPTER
|
37
|
-
end
|
38
|
-
|
39
|
-
property :id, Serial
|
40
|
-
property :color, String
|
41
|
-
property :deleted_at, DataMapper::Types::ParanoidDateTime
|
42
|
-
end
|
43
|
-
|
44
|
-
class ::Lime
|
45
|
-
include DataMapper::Resource
|
46
|
-
|
47
|
-
def self.default_repository_name
|
48
|
-
ADAPTER
|
49
|
-
end
|
50
|
-
|
51
|
-
property :id, Serial
|
52
|
-
property :color, String
|
53
|
-
property :deleted_at, DataMapper::Types::ParanoidBoolean
|
54
|
-
end
|
55
|
-
|
56
|
-
describe DataMapper::Type, "with #{ADAPTER}" do
|
57
|
-
before do
|
58
|
-
TypeTests::Coconut.auto_migrate!(ADAPTER)
|
59
|
-
|
60
|
-
@document = <<-EOS.margin
|
61
|
-
NAME, RATING, CONVENIENCE
|
62
|
-
Freebird's, 3, 3
|
63
|
-
Whataburger, 1, 5
|
64
|
-
Jimmy John's, 3, 4
|
65
|
-
Mignon, 5, 2
|
66
|
-
Fuzi Yao's, 5, 1
|
67
|
-
Blue Goose, 5, 1
|
68
|
-
EOS
|
69
|
-
|
70
|
-
@stuff = YAML::dump({ 'Happy Cow!' => true, 'Sad Cow!' => false })
|
71
|
-
|
72
|
-
@active = true
|
73
|
-
@note = "This is a note on our ol' guy bob"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should instantiate an object with custom types" do
|
77
|
-
coconut = TypeTests::Coconut.new(:faked => 'bob', :active => @active, :note => @note)
|
78
|
-
coconut.faked.should == 'bob'
|
79
|
-
coconut.active.should be_a_kind_of(TrueClass)
|
80
|
-
coconut.note.should be_a_kind_of(String)
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should CRUD an object with custom types" do
|
84
|
-
repository(ADAPTER) do
|
85
|
-
coconut = TypeTests::Coconut.new(:faked => 'bob', :active => @active, :note => @note)
|
86
|
-
coconut.save.should be_true
|
87
|
-
coconut.id.should_not be_nil
|
88
|
-
|
89
|
-
fred = TypeTests::Coconut.get!(coconut.id)
|
90
|
-
fred.faked.should == 'bob'
|
91
|
-
fred.active.should be_a_kind_of(TrueClass)
|
92
|
-
fred.note.should be_a_kind_of(String)
|
93
|
-
|
94
|
-
note = "Seems like bob is just mockin' around"
|
95
|
-
fred.note = note
|
96
|
-
|
97
|
-
fred.save.should be_true
|
98
|
-
|
99
|
-
active = false
|
100
|
-
fred.active = active
|
101
|
-
|
102
|
-
fred.save.should be_true
|
103
|
-
|
104
|
-
# Can't call coconut.reload since coconut.collection isn't setup.
|
105
|
-
mac = TypeTests::Coconut.get!(fred.id)
|
106
|
-
mac.active.should == active
|
107
|
-
mac.note.should == note
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should respect paranoia with a datetime" do
|
112
|
-
Lemon.auto_migrate!(ADAPTER)
|
113
|
-
|
114
|
-
lemon = nil
|
115
|
-
|
116
|
-
repository(ADAPTER) do |repository|
|
117
|
-
lemon = Lemon.new
|
118
|
-
lemon.color = 'green'
|
119
|
-
|
120
|
-
lemon.save
|
121
|
-
lemon.destroy
|
122
|
-
|
123
|
-
lemon.deleted_at.should be_kind_of(DateTime)
|
124
|
-
end
|
125
|
-
|
126
|
-
repository(ADAPTER) do |repository|
|
127
|
-
Lemon.all.should be_empty
|
128
|
-
Lemon.get(lemon.id).should be_nil
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should provide access to paranoid items with DateTime" do
|
133
|
-
Lemon.auto_migrate!(ADAPTER)
|
134
|
-
|
135
|
-
lemon = nil
|
136
|
-
|
137
|
-
repository(ADAPTER) do |repository|
|
138
|
-
%w(red green yellow blue).each do |color|
|
139
|
-
Lemon.create(:color => color)
|
140
|
-
end
|
141
|
-
|
142
|
-
Lemon.all.size.should == 4
|
143
|
-
Lemon.first.destroy
|
144
|
-
Lemon.all.size.should == 3
|
145
|
-
Lemon.with_deleted{Lemon.all.size.should == 1}
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should set paranoid datetime to a date time" do
|
150
|
-
tmp = (DateTime.now - 0.5)
|
151
|
-
dt = DateTime.now
|
152
|
-
DateTime.stub!(:now).and_return(tmp)
|
153
|
-
|
154
|
-
repository(ADAPTER) do |repository|
|
155
|
-
lemon = Lemon.new
|
156
|
-
lemon.color = 'green'
|
157
|
-
lemon.save
|
158
|
-
lemon.destroy
|
159
|
-
lemon.deleted_at.should == tmp
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should respect paranoia with a boolean" do
|
164
|
-
Lime.auto_migrate!(ADAPTER)
|
165
|
-
|
166
|
-
lime = nil
|
167
|
-
|
168
|
-
repository(ADAPTER) do |repository|
|
169
|
-
lime = Lime.new
|
170
|
-
lime.color = 'green'
|
171
|
-
|
172
|
-
lime.save
|
173
|
-
lime.destroy
|
174
|
-
|
175
|
-
lime.deleted_at.should be_kind_of(TrueClass)
|
176
|
-
end
|
177
|
-
|
178
|
-
repository(ADAPTER) do |repository|
|
179
|
-
Lime.all.should be_empty
|
180
|
-
Lime.get(lime.id).should be_nil
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should provide access to paranoid items with Boolean" do
|
185
|
-
Lime.auto_migrate!(ADAPTER)
|
186
|
-
|
187
|
-
lemon = nil
|
188
|
-
|
189
|
-
repository(ADAPTER) do |repository|
|
190
|
-
%w(red green yellow blue).each do |color|
|
191
|
-
Lime.create(:color => color)
|
192
|
-
end
|
193
|
-
|
194
|
-
Lime.all.size.should == 4
|
195
|
-
Lime.first.destroy
|
196
|
-
Lime.all.size.should == 3
|
197
|
-
Lime.with_deleted{Lime.all.size.should == 1}
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
describe "paranoid types across repositories" do
|
202
|
-
before(:all) do
|
203
|
-
DataMapper::Repository.adapters[:alternate_paranoid] = repository(ADAPTER).adapter.dup
|
204
|
-
|
205
|
-
Object.send(:remove_const, :Orange) if defined?(Orange)
|
206
|
-
class ::Orange
|
207
|
-
include DataMapper::Resource
|
208
|
-
|
209
|
-
def self.default_repository_name
|
210
|
-
ADAPTER
|
211
|
-
end
|
212
|
-
|
213
|
-
property :id, Serial
|
214
|
-
property :color, String
|
215
|
-
|
216
|
-
repository(:alternate_paranoid) do
|
217
|
-
property :deleted, DataMapper::Types::ParanoidBoolean
|
218
|
-
property :deleted_at, DataMapper::Types::ParanoidDateTime
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
repository(:alternate_paranoid){Orange.auto_migrate!}
|
223
|
-
end
|
224
|
-
|
225
|
-
before(:each) do
|
226
|
-
%w(red orange blue green).each{|color| o = Orange.create(:color => color)}
|
227
|
-
end
|
228
|
-
|
229
|
-
after(:each) do
|
230
|
-
Orange.repository.adapter.execute("DELETE FROM oranges")
|
231
|
-
end
|
232
|
-
|
233
|
-
it "should setup the correct objects for the spec" do
|
234
|
-
repository(:alternate_paranoid){Orange.all.should have(4).items}
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should allow access the the default repository" do
|
238
|
-
Orange.all.should have(4).items
|
239
|
-
end
|
240
|
-
|
241
|
-
it "should mark the objects as deleted in the alternate_paranoid repository" do
|
242
|
-
repository(:alternate_paranoid) do
|
243
|
-
Orange.first.destroy
|
244
|
-
Orange.all.should have(3).items
|
245
|
-
Orange.find_by_sql("SELECT * FROM oranges").should have(4).items
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
it "should mark the objects as deleted in the alternate_paranoid repository but ignore it in the #{ADAPTER} repository" do
|
250
|
-
repository(:alternate_paranoid) do
|
251
|
-
Orange.first.destroy
|
252
|
-
end
|
253
|
-
Orange.all.should have(4).items
|
254
|
-
end
|
255
|
-
|
256
|
-
it "should raise an error when trying to destroy from a repository that is not paranoid" do
|
257
|
-
lambda do
|
258
|
-
Orange.first.destroy
|
259
|
-
end.should raise_error(ArgumentError)
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should set all paranoid attributes on delete" do
|
263
|
-
repository(:alternate_paranoid) do
|
264
|
-
orange = Orange.first
|
265
|
-
orange.deleted.should be_false
|
266
|
-
orange.deleted_at.should be_nil
|
267
|
-
orange.destroy
|
268
|
-
|
269
|
-
orange.deleted.should be_true
|
270
|
-
orange.deleted_at.should be_a_kind_of(DateTime)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|