firetail 0.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +11 -0
- data/.github/workflows/main.yml +40 -0
- data/.gitignore +28 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +74 -0
- data/LICENSE +165 -0
- data/LICENSE.txt +165 -21
- data/README.md +24 -10
- data/examples/rails/.gitattributes +8 -0
- data/examples/rails/.gitignore +31 -0
- data/examples/rails/.rspec +1 -0
- data/examples/rails/.ruby-version +1 -0
- data/examples/rails/Gemfile +44 -0
- data/examples/rails/Gemfile.lock +240 -0
- data/examples/rails/README.md +24 -0
- data/examples/rails/Rakefile +6 -0
- data/examples/rails/app/channels/application_cable/channel.rb +4 -0
- data/examples/rails/app/channels/application_cable/connection.rb +4 -0
- data/examples/rails/app/controllers/application_controller.rb +2 -0
- data/examples/rails/app/controllers/comments_controller.rb +52 -0
- data/examples/rails/app/controllers/concerns/.keep +0 -0
- data/examples/rails/app/controllers/posts_controller.rb +51 -0
- data/examples/rails/app/jobs/application_job.rb +7 -0
- data/examples/rails/app/mailers/application_mailer.rb +4 -0
- data/examples/rails/app/models/application_record.rb +3 -0
- data/examples/rails/app/models/comment.rb +4 -0
- data/examples/rails/app/models/concerns/.keep +0 -0
- data/examples/rails/app/models/post.rb +5 -0
- data/examples/rails/app/views/layouts/mailer.html.erb +13 -0
- data/examples/rails/app/views/layouts/mailer.text.erb +1 -0
- data/examples/rails/bin/bundle +114 -0
- data/examples/rails/bin/rails +5 -0
- data/examples/rails/bin/rake +5 -0
- data/examples/rails/bin/setup +33 -0
- data/examples/rails/bin/spring +14 -0
- data/examples/rails/config/application.rb +41 -0
- data/examples/rails/config/boot.rb +4 -0
- data/examples/rails/config/cable.yml +10 -0
- data/examples/rails/config/credentials.yml.enc +1 -0
- data/examples/rails/config/database.yml +25 -0
- data/examples/rails/config/environment.rb +5 -0
- data/examples/rails/config/environments/development.rb +66 -0
- data/examples/rails/config/environments/production.rb +113 -0
- data/examples/rails/config/environments/test.rb +60 -0
- data/examples/rails/config/firetail.yml +2 -0
- data/examples/rails/config/initializers/application_controller_renderer.rb +8 -0
- data/examples/rails/config/initializers/backtrace_silencers.rb +8 -0
- data/examples/rails/config/initializers/cors.rb +16 -0
- data/examples/rails/config/initializers/filter_parameter_logging.rb +6 -0
- data/examples/rails/config/initializers/inflections.rb +16 -0
- data/examples/rails/config/initializers/mime_types.rb +4 -0
- data/examples/rails/config/initializers/wrap_parameters.rb +14 -0
- data/examples/rails/config/locales/en.yml +33 -0
- data/examples/rails/config/puma.rb +43 -0
- data/examples/rails/config/routes.rb +6 -0
- data/examples/rails/config/schema.json +431 -0
- data/examples/rails/config/spring.rb +6 -0
- data/examples/rails/config/storage.yml +34 -0
- data/examples/rails/config.ru +6 -0
- data/examples/rails/db/migrate/20230730163722_create_posts.rb +8 -0
- data/examples/rails/db/migrate/20230730163741_create_comments.rb +9 -0
- data/examples/rails/db/migrate/20230730164121_add_fields_to_post.rb +6 -0
- data/examples/rails/db/migrate/20230730164214_add_fields_to_comments.rb +6 -0
- data/examples/rails/db/schema.rb +30 -0
- data/examples/rails/db/seeds.rb +7 -0
- data/examples/rails/lib/tasks/.keep +0 -0
- data/examples/rails/log/.keep +0 -0
- data/examples/rails/public/robots.txt +1 -0
- data/examples/rails/spec/models/comment_spec.rb +5 -0
- data/examples/rails/spec/models/post_spec.rb +5 -0
- data/examples/rails/spec/rails_helper.rb +63 -0
- data/examples/rails/spec/requests/comments_spec.rb +127 -0
- data/examples/rails/spec/requests/posts_spec.rb +127 -0
- data/examples/rails/spec/routing/comments_routing_spec.rb +30 -0
- data/examples/rails/spec/routing/posts_routing_spec.rb +30 -0
- data/examples/rails/spec/spec_helper.rb +94 -0
- data/examples/rails/storage/.keep +0 -0
- data/examples/rails/test/channels/application_cable/connection_test.rb +11 -0
- data/examples/rails/test/controllers/.keep +0 -0
- data/examples/rails/test/fixtures/files/.keep +0 -0
- data/examples/rails/test/integration/.keep +0 -0
- data/examples/rails/test/mailers/.keep +0 -0
- data/examples/rails/test/models/.keep +0 -0
- data/examples/rails/test/test_helper.rb +13 -0
- data/examples/rails/tmp/.keep +0 -0
- data/examples/rails/tmp/pids/.keep +0 -0
- data/examples/rails/vendor/.keep +0 -0
- data/firetail.gemspec +8 -1
- data/lib/backend.rb +34 -0
- data/lib/background_tasks.rb +43 -0
- data/lib/case_sensitive_headers.rb +29 -0
- data/lib/firetail/version.rb +1 -1
- data/lib/firetail.rb +264 -1
- data/lib/generators/firetail/install/templates/README +15 -0
- data/lib/generators/firetail/install/templates/firetail.yml +2 -0
- data/lib/generators/firetail/install/templates/schema.json +108 -0
- data/lib/generators/firetail/install_generator.rb +26 -0
- data/lib/railtie.rb +29 -0
- metadata +169 -8
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to test the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
|
15
|
+
RSpec.describe "/comments", type: :request do
|
16
|
+
# This should return the minimal set of attributes required to create a valid
|
17
|
+
# Comment. As you add validations to Comment, be sure to
|
18
|
+
# adjust the attributes here as well.
|
19
|
+
let(:valid_attributes) {
|
20
|
+
skip("Add a hash of attributes valid for your model")
|
21
|
+
}
|
22
|
+
|
23
|
+
let(:invalid_attributes) {
|
24
|
+
skip("Add a hash of attributes invalid for your model")
|
25
|
+
}
|
26
|
+
|
27
|
+
# This should return the minimal set of values that should be in the headers
|
28
|
+
# in order to pass any filters (e.g. authentication) defined in
|
29
|
+
# CommentsController, or in your router and rack
|
30
|
+
# middleware. Be sure to keep this updated too.
|
31
|
+
let(:valid_headers) {
|
32
|
+
{}
|
33
|
+
}
|
34
|
+
|
35
|
+
describe "GET /index" do
|
36
|
+
it "renders a successful response" do
|
37
|
+
Comment.create! valid_attributes
|
38
|
+
get comments_url, headers: valid_headers, as: :json
|
39
|
+
expect(response).to be_successful
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "GET /show" do
|
44
|
+
it "renders a successful response" do
|
45
|
+
comment = Comment.create! valid_attributes
|
46
|
+
get comment_url(comment), as: :json
|
47
|
+
expect(response).to be_successful
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "POST /create" do
|
52
|
+
context "with valid parameters" do
|
53
|
+
it "creates a new Comment" do
|
54
|
+
expect {
|
55
|
+
post comments_url,
|
56
|
+
params: { comment: valid_attributes }, headers: valid_headers, as: :json
|
57
|
+
}.to change(Comment, :count).by(1)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "renders a JSON response with the new comment" do
|
61
|
+
post comments_url,
|
62
|
+
params: { comment: valid_attributes }, headers: valid_headers, as: :json
|
63
|
+
expect(response).to have_http_status(:created)
|
64
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with invalid parameters" do
|
69
|
+
it "does not create a new Comment" do
|
70
|
+
expect {
|
71
|
+
post comments_url,
|
72
|
+
params: { comment: invalid_attributes }, as: :json
|
73
|
+
}.to change(Comment, :count).by(0)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "renders a JSON response with errors for the new comment" do
|
77
|
+
post comments_url,
|
78
|
+
params: { comment: invalid_attributes }, headers: valid_headers, as: :json
|
79
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
80
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "PATCH /update" do
|
86
|
+
context "with valid parameters" do
|
87
|
+
let(:new_attributes) {
|
88
|
+
skip("Add a hash of attributes valid for your model")
|
89
|
+
}
|
90
|
+
|
91
|
+
it "updates the requested comment" do
|
92
|
+
comment = Comment.create! valid_attributes
|
93
|
+
patch comment_url(comment),
|
94
|
+
params: { comment: new_attributes }, headers: valid_headers, as: :json
|
95
|
+
comment.reload
|
96
|
+
skip("Add assertions for updated state")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "renders a JSON response with the comment" do
|
100
|
+
comment = Comment.create! valid_attributes
|
101
|
+
patch comment_url(comment),
|
102
|
+
params: { comment: new_attributes }, headers: valid_headers, as: :json
|
103
|
+
expect(response).to have_http_status(:ok)
|
104
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with invalid parameters" do
|
109
|
+
it "renders a JSON response with errors for the comment" do
|
110
|
+
comment = Comment.create! valid_attributes
|
111
|
+
patch comment_url(comment),
|
112
|
+
params: { comment: invalid_attributes }, headers: valid_headers, as: :json
|
113
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
114
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "DELETE /destroy" do
|
120
|
+
it "destroys the requested comment" do
|
121
|
+
comment = Comment.create! valid_attributes
|
122
|
+
expect {
|
123
|
+
delete comment_url(comment), headers: valid_headers, as: :json
|
124
|
+
}.to change(Comment, :count).by(-1)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
4
|
+
# It demonstrates how one might use RSpec to test the controller code that
|
5
|
+
# was generated by Rails when you ran the scaffold generator.
|
6
|
+
#
|
7
|
+
# It assumes that the implementation code is generated by the rails scaffold
|
8
|
+
# generator. If you are using any extension libraries to generate different
|
9
|
+
# controller code, this generated spec may or may not pass.
|
10
|
+
#
|
11
|
+
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
12
|
+
# of tools you can use to make these specs even more expressive, but we're
|
13
|
+
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
14
|
+
|
15
|
+
RSpec.describe "/posts", type: :request do
|
16
|
+
# This should return the minimal set of attributes required to create a valid
|
17
|
+
# Post. As you add validations to Post, be sure to
|
18
|
+
# adjust the attributes here as well.
|
19
|
+
let(:valid_attributes) {
|
20
|
+
skip("Add a hash of attributes valid for your model")
|
21
|
+
}
|
22
|
+
|
23
|
+
let(:invalid_attributes) {
|
24
|
+
skip("Add a hash of attributes invalid for your model")
|
25
|
+
}
|
26
|
+
|
27
|
+
# This should return the minimal set of values that should be in the headers
|
28
|
+
# in order to pass any filters (e.g. authentication) defined in
|
29
|
+
# PostsController, or in your router and rack
|
30
|
+
# middleware. Be sure to keep this updated too.
|
31
|
+
let(:valid_headers) {
|
32
|
+
{}
|
33
|
+
}
|
34
|
+
|
35
|
+
describe "GET /index" do
|
36
|
+
it "renders a successful response" do
|
37
|
+
Post.create! valid_attributes
|
38
|
+
get posts_url, headers: valid_headers, as: :json
|
39
|
+
expect(response).to be_successful
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "GET /show" do
|
44
|
+
it "renders a successful response" do
|
45
|
+
post = Post.create! valid_attributes
|
46
|
+
get post_url(post), as: :json
|
47
|
+
expect(response).to be_successful
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "POST /create" do
|
52
|
+
context "with valid parameters" do
|
53
|
+
it "creates a new Post" do
|
54
|
+
expect {
|
55
|
+
post posts_url,
|
56
|
+
params: { post: valid_attributes }, headers: valid_headers, as: :json
|
57
|
+
}.to change(Post, :count).by(1)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "renders a JSON response with the new post" do
|
61
|
+
post posts_url,
|
62
|
+
params: { post: valid_attributes }, headers: valid_headers, as: :json
|
63
|
+
expect(response).to have_http_status(:created)
|
64
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with invalid parameters" do
|
69
|
+
it "does not create a new Post" do
|
70
|
+
expect {
|
71
|
+
post posts_url,
|
72
|
+
params: { post: invalid_attributes }, as: :json
|
73
|
+
}.to change(Post, :count).by(0)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "renders a JSON response with errors for the new post" do
|
77
|
+
post posts_url,
|
78
|
+
params: { post: invalid_attributes }, headers: valid_headers, as: :json
|
79
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
80
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "PATCH /update" do
|
86
|
+
context "with valid parameters" do
|
87
|
+
let(:new_attributes) {
|
88
|
+
skip("Add a hash of attributes valid for your model")
|
89
|
+
}
|
90
|
+
|
91
|
+
it "updates the requested post" do
|
92
|
+
post = Post.create! valid_attributes
|
93
|
+
patch post_url(post),
|
94
|
+
params: { post: new_attributes }, headers: valid_headers, as: :json
|
95
|
+
post.reload
|
96
|
+
skip("Add assertions for updated state")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "renders a JSON response with the post" do
|
100
|
+
post = Post.create! valid_attributes
|
101
|
+
patch post_url(post),
|
102
|
+
params: { post: new_attributes }, headers: valid_headers, as: :json
|
103
|
+
expect(response).to have_http_status(:ok)
|
104
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with invalid parameters" do
|
109
|
+
it "renders a JSON response with errors for the post" do
|
110
|
+
post = Post.create! valid_attributes
|
111
|
+
patch post_url(post),
|
112
|
+
params: { post: invalid_attributes }, headers: valid_headers, as: :json
|
113
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
114
|
+
expect(response.content_type).to match(a_string_including("application/json"))
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "DELETE /destroy" do
|
120
|
+
it "destroys the requested post" do
|
121
|
+
post = Post.create! valid_attributes
|
122
|
+
expect {
|
123
|
+
delete post_url(post), headers: valid_headers, as: :json
|
124
|
+
}.to change(Post, :count).by(-1)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe CommentsController, type: :routing do
|
4
|
+
describe "routing" do
|
5
|
+
it "routes to #index" do
|
6
|
+
expect(get: "/comments").to route_to("comments#index")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "routes to #show" do
|
10
|
+
expect(get: "/comments/1").to route_to("comments#show", id: "1")
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
it "routes to #create" do
|
15
|
+
expect(post: "/comments").to route_to("comments#create")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "routes to #update via PUT" do
|
19
|
+
expect(put: "/comments/1").to route_to("comments#update", id: "1")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "routes to #update via PATCH" do
|
23
|
+
expect(patch: "/comments/1").to route_to("comments#update", id: "1")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "routes to #destroy" do
|
27
|
+
expect(delete: "/comments/1").to route_to("comments#destroy", id: "1")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rails_helper"
|
2
|
+
|
3
|
+
RSpec.describe PostsController, type: :routing do
|
4
|
+
describe "routing" do
|
5
|
+
it "routes to #index" do
|
6
|
+
expect(get: "/posts").to route_to("posts#index")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "routes to #show" do
|
10
|
+
expect(get: "/posts/1").to route_to("posts#show", id: "1")
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
it "routes to #create" do
|
15
|
+
expect(post: "/posts").to route_to("posts#create")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "routes to #update via PUT" do
|
19
|
+
expect(put: "/posts/1").to route_to("posts#update", id: "1")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "routes to #update via PATCH" do
|
23
|
+
expect(patch: "/posts/1").to route_to("posts#update", id: "1")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "routes to #destroy" do
|
27
|
+
expect(delete: "/posts/1").to route_to("posts#destroy", id: "1")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
RSpec.configure do |config|
|
17
|
+
# rspec-expectations config goes here. You can use an alternate
|
18
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
19
|
+
# assertions if you prefer.
|
20
|
+
config.expect_with :rspec do |expectations|
|
21
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
22
|
+
# and `failure_message` of custom matchers include text for helper methods
|
23
|
+
# defined using `chain`, e.g.:
|
24
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
25
|
+
# # => "be bigger than 2 and smaller than 4"
|
26
|
+
# ...rather than:
|
27
|
+
# # => "be bigger than 2"
|
28
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
32
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
33
|
+
config.mock_with :rspec do |mocks|
|
34
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
35
|
+
# a real object. This is generally recommended, and will default to
|
36
|
+
# `true` in RSpec 4.
|
37
|
+
mocks.verify_partial_doubles = true
|
38
|
+
end
|
39
|
+
|
40
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
41
|
+
# have no way to turn it off -- the option exists only for backwards
|
42
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
43
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
44
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
45
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
46
|
+
|
47
|
+
# The settings below are suggested to provide a good initial experience
|
48
|
+
# with RSpec, but feel free to customize to your heart's content.
|
49
|
+
=begin
|
50
|
+
# This allows you to limit a spec run to individual examples or groups
|
51
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
52
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
53
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
54
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
55
|
+
config.filter_run_when_matching :focus
|
56
|
+
|
57
|
+
# Allows RSpec to persist some state between runs in order to support
|
58
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
59
|
+
# you configure your source control system to ignore this file.
|
60
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
61
|
+
|
62
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
63
|
+
# recommended. For more details, see:
|
64
|
+
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
|
65
|
+
config.disable_monkey_patching!
|
66
|
+
|
67
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
68
|
+
# file, and it's useful to allow more verbose output when running an
|
69
|
+
# individual spec file.
|
70
|
+
if config.files_to_run.one?
|
71
|
+
# Use the documentation formatter for detailed output,
|
72
|
+
# unless a formatter has already been configured
|
73
|
+
# (e.g. via a command-line flag).
|
74
|
+
config.default_formatter = "doc"
|
75
|
+
end
|
76
|
+
|
77
|
+
# Print the 10 slowest examples and example groups at the
|
78
|
+
# end of the spec run, to help surface which specs are running
|
79
|
+
# particularly slow.
|
80
|
+
config.profile_examples = 10
|
81
|
+
|
82
|
+
# Run specs in random order to surface order dependencies. If you find an
|
83
|
+
# order dependency and want to debug it, you can fix the order by providing
|
84
|
+
# the seed, which is printed after each run.
|
85
|
+
# --seed 1234
|
86
|
+
config.order = :random
|
87
|
+
|
88
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
89
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
90
|
+
# test failures related to randomization by passing the same `--seed` value
|
91
|
+
# as the one that triggered the failure.
|
92
|
+
Kernel.srand config.seed
|
93
|
+
=end
|
94
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
require_relative "../config/environment"
|
3
|
+
require "rails/test_help"
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Run tests in parallel with specified workers
|
7
|
+
parallelize(workers: :number_of_processors)
|
8
|
+
|
9
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
10
|
+
fixtures :all
|
11
|
+
|
12
|
+
# Add more helper methods to be used by all tests here...
|
13
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
data/firetail.gemspec
CHANGED
@@ -29,6 +29,13 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.require_paths = ["lib"]
|
30
30
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
-
spec.add_development_dependency "rake", "~>
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "webmock", "~> 3.18.1"
|
35
|
+
|
36
|
+
# These gems are needed for firetail in production
|
37
|
+
spec.add_dependency "async", "~> 1.30.3"
|
38
|
+
spec.add_dependency "jwt", "~> 2.5"
|
39
|
+
spec.add_dependency "json-schema", "~> 3.0.0"
|
40
|
+
spec.add_dependency "committee_firetail", "~> 5.0.1"
|
34
41
|
end
|
data/lib/backend.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class Backend
|
2
|
+
|
3
|
+
def self.send_now(payload, options)
|
4
|
+
#Firetail.logger.debug "running backend"
|
5
|
+
# Parse it as URI
|
6
|
+
uri = URI(options[:url])
|
7
|
+
|
8
|
+
# Create a new request
|
9
|
+
http = Net::HTTP.new(uri.hostname, uri.port)
|
10
|
+
#http.set_debug_output($stdout) # Use this is you want to see the data output
|
11
|
+
http.use_ssl = true
|
12
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
13
|
+
http.read_timeout = options[:network_timeout]
|
14
|
+
|
15
|
+
begin
|
16
|
+
# Create a new request
|
17
|
+
req = CustomPost.new(uri.path,
|
18
|
+
{
|
19
|
+
'content-type': 'application/nd-json',
|
20
|
+
'x-ft-api-key': options[:api_key]
|
21
|
+
})
|
22
|
+
|
23
|
+
req.body = payload
|
24
|
+
# Create new thread
|
25
|
+
Thread.new {
|
26
|
+
# Send the request
|
27
|
+
request = http.request(req)
|
28
|
+
}
|
29
|
+
#Firetail.logger.debug "response from firetail: #{res}"
|
30
|
+
rescue StandardError => e
|
31
|
+
Firetail.logger.info "Firetail HTTP Request failed (#{e.message})"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'backend'
|
2
|
+
|
3
|
+
class BackgroundTasks
|
4
|
+
|
5
|
+
# send the data to backend API
|
6
|
+
# This is an async task
|
7
|
+
def self.http_task(url,
|
8
|
+
timeout,
|
9
|
+
api_key,
|
10
|
+
retries,
|
11
|
+
payload)
|
12
|
+
Async do |task|
|
13
|
+
task.async do
|
14
|
+
# below code includes exponential backoff algorithm
|
15
|
+
retries = 0
|
16
|
+
begin
|
17
|
+
# send to firetail backend
|
18
|
+
# values to use for backend object
|
19
|
+
options = {"url": url,
|
20
|
+
"network_timeout": timeout,
|
21
|
+
"api_key": api_key}
|
22
|
+
|
23
|
+
request = Backend.send_now(payload, options)
|
24
|
+
Firetail.logger.info "Successfully sent to Firetail"
|
25
|
+
rescue Net::HTTPError => e
|
26
|
+
# if request response code is an error
|
27
|
+
# then try sending.
|
28
|
+
# @number_of_retries is configurable in .yaml file
|
29
|
+
|
30
|
+
if retries <= retries
|
31
|
+
retries += 1
|
32
|
+
max_sleep_seconds = Float(2 ** retries)
|
33
|
+
sleep rand(0..max_sleep_seconds)
|
34
|
+
retry
|
35
|
+
else
|
36
|
+
raise "Giving up on the server after #{retries} retries. Got error: #{e.message}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class CustomPost < Net::HTTP::Post
|
2
|
+
def initialize_http_header(headers)
|
3
|
+
@header = {}
|
4
|
+
headers.each { |k, v| @header[k.to_s] = [v] }
|
5
|
+
end
|
6
|
+
|
7
|
+
def [](name)
|
8
|
+
_k, val = header_insensitive_match name
|
9
|
+
val
|
10
|
+
end
|
11
|
+
|
12
|
+
def []=(name, val)
|
13
|
+
key, _val = header_insensitive_match name
|
14
|
+
key = name if key.nil?
|
15
|
+
if val
|
16
|
+
@header[key] = [val]
|
17
|
+
else
|
18
|
+
@header.delete(key)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def capitalize(name)
|
23
|
+
name
|
24
|
+
end
|
25
|
+
|
26
|
+
def header_insensitive_match(name)
|
27
|
+
@header.find { |key, _value| key.match Regexp.new(name.to_s, Regexp::IGNORECASE) }
|
28
|
+
end
|
29
|
+
end
|
data/lib/firetail/version.rb
CHANGED