dao 5.5.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +6 -14
  2. data/README.md +258 -0
  3. data/Rakefile +4 -5
  4. data/coerce-0.0.8/README +28 -0
  5. data/coerce-0.0.8/Rakefile +392 -0
  6. data/coerce-0.0.8/coerce.gemspec +31 -0
  7. data/coerce-0.0.8/lib/coerce.rb +210 -0
  8. data/dao.gemspec +38 -25
  9. data/lib/dao.rb +18 -81
  10. data/lib/dao/_lib.rb +42 -0
  11. data/lib/dao/active_record.rb +8 -8
  12. data/lib/dao/api/call.rb +19 -4
  13. data/lib/dao/api/dsl.rb +1 -1
  14. data/lib/dao/coerce.rb +211 -0
  15. data/lib/dao/conducer.rb +10 -14
  16. data/lib/dao/conducer/controller_support.rb +5 -0
  17. data/lib/dao/conducer/view_support.rb +0 -2
  18. data/lib/dao/db.rb +0 -1
  19. data/lib/dao/errors.rb +17 -11
  20. data/lib/dao/errors2html.rb +128 -0
  21. data/lib/dao/form.rb +13 -16
  22. data/lib/dao/messages.rb +0 -4
  23. data/lib/dao/path.rb +1 -1
  24. data/lib/dao/route.rb +2 -2
  25. data/lib/dao/status.rb +3 -4
  26. data/lib/dao/support.rb +26 -19
  27. data/lib/dao/upload.rb +0 -1
  28. data/lib/dao/validations/common.rb +6 -6
  29. data/lib/dao/validations/validator.rb +3 -3
  30. data/lib/dao/wrap.rb +259 -0
  31. data/tasks/default.rake +207 -0
  32. data/tasks/this.rb +207 -0
  33. data/test/active_model_conducer_lint_test.rb +3 -11
  34. data/test/api_test.rb +24 -35
  35. data/test/conducer_test.rb +37 -47
  36. data/test/errors_test.rb +29 -13
  37. data/test/form_test.rb +24 -34
  38. data/test/rake_rerun_reporter.rb +74 -0
  39. data/test/support_test.rb +9 -14
  40. data/test/test_helper.rb +220 -0
  41. data/test/{helper.rb → util.rb} +0 -0
  42. data/test/validations_test.rb +14 -28
  43. data/wrap-1.5.2/README +57 -0
  44. data/wrap-1.5.2/Rakefile +394 -0
  45. data/wrap-1.5.2/lib/wrap.rb +295 -0
  46. data/{test → wrap-1.5.2/test}/testing.rb +0 -1
  47. data/wrap-1.5.2/test/wrap_test.rb +397 -0
  48. data/wrap-1.5.2/wrap.gemspec +38 -0
  49. metadata +47 -103
  50. data/Gemfile +0 -16
  51. data/Gemfile.lock +0 -118
  52. data/README +0 -256
File without changes
@@ -1,8 +1,9 @@
1
1
  # -*- encoding : utf-8 -*-
2
- Testing Dao::Validations do
2
+ require_relative 'test_helper'
3
+ class DaoValidationsTest < ::Dao::TestCase
3
4
  ## status
4
5
  #
5
- testing 'Status.for' do
6
+ test 'Status.for' do
6
7
  assert{ Dao::Status.for(:unauthorized).code == 401 }
7
8
  assert{ Dao::Status.for(:UNAUTHORIZED).code == 401 }
8
9
  assert{ Dao::Status.for('unauthorized').code == 401 }
@@ -13,7 +14,7 @@ Testing Dao::Validations do
13
14
  assert{ Dao::Status.for(:no_content).code == 204 }
14
15
  end
15
16
 
16
- testing 'status equality operator' do
17
+ test 'status equality operator' do
17
18
  s = Dao::Status.for(401)
18
19
  assert{ s == :unauthorized }
19
20
  assert{ s == 401 }
@@ -22,7 +23,7 @@ Testing Dao::Validations do
22
23
 
23
24
  ## errors
24
25
  #
25
- testing 'that errors can relay from other each-able sources' do
26
+ test 'that errors can relay from other each-able sources' do
26
27
  errors = Dao::Errors.new
27
28
 
28
29
  messages = [
@@ -63,16 +64,14 @@ Testing Dao::Validations do
63
64
 
64
65
  ## validations
65
66
  #
66
- testing 'that simple validations work' do
67
+ test 'that simple validations work' do
67
68
  params = Dao::Params.new
68
69
  assert{ params.validates(:password){|password| password=='haxor'} }
69
70
  params.set(:password, 'haxor')
70
71
  assert{ params.valid? }
71
72
  end
72
73
 
73
- testing 'that validations have some syntax sugar' do
74
- return :pending
75
-
74
+ test 'that validations have some syntax sugar' do
76
75
  assert{
77
76
  api_class =
78
77
  Dao.api do
@@ -92,9 +91,7 @@ Testing Dao::Validations do
92
91
  }
93
92
  end
94
93
 
95
- testing 'that validations use instance_exec - as god intended' do
96
- return :pending
97
-
94
+ test 'that validations use instance_exec - as god intended' do
98
95
  a, b = nil
99
96
 
100
97
  api_class =
@@ -113,9 +110,10 @@ Testing Dao::Validations do
113
110
  assert{ b == 2 }
114
111
  end
115
112
 
116
- testing 'simple validates_confirmation_of' do
113
+ test 'simple validates_confirmation_of' do
114
+ =begin
117
115
  return :pending
118
-
116
+ =end
119
117
  api_class =
120
118
  Dao.api do
121
119
  endpoint('/foobar'){
@@ -137,9 +135,8 @@ Testing Dao::Validations do
137
135
 
138
136
  ## validating
139
137
  #
140
- testing 'that validations clear only that which they know about' do
138
+ test 'that validations clear only that which they know about' do
141
139
  params = Dao::Params.new
142
- errors = params.errors
143
140
 
144
141
  assert{ params.validates(:email){|email| email.to_s.split(/@/).size == 2} }
145
142
  assert{ params.validates(:password){|password| password == 'pa$$w0rd'} }
@@ -173,7 +170,7 @@ Testing Dao::Validations do
173
170
 
174
171
  ## stand alone validations
175
172
  #
176
- testing 'that validations can be used standalone' do
173
+ test 'that validations can be used standalone' do
177
174
  attributes = {
178
175
  :email => 'ara@dojo4.com',
179
176
  :password => 'pa$$w0rd'
@@ -191,7 +188,7 @@ Testing Dao::Validations do
191
188
 
192
189
  ## prefixed validations
193
190
  #
194
- testing 'nested validations' do
191
+ test 'nested validations' do
195
192
  #
196
193
  attributes = {
197
194
  :list => [
@@ -310,14 +307,3 @@ Testing Dao::Validations do
310
307
  assert{ !v.errors.on(:users, 1, :roles, 0, :missing).blank? }
311
308
  end
312
309
  end
313
-
314
-
315
- BEGIN {
316
- testdir = File.dirname(File.expand_path(__FILE__))
317
- rootdir = File.dirname(testdir)
318
- libdir = File.join(rootdir, 'lib')
319
-
320
- require File.join(libdir, 'dao')
321
- require File.join(testdir, 'testing')
322
- require File.join(testdir, 'helper')
323
- }
@@ -0,0 +1,57 @@
1
+ NAME
2
+ wrap
3
+
4
+ SYNOPSIS
5
+ non-sucking :before and :after filters for any ruby class
6
+
7
+ DESCRIPTION
8
+ yes yes, active_support does this. but crapily. with active_support you'll
9
+ need to do this
10
+
11
+
12
+ class Record
13
+ include ActiveSupport::Callbacks
14
+ define_callbacks :save
15
+
16
+ def save
17
+ run_callbacks :save do
18
+ puts "- save"
19
+ end
20
+ end
21
+ end
22
+
23
+ but hey, if a subclass forgets to call 'super' or doesn't manually run
24
+ 'run_callbacks' the codez are *screwed*. that sux. why not this?
25
+
26
+
27
+ class Record
28
+ include Wrap
29
+
30
+ wrap :save
31
+ end
32
+
33
+
34
+ yes, it's that simple. you can now do
35
+
36
+ class SubRecord < Record
37
+ before :save do
38
+ special_sauce
39
+ end
40
+
41
+ def save
42
+ no_special_sauce
43
+ end
44
+ end
45
+
46
+ did you get that? the :before and :after hooks will be called no matter
47
+ what the subclass does. the method will be wrapped, period. no special
48
+ work required. of course, if the sublcass messes with 'method_added' their
49
+ will be hell to pay. that's the price for simplicity.
50
+
51
+ the callbacks are very close, but not identical to active_supports. you can
52
+ return 'false' to halt the chain, but you can also simply call 'halt!'.
53
+ another neat trick is that :before callbacks will be called with the
54
+ arguments to the wrapped method itself iff possible and :after callbacks
55
+ will be called with the result of the wrapped method, iff possible.
56
+
57
+ the test suite reads pretty damn clean. have a go.
@@ -0,0 +1,394 @@
1
+ This.rubyforge_project = 'codeforpeople'
2
+ This.author = "Ara T. Howard"
3
+ This.email = "ara.t.howard@gmail.com"
4
+ This.homepage = "https://github.com/ahoward/#{ This.lib }"
5
+
6
+ task :license do
7
+ open('LICENSE', 'w'){|fd| fd.puts "same as ruby's"}
8
+ end
9
+
10
+ task :default do
11
+ puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
12
+ end
13
+
14
+ task :test do
15
+ run_tests!
16
+ end
17
+
18
+ namespace :test do
19
+ task(:unit){ run_tests!(:unit) }
20
+ task(:functional){ run_tests!(:functional) }
21
+ task(:integration){ run_tests!(:integration) }
22
+ end
23
+
24
+ def run_tests!(which = nil)
25
+ which ||= '**'
26
+ test_dir = File.join(This.dir, "test")
27
+ test_glob ||= File.join(test_dir, "#{ which }/**_test.rb")
28
+ test_rbs = Dir.glob(test_glob).sort
29
+
30
+ div = ('=' * 119)
31
+ line = ('-' * 119)
32
+
33
+ test_rbs.each_with_index do |test_rb, index|
34
+ testno = index + 1
35
+ command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
36
+
37
+ puts
38
+ say(div, :color => :cyan, :bold => true)
39
+ say("@#{ testno } => ", :bold => true, :method => :print)
40
+ say(command, :color => :cyan, :bold => true)
41
+ say(line, :color => :cyan, :bold => true)
42
+
43
+ system(command)
44
+
45
+ say(line, :color => :cyan, :bold => true)
46
+
47
+ status = $?.exitstatus
48
+
49
+ if status.zero?
50
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
51
+ say("SUCCESS", :color => :green, :bold => true)
52
+ else
53
+ say("@#{ testno } <= ", :bold => true, :color => :white, :method => :print)
54
+ say("FAILURE", :color => :red, :bold => true)
55
+ end
56
+ say(line, :color => :cyan, :bold => true)
57
+
58
+ exit(status) unless status.zero?
59
+ end
60
+ end
61
+
62
+
63
+ task :gemspec do
64
+ ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
65
+ ignore_directories = ['pkg']
66
+ ignore_files = ['test/log']
67
+
68
+ shiteless =
69
+ lambda do |list|
70
+ list.delete_if do |entry|
71
+ next unless test(?e, entry)
72
+ extension = File.basename(entry).split(%r/[.]/).last
73
+ ignore_extensions.any?{|ext| ext === extension}
74
+ end
75
+ list.delete_if do |entry|
76
+ next unless test(?d, entry)
77
+ dirname = File.expand_path(entry)
78
+ ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
79
+ end
80
+ list.delete_if do |entry|
81
+ next unless test(?f, entry)
82
+ filename = File.expand_path(entry)
83
+ ignore_files.any?{|file| File.expand_path(file) == filename}
84
+ end
85
+ end
86
+
87
+ lib = This.lib
88
+ object = This.object
89
+ version = This.version
90
+ files = shiteless[Dir::glob("**/**")]
91
+ executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
92
+ #has_rdoc = true #File.exist?('doc')
93
+ test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
94
+ summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
95
+ description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
96
+ license = object.respond_to?(:license) ? object.license : "same as ruby's"
97
+
98
+ if This.extensions.nil?
99
+ This.extensions = []
100
+ extensions = This.extensions
101
+ %w( Makefile configure extconf.rb ).each do |ext|
102
+ extensions << ext if File.exists?(ext)
103
+ end
104
+ end
105
+ extensions = [extensions].flatten.compact
106
+
107
+ if This.dependencies.nil?
108
+ dependencies = []
109
+ else
110
+ case This.dependencies
111
+ when Hash
112
+ dependencies = This.dependencies.values
113
+ when Array
114
+ dependencies = This.dependencies
115
+ end
116
+ end
117
+
118
+ template =
119
+ if test(?e, 'gemspec.erb')
120
+ Template{ IO.read('gemspec.erb') }
121
+ else
122
+ Template {
123
+ <<-__
124
+ ## <%= lib %>.gemspec
125
+ #
126
+
127
+ Gem::Specification::new do |spec|
128
+ spec.name = <%= lib.inspect %>
129
+ spec.version = <%= version.inspect %>
130
+ spec.platform = Gem::Platform::RUBY
131
+ spec.summary = <%= lib.inspect %>
132
+ spec.description = <%= description.inspect %>
133
+ spec.license = <%= license.inspect %>
134
+
135
+ spec.files =\n<%= files.sort.pretty_inspect %>
136
+ spec.executables = <%= executables.inspect %>
137
+
138
+ spec.require_path = "lib"
139
+
140
+ spec.test_files = <%= test_files.inspect %>
141
+
142
+ <% dependencies.each do |lib_version| %>
143
+ spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
144
+ <% end %>
145
+
146
+ spec.extensions.push(*<%= extensions.inspect %>)
147
+
148
+ spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
149
+ spec.author = <%= This.author.inspect %>
150
+ spec.email = <%= This.email.inspect %>
151
+ spec.homepage = <%= This.homepage.inspect %>
152
+ end
153
+ __
154
+ }
155
+ end
156
+
157
+ Fu.mkdir_p(This.pkgdir)
158
+ gemspec = "#{ lib }.gemspec"
159
+ open(gemspec, "w"){|fd| fd.puts(template)}
160
+ This.gemspec = gemspec
161
+ end
162
+
163
+ task :gem => [:clean, :gemspec] do
164
+ Fu.mkdir_p(This.pkgdir)
165
+ before = Dir['*.gem']
166
+ cmd = "gem build #{ This.gemspec }"
167
+ `#{ cmd }`
168
+ after = Dir['*.gem']
169
+ gem = ((after - before).first || after.first) or abort('no gem!')
170
+ Fu.mv(gem, This.pkgdir)
171
+ This.gem = File.join(This.pkgdir, File.basename(gem))
172
+ end
173
+
174
+ task :readme do
175
+ samples = ''
176
+ prompt = '~ > '
177
+ lib = This.lib
178
+ version = This.version
179
+
180
+ Dir['sample*/*'].sort.each do |sample|
181
+ samples << "\n" << " <========< #{ sample } >========>" << "\n\n"
182
+
183
+ cmd = "cat #{ sample }"
184
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
185
+ samples << Util.indent(`#{ cmd }`, 4) << "\n"
186
+
187
+ cmd = "ruby #{ sample }"
188
+ samples << Util.indent(prompt + cmd, 2) << "\n\n"
189
+
190
+ cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -I ./lib #{ sample })'"
191
+ samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
192
+ end
193
+
194
+ template =
195
+ if test(?e, 'README.erb')
196
+ Template{ IO.read('README.erb') }
197
+ else
198
+ Template {
199
+ <<-__
200
+ NAME
201
+ #{ lib }
202
+
203
+ DESCRIPTION
204
+
205
+ INSTALL
206
+ gem install #{ lib }
207
+
208
+ SAMPLES
209
+ #{ samples }
210
+ __
211
+ }
212
+ end
213
+
214
+ open("README", "w"){|fd| fd.puts template}
215
+ end
216
+
217
+
218
+ task :clean do
219
+ Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
220
+ end
221
+
222
+
223
+ task :release => [:clean, :gemspec, :gem] do
224
+ gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
225
+ raise "which one? : #{ gems.inspect }" if gems.size > 1
226
+ raise "no gems?" if gems.size < 1
227
+
228
+ cmd = "gem push #{ This.gem }"
229
+ puts cmd
230
+ puts
231
+ system(cmd)
232
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
233
+
234
+ cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.gem }"
235
+ puts cmd
236
+ puts
237
+ system(cmd)
238
+ abort("cmd(#{ cmd }) failed with (#{ $?.inspect })") unless $?.exitstatus.zero?
239
+ end
240
+
241
+
242
+
243
+
244
+
245
+ BEGIN {
246
+ # support for this rakefile
247
+ #
248
+ $VERBOSE = nil
249
+
250
+ require 'ostruct'
251
+ require 'erb'
252
+ require 'fileutils'
253
+ require 'rbconfig'
254
+ require 'pp'
255
+
256
+ # fu shortcut
257
+ #
258
+ Fu = FileUtils
259
+
260
+ # cache a bunch of stuff about this rakefile/environment
261
+ #
262
+ This = OpenStruct.new
263
+
264
+ This.file = File.expand_path(__FILE__)
265
+ This.dir = File.dirname(This.file)
266
+ This.pkgdir = File.join(This.dir, 'pkg')
267
+
268
+ # grok lib
269
+ #
270
+ lib = ENV['LIB']
271
+ unless lib
272
+ lib = File.basename(Dir.pwd).sub(/[-].*$/, '')
273
+ end
274
+ This.lib = lib
275
+
276
+ # grok version
277
+ #
278
+ version = ENV['VERSION']
279
+ unless version
280
+ require "./lib/#{ This.lib }"
281
+ This.name = lib.capitalize
282
+ This.object = eval(This.name)
283
+ version = This.object.send(:version)
284
+ end
285
+ This.version = version
286
+
287
+ # see if dependencies are export by the module
288
+ #
289
+ if This.object.respond_to?(:dependencies)
290
+ This.dependencies = This.object.dependencies
291
+ end
292
+
293
+ # we need to know the name of the lib an it's version
294
+ #
295
+ abort('no lib') unless This.lib
296
+ abort('no version') unless This.version
297
+
298
+ # discover full path to this ruby executable
299
+ #
300
+ c = Config::CONFIG
301
+ bindir = c["bindir"] || c['BINDIR']
302
+ ruby_install_name = c['ruby_install_name'] || c['RUBY_INSTALL_NAME'] || 'ruby'
303
+ ruby_ext = c['EXEEXT'] || ''
304
+ ruby = File.join(bindir, (ruby_install_name + ruby_ext))
305
+ This.ruby = ruby
306
+
307
+ # some utils
308
+ #
309
+ module Util
310
+ def indent(s, n = 2)
311
+ s = unindent(s)
312
+ ws = ' ' * n
313
+ s.gsub(%r/^/, ws)
314
+ end
315
+
316
+ def unindent(s)
317
+ indent = nil
318
+ s.each_line do |line|
319
+ next if line =~ %r/^\s*$/
320
+ indent = line[%r/^\s*/] and break
321
+ end
322
+ indent ? s.gsub(%r/^#{ indent }/, "") : s
323
+ end
324
+ extend self
325
+ end
326
+
327
+ # template support
328
+ #
329
+ class Template
330
+ def initialize(&block)
331
+ @block = block
332
+ @template = block.call.to_s
333
+ end
334
+ def expand(b=nil)
335
+ ERB.new(Util.unindent(@template)).result((b||@block).binding)
336
+ end
337
+ alias_method 'to_s', 'expand'
338
+ end
339
+ def Template(*args, &block) Template.new(*args, &block) end
340
+
341
+ # colored console output support
342
+ #
343
+ This.ansi = {
344
+ :clear => "\e[0m",
345
+ :reset => "\e[0m",
346
+ :erase_line => "\e[K",
347
+ :erase_char => "\e[P",
348
+ :bold => "\e[1m",
349
+ :dark => "\e[2m",
350
+ :underline => "\e[4m",
351
+ :underscore => "\e[4m",
352
+ :blink => "\e[5m",
353
+ :reverse => "\e[7m",
354
+ :concealed => "\e[8m",
355
+ :black => "\e[30m",
356
+ :red => "\e[31m",
357
+ :green => "\e[32m",
358
+ :yellow => "\e[33m",
359
+ :blue => "\e[34m",
360
+ :magenta => "\e[35m",
361
+ :cyan => "\e[36m",
362
+ :white => "\e[37m",
363
+ :on_black => "\e[40m",
364
+ :on_red => "\e[41m",
365
+ :on_green => "\e[42m",
366
+ :on_yellow => "\e[43m",
367
+ :on_blue => "\e[44m",
368
+ :on_magenta => "\e[45m",
369
+ :on_cyan => "\e[46m",
370
+ :on_white => "\e[47m"
371
+ }
372
+ def say(phrase, *args)
373
+ options = args.last.is_a?(Hash) ? args.pop : {}
374
+ options[:color] = args.shift.to_s.to_sym unless args.empty?
375
+ keys = options.keys
376
+ keys.each{|key| options[key.to_s.to_sym] = options.delete(key)}
377
+
378
+ color = options[:color]
379
+ bold = options.has_key?(:bold)
380
+
381
+ parts = [phrase]
382
+ parts.unshift(This.ansi[color]) if color
383
+ parts.unshift(This.ansi[:bold]) if bold
384
+ parts.push(This.ansi[:clear]) if parts.size > 1
385
+
386
+ method = options[:method] || :puts
387
+
388
+ Kernel.send(method, parts.join)
389
+ end
390
+
391
+ # always run out of the project dir
392
+ #
393
+ Dir.chdir(This.dir)
394
+ }