+
+ [['<', :<],
+ ['<=', :<=],
+ ['>', :>],
+ ['>=', :>=],
+ ['=', :==]].each do |op, rubyop|
+ test "filter collections by replication_desired #{op} replication_confirmed" do
+ authorize_with(:active)
+ get :index, params: {
+ filters: [["(replication_desired #{op} replication_confirmed)", "=", true]],
+ }
+ assert_response :success
+ json_response["items"].each do |c|
+ assert_operator(c["replication_desired"], rubyop, c["replication_confirmed"])
+ end
+ end
+ end
+
+ ["(replication_desired < bogus)",
+ "replication_desired < replication_confirmed",
+ "(replication_desired < replication_confirmed",
+ "(replication_desired ! replication_confirmed)",
+ "(replication_desired <)",
+ "(replication_desired < manifest_text)",
+ "(manifest_text < manifest_text)", # currently only numeric attrs are supported
+ "(replication_desired < 2)", # currently only attrs are supported, not literals
+ "(1 < 2)",
+ ].each do |expr|
+ test "invalid filter expression #{expr}" do
+ authorize_with(:active)
+ get :index, params: {
+ filters: [[expr, "=", true]],
+ }
+ assert_response 422
+ end
+ end
+
+ test "invalid op/arg with filter expression" do
+ authorize_with(:active)
+ get :index, params: {
+ filters: [["replication_desired < replication_confirmed", "!=", false]],
+ }
+ assert_response 422
+ end
+
+ ["storage_classes_desired", "storage_classes_confirmed"].each do |attr|
+ test "filter collections by #{attr}" do
+ authorize_with(:active)
+ get :index, params: {
+ filters: [[attr, "=", '["default"]']]
+ }
+ assert_response :success
+ assert_not_equal 0, json_response["items"].length
+ json_response["items"].each do |c|
+ assert_equal ["default"], c[attr]
+ 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