test_server 0.2.4 → 0.3.1

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.
Files changed (106) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +54 -29
  4. data/README.rdoc +28 -0
  5. data/Rakefile +3 -3
  6. data/app/assets/images/.keep +0 -0
  7. data/app/assets/javascripts/application.js +14 -0
  8. data/app/assets/javascripts/errors.js +2 -0
  9. data/app/assets/stylesheets/application.scss +83 -0
  10. data/app/assets/stylesheets/errors.css +4 -0
  11. data/app/controllers/concerns/.keep +0 -0
  12. data/app/controllers/test_server/application_controller.rb +34 -0
  13. data/app/controllers/test_server/dashboard_controller.rb +9 -0
  14. data/app/controllers/test_server/errors_controller.rb +22 -0
  15. data/app/controllers/test_server/generator_controller.rb +40 -0
  16. data/app/controllers/test_server/static_controller.rb +16 -0
  17. data/app/controllers/test_server/streaming_controller.rb +56 -0
  18. data/app/controllers/test_server/string_controller.rb +39 -0
  19. data/app/helpers/application_helper.rb +2 -0
  20. data/app/helpers/errors_helper.rb +2 -0
  21. data/app/mailers/.keep +0 -0
  22. data/app/models/.keep +0 -0
  23. data/app/models/concerns/.keep +0 -0
  24. data/app/views/layouts/application.html.haml +59 -0
  25. data/app/views/shared/_overview.html.haml +16 -0
  26. data/app/views/test_server/dashboard/show.html.haml +7 -0
  27. data/app/views/test_server/errors/not_found.html.haml +2 -0
  28. data/app/views/test_server/errors/show.html.haml +6 -0
  29. data/app/views/test_server/generator/_overview.html.haml +1 -0
  30. data/app/views/test_server/generator/index.html.haml +1 -0
  31. data/app/views/{xhr/show.haml → test_server/generator/xhr.html.haml} +15 -12
  32. data/app/views/test_server/static/_overview.html.haml +1 -0
  33. data/app/views/test_server/static/index.html.haml +1 -0
  34. data/app/views/test_server/streaming/_overview.html.haml +1 -0
  35. data/app/views/test_server/streaming/index.html.haml +1 -0
  36. data/app/views/test_server/string/_overview.html.haml +1 -0
  37. data/app/views/test_server/string/index.html.haml +1 -0
  38. data/config.ru +3 -50
  39. data/config/application.rb +44 -0
  40. data/config/boot.rb +4 -0
  41. data/config/database.yml +25 -0
  42. data/config/environment.rb +5 -0
  43. data/config/environments/development.rb +37 -0
  44. data/config/environments/production.rb +87 -0
  45. data/config/environments/profile.rb +85 -0
  46. data/config/environments/test.rb +39 -0
  47. data/config/initializers/backtrace_silencers.rb +7 -0
  48. data/config/initializers/breadbrumb_builder.rb +24 -0
  49. data/config/initializers/change_values.rb +5 -0
  50. data/config/initializers/cookies_serializer.rb +3 -0
  51. data/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/config/initializers/inflections.rb +16 -0
  53. data/config/initializers/mime_types.rb +4 -0
  54. data/config/initializers/session_store.rb +3 -0
  55. data/config/initializers/to_bool.rb +23 -0
  56. data/config/initializers/wrap_parameters.rb +14 -0
  57. data/config/locales/en.yml +23 -0
  58. data/config/routes.rb +78 -0
  59. data/config/secrets.yml +22 -0
  60. data/lib/assets/.keep +0 -0
  61. data/lib/tasks/.keep +0 -0
  62. data/lib/test_server.rb +13 -15
  63. data/lib/test_server/error_handler.rb +15 -11
  64. data/lib/test_server/error_messages.rb +16 -6
  65. data/lib/test_server/exceptions.rb +6 -0
  66. data/lib/test_server/locales/en.yml +55 -2
  67. data/lib/test_server/permitted_params.rb +107 -0
  68. data/lib/test_server/version.rb +1 -1
  69. data/lib/test_server/web_helper.rb +7 -31
  70. data/log/.keep +0 -0
  71. data/log/development.log +0 -0
  72. data/log/test.log +1 -0
  73. data/public/404.html +67 -0
  74. data/public/422.html +67 -0
  75. data/public/500.html +66 -0
  76. data/public/favicon.ico +0 -0
  77. data/public/robots.txt +5 -0
  78. data/public/static/plain.html +11 -0
  79. data/script/bundle +3 -0
  80. data/script/rails +8 -0
  81. data/script/rake +8 -0
  82. data/script/spring +18 -0
  83. data/spec/controllers/errors_controller_spec.rb +12 -0
  84. data/spec/error_handler_spec.rb +42 -9
  85. data/spec/features/dashboard_spec.rb +35 -0
  86. data/spec/features/fetch_data_via_javascript_spec.rb +14 -14
  87. data/spec/features/fetch_test_data_plain_spec.rb +11 -29
  88. data/spec/features/fetch_test_data_via_streaming_spec.rb +6 -6
  89. data/spec/features/helper_spec.rb +23 -31
  90. data/spec/helpers/errors_helper_spec.rb +15 -0
  91. data/spec/permitted_params_spec.rb +64 -0
  92. data/spec/spec_helper.rb +44 -3
  93. data/spec/support/capybara.rb +4 -0
  94. data/spec/support/rails.rb +33 -0
  95. data/spec/views/errors/not_found.html.haml_spec.rb +5 -0
  96. data/test_server.gemspec +18 -17
  97. data/vendor/assets/components/open-sans/scss/_base.scss +5 -5
  98. data/vendor/assets/javascripts/.keep +0 -0
  99. data/vendor/assets/stylesheets/.keep +0 -0
  100. metadata +133 -116
  101. data/app/controllers/application_controller.rb +0 -76
  102. data/app/controllers/assets_controller.rb +0 -73
  103. data/app/controllers/javascript_controller.rb +0 -36
  104. data/app/controllers/streaming_controller.rb +0 -52
  105. data/app/controllers/string_controller.rb +0 -51
  106. data/app/views/layouts/application.haml +0 -19
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+ module TestServer
3
+ class StreamingController < ApplicationController
4
+ include ActionController::Live
5
+
6
+ add_breadcrumb I18n.t('views.root.link'), :root_path
7
+ add_breadcrumb I18n.t('views.streaming.link'), :streaming_path
8
+
9
+ def index
10
+ end
11
+
12
+ def plain
13
+ params[:count].to_i.times do |n|
14
+ response.stream.write(
15
+ encode(params) { "#{n + 1}: data" }
16
+ )
17
+ sleep(params[:wait].to_f / 1_000.0)
18
+ end
19
+
20
+ response.stream.close
21
+ end
22
+
23
+ def eicar
24
+ generate_eicar.each do |c|
25
+ response.stream.write(
26
+ encode(params) { c }
27
+ )
28
+
29
+ sleep(params[:wait].to_f / 1_000.0)
30
+ end
31
+
32
+ response.stream.close
33
+ end
34
+
35
+ def random
36
+ params[:count].to_i.times do |n|
37
+
38
+ response.stream.write(
39
+ encode(params) { generate_random_string(1) }
40
+ )
41
+ sleep(params[:wait].to_f / 1_000.0)
42
+ end
43
+
44
+ response.stream.close
45
+ end
46
+
47
+ private
48
+
49
+ def default_params
50
+ {
51
+ wait: 1_000,
52
+ count: 1,
53
+ }.merge super
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ module TestServer
3
+ class StringController < ApplicationController
4
+ def index
5
+ add_breadcrumb I18n.t('views.root.link'), :root_path
6
+ add_breadcrumb I18n.t('views.string.link'), :string_path
7
+ end
8
+
9
+ def plain
10
+ render text: encode(params) { generate_string(params[:count]) }
11
+ end
12
+
13
+ def eicar
14
+ render text: encode(params) { generate_eicar.join }
15
+ end
16
+
17
+ def sleep
18
+ Kernel.sleep params[:count].to_i
19
+
20
+ render text: encode(params) { generate_string(1) }
21
+ end
22
+
23
+ def random
24
+ render text: encode(params) { generate_random_string(params[:count]) }
25
+ end
26
+
27
+ private
28
+
29
+ def default_roles
30
+ [:encodable, :cachable, :countable]
31
+ end
32
+
33
+ def default_params
34
+ {
35
+ count: 1,
36
+ }.merge super
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ErrorsHelper
2
+ end
data/app/mailers/.keep ADDED
File without changes
data/app/models/.keep ADDED
File without changes
File without changes
@@ -0,0 +1,59 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{ charset: 'utf-8'}
5
+ = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
6
+ %title= @title || t('views.application.title')
7
+ %body{ 'data-no-turbolink' => true }
8
+ .ts-page-header
9
+ %nav.ts-top-navigation{ role: 'navigation' }
10
+ %ul.nav.navbar-nav
11
+ %li.active
12
+ %a{href: '/'}
13
+ = t('views.root.link')
14
+ %li.ts-dropdown
15
+ %a.ts-dropdown-toggle{ href: generator_path, 'data-toggle' => 'dropdown'}
16
+ = t('views.generator.link')
17
+ %b.ts-caret
18
+ %ul.ts-dropdown-menu
19
+ %li
20
+ = link_to t('views.generator.index.link'), generator_path
21
+ - [ :xhr ].each do |action|
22
+ %li
23
+ = link_to t("views.generator.#{action}.link"), send("generator_#{action}_path")
24
+ %li.ts-dropdown
25
+ %a.dropdown-toggle{ href: string_path, 'data-toggle' => 'dropdown'}
26
+ = t('views.string.link')
27
+ %b.ts-caret
28
+ %ul.ts-dropdown-menu
29
+ %li
30
+ = link_to t('views.string.index.link'), string_path
31
+ - [ :plain, :random, :eicar, :sleep ].each do |action|
32
+ %li
33
+ = link_to t("views.string.#{action}.link"), send("string_#{action}_path")
34
+ %li.ts-dropdown
35
+ %a.dropdown-toggle{ href: streaming_path, 'data-toggle' => 'dropdown'}
36
+ = t('views.streaming.link')
37
+ %b.ts-caret
38
+ %ul.ts-dropdown-menu
39
+ %li
40
+ = link_to t('views.streaming.index.link'), streaming_path
41
+ - [ :plain, :random, :eicar ].each do |action|
42
+ %li
43
+ = link_to t("views.streaming.#{action}.link"), send("streaming_#{action}_path")
44
+ %li.ts-dropdown
45
+ %a.dropdown-toggle{ href: '#', 'data-toggle' => 'dropdown'}
46
+ = t('views.static.link')
47
+ %b.ts-caret
48
+ %ul.ts-dropdown-menu
49
+ %li
50
+ = link_to t('views.static.index.link'), static_path
51
+ - [ :plain ].each do |action|
52
+ %li
53
+ = link_to t("views.static.#{action}.title"), "/static/#{action}.html"
54
+ %ul.ts-breadcrumb
55
+ = render_breadcrumbs builder: TestServer::BreadcrumbBuilder
56
+ end
57
+ .ts-container
58
+ = yield
59
+ = javascript_include_tag 'application', 'data-turbolinks-track' => true
@@ -0,0 +1,16 @@
1
+ %section.ts-dashboard-section
2
+ .ts-dashboard-section-header
3
+ %h3.ts-dashboard-section-title
4
+ = t("views.#{controller_name}.title")
5
+ .ts-dashboard-section-body
6
+ %ul
7
+ - supported_actions.each do |action|
8
+ %li
9
+ - if static == true
10
+ = link_to t("views.#{controller_name}.#{action}.title"), "/#{controller_name}/#{action}.html"
11
+ - else
12
+ = link_to t("views.#{controller_name}.#{action}.title"), send("#{controller_name}_#{action}_path")
13
+ %br
14
+ %span.ts-dashboard-known_params
15
+ = surround '(', ')' do
16
+ = permitted_params.known_params_for_controller(controller_name, action).join(', ')
@@ -0,0 +1,7 @@
1
+ %h1
2
+ = t('views.dashboard.show.title')
3
+
4
+ = render partial: 'test_server/generator/overview'
5
+ = render partial: 'test_server/string/overview'
6
+ = render partial: 'test_server/streaming/overview'
7
+ = render partial: 'test_server/static/overview'
@@ -0,0 +1,2 @@
1
+ %h1 Errors#not_found
2
+ %p Find me in app/views/errors/not_found.html.haml
@@ -0,0 +1,6 @@
1
+ .ts_warning_container
2
+ .ts_warning_summary
3
+ %i.fa.fa-exclamation-circle
4
+ = @error_summary
5
+ .ts_warning_details
6
+ = @error_details
@@ -0,0 +1 @@
1
+ = render partial: 'shared/overview', locals: { controller_name: 'generator', supported_actions: [:xhr], static: false }
@@ -0,0 +1 @@
1
+ = render partial: 'overview'
@@ -1,25 +1,28 @@
1
1
  %form#form.ts-form{ name: 'form', action: '', role: :form }
2
2
  .ts-form-group
3
3
  %label{ for: :count}
4
- = t('views.javascript.xhr.fields.count')
4
+ = t('views.generator.show.fields.count')
5
5
  %input#count.ts-field-count{ type: :number, name: :count, value: @count }
6
6
  .ts-form-group
7
7
  %label{ for: :timeout}
8
- = t('views.javascript.xhr.fields.timeout')
8
+ = t('views.generator.show.fields.timeout')
9
9
  %input#timeout.ts-field-timeout{ type: :number, name: :timeout, value: @timeout }
10
10
  .ts-form-group
11
11
  %label{ for: :url}
12
- = t('views.javascript.xhr.fields.url')
13
- %input#url.ts-field-url{ type: :url, name: :url, value: @url, placeholder: 'http://www.example.org' }
12
+ = t('views.generator.show.fields.url')
13
+ %input#url.ts-field-url{ type: :url, name: :url, value: @url, placeholder: 'http://www.example.org', list: :url_list }
14
+ %datalist#url_list
15
+ - @urls.each do |url|
16
+ %option{ value: url}
14
17
  %input#hidden_repeat{ type: :hidden, name: :hidden_repeat }
15
18
  .ts-field-repeat
16
19
  %label
17
20
  - if @repeat
18
21
  %input#repeat{ type: :checkbox, checked: 'checked', value: 'on', name: :repeat }
19
- = t('views.javascript.xhr.fields.repeat')
22
+ = t('views.generator.show.fields.repeat')
20
23
  - else
21
24
  %input#repeat{ type: :checkbox, name: :repeat }
22
- = t('views.javascript.xhr.fields.repeat')
25
+ = t('views.generator.show.fields.repeat')
23
26
  %button#start.ts-button-start{type: 'submit', name: 'start', value: t('views.application.buttons.start') }
24
27
  = t('views.application.buttons.start')
25
28
  %button#stop.ts-button-stop{type: 'submit', name: 'stop', value: t('views.application.buttons.stop') }
@@ -29,12 +32,12 @@
29
32
  %a#clone.ts-button-clone{href: '#', name: 'clone'}
30
33
  = t('views.application.buttons.clone')
31
34
  %span.ts-inline#request-spinner
32
- %img{ src: '/assets/ajax-loader.gif', alt: t('views.javascript.xhr.spinner.text') }
33
- = t('views.javascript.xhr.spinner.text')
35
+ = image_tag 'ajax-loader.gif', alt: t('views.generator.xhr.spinner.text')
36
+ = t('views.generator.show.spinner.text')
34
37
 
35
38
  %table#result.ts-result-table
36
39
  %tr#result_table_header
37
- %th= t('views.javascript.xhr.result_table.url')
38
- %th= t('views.javascript.xhr.result_table.timeout')
39
- %th= t('views.javascript.xhr.result_table.runtime')
40
- %th= t('views.javascript.xhr.result_table.status')
40
+ %th= t('views.generator.show.result_table.url')
41
+ %th= t('views.generator.show.result_table.timeout')
42
+ %th= t('views.generator.show.result_table.runtime')
43
+ %th= t('views.generator.show.result_table.status')
@@ -0,0 +1 @@
1
+ = render partial: 'shared/overview', locals: { controller_name: 'static', supported_actions: [ :plain], static: true }
@@ -0,0 +1 @@
1
+ = render partial: 'overview'
@@ -0,0 +1 @@
1
+ = render partial: 'shared/overview', locals: { controller_name: 'streaming', supported_actions: [ :plain, :random, :eicar ], static: false }
@@ -0,0 +1 @@
1
+ = render partial: 'overview'
@@ -0,0 +1 @@
1
+ = render partial: 'shared/overview', locals: { controller_name: 'string', supported_actions: [ :plain, :random, :eicar, :sleep ], static: false }
@@ -0,0 +1 @@
1
+ = render partial: 'overview'
data/config.ru CHANGED
@@ -1,51 +1,4 @@
1
- $LOAD_PATH <<::File.expand_path('../lib/', __FILE__)
1
+ # This file is used by Rack-based servers to start the application.
2
2
 
3
- require 'sass'
4
- require 'test_server'
5
- #require 'bundler'
6
-
7
- #if %w{ development test }.include? ENV['RACK_ENV']
8
- # Bundler.require :default, :test, :development
9
- #else
10
- # Bundler.require :default
11
- #end
12
-
13
- TestServer.config.debug_mode = true if ENV['DEBUG']
14
- TestServer.config.log_level = ENV['LOG_LEVEL'] if ENV['LOG_LEVEL']
15
- TestServer.config.access_log = ENV['ACCESS_LOG'] if ENV['ACCESS_LOG']
16
-
17
- TestServer.ui_logger.level = TestServer.config.log_level
18
-
19
- require File.expand_path('../app/controllers/application_controller.rb', __FILE__)
20
- Dir.glob(::File.expand_path('../app/controllers/*.rb', __FILE__)).each { |f| require f }
21
-
22
-
23
- trap TestServer.config.reload_config_signal do
24
- begin
25
- TestServer.ui_logger.warn 'Reload of configuration requested'
26
- TestServer::Actions::ReloadConfiguration.new.run
27
- TestServer.ui_logger.info 'Reload of configuration successful'
28
- rescue Exceptions::ReloadOfConfigurationFailed => e
29
- TestServer.ui_logger.fatal "Reload of configuration failed: #{e.message}"
30
- end
31
- end
32
-
33
- #map '/v1/testrating/' do
34
- # run TestServer::App::TestRatingController
35
- #end
36
-
37
- map '/v1/test/streaming' do
38
- run TestServer::App::StreamingController
39
- end
40
-
41
- map '/v1/test/string' do
42
- run TestServer::App::StringController
43
- end
44
-
45
- map '/v1/test/javascript' do
46
- run TestServer::App::JavascriptController
47
- end
48
-
49
- map TestServer::App::AssetsController.assets_prefix do
50
- run TestServer::App::AssetsController.assets
51
- end
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_model/railtie"
5
+ require "active_record/railtie"
6
+ require "action_controller/railtie"
7
+ require "action_mailer/railtie"
8
+ require "action_view/railtie"
9
+ require "sprockets/railtie"
10
+ # require "rails/test_unit/railtie"
11
+
12
+ # Require the gems listed in Gemfile, including any gems
13
+ # you've limited to :test, :development, or :production.
14
+ Bundler.require(*Rails.groups)
15
+
16
+ module TestServer
17
+ class Application < Rails::Application
18
+ # Settings in config/environments/* take precedence over those specified here.
19
+ # Application configuration should go into files in config/initializers
20
+ # -- all .rb files in that directory are automatically loaded.
21
+
22
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
23
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
24
+ # config.time_zone = 'Central Time (US & Canada)'
25
+
26
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
27
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
28
+ # config.i18n.default_locale = :de
29
+ config.middleware.use Rack::Deflater
30
+
31
+ # handle exceptions
32
+ #config.exceptions_app = self.routes
33
+
34
+ # logging
35
+ config.logger = ActiveSupport::TaggedLogging.new(::Logger.new(TestServer.config.access_log))
36
+
37
+ # assets
38
+ config.assets.paths << Rails.root.join('vendor', 'assets', 'components')
39
+ config.assets.cache = Sprockets::Cache::FileStore.new(TestServer.config.sass_cache)
40
+
41
+ # store for http caching
42
+ config.cache_store = :memory_store
43
+ end
44
+ end
data/config/boot.rb ADDED
@@ -0,0 +1,4 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,37 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+
30
+ # Adds additional error checking when serving assets at runtime.
31
+ # Checks for improperly declared sprockets dependencies.
32
+ # Raises helpful error messages.
33
+ config.assets.raise_runtime_errors = true
34
+
35
+ # Raises error for missing translations
36
+ # config.action_view.raise_on_missing_translations = true
37
+ end