forked from AlexDenisov/iActiveRecord
/
DependencySpec.mm
138 lines (116 loc) · 3.64 KB
/
DependencySpec.mm
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
//
// DependencySpec.mm
// iActiveRecord
//
// Created by Alex Denisov on 01.08.12.
// Copyright (c) 2012 CoreInvader. All rights reserved.
//
#import "Cedar-iOS/SpecHelper.h"
#import "ARDatabaseManager.h"
#import "User.h"
#import "Project.h"
#import "Group.h"
#import "Issue.h"
using namespace Cedar::Matchers;
SPEC_BEGIN(DependencySpecs)
beforeEach(^{
[[ARDatabaseManager sharedInstance] clearDatabase];
});
afterEach(^{
[[ARDatabaseManager sharedInstance] clearDatabase];
});
describe(@"Destroy", ^{
it(@"HasMany", ^{
User *john = [User newRecord];
john.name = @"John";
[john save];
User *alex = [User newRecord];
alex.name = @"Alex";
[alex save];
Group *students = [Group newRecord];
students.title = @"Students";
[students save];
[students addUser:john];
[students addUser:alex];
[students dropRecord];
[alex release];
[john release];
[students release];
[User count] should equal(0);
});
it(@"BelongsTo", ^{
User *john = [User newRecord];
john.name = @"John";
[john save];
User *peter = [User newRecord];
peter.name = @"Peter";
[peter save];
Group *students = [Group newRecord];
students.title = @"Students";
[students save];
[students addUser:john];
[students addUser:peter];
[john dropRecord];
[Group count] should equal(0);
[User count] should equal(0);
});
it(@"HasManyThrough", ^{
User *john = [User newRecord];
john.name = @"John";
[john save];
Project *makeTea = [Project newRecord];
makeTea.name = @"Make tea";
[makeTea save];
[makeTea addUser:john];
[john dropRecord];
[User count] should equal(0);
[Project count] should equal(0);
});
});
describe(@"Destroy/Nulify", ^{
describe(@"HasMany - destroy, BelongsTo - nullify", ^{
it(@"when i drop project it should drop all issues", ^{
Issue *issue = [Issue newRecord];
issue.title = @"new issue";
[issue save];
Project *project = [Project newRecord];
project.name = @"Make tea";
[project save];
[project addIssue:issue];
Issue *emptyIssue = [Issue newRecord];
emptyIssue.title = @"empty";
[emptyIssue save];
[project dropRecord];
[Issue count] should equal(1);
});
it(@"when i drop issue it should not drop project issues", ^{
Issue *issue = [Issue newRecord];
issue.title = @"new issue";
[issue save];
Project *project = [Project newRecord];
project.name = @"Make tea";
[project save];
[project addIssue:issue];
Issue *emptyIssue = [Issue newRecord];
emptyIssue.title = @"empty";
[emptyIssue save];
NSInteger count = [Project count];
[issue dropRecord];
[Project count] should equal(count);
});
});
});
describe(@"Nulify", ^{
it(@"when i drop project it should not drop group", ^{
Group *students = [Group newRecord];
students.title = @"Students";
[students save];
Project *project = [Project newRecord];
project.name = @"Make tea";
[project save];
[project addGroup:students];
[project dropRecord];
[Group count] should equal(1);
});
});
SPEC_END