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,130 @@
1
+ describe "every accessible one_to_one association", :shared => true do
2
+
3
+ it "should allow to update an existing profile via Person#profile_attributes" do
4
+ person = Person.create :name => 'Martin'
5
+ profile = Profile.create(:person => person, :nick => 'snusnu')
6
+ person.reload
7
+
8
+ Person.all.size.should == 1
9
+ Profile.all.size.should == 1
10
+
11
+ person.profile_attributes = { :id => profile.id, :nick => 'still snusnu somehow' }
12
+ person.save.should be_true
13
+
14
+ Person.all.size.should == 1
15
+ Profile.all.size.should == 1
16
+ Profile.first.nick.should == 'still snusnu somehow'
17
+ end
18
+
19
+ it "should return the attributes written to Person#profile_attributes from the Person#profile_attributes reader" do
20
+ person = Person.new :name => 'Martin'
21
+ person.profile_attributes.should be_nil
22
+ person.profile_attributes = { :nick => 'snusnu' }
23
+ person.profile_attributes.should == { :nick => 'snusnu' }
24
+ end
25
+
26
+ end
27
+
28
+ describe "every accessible one_to_one association with a valid reject_if proc", :shared => true do
29
+
30
+ it "should not allow to create a new profile via Person#profile_attributes" do
31
+ Person.all.size.should == 0
32
+ Profile.all.size.should == 0
33
+
34
+ person = Person.new :name => 'Martin'
35
+ person.profile_attributes = { :nick => 'snusnu' }
36
+ person.save
37
+
38
+ Person.all.size.should == 1
39
+ Profile.all.size.should == 0
40
+ end
41
+
42
+ end
43
+
44
+ describe "every accessible one_to_one association with no reject_if proc", :shared => true do
45
+
46
+ it "should allow to create a new profile via Person#profile_attributes" do
47
+ Person.all.size.should == 0
48
+ Profile.all.size.should == 0
49
+
50
+ person = Person.new :name => 'Martin'
51
+ person.profile_attributes = { :nick => 'snusnu' }
52
+
53
+ Person.all.size.should == 0
54
+ Profile.all.size.should == 0
55
+
56
+ person.save.should be_true
57
+
58
+ Person.all.size.should == 1
59
+ Profile.all.size.should == 1
60
+ Profile.first.nick.should == 'snusnu'
61
+ end
62
+
63
+ it "should perform atomic commits" do
64
+
65
+ # related resource is invalid
66
+ person = Person.new :name => 'Martin'
67
+ person.profile_attributes = { :nick => nil } # will fail because of validations
68
+ person.save.should be_false
69
+
70
+ Person.all.size.should == 0
71
+ Profile.all.size.should == 0
72
+
73
+ # self is invalid
74
+ person.name = nil # will fail because of validations
75
+ person.profile_attributes = { :nick => 'snusnu' }
76
+ person.save.should be_false
77
+
78
+ Person.all.size.should == 0
79
+ Profile.all.size.should == 0
80
+ end
81
+
82
+ end
83
+
84
+ describe "every accessible one_to_one association with :allow_destroy => false", :shared => true do
85
+
86
+ it "should not allow to delete an existing profile via Person#profile_attributes" do
87
+ person = Person.create :name => 'Martin'
88
+
89
+ profile = Profile.create(:person => person, :nick => 'snusnu')
90
+ person.reload
91
+
92
+ Person.all.size.should == 1
93
+ Profile.all.size.should == 1
94
+
95
+ person.profile_attributes = { :id => profile.id, :_delete => true }
96
+
97
+ Person.all.size.should == 1
98
+ Profile.all.size.should == 1
99
+
100
+ person.save
101
+
102
+ Person.all.size.should == 1
103
+ Profile.all.size.should == 1
104
+ end
105
+
106
+ end
107
+
108
+ describe "every accessible one_to_one association with :allow_destroy => true", :shared => true do
109
+
110
+ it "should allow to delete an existing profile via Person#profile_attributes" do
111
+ person = Person.create :name => 'Martin'
112
+
113
+ profile = Profile.create(:person => person, :nick => 'snusnu')
114
+ person.profile = profile
115
+
116
+ Person.all.size.should == 1
117
+ Profile.all.size.should == 1
118
+
119
+ person.profile_attributes = { :id => profile.id, :_delete => true }
120
+
121
+ Person.all.size.should == 1
122
+ Profile.all.size.should == 1
123
+
124
+ person.save
125
+
126
+ Person.all.size.should == 1
127
+ Profile.all.size.should == 0
128
+ end
129
+
130
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --loadby random
3
+ --format profile
4
+ --backtrace
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'pathname'
3
+ require 'spec'
4
+
5
+ # require the plugin
6
+ require 'dm-accepts_nested_attributes'
7
+
8
+ # allow testing with dm-validations enabled
9
+ # must be required after the plugin, since
10
+ # dm-validations seems to need dm-core
11
+ require 'dm-validations'
12
+ require 'dm-constraints'
13
+
14
+ ENV["SQLITE3_SPEC_URI"] ||= 'sqlite3::memory:'
15
+ ENV["MYSQL_SPEC_URI"] ||= 'mysql://localhost/dm-accepts_nested_attributes_test'
16
+ ENV["POSTGRES_SPEC_URI"] ||= 'postgres://postgres@localhost/dm-accepts_nested_attributes_test'
17
+
18
+
19
+ def setup_adapter(name, default_uri = nil)
20
+ begin
21
+ DataMapper.setup(name, ENV["#{ENV['ADAPTER'].to_s.upcase}_SPEC_URI"] || default_uri)
22
+ Object.const_set('ADAPTER', ENV['ADAPTER'].to_sym) if name.to_s == ENV['ADAPTER']
23
+ true
24
+ rescue Exception => e
25
+ if name.to_s == ENV['ADAPTER']
26
+ Object.const_set('ADAPTER', nil)
27
+ warn "Could not load do_#{name}: #{e}"
28
+ end
29
+ false
30
+ end
31
+ end
32
+
33
+ ENV['ADAPTER'] ||= 'mysql'
34
+ setup_adapter(:default)
35
+
36
+
37
+ require 'shared/many_to_many_spec'
38
+ require 'shared/many_to_one_spec'
39
+ require 'shared/one_to_many_spec'
40
+ require 'shared/one_to_one_spec'
41
+
42
+
43
+ module ConstraintSupport
44
+
45
+ def constraint(type)
46
+ if DataMapper.const_defined?('Constraints')
47
+ { :constraint => type }
48
+ else
49
+ {}
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,20 @@
1
+ require 'time'
2
+
3
+ desc 'update changelog'
4
+ task :changelog do
5
+ File.open('CHANGELOG', 'w+') do |changelog|
6
+ `git log -z --abbrev-commit`.split("\0").each do |commit|
7
+ next if commit =~ /^Merge: \d*/
8
+ ref, author, time, _, title, _, message = commit.split("\n", 7)
9
+ ref = ref[/commit ([0-9a-f]+)/, 1]
10
+ author = author[/Author: (.*)/, 1].strip
11
+ time = Time.parse(time[/Date: (.*)/, 1]).utc
12
+ title.strip!
13
+
14
+ changelog.puts "[#{ref} | #{time}] #{author}"
15
+ changelog.puts '', " * #{title}"
16
+ changelog.puts '', message.rstrip if message
17
+ changelog.puts
18
+ end
19
+ end
20
+ end
data/tasks/ci.rake ADDED
@@ -0,0 +1 @@
1
+ task :ci => [ :verify_measurements, 'metrics:all' ]
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'metric_fu'
3
+ rescue LoadError
4
+ namespace :metrics do
5
+ task :all do
6
+ abort 'metric_fu is not available. In order to run metrics:all, you must: gem install metric_fu'
7
+ end
8
+ end
9
+ end
10
+
11
+ begin
12
+ require 'reek/adapters/rake_task'
13
+
14
+ Reek::RakeTask.new do |t|
15
+ t.fail_on_error = true
16
+ t.verbose = false
17
+ t.source_files = 'lib/**/*.rb'
18
+ end
19
+ rescue LoadError
20
+ task :reek do
21
+ abort 'Reek is not available. In order to run reek, you must: gem install reek'
22
+ end
23
+ end
24
+
25
+ begin
26
+ require 'roodi'
27
+ require 'roodi_task'
28
+
29
+ RoodiTask.new do |t|
30
+ t.verbose = false
31
+ end
32
+ rescue LoadError
33
+ task :roodi do
34
+ abort 'Roodi is not available. In order to run roodi, you must: gem install roodi'
35
+ end
36
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,25 @@
1
+ require 'spec/rake/spectask'
2
+ require 'spec/rake/verify_rcov'
3
+
4
+ spec_defaults = lambda do |spec|
5
+ spec.pattern = 'spec/**/*_spec.rb'
6
+ spec.libs << 'lib' << 'spec'
7
+ spec.spec_opts << '--options' << 'spec/spec.opts'
8
+ end
9
+
10
+ Spec::Rake::SpecTask.new(:spec, &spec_defaults)
11
+
12
+ Spec::Rake::SpecTask.new(:rcov) do |rcov|
13
+ spec_defaults.call(rcov)
14
+ rcov.rcov = true
15
+ rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
16
+ end
17
+
18
+ RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
19
+ rcov.threshold = 100
20
+ end
21
+
22
+ task :spec => :check_dependencies
23
+ task :rcov => :check_dependencies
24
+
25
+ task :default => :spec
data/tasks/yard.rake ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'yard'
3
+
4
+ YARD::Rake::YardocTask.new
5
+ rescue LoadError
6
+ task :yard do
7
+ abort 'YARD is not available. In order to run yard, you must: gem install yard'
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'pathname'
3
+ require 'yardstick/rake/measurement'
4
+ require 'yardstick/rake/verify'
5
+
6
+ # yardstick_measure task
7
+ Yardstick::Rake::Measurement.new
8
+
9
+ # verify_measurements task
10
+ Yardstick::Rake::Verify.new do |verify|
11
+ verify.threshold = 100
12
+ end
13
+ rescue LoadError
14
+ %w[ yardstick_measure verify_measurements ].each do |name|
15
+ task name.to_s do
16
+ abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-accepts_nested_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.12.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Gamsjaeger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-23 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dm-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.10.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: yard
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.4.0
44
+ version:
45
+ description: A datamapper plugin that allows nested model assignment like activerecord.
46
+ email: gamsnjaga [a] gmail [d] com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.textile
54
+ - TODO
55
+ files:
56
+ - .gitignore
57
+ - CHANGELOG
58
+ - LICENSE
59
+ - README.textile
60
+ - Rakefile
61
+ - TODO
62
+ - dm-accepts_nested_attributes.gemspec
63
+ - lib/dm-accepts_nested_attributes.rb
64
+ - lib/dm-accepts_nested_attributes/error_collecting.rb
65
+ - lib/dm-accepts_nested_attributes/model.rb
66
+ - lib/dm-accepts_nested_attributes/resource.rb
67
+ - lib/dm-accepts_nested_attributes/transactional_save.rb
68
+ - lib/dm-accepts_nested_attributes/version.rb
69
+ - spec/accepts_nested_attributes_for_spec.rb
70
+ - spec/many_to_many_spec.rb
71
+ - spec/many_to_one_spec.rb
72
+ - spec/one_to_many_spec.rb
73
+ - spec/one_to_one_spec.rb
74
+ - spec/rcov.opts
75
+ - spec/shared/many_to_many_spec.rb
76
+ - spec/shared/many_to_one_spec.rb
77
+ - spec/shared/one_to_many_spec.rb
78
+ - spec/shared/one_to_one_spec.rb
79
+ - spec/spec.opts
80
+ - spec/spec_helper.rb
81
+ - tasks/changelog.rake
82
+ - tasks/ci.rake
83
+ - tasks/metrics.rake
84
+ - tasks/spec.rake
85
+ - tasks/yard.rake
86
+ - tasks/yardstick.rake
87
+ has_rdoc: true
88
+ homepage: http://github.com/snusnu/dm-accepts_nested_attributes
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --charset=UTF-8
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.5
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Nested model assignment for datamapper
115
+ test_files:
116
+ - spec/accepts_nested_attributes_for_spec.rb
117
+ - spec/many_to_many_spec.rb
118
+ - spec/many_to_one_spec.rb
119
+ - spec/one_to_many_spec.rb
120
+ - spec/one_to_one_spec.rb
121
+ - spec/shared/many_to_many_spec.rb
122
+ - spec/shared/many_to_one_spec.rb
123
+ - spec/shared/one_to_many_spec.rb
124
+ - spec/shared/one_to_one_spec.rb
125
+ - spec/spec_helper.rb