|
| 1 | +require 'spec_helper' |
| 2 | +require 'fast_jsonapi/instrumentation' |
| 3 | + |
| 4 | +describe FastJsonapi::ObjectSerializer do |
| 5 | + include_context 'movie class' |
| 6 | + |
| 7 | + context 'instrument' do |
| 8 | + |
| 9 | + before(:each) do |
| 10 | + options = {} |
| 11 | + options[:meta] = { total: 2 } |
| 12 | + options[:include] = [:actors] |
| 13 | + |
| 14 | + @serializer = MovieSerializer.new([movie, movie], options) |
| 15 | + end |
| 16 | + |
| 17 | + context 'serializable_hash' do |
| 18 | + |
| 19 | + it 'should send notifications' do |
| 20 | + events = [] |
| 21 | + |
| 22 | + ActiveSupport::Notifications.subscribe(FastJsonapi::ObjectSerializer::SERIALIZABLE_HASH_NOTIFICATION) do |*args| |
| 23 | + events << ActiveSupport::Notifications::Event.new(*args) |
| 24 | + end |
| 25 | + |
| 26 | + serialized_hash = @serializer.serializable_hash |
| 27 | + |
| 28 | + expect(events.length).to eq(1) |
| 29 | + |
| 30 | + event = events.first |
| 31 | + |
| 32 | + expect(event.duration).to be > 0 |
| 33 | + expect(event.payload).to eq({ name: 'MovieSerializer' }) |
| 34 | + expect(event.name).to eq(FastJsonapi::ObjectSerializer::SERIALIZABLE_HASH_NOTIFICATION) |
| 35 | + |
| 36 | + expect(serialized_hash.key?(:data)).to eq(true) |
| 37 | + expect(serialized_hash.key?(:meta)).to eq(true) |
| 38 | + expect(serialized_hash.key?(:included)).to eq(true) |
| 39 | + end |
| 40 | + |
| 41 | + end |
| 42 | + |
| 43 | + context 'serialized_json' do |
| 44 | + |
| 45 | + it 'should send notifications' do |
| 46 | + events = [] |
| 47 | + |
| 48 | + ActiveSupport::Notifications.subscribe(FastJsonapi::ObjectSerializer::SERIALIZED_JSON_NOTIFICATION) do |*args| |
| 49 | + events << ActiveSupport::Notifications::Event.new(*args) |
| 50 | + end |
| 51 | + |
| 52 | + json = @serializer.serialized_json |
| 53 | + |
| 54 | + expect(events.length).to eq(1) |
| 55 | + |
| 56 | + event = events.first |
| 57 | + |
| 58 | + expect(event.duration).to be > 0 |
| 59 | + expect(event.payload).to eq({ name: 'MovieSerializer' }) |
| 60 | + expect(event.name).to eq(FastJsonapi::ObjectSerializer::SERIALIZED_JSON_NOTIFICATION) |
| 61 | + |
| 62 | + expect(json.length).to be > 50 |
| 63 | + end |
| 64 | + |
| 65 | + end |
| 66 | + |
| 67 | + end |
| 68 | + |
| 69 | +end |
0 commit comments