-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathschema_spec.rb
More file actions
175 lines (147 loc) · 5.82 KB
/
Copy pathschema_spec.rb
File metadata and controls
175 lines (147 loc) · 5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Specs to experiment with the schema
module MotionData
describe Schema do
describe ".current" do
it "creates a new schema with version identifier as 'current'" do
Schema.current.versionIdentifiers.allObjects.should == ['current']
end
it "returns the same schema if called twice" do
Schema.current.should === Schema.current
end
end
describe ".defineVersion" do
it "returns a new schema with the given version identifier" do
schema = Schema.defineVersion('this version')
schema.versionIdentifiers.allObjects.should == ['this version']
end
end
describe "when defining" do
before do
end
describe "#entity" do
it "yields an entity description to the block" do
Schema.defineVersion('test') do |s|
s.entity do |e|
e.name = 'AnEntity' # Needed so Core Data doesn't gripe
e.class.should == EntityDescription
end
end
end
it "registers the entity with the schema" do
schema = Schema.defineVersion('test') do |s|
s.entity do |e|
e.name = 'AnEntity' # Needed so Core Data doesn't gripe
end
end
schema.entities.first.name.should == 'AnEntity'
end
end
describe "#property" do
after do
#MagicalRecord.cleanUp
end
it "creates attributes with the given name and type" do
schema = Schema.defineVersion('test') do |s|
s.entity do |e|
e.name = 'AnEntity' # Needed so Core Data doesn't gripe
e.property :someProp, String
end
end
schema.setupCoreDataStackWithInMemoryStore
object = EntityDescription.insertNewObjectForEntityForName('AnEntity',
inManagedObjectContext:Context.current)
object.someProp = 'hey'
object.someProp.should == 'hey'
end
#it "can create non optional types"
end
end
#describe "when migrating" do
#before do
#@version_1 = Schema.defineVersion('migration-test-1') do |s|
#s.entity do |e|
#e.name = 'Entity1'
#e.property :firstProperty, String
#end
#end
#@version_2 = Schema.defineVersion('migration-test-2') do |s|
#s.entity do |e|
#e.name = 'Entity1'
#e.property :firstProperty, String
#e.property :secondProperty, CoreTypes::Boolean
#end
#s.entity do |e|
#e.name = 'Entity2'
#e.property :firstProperty, String
#end
#end
#@version_3 = Schema.defineVersion('migration-test-3') do |s|
#s.entity do |e|
#e.name = 'Entity1'
#e.property :firstProperty, String
## Removed secondProperty
#end
#s.entity do |e|
#e.name = 'Entity2'
## Removed firstProperty
#e.property :secondProperty, CoreTypes::Boolean
#end
#s.entity do |e|
#e.name = 'Entity3'
#e.property :firstProperty, String
#e.property :secondProperty, CoreTypes::Boolean
#end
#end
#end
#after do
#MagicalRecord.cleanUp
#end
#def ensure_schema_version_3_exists!
#entity1 = NSEntityDescription.entityForName('Entity1', inManagedObjectContext:NSManagedObjectContext.defaultContext)
#entity1.properties.size.should == 1
#property = entity1.properties.first
#property.name.should == :firstProperty
#property.attributeType.should == NSStringAttributeType
#entity2 = NSEntityDescription.entityForName('Entity2', inManagedObjectContext:NSManagedObjectContext.defaultContext)
#entity2.properties.size.should == 1
#property = entity2.properties.first
#property.name.should == :secondProperty
#property.attributeType.should == NSBooleanAttributeType
#entity3 = NSEntityDescription.entityForName('Entity3', inManagedObjectContext:NSManagedObjectContext.defaultContext)
#entity3.properties.size.should == 2
#property = entity3.properties.first
#property.name.should == :firstProperty
#property.attributeType.should == NSStringAttributeType
#property = entity3.properties.last
#property.name.should == :secondProperty
#property.attributeType.should == NSBooleanAttributeType
#end
##it "migrates to the latest version from an clean slate" do
### nil -> @version_3
##@version_3.setupCoreDataStackWithInMemoryStore
##@version_3.migrate!
##end
#it "migrates to the latest version from the first version" do
## @version_1 -> @version_3
#@version_1.setupCoreDataStackWithInMemoryStore
#entity1 = NSEntityDescription.entityForName('Entity1', inManagedObjectContext:NSManagedObjectContext.defaultContext)
#entity1.properties.size.should == 1
#property = entity1.properties.first
#property.name.should == :firstProperty
#property.attributeType.should == NSStringAttributeType
#entity2 = NSEntityDescription.entityForName('Entity2', inManagedObjectContext:NSManagedObjectContext.defaultContext)
#entity2.should == nil
#entity3 = NSEntityDescription.entityForName('Entity3', inManagedObjectContext:NSManagedObjectContext.defaultContext)
#entity3.should == nil
##@version_3.migrate!
#@version_3.migrateFromSchema(@version_1)
#ensure_schema_version_3_exists!
#end
##it "migrates to the latest version from an arbitrary version" do
### @version_2 -> @version_3
##@version_2.setupCoreDataStackWithInMemoryStore
##@version_3.migrate!
##end
#end
end
end