|
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 = 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.sort).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 | + |
| 79 | + describe 'given a block' do |
| 80 | + it 'creates a span' do |
| 81 | + account = Account.create! |
| 82 | + User.create!(account: account) |
| 83 | + |
| 84 | + record_ids = [] |
| 85 | + |
| 86 | + Account.find_by(id: account.id) do |record| |
| 87 | + record_ids << record.id |
| 88 | + end |
| 89 | + |
| 90 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 91 | + _(account_find_span).wont_be_nil |
| 92 | + _(account_find_span.attributes).must_be_empty |
| 93 | + _(record_ids).must_equal([account.id]) |
| 94 | + end |
| 95 | + end |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + describe 'find' do |
| 100 | + it 'creates a span' do |
| 101 | + account = Account.create! |
| 102 | + User.create!(account: account) |
| 103 | + |
| 104 | + Account.find(account.id) |
| 105 | + |
| 106 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 107 | + _(account_find_span).wont_be_nil |
| 108 | + _(account_find_span.attributes).must_be_empty |
| 109 | + end |
| 110 | + |
| 111 | + describe 'given a block' do |
| 112 | + it 'creates a span' do |
| 113 | + account = Account.create! |
| 114 | + User.create!(account: account) |
| 115 | + |
| 116 | + record_ids = [] |
| 117 | + |
| 118 | + Account.find(account.id) do |record| |
| 119 | + record_ids << record.id |
| 120 | + end |
| 121 | + |
| 122 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 123 | + _(account_find_span).wont_be_nil |
| 124 | + _(account_find_span.attributes).must_be_empty |
| 125 | + _(record_ids).must_equal([account.id]) |
| 126 | + end |
| 127 | + end |
| 128 | + end |
| 129 | + |
| 130 | + describe 'where' do |
| 131 | + it 'creates a span' do |
| 132 | + account = Account.create! |
| 133 | + User.create!(account: account) |
| 134 | + |
| 135 | + Account.where(id: [account.id]) |
| 136 | + |
| 137 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 138 | + _(account_find_span).wont_be_nil |
| 139 | + _(account_find_span.attributes).must_be_empty |
| 140 | + end |
| 141 | + |
| 142 | + describe 'given a block' do |
| 143 | + it 'creates a span' do |
| 144 | + account = Account.create! |
| 145 | + User.create!(account: account) |
| 146 | + |
| 147 | + record_ids = [] |
| 148 | + |
| 149 | + Account.where(id: [account.id]) do |record| |
| 150 | + record_ids << record.id |
| 151 | + end |
| 152 | + |
| 153 | + account_find_span = spans.find { |s| s.name == 'Account query' } |
| 154 | + _(account_find_span).wont_be_nil |
| 155 | + _(account_find_span.attributes).must_be_empty |
| 156 | + _(record_ids).must_equal([account.id]) |
| 157 | + end |
| 158 | + end |
31 | 159 | end |
32 | 160 | end |
0 commit comments