"Expected 'duplicate key' error in #{response_errors.first}")
end
+ [false, true].each do |ensure_unique_name|
+ test "create failure with duplicate name, ensure_unique_name #{ensure_unique_name}" do
+ authorize_with :active
+ post :create, params: {
+ collection: {
+ owner_uuid: users(:active).uuid,
+ manifest_text: "",
+ name: "this...............................................................................................................................................................................................................................................................name is too long"
+ },
+ ensure_unique_name: ensure_unique_name
+ }
+ assert_response 422
+ # check the real error isn't masked by an
+ # ensure_unique_name-related error (#19698)
+ assert_match /value too long for type/, json_response['errors'][0]
+ end
+ end
+
[false, true].each do |unsigned|
test "create with duplicate name, ensure_unique_name, unsigned=#{unsigned}" do
permit_unsigned_manifests unsigned
ensure_unique_name: true
}
assert_response :success
- assert_match /^owned_by_active \(\d{4}-\d\d-\d\d.*?Z\)$/, json_response['name']
+ assert_match /^owned_by_active \(#{json_response['uuid'][-15..-1]}\)$/, json_response['name']
end
end
test "get full provenance for baz file" do
authorize_with :active
- get :provenance, params: {id: 'ea10d51bcf88862dbcc36eb292017dfd+45'}
+ get :provenance, params: {id: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'}
assert_response :success
resp = JSON.parse(@response.body)
- assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
- assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
- assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
- assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
- assert_not_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
+ assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # baz collection
end
test "get no provenance for foo file" do
assert_response :success
resp = JSON.parse(@response.body)
assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
- assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
- assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
- assert_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
- assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
+ assert_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # foo->bar
end
test "search collections with 'any' operator" do
assert_nil json_response['trash_at']
end
+ test 'untrash a trashed collection by assigning nil to trash_at' do
+ authorize_with :active
+ post :update, params: {
+ id: collections(:expired_collection).uuid,
+ collection: {
+ trash_at: nil,
+ },
+ include_trash: true,
+ }
+ assert_response 200
+ assert_equal false, json_response['is_trashed']
+ assert_nil json_response['trash_at']
+ end
+
test 'untrash error on not trashed collection' do
authorize_with :active
post :untrash, params: {
assert_equal false, json_response['is_trashed']
assert_nil json_response['trash_at']
assert_nil json_response['delete_at']
- assert_match /^same name for trashed and persisted collections \(\d{4}-\d\d-\d\d.*?Z\)$/, json_response['name']
+ assert_match /^same name for trashed and persisted collections \(#{json_response['uuid'][-15..-1]}\)$/, json_response['name']
end
test 'cannot show collection in trashed subproject' do
end
end
end
+
+ test "select param is respected in 'show' response" do
+ authorize_with :active
+ get :show, params: {
+ id: collections(:collection_owned_by_active).uuid,
+ select: ["name"],
+ }
+ assert_response :success
+ assert_raises ActiveModel::MissingAttributeError do
+ assigns(:object).manifest_text
+ end
+ assert_nil json_response["manifest_text"]
+ assert_nil json_response["properties"]
+ assert_equal collections(:collection_owned_by_active).name, json_response["name"]
+ end
+
+ test "select param is respected in 'update' response" do
+ authorize_with :active
+ post :update, params: {
+ id: collections(:collection_owned_by_active).uuid,
+ collection: {
+ manifest_text: ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foobar.txt\n",
+ },
+ select: ["name"],
+ }
+ assert_response :success
+ assert_nil json_response["manifest_text"]
+ 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