blob: 411b1eacb8634da2e5e7b89ee995d0303369702c (
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe CreateSyncNamespaceDetailsTrigger do
let(:migration) { described_class.new }
let(:namespaces) { table(:namespaces) }
let(:namespace_details) { table(:namespace_details) }
let!(:timestamp) { Time.new(2020, 01, 01).utc }
let(:synced_attributes) do
{
description: 'description',
description_html: '<p>description</p>',
cached_markdown_version: 1966080,
created_at: timestamp,
updated_at: timestamp
}
end
let(:other_attributes) do
{
name: 'name',
path: 'path'
}
end
let(:attributes) { other_attributes.merge(synced_attributes) }
describe '#up' do
before do
migrate!
end
describe 'INSERT trigger' do
it 'creates a namespace_detail record' do
expect do
namespaces.create!(attributes)
end.to change(namespace_details, :count).by(1)
end
it 'the created namespace_details record has matching attributes' do
namespaces.create!(attributes)
synced_namespace_details = namespace_details.last
expect(synced_namespace_details).to have_attributes(synced_attributes)
end
end
describe 'UPDATE trigger' do
let!(:namespace) { namespaces.create!(attributes) }
it 'updates the attribute in the synced namespace_details record' do
namespace.update!(description: 'new_description')
synced_namespace_details = namespace_details.last
expect(synced_namespace_details.description).to eq('new_description')
end
end
end
describe '#down' do
before do
migration.up
migration.down
end
it 'drops the trigger' do
expect do
namespaces.create!(attributes)
end.not_to change(namespace_details, :count)
end
end
end
|