spec/lib/appsignal/transaction_spec.rb in appsignal-1.2.5 vs spec/lib/appsignal/transaction_spec.rb in appsignal-1.3.0.beta.1
- old
+ new
@@ -22,11 +22,10 @@
before { Timecop.freeze(time) }
after { Timecop.return }
context "class methods" do
describe ".create" do
-
it "should add the transaction to thread local" do
Appsignal::Extension.should_receive(:start_transaction).with('1', 'http_request')
created_transaction = Appsignal::Transaction.create('1', namespace, request, options)
@@ -445,11 +444,11 @@
transaction.start_event
end
end
- describe "finish_event" do
+ describe "#finish_event" do
it "should finish the event in the extension" do
transaction.ext.should_receive(:finish_event).with(
'name',
'title',
'body',
@@ -479,10 +478,67 @@
nil
)
end
end
+ describe "#record_event" do
+ it "should record the event in the extension" do
+ transaction.ext.should_receive(:record_event).with(
+ 'name',
+ 'title',
+ 'body',
+ 1000,
+ 1
+ )
+
+ transaction.record_event(
+ 'name',
+ 'title',
+ 'body',
+ 1000,
+ 1
+ )
+ end
+
+ it "should finish the event in the extension with nil arguments" do
+ transaction.ext.should_receive(:record_event).with(
+ 'name',
+ '',
+ '',
+ 1000,
+ 0
+ )
+
+ transaction.record_event(
+ 'name',
+ nil,
+ nil,
+ 1000,
+ nil
+ )
+ end
+ end
+
+ describe "#instrument" do
+ it "should start and finish an event around the given block" do
+ stub = double
+ stub.should_receive(:method_call).and_return('return value')
+
+ transaction.should_receive(:start_event)
+ transaction.should_receive(:finish_event).with(
+ 'name',
+ 'title',
+ 'body',
+ 0
+ )
+
+ transaction.instrument 'name', 'title', 'body' do
+ stub.method_call
+ end.should eq 'return value'
+ end
+ end
+
context "generic request" do
let(:env) { {} }
subject { Appsignal::Transaction::GenericRequest.new(env) }
it "should initialize with an empty env" do
@@ -593,43 +649,66 @@
before { transaction.request.stub(:params).and_raise(NoMethodError) }
it { should be_nil }
end
- context "when not sending params" do
- before { Appsignal.config.config_hash[:send_params] = false }
- after { Appsignal.config.config_hash[:send_params] = true }
+ context "when params method does not exist" do
+ let(:options) { {:params_method => :nonsense} }
it { should be_nil }
end
- context "when params method does not exist" do
- let(:options) { {:params_method => :nonsense} }
+ context "when not sending params" do
+ before { Appsignal.config.config_hash[:send_params] = false }
+ after { Appsignal.config.config_hash[:send_params] = true }
it { should be_nil }
end
context "with an array" do
- let(:request) { Appsignal::Transaction::GenericRequest.new(background_env_with_data(:params => ['arg1', 'arg2'])) }
+ let(:request) do
+ Appsignal::Transaction::GenericRequest.new(background_env_with_data(:params => ['arg1', 'arg2']))
+ end
it { should == ['arg1', 'arg2'] }
+
+ context "with AppSignal filtering" do
+ before { Appsignal.config.config_hash[:filter_parameters] = %w(foo) }
+ after { Appsignal.config.config_hash[:filter_parameters] = [] }
+
+ it { should == ['arg1', 'arg2'] }
+ end
end
context "with env" do
- it "should call the params sanitizer" do
- Appsignal::ParamsSanitizer.should_receive(:sanitize).with(kind_of(Hash)).and_return({
- 'controller' => 'blog_posts',
- 'action' => 'show',
- 'id' => '1'
- })
+ context "with sanitization" do
+ let(:request) do
+ Appsignal::Transaction::GenericRequest.new \
+ http_request_env_with_data(:params => { :foo => :bar })
+ end
- subject.should == {
- 'controller' => 'blog_posts',
- 'action' => 'show',
- 'id' => '1'
- }
+ it "should call the params sanitizer" do
+ puts Appsignal.config.config_hash[:filter_parameters].inspect
+ subject.should == { :foo => :bar }
+ end
end
+
+ context "with AppSignal filtering" do
+ let(:request) do
+ Appsignal::Transaction::GenericRequest.new \
+ http_request_env_with_data(:params => { :foo => :bar, :baz => :bat })
+ end
+ before { Appsignal.config.config_hash[:filter_parameters] = %w(foo) }
+ after { Appsignal.config.config_hash[:filter_parameters] = [] }
+
+ it "should call the params sanitizer with filtering" do
+ subject.should == {
+ :foo => '[FILTERED]',
+ :baz => :bat
+ }
+ end
+ end
end
end
describe "#sanitized_environment" do
let(:whitelisted_keys) { Appsignal::Transaction::ENV_METHODS }
@@ -682,11 +761,11 @@
transaction.stub_chain(:request, :session => {:foo => :bar})
transaction.stub_chain(:request, :fullpath => :bar)
end
it "passes the session data into the params sanitizer" do
- Appsignal::ParamsSanitizer.should_receive(:sanitize).with({:foo => :bar}).
+ Appsignal::Utils::ParamsSanitizer.should_receive(:sanitize).with({:foo => :bar}).
and_return(:sanitized_foo)
subject.should == :sanitized_foo
end
if defined? ActionDispatch::Request::Session
@@ -696,11 +775,11 @@
transaction.stub_chain(:request, :session => action_dispatch_session)
transaction.stub_chain(:request, :fullpath => :bar)
end
it "should return an session hash" do
- Appsignal::ParamsSanitizer.should_receive(:sanitize).with({'foo' => :bar}).
+ Appsignal::Utils::ParamsSanitizer.should_receive(:sanitize).with({'foo' => :bar}).
and_return(:sanitized_foo)
subject
end
def action_dispatch_session
@@ -717,10 +796,10 @@
before do
Appsignal.config = {:skip_session_data => true}
end
it "does not pass the session data into the params sanitizer" do
- Appsignal::ParamsSanitizer.should_not_receive(:sanitize)
+ Appsignal::Utils::ParamsSanitizer.should_not_receive(:sanitize)
subject.should be_nil
end
end
end
end