Skip to content

change from present? (Rails) to native Ruby check #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/weaviate/objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create(
req.body = {}
req.body["class"] = class_name
req.body["properties"] = properties
req.body["tenant"] = tenant unless tenant.blank?
req.body["tenant"] = tenant unless tenant.nil?
req.body["id"] = id unless id.nil?
req.body["vector"] = vector unless vector.nil?
end
Expand Down
6 changes: 4 additions & 2 deletions lib/weaviate/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def create(
description: nil,
properties: nil,
multi_tenant: nil,
auto_tenant_creation: nil,
vector_index_type: nil,
vector_index_config: nil,
vectorizer: nil,
Expand All @@ -45,8 +46,9 @@ def create(
req.body["properties"] = properties unless properties.nil?
if multi_tenant.is_a?(Hash)
req.body["multiTenancyConfig"] = multi_tenant
elsif multi_tenant.present?
req.body["multiTenancyConfig"] = {enabled: true}
elsif !multi_tenant.nil?
req.body["multiTenancyConfig"] = { enabled: true }
req.body["multiTenancyConfig"].merge!(autoTenantCreation: true) unless auto_tenant_creation.nil?
end
req.body["invertedIndexConfig"] = inverted_index_config unless inverted_index_config.nil?
req.body["replicationConfig"] = replication_config unless replication_config.nil?
Expand Down
24 changes: 24 additions & 0 deletions spec/weaviate/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@
)
expect(response.dig("class")).to eq("Question")
end

context "when auto_tenant_creation passed" do
before do
@captured_request = nil
allow_any_instance_of(Faraday::Connection).to receive(:post) do |_, path, &block|
expect(path).to eq("schema")
req = OpenStruct.new(body: {})
block.call(req)
@captured_request = req
response
end
end
Comment on lines +81 to +90
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VCR or WebMock would simplify this a ton, but this is essentially grabbing the req object yielded to Faraday so we can check that multiTenancyConfig is set up correctly.


it "sets up multiTenancyConfig with autoTenantCreation enabled" do
schema.create(
class_name: "Question",
description: "Information from a Jeopardy! question",
multi_tenant: true,
auto_tenant_creation: true
)

expect(@captured_request.body["multiTenancyConfig"]).to eq({ enabled: true, autoTenantCreation: true })
end
end
end

describe "#delete" do
Expand Down