blob: 1205b74dc9d5a8714fea20235c456df2303bd941 (
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Integrations::StiType do
let(:types) { ['AsanaService', 'Integrations::Asana', Integrations::Asana] }
describe '#serialize' do
context 'SQL SELECT' do
let(:expected_sql) do
<<~SQL.strip
SELECT "integrations".* FROM "integrations" WHERE "integrations"."type" = 'AsanaService'
SQL
end
it 'forms SQL SELECT statements correctly' do
sql_statements = types.map do |type|
Integration.where(type: type).to_sql
end
expect(sql_statements).to all(eq(expected_sql))
end
end
context 'SQL CREATE' do
let(:expected_sql) do
<<~SQL.strip
INSERT INTO "integrations" ("type") VALUES ('AsanaService')
SQL
end
it 'forms SQL CREATE statements correctly' do
sql_statements = types.map do |type|
record = ActiveRecord::QueryRecorder.new { Integration.insert({ type: type }) }
record.log.first
end
expect(sql_statements).to all(include(expected_sql))
end
end
context 'SQL UPDATE' do
let(:expected_sql) do
<<~SQL.strip
UPDATE "integrations" SET "type" = 'AsanaService'
SQL
end
let_it_be(:integration) { create(:integration) }
it 'forms SQL UPDATE statements correctly' do
sql_statements = types.map do |type|
record = ActiveRecord::QueryRecorder.new { integration.update_column(:type, type) }
record.log.first
end
expect(sql_statements).to all(include(expected_sql))
end
end
context 'SQL DELETE' do
let(:expected_sql) do
<<~SQL.strip
DELETE FROM "integrations" WHERE "integrations"."type" = 'AsanaService'
SQL
end
it 'forms SQL DELETE statements correctly' do
sql_statements = types.map do |type|
record = ActiveRecord::QueryRecorder.new { Integration.delete_by(type: type) }
record.log.first
end
expect(sql_statements).to all(match(expected_sql))
end
end
end
describe '#deserialize' do
specify 'it deserializes type correctly', :aggregate_failures do
types.each do |type|
service = create(:integration, type: type)
expect(service.type).to eq('AsanaService')
end
end
end
describe '#cast' do
it 'casts type as model correctly', :aggregate_failures do
create(:integration, type: 'AsanaService')
types.each do |type|
expect(Integration.find_by(type: type)).to be_kind_of(Integrations::Asana)
end
end
end
describe '#changed?' do
it 'detects changes correctly', :aggregate_failures do
service = create(:integration, type: 'AsanaService')
types.each do |type|
service.type = type
expect(service).not_to be_changed
end
service.type = 'NewType'
expect(service).to be_changed
end
end
end
|