spec/lib/appsignal/transaction_spec.rb in appsignal-0.8.15 vs spec/lib/appsignal/transaction_spec.rb in appsignal-0.9.0.alpha.1

- old
+ new

@@ -4,18 +4,20 @@ before :all do start_agent end describe '.create' do - before { Appsignal::Transaction.create('1', {}) } + subject { Appsignal::Transaction.create('1', {}) } - it 'should add the id to the thread' do + it 'should add the request id to the thread local' do + subject Thread.current[:appsignal_transaction_id].should == '1' end - it 'should add the transaction to the list' do - Appsignal.transactions['1'].should be_a Appsignal::Transaction + it "should create a transaction" do + subject.should be_a Appsignal::Transaction + subject.request_id.should == '1' end end describe '.current' do let(:transaction) { Appsignal::Transaction.create('1', {}) } @@ -25,21 +27,48 @@ it 'should return the correct transaction' do should eq transaction end end + describe "complete_current!" do + before { Thread.current[:appsignal_transaction_id] = nil } + + context "with a current transaction" do + before { Appsignal::Transaction.create('2', {}) } + + it "should complete the current transaction and reset the thread appsignal_transaction_id" do + Appsignal::Transaction.current.should_receive(:complete!) + + Appsignal::Transaction.complete_current! + + Thread.current[:appsignal_transaction_id].should be_nil + end + end + + context "without a current transaction" do + it "should not raise an error" do + Appsignal::Transaction.complete_current! + end + end + end + context "with transaction instance" do let(:env) do { 'HTTP_USER_AGENT' => 'IE6', 'SERVER_NAME' => 'localhost', 'action_dispatch.routes' => 'not_available', 'HTTP_X_REQUEST_START' => '1000000' } end - let(:transaction) { Appsignal::Transaction.create('1', env) } + let(:transaction) { Appsignal::Transaction.create('3', env) } + it "should add the transaction to the list" do + transaction + Appsignal.transactions['3'].should == transaction + end + describe '#request' do subject { transaction.request } it { should be_a ::Rack::Request } end @@ -320,17 +349,9 @@ Appsignal.should_receive(:enqueue).with(transaction) end end after { transaction.complete! } - end - - context 'thread' do - before { transaction.complete! } - - it 'should reset the thread transaction id' do - Thread.current[:appsignal_transaction_id].should be_nil - end end context 'when using pipes' do let(:pipe) { double } before { Appsignal::Pipe.stub(:current => pipe) }