Commit e7c94bf0 authored by Thong Kuah's avatar Thong Kuah

Remove workaround to build namespace owner inline

This prevents having to modify the owner after it has been frozen from a
create_default
parent 3fecaf59
...@@ -5,22 +5,7 @@ FactoryBot.define do ...@@ -5,22 +5,7 @@ FactoryBot.define do
sequence(:name) { |n| "namespace#{n}" } sequence(:name) { |n| "namespace#{n}" }
path { name.downcase.gsub(/\s/, '_') } path { name.downcase.gsub(/\s/, '_') }
# This is a workaround to avoid the user creating another namespace via owner { association(:user, strategy: :build, namespace: instance, username: path) }
# User#ensure_namespace_correct. We should try to remove it and then
# we could remove this workaround
association :owner, factory: :user, strategy: :build
before(:create) do |namespace|
owner = namespace.owner
if owner
# We're changing the username here because we want to keep our path,
# and User#ensure_namespace_correct would change the path based on
# username, so we're forced to do this otherwise we'll need to change
# a lot of existing tests.
owner.username = namespace.path
owner.namespace = namespace
end
end
trait :with_aggregation_schedule do trait :with_aggregation_schedule do
after(:create) do |namespace| after(:create) do |namespace|
......
...@@ -141,7 +141,7 @@ RSpec.describe Namespace do ...@@ -141,7 +141,7 @@ RSpec.describe Namespace do
end end
it 'allows updating other attributes for existing record' do it 'allows updating other attributes for existing record' do
namespace = build(:namespace, path: 'j') namespace = build(:namespace, path: 'j', owner: create(:user))
namespace.save(validate: false) namespace.save(validate: false)
namespace.reload namespace.reload
......
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