summaryrefslogtreecommitdiff
path: root/spec/migrations/create_missing_namespace_for_internal_users_spec.rb
blob: ac3a4b1f68fc834cdab0ec7b4c0f35b0897043d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20180413022611_create_missing_namespace_for_internal_users.rb')

describe CreateMissingNamespaceForInternalUsers, :migration do
  let(:users) { table(:users) }
  let(:namespaces) { table(:namespaces) }
  let(:routes) { table(:routes) }

  internal_user_types = [:ghost]
  internal_user_types << :support_bot if ActiveRecord::Base.connection.column_exists?(:users, :support_bot)

  internal_user_types.each do |attr|
    context "for #{attr} user" do
      let(:internal_user) do
        users.create!(email: 'test@example.com', projects_limit: 100, username: 'test', attr => true)
      end

      it 'creates the missing namespace' do
        expect(namespaces.find_by(owner_id: internal_user.id)).to be_nil

        migrate!

        namespace = Namespace.find_by(type: nil, owner_id: internal_user.id)
        route = namespace.route

        expect(namespace.path).to eq(route.path)
        expect(namespace.name).to eq(route.name)
      end

      it 'sets notification email' do
        users.update(internal_user.id, notification_email: nil)

        expect(users.find(internal_user.id).notification_email).to be_nil

        migrate!

        user = users.find(internal_user.id)
        expect(user.notification_email).to eq(user.email)
      end
    end
  end
end