require 'rails_helper'

describe User do

  subject { create(:user) }

  it { should validate_uniqueness_of(:email) }
  it { should validate_uniqueness_of(:username) }

  describe '#create_personal_namespace!' do

    it 'creates a team and a namespace with the name of username' do
      subject.create_personal_namespace!
      team = Team.find_by!(name: subject.username)
      Namespace.find_by!(name: subject.username)
      TeamUser.find_by!(user: subject, team: team)
    end

  end

end

require 'rails_helper'

describe User do

  subject { create(:user) }

  it { should validate_uniqueness_of(:email) }
  it { should validate_uniqueness_of(:username) }

  describe '#create_personal_namespace!' do

    it 'creates a team and a namespace with the name of username' do
      subject.create_personal_namespace!
      team = Team.find_by!(name: subject.username)
      Namespace.find_by!(name: subject.username)
      tu = TeamUser.find_by!(user: subject, team: team)
      assert tu.owner
    end

  end

end

Make sure that the user owns the team created by create_personal_namespace
Make sure that the user owns the team created by create_personal_namespace

Signed-off-by: Miquel Sabaté <59dd01d5f2d887d8f62723e70d14bf48e0ed35a3@gmail.com>
