snusnu-dm-accepts_nested_attributes 0.0.6 → 0.10.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.
Files changed (33) hide show
  1. data/Manifest.txt +13 -8
  2. data/Rakefile +2 -3
  3. data/TODO +5 -0
  4. data/lib/dm-accepts_nested_attributes.rb +7 -14
  5. data/lib/dm-accepts_nested_attributes/error_collecting.rb +35 -0
  6. data/lib/dm-accepts_nested_attributes/model.rb +132 -0
  7. data/lib/dm-accepts_nested_attributes/resource.rb +218 -29
  8. data/lib/dm-accepts_nested_attributes/save.rb +13 -0
  9. data/lib/dm-accepts_nested_attributes/transactional_save.rb +15 -0
  10. data/lib/dm-accepts_nested_attributes/version.rb +1 -1
  11. data/spec/fixtures/person.rb +8 -0
  12. data/spec/fixtures/profile.rb +9 -0
  13. data/spec/fixtures/project.rb +8 -0
  14. data/spec/fixtures/project_membership.rb +8 -0
  15. data/spec/fixtures/task.rb +9 -0
  16. data/spec/integration/belongs_to_spec.rb +10 -134
  17. data/spec/integration/has_1_spec.rb +9 -121
  18. data/spec/integration/has_n_spec.rb +10 -149
  19. data/spec/integration/has_n_through_spec.rb +10 -162
  20. data/spec/{shared → lib}/rspec_tmbundle_support.rb +1 -1
  21. data/spec/shared/belongs_to_spec.rb +127 -0
  22. data/spec/shared/has_1_spec.rb +103 -0
  23. data/spec/shared/has_n_spec.rb +114 -0
  24. data/spec/shared/has_n_through_spec.rb +139 -0
  25. data/spec/spec_helper.rb +12 -9
  26. data/spec/unit/accepts_nested_attributes_for_spec.rb +39 -118
  27. data/tasks/changelog.rb +18 -0
  28. data/tasks/spec.rb +0 -1
  29. metadata +19 -14
  30. data/lib/dm-accepts_nested_attributes/association_proxies.rb +0 -55
  31. data/lib/dm-accepts_nested_attributes/association_validation.rb +0 -49
  32. data/lib/dm-accepts_nested_attributes/nested_attributes.rb +0 -350
  33. data/spec/unit/resource_spec.rb +0 -174
@@ -1,174 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- describe DataMapper::Resource do
5
-
6
- before(:all) do
7
- DataMapper.auto_migrate!
8
- end
9
-
10
- describe ".reject_new_nested_attributes_proc_for(association_name)" do
11
-
12
- it "should be available" do
13
- Person.respond_to?(:reject_new_nested_attributes_proc_for).should be_true
14
- end
15
-
16
- it "should return the proc that has been stored for the association named association_name" do
17
- guard = lambda { |attributes| true }
18
- Person.accepts_nested_attributes_for :profile, :reject_if => guard
19
- Person.reject_new_nested_attributes_proc_for(:profile).should == guard
20
- end
21
-
22
- it "should return nil if association_name is nil" do
23
- Person.reject_new_nested_attributes_proc_for(nil).should be_nil
24
- end
25
-
26
- it "should return nil if association_name is no valid association" do
27
- Person.reject_new_nested_attributes_proc_for(:foo).should be_nil
28
- end
29
-
30
- end
31
-
32
- describe ".association_for_name(name)" do
33
-
34
- it "should raise when passed no name" do
35
- lambda { Person.association_for_name }.should raise_error(ArgumentError)
36
- end
37
-
38
- it "should raise when passed nil as name" do
39
- lambda { Person.association_for_name(nil) }.should raise_error(ArgumentError)
40
- end
41
-
42
- it "should raise when there is no association named name" do
43
- lambda { Person.association_for_name(:foo) }.should raise_error(ArgumentError)
44
- end
45
-
46
- it "should not raise when there is an association named name" do
47
- lambda { Person.association_for_name(:profile) }.should_not raise_error
48
- end
49
-
50
- it "should return an instance of DataMapper::Associations::Relationship when there is an association named name" do
51
- Person.association_for_name(:profile).is_a?(DataMapper::Associations::Relationship).should be_true
52
- end
53
-
54
- end
55
-
56
- describe ".associated_model_for_name(association_name)" do
57
-
58
- it "should raise when passed no association_name" do
59
- lambda { Person.associated_model_for_name }.should raise_error(ArgumentError)
60
- end
61
-
62
- it "should raise when passed nil as association_name" do
63
- lambda { Person.associated_model_for_name(nil) }.should raise_error(ArgumentError)
64
- end
65
-
66
- it "should raise when there is no association named association_name" do
67
- lambda { Person.associated_model_for_name(:foo) }.should raise_error(ArgumentError)
68
- end
69
-
70
- it "should not raise when there is an association named association_name" do
71
- lambda { Person.associated_model_for_name(:profile) }.should_not raise_error
72
- end
73
-
74
- describe "and association_name points to a has(1) association" do
75
-
76
- it "should return the class of the associated model when the association named association_name is present" do
77
- Person.associated_model_for_name(:profile).should == Profile
78
- end
79
-
80
- end
81
-
82
- describe "and association_name points to a has(n) association" do
83
-
84
- it "should return the class of the associated model when the association named association_name is present" do
85
- Person.associated_model_for_name(:project_memberships).should == ProjectMembership
86
- end
87
-
88
- end
89
-
90
- describe "and association_name points to a has(n, :through) association" do
91
-
92
- it "should return the class of the associated model when the association named association_name is present" do
93
- Person.associated_model_for_name(:projects).should == Project
94
- end
95
-
96
- end
97
-
98
- describe "and association_name points to a belongs_to association" do
99
-
100
- it "should return the class of the associated model when the association named association_name is present" do
101
- Profile.associated_model_for_name(:person).should == Person
102
- end
103
-
104
- end
105
-
106
- end
107
-
108
- describe ".nr_of_possible_child_instances(assocation_name)" do
109
-
110
- it "should raise when passed no association_name" do
111
- lambda { Person.nr_of_possible_child_instances }.should raise_error(ArgumentError)
112
- end
113
-
114
- it "should raise when passed nil as association_name" do
115
- lambda { Person.nr_of_possible_child_instances(nil) }.should raise_error(ArgumentError)
116
- end
117
-
118
- it "should raise when there is no association named association_name" do
119
- lambda { Person.nr_of_possible_child_instances(:foo) }.should raise_error(ArgumentError)
120
- end
121
-
122
- it "should not raise when there is an association named association_name" do
123
- lambda { Person.nr_of_possible_child_instances(:profile) }.should_not raise_error
124
- end
125
-
126
- it "should return 1 for a belongs_to relation" do
127
- Profile.nr_of_possible_child_instances(:person).should == 1
128
- end
129
-
130
- it "should return 1 for a has(1) relation" do
131
- Person.nr_of_possible_child_instances(:profile).should == 1
132
- end
133
-
134
- it "should return Infinity for a has(n) relation" do
135
- Person.nr_of_possible_child_instances(:project_memberships).should == Person.n
136
- end
137
-
138
- it "should return Infinity for a has(n, :through) relation" do
139
- Person.nr_of_possible_child_instances(:projects).should == Person.n
140
- end
141
-
142
- end
143
-
144
- describe "#associated_instance_get(association_name)" do
145
-
146
- before(:each) do
147
- @person = Person.create(:name => 'snusnu')
148
- @person.profile = Profile.new
149
- @person.save
150
- end
151
-
152
- it "should raise when passed no association_name" do
153
- lambda { @person.associated_instance_get }.should raise_error
154
- end
155
-
156
- it "should raise when passed nil as association_name" do
157
- lambda { @person.associated_instance_get(nil) }.should raise_error
158
- end
159
-
160
- it "should raise when there is no association named association_name" do
161
- lambda { @person.associated_instance_get(:foo) }.should raise_error
162
- end
163
-
164
- it "should return an object that has the same class like the associated resource" do
165
- @person.associated_instance_get(:profile).class.should == Profile
166
- end
167
-
168
- it "should return the associated object when there is an association named association_name" do
169
- @person.associated_instance_get(:profile).should == @person.profile
170
- end
171
-
172
- end
173
-
174
- end