snusnu-dm-accepts_nested_attributes 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +23 -0
- data/History.txt +1 -0
- data/LICENSE +20 -0
- data/Manifest.txt +29 -0
- data/README.textile +250 -0
- data/Rakefile +32 -0
- data/TODO +3 -0
- data/lib/dm-accepts_nested_attributes.rb +18 -0
- data/lib/dm-accepts_nested_attributes/associations.rb +55 -0
- data/lib/dm-accepts_nested_attributes/nested_attributes.rb +300 -0
- data/lib/dm-accepts_nested_attributes/version.rb +7 -0
- data/spec/fixtures/person.rb +8 -0
- data/spec/fixtures/profile.rb +7 -0
- data/spec/fixtures/project.rb +8 -0
- data/spec/fixtures/project_membership.rb +8 -0
- data/spec/fixtures/task.rb +7 -0
- data/spec/integration/belongs_to_spec.rb +204 -0
- data/spec/integration/has_1_spec.rb +193 -0
- data/spec/integration/has_n_spec.rb +181 -0
- data/spec/integration/has_n_through_spec.rb +200 -0
- data/spec/shared/rspec_tmbundle_support.rb +35 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/unit/accepts_nested_attributes_for_spec.rb +454 -0
- data/spec/unit/resource_spec.rb +174 -0
- data/tasks/gemspec.rb +10 -0
- data/tasks/hoe.rb +46 -0
- data/tasks/install.rb +15 -0
- data/tasks/spec.rb +25 -0
- metadata +103 -0
@@ -0,0 +1,174 @@
|
|
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 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
|
data/tasks/gemspec.rb
ADDED
data/tasks/hoe.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
|
3
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
4
|
+
@config = nil
|
5
|
+
RUBYFORGE_USERNAME = "unknown"
|
6
|
+
def rubyforge_username
|
7
|
+
unless @config
|
8
|
+
begin
|
9
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
10
|
+
rescue
|
11
|
+
puts <<-EOS
|
12
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
13
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
14
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
15
|
+
EOS
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Remove hoe dependency
|
23
|
+
class Hoe
|
24
|
+
def extra_dev_deps
|
25
|
+
@extra_dev_deps.reject! { |dep| dep[0] == "hoe" }
|
26
|
+
@extra_dev_deps
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
hoe = Hoe.new(GEM_NAME, GEM_VERSION) do |p|
|
31
|
+
|
32
|
+
p.developer(AUTHOR, EMAIL)
|
33
|
+
|
34
|
+
p.description = PROJECT_DESCRIPTION
|
35
|
+
p.summary = PROJECT_SUMMARY
|
36
|
+
p.url = PROJECT_URL
|
37
|
+
|
38
|
+
p.rubyforge_name = PROJECT_NAME if PROJECT_NAME
|
39
|
+
|
40
|
+
p.clean_globs |= %w[ {coverage,doc,log,tmp} **/*.{log,db} profile_results.* **/.DS_Store spec/db ]
|
41
|
+
|
42
|
+
GEM_DEPENDENCIES.each do |dep|
|
43
|
+
p.extra_deps << dep
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/tasks/install.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
def sudo_gem(cmd)
|
2
|
+
sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
|
3
|
+
end
|
4
|
+
|
5
|
+
if WINDOWS
|
6
|
+
desc "Install #{GEM_NAME}"
|
7
|
+
task :install => :gem do
|
8
|
+
sudo_gem "install --no-rdoc --no-ri --local pkg/#{GEM_NAME}-#{GEM_VERSION}.gem"
|
9
|
+
end
|
10
|
+
else
|
11
|
+
desc "Install #{GEM_NAME}"
|
12
|
+
task :install => :package do
|
13
|
+
sudo_gem "install --no-rdoc --no-ri --local pkg/#{GEM_NAME}-#{GEM_VERSION}.gem"
|
14
|
+
end
|
15
|
+
end
|
data/tasks/spec.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
begin
|
2
|
+
gem 'rspec', '>=1.1.12'
|
3
|
+
require 'spec'
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
task :default => [ :spec ]
|
7
|
+
|
8
|
+
desc 'Run specifications'
|
9
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
10
|
+
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
11
|
+
t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
|
12
|
+
|
13
|
+
begin
|
14
|
+
gem 'rcov', '~>0.8'
|
15
|
+
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
16
|
+
t.rcov_opts << '--exclude' << 'spec'
|
17
|
+
t.rcov_opts << '--text-summary'
|
18
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
19
|
+
rescue LoadError
|
20
|
+
# rcov not installed
|
21
|
+
end
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
# rspec not installed
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snusnu-dm-accepts_nested_attributes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Martin Gamsj\xC3\xA4ger"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-13 00:00:00 -07: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.9.11
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: addressable
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.2
|
34
|
+
version:
|
35
|
+
description: A DataMapper plugin that adds the possibility to perform nested model attribute assignment
|
36
|
+
email:
|
37
|
+
- gamsnjaga [a] gmail [d] com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- History.txt
|
48
|
+
- LICENSE
|
49
|
+
- Manifest.txt
|
50
|
+
- README.textile
|
51
|
+
- Rakefile
|
52
|
+
- TODO
|
53
|
+
- lib/dm-accepts_nested_attributes.rb
|
54
|
+
- lib/dm-accepts_nested_attributes/associations.rb
|
55
|
+
- lib/dm-accepts_nested_attributes/nested_attributes.rb
|
56
|
+
- lib/dm-accepts_nested_attributes/version.rb
|
57
|
+
- spec/fixtures/person.rb
|
58
|
+
- spec/fixtures/profile.rb
|
59
|
+
- spec/fixtures/project.rb
|
60
|
+
- spec/fixtures/project_membership.rb
|
61
|
+
- spec/fixtures/task.rb
|
62
|
+
- spec/integration/belongs_to_spec.rb
|
63
|
+
- spec/integration/has_1_spec.rb
|
64
|
+
- spec/integration/has_n_spec.rb
|
65
|
+
- spec/integration/has_n_through_spec.rb
|
66
|
+
- spec/shared/rspec_tmbundle_support.rb
|
67
|
+
- spec/spec.opts
|
68
|
+
- spec/spec_helper.rb
|
69
|
+
- spec/unit/accepts_nested_attributes_for_spec.rb
|
70
|
+
- spec/unit/resource_spec.rb
|
71
|
+
- tasks/gemspec.rb
|
72
|
+
- tasks/hoe.rb
|
73
|
+
- tasks/install.rb
|
74
|
+
- tasks/spec.rb
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://github.com/snusnu/dm-accepts_nested_attributes/tree/master
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options:
|
79
|
+
- --main
|
80
|
+
- README.txt
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project: dm-accepts_nested_attributes
|
98
|
+
rubygems_version: 1.2.0
|
99
|
+
signing_key:
|
100
|
+
specification_version: 2
|
101
|
+
summary: A DataMapper plugin that adds the possibility to perform nested model attribute assignment
|
102
|
+
test_files: []
|
103
|
+
|