-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from ChrisBr/refactoring
Several refactorings
- Loading branch information
Showing
11 changed files
with
49 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
RSpec.describe "Context", type: :request do | ||
before do | ||
allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_environments).and_return(%w[development]) | ||
end | ||
|
||
it "resets the context between requests" do | ||
it "resets the context after a request" do | ||
get "/metrics" | ||
|
||
expect_metric( | ||
tags: a_hash_including( | ||
method: "MetricsController#index", | ||
hook: "process_action" | ||
location: "MetricsController#index", | ||
hook: "sql" | ||
) | ||
) | ||
|
||
get "/exceptions" | ||
expect(InfluxDB::Rails.current.tags).to be_empty | ||
expect(InfluxDB::Rails.current.values).to be_empty | ||
end | ||
|
||
expect_metric( | ||
name: "rails", | ||
tags: a_hash_including( | ||
method: "ExceptionsController#index", | ||
hook: "process_action" | ||
) | ||
) | ||
it "resets the context after a request when exceptioni occurs" do | ||
setup_broken_client | ||
|
||
get "/metrics" | ||
|
||
expect_no_metric(hook: "process_action") | ||
expect(InfluxDB::Rails.current.tags).to be_empty | ||
expect(InfluxDB::Rails.current.values).to be_empty | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require File.dirname(__FILE__) + "/../spec_helper" | ||
|
||
RSpec.describe "Logger", type: :request do | ||
it "logs exception" do | ||
setup_broken_client | ||
expect(Rails.logger).to receive(:error).with(/message/).at_least(:once) | ||
|
||
get "/metrics" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require File.expand_path(File.dirname(__FILE__) + "/test_client") | ||
|
||
module InfluxDB | ||
module Rails | ||
module BrokenClient | ||
def setup_broken_client | ||
client = double | ||
allow(client).to receive(:write_point).and_raise("message") | ||
allow(InfluxDB::Rails).to receive(:client).and_return(client) | ||
end | ||
end | ||
end | ||
end |