datamapper 0.3.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +0 -0
- data/Manifest.txt +5 -0
- data/README.txt +11 -0
- data/Rakefile +70 -0
- data/lib/datamapper.rb +8 -0
- metadata +152 -319
- data/CHANGELOG +0 -145
- data/FAQ +0 -96
- data/MIT-LICENSE +0 -22
- data/QUICKLINKS +0 -12
- data/README +0 -105
- data/environment.rb +0 -62
- data/example.rb +0 -156
- data/lib/data_mapper.rb +0 -88
- data/lib/data_mapper/adapters/abstract_adapter.rb +0 -43
- data/lib/data_mapper/adapters/data_object_adapter.rb +0 -480
- data/lib/data_mapper/adapters/mysql_adapter.rb +0 -72
- data/lib/data_mapper/adapters/postgresql_adapter.rb +0 -258
- data/lib/data_mapper/adapters/sql/coersion.rb +0 -134
- data/lib/data_mapper/adapters/sql/commands/load_command.rb +0 -545
- data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +0 -34
- data/lib/data_mapper/adapters/sql/mappings/column.rb +0 -279
- data/lib/data_mapper/adapters/sql/mappings/conditions.rb +0 -172
- data/lib/data_mapper/adapters/sql/mappings/schema.rb +0 -60
- data/lib/data_mapper/adapters/sql/mappings/table.rb +0 -459
- data/lib/data_mapper/adapters/sql/quoting.rb +0 -24
- data/lib/data_mapper/adapters/sqlite3_adapter.rb +0 -159
- data/lib/data_mapper/associations.rb +0 -106
- data/lib/data_mapper/associations/belongs_to_association.rb +0 -160
- data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +0 -437
- data/lib/data_mapper/associations/has_many_association.rb +0 -283
- data/lib/data_mapper/associations/has_n_association.rb +0 -143
- data/lib/data_mapper/associations/reference.rb +0 -47
- data/lib/data_mapper/attributes.rb +0 -73
- data/lib/data_mapper/auto_migrations.rb +0 -36
- data/lib/data_mapper/base.rb +0 -17
- data/lib/data_mapper/callbacks.rb +0 -107
- data/lib/data_mapper/context.rb +0 -112
- data/lib/data_mapper/database.rb +0 -234
- data/lib/data_mapper/dependency_queue.rb +0 -28
- data/lib/data_mapper/embedded_value.rb +0 -145
- data/lib/data_mapper/identity_map.rb +0 -47
- data/lib/data_mapper/is/tree.rb +0 -121
- data/lib/data_mapper/migration.rb +0 -155
- data/lib/data_mapper/persistence.rb +0 -852
- data/lib/data_mapper/property.rb +0 -310
- data/lib/data_mapper/query.rb +0 -164
- data/lib/data_mapper/support/blank.rb +0 -35
- data/lib/data_mapper/support/connection_pool.rb +0 -117
- data/lib/data_mapper/support/enumerable.rb +0 -35
- data/lib/data_mapper/support/errors.rb +0 -16
- data/lib/data_mapper/support/inflector.rb +0 -265
- data/lib/data_mapper/support/object.rb +0 -54
- data/lib/data_mapper/support/serialization.rb +0 -96
- data/lib/data_mapper/support/silence.rb +0 -10
- data/lib/data_mapper/support/string.rb +0 -72
- data/lib/data_mapper/support/struct.rb +0 -7
- data/lib/data_mapper/support/symbol.rb +0 -82
- data/lib/data_mapper/support/typed_set.rb +0 -65
- data/lib/data_mapper/types/base.rb +0 -44
- data/lib/data_mapper/types/string.rb +0 -34
- data/lib/data_mapper/validatable_extensions/errors.rb +0 -12
- data/lib/data_mapper/validatable_extensions/macros.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validatable_instance_methods.rb +0 -62
- data/lib/data_mapper/validatable_extensions/validation_base.rb +0 -18
- data/lib/data_mapper/validatable_extensions/validations/formats/email.rb +0 -43
- data/lib/data_mapper/validatable_extensions/validations/validates_acceptance_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_confirmation_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_each.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_format_of.rb +0 -28
- data/lib/data_mapper/validatable_extensions/validations/validates_length_of.rb +0 -15
- data/lib/data_mapper/validatable_extensions/validations/validates_numericality_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_presence_of.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_true_for.rb +0 -7
- data/lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb +0 -40
- data/lib/data_mapper/validations.rb +0 -20
- data/lib/data_mapper/validations/number_validator.rb +0 -40
- data/lib/data_mapper/validations/string_validator.rb +0 -20
- data/lib/data_mapper/validations/validator.rb +0 -13
- data/performance.rb +0 -307
- data/plugins/can_has_sphinx/LICENSE +0 -23
- data/plugins/can_has_sphinx/README +0 -4
- data/plugins/can_has_sphinx/REVISION +0 -1
- data/plugins/can_has_sphinx/Rakefile +0 -22
- data/plugins/can_has_sphinx/init.rb +0 -1
- data/plugins/can_has_sphinx/install.rb +0 -1
- data/plugins/can_has_sphinx/lib/acts_as_sphinx.rb +0 -123
- data/plugins/can_has_sphinx/lib/sphinx.rb +0 -460
- data/plugins/can_has_sphinx/scripts/sphinx.sh +0 -47
- data/plugins/can_has_sphinx/tasks/acts_as_sphinx_tasks.rake +0 -41
- data/profile_data_mapper.rb +0 -40
- data/rakefile.rb +0 -159
- data/spec/acts_as_tree_spec.rb +0 -67
- data/spec/adapters/data_object_adapter_spec.rb +0 -31
- data/spec/associations/belongs_to_association_spec.rb +0 -98
- data/spec/associations/has_and_belongs_to_many_association_spec.rb +0 -377
- data/spec/associations/has_many_association_spec.rb +0 -337
- data/spec/attributes_spec.rb +0 -52
- data/spec/auto_migrations_spec.rb +0 -101
- data/spec/callbacks_spec.rb +0 -186
- data/spec/can_has_sphinx.rb +0 -5
- data/spec/coersion_spec.rb +0 -41
- data/spec/column_spec.rb +0 -114
- data/spec/count_command_spec.rb +0 -45
- data/spec/database_spec.rb +0 -18
- data/spec/dataobjects_spec.rb +0 -27
- data/spec/delete_command_spec.rb +0 -11
- data/spec/dependency_spec.rb +0 -29
- data/spec/embedded_value_spec.rb +0 -161
- data/spec/fixtures/animals.yaml +0 -33
- data/spec/fixtures/animals_exhibits.yaml +0 -2
- data/spec/fixtures/careers.yaml +0 -5
- data/spec/fixtures/comments.yaml +0 -1
- data/spec/fixtures/exhibits.yaml +0 -90
- data/spec/fixtures/fruit.yaml +0 -6
- data/spec/fixtures/people.yaml +0 -37
- data/spec/fixtures/posts.yaml +0 -3
- data/spec/fixtures/projects.yaml +0 -13
- data/spec/fixtures/sections.yaml +0 -5
- data/spec/fixtures/serializers.yaml +0 -6
- data/spec/fixtures/tasks.yaml +0 -6
- data/spec/fixtures/tasks_tasks.yaml +0 -2
- data/spec/fixtures/tomatoes.yaml +0 -1
- data/spec/fixtures/users.yaml +0 -1
- data/spec/fixtures/zoos.yaml +0 -24
- data/spec/is_a_tree_spec.rb +0 -149
- data/spec/legacy_spec.rb +0 -16
- data/spec/load_command_spec.rb +0 -322
- data/spec/magic_columns_spec.rb +0 -26
- data/spec/migration_spec.rb +0 -267
- data/spec/mock_adapter.rb +0 -20
- data/spec/models/animal.rb +0 -12
- data/spec/models/candidate.rb +0 -8
- data/spec/models/career.rb +0 -7
- data/spec/models/chain.rb +0 -8
- data/spec/models/comment.rb +0 -6
- data/spec/models/exhibit.rb +0 -14
- data/spec/models/fence.rb +0 -7
- data/spec/models/fruit.rb +0 -8
- data/spec/models/job.rb +0 -8
- data/spec/models/person.rb +0 -30
- data/spec/models/post.rb +0 -14
- data/spec/models/project.rb +0 -41
- data/spec/models/sales_person.rb +0 -5
- data/spec/models/section.rb +0 -8
- data/spec/models/serializer.rb +0 -5
- data/spec/models/task.rb +0 -9
- data/spec/models/tomato.rb +0 -27
- data/spec/models/user.rb +0 -12
- data/spec/models/zoo.rb +0 -13
- data/spec/natural_key_spec.rb +0 -36
- data/spec/paranoia_spec.rb +0 -38
- data/spec/persistence_spec.rb +0 -479
- data/spec/postgres_spec.rb +0 -96
- data/spec/property_spec.rb +0 -151
- data/spec/query_spec.rb +0 -77
- data/spec/save_command_spec.rb +0 -94
- data/spec/schema_spec.rb +0 -8
- data/spec/serialize_spec.rb +0 -19
- data/spec/single_table_inheritance_spec.rb +0 -43
- data/spec/spec_helper.rb +0 -45
- data/spec/support/blank_spec.rb +0 -8
- data/spec/support/inflector_spec.rb +0 -41
- data/spec/support/object_spec.rb +0 -9
- data/spec/support/serialization_spec.rb +0 -61
- data/spec/support/silence_spec.rb +0 -15
- data/spec/support/string_spec.rb +0 -7
- data/spec/support/struct_spec.rb +0 -12
- data/spec/support/typed_set_spec.rb +0 -66
- data/spec/symbolic_operators_spec.rb +0 -27
- data/spec/table_spec.rb +0 -79
- data/spec/types/string.rb +0 -81
- data/spec/validates_confirmation_of_spec.rb +0 -55
- data/spec/validates_format_of_spec.rb +0 -78
- data/spec/validates_length_of_spec.rb +0 -117
- data/spec/validates_uniqueness_of_spec.rb +0 -92
- data/spec/validations/number_validator.rb +0 -59
- data/spec/validations/string_validator.rb +0 -14
- data/spec/validations_spec.rb +0 -141
- data/tasks/fixtures.rb +0 -53
@@ -1,47 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
#
|
3
|
-
# start/stop searchd server.
|
4
|
-
|
5
|
-
if ! [ -x /usr/local/bin/searchd ]; then
|
6
|
-
exit 0
|
7
|
-
fi
|
8
|
-
|
9
|
-
case "$1" in
|
10
|
-
start)
|
11
|
-
echo -n "Starting sphinx searchd server:"
|
12
|
-
echo -n " searchd" ;
|
13
|
-
/sbin/start-stop-daemon --start --quiet --pidfile /var/run/searchd.pid --chdir /etc --exec /usr/local/bin/searchd
|
14
|
-
echo "."
|
15
|
-
;;
|
16
|
-
stop)
|
17
|
-
echo -n "Stopping sphinx searchd server:"
|
18
|
-
echo -n " searchd" ;
|
19
|
-
/sbin/start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/searchd.pid --exec /usr/local/bin/searchd
|
20
|
-
echo "."
|
21
|
-
;;
|
22
|
-
reload)
|
23
|
-
echo -n "Reloading sphinx searchd server:"
|
24
|
-
echo -n " searchd"
|
25
|
-
/sbin/start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/searchd.pid --signal 1
|
26
|
-
echo "."
|
27
|
-
;;
|
28
|
-
force-reload)
|
29
|
-
$0 reload
|
30
|
-
;;
|
31
|
-
reindex)
|
32
|
-
cd /etc
|
33
|
-
/usr/local/bin/indexer --rotate --quiet --all
|
34
|
-
;;
|
35
|
-
restart)
|
36
|
-
echo -n "Restarting sphinx searchd server:"
|
37
|
-
echo -n " searchd"
|
38
|
-
/sbin/start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/searchd.pid --exec /usr/local/bin/searchd
|
39
|
-
/sbin/start-stop-daemon --start --quiet --pidfile /var/run/searchd.pid --chdir /etc --exec /usr/local/bin/searchd
|
40
|
-
echo "."
|
41
|
-
;;
|
42
|
-
*)
|
43
|
-
echo "Usage: /etc/init.d/searchd {start|stop|reload|restart|reindex}"
|
44
|
-
exit 1
|
45
|
-
;;
|
46
|
-
esac
|
47
|
-
exit 0
|
@@ -1,41 +0,0 @@
|
|
1
|
-
namespace :sphinx do
|
2
|
-
desc "Run indexer"
|
3
|
-
task :index do
|
4
|
-
cd 'config' do
|
5
|
-
system 'indexer --all'
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
desc "Rotate idendexes and restart searchd server"
|
10
|
-
task :rotate do
|
11
|
-
cd 'config' do
|
12
|
-
system 'indexer --rotate --all'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
desc "Start searchd server"
|
17
|
-
task :start do
|
18
|
-
if File.exists?('/var/run/searchd.pid')
|
19
|
-
puts 'Sphinx searchd server is already started.'
|
20
|
-
else
|
21
|
-
cd 'config' do
|
22
|
-
system 'searchd'
|
23
|
-
puts 'Sphinx searchd server started.'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
desc "Stop searchd server"
|
29
|
-
task :stop do
|
30
|
-
unless File.exists?('/var/run/searchd.pid')
|
31
|
-
puts 'Sphinx searchd server is not running.'
|
32
|
-
else
|
33
|
-
pid = File.read('/var/run/searchd.pid').chomp
|
34
|
-
system "kill #{pid}"
|
35
|
-
puts 'Sphinx searchd server stopped.'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
desc "Restart searchd server"
|
40
|
-
task :restart => [:stop, :start]
|
41
|
-
end
|
data/profile_data_mapper.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
#!/opt/local/bin/ruby
|
2
|
-
|
3
|
-
require 'environment'
|
4
|
-
require 'ruby-prof'
|
5
|
-
|
6
|
-
# RubyProf, making profiling Ruby pretty since 1899!
|
7
|
-
def profile(&b)
|
8
|
-
result = RubyProf.profile &b
|
9
|
-
|
10
|
-
printer = RubyProf::GraphHtmlPrinter.new(result)
|
11
|
-
File::open('profile_results.html', 'w+') do |file|
|
12
|
-
printer.print(file, 0)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
profile do
|
17
|
-
1000.times do
|
18
|
-
Zoo.all.each { |zoo| zoo.name; zoo.exhibits.entries }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
puts "Done!"
|
23
|
-
|
24
|
-
# require 'benchmark'
|
25
|
-
#
|
26
|
-
# N = 100_000
|
27
|
-
#
|
28
|
-
# Benchmark::bmbm do |x|
|
29
|
-
# x.report do
|
30
|
-
# N.times do
|
31
|
-
# Inflector.underscore('DataMapper')
|
32
|
-
# end
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# x.report do
|
36
|
-
# N.times do
|
37
|
-
# String::memoized_underscore('DataMapper')
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
# end
|
data/rakefile.rb
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'rake'
|
5
|
-
require 'spec/rake/spectask'
|
6
|
-
require 'rake/rdoctask'
|
7
|
-
require 'rake/gempackagetask'
|
8
|
-
require 'rake/contrib/rubyforgepublisher'
|
9
|
-
|
10
|
-
Dir[File.dirname(__FILE__) + '/tasks/*'].each { |t| require(t) }
|
11
|
-
|
12
|
-
task :default => 'dm:spec'
|
13
|
-
|
14
|
-
task :environment => 'dm:environment'
|
15
|
-
|
16
|
-
dm = namespace :dm do
|
17
|
-
|
18
|
-
desc "Setup Environment"
|
19
|
-
task :environment do
|
20
|
-
require 'environment'
|
21
|
-
end
|
22
|
-
|
23
|
-
desc "Run specifications"
|
24
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
25
|
-
t.spec_opts = ["--format", "specdoc", "--colour"]
|
26
|
-
t.spec_files = FileList[(ENV['FILES'] || 'spec/**/*_spec.rb')]
|
27
|
-
unless ENV['NO_RCOV']
|
28
|
-
t.rcov = true
|
29
|
-
t.rcov_opts = ['--exclude', 'examples,spec,environment.rb']
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "Run comparison with ActiveRecord"
|
34
|
-
task :perf do
|
35
|
-
load 'performance.rb'
|
36
|
-
end
|
37
|
-
|
38
|
-
desc "Profile DataMapper"
|
39
|
-
task :profile do
|
40
|
-
load 'profile_data_mapper.rb'
|
41
|
-
end
|
42
|
-
|
43
|
-
namespace :spec do
|
44
|
-
def set_model_mode(fl, mode)
|
45
|
-
fl.each do |fname|
|
46
|
-
contents = File.open(fname, 'r') { |f| f.read }
|
47
|
-
|
48
|
-
if mode == :compat
|
49
|
-
contents.gsub!(/#< DataMapper::Base #/, '< DataMapper::Base #')
|
50
|
-
contents.gsub!(/include DataMapper::Persistence/, '#include DataMapper::Persistence')
|
51
|
-
elsif mode == :normal
|
52
|
-
contents.gsub!(/< DataMapper::Base #/, '#< DataMapper::Base #')
|
53
|
-
contents.gsub!(/#include DataMapper::Persistence/, 'include DataMapper::Persistence')
|
54
|
-
else
|
55
|
-
raise "Unknown mode #{mode}."
|
56
|
-
end
|
57
|
-
|
58
|
-
File.open(fname, 'w') do |f|
|
59
|
-
f.write(contents)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
desc "Run specifications with DataMapper::Base compatibilty"
|
65
|
-
task :compat do
|
66
|
-
fl = FileList['spec/**/*.rb'].exclude(/\b\.svn/)
|
67
|
-
|
68
|
-
set_model_mode(fl, :compat)
|
69
|
-
|
70
|
-
begin
|
71
|
-
dm[:spec].execute
|
72
|
-
ensure
|
73
|
-
set_model_mode(fl, :normal)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
PACKAGE_VERSION = '0.3.2'
|
80
|
-
|
81
|
-
PACKAGE_FILES = FileList[
|
82
|
-
'README',
|
83
|
-
'FAQ',
|
84
|
-
'QUICKLINKS',
|
85
|
-
'CHANGELOG',
|
86
|
-
'MIT-LICENSE',
|
87
|
-
'*.rb',
|
88
|
-
'lib/**/*.rb',
|
89
|
-
'spec/**/*.{rb,yaml}',
|
90
|
-
'tasks/**/*',
|
91
|
-
'plugins/**/*'
|
92
|
-
].to_a.reject { |path| path =~ /(\/db|Makefile|\.bundle|\.log|\.o)$/ }
|
93
|
-
|
94
|
-
DOCUMENTED_FILES = PACKAGE_FILES.reject do |path|
|
95
|
-
FileTest.directory?(path) || path =~ /(^spec|\/spec|\/swig\_)/
|
96
|
-
end
|
97
|
-
|
98
|
-
PROJECT = 'datamapper'
|
99
|
-
|
100
|
-
task :ls do
|
101
|
-
p PACKAGE_FILES
|
102
|
-
end
|
103
|
-
|
104
|
-
desc "Generate Documentation"
|
105
|
-
rd = Rake::RDocTask.new do |rdoc|
|
106
|
-
rdoc.rdoc_dir = 'doc'
|
107
|
-
rdoc.title = "DataMapper -- An Object/Relational Mapper for Ruby"
|
108
|
-
rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
|
109
|
-
rdoc.rdoc_files.include(*DOCUMENTED_FILES)
|
110
|
-
end
|
111
|
-
|
112
|
-
gem_spec = Gem::Specification.new do |s|
|
113
|
-
s.platform = Gem::Platform::RUBY
|
114
|
-
s.name = PROJECT
|
115
|
-
s.summary = "An Object/Relational Mapper for Ruby"
|
116
|
-
s.description = "Faster, Better, Simpler."
|
117
|
-
s.version = PACKAGE_VERSION
|
118
|
-
|
119
|
-
s.authors = 'Sam Smoot'
|
120
|
-
s.email = 'ssmoot@gmail.com'
|
121
|
-
s.rubyforge_project = PROJECT
|
122
|
-
s.homepage = 'http://datamapper.org'
|
123
|
-
|
124
|
-
s.files = PACKAGE_FILES
|
125
|
-
|
126
|
-
s.require_path = 'lib'
|
127
|
-
s.requirements << 'none'
|
128
|
-
s.autorequire = 'data_mapper'
|
129
|
-
s.add_dependency('fastthread')
|
130
|
-
s.add_dependency('json')
|
131
|
-
s.add_dependency('rspec')
|
132
|
-
s.add_dependency('validatable')
|
133
|
-
|
134
|
-
s.has_rdoc = true
|
135
|
-
s.rdoc_options << '--line-numbers' << '--inline-source' << '--main' << 'README'
|
136
|
-
s.extra_rdoc_files = DOCUMENTED_FILES
|
137
|
-
end
|
138
|
-
|
139
|
-
Rake::GemPackageTask.new(gem_spec) do |p|
|
140
|
-
p.gem_spec = gem_spec
|
141
|
-
p.need_tar = true
|
142
|
-
p.need_zip = true
|
143
|
-
end
|
144
|
-
|
145
|
-
desc "Publish to RubyForge"
|
146
|
-
task :rubyforge => [ :rdoc, :gem ] do
|
147
|
-
Rake::SshDirPublisher.new("#{ENV['RUBYFORGE_USER']}@rubyforge.org", "/var/www/gforge-projects/#{PROJECT}", 'doc').upload
|
148
|
-
end
|
149
|
-
|
150
|
-
task :install => :package do
|
151
|
-
sh %{sudo gem install pkg/#{PROJECT}-#{PACKAGE_VERSION}}
|
152
|
-
end
|
153
|
-
|
154
|
-
namespace :dev do
|
155
|
-
desc "Install for development (for windows)"
|
156
|
-
task :winstall => :gem do
|
157
|
-
system %{gem install --no-rdoc --no-ri -l pkg/#{PROJECT}-#{PACKAGE_VERSION}.gem}
|
158
|
-
end
|
159
|
-
end
|
data/spec/acts_as_tree_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
-
|
3
|
-
describe('A tree') do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
class Node #< DataMapper::Base # please do not remove this
|
7
|
-
include DataMapper::Persistence
|
8
|
-
|
9
|
-
property :name, :string
|
10
|
-
|
11
|
-
belongs_to :parent, :class => 'Node'
|
12
|
-
has_many :children, :class => 'Node', :foreign_key => 'parent_id'
|
13
|
-
|
14
|
-
def <=>(other)
|
15
|
-
name <=> other.name
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Node.auto_migrate!
|
20
|
-
end
|
21
|
-
|
22
|
-
after(:all) do
|
23
|
-
database.table(Node).drop!
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should work' do
|
27
|
-
root = Node.new(:name => 'root')
|
28
|
-
|
29
|
-
one = Node.new(:name => 'one')
|
30
|
-
two = Node.new(:name => 'two')
|
31
|
-
|
32
|
-
root.children << one << two
|
33
|
-
|
34
|
-
root.parent_id.should be_nil
|
35
|
-
|
36
|
-
one_one = Node.new(:name => 'one_one')
|
37
|
-
one_two = Node.new(:name => 'one_two')
|
38
|
-
one.children << one_one << one_two
|
39
|
-
|
40
|
-
two_one = Node.new(:name => 'two_one')
|
41
|
-
two_two = Node.new(:name => 'two_two')
|
42
|
-
two.children << two_one << two_two
|
43
|
-
|
44
|
-
root.save.should == true
|
45
|
-
root.parent_id.should be_nil
|
46
|
-
|
47
|
-
root.should have(2).children
|
48
|
-
one.should have(2).children
|
49
|
-
two.should have(2).children
|
50
|
-
|
51
|
-
Node.all(:name => 'root').should have(1).entries
|
52
|
-
|
53
|
-
grand = Node.first(:name => 'root')
|
54
|
-
|
55
|
-
grand.should have(2).children
|
56
|
-
|
57
|
-
root.should == grand # true since +root+ and +grand+ are objects with identical types and attributes.
|
58
|
-
root.object_id.should_not eql(grand.object_id) # false since +root+ and +grand+ are in different sessions.
|
59
|
-
|
60
|
-
grand.children.should include(one)
|
61
|
-
one.reload
|
62
|
-
one.children.should include(one_one)
|
63
|
-
|
64
|
-
grand.children.first.children.first.should eql(one_one)
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Adapters::DataObjectAdapter do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
fixtures(:zoos)
|
7
|
-
end
|
8
|
-
|
9
|
-
if ENV['ADAPTER'] == 'postgresql'
|
10
|
-
it "should be able to be given a port" do
|
11
|
-
options = {
|
12
|
-
:adapter => 'postgresql',
|
13
|
-
:database => 'data_mapper_1',
|
14
|
-
:port => 4001
|
15
|
-
}
|
16
|
-
db = DataMapper::Database.setup(:my_postgres, options)
|
17
|
-
db.port.should == 4001
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should use DB defaults when creating an empty record" do
|
22
|
-
comment = Comment.create({})
|
23
|
-
comment.new_record?.should be_false
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should raise an argument error on create if an attribute value is not a primitive" do
|
27
|
-
lambda { Zoo.create(:name => [nil, 'bob']) }.should raise_error(ArgumentError)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should accept a subclass as a valid type if the parent is a valid type"
|
31
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
-
|
3
|
-
describe DataMapper::Associations::BelongsToAssociation do
|
4
|
-
before(:all) do
|
5
|
-
fixtures(:zoos)
|
6
|
-
end
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
@aviary = Exhibit.first(:name => 'Monkey Mayhem')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should provide a shallow_append method that doesn't impact the complementary association" do
|
13
|
-
project = Project.new
|
14
|
-
section = Section.new
|
15
|
-
section.send(:project_association).shallow_append(project)
|
16
|
-
project.sections.should be_empty
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'has a zoo association' do
|
20
|
-
@aviary.zoo.class.should == Zoo
|
21
|
-
Exhibit.new.zoo.should == nil
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'belongs to a zoo' do
|
25
|
-
@aviary.zoo.should == @aviary.database_context.first(Zoo, :name => 'San Diego')
|
26
|
-
end
|
27
|
-
|
28
|
-
it "is assigned a zoo_id" do
|
29
|
-
zoo = Zoo.first
|
30
|
-
exhibit = Exhibit.new(:name => 'bob')
|
31
|
-
exhibit.zoo = zoo
|
32
|
-
exhibit.instance_variable_get("@zoo_id").should == zoo.id
|
33
|
-
|
34
|
-
exhibit.save.should eql(true)
|
35
|
-
|
36
|
-
zoo2 = Zoo.first
|
37
|
-
zoo2.exhibits.should include(exhibit)
|
38
|
-
|
39
|
-
exhibit.destroy!
|
40
|
-
|
41
|
-
zoo = Zoo.new(:name => 'bob')
|
42
|
-
bob = Exhibit.new(:name => 'bob')
|
43
|
-
zoo.exhibits << bob
|
44
|
-
zoo.save.should eql(true)
|
45
|
-
|
46
|
-
zoo.exhibits.first.should_not be_a_new_record
|
47
|
-
|
48
|
-
bob.destroy!
|
49
|
-
zoo.destroy!
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should not assign zoo_id when passed nil" do
|
53
|
-
# pending "http://wm.lighthouseapp.com/projects/4819-datamapper/tickets/147"
|
54
|
-
exhibit = Exhibit.first
|
55
|
-
exhibit.zoo_id = nil
|
56
|
-
exhibit.zoo_id.should be_nil
|
57
|
-
exhibit.save.should == true
|
58
|
-
|
59
|
-
exhibit.reload
|
60
|
-
exhibit.zoo_id.should be_nil
|
61
|
-
exhibit.zoo.should be_nil
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should be marked dirty if the complementary association is a new_record and the instance is already saved" do
|
65
|
-
zoo = Zoo.new(:name => "My Zoo")
|
66
|
-
tiger = Exhibit.create(:name => "Tiger")
|
67
|
-
zoo.exhibits << tiger
|
68
|
-
tiger.should be_dirty
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'can build its zoo' do
|
72
|
-
database do |db|
|
73
|
-
e = Exhibit.new({:name => 'Super Extra Crazy Monkey Cage'})
|
74
|
-
e.zoo.should == nil
|
75
|
-
e.build_zoo({:name => 'Monkey Zoo'})
|
76
|
-
e.zoo.class == Zoo
|
77
|
-
e.zoo.new_record?.should == true
|
78
|
-
|
79
|
-
e.save
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'can build its zoo' do
|
84
|
-
database do |db|
|
85
|
-
e = Exhibit.new({:name => 'Super Extra Crazy Monkey Cage'})
|
86
|
-
e.zoo.should == nil
|
87
|
-
e.create_zoo({:name => 'Monkey Zoo'})
|
88
|
-
e.zoo.class == Zoo
|
89
|
-
e.zoo.new_record?.should == false
|
90
|
-
e.save
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
after(:all) do
|
95
|
-
fixtures('zoos')
|
96
|
-
fixtures('exhibits')
|
97
|
-
end
|
98
|
-
end
|