diaspora/spec/serializers/serializer_post_processing_spec.rb
cmrd Senya 7374661e2f
Update the user data export archive format.
This commit introduces changes to the user data export archive format.
This extends data set which is included in the archive. This data can be
then imported to other pods when this feature is implemented.

Also the commit adds the archive format json schema. ATM it is used in
automatic tests only, but in future it will also be used to validate
incoming archives.
2017-08-10 09:36:26 +03:00

33 lines
998 B
Ruby

describe SerializerPostProcessing do
describe "#modify_serializable_object" do
it "allows to modify serializable object of ActiveModel::Serializer ancestor" do
class TestSerializer < ActiveModel::Serializer
include SerializerPostProcessing
def modify_serializable_object(*)
{
custom_key: "custom_value"
}
end
end
serializer = TestSerializer.new({}, root: false)
expect(serializer).to receive(:modify_serializable_object).and_call_original
expect(serializer.to_json).to eq("{\"custom_key\":\"custom_value\"}")
end
end
describe "#except" do
it "allows to except a key from attributes" do
class TestSerializer2 < ActiveModel::Serializer
include SerializerPostProcessing
attributes :key_to_exclude
end
serializer = TestSerializer2.new({}, root: false)
serializer.except = [:key_to_exclude]
expect(serializer.to_json).to eq("{}")
end
end
end