# it will select the Collection object with the longest
# available lifetime.
+ select_attrs = (@select || ["manifest_text"]) | ["portable_data_hash", "trash_at"]
if c = Collection.
readable_by(*@read_users, opts).
where({ portable_data_hash: loc.to_s }).
order("trash_at desc").
- select(((@select || ["manifest_text"]) | ["portable_data_hash", "trash_at"]).join(", ")).
+ select(select_attrs.join(", ")).
limit(1).
first
@object = {
uuid: c.portable_data_hash,
portable_data_hash: c.portable_data_hash,
- manifest_text: c.manifest_text,
+ trash_at: c.trash_at,
}
+ if select_attrs.index("manifest_text")
+ @object[:manifest_text] = c.manifest_text
+ end
end
else
super
assert_nil json_response["properties"]
assert_equal collections(:collection_owned_by_active).name, json_response["name"]
end
+
+ [nil,
+ [],
+ ["is_trashed", "trash_at"],
+ ["is_trashed", "trash_at", "portable_data_hash"],
+ ["portable_data_hash"],
+ ["portable_data_hash", "manifest_text"],
+ ].each do |select|
+ test "select=#{select.inspect} param is respected in 'get by pdh' response" do
+ authorize_with :active
+ get :show, params: {
+ id: collections(:collection_owned_by_active).portable_data_hash,
+ select: select,
+ }
+ assert_response :success
+ if !select || select.index("manifest_text")
+ assert_not_nil json_response["manifest_text"]
+ else
+ assert_nil json_response["manifest_text"]
+ end
+ end
+ end
end