snusnu-dm-accepts_nested_attributes 0.0.2 → 0.0.3

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.
data/spec/spec_helper.rb CHANGED
@@ -3,12 +3,9 @@ require 'rubygems'
3
3
 
4
4
  gem 'rspec', '>=1.1.12'
5
5
  require 'spec'
6
-
7
- gem 'dm-core', '0.9.11'
8
- require 'dm-core'
9
-
10
- gem 'dm-validations', '0.9.11'
11
- require 'dm-validations'
6
+
7
+ gem 'dm-association_validator', '>=0.0.1'
8
+ require 'dm-association_validator'
12
9
 
13
10
  require Pathname(__FILE__).dirname.parent.expand_path + 'lib/dm-accepts_nested_attributes'
14
11
 
@@ -54,3 +51,32 @@ end
54
51
  ENV['ADAPTER'] ||= 'sqlite3'
55
52
  setup_adapter(:default)
56
53
  Dir[Pathname(__FILE__).dirname.to_s + "/fixtures/**/*.rb"].each { |rb| require(rb) }
54
+
55
+
56
+ module XToOneHelpers
57
+
58
+ def clear_data
59
+ Profile.all.destroy!
60
+ Person.all.destroy!
61
+ end
62
+
63
+ end
64
+
65
+ module OneToManyHelpers
66
+
67
+ def clear_data
68
+ Task.all.destroy!
69
+ Project.all.destroy!
70
+ end
71
+
72
+ end
73
+
74
+ module ManyToManyHelpers
75
+
76
+ def clear_data
77
+ ProjectMembership.all.destroy!
78
+ Project.all.destroy!
79
+ Person.all.destroy!
80
+ end
81
+
82
+ end
@@ -3,16 +3,7 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
3
 
4
4
  describe "DataMapper::Model.accepts_nested_attributes_for" do
5
5
 
6
- before(:each) do
7
-
8
- # don't use the originally defined fixtures but provide new ones,
9
- # this time without already calling accepts_nested_attributes_for on them.
10
- # this helps speccing the exact behavior of this very method call
11
-
12
- Object.send(:remove_const, 'Branch') if Object.const_defined?('Branch')
13
- Object.send(:remove_const, 'Shop') if Object.const_defined?('Shop')
14
- Object.send(:remove_const, 'Item') if Object.const_defined?('Item')
15
- Object.send(:remove_const, 'Booking') if Object.const_defined?('Booking')
6
+ FIXTURES = <<-RUBY
16
7
 
17
8
  class Branch
18
9
  include DataMapper::Resource
@@ -21,14 +12,14 @@ describe "DataMapper::Model.accepts_nested_attributes_for" do
21
12
  has n, :items
22
13
  has n, :bookings, :through => :items
23
14
  end
24
-
15
+
25
16
  class Shop
26
17
  include DataMapper::Resource
27
18
  property :id, Serial
28
19
  property :branch_id, Integer
29
20
  belongs_to :branch
30
21
  end
31
-
22
+
32
23
  class Item
33
24
  include DataMapper::Resource
34
25
  property :id, Serial
@@ -36,15 +27,29 @@ describe "DataMapper::Model.accepts_nested_attributes_for" do
36
27
  belongs_to :branch
37
28
  has n, :bookings
38
29
  end
39
-
30
+
40
31
  class Booking
41
32
  include DataMapper::Resource
42
33
  property :id, Serial
43
34
  property :item_id, Integer
44
35
  belongs_to :item
45
36
  end
46
-
37
+
38
+ RUBY
39
+
40
+ before(:all) do
41
+ eval FIXTURES
47
42
  DataMapper.auto_migrate!
43
+ end
44
+
45
+ before(:each) do
46
+
47
+ Object.send(:remove_const, 'Branch') if Object.const_defined?('Branch')
48
+ Object.send(:remove_const, 'Shop') if Object.const_defined?('Shop')
49
+ Object.send(:remove_const, 'Item') if Object.const_defined?('Item')
50
+ Object.send(:remove_const, 'Booking') if Object.const_defined?('Booking')
51
+
52
+ eval FIXTURES # neither class_eval nor instance_eval work here
48
53
 
49
54
  end
50
55
 
@@ -143,7 +143,7 @@ describe DataMapper::Resource do
143
143
 
144
144
  describe "#associated_instance_get(association_name)" do
145
145
 
146
- before do
146
+ before(:each) do
147
147
  @person = Person.create(:name => 'snusnu')
148
148
  @person.profile = Profile.new
149
149
  @person.save
data/tasks/gemspec.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  desc "Generate gemspec"
2
2
  task :gemspec do |x|
3
3
 
4
- # # Clean up extraneous files before checking manifest
5
- # %x[rake clean]
6
-
7
4
  %x[rake debug_gem > #{GEM_NAME}.gemspec]
8
5
  puts "Successfully created gemspec for #{GEM_NAME}!"
9
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snusnu-dm-accepts_nested_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Martin Gamsj\xC3\xA4ger"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-15 00:00:00 -07:00
12
+ date: 2009-04-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,21 +51,18 @@ files:
51
51
  - Rakefile
52
52
  - TODO
53
53
  - lib/dm-accepts_nested_attributes.rb
54
- - lib/dm-accepts_nested_attributes/associations.rb
54
+ - lib/dm-accepts_nested_attributes/association_proxies.rb
55
+ - lib/dm-accepts_nested_attributes/association_validation.rb
55
56
  - lib/dm-accepts_nested_attributes/nested_attributes.rb
56
57
  - lib/dm-accepts_nested_attributes/version.rb
57
58
  - spec/fixtures/person.rb
58
- - spec/fixtures/photo.rb
59
59
  - spec/fixtures/profile.rb
60
60
  - spec/fixtures/project.rb
61
61
  - spec/fixtures/project_membership.rb
62
- - spec/fixtures/tag.rb
63
- - spec/fixtures/tagging.rb
64
62
  - spec/fixtures/task.rb
65
63
  - spec/integration/belongs_to_spec.rb
66
64
  - spec/integration/has_1_spec.rb
67
65
  - spec/integration/has_n_spec.rb
68
- - spec/integration/has_n_through_renamed_spec.rb
69
66
  - spec/integration/has_n_through_spec.rb
70
67
  - spec/shared/rspec_tmbundle_support.rb
71
68
  - spec/spec.opts
@@ -1,9 +0,0 @@
1
- class Photo
2
- include DataMapper::Resource
3
-
4
- property :id, Serial
5
- property :name, String
6
-
7
- has n, :tagged_things, :class_name => "Tagging"
8
- has n, :tags, :through => :tagged_things
9
- end
data/spec/fixtures/tag.rb DELETED
@@ -1,12 +0,0 @@
1
- class Tag
2
- include DataMapper::Resource
3
-
4
- property :id, Serial
5
- property :name, String
6
-
7
- has n, :tagged_things, :class_name => "Tagging"
8
- has n, :pictures, :through => :tagged_things,
9
- :class_name => 'Photo',
10
- :child_key => [:tag_id],
11
- :remote_name => :photo
12
- end
@@ -1,10 +0,0 @@
1
- class Tagging
2
- include DataMapper::Resource
3
-
4
- property :id, Serial
5
- property :tag_id, Integer
6
- property :photo_id, Integer
7
-
8
- belongs_to :tag
9
- belongs_to :photo
10
- end
@@ -1,214 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- # TODO: this is overkill - really should use some more focussed unit tests instead
5
- describe DataMapper::NestedAttributes do
6
-
7
- describe "every accessible has(n, :through) renamed association with a valid reject_if proc", :shared => true do
8
-
9
- it "should not allow to create a new picture via Tag#pictures_attributes" do
10
- @tag.save
11
- Tag.all.size.should == 1
12
- Tagging.all.size.should == 0
13
- Photo.all.size.should == 0
14
-
15
- @tag.pictures_attributes = { 'new_1' => { :name => 'dm-accepts_nested_attributes' } }
16
- @tag.pictures.should be_empty
17
- @tag.save
18
-
19
- Tag.all.size.should == 1
20
- Tagging.all.size.should == 0
21
- Photo.all.size.should == 0
22
- end
23
-
24
- end
25
-
26
- describe "every accessible has(n, :through) renamed association with no reject_if proc", :shared => true do
27
-
28
- it "should allow to create a new picture via Tag#pictures_attributes" do
29
- @tag.save
30
- Tag.all.size.should == 1
31
- Tagging.all.size.should == 0
32
- Photo.all.size.should == 0
33
-
34
- @tag.pictures_attributes = { 'new_1' => { :name => 'dm-accepts_nested_attributes' } }
35
- @tag.pictures.should_not be_empty
36
- @tag.pictures.first.name.should == 'dm-accepts_nested_attributes'
37
- @tag.save
38
- @tag.pictures.first.should == Photo.first
39
-
40
- Tag.all.size.should == 1
41
- Tagging.all.size.should == 1
42
- Photo.all.size.should == 1
43
-
44
- Photo.first.name.should == 'dm-accepts_nested_attributes'
45
- end
46
-
47
- it "should allow to update an existing picture via Tag#pictures_attributes" do
48
- @tag.save
49
- photo = Photo.create(:name => 'dm-accepts_nested_attributes')
50
- tagging = Tagging.create(:tag => @tag, :photo => photo)
51
- Tag.all.size.should == 1
52
- Photo.all.size.should == 1
53
- Tagging.all.size.should == 1
54
-
55
- @tag.reload
56
-
57
- @tag.pictures_attributes = { photo.id.to_s => { :id => photo.id, :name => 'still dm-accepts_nested_attributes' } }
58
- @tag.pictures.should_not be_empty
59
- @tag.pictures.first.name.should == 'still dm-accepts_nested_attributes'
60
- @tag.save
61
-
62
- Tag.all.size.should == 1
63
- Tagging.all.size.should == 1
64
- Photo.all.size.should == 1
65
-
66
- Photo.first.name.should == 'still dm-accepts_nested_attributes'
67
- end
68
-
69
- end
70
-
71
- describe "every accessible has(n, :through) renamed association with :allow_destroy => false", :shared => true do
72
-
73
- it "should not allow to delete an existing picture via Tag#pictures_attributes" do
74
- @tag.save
75
- photo = Photo.create(:name => 'dm-accepts_nested_attributes')
76
- tagging = Tagging.create(:tag => @tag, :photo => photo)
77
-
78
- Tag.all.size.should == 1
79
- Tagging.all.size.should == 1
80
- Photo.all.size.should == 1
81
-
82
- @tag.reload
83
- @tag.pictures_attributes = { '1' => { :id => photo.id, :_delete => true } }
84
- @tag.save
85
-
86
- Tag.all.size.should == 1
87
- Tagging.all.size.should == 1
88
- Photo.all.size.should == 1
89
- end
90
-
91
- end
92
-
93
- describe "every accessible has(n, :through) renamed association with :allow_destroy => true", :shared => true do
94
-
95
- it "should allow to delete an existing picture via Tag#pictures_attributes" do
96
- @tag.save
97
- photo = Photo.create(:name => 'dm-accepts_nested_attributes')
98
- tagging = Tagging.create(:tag => @tag, :photo => photo)
99
-
100
- Tag.all.size.should == 1
101
- Tagging.all.size.should == 1
102
- Photo.all.size.should == 1
103
-
104
- @tag.reload
105
- @tag.pictures_attributes = { '1' => { :id => photo.id, :_delete => true } }
106
- @tag.save
107
-
108
- Tag.all.size.should == 1
109
- Tagging.all.size.should == 0
110
- Photo.all.size.should == 0
111
- end
112
-
113
- end
114
-
115
- describe "every accessible has(n, :through) renamed association with a nested attributes reader", :shared => true do
116
-
117
- it "should return the attributes written to Tag#pictures_attributes from the Tag#pictures_attributes reader" do
118
- @tag.pictures_attributes.should be_nil
119
-
120
- @tag.pictures_attributes = { 'new_1' => { :name => 'write specs' } }
121
-
122
- @tag.pictures_attributes.should == { 'new_1' => { :name => 'write specs' } }
123
- end
124
-
125
- end
126
-
127
- describe "Tag.has(n, :pictures, :through => :taggings) renamed" do
128
-
129
- describe "accepts_nested_attributes_for(:pictures)" do
130
-
131
- before(:each) do
132
- DataMapper.auto_migrate!
133
- Tag.accepts_nested_attributes_for :pictures
134
- @tag = Tag.new :name => 'snusnu'
135
- end
136
-
137
- it_should_behave_like "every accessible has(n, :through) renamed association with no reject_if proc"
138
- it_should_behave_like "every accessible has(n, :through) renamed association with :allow_destroy => false"
139
- it_should_behave_like "every accessible has(n, :through) renamed association with a nested attributes reader"
140
-
141
- end
142
-
143
- describe "accepts_nested_attributes_for(:pictures, :allow_destroy => false)" do
144
-
145
- before(:each) do
146
- DataMapper.auto_migrate!
147
- Tag.accepts_nested_attributes_for :pictures, :allow_destroy => false
148
- @tag = Tag.new :name => 'snusnu'
149
- end
150
-
151
- it_should_behave_like "every accessible has(n, :through) renamed association with no reject_if proc"
152
- it_should_behave_like "every accessible has(n, :through) renamed association with :allow_destroy => false"
153
-
154
- end
155
-
156
- describe "accepts_nested_attributes_for(:pictures, :allow_destroy = true)" do
157
-
158
- before(:each) do
159
- DataMapper.auto_migrate!
160
- Tag.accepts_nested_attributes_for :pictures, :allow_destroy => true
161
- @tag = Tag.new :name => 'snusnu'
162
- end
163
-
164
- it_should_behave_like "every accessible has(n, :through) renamed association with no reject_if proc"
165
- it_should_behave_like "every accessible has(n, :through) renamed association with :allow_destroy => true"
166
-
167
- end
168
-
169
- describe "accepts_nested_attributes_for :pictures, " do
170
-
171
- describe ":reject_if => :foo" do
172
-
173
- before(:each) do
174
- DataMapper.auto_migrate!
175
- Tag.accepts_nested_attributes_for :pictures, :reject_if => :foo
176
- @tag = Tag.new :name => 'snusnu'
177
- end
178
-
179
- it_should_behave_like "every accessible has(n, :through) renamed association with no reject_if proc"
180
- it_should_behave_like "every accessible has(n, :through) renamed association with :allow_destroy => false"
181
-
182
- end
183
-
184
- describe ":reject_if => lambda { |attrs| true }" do
185
-
186
- before(:each) do
187
- DataMapper.auto_migrate!
188
- Tag.accepts_nested_attributes_for :pictures, :reject_if => lambda { |attrs| true }
189
- @tag = Tag.new :name => 'snusnu'
190
- end
191
-
192
- it_should_behave_like "every accessible has(n, :through) renamed association with a valid reject_if proc"
193
- it_should_behave_like "every accessible has(n, :through) renamed association with :allow_destroy => false"
194
-
195
- end
196
-
197
- describe ":reject_if => lambda { |attrs| false }" do
198
-
199
- before(:each) do
200
- DataMapper.auto_migrate!
201
- Tag.accepts_nested_attributes_for :pictures, :reject_if => lambda { |attrs| false }
202
- @tag = Tag.new :name => 'snusnu'
203
- end
204
-
205
- it_should_behave_like "every accessible has(n, :through) renamed association with no reject_if proc"
206
- it_should_behave_like "every accessible has(n, :through) renamed association with :allow_destroy => false"
207
-
208
- end
209
-
210
- end
211
-
212
- end
213
-
214
- end