Commit 9388bb91 authored by jejacks0n's avatar jejacks0n

Don’t create new records on nested attributes

- When passing nested attributes for the gitlab_subscription record, we
shouldn’t create new records and instead update the existing (singleton)
record.
parent df2052b5
...@@ -31,7 +31,7 @@ module EE ...@@ -31,7 +31,7 @@ module EE
has_one :gitlab_subscription has_one :gitlab_subscription
has_one :elasticsearch_indexed_namespace has_one :elasticsearch_indexed_namespace
accepts_nested_attributes_for :gitlab_subscription accepts_nested_attributes_for :gitlab_subscription, update_only: true
accepts_nested_attributes_for :namespace_limit accepts_nested_attributes_for :namespace_limit
scope :include_gitlab_subscription, -> { includes(:gitlab_subscription) } scope :include_gitlab_subscription, -> { includes(:gitlab_subscription) }
......
---
title: Don’t create new gitlab_subscription records on nested attributes to namespaces
merge_request: 40537
author:
type: fixed
...@@ -246,13 +246,14 @@ RSpec.describe API::Namespaces do ...@@ -246,13 +246,14 @@ RSpec.describe API::Namespaces do
end end
it "updates the gitlab_subscription record" do it "updates the gitlab_subscription record" do
group1.create_gitlab_subscription! existing_subscription = group1.create_gitlab_subscription!
put api("/namespaces/#{group1.id}", admin), params: { put api("/namespaces/#{group1.id}", admin), params: {
gitlab_subscription_attributes: gitlab_subscription gitlab_subscription_attributes: gitlab_subscription
} }
expect(group1.reload.gitlab_subscription.reload.seats).to eq 20 expect(group1.reload.gitlab_subscription.reload.seats).to eq 20
expect(group1.gitlab_subscription).to eq existing_subscription
end end
context 'when params are invalid' do context 'when params are invalid' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment