You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: field_selection_test.rb
    path of file: ./repos/alba/test/usecases
    
    the code of the file until where you have to start completion: require_relative '../test_helper'

class FieldSelectionTest < Minitest::Test
  module FieldSelection
    def field_when_selected(*attrs, key:)
      attrs.each do |attr|
        attribute(attr, if: proc { params[:fields].nil? ? true : params[:fields][key].include?(attr.to_sym) }) do |object|
          object.__send__(attr)
        end
      end
    end
  end

  Bar = Struct.new(:id, :name)
  Foo = Struct.new(:id,
    
  def test_field_selection_with_params
    foo = Foo.new(1, 'foo', Bar.new(1, 'bar'))
    assert_equal(
      '{"id":1,"name":"foo","bar":{"id":1,"name":"bar"}}',
      FooResource.new(foo, params: {fields: {foo: [:id, :name], bar: [:id, :name]}}).serialize
    )
    assert_equal(
      '{"id":1,"name":"foo","bar":{"id":1}}',
      FooResource.new(foo, params: {fields: {foo: [:id, :name], bar: [:id]}}).serialize
    )
    assert_equal(
      '{"id":1,"name":"foo","bar":{"id":1,"name":"bar"}}',
      FooResource.new(foo).serialize
    )
  end