Files
ubicloud/spec/model/api_key_spec.rb
Jeremy Evans 4b819d3cb2 Change all create_with_id to create
It hasn't been necessary to use create_with_id since
ebc79622df, in December 2024.

I have plans to introduce:

```ruby
def create_with_id(id, values)
  obj = new(values)
  obj.id = id
  obj.save_changes
end
```

This will make it easier to use the same id when creating
multiple objects.  The first step is removing the existing
uses of create_with_id.
2025-08-06 01:55:51 +09:00

23 lines
758 B
Ruby

# frozen_string_literal: true
require_relative "spec_helper"
RSpec.describe ApiKey do
let(:prj) {
Project.create(name: "test-project")
}
it "can be created and rotated" do
expect(prj.api_keys.count).to eq 0
api_key = described_class.create(owner_table: "project", owner_id: prj.id, used_for: "inference_endpoint", project_id: prj.id)
expect(prj.reload.api_keys.count).to eq 1
key = api_key.key
api_key.rotate
expect(api_key.key).not_to eq key
end
it "can be created and rotated2" do
expect { described_class.create(owner_table: "invalid-owner", owner_id: "2d1784a8-f70d-48e7-92b1-3f428381d62f", used_for: "inference_endpoint", project_id: prj.id) }.to raise_error("Invalid owner_table: invalid-owner")
end
end