|
14 | 14 | let(:spans) { exporter.finished_spans } |
15 | 15 |
|
16 | 16 | before { exporter.reset } |
| 17 | + after do |
| 18 | + ActiveRecord::Base.subclasses.each do |model| |
| 19 | + model.connection.truncate(model.table_name) |
| 20 | + end |
| 21 | + end |
17 | 22 |
|
18 | 23 | describe 'query' do |
19 | 24 | it 'traces' do |
|
28 | 33 | _(user_find_spans.length).must_equal(2) |
29 | 34 | _(account_find_span).wont_be_nil |
30 | 35 | end |
| 36 | + |
| 37 | + describe 'find_by_sql' do |
| 38 | + it 'creates a span' do |
| 39 | + Account.create! |
| 40 | + |
| 41 | + Account.find_by_sql('SELECT * FROM accounts') |
| 42 | + |
| 43 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 44 | + _(account_find_span).wont_be_nil |
| 45 | + _(account_find_span.attributes).must_be_empty |
| 46 | + end |
| 47 | + |
| 48 | + describe 'given a block' do |
| 49 | + it 'creates a span' do |
| 50 | + account = Account.create! |
| 51 | + |
| 52 | + record_ids = [] |
| 53 | + |
| 54 | + Account.find_by_sql('SELECT * FROM accounts') do |record| |
| 55 | + record_ids << record.id |
| 56 | + end |
| 57 | + |
| 58 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 59 | + _(account_find_span).wont_be_nil |
| 60 | + _(account_find_span.attributes).must_be_empty |
| 61 | + |
| 62 | + _(record_ids).must_equal([account.id]) |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + describe 'find_by' do |
| 68 | + it 'creates a span' do |
| 69 | + account = Account.create! |
| 70 | + User.create!(account: account) |
| 71 | + |
| 72 | + Account.find_by(id: account.id) |
| 73 | + |
| 74 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 75 | + _(account_find_span).wont_be_nil |
| 76 | + _(account_find_span.attributes).must_be_empty |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + describe 'find' do |
| 81 | + it 'creates a span' do |
| 82 | + account = Account.create! |
| 83 | + User.create!(account: account) |
| 84 | + |
| 85 | + Account.find(account.id) |
| 86 | + |
| 87 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 88 | + _(account_find_span).wont_be_nil |
| 89 | + _(account_find_span.attributes).must_be_empty |
| 90 | + end |
| 91 | + |
| 92 | + describe 'given a block' do |
| 93 | + it 'creates a span' do |
| 94 | + account = Account.create! |
| 95 | + User.create!(account: account) |
| 96 | + |
| 97 | + record_ids = [] |
| 98 | + |
| 99 | + Account.find(account.id) do |record| |
| 100 | + record_ids << record.id |
| 101 | + end |
| 102 | + |
| 103 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 104 | + _(account_find_span).wont_be_nil |
| 105 | + _(account_find_span.attributes).must_be_empty |
| 106 | + _(record_ids).must_equal([account.id]) |
| 107 | + end |
| 108 | + end |
| 109 | + end |
31 | 110 | end |
32 | 111 | end |
0 commit comments