dao 5.5.0 → 8.0.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.
- checksums.yaml +6 -14
- data/README.md +258 -0
- data/Rakefile +4 -5
- data/coerce-0.0.8/README +28 -0
- data/coerce-0.0.8/Rakefile +392 -0
- data/coerce-0.0.8/coerce.gemspec +31 -0
- data/coerce-0.0.8/lib/coerce.rb +210 -0
- data/dao.gemspec +38 -25
- data/lib/dao.rb +18 -81
- data/lib/dao/_lib.rb +42 -0
- data/lib/dao/active_record.rb +8 -8
- data/lib/dao/api/call.rb +19 -4
- data/lib/dao/api/dsl.rb +1 -1
- data/lib/dao/coerce.rb +211 -0
- data/lib/dao/conducer.rb +10 -14
- data/lib/dao/conducer/controller_support.rb +5 -0
- data/lib/dao/conducer/view_support.rb +0 -2
- data/lib/dao/db.rb +0 -1
- data/lib/dao/errors.rb +17 -11
- data/lib/dao/errors2html.rb +128 -0
- data/lib/dao/form.rb +13 -16
- data/lib/dao/messages.rb +0 -4
- data/lib/dao/path.rb +1 -1
- data/lib/dao/route.rb +2 -2
- data/lib/dao/status.rb +3 -4
- data/lib/dao/support.rb +26 -19
- data/lib/dao/upload.rb +0 -1
- data/lib/dao/validations/common.rb +6 -6
- data/lib/dao/validations/validator.rb +3 -3
- data/lib/dao/wrap.rb +259 -0
- data/tasks/default.rake +207 -0
- data/tasks/this.rb +207 -0
- data/test/active_model_conducer_lint_test.rb +3 -11
- data/test/api_test.rb +24 -35
- data/test/conducer_test.rb +37 -47
- data/test/errors_test.rb +29 -13
- data/test/form_test.rb +24 -34
- data/test/rake_rerun_reporter.rb +74 -0
- data/test/support_test.rb +9 -14
- data/test/test_helper.rb +220 -0
- data/test/{helper.rb → util.rb} +0 -0
- data/test/validations_test.rb +14 -28
- data/wrap-1.5.2/README +57 -0
- data/wrap-1.5.2/Rakefile +394 -0
- data/wrap-1.5.2/lib/wrap.rb +295 -0
- data/{test → wrap-1.5.2/test}/testing.rb +0 -1
- data/wrap-1.5.2/test/wrap_test.rb +397 -0
- data/wrap-1.5.2/wrap.gemspec +38 -0
- metadata +47 -103
- data/Gemfile +0 -16
- data/Gemfile.lock +0 -118
- data/README +0 -256
data/tasks/this.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
# Public: A Class containing all the metadata and utilities needed to manage a
|
4
|
+
# ruby project.
|
5
|
+
class ThisProject
|
6
|
+
# The name of this project
|
7
|
+
attr_accessor :name
|
8
|
+
|
9
|
+
# The author's name
|
10
|
+
attr_accessor :author
|
11
|
+
|
12
|
+
# The email address of the author(s)
|
13
|
+
attr_accessor :email
|
14
|
+
|
15
|
+
# The homepage of this project
|
16
|
+
attr_accessor :homepage
|
17
|
+
|
18
|
+
# The regex of files to exclude from the manifest
|
19
|
+
attr_accessor :exclude_from_manifest
|
20
|
+
|
21
|
+
# The hash of Gem::Specifications keyed' by platform
|
22
|
+
attr_accessor :gemspecs
|
23
|
+
|
24
|
+
# Public: Initialize ThisProject
|
25
|
+
#
|
26
|
+
# Yields self
|
27
|
+
def initialize(&block)
|
28
|
+
@exclude_from_manifest = Regexp.union(/\.(git|DS_Store)/,
|
29
|
+
/^(doc|coverage|pkg|tmp|Gemfile(\.lock)?)/,
|
30
|
+
/^[^\/]+\.gemspec/,
|
31
|
+
/\.(swp|jar|bundle|so|rvmrc|travis.yml)$/,
|
32
|
+
/~$/)
|
33
|
+
@gemspecs = Hash.new
|
34
|
+
yield self if block_given?
|
35
|
+
end
|
36
|
+
|
37
|
+
# Public: return the version of ThisProject
|
38
|
+
#
|
39
|
+
# Search the ruby files in the project looking for the one that has the
|
40
|
+
# version string in it. This does not eval any code in the project, it parses
|
41
|
+
# the source code looking for the string.
|
42
|
+
#
|
43
|
+
# Returns a String version
|
44
|
+
def version
|
45
|
+
[ "lib/#{ name }.rb", "lib/#{ name }/version.rb" ].each do |v|
|
46
|
+
path = project_path( v )
|
47
|
+
next unless path.exist?
|
48
|
+
line = path.read[/^\s*VERSION\s*=\s*.*/i]
|
49
|
+
if line then
|
50
|
+
return line.match(/.*VERSION\s*=\s*['"](.*)['"]/i)[1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Internal: Return a section of an RDoc file with the given section name
|
56
|
+
#
|
57
|
+
# path - the relative path in the project of the file to parse
|
58
|
+
# section_name - the section out of the file from which to parse data
|
59
|
+
#
|
60
|
+
# Retuns the text of the section as an array of paragrphs.
|
61
|
+
def section_of( file, section_name )
|
62
|
+
re = /^[=#]+ (.*)$/
|
63
|
+
sectional = project_path( file )
|
64
|
+
parts = sectional.read.split( re )[1..-1]
|
65
|
+
parts.map! { |p| p.strip }
|
66
|
+
|
67
|
+
sections = Hash.new
|
68
|
+
Hash[*parts].each do |k,v|
|
69
|
+
sections[k] = v.split("\n\n")
|
70
|
+
end
|
71
|
+
return sections[section_name]
|
72
|
+
end
|
73
|
+
|
74
|
+
# Internal: print out a warning about the give task
|
75
|
+
def task_warning( task )
|
76
|
+
warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
|
77
|
+
end
|
78
|
+
|
79
|
+
# Internal: Return the full path to the file that is relative to the project
|
80
|
+
# root.
|
81
|
+
#
|
82
|
+
# path - the relative path of the file from the project root
|
83
|
+
#
|
84
|
+
# Returns the Pathname of the file
|
85
|
+
def project_path( *relative_path )
|
86
|
+
project_root.join( *relative_path )
|
87
|
+
end
|
88
|
+
|
89
|
+
# Internal: The absolute path of this file
|
90
|
+
#
|
91
|
+
# Returns the Pathname of this file.
|
92
|
+
def this_file_path
|
93
|
+
Pathname.new( __FILE__ ).expand_path
|
94
|
+
end
|
95
|
+
|
96
|
+
# Internal: The root directory of this project
|
97
|
+
#
|
98
|
+
# This is defined as being the directory that is in the path of this project
|
99
|
+
# that has the first Rakefile
|
100
|
+
#
|
101
|
+
# Returns the Pathname of the directory
|
102
|
+
def project_root
|
103
|
+
this_file_path.ascend do |p|
|
104
|
+
rakefile = p.join( 'Rakefile' )
|
105
|
+
return p if rakefile.exist?
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Internal: Returns the contents of the Manifest.txt file as an array
|
110
|
+
#
|
111
|
+
# Returns an Array of strings
|
112
|
+
def manifest
|
113
|
+
manifest_file = project_path( "Manifest.txt" )
|
114
|
+
abort "You need a Manifest.txt" unless manifest_file.readable?
|
115
|
+
manifest_file.readlines.map { |l| l.strip }
|
116
|
+
end
|
117
|
+
|
118
|
+
# Internal: Return the files that define the extensions
|
119
|
+
#
|
120
|
+
# Returns an Array
|
121
|
+
def extension_conf_files
|
122
|
+
manifest.grep( /extconf.rb\Z/ )
|
123
|
+
end
|
124
|
+
|
125
|
+
# Internal: Returns the gemspace associated with the current ruby platform
|
126
|
+
def platform_gemspec
|
127
|
+
gemspecs.fetch(platform) { This.ruby_gemspec }
|
128
|
+
end
|
129
|
+
|
130
|
+
def core_gemspec
|
131
|
+
Gem::Specification.new do |spec|
|
132
|
+
spec.name = name
|
133
|
+
spec.version = version
|
134
|
+
spec.author = author
|
135
|
+
spec.email = email
|
136
|
+
spec.homepage = homepage
|
137
|
+
|
138
|
+
spec.summary = summary
|
139
|
+
spec.description = description
|
140
|
+
spec.license = license
|
141
|
+
|
142
|
+
spec.files = manifest
|
143
|
+
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
|
144
|
+
spec.test_files = spec.files.grep(/^spec/)
|
145
|
+
|
146
|
+
spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc|md)$/)
|
147
|
+
spec.rdoc_options = [ "--main" , 'README.md',
|
148
|
+
"--markup", "tomdoc" ]
|
149
|
+
|
150
|
+
spec.required_ruby_version = '>= 2.2.0'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Internal: Return the gemspec for the ruby platform
|
155
|
+
def ruby_gemspec( core = core_gemspec, &block )
|
156
|
+
yielding_gemspec( 'ruby', core, &block )
|
157
|
+
end
|
158
|
+
|
159
|
+
# Internal: Return the gemspec for the jruby platform
|
160
|
+
def java_gemspec( core = core_gemspec, &block )
|
161
|
+
yielding_gemspec( 'java', core, &block )
|
162
|
+
end
|
163
|
+
|
164
|
+
# Internal: give an initial spec and a key, create a new gemspec based off of
|
165
|
+
# it.
|
166
|
+
#
|
167
|
+
# This will force the new gemspecs 'platform' to be that of the key, since the
|
168
|
+
# only reason you would have multiple gemspecs at this point is to deal with
|
169
|
+
# different platforms.
|
170
|
+
def yielding_gemspec( key, core )
|
171
|
+
spec = gemspecs[key] ||= core.dup
|
172
|
+
spec.platform = key
|
173
|
+
yield spec if block_given?
|
174
|
+
return spec
|
175
|
+
end
|
176
|
+
|
177
|
+
# Internal: Return the platform of ThisProject at the current moment in time.
|
178
|
+
def platform
|
179
|
+
(RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
|
180
|
+
end
|
181
|
+
|
182
|
+
# Internal: Return the DESCRIPTION section of the README.rdoc file
|
183
|
+
def description_section
|
184
|
+
section_of( 'README.md', 'DESCRIPTION')
|
185
|
+
end
|
186
|
+
|
187
|
+
# Internal: Return the summary text from the README
|
188
|
+
def summary
|
189
|
+
description_section.first
|
190
|
+
end
|
191
|
+
|
192
|
+
# Internal: Return the full description text from the README
|
193
|
+
def description
|
194
|
+
description_section.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
|
195
|
+
end
|
196
|
+
|
197
|
+
def license
|
198
|
+
"ISC"
|
199
|
+
end
|
200
|
+
|
201
|
+
# Internal: The path to the gemspec file
|
202
|
+
def gemspec_file
|
203
|
+
project_path( "#{ name }.gemspec" )
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
This = ThisProject.new
|
@@ -1,20 +1,12 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
-
|
2
|
+
require './test/test_helper'
|
3
|
+
class LintTest < Dao::TestCase
|
3
4
|
include ActiveModel::Lint::Tests
|
4
5
|
|
5
6
|
class LintConducer < Dao::Conducer; end
|
6
|
-
|
7
|
+
|
7
8
|
def setup
|
8
9
|
@model = LintConducer.new
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
BEGIN {
|
14
|
-
testdir = File.dirname(File.expand_path(__FILE__))
|
15
|
-
rootdir = File.dirname(testdir)
|
16
|
-
libdir = File.join(rootdir, 'lib')
|
17
|
-
|
18
|
-
require File.join(libdir, 'dao')
|
19
|
-
require File.join(testdir, 'testing')
|
20
|
-
}
|
data/test/api_test.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
+
require_relative 'test_helper'
|
2
3
|
|
3
|
-
|
4
|
-
Testing Dao do
|
4
|
+
class DaoTest < ::Dao::TestCase
|
5
5
|
## api
|
6
6
|
#
|
7
|
-
|
7
|
+
test 'that an api class for your application can be built using a simple dsl' do
|
8
8
|
assert{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
9
|
+
Dao.api do
|
10
|
+
### dsl
|
11
|
+
end
|
13
12
|
}
|
14
13
|
end
|
15
14
|
|
16
|
-
|
15
|
+
test 'that apis can have callable endpoints added to them which accept params and return results' do
|
17
16
|
captured = []
|
18
17
|
|
19
18
|
api_class =
|
@@ -29,7 +28,7 @@ Testing Dao do
|
|
29
28
|
assert{ result.is_a?(Hash) }
|
30
29
|
end
|
31
30
|
|
32
|
-
|
31
|
+
test 'that endpoints are automatically called according to arity' do
|
33
32
|
api = assert{ Class.new(Dao.api) }
|
34
33
|
assert{ api.class_eval{ endpoint(:zero){|| result.update :args => [] } } }
|
35
34
|
assert{ api.class_eval{ endpoint(:one){|a| result.update :args => [a]} } }
|
@@ -40,14 +39,14 @@ Testing Dao do
|
|
40
39
|
assert{ api.new.call(:two).args.size == 2 }
|
41
40
|
end
|
42
41
|
|
43
|
-
|
42
|
+
test 'that endpoints have an auto-vivifying params/result' do
|
44
43
|
api = assert{ Class.new(Dao.api) }
|
45
44
|
assert{ api.class_eval{ endpoint(:foo){ params; result; } } }
|
46
45
|
result = assert{ api.new.call(:foo) }
|
47
46
|
assert{ result.path.to_s =~ /foo/ }
|
48
47
|
end
|
49
48
|
|
50
|
-
|
49
|
+
test 'that an api can be called with different modes' do
|
51
50
|
Dao::Mode.list.each do |mode|
|
52
51
|
api_class =
|
53
52
|
assert{
|
@@ -63,7 +62,7 @@ Testing Dao do
|
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
|
65
|
+
test 'that read==get' do
|
67
66
|
api_class =
|
68
67
|
assert{
|
69
68
|
Dao.api do
|
@@ -85,7 +84,7 @@ Testing Dao do
|
|
85
84
|
assert{ api.get.call(:bar).data.answer == 42.0 }
|
86
85
|
end
|
87
86
|
|
88
|
-
|
87
|
+
test 'that write==post' do
|
89
88
|
api_class =
|
90
89
|
assert{
|
91
90
|
Dao.api do
|
@@ -107,7 +106,7 @@ Testing Dao do
|
|
107
106
|
assert{ api.post.call(:bar).data.answer == 42.0 }
|
108
107
|
end
|
109
108
|
|
110
|
-
|
109
|
+
test 'that aliases are re-defined in scope' do
|
111
110
|
api_class =
|
112
111
|
assert{
|
113
112
|
Dao.api do
|
@@ -149,7 +148,7 @@ Testing Dao do
|
|
149
148
|
|
150
149
|
## context
|
151
150
|
#
|
152
|
-
|
151
|
+
test 'that calls have a shortcut to status' do
|
153
152
|
api_class =
|
154
153
|
assert{
|
155
154
|
Dao.api do
|
@@ -163,7 +162,7 @@ Testing Dao do
|
|
163
162
|
|
164
163
|
## results
|
165
164
|
#
|
166
|
-
|
165
|
+
test 'that results can be created' do
|
167
166
|
result = assert{ Dao::Result.new }
|
168
167
|
assert{ result.path }
|
169
168
|
assert{ result.status }
|
@@ -172,14 +171,14 @@ Testing Dao do
|
|
172
171
|
assert{ result.data }
|
173
172
|
end
|
174
173
|
|
175
|
-
|
174
|
+
test 'that results can be created with a path' do
|
176
175
|
result = assert{ Dao::Result.new('/api/foo/bar') }
|
177
176
|
assert{ result.path == '/api/foo/bar' }
|
178
177
|
end
|
179
178
|
|
180
179
|
## paths
|
181
180
|
#
|
182
|
-
|
181
|
+
test 'that simple paths can be contstructed/compiled' do
|
183
182
|
path = assert{ Dao::Path.for('./api/../foo/bar') }
|
184
183
|
assert{ path =~ %r|^/| }
|
185
184
|
assert{ path !~ %r|[.]| }
|
@@ -190,7 +189,7 @@ Testing Dao do
|
|
190
189
|
|
191
190
|
## routes
|
192
191
|
#
|
193
|
-
|
192
|
+
test 'that an api has a list of routes' do
|
194
193
|
api_class =
|
195
194
|
assert{
|
196
195
|
Dao.api do
|
@@ -199,7 +198,7 @@ Testing Dao do
|
|
199
198
|
assert{ api_class.routes.is_a?(Array) }
|
200
199
|
end
|
201
200
|
|
202
|
-
|
201
|
+
test 'that routed endpoints call be declared' do
|
203
202
|
api_class =
|
204
203
|
assert{
|
205
204
|
Dao.api do
|
@@ -208,10 +207,10 @@ Testing Dao do
|
|
208
207
|
end
|
209
208
|
end
|
210
209
|
}
|
211
|
-
|
210
|
+
api_class.new
|
212
211
|
end
|
213
212
|
|
214
|
-
|
213
|
+
test 'that routed methods can be called with embedded params' do
|
215
214
|
api_class =
|
216
215
|
assert{
|
217
216
|
Dao.api do
|
@@ -236,7 +235,7 @@ Testing Dao do
|
|
236
235
|
|
237
236
|
## doc
|
238
237
|
#
|
239
|
-
|
238
|
+
test 'that apis can be documented via the api' do
|
240
239
|
api_class =
|
241
240
|
assert {
|
242
241
|
Dao.api {
|
@@ -253,7 +252,7 @@ Testing Dao do
|
|
253
252
|
|
254
253
|
# aliases
|
255
254
|
#
|
256
|
-
|
255
|
+
test 'that apis can alias methods' do
|
257
256
|
api_class =
|
258
257
|
assert {
|
259
258
|
Dao.api {
|
@@ -274,17 +273,7 @@ protected
|
|
274
273
|
|
275
274
|
def api(&block)
|
276
275
|
api_class = assert{ Dao.api(&block) }
|
277
|
-
|
276
|
+
assert{ api_class.new }
|
278
277
|
end
|
279
278
|
end
|
280
279
|
|
281
|
-
|
282
|
-
BEGIN {
|
283
|
-
testdir = File.dirname(File.expand_path(__FILE__))
|
284
|
-
rootdir = File.dirname(testdir)
|
285
|
-
libdir = File.join(rootdir, 'lib')
|
286
|
-
|
287
|
-
require File.join(libdir, 'dao')
|
288
|
-
require File.join(testdir, 'testing')
|
289
|
-
require File.join(testdir, 'helper')
|
290
|
-
}
|
data/test/conducer_test.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
|
+
require_relative 'test_helper'
|
2
3
|
|
3
|
-
|
4
|
-
Testing Dao::Conducer do
|
4
|
+
class Dao::ConducerTest < Dao::TestCase
|
5
5
|
##
|
6
6
|
#
|
7
7
|
context :teh_ctor do
|
8
8
|
#
|
9
|
-
|
9
|
+
test 'conducers have a POLS .new method' do
|
10
10
|
[
|
11
11
|
{:key => :val, :array => [0,1,2]},
|
12
12
|
{}
|
@@ -17,7 +17,7 @@ Testing Dao::Conducer do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
#
|
20
|
-
|
20
|
+
test 'models passed to .new are automatically tracked' do
|
21
21
|
user = User.new
|
22
22
|
post = Post.new
|
23
23
|
comment = Comment.new
|
@@ -33,7 +33,7 @@ Testing Dao::Conducer do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
#
|
36
|
-
|
36
|
+
test 'that the conduced model can be declared at the class level' do
|
37
37
|
user = User.new
|
38
38
|
post = Post.new
|
39
39
|
comment = Comment.new
|
@@ -49,7 +49,7 @@ Testing Dao::Conducer do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
#
|
52
|
-
|
52
|
+
test 'that the conduced model can be declared at the instance level' do
|
53
53
|
user = User.new
|
54
54
|
post = Post.new
|
55
55
|
comment = Comment.new
|
@@ -71,7 +71,7 @@ Testing Dao::Conducer do
|
|
71
71
|
#
|
72
72
|
context :teh_default_initialize do
|
73
73
|
#
|
74
|
-
|
74
|
+
test 'that the last mode determines the lifecycle state when a models are passed in' do
|
75
75
|
user = User.new
|
76
76
|
post = Post.new
|
77
77
|
comment = Comment.new
|
@@ -92,7 +92,7 @@ Testing Dao::Conducer do
|
|
92
92
|
end
|
93
93
|
|
94
94
|
#
|
95
|
-
|
95
|
+
test 'that passed in models/params are sanely ker-sploded onto the attributes' do
|
96
96
|
user = User.new :k => 1
|
97
97
|
post = Post.new :k => 2
|
98
98
|
comment = Comment.new :k => 3, :x => 4
|
@@ -119,7 +119,7 @@ Testing Dao::Conducer do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
#
|
122
|
-
|
122
|
+
test 'that .new specialises based on current action' do
|
123
123
|
conducer_class =
|
124
124
|
new_conducer_class do
|
125
125
|
def initialize_for_new
|
@@ -145,7 +145,7 @@ Testing Dao::Conducer do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
#
|
148
|
-
|
148
|
+
test 'that conducers can build a highly specialized .new method based on action' do
|
149
149
|
c =
|
150
150
|
new_conducer_class do
|
151
151
|
def initialize(a, b, c, params)
|
@@ -181,7 +181,7 @@ Testing Dao::Conducer do
|
|
181
181
|
end
|
182
182
|
|
183
183
|
#
|
184
|
-
|
184
|
+
test 'that conducers *fold* in attributes' do
|
185
185
|
c = new_conducer
|
186
186
|
|
187
187
|
assert{ c.update_attributes :key => {:a => :b} }
|
@@ -193,7 +193,7 @@ Testing Dao::Conducer do
|
|
193
193
|
#
|
194
194
|
context :teh_default_save do
|
195
195
|
#
|
196
|
-
|
196
|
+
test 'is sane and based solely on the last model' do
|
197
197
|
user = User.new
|
198
198
|
post = Post.new
|
199
199
|
comment = Comment.new
|
@@ -211,7 +211,7 @@ Testing Dao::Conducer do
|
|
211
211
|
end
|
212
212
|
|
213
213
|
#
|
214
|
-
|
214
|
+
test 'halts when the conducer is invalid with errors' do
|
215
215
|
conducer_class =
|
216
216
|
new_conducer_class do
|
217
217
|
validates_presence_of(:foo)
|
@@ -225,7 +225,7 @@ Testing Dao::Conducer do
|
|
225
225
|
end
|
226
226
|
|
227
227
|
#
|
228
|
-
|
228
|
+
test 'halts when the model is invalid and relays errors' do
|
229
229
|
post = Post.new
|
230
230
|
post.errors[:foo] = 'is fucked'
|
231
231
|
c = new_conducer(post)
|
@@ -234,7 +234,7 @@ Testing Dao::Conducer do
|
|
234
234
|
end
|
235
235
|
|
236
236
|
#
|
237
|
-
|
237
|
+
test 'raises a validation error on #save!' do
|
238
238
|
post = Post.new
|
239
239
|
post.errors[:foo] = 'is fucked'
|
240
240
|
c = new_conducer(post)
|
@@ -251,7 +251,7 @@ Testing Dao::Conducer do
|
|
251
251
|
#
|
252
252
|
context :validations do
|
253
253
|
#
|
254
|
-
|
254
|
+
test 'that simple validations/errors work' do
|
255
255
|
c =
|
256
256
|
assert{
|
257
257
|
new_foo_conducer_class do
|
@@ -276,7 +276,7 @@ Testing Dao::Conducer do
|
|
276
276
|
end
|
277
277
|
|
278
278
|
#
|
279
|
-
|
279
|
+
test 'that validations are evaluated in the context of the object' do
|
280
280
|
c =
|
281
281
|
assert{
|
282
282
|
new_foo_conducer_class do
|
@@ -296,7 +296,7 @@ Testing Dao::Conducer do
|
|
296
296
|
end
|
297
297
|
|
298
298
|
#
|
299
|
-
|
299
|
+
test 'that validates_each werks at the class and instance level' do
|
300
300
|
conducer_class =
|
301
301
|
new_conducer_class do
|
302
302
|
validates_each :a do |item|
|
@@ -335,7 +335,7 @@ Testing Dao::Conducer do
|
|
335
335
|
#
|
336
336
|
context :forms do
|
337
337
|
#
|
338
|
-
|
338
|
+
test 'that basic form helpers work' do
|
339
339
|
c =
|
340
340
|
assert{
|
341
341
|
new_foo_conducer_class do
|
@@ -357,12 +357,12 @@ Testing Dao::Conducer do
|
|
357
357
|
#
|
358
358
|
context :class_methods do
|
359
359
|
#
|
360
|
-
|
360
|
+
test 'that base classes can be constructed and named' do
|
361
361
|
new_foo_conducer_class()
|
362
362
|
end
|
363
363
|
|
364
364
|
#
|
365
|
-
|
365
|
+
test '.new' do
|
366
366
|
c = assert{ new_foo_conducer_class }
|
367
367
|
controller = assert{ Dao.mock_controller }
|
368
368
|
|
@@ -386,7 +386,7 @@ Testing Dao::Conducer do
|
|
386
386
|
end
|
387
387
|
|
388
388
|
#
|
389
|
-
|
389
|
+
test '.model_name' do
|
390
390
|
c = assert{ new_foo_conducer_class }
|
391
391
|
assert{ c.model_name }
|
392
392
|
o = assert{ c.new }
|
@@ -397,7 +397,7 @@ Testing Dao::Conducer do
|
|
397
397
|
##
|
398
398
|
#
|
399
399
|
context :instance_methods do
|
400
|
-
|
400
|
+
test '#id' do
|
401
401
|
[:_id, :id].each do |id_key|
|
402
402
|
o = assert{ new_foo_conducer() }
|
403
403
|
assert{ o.id.nil? }
|
@@ -410,20 +410,20 @@ Testing Dao::Conducer do
|
|
410
410
|
end
|
411
411
|
end
|
412
412
|
|
413
|
-
|
413
|
+
test '#to_param' do
|
414
414
|
o = assert{ new_foo_conducer() }
|
415
415
|
assert{ o.to_param.nil? }
|
416
416
|
o.id = 42
|
417
417
|
assert{ o.to_param }
|
418
418
|
end
|
419
419
|
|
420
|
-
|
420
|
+
test '#errors' do
|
421
421
|
o = assert{ new_foo_conducer() }
|
422
422
|
assert{ o.errors.respond_to?(:[]) }
|
423
423
|
end
|
424
424
|
|
425
425
|
=begin
|
426
|
-
|
426
|
+
test 'that conducers can register handlers for setting deeply nested attributes' do
|
427
427
|
c =
|
428
428
|
new_conducer_class do
|
429
429
|
def _update_attributes(attributes = {})
|
@@ -454,7 +454,7 @@ Testing Dao::Conducer do
|
|
454
454
|
#
|
455
455
|
context :teh_mount do
|
456
456
|
#
|
457
|
-
|
457
|
+
test 'that mounted objects can be declared at the class level' do
|
458
458
|
conducer_class =
|
459
459
|
new_conducer_class do
|
460
460
|
mount Dao::Upload, :a, :b, :placeholder => '/images/foo.jpg'
|
@@ -470,7 +470,7 @@ Testing Dao::Conducer do
|
|
470
470
|
end
|
471
471
|
|
472
472
|
#
|
473
|
-
|
473
|
+
test 'that mounted objects replace their location in attributes' do
|
474
474
|
conducer_class =
|
475
475
|
new_conducer_class do
|
476
476
|
mount Dao::Upload, :a, :b, :placeholder => '/images/foo.jpg'
|
@@ -488,7 +488,7 @@ Testing Dao::Conducer do
|
|
488
488
|
end
|
489
489
|
|
490
490
|
#
|
491
|
-
|
491
|
+
test 'that the default save uses the mounted _value and _clears it' do
|
492
492
|
begin
|
493
493
|
$pry=true
|
494
494
|
conducer_class =
|
@@ -498,7 +498,7 @@ $pry=true
|
|
498
498
|
|
499
499
|
path = File.join(File.dirname(__FILE__), 'data/han-solo.jpg')
|
500
500
|
assert{ test(?s, path) }
|
501
|
-
|
501
|
+
_up = Upload.new(path)
|
502
502
|
comment = Comment.new
|
503
503
|
|
504
504
|
c = conducer_class.new( comment, :up => {:file => Upload.new(path)} )
|
@@ -512,8 +512,8 @@ $pry=true
|
|
512
512
|
|
513
513
|
assert{ c.save }
|
514
514
|
|
515
|
-
|
516
|
-
|
515
|
+
_value_was_relayed = assert{ comment.attributes[:up] == upload._value }
|
516
|
+
_value_was_cleared = assert{ !test(?f, upload.path) }
|
517
517
|
|
518
518
|
assert{ test(?s, path) }
|
519
519
|
ensure
|
@@ -525,7 +525,7 @@ end
|
|
525
525
|
##
|
526
526
|
#
|
527
527
|
context :collections do
|
528
|
-
|
528
|
+
test 'can be created from page-y blessed arrays' do
|
529
529
|
paginated = Paginated[Post.new, Post.new, Post.new]
|
530
530
|
paginated.limit = 42
|
531
531
|
paginated.offset = 42.0
|
@@ -551,7 +551,7 @@ end
|
|
551
551
|
##
|
552
552
|
#
|
553
553
|
context :callbacks do
|
554
|
-
|
554
|
+
test 'can be added lazily in an ad-hoc fashion' do
|
555
555
|
callbacks = []
|
556
556
|
|
557
557
|
conducer_class =
|
@@ -602,7 +602,7 @@ protected
|
|
602
602
|
end
|
603
603
|
alias_method :new_conducer, :new_foo_conducer
|
604
604
|
|
605
|
-
|
605
|
+
def setup
|
606
606
|
$db = Dao::Db.new(:path => 'test/db.yml')
|
607
607
|
Dao::Db.instance = $db
|
608
608
|
collection = $db['foos']
|
@@ -613,7 +613,7 @@ protected
|
|
613
613
|
end
|
614
614
|
end
|
615
615
|
|
616
|
-
|
616
|
+
def teardown
|
617
617
|
$db = Dao::Db.new(:path => 'test/db.yml')
|
618
618
|
$db.rm_f
|
619
619
|
end
|
@@ -705,7 +705,7 @@ protected
|
|
705
705
|
|
706
706
|
def method_missing(method, *args, &block)
|
707
707
|
re = /^([^=!?]+)([=!?])?$/imox
|
708
|
-
|
708
|
+
_matched, key, suffix = re.match(method.to_s).to_a
|
709
709
|
|
710
710
|
case suffix
|
711
711
|
when '=' then attributes.set(key, args.first)
|
@@ -758,13 +758,3 @@ protected
|
|
758
758
|
class Comment < Model
|
759
759
|
end
|
760
760
|
end
|
761
|
-
|
762
|
-
|
763
|
-
BEGIN {
|
764
|
-
testdir = File.dirname(File.expand_path(__FILE__))
|
765
|
-
rootdir = File.dirname(testdir)
|
766
|
-
libdir = File.join(rootdir, 'lib')
|
767
|
-
require File.join(libdir, 'dao')
|
768
|
-
require File.join(testdir, 'testing')
|
769
|
-
require 'stringio'
|
770
|
-
}
|