scout-camp 0.1.13 → 0.1.14
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 +4 -4
- data/.vimproject +52 -11
- data/Rakefile +5 -0
- data/VERSION +1 -1
- data/bin/scout-camp +46 -0
- data/doc/terraform.md +188 -0
- data/lib/scout/aws/s3.rb +6 -4
- data/lib/scout/offsite/resource.rb +110 -5
- data/lib/scout/offsite/step.rb +21 -14
- data/lib/scout/offsite/sync.rb +38 -10
- data/lib/scout/offsite.rb +1 -0
- data/lib/scout/render/engine.rb +119 -0
- data/lib/scout/render/helpers.rb +92 -0
- data/lib/scout/render/resource.rb +54 -0
- data/lib/scout/render.rb +3 -0
- data/lib/scout/sinatra/auth.rb +158 -0
- data/lib/scout/sinatra/base/assets.rb +245 -0
- data/lib/scout/sinatra/base/favicon.rb +43 -0
- data/lib/scout/sinatra/base/headers.rb +77 -0
- data/lib/scout/sinatra/base/helpers.rb +14 -0
- data/lib/scout/sinatra/base/parameters.rb +147 -0
- data/lib/scout/sinatra/base/post_processing.rb +18 -0
- data/lib/scout/sinatra/base/session.rb +72 -0
- data/lib/scout/sinatra/base.rb +253 -0
- data/lib/scout/sinatra/entity.rb +259 -0
- data/lib/scout/sinatra/finder.rb +9 -0
- data/lib/scout/sinatra/fragment.rb +275 -0
- data/lib/scout/sinatra/htmx.rb +68 -0
- data/lib/scout/sinatra/knowledge_base.rb +14 -0
- data/lib/scout/sinatra/tool.rb +11 -0
- data/lib/scout/sinatra/workflow.rb +129 -0
- data/lib/scout-camp.rb +1 -1
- data/scout-camp.gemspec +39 -3
- data/scout_commands/find +83 -0
- data/scout_commands/glob +90 -0
- data/share/aws/lambda_function.rb +53 -30
- data/share/terraform/aws/efs_host/data.tf +1 -2
- data/share/terraform/aws/efs_host/main.tf +1 -1
- data/share/terraform/aws/efs_host/variables.tf +5 -1
- data/test/scout/render/test_engine.rb +88 -0
- data/test/scout/render/test_resource.rb +29 -0
- data/test/scout/sinatra/base/test_headers.rb +125 -0
- data/test/scout/sinatra/base/test_parameters.rb +88 -0
- data/test/scout/sinatra/test_base.rb +27 -0
- data/test/scout/sinatra/test_entity.rb +44 -0
- data/test/scout/sinatra/test_render.rb +44 -0
- data/test/scout/sinatra/test_workflow.rb +157 -0
- data/test/test_helper.rb +26 -0
- metadata +103 -2
data/scout_commands/glob
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'scout-camp'
|
|
4
|
+
|
|
5
|
+
$0 = "scout #{$previous_commands.any? ? $previous_commands*" " + " " : "" }#{ File.basename(__FILE__) }" if $previous_commands
|
|
6
|
+
|
|
7
|
+
options = SOPT.setup <<EOF
|
|
8
|
+
|
|
9
|
+
Find files
|
|
10
|
+
|
|
11
|
+
$ #{$0} [<options>] (<resource> <path>|<path>)
|
|
12
|
+
|
|
13
|
+
-h--help Print this help
|
|
14
|
+
-r--requires* Files to require; 'all' for all in Scout.etc.requires
|
|
15
|
+
-lw--load_workflow* Files to require; 'all' for all in Scout.etc.requires
|
|
16
|
+
-w--where* Where to look for the path
|
|
17
|
+
EOF
|
|
18
|
+
if options[:help]
|
|
19
|
+
if defined? scout_usage
|
|
20
|
+
scout_usage
|
|
21
|
+
else
|
|
22
|
+
puts SOPT.doc
|
|
23
|
+
end
|
|
24
|
+
exit 0
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
resource, path = ARGV
|
|
28
|
+
path, resource = resource, nil if path.nil?
|
|
29
|
+
|
|
30
|
+
raise MissingParameterException.new(:path) if path.nil?
|
|
31
|
+
|
|
32
|
+
case options[:workflows]
|
|
33
|
+
when nil, false, "false", "none"
|
|
34
|
+
when "all"
|
|
35
|
+
Scout.etc.workflows.list.each do |workflow|
|
|
36
|
+
Workflow.require_workflow file
|
|
37
|
+
end if Scout.etc.workflows.exists?
|
|
38
|
+
else
|
|
39
|
+
options[:workflows].split(/[ ,;|]/).each do |workflow|
|
|
40
|
+
Workflow.require_workflow workflow
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
case options[:requires]
|
|
45
|
+
when nil, false, "false", "none"
|
|
46
|
+
when "all"
|
|
47
|
+
Scout.etc.requires.list.each do |file|
|
|
48
|
+
require file
|
|
49
|
+
end if Scout.etc.requires.exists?
|
|
50
|
+
else
|
|
51
|
+
options[:requires].split(/[ ,;|]/).each do |file|
|
|
52
|
+
require file
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
location = nil
|
|
57
|
+
where = options[:where]
|
|
58
|
+
all = options[:all]
|
|
59
|
+
|
|
60
|
+
begin
|
|
61
|
+
resource = Workflow.require_workflow resource
|
|
62
|
+
rescue
|
|
63
|
+
begin
|
|
64
|
+
resource = Kernel.const_get(resource)
|
|
65
|
+
rescue
|
|
66
|
+
raise "Resource not found: #{ resource }"
|
|
67
|
+
end
|
|
68
|
+
end if resource
|
|
69
|
+
|
|
70
|
+
path = (resource || Scout)[path.dup]
|
|
71
|
+
|
|
72
|
+
if where.nil? || where == 'all' || path.path_maps.include?(where.to_sym)
|
|
73
|
+
case where
|
|
74
|
+
when nil
|
|
75
|
+
location = path.glob
|
|
76
|
+
when 'all'
|
|
77
|
+
location = path.glob_all
|
|
78
|
+
else
|
|
79
|
+
location = path.find(where).glob
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
if Array === location
|
|
83
|
+
puts location * "\n"
|
|
84
|
+
else
|
|
85
|
+
location = nil if ! Open.exists?(location)
|
|
86
|
+
puts location
|
|
87
|
+
end
|
|
88
|
+
else
|
|
89
|
+
puts SSHLine.command(where, $0, ARGV, options.merge("where" => :all, add_option_dashes: true))
|
|
90
|
+
end
|
|
@@ -4,21 +4,19 @@ def lambda_handler(event:, context:)
|
|
|
4
4
|
Path.path_maps[:bucket] = "s3://#{ENV["AWS_BUCKET"]}/{TOPLEVEL}/{SUBPATH}"
|
|
5
5
|
Path.path_maps[:default] = :bucket
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
require 'scout/workflow'
|
|
8
9
|
require 'scout/aws/s3'
|
|
9
10
|
|
|
10
|
-
TmpFile.tmpdir = Path.setup('/tmp')
|
|
11
|
-
Open.sensible_write_dir = Path.setup('/tmp/sensible_write')
|
|
12
11
|
|
|
13
12
|
Log.info "Payload: #{Log.fingerprint(event)}"
|
|
14
13
|
|
|
15
|
-
workflow, task_name, jobname, inputs, clean, queue, info = IndiferentHash.process_options event,
|
|
16
|
-
:workflow, :task_name, :jobname, :inputs, :clean, :queue, :info
|
|
14
|
+
workflow, task_name, jobname, inputs, clean, queue, info, path = IndiferentHash.process_options event,
|
|
15
|
+
:workflow, :task_name, :jobname, :inputs, :clean, :queue, :info, :path
|
|
17
16
|
|
|
17
|
+
task_name = "path" if path
|
|
18
18
|
raise ParameterException, "No workflow specified" if workflow.nil?
|
|
19
19
|
|
|
20
|
-
workflow = Workflow.require_workflow workflow
|
|
21
|
-
|
|
22
20
|
case task_name
|
|
23
21
|
when nil
|
|
24
22
|
return {tasks: workflow.tasks.keys, documentation: workflow.documentation}
|
|
@@ -28,7 +26,20 @@ def lambda_handler(event:, context:)
|
|
|
28
26
|
else
|
|
29
27
|
Workflow.job_cache.clear
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
TmpFile.tmpdir = Path.setup('/tmp')
|
|
30
|
+
Open.sensible_write_dir = Path.setup('/tmp/sensible_write')
|
|
31
|
+
|
|
32
|
+
if path
|
|
33
|
+
job = Step.load path
|
|
34
|
+
task_name = job.task_name
|
|
35
|
+
workflow = job.workflow
|
|
36
|
+
wait = true
|
|
37
|
+
else
|
|
38
|
+
workflow = Workflow.require_workflow workflow
|
|
39
|
+
job = workflow.job(task_name, jobname, inputs)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Log.info "Job info: #{job.info}"
|
|
32
43
|
|
|
33
44
|
case clean
|
|
34
45
|
when true, 'true'
|
|
@@ -37,29 +48,41 @@ def lambda_handler(event:, context:)
|
|
|
37
48
|
job.recursive_clean
|
|
38
49
|
end
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
job.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
begin
|
|
52
|
+
if info
|
|
53
|
+
info = job.info.dup
|
|
54
|
+
info["path"] = job.path
|
|
55
|
+
{info: info}
|
|
56
|
+
elsif job.done?
|
|
57
|
+
job.load_info unless job.status == :done
|
|
58
|
+
{result: job.load}
|
|
59
|
+
elsif job.error?
|
|
60
|
+
{exception: job.exception, error: job.messages.last}
|
|
61
|
+
elsif job.started?
|
|
62
|
+
{job: job.path, info: job.info, status: job.info[:status] }
|
|
63
|
+
elsif queue
|
|
64
|
+
save_inputs = Scout.var.queue[workflow.to_s][task_name][job.name].find :bucket
|
|
65
|
+
|
|
66
|
+
job.save_info status: :queue
|
|
67
|
+
job.save_input_bundle(save_inputs) unless save_inputs.exists?
|
|
68
|
+
|
|
69
|
+
Log.info "Queue: #{save_inputs}"
|
|
70
|
+
|
|
71
|
+
{job: job.path}
|
|
72
|
+
elsif wait
|
|
73
|
+
save_inputs = Scout.var.queue[workflow.to_s][task_name][job.name].find :bucket
|
|
74
|
+
if not save_inputs.exists?
|
|
75
|
+
job.join
|
|
76
|
+
raise TryAgain
|
|
77
|
+
else
|
|
78
|
+
{job: job.path}
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
job.produce
|
|
82
|
+
raise TryAgain
|
|
83
|
+
end
|
|
84
|
+
rescue TryAgain
|
|
85
|
+
retry
|
|
63
86
|
end
|
|
64
87
|
end
|
|
65
88
|
end
|
|
@@ -5,7 +5,7 @@ resource "aws_key_pair" "this" {
|
|
|
5
5
|
|
|
6
6
|
resource "aws_instance" "this" {
|
|
7
7
|
ami = data.aws_ami.amazon_linux_2.id
|
|
8
|
-
instance_type =
|
|
8
|
+
instance_type = var.instance_type
|
|
9
9
|
iam_instance_profile = var.policies.outputs.ec2_host_profile_id
|
|
10
10
|
|
|
11
11
|
key_name = aws_key_pair.this.key_name
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
variable "network" {
|
|
2
2
|
description = "Name of the remote state block to use for the network"
|
|
3
3
|
}
|
|
4
|
-
|
|
4
|
+
variable "instance_type" {
|
|
5
|
+
description = "Instance to use"
|
|
6
|
+
type = string
|
|
7
|
+
default = "t2.micro"
|
|
8
|
+
}
|
|
5
9
|
variable "efs" {
|
|
6
10
|
description = "Name of the remote state block to use for the EFS"
|
|
7
11
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class TestRenderStep < Test::Unit::TestCase
|
|
6
|
+
def test_render_proc
|
|
7
|
+
out = ScoutRender.render(nil, name: 'Miguel') do |name|
|
|
8
|
+
"Hi #{name}"
|
|
9
|
+
end
|
|
10
|
+
assert_equal 'Hi Miguel', out
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_render_step
|
|
14
|
+
step = ScoutRender.render_step(nil, name: 'Miguel') do |name|
|
|
15
|
+
"Hi #{name}"
|
|
16
|
+
end
|
|
17
|
+
out = step.run
|
|
18
|
+
assert_equal 'Hi Miguel', out
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_render_step_template
|
|
22
|
+
TmpFile.with_path do |dir|
|
|
23
|
+
dir.share.views['test.haml'].write <<-'EOF'
|
|
24
|
+
%p Hi #{name}
|
|
25
|
+
EOF
|
|
26
|
+
|
|
27
|
+
ScoutRender.prepend_path :test_temp, dir
|
|
28
|
+
|
|
29
|
+
step = ScoutRender.render_step(dir.share.views['test.haml'], name: 'Miguel')
|
|
30
|
+
step.clean
|
|
31
|
+
out = step.run
|
|
32
|
+
assert_include out, 'Hi Miguel'
|
|
33
|
+
assert_include out, '<p>'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_render_template
|
|
38
|
+
TmpFile.with_path do |dir|
|
|
39
|
+
dir.share.views['test.haml'].write <<-'EOF'
|
|
40
|
+
%p Hi #{name}
|
|
41
|
+
EOF
|
|
42
|
+
|
|
43
|
+
ScoutRender.prepend_path :test_temp, dir
|
|
44
|
+
|
|
45
|
+
out = ScoutRender.render_template('test', name: 'Miguel', layout: nil)
|
|
46
|
+
assert_include out, 'Hi Miguel'
|
|
47
|
+
assert_include out, '<p>'
|
|
48
|
+
|
|
49
|
+
out = ScoutRender.render_partial('test', name: 'Miguel')
|
|
50
|
+
assert_include out, 'Hi Miguel'
|
|
51
|
+
assert_include out, '<p>'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_render_template_no_run
|
|
56
|
+
TmpFile.with_path do |dir|
|
|
57
|
+
dir.share.views['test.haml'].write <<-'EOF'
|
|
58
|
+
%p Hi #{name}
|
|
59
|
+
EOF
|
|
60
|
+
|
|
61
|
+
ScoutRender.prepend_path :test_temp, dir
|
|
62
|
+
|
|
63
|
+
job = ScoutRender.render_template('test', name: 'Miguel', layout: nil, run: false)
|
|
64
|
+
assert Step === job
|
|
65
|
+
|
|
66
|
+
out = job.run
|
|
67
|
+
|
|
68
|
+
assert_include out, 'Hi Miguel'
|
|
69
|
+
assert_include out, '<p>'
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_render_template_no_cache
|
|
75
|
+
TmpFile.with_path do |dir|
|
|
76
|
+
dir.share.views['test.haml'].write <<-'EOF'
|
|
77
|
+
%p Hi #{name}
|
|
78
|
+
EOF
|
|
79
|
+
|
|
80
|
+
ScoutRender.prepend_path :test_temp, dir
|
|
81
|
+
|
|
82
|
+
out = ScoutRender.render_template('test', name: 'Miguel', layout: nil, cache: false)
|
|
83
|
+
assert_include out, 'Hi Miguel'
|
|
84
|
+
assert_include out, '<p>'
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
|
3
|
+
|
|
4
|
+
class TestScoutRenderResource < Test::Unit::TestCase
|
|
5
|
+
def test_find_template_registered_dir
|
|
6
|
+
TmpFile.with_path do |dir|
|
|
7
|
+
dir.share.views['test_find_template.haml'].write "Test"
|
|
8
|
+
|
|
9
|
+
path = ScoutRender.find_haml('test_find_template')
|
|
10
|
+
refute path.exists?
|
|
11
|
+
|
|
12
|
+
path = ScoutRender.find_resource('test_find_template', extension: 'haml')
|
|
13
|
+
refute path.exists?
|
|
14
|
+
|
|
15
|
+
path = ScoutRender.find_resource('test_find_template', extension: ['haml'])
|
|
16
|
+
refute path.exists?
|
|
17
|
+
|
|
18
|
+
ScoutRender.prepend_path :tmp_dir, dir
|
|
19
|
+
|
|
20
|
+
path = ScoutRender.find_haml('test_find_template')
|
|
21
|
+
assert path.exists?
|
|
22
|
+
|
|
23
|
+
ScoutRender.path_maps.delete :tmp_dir
|
|
24
|
+
|
|
25
|
+
path = ScoutRender.find_haml('test_find_template')
|
|
26
|
+
refute path.exists?
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
|
3
|
+
|
|
4
|
+
require 'scout/render'
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
require 'rack/test'
|
|
7
|
+
require 'json'
|
|
8
|
+
require 'sinatra/base'
|
|
9
|
+
|
|
10
|
+
class TestSinatraHeaders < Test::Unit::TestCase
|
|
11
|
+
include Rack::Test::Methods
|
|
12
|
+
|
|
13
|
+
setup do
|
|
14
|
+
header 'Host', 'localhost'
|
|
15
|
+
app.set :protection, false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class TestApp < Sinatra::Base
|
|
19
|
+
helpers ScoutRenderHelpers
|
|
20
|
+
register SinatraScoutHeaders
|
|
21
|
+
|
|
22
|
+
set :protection, false
|
|
23
|
+
|
|
24
|
+
# expose small test routes using the helpers
|
|
25
|
+
get '/env' do
|
|
26
|
+
environment.to_s
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
get '/is_production' do
|
|
30
|
+
production?.to_s
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
get '/is_development' do
|
|
34
|
+
development?.to_s
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
get '/script' do
|
|
38
|
+
script_name.to_s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
get '/xhr' do
|
|
42
|
+
xhr?.to_s
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
get '/method' do
|
|
46
|
+
request_method.to_s
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
post '/post_flag' do
|
|
50
|
+
post?.to_s
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
get '/some/path' do
|
|
54
|
+
{
|
|
55
|
+
path_info: path_info,
|
|
56
|
+
query: query,
|
|
57
|
+
fullpath: fullpath,
|
|
58
|
+
original_uri: original_uri
|
|
59
|
+
}.to_json
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
get '/clean_uri' do
|
|
63
|
+
clean_uri(request.env['REQUEST_URI']).to_s
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def app
|
|
68
|
+
TestApp
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_environment_helpers
|
|
72
|
+
get '/env'
|
|
73
|
+
assert_equal 'development', last_response.body if TestApp.environment == :development
|
|
74
|
+
# We don't assert strict value across envs, just that it returns a string
|
|
75
|
+
assert last_response.status == 200
|
|
76
|
+
assert_kind_of String, last_response.body
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_production_development_flags
|
|
80
|
+
get '/is_production'
|
|
81
|
+
assert_equal 'false', last_response.body
|
|
82
|
+
|
|
83
|
+
get '/is_development'
|
|
84
|
+
assert_equal 'true', last_response.body
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_script_name_from_header
|
|
88
|
+
header 'SCRIPT_NAME', '/my/script'
|
|
89
|
+
get '/script', {}
|
|
90
|
+
assert_equal '/my/script', last_response.body
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_xhr_detection
|
|
94
|
+
# Rack::Test sets X-Requested-With when xhr? helper called in real browsers; emulate header
|
|
95
|
+
header 'X-Requested-With', 'XMLHttpRequest'
|
|
96
|
+
get '/xhr'
|
|
97
|
+
assert_equal 'true', last_response.body
|
|
98
|
+
ensure
|
|
99
|
+
# clear header for subsequent tests
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_request_method_and_post_flag
|
|
103
|
+
get '/method'
|
|
104
|
+
assert_equal 'GET', last_response.body
|
|
105
|
+
post '/post_flag'
|
|
106
|
+
assert_equal 'true', last_response.body
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_uri_helpers_and_clean_uri
|
|
110
|
+
env = {
|
|
111
|
+
"PATH_INFO" => "/some/path",
|
|
112
|
+
"QUERY_STRING" => "a=1&_update=reload&b=2",
|
|
113
|
+
"REQUEST_URI" => "/some/path?a=1&_update=reload&b=2"
|
|
114
|
+
}
|
|
115
|
+
get '/some/path?a=1&_update=reload&b=2', {}
|
|
116
|
+
assert_equal 200, last_response.status, last_response.errors
|
|
117
|
+
body = JSON.parse(last_response.body)
|
|
118
|
+
assert_equal '/some/path', body['path_info']
|
|
119
|
+
assert_equal 'a=1&_update=reload&b=2', body['query']
|
|
120
|
+
# fullpath uses clean_uri so _update should be removed from fullpath
|
|
121
|
+
assert_equal '/some/path?a=1&b=2', body['fullpath']
|
|
122
|
+
# original_uri uses clean_uri on REQUEST_URI
|
|
123
|
+
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
|
3
|
+
|
|
4
|
+
require 'scout/render'
|
|
5
|
+
require 'test/unit'
|
|
6
|
+
require 'rack/test'
|
|
7
|
+
require 'json'
|
|
8
|
+
require 'sinatra/base'
|
|
9
|
+
require 'scout/sinatra/base/headers'
|
|
10
|
+
|
|
11
|
+
class TestSinatraHeaders < Test::Unit::TestCase
|
|
12
|
+
include Rack::Test::Methods
|
|
13
|
+
|
|
14
|
+
setup do
|
|
15
|
+
header 'Host', 'localhost'
|
|
16
|
+
app.set :protection, false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# register a temporary common parameter for testing
|
|
20
|
+
SinatraScoutParameters.register_common_parameter(:_flag_test, :boolean, nil) { false }
|
|
21
|
+
|
|
22
|
+
class TestApp < Sinatra::Base
|
|
23
|
+
register SinatraScoutHeaders
|
|
24
|
+
register SinatraScoutParameters
|
|
25
|
+
|
|
26
|
+
# route to inspect consume_parameter
|
|
27
|
+
get '/consume' do
|
|
28
|
+
val = consume_parameter('x', params)
|
|
29
|
+
(val.nil? ? 'nil' : val.to_s)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
get '/clean' do
|
|
33
|
+
content_type 'application/json'
|
|
34
|
+
clean_params.to_json
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
get '/process_common' do
|
|
38
|
+
# call process_common_parameters and return the value of the helper-generated method
|
|
39
|
+
process_common_parameters
|
|
40
|
+
_flag_test.to_s
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def app
|
|
45
|
+
TestApp
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_consume_parameter_blank_becomes_nil
|
|
49
|
+
get '/consume', { 'x' => '' }
|
|
50
|
+
assert_equal 'nil', last_response.body
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_clean_params_removes_internal_keys_and_checkbox_false
|
|
54
|
+
params = {
|
|
55
|
+
'name' => 'John',
|
|
56
|
+
'_internal' => 'should_remove',
|
|
57
|
+
'agree_checkbox_false' => '1'
|
|
58
|
+
}
|
|
59
|
+
get '/clean', params
|
|
60
|
+
assert_equal 200, last_response.status
|
|
61
|
+
body = JSON.parse(last_response.body)
|
|
62
|
+
# _internal should not be present
|
|
63
|
+
assert !body.key?('_internal')
|
|
64
|
+
# agree_checkbox_false should be removed; agree should be false (since no 'agree' key present)
|
|
65
|
+
assert_equal false, body['agree']
|
|
66
|
+
assert_equal 'John', body['name']
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_common_parameter_helper_created_and_defaults_work
|
|
70
|
+
# no param provided, the registered default block returns false
|
|
71
|
+
get '/process_common'
|
|
72
|
+
assert_equal 'false', last_response.body
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_consume_parameter_from_given_source_hash
|
|
76
|
+
# supply nested hash as source
|
|
77
|
+
source = { 'a' => '1', 'b' => '' }
|
|
78
|
+
# create a route to call consume_parameter with a custom source
|
|
79
|
+
TestApp.get '/consume_custom' do
|
|
80
|
+
v1 = consume_parameter('a', source)
|
|
81
|
+
v2 = consume_parameter('b', source)
|
|
82
|
+
"#{v1}-#{v2.inspect}"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
get '/consume_custom'
|
|
86
|
+
assert_equal '1-nil', last_response.body
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
|
3
|
+
|
|
4
|
+
require 'rack/test'
|
|
5
|
+
class TestSinatraBase < Test::Unit::TestCase
|
|
6
|
+
include Rack::Test::Methods
|
|
7
|
+
|
|
8
|
+
class TestApp < Sinatra::Base
|
|
9
|
+
set :protection, false
|
|
10
|
+
register SinatraScoutBase
|
|
11
|
+
set :protection, false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
setup do
|
|
15
|
+
header 'Host', 'localhost'
|
|
16
|
+
app.set :protection, false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def app
|
|
20
|
+
TestApp
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_true
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
|
3
|
+
|
|
4
|
+
require 'rack/test'
|
|
5
|
+
|
|
6
|
+
module TestEntity
|
|
7
|
+
extend Entity
|
|
8
|
+
|
|
9
|
+
property :hi do |name=nil|
|
|
10
|
+
"Hi #{name||self}"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class TestSinatraWorkflows < Test::Unit::TestCase
|
|
15
|
+
include Rack::Test::Methods
|
|
16
|
+
|
|
17
|
+
class TestApp < Sinatra::Base
|
|
18
|
+
set :protection, false
|
|
19
|
+
register SinatraScoutBase
|
|
20
|
+
register SinatraScoutEntity
|
|
21
|
+
set :protection, false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
setup do
|
|
25
|
+
header 'Host', 'localhost'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def app
|
|
29
|
+
TestApp
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_property
|
|
33
|
+
get '/entity_property/TestEntity/hi/Test', { '_format' => 'json'}
|
|
34
|
+
assert_equal 200, last_response.status, "expected 200 got #{last_response.status}: #{last_response.errors}"
|
|
35
|
+
body = IndiferentHash.setup(JSON.parse(last_response.body))
|
|
36
|
+
assert_equal "Hi Test", body[:message]
|
|
37
|
+
|
|
38
|
+
get '/entity_property/TestEntity/hi/Test', { '_format' => 'json', args: "Miguel"}
|
|
39
|
+
assert_equal 200, last_response.status, "expected 200 got #{last_response.status}: #{last_response.errors}"
|
|
40
|
+
body = IndiferentHash.setup(JSON.parse(last_response.body))
|
|
41
|
+
assert_equal "Hi Miguel", body[:message]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
|
2
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
|
3
|
+
|
|
4
|
+
require 'rack/test'
|
|
5
|
+
|
|
6
|
+
class TestSinatraRender < Test::Unit::TestCase
|
|
7
|
+
include Rack::Test::Methods
|
|
8
|
+
|
|
9
|
+
class TestApp < Sinatra::Base
|
|
10
|
+
set :protection, false
|
|
11
|
+
register SinatraScoutRender
|
|
12
|
+
set :protection, false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def app
|
|
16
|
+
TestApp
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
setup do
|
|
20
|
+
header 'Host', 'localhost'
|
|
21
|
+
app.set :protection, false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_get
|
|
26
|
+
TmpFile.with_path do |dir|
|
|
27
|
+
dir.share.views.main['test.haml'].write <<-'EOF'
|
|
28
|
+
%p Hi #{name}
|
|
29
|
+
EOF
|
|
30
|
+
|
|
31
|
+
dir.share.views['layout.haml'].write <<-'EOF'
|
|
32
|
+
%H3 Layout
|
|
33
|
+
!= yield
|
|
34
|
+
EOF
|
|
35
|
+
|
|
36
|
+
ScoutRender.prepend_path :test_temp, dir
|
|
37
|
+
|
|
38
|
+
get '/main/test', { '_format' => 'json', 'name' => "Miguel"}
|
|
39
|
+
assert_equal 200, last_response.status, "expected 200 got #{last_response.status}: #{last_response.status == 500 ? last_response.errors : last_response.body}"
|
|
40
|
+
assert_include = last_response.body, 'Miguel'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|