Files
ubicloud/spec/routes/api/spec_helper.rb
Jeremy Evans 1227c7e377 Set project_id columns when creating objects for 6 models
For the following 6 models:

* ApiKey
* Firewall
* LoadBalancer
* MinioCluster
* PrivateSubnet
* Vm

Set the project_id when creating the object.  Continue to use
associate_with_project to update access_tag, and have
associate_with_project check that project_id is already set
correctly.  This is a temporary state until all project_id
columns have been correctly populated.

Unfortunately, this causes a large amount of fallout in the tests.
This adds the necessary project_id keyword arguments, so that a
future commit can just drop most of the associate_with_project
calls.
2025-01-14 11:56:06 -08:00

41 lines
1.3 KiB
Ruby

# frozen_string_literal: true
require_relative "../spec_helper"
RSpec.configure do |config|
def login_api(email = TEST_USER_EMAIL, password = TEST_USER_PASSWORD, use_pat: true)
if use_pat
account = Account[email: email]
@pat = account.api_keys.first || ApiKey.create_personal_access_token(account)
header "Authorization", "Bearer pat-#{@pat.ubid}-#{@pat.key}"
else
post "/login", JSON.generate(login: email, password: password), {"CONTENT_TYPE" => "application/json"}
expect(last_response.status).to eq(200)
header "Authorization", "Bearer #{last_response.headers["authorization"]}"
end
end
def project_with_default_policy(account, name: "project-1")
project = account.create_project_with_default_policy(name)
if @pat
SubjectTag.first(project_id: project.id, name: "Admin").add_subject(@pat.id)
@pat.update(project_id: project.id)
@pat.associate_with_project(project)
end
project
end
config.define_derived_metadata(file_path: %r{\A\./spec/routes/api/}) do |metadata|
metadata[:clover_api] = true
end
config.before do |example|
next unless example.metadata[:clover_api]
header "Host", "api.ubicloud.com"
header "Content-Type", "application/json"
header "Accept", "application/json"
end
end