godfat-dm-mapping 0.3.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.
- data/.gitignore +2 -0
- data/CHANGES +137 -0
- data/LICENSE +201 -0
- data/NOTICE +9 -0
- data/README +95 -0
- data/Rakefile +58 -0
- data/TODO +4 -0
- data/dm-mapping.gemspec +34 -0
- data/lib/dm-mapping/adapters/abstract_adapter.rb +36 -0
- data/lib/dm-mapping/adapters/sqlite3adapter.rb +40 -0
- data/lib/dm-mapping/model.rb +36 -0
- data/lib/dm-mapping/type_map.rb +10 -0
- data/lib/dm-mapping/version.rb +5 -0
- data/lib/dm-mapping.rb +29 -0
- data/tasks/ann.rake +81 -0
- data/tasks/bones.rake +21 -0
- data/tasks/gem.rake +126 -0
- data/tasks/git.rake +41 -0
- data/tasks/manifest.rake +49 -0
- data/tasks/notes.rake +28 -0
- data/tasks/post_load.rake +39 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +57 -0
- data/tasks/setup.rb +268 -0
- data/tasks/spec.rake +55 -0
- data/tasks/svn.rake +48 -0
- data/tasks/test.rake +38 -0
- data/test/test_dm-mapping.rb +137 -0
- metadata +112 -0
data/tasks/setup.rb
ADDED
@@ -0,0 +1,268 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/clean'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
class OpenStruct; undef :gem; end
|
10
|
+
|
11
|
+
PROJ = OpenStruct.new(
|
12
|
+
# Project Defaults
|
13
|
+
:name => nil,
|
14
|
+
:summary => nil,
|
15
|
+
:description => nil,
|
16
|
+
:changes => nil,
|
17
|
+
:authors => nil,
|
18
|
+
:email => nil,
|
19
|
+
:url => "\000",
|
20
|
+
:version => ENV['VERSION'] || '0.0.0',
|
21
|
+
:exclude => %w(tmp$ bak$ ~$ CVS \.svn/ \.git/ ^pkg/),
|
22
|
+
:release_name => ENV['RELEASE'],
|
23
|
+
|
24
|
+
# System Defaults
|
25
|
+
:ruby_opts => %w(-w),
|
26
|
+
:libs => [],
|
27
|
+
:history_file => 'History.txt',
|
28
|
+
:manifest_file => 'Manifest.txt',
|
29
|
+
:readme_file => 'README.txt',
|
30
|
+
|
31
|
+
# Announce
|
32
|
+
:ann => OpenStruct.new(
|
33
|
+
:file => 'announcement.txt',
|
34
|
+
:text => nil,
|
35
|
+
:paragraphs => [],
|
36
|
+
:email => {
|
37
|
+
:from => nil,
|
38
|
+
:to => %w(ruby-talk@ruby-lang.org),
|
39
|
+
:server => 'localhost',
|
40
|
+
:port => 25,
|
41
|
+
:domain => ENV['HOSTNAME'],
|
42
|
+
:acct => nil,
|
43
|
+
:passwd => nil,
|
44
|
+
:authtype => :plain
|
45
|
+
}
|
46
|
+
),
|
47
|
+
|
48
|
+
# Gem Packaging
|
49
|
+
:gem => OpenStruct.new(
|
50
|
+
:dependencies => [],
|
51
|
+
:executables => nil,
|
52
|
+
:extensions => FileList['ext/**/extconf.rb'],
|
53
|
+
:files => nil,
|
54
|
+
:need_tar => true,
|
55
|
+
:need_zip => false,
|
56
|
+
:extras => {}
|
57
|
+
),
|
58
|
+
|
59
|
+
# File Annotations
|
60
|
+
:notes => OpenStruct.new(
|
61
|
+
:exclude => %w(^tasks/setup\.rb$),
|
62
|
+
:extensions => %w(.txt .rb .erb) << '',
|
63
|
+
:tags => %w(FIXME OPTIMIZE TODO)
|
64
|
+
),
|
65
|
+
|
66
|
+
# Rcov
|
67
|
+
:rcov => OpenStruct.new(
|
68
|
+
:dir => 'coverage',
|
69
|
+
:opts => %w[--sort coverage -T],
|
70
|
+
:threshold => 90.0,
|
71
|
+
:threshold_exact => false
|
72
|
+
),
|
73
|
+
|
74
|
+
# Rdoc
|
75
|
+
:rdoc => OpenStruct.new(
|
76
|
+
:opts => [],
|
77
|
+
:include => %w(^lib/ ^bin/ ^ext/ \.txt$),
|
78
|
+
:exclude => %w(extconf\.rb$),
|
79
|
+
:main => nil,
|
80
|
+
:dir => 'doc',
|
81
|
+
:remote_dir => nil
|
82
|
+
),
|
83
|
+
|
84
|
+
# Rubyforge
|
85
|
+
:rubyforge => OpenStruct.new(
|
86
|
+
:name => "\000"
|
87
|
+
),
|
88
|
+
|
89
|
+
# Rspec
|
90
|
+
:spec => OpenStruct.new(
|
91
|
+
:files => FileList['spec/**/*_spec.rb'],
|
92
|
+
:opts => []
|
93
|
+
),
|
94
|
+
|
95
|
+
# Subversion Repository
|
96
|
+
:svn => OpenStruct.new(
|
97
|
+
:root => nil,
|
98
|
+
:path => '',
|
99
|
+
:trunk => 'trunk',
|
100
|
+
:tags => 'tags',
|
101
|
+
:branches => 'branches'
|
102
|
+
),
|
103
|
+
|
104
|
+
# Test::Unit
|
105
|
+
:test => OpenStruct.new(
|
106
|
+
:files => FileList['test/**/test_*.rb'],
|
107
|
+
:file => 'test/all.rb',
|
108
|
+
:opts => []
|
109
|
+
)
|
110
|
+
)
|
111
|
+
|
112
|
+
# Load the other rake files in the tasks folder
|
113
|
+
rakefiles = Dir.glob('tasks/*.rake').sort
|
114
|
+
rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
|
115
|
+
import(*rakefiles)
|
116
|
+
|
117
|
+
# Setup the project libraries
|
118
|
+
%w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
|
119
|
+
|
120
|
+
# Setup some constants
|
121
|
+
WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
|
122
|
+
|
123
|
+
DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
|
124
|
+
|
125
|
+
def quiet( &block )
|
126
|
+
io = [STDOUT.dup, STDERR.dup]
|
127
|
+
STDOUT.reopen DEV_NULL
|
128
|
+
STDERR.reopen DEV_NULL
|
129
|
+
block.call
|
130
|
+
ensure
|
131
|
+
STDOUT.reopen io.first
|
132
|
+
STDERR.reopen io.last
|
133
|
+
$stdout, $stderr = STDOUT, STDERR
|
134
|
+
end
|
135
|
+
|
136
|
+
DIFF = if WIN32 then 'diff.exe'
|
137
|
+
else
|
138
|
+
if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
|
139
|
+
else 'diff' end
|
140
|
+
end unless defined? DIFF
|
141
|
+
|
142
|
+
SUDO = if WIN32 then ''
|
143
|
+
else
|
144
|
+
if quiet {system 'which sudo'} then 'sudo'
|
145
|
+
else '' end
|
146
|
+
end
|
147
|
+
|
148
|
+
RCOV = WIN32 ? 'rcov.bat' : 'rcov'
|
149
|
+
RDOC = WIN32 ? 'rdoc.bat' : 'rdoc'
|
150
|
+
GEM = WIN32 ? 'gem.bat' : 'gem'
|
151
|
+
|
152
|
+
%w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
|
153
|
+
begin
|
154
|
+
require lib
|
155
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
|
156
|
+
rescue LoadError
|
157
|
+
Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
HAVE_SVN = (Dir.entries(Dir.pwd).include?('.svn') and
|
161
|
+
system("svn --version 2>&1 > #{DEV_NULL}"))
|
162
|
+
HAVE_GIT = (Dir.entries(Dir.pwd).include?('.git') and
|
163
|
+
system("git --version 2>&1 > #{DEV_NULL}"))
|
164
|
+
|
165
|
+
# Reads a file at +path+ and spits out an array of the +paragraphs+
|
166
|
+
# specified.
|
167
|
+
#
|
168
|
+
# changes = paragraphs_of('History.txt', 0..1).join("\n\n")
|
169
|
+
# summary, *description = paragraphs_of('README.txt', 3, 3..8)
|
170
|
+
#
|
171
|
+
def paragraphs_of( path, *paragraphs )
|
172
|
+
title = String === paragraphs.first ? paragraphs.shift : nil
|
173
|
+
ary = File.read(path).delete("\r").split(/\n\n+/)
|
174
|
+
|
175
|
+
result = if title
|
176
|
+
tmp, matching = [], false
|
177
|
+
rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
|
178
|
+
paragraphs << (0..-1) if paragraphs.empty?
|
179
|
+
|
180
|
+
ary.each do |val|
|
181
|
+
if val =~ rgxp
|
182
|
+
break if matching
|
183
|
+
matching = true
|
184
|
+
rgxp = %r/^=+/i
|
185
|
+
elsif matching
|
186
|
+
tmp << val
|
187
|
+
end
|
188
|
+
end
|
189
|
+
tmp
|
190
|
+
else ary end
|
191
|
+
|
192
|
+
result.values_at(*paragraphs)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Adds the given gem _name_ to the current project's dependency list. An
|
196
|
+
# optional gem _version_ can be given. If omitted, the newest gem version
|
197
|
+
# will be used.
|
198
|
+
#
|
199
|
+
def depend_on( name, version = nil )
|
200
|
+
spec = Gem.source_index.find_name(name).last
|
201
|
+
version = spec.version.to_s if version.nil? and !spec.nil?
|
202
|
+
|
203
|
+
PROJ.gem.dependencies << case version
|
204
|
+
when nil; [name]
|
205
|
+
when %r/^\d/; [name, ">= #{version}"]
|
206
|
+
else [name, version] end
|
207
|
+
end
|
208
|
+
|
209
|
+
# Adds the given arguments to the include path if they are not already there
|
210
|
+
#
|
211
|
+
def ensure_in_path( *args )
|
212
|
+
args.each do |path|
|
213
|
+
path = File.expand_path(path)
|
214
|
+
$:.unshift(path) if test(?d, path) and not $:.include?(path)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Find a rake task using the task name and remove any description text. This
|
219
|
+
# will prevent the task from being displayed in the list of available tasks.
|
220
|
+
#
|
221
|
+
def remove_desc_for_task( names )
|
222
|
+
Array(names).each do |task_name|
|
223
|
+
task = Rake.application.tasks.find {|t| t.name == task_name}
|
224
|
+
next if task.nil?
|
225
|
+
task.instance_variable_set :@comment, nil
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Change working directories to _dir_, call the _block_ of code, and then
|
230
|
+
# change back to the original working directory (the current directory when
|
231
|
+
# this method was called).
|
232
|
+
#
|
233
|
+
def in_directory( dir, &block )
|
234
|
+
curdir = pwd
|
235
|
+
begin
|
236
|
+
cd dir
|
237
|
+
return block.call
|
238
|
+
ensure
|
239
|
+
cd curdir
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Scans the current working directory and creates a list of files that are
|
244
|
+
# candidates to be in the manifest.
|
245
|
+
#
|
246
|
+
def manifest_files
|
247
|
+
files = []
|
248
|
+
exclude = Regexp.new(PROJ.exclude.join('|'))
|
249
|
+
Find.find '.' do |path|
|
250
|
+
path.sub! %r/^(\.\/|\/)/o, ''
|
251
|
+
next unless test ?f, path
|
252
|
+
next if path =~ exclude
|
253
|
+
files << path
|
254
|
+
end
|
255
|
+
files.sort!
|
256
|
+
end
|
257
|
+
|
258
|
+
# We need a "valid" method thtat determines if a string is suitable for use
|
259
|
+
# in the gem specification.
|
260
|
+
#
|
261
|
+
class Object
|
262
|
+
def valid?
|
263
|
+
return !(self.empty? or self == "\000") if self.respond_to?(:to_str)
|
264
|
+
return false
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# EOF
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_SPEC_RAKE_SPECTASK
|
4
|
+
require 'spec/rake/verify_rcov'
|
5
|
+
|
6
|
+
namespace :spec do
|
7
|
+
|
8
|
+
desc 'Run all specs with basic output'
|
9
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
10
|
+
t.ruby_opts = PROJ.ruby_opts
|
11
|
+
t.spec_opts = PROJ.spec.opts
|
12
|
+
t.spec_files = PROJ.spec.files
|
13
|
+
t.libs += PROJ.libs
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Run all specs with text output'
|
17
|
+
Spec::Rake::SpecTask.new(:specdoc) do |t|
|
18
|
+
t.ruby_opts = PROJ.ruby_opts
|
19
|
+
t.spec_opts = PROJ.spec.opts + ['--format', 'specdoc']
|
20
|
+
t.spec_files = PROJ.spec.files
|
21
|
+
t.libs += PROJ.libs
|
22
|
+
end
|
23
|
+
|
24
|
+
if HAVE_RCOV
|
25
|
+
desc 'Run all specs with RCov'
|
26
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
27
|
+
t.ruby_opts = PROJ.ruby_opts
|
28
|
+
t.spec_opts = PROJ.spec.opts
|
29
|
+
t.spec_files = PROJ.spec.files
|
30
|
+
t.libs += PROJ.libs
|
31
|
+
t.rcov = true
|
32
|
+
t.rcov_dir = PROJ.rcov.dir
|
33
|
+
t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
|
34
|
+
end
|
35
|
+
|
36
|
+
RCov::VerifyTask.new(:verify) do |t|
|
37
|
+
t.threshold = PROJ.rcov.threshold
|
38
|
+
t.index_html = File.join(PROJ.rcov.dir, 'index.html')
|
39
|
+
t.require_exact_threshold = PROJ.rcov.threshold_exact
|
40
|
+
end
|
41
|
+
|
42
|
+
task :verify => :rcov
|
43
|
+
remove_desc_for_task %w(spec:clobber_rcov)
|
44
|
+
end
|
45
|
+
|
46
|
+
end # namespace :spec
|
47
|
+
|
48
|
+
desc 'Alias to spec:run'
|
49
|
+
task :spec => 'spec:run'
|
50
|
+
|
51
|
+
task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
|
52
|
+
|
53
|
+
end # if HAVE_SPEC_RAKE_SPECTASK
|
54
|
+
|
55
|
+
# EOF
|
data/tasks/svn.rake
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
if HAVE_SVN
|
4
|
+
|
5
|
+
unless PROJ.svn.root
|
6
|
+
info = %x/svn info ./
|
7
|
+
m = %r/^Repository Root:\s+(.*)$/.match(info)
|
8
|
+
PROJ.svn.root = (m.nil? ? '' : m[1])
|
9
|
+
end
|
10
|
+
PROJ.svn.root = File.join(PROJ.svn.root, PROJ.svn.path) unless PROJ.svn.path.empty?
|
11
|
+
|
12
|
+
namespace :svn do
|
13
|
+
|
14
|
+
# A prerequisites task that all other tasks depend upon
|
15
|
+
task :prereqs
|
16
|
+
|
17
|
+
desc 'Show tags from the SVN repository'
|
18
|
+
task :show_tags => 'svn:prereqs' do |t|
|
19
|
+
tags = %x/svn list #{File.join(PROJ.svn.root, PROJ.svn.tags)}/
|
20
|
+
tags.gsub!(%r/\/$/, '')
|
21
|
+
tags = tags.split("\n").sort {|a,b| b <=> a}
|
22
|
+
puts tags
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Create a new tag in the SVN repository'
|
26
|
+
task :create_tag => 'svn:prereqs' do |t|
|
27
|
+
v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
|
28
|
+
abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
|
29
|
+
|
30
|
+
svn = PROJ.svn
|
31
|
+
trunk = File.join(svn.root, svn.trunk)
|
32
|
+
tag = "%s-%s" % [PROJ.name, PROJ.version]
|
33
|
+
tag = File.join(svn.root, svn.tags, tag)
|
34
|
+
msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
|
35
|
+
|
36
|
+
puts "Creating SVN tag '#{tag}'"
|
37
|
+
unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
|
38
|
+
abort "Tag creation failed"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end # namespace :svn
|
43
|
+
|
44
|
+
task 'gem:release' => 'svn:create_tag'
|
45
|
+
|
46
|
+
end # if PROJ.svn.path
|
47
|
+
|
48
|
+
# EOF
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# $Id$
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
namespace :test do
|
6
|
+
|
7
|
+
Rake::TestTask.new(:run) do |t|
|
8
|
+
t.libs = PROJ.libs
|
9
|
+
t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
10
|
+
else PROJ.test.files end
|
11
|
+
t.ruby_opts += PROJ.ruby_opts
|
12
|
+
t.ruby_opts += PROJ.test.opts
|
13
|
+
end
|
14
|
+
|
15
|
+
if HAVE_RCOV
|
16
|
+
desc 'Run rcov on the unit tests'
|
17
|
+
task :rcov => :clobber_rcov do
|
18
|
+
opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
|
19
|
+
opts = opts.join(' ')
|
20
|
+
files = if test(?f, PROJ.test.file) then [PROJ.test.file]
|
21
|
+
else PROJ.test.files end
|
22
|
+
files = files.join(' ')
|
23
|
+
sh "#{RCOV} #{files} #{opts}"
|
24
|
+
end
|
25
|
+
|
26
|
+
task :clobber_rcov do
|
27
|
+
rm_r 'coverage' rescue nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end # namespace :test
|
32
|
+
|
33
|
+
desc 'Alias to test:run'
|
34
|
+
task :test => 'test:run'
|
35
|
+
|
36
|
+
task :clobber => 'test:clobber_rcov' if HAVE_RCOV
|
37
|
+
|
38
|
+
# EOF
|
@@ -0,0 +1,137 @@
|
|
1
|
+
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'data_mapper'
|
6
|
+
require 'dm-mapping'
|
7
|
+
|
8
|
+
class DMMTest < Test::Unit::TestCase
|
9
|
+
class User
|
10
|
+
include DataMapper::Resource
|
11
|
+
has n, :comments
|
12
|
+
|
13
|
+
property :id, Integer, :serial => true
|
14
|
+
property :login, String
|
15
|
+
property :sig, Text
|
16
|
+
property :created_at, DateTime
|
17
|
+
end
|
18
|
+
|
19
|
+
class Comment
|
20
|
+
include DataMapper::Resource
|
21
|
+
belongs_to :user
|
22
|
+
|
23
|
+
property :id, Integer, :serial => true
|
24
|
+
property :title, String, :default => 'default title'
|
25
|
+
property :body, Text
|
26
|
+
end
|
27
|
+
|
28
|
+
class Model; end
|
29
|
+
|
30
|
+
def create_fake_model
|
31
|
+
[Model.dup.__send__(:include, DataMapper::Resource),
|
32
|
+
DataMapper.setup(:default, 'sqlite3:tmp.db')]
|
33
|
+
end
|
34
|
+
|
35
|
+
@@dm = DataMapper.setup :default, 'sqlite3:tmp.db'
|
36
|
+
def dm; @@dm; end
|
37
|
+
|
38
|
+
def setup
|
39
|
+
User.auto_migrate!
|
40
|
+
Comment.auto_migrate!
|
41
|
+
end
|
42
|
+
|
43
|
+
def user_fields
|
44
|
+
[['created_at', DateTime, {}],
|
45
|
+
['id', Integer, {:serial => true}],
|
46
|
+
['login', String, {}],
|
47
|
+
['sig', DataMapper::Types::Text, {}]]
|
48
|
+
end
|
49
|
+
|
50
|
+
def comment_fields
|
51
|
+
[['body', DataMapper::Types::Text, {}],
|
52
|
+
['id', Integer , {:serial => true}],
|
53
|
+
['title', String , {:default => 'default title'}],
|
54
|
+
['user_id', Integer , {}]]
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_storages
|
58
|
+
assert_equal ['dmm_test_comments', 'dmm_test_users'], dm.storages.sort
|
59
|
+
assert_equal comment_fields, dm.fields('dmm_test_comments').sort
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_create_comment
|
63
|
+
Comment.create(:title => 'XD')
|
64
|
+
assert_equal 1, Comment.first.id
|
65
|
+
assert_equal 'XD', Comment.first.title
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_mapping_all
|
69
|
+
test_create_comment # for fixtures
|
70
|
+
model, local_dm = create_fake_model
|
71
|
+
model.storage_names[:default] = 'dmm_test_comments'
|
72
|
+
|
73
|
+
assert_equal ['dmm_test_comments', 'dmm_test_users'], local_dm.storages.sort
|
74
|
+
assert_equal 'dmm_test_comments', model.storage_name
|
75
|
+
|
76
|
+
assert_equal 1, model.count
|
77
|
+
assert_equal comment_fields, model.fields.sort
|
78
|
+
|
79
|
+
model.send :mapping
|
80
|
+
assert_equal 'XD', model.first.title
|
81
|
+
assert_equal 1, model.first.id
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_mapping_and_create
|
85
|
+
model, local_dm = create_fake_model
|
86
|
+
model.storage_names[:default] = 'dmm_test_comments'
|
87
|
+
model.send :mapping
|
88
|
+
|
89
|
+
model.create(:title => 'orz')
|
90
|
+
assert_equal 'orz', model.first.title
|
91
|
+
assert_equal 1, model.first.id
|
92
|
+
|
93
|
+
model.create
|
94
|
+
assert_equal 'default title', model.get(2).title
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_storages_and_fields
|
98
|
+
assert_equal user_fields, dm.fields('dmm_test_users').sort
|
99
|
+
assert_equal( {'dmm_test_users' => user_fields, 'dmm_test_comments' => comment_fields},
|
100
|
+
dm.storages_and_fields.inject({}){ |r, i|
|
101
|
+
key, value = i
|
102
|
+
r[key] = value.sort
|
103
|
+
r
|
104
|
+
} )
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_mapping_type
|
108
|
+
model, local_dm = create_fake_model
|
109
|
+
model.storage_names[:default] = 'dmm_test_comments'
|
110
|
+
model.send :mapping, Integer
|
111
|
+
|
112
|
+
assert_equal ['id', 'user_id'], model.properties.map(&:name).map(&:to_s).sort
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_mapping_multiple
|
116
|
+
model, local_dm = create_fake_model
|
117
|
+
model.storage_names[:default] = 'dmm_test_users'
|
118
|
+
model.send :mapping, :login, Integer
|
119
|
+
|
120
|
+
assert_equal ['id', 'login'], model.properties.map(&:name).map(&:to_s).sort
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_mapping_regexp
|
124
|
+
model, local_dm = create_fake_model
|
125
|
+
model.storage_names[:default] = 'dmm_test_comments'
|
126
|
+
model.send :mapping, /id$/
|
127
|
+
|
128
|
+
assert_equal ['id', 'user_id'], model.properties.map(&:name).map(&:to_s).sort
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_invalid_argument
|
132
|
+
assert_raise(ArgumentError){
|
133
|
+
User.send :mapping, 29
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: godfat-dm-mapping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Lin Jen-Shin (a.k.a. godfat \xE7\x9C\x9F\xE5\xB8\xB8)"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-04 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dm-core
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.3
|
23
|
+
version:
|
24
|
+
description: DataMapper plugin that helps you manipulate an existing database. It creates mappings between existing columns and model's properties.
|
25
|
+
email: "strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org"
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- .gitignore
|
32
|
+
- CHANGES
|
33
|
+
- LICENSE
|
34
|
+
- NOTICE
|
35
|
+
- README
|
36
|
+
- TODO
|
37
|
+
- dm-mapping.gemspec
|
38
|
+
- tasks/ann.rake
|
39
|
+
- tasks/bones.rake
|
40
|
+
- tasks/gem.rake
|
41
|
+
- tasks/git.rake
|
42
|
+
- tasks/manifest.rake
|
43
|
+
- tasks/notes.rake
|
44
|
+
- tasks/post_load.rake
|
45
|
+
- tasks/rdoc.rake
|
46
|
+
- tasks/rubyforge.rake
|
47
|
+
- tasks/spec.rake
|
48
|
+
- tasks/svn.rake
|
49
|
+
- tasks/test.rake
|
50
|
+
files:
|
51
|
+
- .gitignore
|
52
|
+
- CHANGES
|
53
|
+
- LICENSE
|
54
|
+
- NOTICE
|
55
|
+
- README
|
56
|
+
- Rakefile
|
57
|
+
- TODO
|
58
|
+
- dm-mapping.gemspec
|
59
|
+
- lib/dm-mapping.rb
|
60
|
+
- lib/dm-mapping/adapters/abstract_adapter.rb
|
61
|
+
- lib/dm-mapping/adapters/sqlite3adapter.rb
|
62
|
+
- lib/dm-mapping/model.rb
|
63
|
+
- lib/dm-mapping/type_map.rb
|
64
|
+
- lib/dm-mapping/version.rb
|
65
|
+
- tasks/ann.rake
|
66
|
+
- tasks/bones.rake
|
67
|
+
- tasks/gem.rake
|
68
|
+
- tasks/git.rake
|
69
|
+
- tasks/manifest.rake
|
70
|
+
- tasks/notes.rake
|
71
|
+
- tasks/post_load.rake
|
72
|
+
- tasks/rdoc.rake
|
73
|
+
- tasks/rubyforge.rake
|
74
|
+
- tasks/setup.rb
|
75
|
+
- tasks/spec.rake
|
76
|
+
- tasks/svn.rake
|
77
|
+
- tasks/test.rake
|
78
|
+
- test/test_dm-mapping.rb
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://github.com/godfat/dm-mapping
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --diagram
|
84
|
+
- --charset=utf-8
|
85
|
+
- --inline-source
|
86
|
+
- --line-numbers
|
87
|
+
- --promiscuous
|
88
|
+
- --main
|
89
|
+
- README
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
version:
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project: ludy
|
107
|
+
rubygems_version: 1.2.0
|
108
|
+
signing_key:
|
109
|
+
specification_version: 2
|
110
|
+
summary: DataMapper plugin that helps you manipulate an existing database. It creates mappings between existing columns and model's properties.
|
111
|
+
test_files:
|
112
|
+
- test/test_dm-mapping.rb
|