rack-mock_json 0.0.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 (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/CODE_OF_CONDUCT.md +13 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +67 -0
  7. data/Rakefile +1 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +7 -0
  10. data/example/rails-example/.gitignore +13 -0
  11. data/example/rails-example/Gemfile +45 -0
  12. data/example/rails-example/README.rdoc +28 -0
  13. data/example/rails-example/Rakefile +6 -0
  14. data/example/rails-example/app/assets/images/.keep +0 -0
  15. data/example/rails-example/app/assets/javascripts/application.js +16 -0
  16. data/example/rails-example/app/assets/stylesheets/application.css +15 -0
  17. data/example/rails-example/app/controllers/application_controller.rb +5 -0
  18. data/example/rails-example/app/controllers/concerns/.keep +0 -0
  19. data/example/rails-example/app/helpers/application_helper.rb +2 -0
  20. data/example/rails-example/app/mailers/.keep +0 -0
  21. data/example/rails-example/app/models/.keep +0 -0
  22. data/example/rails-example/app/models/concerns/.keep +0 -0
  23. data/example/rails-example/app/views/layouts/application.html.erb +14 -0
  24. data/example/rails-example/bin/bundle +3 -0
  25. data/example/rails-example/bin/rails +4 -0
  26. data/example/rails-example/bin/rake +4 -0
  27. data/example/rails-example/bin/setup +29 -0
  28. data/example/rails-example/config.ru +4 -0
  29. data/example/rails-example/config/application.rb +26 -0
  30. data/example/rails-example/config/boot.rb +3 -0
  31. data/example/rails-example/config/database.yml +54 -0
  32. data/example/rails-example/config/environment.rb +5 -0
  33. data/example/rails-example/config/environments/development.rb +43 -0
  34. data/example/rails-example/config/environments/production.rb +79 -0
  35. data/example/rails-example/config/environments/test.rb +42 -0
  36. data/example/rails-example/config/initializers/assets.rb +11 -0
  37. data/example/rails-example/config/initializers/backtrace_silencers.rb +7 -0
  38. data/example/rails-example/config/initializers/cookies_serializer.rb +3 -0
  39. data/example/rails-example/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/example/rails-example/config/initializers/inflections.rb +16 -0
  41. data/example/rails-example/config/initializers/mime_types.rb +4 -0
  42. data/example/rails-example/config/initializers/session_store.rb +3 -0
  43. data/example/rails-example/config/initializers/wrap_parameters.rb +14 -0
  44. data/example/rails-example/config/locales/en.yml +23 -0
  45. data/example/rails-example/config/mock_json.yml +5 -0
  46. data/example/rails-example/config/routes.rb +56 -0
  47. data/example/rails-example/config/secrets.yml +22 -0
  48. data/example/rails-example/db/seeds.rb +7 -0
  49. data/example/rails-example/lib/assets/.keep +0 -0
  50. data/example/rails-example/lib/tasks/.keep +0 -0
  51. data/example/rails-example/log/.keep +0 -0
  52. data/example/rails-example/public/404.html +67 -0
  53. data/example/rails-example/public/422.html +67 -0
  54. data/example/rails-example/public/500.html +66 -0
  55. data/example/rails-example/public/favicon.ico +0 -0
  56. data/example/rails-example/public/robots.txt +5 -0
  57. data/example/rails-example/test/controllers/.keep +0 -0
  58. data/example/rails-example/test/fixtures/.keep +0 -0
  59. data/example/rails-example/test/helpers/.keep +0 -0
  60. data/example/rails-example/test/integration/.keep +0 -0
  61. data/example/rails-example/test/mailers/.keep +0 -0
  62. data/example/rails-example/test/models/.keep +0 -0
  63. data/example/rails-example/test/test_helper.rb +10 -0
  64. data/example/rails-example/vendor/assets/javascripts/.keep +0 -0
  65. data/example/rails-example/vendor/assets/stylesheets/.keep +0 -0
  66. data/lib/rack-mock_json.rb +1 -0
  67. data/lib/rack/mock_json.rb +9 -0
  68. data/lib/rack/mock_json/mock.rb +18 -0
  69. data/lib/rack/mock_json/request_handler.rb +43 -0
  70. data/lib/rack/mock_json/version.rb +5 -0
  71. data/rack-mock_json.gemspec +27 -0
  72. metadata +172 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
+ fixtures :all
8
+
9
+ # Add more helper methods to be used by all tests here...
10
+ end
@@ -0,0 +1 @@
1
+ require "rack/mock_json"
@@ -0,0 +1,9 @@
1
+ require "rack"
2
+ require "active_support"
3
+ require "active_support/core_ext"
4
+ require "yaml"
5
+ require "hashie"
6
+
7
+ require "rack/mock_json/request_handler"
8
+ require "rack/mock_json/mock"
9
+ require "rack/mock_json/version"
@@ -0,0 +1,18 @@
1
+ module Rack
2
+ module MockJson
3
+ class Mock
4
+ def initialize(config_file_path)
5
+ @config = YAML.load_file(config_file_path)
6
+ end
7
+
8
+ def mock_element(path)
9
+ element = @config.find { |e| path.match(/#{e[:request_path]}/).present? }
10
+ return nil if element.blank?
11
+
12
+ element = Hashie::Mash.new(element)
13
+ element.status ||= 200
14
+ element
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ module Rack
2
+ module MockJson
3
+ class RequestHandler
4
+ def initialize(app, config_file_path: nil)
5
+ @app = app
6
+ @mock = Rack::MockJson::Mock.new(config_file_path)
7
+ end
8
+
9
+ def call(env)
10
+ mock_element = @mock.mock_element(request_path(env))
11
+
12
+ return @app.call(env) if mock_element.nil?
13
+
14
+ [
15
+ mock_element.status,
16
+ {
17
+
18
+ "Content-Type" => "application/json",
19
+ "Content-Length" => mock_element.content.bytesize.to_s,
20
+ "X-XSS-Protection" => "1; mode=block",
21
+ "X-Content-Type-Options" => "nosniff",
22
+ "X-Frame-Options" => "SAMEORIGIN"
23
+ },
24
+ [mock_element.content]
25
+ ]
26
+ end
27
+
28
+ private
29
+
30
+ def request_path(env)
31
+ "#{request_method(env)} #{path_info(env)}"
32
+ end
33
+
34
+ def path_info(env)
35
+ env["PATH_INFO"]
36
+ end
37
+
38
+ def request_method(env)
39
+ env["REQUEST_METHOD"]
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module MockJson
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/mock_json/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-mock_json"
8
+ spec.version = Rack::MockJson::VERSION
9
+ spec.authors = ["fukuiretu"]
10
+ spec.email = ["s0232101@gmail.com"]
11
+
12
+ spec.summary = %q{any request in the rack layer, returns any json response(Content-Type: application/json) and http status.}
13
+ spec.description = %q{any request in the rack layer, returns any json response(Content-Type: application/json) and http status.}
14
+ spec.homepage = "https://github.com/fukuiretu/rack-mock_json"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "activesupport"
23
+ spec.add_runtime_dependency "hashie"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-mock_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - fukuiretu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: 'any request in the rack layer, returns any json response(Content-Type:
70
+ application/json) and http status.'
71
+ email:
72
+ - s0232101@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - example/rails-example/.gitignore
86
+ - example/rails-example/Gemfile
87
+ - example/rails-example/README.rdoc
88
+ - example/rails-example/Rakefile
89
+ - example/rails-example/app/assets/images/.keep
90
+ - example/rails-example/app/assets/javascripts/application.js
91
+ - example/rails-example/app/assets/stylesheets/application.css
92
+ - example/rails-example/app/controllers/application_controller.rb
93
+ - example/rails-example/app/controllers/concerns/.keep
94
+ - example/rails-example/app/helpers/application_helper.rb
95
+ - example/rails-example/app/mailers/.keep
96
+ - example/rails-example/app/models/.keep
97
+ - example/rails-example/app/models/concerns/.keep
98
+ - example/rails-example/app/views/layouts/application.html.erb
99
+ - example/rails-example/bin/bundle
100
+ - example/rails-example/bin/rails
101
+ - example/rails-example/bin/rake
102
+ - example/rails-example/bin/setup
103
+ - example/rails-example/config.ru
104
+ - example/rails-example/config/application.rb
105
+ - example/rails-example/config/boot.rb
106
+ - example/rails-example/config/database.yml
107
+ - example/rails-example/config/environment.rb
108
+ - example/rails-example/config/environments/development.rb
109
+ - example/rails-example/config/environments/production.rb
110
+ - example/rails-example/config/environments/test.rb
111
+ - example/rails-example/config/initializers/assets.rb
112
+ - example/rails-example/config/initializers/backtrace_silencers.rb
113
+ - example/rails-example/config/initializers/cookies_serializer.rb
114
+ - example/rails-example/config/initializers/filter_parameter_logging.rb
115
+ - example/rails-example/config/initializers/inflections.rb
116
+ - example/rails-example/config/initializers/mime_types.rb
117
+ - example/rails-example/config/initializers/session_store.rb
118
+ - example/rails-example/config/initializers/wrap_parameters.rb
119
+ - example/rails-example/config/locales/en.yml
120
+ - example/rails-example/config/mock_json.yml
121
+ - example/rails-example/config/routes.rb
122
+ - example/rails-example/config/secrets.yml
123
+ - example/rails-example/db/seeds.rb
124
+ - example/rails-example/lib/assets/.keep
125
+ - example/rails-example/lib/tasks/.keep
126
+ - example/rails-example/log/.keep
127
+ - example/rails-example/public/404.html
128
+ - example/rails-example/public/422.html
129
+ - example/rails-example/public/500.html
130
+ - example/rails-example/public/favicon.ico
131
+ - example/rails-example/public/robots.txt
132
+ - example/rails-example/test/controllers/.keep
133
+ - example/rails-example/test/fixtures/.keep
134
+ - example/rails-example/test/helpers/.keep
135
+ - example/rails-example/test/integration/.keep
136
+ - example/rails-example/test/mailers/.keep
137
+ - example/rails-example/test/models/.keep
138
+ - example/rails-example/test/test_helper.rb
139
+ - example/rails-example/vendor/assets/javascripts/.keep
140
+ - example/rails-example/vendor/assets/stylesheets/.keep
141
+ - lib/rack-mock_json.rb
142
+ - lib/rack/mock_json.rb
143
+ - lib/rack/mock_json/mock.rb
144
+ - lib/rack/mock_json/request_handler.rb
145
+ - lib/rack/mock_json/version.rb
146
+ - rack-mock_json.gemspec
147
+ homepage: https://github.com/fukuiretu/rack-mock_json
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.4.8
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: 'any request in the rack layer, returns any json response(Content-Type: application/json)
171
+ and http status.'
172
+ test_files: []