Skip to content
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

Fix marshal load of array for drafted/deleted child entries #207

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/contentful/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def marshal_load(raw_object)
ResourceBuilder.new(
item.raw,
raw_object[:configuration].merge(includes_for_single: Support.includes_from_response(raw, false)),
item.respond_to?(:localized) ? item.localized : false
item.respond_to?(:localized) ? item.localized : false,
0,
raw_object[:configuration][:errors] || []
).run
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,31 @@ class CustomClass < Contentful::Entry; end
expect(dehydrated.first.inspect).to eq "<CustomClass[parent] id='5aV3O0l5jU0cwQ2OkyYsyU'>"
}
end

it 'filters out unpublished resources after rehydration' do
vcr('array/marshal_unpublished') {
parent = create_client(
space: 'z3eix6mwjid2',
access_token: '9047c4394a2130dff8e9dc544a7a3ec299703fdac8e52575eb5a6678be06c468',
dynamic_entries: :auto
).entries('sys.id': '5Etc0jWzIWwMeSu4W0SCi8')

rehydrated = Marshal.load(Marshal.dump(parent))

expect(rehydrated.first.children).to be_empty

preview_parent = create_client(
space: 'z3eix6mwjid2',
access_token: '38153b942011a70b5482fda61c6a3a9d22f5e8a512662dac00fcf7eb344b75f4',
dynamic_entries: :auto,
api_url: 'preview.contentful.com'
).entries('sys.id': '5Etc0jWzIWwMeSu4W0SCi8')

preview_rehydrated = Marshal.load(Marshal.dump(preview_parent))

expect(preview_rehydrated.first.children).not_to be_empty
expect(preview_rehydrated.first.children.first.title).to eq 'Child'
}
end
end
end
315 changes: 315 additions & 0 deletions spec/fixtures/vcr_cassettes/array/marshal_unpublished.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.