-
Notifications
You must be signed in to change notification settings - Fork 420
Proof of concept for ActiveSupport::Notifications
#61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
74bb873
631754c
823d0df
4312d02
bb7bc45
cb4bbba
df71ed0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'spec_helper' | ||
|
||
describe FastJsonapi::ObjectSerializer do | ||
include_context 'movie class' | ||
|
||
context 'instrument' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be more readable if the spec were named a little elaborately. It's important to test both cases.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course. These tests were mostly just to make sure that I was actually getting notifications. :p TDD FTW!!! |
||
it 'serializable_hash' do | ||
options = {} | ||
options[:meta] = { total: 2 } | ||
options[:include] = [:actors] | ||
|
||
serializer = MovieSerializer.new([movie, movie], options) | ||
allow(serializer).to receive(:instrumentation_enabled?).and_return(true) | ||
|
||
events = [] | ||
|
||
ActiveSupport::Notifications.subscribe(FastJsonapi::ObjectSerializer::SERIALIZE_HASH_NOTIFICATION) do |*args| | ||
events << ActiveSupport::Notifications::Event.new(*args) | ||
end | ||
|
||
serialized_hash = serializer.serializable_hash | ||
|
||
event = events.first | ||
|
||
expect(event.duration).to be > 0 | ||
expect(event.payload).to eq({ name: 'MovieSerializer' }) | ||
expect(event.name).to eq(FastJsonapi::ObjectSerializer::SERIALIZE_HASH_NOTIFICATION) | ||
|
||
expect(serialized_hash.key?(:data)).to eq(true) | ||
expect(serialized_hash.key?(:meta)).to eq(true) | ||
expect(serialized_hash.key?(:included)).to eq(true) | ||
end | ||
|
||
it 'to_json' do | ||
options = {} | ||
options[:meta] = { total: 2 } | ||
options[:include] = [:actors] | ||
|
||
serializer = MovieSerializer.new([movie, movie], options) | ||
allow(serializer).to receive(:instrumentation_enabled?).and_return(true) | ||
|
||
events = [] | ||
|
||
ActiveSupport::Notifications.subscribe(FastJsonapi::ObjectSerializer::TO_JSON_HASH_NOTIFICATION) do |*args| | ||
events << ActiveSupport::Notifications::Event.new(*args) | ||
end | ||
|
||
json = serializer.to_json | ||
|
||
event = events.first | ||
|
||
expect(event.duration).to be > 0 | ||
expect(event.payload).to eq({ name: 'MovieSerializer' }) | ||
expect(event.name).to eq(FastJsonapi::ObjectSerializer::TO_JSON_HASH_NOTIFICATION) | ||
|
||
expect(json.length).to be > 50 | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we dont have a method called
to_json
. I think the method we use is calledserialized_json
to get the JSON string representation.I like the simple and readable approach you have taken with
serializable_hash
can we do the same withserialized_json
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going off the original Skylight instrumenting, here, which did
serializable_hash
andto_json
. It would be easy enough to change.