dm-accepts_nested_attributes 0.12.0

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.
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Person.has(n, :projects, :through => :project_memberships);" do
4
+
5
+ before(:all) do
6
+
7
+ class Person
8
+
9
+ include DataMapper::Resource
10
+ extend ConstraintSupport
11
+
12
+ property :id, Serial
13
+ property :name, String, :required => true
14
+
15
+ has n, :project_memberships, constraint(:destroy)
16
+ has n, :projects, :through => :project_memberships
17
+ has n, :tasks, :through => :projects
18
+
19
+ end
20
+
21
+ class Project
22
+
23
+ include DataMapper::Resource
24
+ extend ConstraintSupport
25
+
26
+ property :id, Serial
27
+ property :name, String, :required => true
28
+
29
+ has n, :project_memberships, constraint(:destroy)
30
+ has n, :people, :through => :project_memberships
31
+ has n, :tasks, constraint(:destroy)
32
+
33
+ end
34
+
35
+ class ProjectMembership
36
+
37
+ include DataMapper::Resource
38
+
39
+ property :id, Serial
40
+
41
+ belongs_to :person
42
+ belongs_to :project
43
+
44
+ end
45
+
46
+ class Task
47
+
48
+ include DataMapper::Resource
49
+
50
+ property :id, Serial
51
+ property :name, String, :required => true
52
+
53
+ belongs_to :project
54
+
55
+ end
56
+
57
+ DataMapper.auto_upgrade!
58
+
59
+ end
60
+
61
+ before(:each) do
62
+ ProjectMembership.all.destroy!
63
+ Task.all.destroy!
64
+ Project.all.destroy!
65
+ Person.all.destroy!
66
+ end
67
+
68
+
69
+ describe "Person.accepts_nested_attributes_for(:projects)" do
70
+
71
+ before(:all) do
72
+ Person.accepts_nested_attributes_for :projects
73
+ end
74
+
75
+ it_should_behave_like "every accessible many_to_many association"
76
+ it_should_behave_like "every accessible many_to_many association with no reject_if proc"
77
+ it_should_behave_like "every accessible many_to_many association with :allow_destroy => false"
78
+
79
+ end
80
+
81
+ describe "Person.accepts_nested_attributes_for(:projects, :allow_destroy => false)" do
82
+
83
+ before(:all) do
84
+ Person.accepts_nested_attributes_for :projects, :allow_destroy => false
85
+ end
86
+
87
+ it_should_behave_like "every accessible many_to_many association"
88
+ it_should_behave_like "every accessible many_to_many association with no reject_if proc"
89
+ it_should_behave_like "every accessible many_to_many association with :allow_destroy => false"
90
+
91
+ end
92
+
93
+ describe "Person.accepts_nested_attributes_for(:projects, :allow_destroy = true)" do
94
+
95
+ before(:all) do
96
+ Person.accepts_nested_attributes_for :projects, :allow_destroy => true
97
+ end
98
+
99
+ it_should_behave_like "every accessible many_to_many association"
100
+ it_should_behave_like "every accessible many_to_many association with no reject_if proc"
101
+ it_should_behave_like "every accessible many_to_many association with :allow_destroy => true"
102
+
103
+ end
104
+
105
+ describe "Person.accepts_nested_attributes_for(:projects, :reject_if => lambda { |attrs| true })" do
106
+
107
+ before(:all) do
108
+ Person.accepts_nested_attributes_for :projects, :reject_if => lambda { |attrs| true }
109
+ end
110
+
111
+ it_should_behave_like "every accessible many_to_many association"
112
+ it_should_behave_like "every accessible many_to_many association with a valid reject_if proc"
113
+ it_should_behave_like "every accessible many_to_many association with :allow_destroy => false"
114
+
115
+ end
116
+
117
+ describe "Person.accepts_nested_attributes_for(:projects, :reject_if => lambda { |attrs| false })" do
118
+
119
+ before(:all) do
120
+ Person.accepts_nested_attributes_for :projects, :reject_if => lambda { |attrs| false }
121
+ end
122
+
123
+ it_should_behave_like "every accessible many_to_many association"
124
+ it_should_behave_like "every accessible many_to_many association with no reject_if proc"
125
+ it_should_behave_like "every accessible many_to_many association with :allow_destroy => false"
126
+
127
+ end
128
+
129
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Profile.belongs_to(:person);" do
4
+
5
+ before(:all) do
6
+
7
+ class Person
8
+
9
+ include DataMapper::Resource
10
+ extend ConstraintSupport
11
+
12
+ property :id, Serial
13
+ property :name, String, :required => true
14
+
15
+ has 1, :profile, constraint(:destroy)
16
+
17
+ end
18
+
19
+ class Profile
20
+
21
+ include DataMapper::Resource
22
+
23
+ property :id, Serial
24
+ property :person_id, Integer, :required => true, :min => 0
25
+ property :nick, String, :required => true
26
+
27
+ belongs_to :person
28
+
29
+ end
30
+
31
+ DataMapper.auto_upgrade!
32
+
33
+ end
34
+
35
+ before(:each) do
36
+ Profile.all.destroy!
37
+ Person.all.destroy!
38
+ end
39
+
40
+
41
+ describe "Profile.accepts_nested_attributes_for(:person)" do
42
+
43
+ before(:all) do
44
+ Profile.accepts_nested_attributes_for :person
45
+ end
46
+
47
+ it_should_behave_like "every accessible many_to_one association"
48
+ it_should_behave_like "every accessible many_to_one association with no reject_if proc"
49
+ it_should_behave_like "every accessible many_to_one association with :allow_destroy => false"
50
+
51
+ end
52
+
53
+ describe "Profile.accepts_nested_attributes_for(:person, :allow_destroy => false)" do
54
+
55
+ before(:all) do
56
+ Profile.accepts_nested_attributes_for :person, :allow_destroy => false
57
+ end
58
+
59
+ it_should_behave_like "every accessible many_to_one association"
60
+ it_should_behave_like "every accessible many_to_one association with no reject_if proc"
61
+ it_should_behave_like "every accessible many_to_one association with :allow_destroy => false"
62
+
63
+ end
64
+
65
+ describe "Profile.accepts_nested_attributes_for(:person, :allow_destroy = true)" do
66
+
67
+ before(:all) do
68
+ Profile.accepts_nested_attributes_for :person, :allow_destroy => true
69
+ end
70
+
71
+ it_should_behave_like "every accessible many_to_one association"
72
+ it_should_behave_like "every accessible many_to_one association with no reject_if proc"
73
+ it_should_behave_like "every accessible many_to_one association with :allow_destroy => true"
74
+
75
+ end
76
+
77
+ describe "Profile.accepts_nested_attributes_for(:person, :reject_if => lambda { |attrs| true })" do
78
+
79
+ before(:all) do
80
+ Profile.accepts_nested_attributes_for :person, :reject_if => lambda { |attrs| true }
81
+ end
82
+
83
+ it_should_behave_like "every accessible many_to_one association"
84
+ it_should_behave_like "every accessible many_to_one association with a valid reject_if proc"
85
+ it_should_behave_like "every accessible many_to_one association with :allow_destroy => false"
86
+
87
+ end
88
+
89
+ describe "Profile.accepts_nested_attributes_for(:person, :reject_if => lambda { |attrs| false })" do
90
+
91
+ before(:all) do
92
+ Profile.accepts_nested_attributes_for :person, :reject_if => lambda { |attrs| false }
93
+ end
94
+
95
+ it_should_behave_like "every accessible many_to_one association"
96
+ it_should_behave_like "every accessible many_to_one association with no reject_if proc"
97
+ it_should_behave_like "every accessible many_to_one association with :allow_destroy => false"
98
+
99
+ end
100
+
101
+ end
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Project.has(n, :tasks);" do
4
+
5
+ before(:all) do
6
+
7
+ class Project
8
+
9
+ include DataMapper::Resource
10
+ extend ConstraintSupport
11
+
12
+ property :id, Serial
13
+ property :name, String, :required => true
14
+
15
+ has n, :tasks, constraint(:destroy)
16
+
17
+ end
18
+
19
+ class Task
20
+
21
+ include DataMapper::Resource
22
+
23
+ property :id, Serial
24
+ property :name, String, :required => true
25
+
26
+ belongs_to :project
27
+
28
+ end
29
+
30
+ DataMapper.auto_upgrade!
31
+
32
+ end
33
+
34
+ before(:each) do
35
+ Task.all.destroy!
36
+ Project.all.destroy!
37
+ end
38
+
39
+
40
+ describe "Project.accepts_nested_attributes_for(:tasks)" do
41
+
42
+ before(:all) do
43
+ Project.accepts_nested_attributes_for :tasks
44
+ end
45
+
46
+ it_should_behave_like "every accessible one_to_many association"
47
+ it_should_behave_like "every accessible one_to_many association with no reject_if proc"
48
+ it_should_behave_like "every accessible one_to_many association with :allow_destroy => false"
49
+
50
+ end
51
+
52
+ describe "Project.accepts_nested_attributes_for(:tasks, :allow_destroy => false)" do
53
+
54
+ before(:all) do
55
+ Project.accepts_nested_attributes_for :tasks, :allow_destroy => false
56
+ end
57
+
58
+ it_should_behave_like "every accessible one_to_many association"
59
+ it_should_behave_like "every accessible one_to_many association with no reject_if proc"
60
+ it_should_behave_like "every accessible one_to_many association with :allow_destroy => false"
61
+
62
+ end
63
+
64
+ describe "Project.accepts_nested_attributes_for(:tasks, :allow_destroy => true)" do
65
+
66
+ before(:all) do
67
+ Project.accepts_nested_attributes_for :tasks, :allow_destroy => true
68
+ end
69
+
70
+ it_should_behave_like "every accessible one_to_many association"
71
+ it_should_behave_like "every accessible one_to_many association with no reject_if proc"
72
+ it_should_behave_like "every accessible one_to_many association with :allow_destroy => true"
73
+
74
+ end
75
+
76
+ describe "Project.accepts_nested_attributes_for(:tasks, :reject_if => lambda { |attrs| true })" do
77
+
78
+ before(:all) do
79
+ Project.accepts_nested_attributes_for :tasks, :reject_if => lambda { |attrs| true }
80
+ end
81
+
82
+ it_should_behave_like "every accessible one_to_many association"
83
+ it_should_behave_like "every accessible one_to_many association with a valid reject_if proc"
84
+ it_should_behave_like "every accessible one_to_many association with :allow_destroy => false"
85
+
86
+ end
87
+
88
+ describe "Project.accepts_nested_attributes_for(:tasks, :reject_if => lambda { |attrs| false })" do
89
+
90
+ before(:all) do
91
+ Project.accepts_nested_attributes_for :tasks, :reject_if => lambda { |attrs| false }
92
+ end
93
+
94
+ it_should_behave_like "every accessible one_to_many association"
95
+ it_should_behave_like "every accessible one_to_many association with no reject_if proc"
96
+ it_should_behave_like "every accessible one_to_many association with :allow_destroy => false"
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Person.has(1, :profile);" do
4
+
5
+ before(:all) do
6
+
7
+ class Person
8
+
9
+ include DataMapper::Resource
10
+ extend ConstraintSupport
11
+
12
+ property :id, Serial
13
+ property :name, String, :required => true
14
+
15
+ has 1, :profile, constraint(:destroy)
16
+ has 1, :address, :through => :profile
17
+
18
+ end
19
+
20
+ class Profile
21
+
22
+ include DataMapper::Resource
23
+
24
+ property :id, Serial
25
+ property :nick, String, :required => true
26
+
27
+ belongs_to :person
28
+ has 1, :address
29
+
30
+ end
31
+
32
+ class Address
33
+
34
+ include DataMapper::Resource
35
+
36
+ property :id, Serial
37
+ property :profile_id, Integer, :required => true, :unique => true, :unique_index => true, :min => 0
38
+ property :body, String, :required => true
39
+
40
+ belongs_to :profile
41
+
42
+ end
43
+
44
+ DataMapper.auto_upgrade!
45
+
46
+ end
47
+
48
+ before(:each) do
49
+ Address.all.destroy!
50
+ Profile.all.destroy!
51
+ Person.all.destroy!
52
+ end
53
+
54
+
55
+ describe "Person.accepts_nested_attributes_for(:profile)" do
56
+
57
+ before(:all) do
58
+ Person.accepts_nested_attributes_for :profile
59
+ end
60
+
61
+ it_should_behave_like "every accessible one_to_one association"
62
+ it_should_behave_like "every accessible one_to_one association with no reject_if proc"
63
+ it_should_behave_like "every accessible one_to_one association with :allow_destroy => false"
64
+
65
+ end
66
+
67
+ describe "Person.accepts_nested_attributes_for(:profile, :allow_destroy => false)" do
68
+
69
+ before(:all) do
70
+ Person.accepts_nested_attributes_for :profile, :allow_destroy => false
71
+ end
72
+
73
+ it_should_behave_like "every accessible one_to_one association"
74
+ it_should_behave_like "every accessible one_to_one association with no reject_if proc"
75
+ it_should_behave_like "every accessible one_to_one association with :allow_destroy => false"
76
+
77
+ end
78
+
79
+ describe "Person.accepts_nested_attributes_for(:profile, :allow_destroy => true)" do
80
+
81
+ before(:all) do
82
+ Person.accepts_nested_attributes_for :profile, :allow_destroy => true
83
+ end
84
+
85
+ it_should_behave_like "every accessible one_to_one association"
86
+ it_should_behave_like "every accessible one_to_one association with no reject_if proc"
87
+ it_should_behave_like "every accessible one_to_one association with :allow_destroy => true"
88
+
89
+ end
90
+
91
+ describe "Person.accepts_nested_attributes_for(:profile, :reject_if => lambda { |attrs| true })" do
92
+
93
+ before(:all) do
94
+ Person.accepts_nested_attributes_for :profile, :reject_if => lambda { |attrs| true }
95
+ end
96
+
97
+ it_should_behave_like "every accessible one_to_one association"
98
+ it_should_behave_like "every accessible one_to_one association with a valid reject_if proc"
99
+ it_should_behave_like "every accessible one_to_one association with :allow_destroy => false"
100
+
101
+ end
102
+
103
+ describe "Person.accepts_nested_attributes_for(:profile, :reject_if => lambda { |attrs| false })" do
104
+
105
+ before(:all) do
106
+ Person.accepts_nested_attributes_for :profile, :reject_if => lambda { |attrs| false }
107
+ end
108
+
109
+ it_should_behave_like "every accessible one_to_one association"
110
+ it_should_behave_like "every accessible one_to_one association with no reject_if proc"
111
+ it_should_behave_like "every accessible one_to_one association with :allow_destroy => false"
112
+
113
+ end
114
+
115
+ end