-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_function_definition_spec.rb
More file actions
116 lines (96 loc) · 4.73 KB
/
Copy pathruntime_function_definition_spec.rb
File metadata and controls
116 lines (96 loc) · 4.73 KB
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
115
116
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe RuntimeFunctionDefinition do
subject(:function) { create(:runtime_function_definition) }
describe 'validations' do
it { is_expected.to have_many(:parameters).inverse_of(:runtime_function_definition) }
it { is_expected.to validate_presence_of(:runtime_name) }
it { is_expected.to validate_uniqueness_of(:runtime_name).case_insensitive.scoped_to(:runtime_id) }
it { is_expected.to validate_length_of(:runtime_name).is_at_most(50) }
it { is_expected.to validate_presence_of(:signature) }
it { is_expected.to validate_length_of(:signature).is_at_most(500) }
it { is_expected.to validate_length_of(:definition_source).is_at_most(50) }
it { is_expected.to validate_length_of(:display_icon).is_at_most(100) }
it { is_expected.to validate_length_of(:design).is_at_most(200) }
describe '#validate_version' do
it 'adds an error if version is blank' do
function.version = ''
function.validate_version
expect(function.errors.added?(:version, :blank)).to be(true)
end
it 'adds an error if version is invalid' do
function.version = 'invalid_version'
function.validate_version
expect(function.errors.added?(:version, :invalid)).to be(true)
end
it 'does not add an error if version is valid' do
function.version = '1.0.0'
function.validate_version
expect(function.errors[:version]).to be_empty
end
end
end
describe 'associations' do
it { is_expected.to belong_to(:runtime) }
it { is_expected.to belong_to(:runtime_module).inverse_of(:runtime_function_definitions) }
it do
is_expected.to have_many(:parameters)
.class_name('RuntimeParameterDefinition')
.inverse_of(:runtime_function_definition)
end
it do
is_expected.to have_many(:runtime_function_definition_data_type_links).inverse_of(:runtime_function_definition)
end
it do
is_expected.to have_many(:referenced_data_types)
.through(:runtime_function_definition_data_type_links)
.source(:referenced_data_type)
end
it { is_expected.to have_many(:names).class_name('Translation').inverse_of(:owner) }
it { is_expected.to have_many(:descriptions).class_name('Translation').inverse_of(:owner) }
it { is_expected.to have_many(:documentations).class_name('Translation').inverse_of(:owner) }
it { is_expected.to have_many(:deprecation_messages).class_name('Translation').inverse_of(:owner) }
end
describe '#to_grpc' do
let!(:param) { create(:runtime_parameter_definition, runtime_function_definition: function) }
let!(:name) { create(:translation, owner: function, purpose: :name, code: 'en', content: 'Name') }
let!(:description) { create(:translation, owner: function, purpose: :description, code: 'en', content: 'Desc') }
let!(:documentation) { create(:translation, owner: function, purpose: :documentation, code: 'en', content: 'Doc') }
let!(:deprecation) do
create(:translation, owner: function, purpose: :deprecation_message, code: 'en', content: 'Dep')
end
let!(:display) { create(:translation, owner: function, purpose: :display_message, code: 'en', content: 'Disp') }
let!(:alias_t) { create(:translation, owner: function, purpose: :alias, code: 'en', content: 'Ali') }
let!(:data_type) { create(:data_type, runtime: function.runtime) }
before do
create(:runtime_function_definition_data_type_link,
runtime_function_definition: function, referenced_data_type: data_type)
end
it 'matches the model' do
grpc_object = function.to_grpc
expect(grpc_object.to_h).to eq(
runtime_name: function.runtime_name,
runtime_parameter_definitions: [param.to_grpc.to_h],
signature: function.signature,
throws_error: function.throws_error,
name: [name.to_grpc.to_h],
description: [description.to_grpc.to_h],
documentation: [documentation.to_grpc.to_h],
deprecation_message: [deprecation.to_grpc.to_h],
display_message: [display.to_grpc.to_h],
alias: [alias_t.to_grpc.to_h],
linked_data_type_identifiers: [data_type.identifier],
version: function.version,
definition_source: 'sagittarius'
)
end
end
describe '#ordered_parameters' do
it 'orders parameters by persisted order' do
first_parameter = create(:runtime_parameter_definition, runtime_function_definition: function)
second_parameter = create(:runtime_parameter_definition, runtime_function_definition: function)
expect(function.parameters.to_a).to include(first_parameter, second_parameter)
expect(function.ordered_parameters).to eq([first_parameter, second_parameter])
end
end
end