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
@@ -12,53 +12,36 @@ describe 'Fetch plain data' do
12
12
  end.new
13
13
 
14
14
  TestServer.config = config
15
- Capybara.app = TestServer::App::StringController.new
15
+ #Capybara.app = TestServer::App::StringController.new
16
16
  end
17
17
 
18
18
  it 'downloads the data' do
19
- visit('/default/')
19
+ visit('/string/plain')
20
20
 
21
21
  expect(page.status_code).to eq 200
22
22
  expect(page).to have_content('Plain Data')
23
23
  end
24
24
 
25
25
  it 'downloads the data with multiplier' do
26
- visit('/default?count=10')
26
+ visit('/string/plain?count=10')
27
27
 
28
28
  expect(page.status_code).to eq 200
29
29
  expect(page.source.split(/\n/).size).to eq 10
30
30
  end
31
31
 
32
- it 'prevents caching' do
33
- visit('/default?no_cache')
32
+ it 'prevents caching by default' do
33
+ visit('/string/plain')
34
34
 
35
35
  expect(page.status_code).to eq 200
36
36
  expect(page.response_headers).to be_key('Cache-Control')
37
37
  expect(page.response_headers['Cache-Control']).to include('no-cache')
38
38
  end
39
39
 
40
- it 'requires re-validation' do
41
- visit('/default?must_revalidate')
42
-
43
- expect(page.status_code).to eq 200
44
- expect(page.response_headers).to be_key('Cache-Control')
45
- expect(page.response_headers['Cache-Control']).to include('must-revalidate')
46
- end
47
-
48
- it 'sets max age' do
49
- visit('/default?max_age=500')
50
-
51
- expect(page.status_code).to eq 200
52
- expect(page.response_headers).to be_key('Cache-Control')
53
- expect(page.response_headers['Cache-Control']).to include('max-age=500')
54
- end
55
-
56
40
  it 'sets everything' do
57
- visit('/default?expires=500')
41
+ visit('/string/plain?expires=500')
58
42
 
59
43
  expect(page.status_code).to eq 200
60
44
  expect(page.response_headers).to be_key('Cache-Control')
61
- expect(page.response_headers['Cache-Control']).to include('no-cache')
62
45
  expect(page.response_headers['Cache-Control']).to include('must-revalidate')
63
46
  expect(page.response_headers['Cache-Control']).to include('max-age=500')
64
47
  end
@@ -71,14 +54,14 @@ describe 'Fetch plain data' do
71
54
  '-', 'T', 'E', 'S', 'T', '-', 'F', 'I', 'L', 'E', '!', '$', 'H',
72
55
  '+', 'H', '*' ]
73
56
 
74
- visit('/eicar/')
57
+ visit('/string/eicar')
75
58
  expect(page.status_code).to eq 200
76
59
  expect(page).to have_content(eicar.join)
77
60
  end
78
61
 
79
62
  it 'supports long running requests' do
80
63
  timeout(3) do
81
- visit('/sleep?count=2')
64
+ visit('/string/sleep?count=2')
82
65
  end
83
66
 
84
67
  expect(page.status_code).to eq 200
@@ -86,24 +69,23 @@ describe 'Fetch plain data' do
86
69
  end
87
70
 
88
71
  it 'supports random string' do
89
- visit('/random?count=2')
72
+ visit('/string/random?count=2')
90
73
 
91
74
  expect(page.status_code).to eq 200
92
75
  expect(page.source.size).to eq 2
93
76
  end
94
77
 
95
78
  it 'supports base64 encoding' do
96
- visit('/default?base64')
79
+ visit('/string/plain?base64=on')
97
80
 
98
81
  expect(page.status_code).to eq 200
99
82
  expect(Base64.decode64(page.source)).to include 'Plain Data'
100
83
  end
101
84
 
102
85
  it 'supports base64 stric encoding' do
103
- visit('/default?base64_strict')
86
+ visit('/string/plain?base64_strict=on')
104
87
 
105
88
  expect(page.status_code).to eq 200
106
89
  expect(Base64.strict_decode64(page.source)).to include 'Plain Data'
107
90
  end
108
-
109
91
  end
@@ -13,28 +13,28 @@ describe 'Fetch Test Data via Streaming' do
13
13
  end.new
14
14
 
15
15
  TestServer.config = config
16
- Capybara.app = TestServer::App::StreamingController.new
16
+ #Capybara.app = TestServer::App::StreamingController.new
17
17
  end
18
18
 
19
19
  it 'downloads stream' do
20
- visit('/default?count=2')
20
+ visit('/streaming/plain?count=2')
21
21
 
22
22
  expect(page.status_code).to be 200
23
23
  expect(page).to have_content('data')
24
24
  end
25
25
 
26
26
  it 'supports base64 encoding' do
27
- visit('/default?count=2&base64')
27
+ visit('/streaming/plain?count=2&base64=on')
28
28
 
29
29
  expect(page.status_code).to be 200
30
30
  expect(Base64.decode64(page.source.split(/\n/).last)).to include 'data'
31
31
  end
32
32
 
33
33
  it 'supports gzip encoding' do
34
- visit('/default?count=2&gzip')
34
+ visit('/streaming/plain?count=2&gzip=on')
35
35
 
36
36
  expect(page.status_code).to be 200
37
- expect(Base64.decode64(page.source.split(/\n/).last)).to include "\xC6\xC2\bODLT\x91\xCC \xC32\xC7tG \x85q\xDD\x11\xC8".force_encoding('ASCII-8bit')
37
+ expect(Base64.decode64(page.source.split(/\n/).last)).to include "\xC7tG \x85q\xDD\x11\xC8".force_encoding('ASCII-8bit')
38
38
  end
39
39
 
40
40
  it 'serves eicar test string to check if virus scanners find that string' do
@@ -45,7 +45,7 @@ describe 'Fetch Test Data via Streaming' do
45
45
  '-', 'T', 'E', 'S', 'T', '-', 'F', 'I', 'L', 'E', '!', '$', 'H',
46
46
  '+', 'H', '*' ]
47
47
 
48
- visit('/eicar/')
48
+ visit('/streaming/eicar')
49
49
 
50
50
  expect(page.status_code).to be 200
51
51
  expect(page).to have_content(eicar.join)
@@ -37,11 +37,10 @@ describe WebHelper do
37
37
 
38
38
  context '#encoding' do
39
39
  it 'supports base64 encoding' do
40
- @test_object.params = {
41
- 'base64' => nil,
42
- }
40
+ params = double('RailsStrongParameter')
41
+ allow(params).to receive(:symbolize_keys).and_return(base64: 'on')
43
42
 
44
- result = @test_object.encode do
43
+ result = @test_object.encode params do
45
44
  'string'
46
45
  end
47
46
 
@@ -49,11 +48,10 @@ describe WebHelper do
49
48
  end
50
49
 
51
50
  it 'supports strict base64 encoding' do
52
- @test_object.params = {
53
- 'base64_strict' => nil,
54
- }
51
+ params = double('RailsStrongParameter')
52
+ allow(params).to receive(:symbolize_keys).and_return(base64_strict: 'on')
55
53
 
56
- result = @test_object.encode do
54
+ result = @test_object.encode params do
57
55
  'string'
58
56
  end
59
57
 
@@ -61,48 +59,43 @@ describe WebHelper do
61
59
  end
62
60
 
63
61
  it 'supports gzip encoding' do
64
- @test_object.params = {
65
- 'gzip' => nil,
66
- }
62
+ params = double('RailsStrongParameter')
63
+ allow(params).to receive(:symbolize_keys).and_return(gzip: 'on')
67
64
 
68
- result = @test_object.encode do
65
+ result = @test_object.encode params do
69
66
  'string'
70
67
  end
71
68
 
72
69
  expect(result).to eq "x\x9C+.)\xCA\xCCK\a\x00\tB\x02\x98".force_encoding('ASCII-8Bit')
73
70
  end
74
71
 
75
- it 'can combine multiple encodings, based on occurrence (gzip, base64)' do
76
- @test_object.params = {
77
- 'gzip' => nil,
78
- 'base64' => nil,
79
- }
72
+ it 'can combine multiple encodings, based on occurrence: gzip, base64' do
73
+ params = double('RailsStrongParameter')
74
+ allow(params).to receive(:symbolize_keys).and_return(gzip: 'on', base64: 'on')
80
75
 
81
- result = @test_object.encode do
76
+ result = @test_object.encode params do
82
77
  'string'
83
78
  end
84
79
 
85
80
  expect(result).to eq "eJwrLinKzEsHAAlCApg=\n"
86
81
  end
87
82
 
88
- it 'can combine multiple encodings, based on occurrence (gzip, base64)' do
89
- @test_object.params = {
90
- 'base64' => nil,
91
- 'gzip' => nil,
92
- }
83
+ it 'can combine multiple encodings, based on occurrence: base64, gzip (the other way around)' do
84
+ params = double('RailsStrongParameter')
85
+ allow(params).to receive(:symbolize_keys).and_return(base64: 'on', gzip: 'on')
93
86
 
94
87
  expect {
95
- result = @test_object.encode do
88
+ @test_object.encode params do
96
89
  'string'
97
90
  end
98
91
  }.not_to raise_error
99
92
  end
100
93
 
101
94
  it 'runs null encoders if no encoder is given' do
102
- @test_object.params = {
103
- }
95
+ params = double('RailsStrongParameter')
96
+ allow(params).to receive(:symbolize_keys).and_return({})
104
97
 
105
- result = @test_object.encode do
98
+ result = @test_object.encode params do
106
99
  'string'
107
100
  end
108
101
 
@@ -110,11 +103,10 @@ describe WebHelper do
110
103
  end
111
104
 
112
105
  it 'runs null encoders if unknown encoder is given' do
113
- @test_object.params = {
114
- 'unknown' => nil,
115
- }
106
+ params = double('RailsStrongParameter')
107
+ allow(params).to receive(:symbolize_keys).and_return(unknown: nil)
116
108
 
117
- result = @test_object.encode do
109
+ result = @test_object.encode params do
118
110
  'string'
119
111
  end
120
112
 
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the ErrorsHelper. For example:
5
+ #
6
+ # describe ErrorsHelper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # expect(helper.concat_strings("this","that")).to eq("this that")
10
+ # end
11
+ # end
12
+ # end
13
+ describe ErrorsHelper do
14
+ pending "add some examples to (or delete) #{__FILE__}"
15
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe PermittedParams do
5
+ context '#initialize' do
6
+
7
+ end
8
+
9
+ context '#params_for_controller' do
10
+ it 'raises an error on unknown controller' do
11
+ params = ActionController::Parameters.new({})
12
+ permitted_params = PermittedParams.new(params)
13
+
14
+ expect {
15
+ permitted_params.params_for_controller("asdfasdf", "show", {})
16
+ }.to raise_error Exceptions::ControllerNotDefinedInParameterList
17
+ end
18
+
19
+ it 'raises an error on unknown action' do
20
+ params = ActionController::Parameters.new({})
21
+ permitted_params = PermittedParams.new(params)
22
+
23
+ expect {
24
+ permitted_params.params_for_controller("string", "asdf", {})
25
+ }.to raise_error Exceptions::ActionNotDefinedInParameterList
26
+ end
27
+
28
+ it 'defines parameters for controllers' do
29
+ params = ActionController::Parameters.new(count: 100)
30
+ permitted_params = PermittedParams.new(params)
31
+
32
+ params = permitted_params.params_for_controller("string", "plain", {})
33
+ expect(params[:count]).to eq 100
34
+ end
35
+ end
36
+
37
+ context '#known_params_for_controller' do
38
+ it 'raises an error on unknown controller' do
39
+ params = ActionController::Parameters.new({})
40
+ permitted_params = PermittedParams.new(params)
41
+
42
+ expect {
43
+ permitted_params.known_params_for_controller("asdfasdf", "show")
44
+ }.to raise_error Exceptions::ControllerNotDefinedInParameterList
45
+ end
46
+
47
+ it 'raises an error on unknown action' do
48
+ params = ActionController::Parameters.new({})
49
+ permitted_params = PermittedParams.new(params)
50
+
51
+ expect {
52
+ permitted_params.known_params_for_controller("string", "asdf")
53
+ }.to raise_error Exceptions::ActionNotDefinedInParameterList
54
+ end
55
+
56
+ it 'returns known parameters for controllers' do
57
+ params = ActionController::Parameters.new(count: 100)
58
+ permitted_params = PermittedParams.new(params)
59
+
60
+ params = permitted_params.known_params_for_controller("string", "plain")
61
+ expect(params).to eq [:base64, :base64_strict, :count, :expires, :gzip]
62
+ end
63
+ end
64
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # encoding: utf-8
2
2
  $LOAD_PATH << ::File.expand_path('../../lib', __FILE__)
3
3
 
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+ require File.expand_path("../../config/environment", __FILE__)
6
+
4
7
  require 'simplecov'
5
8
  SimpleCov.command_name 'rspec'
6
9
  SimpleCov.start
@@ -11,10 +14,48 @@ Bundler.require :default, :test, :development
11
14
 
12
15
  require 'test_server'
13
16
 
14
- require File.expand_path('../../app/controllers/application_controller.rb', __FILE__)
15
- Dir.glob(::File.expand_path('../../app/controllers/*.rb', __FILE__)).each { |f| require f }
16
-
17
17
  # Loading support files
18
18
  Dir.glob(::File.expand_path('../support/*.rb', __FILE__)).each { |f| require_relative f }
19
19
 
20
20
  include TestServer
21
+
22
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
23
+ require 'rspec/rails'
24
+ require 'rspec/autorun'
25
+
26
+ # Requires supporting ruby files with custom matchers and macros, etc,
27
+ # in spec/support/ and its subdirectories.
28
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
29
+
30
+ # Checks for pending migrations before tests are run.
31
+ # If you are not using ActiveRecord, you can remove this line.
32
+ ActiveRecord::Migration.maintain_test_schema!
33
+
34
+ RSpec.configure do |config|
35
+ # ## Mock Framework
36
+ #
37
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
38
+ #
39
+ # config.mock_with :mocha
40
+ # config.mock_with :flexmock
41
+ # config.mock_with :rr
42
+
43
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
44
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
45
+
46
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
47
+ # examples within a transaction, remove the following line or assign false
48
+ # instead of true.
49
+ config.use_transactional_fixtures = true
50
+
51
+ # If true, the base class of anonymous controllers will be inferred
52
+ # automatically. This will be the default behavior in future versions of
53
+ # rspec-rails.
54
+ config.infer_base_class_for_anonymous_controllers = false
55
+
56
+ # Run specs in random order to surface order dependencies. If you find an
57
+ # order dependency and want to debug it, you can fix the order by providing
58
+ # the seed, which is printed after each run.
59
+ # --seed 1234
60
+ config.order = "random"
61
+ end
@@ -1,3 +1,7 @@
1
+ # encoding: utf-8
2
+ require 'capybara/rspec'
3
+ require 'capybara/rails'
4
+
1
5
  module TestServer
2
6
  module SpecHelper
3
7
  module Capybara
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ #
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../../../config/environment", __FILE__)
5
+
6
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
7
+ require 'rspec/rails'
8
+ require 'rspec/autorun'
9
+
10
+ # Checks for pending migrations before tests are run.
11
+ # If you are not using ActiveRecord, you can remove this line.
12
+ ActiveRecord::Migration.maintain_test_schema!
13
+
14
+ RSpec.configure do |config|
15
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
16
+ #config.fixture_path = "#{::Rails.root}/spec/fixtures"
17
+
18
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
19
+ # examples within a transaction, remove the following line or assign false
20
+ # instead of true.
21
+ #config.use_transactional_fixtures = true
22
+
23
+ # If true, the base class of anonymous controllers will be inferred
24
+ # automatically. This will be the default behavior in future versions of
25
+ # rspec-rails.
26
+ #config.infer_base_class_for_anonymous_controllers = false
27
+
28
+ # Run specs in random order to surface order dependencies. If you find an
29
+ # order dependency and want to debug it, you can fix the order by providing
30
+ # the seed, which is printed after each run.
31
+ # --seed 1234
32
+ #config.order = "random"
33
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe "errors/not_found.html.haml" do
4
+ pending "add some examples to (or delete) #{__FILE__}"
5
+ end