spec/lib/appsignal/transaction_spec.rb in appsignal-0.10.6 vs spec/lib/appsignal/transaction_spec.rb in appsignal-0.11.0.beta.1
- old
+ new
@@ -228,10 +228,20 @@
it { should be_true }
end
end
+ describe "clear_events!" do
+ let(:transaction) { slow_transaction }
+
+ it "should remove events from the transaction" do
+ expect {
+ transaction.clear_events!
+ }.to change(transaction.events, :length).from(1).to(0)
+ end
+ end
+
describe "#truncate!" do
subject { slow_transaction }
before { subject.set_tags('a' => 'b') }
it "should clear the process action payload and events" do
@@ -242,31 +252,31 @@
subject.tags.should be_empty
subject.truncated?.should be_true
end
it "should not truncate twice" do
- subject.process_action_event.payload.should_receive(:clear).once
+ subject.process_action_event.should_receive(:truncate!).once
subject.events.should_receive(:clear).once
subject.truncate!
subject.truncate!
end
end
describe "#convert_values_to_primitives!" do
let(:transaction) { slow_transaction }
- let(:action_event_payload) { transaction.process_action_event.payload }
- let(:event_payload) { transaction.events.first.payload }
+ let(:action_event) { transaction.process_action_event }
+ let(:event) { transaction.events.first }
let(:weird_class) { Class.new }
let(:smash) { Smash.new.merge!(:foo => 'bar') }
context "with values that need to be converted" do
context "process action event payload" do
- subject { action_event_payload }
+ subject { action_event.payload }
before do
- action_event_payload.clear
- action_event_payload.merge!(
+ action_event.payload.clear
+ action_event.payload.merge!(
:model => {:with => [:weird, weird_class]},
)
transaction.convert_values_to_primitives!
end
@@ -276,14 +286,14 @@
}
end
end
context "payload of events" do
- subject { event_payload }
+ subject { event.payload }
before do
- event_payload.clear
- event_payload.merge!(
+ event.payload.clear
+ event.payload.merge!(
:weird => weird_class,
:smash => smash
)
transaction.convert_values_to_primitives!
end
@@ -296,26 +306,26 @@
context "without values that need to be converted" do
subject { transaction.convert_values_to_primitives! }
it "doesn't change the action event payload" do
- before = action_event_payload.dup
+ before = action_event.payload.dup
subject
- action_event_payload.should == before
+ action_event.payload.should == before
end
it " doesn't change the event payloads" do
- before = event_payload.dup
+ before = event.payload.dup
subject
- event_payload.should == before
+ event.payload.should == before
end
it "should not covert to primitives twice" do
transaction.convert_values_to_primitives!
transaction.have_values_been_converted_to_primitives?.should be_true
- Appsignal::Transaction::ParamsSanitizer.should_not_receive(:sanitize!)
+ Appsignal::ParamsSanitizer.should_not_receive(:sanitize!)
transaction.convert_values_to_primitives!
end
end
end
@@ -346,11 +356,11 @@
end
describe '#complete!' do
let(:event) { double(:event) }
before do
- Appsignal::Pipe.stub(:current => nil)
+ Appsignal::IPC.stub(:current => nil)
transaction.set_process_action_event(notification_event)
end
it 'should remove transaction from the list' do
expect { transaction.complete! }.
@@ -385,24 +395,22 @@
end
after { transaction.complete! }
end
- context 'when using pipes' do
- let(:pipe) { double }
+ context 'when using IPC' do
before do
- Appsignal::Pipe.stub(:current => pipe)
- pipe.stub(:write => true)
+ Appsignal::IPC::Client.start
transaction.stub(:convert_values_to_primitives! => true)
end
-
- it "should send itself trough the pipe" do
- pipe.should_receive(:write).with(transaction)
+ after do
+ Appsignal::IPC::Client.stop
end
- it "should convert itself to primitives" do
+ it "should convert to primitves and send itself trough the pipe" do
transaction.should_receive(:convert_values_to_primitives!)
+ Appsignal::IPC::Client.should_receive(:enqueue).with(transaction)
end
after { transaction.complete! }
end
end
@@ -563,11 +571,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::Transaction::ParamsSanitizer.should_receive(:sanitize).with({:foo => :bar}).
+ Appsignal::ParamsSanitizer.should_receive(:sanitize).with({:foo => :bar}).
and_return(:sanitized_foo)
subject
transaction.sanitized_session_data.should == :sanitized_foo
end
@@ -582,10 +590,10 @@
transaction.stub_chain(:request, :session => action_dispatch_session)
transaction.stub_chain(:request, :fullpath => :bar)
end
it "should return an session hash" do
- Appsignal::Transaction::ParamsSanitizer.should_receive(:sanitize).with({'foo' => :bar}).
+ Appsignal::ParamsSanitizer.should_receive(:sanitize).with({'foo' => :bar}).
and_return(:sanitized_foo)
subject
end
def action_dispatch_session