gorp 0.12.0 → 0.13.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/gorp.gemspec +2 -2
- data/lib/gorp.rb +38 -28
- data/lib/version.rb +1 -1
- metadata +2 -2
data/gorp.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{gorp}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.13.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sam Ruby"]
|
9
|
-
s.date = %q{2009-12-
|
9
|
+
s.date = %q{2009-12-12}
|
10
10
|
s.description = %q{ Enables the creation of scenarios that involve creating a rails project,
|
11
11
|
starting and stoppping of servers, generating projects, editing files,
|
12
12
|
issuing http requests, running of commands, etc. Output is captured as
|
data/lib/gorp.rb
CHANGED
@@ -10,6 +10,7 @@ require 'builder'
|
|
10
10
|
require 'stringio'
|
11
11
|
require 'gorp/env'
|
12
12
|
require 'time'
|
13
|
+
require 'cgi'
|
13
14
|
|
14
15
|
require 'rbconfig'
|
15
16
|
$ruby = File.join(Config::CONFIG["bindir"], Config::CONFIG["RUBY_INSTALL_NAME"])
|
@@ -200,7 +201,6 @@ def irb file
|
|
200
201
|
end
|
201
202
|
|
202
203
|
def edit filename, tag=nil
|
203
|
-
log :edit, filename
|
204
204
|
$x.pre "edit #{filename}", :class=>'stdin'
|
205
205
|
|
206
206
|
stale = File.mtime(filename) rescue Time.now-2
|
@@ -209,6 +209,10 @@ def edit filename, tag=nil
|
|
209
209
|
|
210
210
|
begin
|
211
211
|
yield data
|
212
|
+
|
213
|
+
now = Time.now
|
214
|
+
usec = now.usec/1000000.0
|
215
|
+
sleep 1-usec if now-usec <= stale
|
212
216
|
open(filename,'w') {|file| file.write data}
|
213
217
|
File.utime(stale+2, stale+2, filename) if File.mtime(filename) <= stale
|
214
218
|
|
@@ -221,6 +225,8 @@ def edit filename, tag=nil
|
|
221
225
|
tag = nil
|
222
226
|
|
223
227
|
ensure
|
228
|
+
log :edit, filename
|
229
|
+
|
224
230
|
include = tag.nil?
|
225
231
|
hilight = false
|
226
232
|
data.split("\n").each do |line|
|
@@ -413,7 +419,7 @@ def snap response, form={}
|
|
413
419
|
$x << child.to_xml unless child.instance_of?(Comment)
|
414
420
|
end
|
415
421
|
end
|
416
|
-
$x.div :style => "clear: both"
|
422
|
+
$x.div '', :style => "clear: both"
|
417
423
|
end
|
418
424
|
|
419
425
|
def get path
|
@@ -439,28 +445,36 @@ def post path, form, options={}
|
|
439
445
|
if ! form.empty?
|
440
446
|
body = xhtmlparse(response.body).at('//body')
|
441
447
|
body = xhtmlparse(response.body).root unless body
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
query =
|
448
|
-
|
449
|
-
query.all? {|kv| element.attribute('action').to_s =~ kv}
|
450
|
-
end
|
448
|
+
xforms = body.search('//form')
|
449
|
+
|
450
|
+
# find matching button by action
|
451
|
+
xform = xforms.find do |element|
|
452
|
+
next unless element.attribute('action').to_s.include?('?')
|
453
|
+
query = CGI.parse(URI.parse(element.attribute('action').to_s).query)
|
454
|
+
query.all? {|key,values| values.include?(form[key].to_s)}
|
451
455
|
end
|
452
456
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
@value=#{value.inspect}]")
|
457
|
+
# find matching button by input names
|
458
|
+
xform ||= xforms.find do |element|
|
459
|
+
form.all? do |name, value|
|
460
|
+
element.search('.//input | .//textarea | ..//select').any? do |input|
|
461
|
+
input.attribute('name').to_s==name.to_s
|
459
462
|
end
|
460
463
|
end
|
461
464
|
end
|
462
465
|
|
466
|
+
# match based on action itself
|
467
|
+
xform ||= xforms.find do |element|
|
468
|
+
form.all? do |name, value|
|
469
|
+
element.attribute('action').to_s.include?(path)
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
# look for a commit button
|
474
|
+
xform ||= xforms.find {|element| element.at('.//input[@name="commit"]')}
|
475
|
+
|
463
476
|
return unless xform
|
477
|
+
|
464
478
|
path = xform.attribute('action').to_s unless
|
465
479
|
xform.attribute('action').to_s.empty?
|
466
480
|
$x.pre "post #{path}", :class=>'stdin'
|
@@ -469,10 +483,11 @@ def post path, form, options={}
|
|
469
483
|
form.each do |name, value|
|
470
484
|
$x.li "#{name} => #{value}"
|
471
485
|
end
|
472
|
-
end
|
473
486
|
|
474
|
-
|
475
|
-
|
487
|
+
xform.search('.//input[@type="hidden"]').each do |element|
|
488
|
+
# $x.li "#{element['name']} => #{element['value']}"
|
489
|
+
form[element['name']] ||= element['value']
|
490
|
+
end
|
476
491
|
end
|
477
492
|
|
478
493
|
post = Net::HTTP::Post.new(path)
|
@@ -605,6 +620,7 @@ def secinclude ranges, section
|
|
605
620
|
end
|
606
621
|
|
607
622
|
at_exit do
|
623
|
+
$x.declare! :DOCTYPE, :html
|
608
624
|
$x.html :xmlns => 'http://www.w3.org/1999/xhtml' do
|
609
625
|
$x.header do
|
610
626
|
$x.title $title
|
@@ -743,15 +759,9 @@ at_exit do
|
|
743
759
|
$x.target!.sub! /<ul class="todos"\/>/,
|
744
760
|
"<ul class=\"todos\">\n#{$todos.target!.gsub(/^/,' '*6)} </ul>"
|
745
761
|
$x.target!.gsub! '<strong/>', '<strong></strong>'
|
762
|
+
$x.target!.gsub! /(<textarea[^>]+)\/>/, '\1></textarea>'
|
746
763
|
log :WRITE, "#{$output}.html"
|
747
|
-
open("#{$WORK}/#{$output}.html",'w')
|
748
|
-
file.write <<-EOF.unindent(6)
|
749
|
-
<!DOCTYPE html
|
750
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
751
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
752
|
-
EOF
|
753
|
-
file.write $x.target!
|
754
|
-
end
|
764
|
+
open("#{$WORK}/#{$output}.html",'w') { |file| file.write $x.target! }
|
755
765
|
|
756
766
|
# run tests
|
757
767
|
if $checker
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gorp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-12 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|