spec/lib/appsignal/transaction_spec.rb in appsignal-1.3.1 vs spec/lib/appsignal/transaction_spec.rb in appsignal-1.3.2
- old
+ new
@@ -27,19 +27,19 @@
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)
- Thread.current[:appsignal_transaction].should == created_transaction
+ Thread.current[:appsignal_transaction].should eq created_transaction
end
it "should create a transaction" do
created_transaction = Appsignal::Transaction.create('1', namespace, request, options)
created_transaction.should be_a Appsignal::Transaction
- created_transaction.transaction_id.should == '1'
- created_transaction.namespace.should == 'http_request'
+ created_transaction.transaction_id.should eq '1'
+ created_transaction.namespace.should eq 'http_request'
end
context "when a transaction is already running" do
let(:running_transaction) { double(:transaction_id => 2) }
before { Thread.current[:appsignal_transaction] = running_transaction }
@@ -76,11 +76,11 @@
context "if there is a transaction" do
before { Appsignal::Transaction.create('1', namespace, request, options) }
it "should return the correct transaction" do
- should == transaction
+ should eq transaction
end
it "should indicate it's not a nil transaction" do
subject.nil_transaction?.should be_false
end
@@ -117,10 +117,29 @@
Appsignal::Transaction.complete_current!
Thread.current[:appsignal_transaction].should be_nil
end
+
+ context "if a transaction is discarded" do
+ it "should not complete the transaction" do
+ Appsignal::Transaction.current.should_not_receive(:complete)
+
+ Appsignal::Transaction.current.discard!
+ expect(Appsignal::Transaction.current.discarded?).to be_true
+ Appsignal::Transaction.complete_current!
+
+ Thread.current[:appsignal_transaction].should be_nil
+ end
+
+ it "should not be discarded when restore! is called" do
+ Appsignal::Transaction.current.discard!
+ expect(Appsignal::Transaction.current.discarded?).to be_true
+ Appsignal::Transaction.current.restore!
+ expect(Appsignal::Transaction.current.discarded?).to be_false
+ end
+ end
end
end
describe "#complete" do
it "should sample data if it needs to be sampled" do
@@ -178,25 +197,25 @@
context "with transaction instance" do
context "initialization" do
subject { transaction }
its(:ext) { should_not be_nil }
- its(:transaction_id) { should == '1' }
- its(:namespace) { should == 'http_request' }
+ its(:transaction_id) { should eq '1' }
+ its(:namespace) { should eq 'http_request' }
its(:request) { should_not be_nil }
its(:paused) { should be_false }
- its(:tags) { should == {} }
+ its(:tags) { should eq({}) }
context "options" do
subject { transaction.options }
- its([:params_method]) { should == :params }
+ its([:params_method]) { should eq :params }
context "with overridden options" do
let(:options) { {:params_method => :filtered_params} }
- its([:params_method]) { should == :filtered_params }
+ its([:params_method]) { should eq :filtered_params }
end
end
end
describe "#store" do
@@ -551,28 +570,28 @@
:params => {:id => 1},
:queue_start => 10
}
end
- its(:env) { should == env }
- its(:params) { should == {:id => 1} }
+ its(:env) { should eq env }
+ its(:params) { should eq({:id => 1}) }
end
end
# protected
describe "#background_queue_start" do
subject { transaction.send(:background_queue_start) }
context "when queue start is nil" do
- it { should == nil }
+ it { should eq nil }
end
context "when queue start is set" do
let(:env) { background_env_with_data }
- it { should == 1389783590000 }
+ it { should eq 1389783590000 }
end
end
describe "#http_queue_start" do
let(:slightly_earlier_time) { fixed_time - 0.4 }
@@ -593,22 +612,22 @@
end
context "with the HTTP_X_REQUEST_START header set" do
let(:env) { {'HTTP_X_REQUEST_START' => "t=#{slightly_earlier_time_value}"} }
- it { should == 1389783599600 }
+ it { should eq 1389783599600 }
context "with unparsable content" do
let(:env) { {'HTTP_X_REQUEST_START' => 'something'} }
it { should be_nil }
end
context "with some cruft" do
let(:env) { {'HTTP_X_REQUEST_START' => "t=#{slightly_earlier_time_value}aaaa"} }
- it { should == 1389783599600 }
+ it { should eq 1389783599600 }
end
context "with a really low number" do
let(:env) { {'HTTP_X_REQUEST_START' => "t=100"} }
@@ -616,11 +635,11 @@
end
context "with the alternate HTTP_X_QUEUE_START header set" do
let(:env) { {'HTTP_X_QUEUE_START' => "t=#{slightly_earlier_time_value}"} }
- it { should == 1389783599600 }
+ it { should eq 1389783599600 }
end
end
end
context "time in miliseconds" do
@@ -667,17 +686,17 @@
context "with an array" do
let(:request) do
Appsignal::Transaction::GenericRequest.new(background_env_with_data(:params => ['arg1', 'arg2']))
end
- it { should == ['arg1', 'arg2'] }
+ it { should eq ['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'] }
+ it { should eq ['arg1', 'arg2'] }
end
end
context "with env" do
context "with sanitization" do
@@ -686,11 +705,11 @@
http_request_env_with_data(:params => { :foo => :bar })
end
it "should call the params sanitizer" do
puts Appsignal.config.config_hash[:filter_parameters].inspect
- subject.should == { :foo => :bar }
+ subject.should eq({:foo => :bar })
end
end
context "with AppSignal filtering" do
let(:request) do
@@ -699,14 +718,14 @@
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 == {
+ subject.should eq({
:foo => '[FILTERED]',
:baz => :bat
- }
+ })
end
end
end
end
@@ -744,11 +763,11 @@
end
context "when env is empty" do
before { transaction.request.stub(:session => {}) }
- it { should == {} }
+ it { should eq({}) }
end
context "when request class does not have a session method" do
let(:request) { Appsignal::Transaction::GenericRequest.new({}) }
@@ -763,11 +782,11 @@
end
it "passes the session data into the params sanitizer" do
Appsignal::Utils::ParamsSanitizer.should_receive(:sanitize).with({:foo => :bar}).
and_return(:sanitized_foo)
- subject.should == :sanitized_foo
+ subject.should eq :sanitized_foo
end
if defined? ActionDispatch::Request::Session
context "with ActionDispatch::Request::Session" do
before do
@@ -815,11 +834,11 @@
end
context "when env is present" do
let(:env) { {:metadata => {:key => 'value'}} }
- it { should == env[:metadata] }
+ it { should eq env[:metadata] }
end
end
describe '#sanitized_tags' do
before do
@@ -850,10 +869,10 @@
end
describe "#cleaned_backtrace" do
subject { transaction.send(:cleaned_backtrace, ['line 1']) }
- it { should == ['line 1'] }
+ it { should eq ['line 1'] }
pending "calls Rails backtrace cleaner if Rails is present"
end
end