tataru 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/tataru.rb +70 -12
- data/lib/tataru/base_resource.rb +49 -0
- data/lib/tataru/base_resource_desc.rb +35 -0
- data/lib/tataru/compiler.rb +100 -0
- data/lib/tataru/create_subroutines.rb +31 -0
- data/lib/tataru/delete_subroutines.rb +42 -0
- data/lib/tataru/flattener.rb +81 -0
- data/lib/tataru/init_hash_compiler.rb +41 -0
- data/lib/tataru/instruction.rb +52 -7
- data/lib/tataru/instruction_hash.rb +54 -0
- data/lib/tataru/instructions/call_instruction.rb +19 -0
- data/lib/tataru/instructions/check_create_instruction.rb +27 -0
- data/lib/tataru/instructions/check_delete_instruction.rb +20 -0
- data/lib/tataru/instructions/check_instruction.rb +26 -0
- data/lib/tataru/instructions/check_update_instruction.rb +27 -0
- data/lib/tataru/instructions/clear_instruction.rb +12 -0
- data/lib/tataru/instructions/compare_instruction.rb +16 -0
- data/lib/tataru/instructions/create_instruction.rb +20 -0
- data/lib/tataru/instructions/delete_instruction.rb +14 -0
- data/lib/tataru/instructions/end_instruction.rb +12 -0
- data/lib/tataru/instructions/goto_if_instruction.rb +26 -0
- data/lib/tataru/instructions/immediate_mode_instruction.rb +12 -0
- data/lib/tataru/instructions/init_instruction.rb +27 -0
- data/lib/tataru/instructions/key_instruction.rb +12 -0
- data/lib/tataru/instructions/mark_deletable_instruction.rb +13 -0
- data/lib/tataru/instructions/read_instruction.rb +28 -0
- data/lib/tataru/instructions/rescmp_instruction.rb +34 -0
- data/lib/tataru/instructions/resource_instruction.rb +15 -0
- data/lib/tataru/instructions/return_instruction.rb +16 -0
- data/lib/tataru/instructions/update_instruction.rb +16 -0
- data/lib/tataru/instructions/value_instruction.rb +15 -0
- data/lib/tataru/instructions/value_rom_instruction.rb +23 -0
- data/lib/tataru/instructions/value_update_instruction.rb +18 -0
- data/lib/tataru/memory.rb +16 -0
- data/lib/tataru/quest.rb +43 -0
- data/lib/tataru/representation.rb +22 -0
- data/lib/tataru/representations/array_representation.rb +18 -0
- data/lib/tataru/representations/hash_representation.rb +20 -0
- data/lib/tataru/representations/literal_representation.rb +9 -0
- data/lib/tataru/representations/output_representation.rb +19 -0
- data/lib/tataru/representations/resource_representation.rb +49 -0
- data/lib/tataru/resolver.rb +39 -0
- data/lib/tataru/resource_dsl.rb +21 -71
- data/lib/tataru/resource_type_pool.rb +22 -0
- data/lib/tataru/rom_reader.rb +47 -0
- data/lib/tataru/runner.rb +48 -0
- data/lib/tataru/sub_planner.rb +41 -0
- data/lib/tataru/subroutine_compiler.rb +52 -0
- data/lib/tataru/top_dsl.rb +35 -0
- data/lib/tataru/update_subroutines.rb +111 -0
- data/lib/tataru/version.rb +1 -1
- data/spec/compiler_spec.rb +181 -0
- data/spec/flattener_spec.rb +88 -0
- data/spec/init_hash_compiler_spec.rb +85 -0
- data/spec/instruction_hash_spec.rb +63 -0
- data/spec/instruction_spec.rb +36 -0
- data/spec/instructions/call_instruction_spec.rb +28 -0
- data/spec/instructions/check_create_instruction_spec.rb +67 -0
- data/spec/instructions/check_delete_instruction_spec.rb +47 -0
- data/spec/instructions/check_update_instruction_spec.rb +67 -0
- data/spec/instructions/clear_instruction_spec.rb +16 -0
- data/spec/instructions/compare_instruction_spec.rb +29 -0
- data/spec/instructions/create_instruction_spec.rb +62 -0
- data/spec/instructions/delete_instruction_spec.rb +20 -0
- data/spec/instructions/end_instruction_spec.rb +15 -0
- data/spec/instructions/goto_if_instruction_spec.rb +42 -0
- data/spec/instructions/init_instruction_spec.rb +16 -0
- data/spec/instructions/key_instruction_spec.rb +15 -0
- data/spec/instructions/mark_deletable_instruction_spec.rb +20 -0
- data/spec/instructions/read_instruction_spec.rb +34 -0
- data/spec/instructions/rescmp_instruction_spec.rb +113 -0
- data/spec/instructions/return_instruction_spec.rb +28 -0
- data/spec/instructions/update_instruction_spec.rb +39 -0
- data/spec/instructions/value_instruction_spec.rb +27 -0
- data/spec/instructions/value_rom_instruction_spec.rb +170 -0
- data/spec/instructions/value_update_instruction_spec.rb +35 -0
- data/spec/quest_spec.rb +9 -0
- data/spec/representations/array_representation_spec.rb +29 -0
- data/spec/representations/hash_representation_spec.rb +29 -0
- data/spec/representations/literal_representation_spec.rb +10 -0
- data/spec/representations/output_representation_spec.rb +11 -0
- data/spec/representations/resource_representation_spec.rb +50 -0
- data/spec/resource_dsl_spec.rb +71 -0
- data/spec/runner_spec.rb +99 -0
- data/spec/spec_helper.rb +401 -0
- data/spec/subroutine_compiler_spec.rb +39 -0
- data/spec/taru_spec.rb +616 -0
- data/spec/top_dsl_spec.rb +68 -0
- data/tataru.gemspec +45 -0
- metadata +145 -27
- data/Rakefile +0 -8
- data/lib/tataru/default_resource_finder.rb +0 -10
- data/lib/tataru/execution_step.rb +0 -79
- data/lib/tataru/planner.rb +0 -93
- data/lib/tataru/requirements.rb +0 -67
- data/lib/tataru/requirements_dsl.rb +0 -33
- data/lib/tataru/resource.rb +0 -52
- data/lib/tataru/state.rb +0 -64
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::Instructions::ValueInstruction do
|
6
|
+
it 'set a value' do
|
7
|
+
mem = Tataru::Memory.new
|
8
|
+
instr = Tataru::Instructions::ValueInstruction.new('something')
|
9
|
+
|
10
|
+
mem.hash[:temp] = { _key: :somefield }
|
11
|
+
instr.memory = mem
|
12
|
+
instr.run
|
13
|
+
|
14
|
+
expect(mem.hash[:temp]).to eq(somefield: 'something')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns an error if no key' do
|
18
|
+
mem = Tataru::Memory.new
|
19
|
+
instr = Tataru::Instructions::ValueInstruction.new('something')
|
20
|
+
|
21
|
+
mem.hash[:temp] = {}
|
22
|
+
instr.memory = mem
|
23
|
+
instr.run
|
24
|
+
|
25
|
+
expect(mem.error).to eq 'No key set'
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::Instructions::ValueRomInstruction do
|
6
|
+
it 'returns an error if no key' do
|
7
|
+
mem = Tataru::Memory.new
|
8
|
+
instr = Tataru::Instructions::ValueRomInstruction.new('something')
|
9
|
+
|
10
|
+
mem.hash[:rom] = {}
|
11
|
+
mem.hash[:temp] = {}
|
12
|
+
instr.memory = mem
|
13
|
+
instr.run
|
14
|
+
|
15
|
+
expect(mem.error).to eq 'No key set'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns an error if no such thing' do
|
19
|
+
mem = Tataru::Memory.new
|
20
|
+
instr = Tataru::Instructions::ValueRomInstruction.new('something')
|
21
|
+
|
22
|
+
mem.hash[:rom] = {}
|
23
|
+
mem.hash[:temp] = { _key: :somefield }
|
24
|
+
instr.memory = mem
|
25
|
+
expect { instr.run }.to raise_error 'Not found'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets a literal' do
|
29
|
+
mem = Tataru::Memory.new
|
30
|
+
instr = Tataru::Instructions::ValueRomInstruction.new('something')
|
31
|
+
|
32
|
+
mem.hash[:rom] = {
|
33
|
+
'something' => {
|
34
|
+
type: :literal,
|
35
|
+
value: 'somevalue'
|
36
|
+
}
|
37
|
+
}
|
38
|
+
mem.hash[:temp] = { _key: :somefield }
|
39
|
+
instr.memory = mem
|
40
|
+
instr.run
|
41
|
+
|
42
|
+
expect(mem.hash[:temp]).to eq(somefield: 'somevalue')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sets an array' do
|
46
|
+
mem = Tataru::Memory.new
|
47
|
+
instr = Tataru::Instructions::ValueRomInstruction.new('something')
|
48
|
+
|
49
|
+
mem.hash[:rom] = {
|
50
|
+
'something' => {
|
51
|
+
type: :array,
|
52
|
+
references: {
|
53
|
+
0 => 'a',
|
54
|
+
1 => 'b'
|
55
|
+
}
|
56
|
+
},
|
57
|
+
'a' => {
|
58
|
+
type: :literal,
|
59
|
+
value: 'meow'
|
60
|
+
},
|
61
|
+
'b' => {
|
62
|
+
type: :literal,
|
63
|
+
value: 'woof'
|
64
|
+
}
|
65
|
+
}
|
66
|
+
mem.hash[:temp] = { _key: :somefield }
|
67
|
+
instr.memory = mem
|
68
|
+
instr.run
|
69
|
+
|
70
|
+
expect(mem.hash[:temp]).to eq(somefield: ['meow', 'woof'])
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'sets a hash' do
|
74
|
+
mem = Tataru::Memory.new
|
75
|
+
instr = Tataru::Instructions::ValueRomInstruction.new('something')
|
76
|
+
|
77
|
+
mem.hash[:rom] = {
|
78
|
+
'something' => {
|
79
|
+
type: :hash,
|
80
|
+
references: {
|
81
|
+
'x' => 'aaa',
|
82
|
+
'y' => 'bbbb'
|
83
|
+
}
|
84
|
+
},
|
85
|
+
'aaa' => {
|
86
|
+
type: :literal,
|
87
|
+
value: 100
|
88
|
+
},
|
89
|
+
'bbbb' => {
|
90
|
+
type: :literal,
|
91
|
+
value: 200
|
92
|
+
}
|
93
|
+
}
|
94
|
+
mem.hash[:temp] = { _key: :somefield }
|
95
|
+
instr.memory = mem
|
96
|
+
instr.run
|
97
|
+
|
98
|
+
expect(mem.hash[:temp]).to eq(somefield: {
|
99
|
+
'x' => 100,
|
100
|
+
'y' => 200
|
101
|
+
})
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'sets an output' do
|
105
|
+
mem = Tataru::Memory.new
|
106
|
+
instr = Tataru::Instructions::ValueRomInstruction.new('something')
|
107
|
+
|
108
|
+
mem.hash[:outputs] = {
|
109
|
+
'someresource' => {
|
110
|
+
name: 'somename'
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
mem.hash[:rom] = {
|
115
|
+
'something' => {
|
116
|
+
type: :output,
|
117
|
+
resource: 'someresource',
|
118
|
+
output: :name
|
119
|
+
}
|
120
|
+
}
|
121
|
+
mem.hash[:temp] = { _key: :somefield }
|
122
|
+
instr.memory = mem
|
123
|
+
instr.run
|
124
|
+
|
125
|
+
expect(mem.hash[:temp]).to eq(somefield: 'somename')
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'sets inner values' do
|
129
|
+
mem = Tataru::Memory.new
|
130
|
+
instr = Tataru::Instructions::ValueRomInstruction.new('something')
|
131
|
+
|
132
|
+
mem.hash[:rom] = {
|
133
|
+
'something' => {
|
134
|
+
type: :hash,
|
135
|
+
references: {
|
136
|
+
'x' => 'literal',
|
137
|
+
'y' => 'array'
|
138
|
+
}
|
139
|
+
},
|
140
|
+
'literal' => {
|
141
|
+
type: :literal,
|
142
|
+
value: 'something'
|
143
|
+
},
|
144
|
+
'array' => {
|
145
|
+
type: :array,
|
146
|
+
references: {
|
147
|
+
0 => 'value1',
|
148
|
+
1 => 'value2'
|
149
|
+
}
|
150
|
+
},
|
151
|
+
'value1' => {
|
152
|
+
type: :literal,
|
153
|
+
value: 'v1'
|
154
|
+
},
|
155
|
+
'value2' => {
|
156
|
+
type: :literal,
|
157
|
+
value: 'v2'
|
158
|
+
}
|
159
|
+
}
|
160
|
+
mem.hash[:temp] = { _key: :somefield }
|
161
|
+
instr.memory = mem
|
162
|
+
instr.run
|
163
|
+
|
164
|
+
expect(mem.hash[:temp]).to eq(somefield: {
|
165
|
+
'x' => 'something',
|
166
|
+
'y' => ['v1', 'v2']
|
167
|
+
})
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::Instructions::ValueUpdateInstruction do
|
6
|
+
it 'sets temp with update action of resource' do
|
7
|
+
mem = Tataru::Memory.new
|
8
|
+
instr = Tataru::Instructions::ValueUpdateInstruction.new('thething')
|
9
|
+
|
10
|
+
mem.hash[:update_action] = {
|
11
|
+
'thething' => :hello
|
12
|
+
}
|
13
|
+
|
14
|
+
mem.hash[:temp] = {}
|
15
|
+
|
16
|
+
instr.memory = mem
|
17
|
+
instr.run
|
18
|
+
|
19
|
+
expect(mem.hash[:temp]).to eq(
|
20
|
+
result: :hello
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'throws if no such resource' do
|
25
|
+
mem = Tataru::Memory.new
|
26
|
+
instr = Tataru::Instructions::ValueUpdateInstruction.new('thething')
|
27
|
+
|
28
|
+
mem.hash[:update_action] = {}
|
29
|
+
|
30
|
+
mem.hash[:temp] = {}
|
31
|
+
|
32
|
+
instr.memory = mem
|
33
|
+
expect { instr.run }.to raise_error "No value set for 'thething'"
|
34
|
+
end
|
35
|
+
end
|
data/spec/quest_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::Representations::ArrayRepresentation do
|
6
|
+
it 'has no dependencies for empty array' do
|
7
|
+
rep = Tataru::Representations::ArrayRepresentation.new([])
|
8
|
+
expect(rep.dependencies).to eq []
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has no dependencies for array with only literals' do
|
12
|
+
rep = Tataru::Representations::ArrayRepresentation.new(['hi'])
|
13
|
+
expect(rep.dependencies).to eq []
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has dependencies for each resource' do
|
17
|
+
rr = Tataru::Representations::ResourceRepresentation.new('file', Tataru::BaseResourceDesc.new, {})
|
18
|
+
rep = Tataru::Representations::ArrayRepresentation.new([rr])
|
19
|
+
expect(rep.dependencies).to eq ['file']
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has dependencies for every resource' do
|
23
|
+
rr1 = Tataru::Representations::ResourceRepresentation.new('file1', Tataru::BaseResourceDesc.new, {})
|
24
|
+
rr2 = Tataru::Representations::ResourceRepresentation.new('file2', Tataru::BaseResourceDesc.new, {})
|
25
|
+
rep = Tataru::Representations::ArrayRepresentation.new([rr1, rr2, 'awd'])
|
26
|
+
|
27
|
+
expect(rep.dependencies).to eq ['file1', 'file2']
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::Representations::HashRepresentation do
|
6
|
+
it 'has no dependencies for empty array' do
|
7
|
+
rep = Tataru::Representations::HashRepresentation.new({})
|
8
|
+
expect(rep.dependencies).to eq []
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'has no dependencies for array with only literals' do
|
12
|
+
rep = Tataru::Representations::HashRepresentation.new({'greeting' => 'hi'})
|
13
|
+
expect(rep.dependencies).to eq []
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has dependencies for each resource' do
|
17
|
+
rr = Tataru::Representations::ResourceRepresentation.new('file', Tataru::BaseResourceDesc.new, {})
|
18
|
+
rep = Tataru::Representations::HashRepresentation.new(thing: rr)
|
19
|
+
expect(rep.dependencies).to eq ['file']
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has dependencies for every resource' do
|
23
|
+
rr1 = Tataru::Representations::ResourceRepresentation.new('file1', Tataru::BaseResourceDesc.new, {})
|
24
|
+
rr2 = Tataru::Representations::ResourceRepresentation.new('file2', Tataru::BaseResourceDesc.new, {})
|
25
|
+
rep = Tataru::Representations::HashRepresentation.new(thing1: rr1, thing2: rr2, text: 'hello')
|
26
|
+
|
27
|
+
expect(rep.dependencies).to eq ['file1', 'file2']
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::Representations::OutputRepresentation do
|
6
|
+
it 'has a dependency on itself' do
|
7
|
+
rr = Tataru::Representations::OutputRepresentation.new('file', 'created_at')
|
8
|
+
|
9
|
+
expect(rr.dependencies).to eq ['file']
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::Representations::ResourceRepresentation do
|
6
|
+
it 'has a dependency on itself' do
|
7
|
+
rr = Tataru::Representations::ResourceRepresentation.new('file', Tataru::BaseResourceDesc.new, {})
|
8
|
+
|
9
|
+
expect(rr.dependencies).to eq ['file']
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'releases outputs' do
|
13
|
+
desc = Tataru::BaseResourceDesc.new
|
14
|
+
rr = Tataru::Representations::ResourceRepresentation.new('file', desc, {})
|
15
|
+
|
16
|
+
allow(desc).to receive(:output_fields) { [:created_at] }
|
17
|
+
|
18
|
+
expect(rr.created_at).to be_a(Tataru::Representations::OutputRepresentation)
|
19
|
+
expect(rr.created_at.resource_name).to eq 'file'
|
20
|
+
expect(rr.created_at.output_field_name).to eq :created_at
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'throws error if required field not filled' do
|
24
|
+
desc = Tataru::BaseResourceDesc.new
|
25
|
+
rr = Tataru::Representations::ResourceRepresentation.new('file', desc, {})
|
26
|
+
allow(desc).to receive(:immutable_fields) { [:filename] }
|
27
|
+
allow(desc).to receive(:required_fields) { [:filename] }
|
28
|
+
|
29
|
+
expect { rr.check_required_fields! }.to raise_error "Required field 'filename' not provided in 'file'"
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'throws error when no such output' do
|
33
|
+
desc = Tataru::BaseResourceDesc.new
|
34
|
+
rr = Tataru::Representations::ResourceRepresentation.new('file', desc, {})
|
35
|
+
|
36
|
+
allow(desc).to receive(:output_fields) { [:created_at] }
|
37
|
+
|
38
|
+
expect { rr.updated_at }.to raise_error NoMethodError
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'throws error when no such output' do
|
42
|
+
desc = Tataru::BaseResourceDesc.new
|
43
|
+
allow(desc).to receive(:needs_remote_id?) { false }
|
44
|
+
allow(desc).to receive(:delete_at_end?) { true }
|
45
|
+
|
46
|
+
expect { Tataru::Representations::ResourceRepresentation.new('file', desc, {}) }.to raise_error(
|
47
|
+
'must need remote id if deletes at end'
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tataru'
|
4
|
+
|
5
|
+
describe Tataru::ResourceDsl do
|
6
|
+
it 'validates mutable fields' do
|
7
|
+
resource_desc = Tataru::BaseResourceDesc.new
|
8
|
+
allow(resource_desc).to receive(:mutable_fields) { [:filename] }
|
9
|
+
|
10
|
+
dsl = Tataru::ResourceDsl.new('somefile', resource_desc)
|
11
|
+
dsl.filename 'thing'
|
12
|
+
|
13
|
+
expect(dsl.representation).to be_a Tataru::Representations::ResourceRepresentation
|
14
|
+
expect(dsl.representation.properties[:filename]).to be_a Tataru::Representations::LiteralRepresentation
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'validates immutable fields' do
|
18
|
+
resource_desc = Tataru::BaseResourceDesc.new
|
19
|
+
allow(resource_desc).to receive(:immutable_fields) { [:filename] }
|
20
|
+
|
21
|
+
dsl = Tataru::ResourceDsl.new('somefile', resource_desc)
|
22
|
+
dsl.filename 'thing'
|
23
|
+
|
24
|
+
expect(dsl.representation).to be_a Tataru::Representations::ResourceRepresentation
|
25
|
+
expect(dsl.representation.properties[:filename]).to be_a Tataru::Representations::LiteralRepresentation
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns an output representation when given an output' do
|
29
|
+
resource_desc = Tataru::BaseResourceDesc.new
|
30
|
+
allow(resource_desc).to receive(:immutable_fields) { [:filename] }
|
31
|
+
|
32
|
+
desc = Tataru::BaseResourceDesc.new
|
33
|
+
rr = Tataru::Representations::ResourceRepresentation.new('other_resource', desc, {})
|
34
|
+
allow(desc).to receive(:output_fields) { [:created_at] }
|
35
|
+
|
36
|
+
dsl = Tataru::ResourceDsl.new('somefile', resource_desc)
|
37
|
+
dsl.filename rr.created_at
|
38
|
+
|
39
|
+
expect(dsl.representation).to be_a Tataru::Representations::ResourceRepresentation
|
40
|
+
expect(dsl.representation.properties[:filename]).to be_a Tataru::Representations::OutputRepresentation
|
41
|
+
expect(dsl.representation.properties[:filename].resource_name).to eq 'other_resource'
|
42
|
+
expect(dsl.representation.properties[:filename].output_field_name).to eq :created_at
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns an output representation of remote ID' do
|
46
|
+
resource_desc = Tataru::BaseResourceDesc.new
|
47
|
+
allow(resource_desc).to receive(:immutable_fields) { [:filename] }
|
48
|
+
|
49
|
+
|
50
|
+
desc = Tataru::BaseResourceDesc.new
|
51
|
+
rr = Tataru::Representations::ResourceRepresentation.new('other_resource', desc, {})
|
52
|
+
allow(desc).to receive(:output_fields) { [:created_at] }
|
53
|
+
|
54
|
+
|
55
|
+
dsl = Tataru::ResourceDsl.new('somefile', resource_desc)
|
56
|
+
dsl.filename rr
|
57
|
+
|
58
|
+
expect(dsl.representation).to be_a Tataru::Representations::ResourceRepresentation
|
59
|
+
expect(dsl.representation.properties[:filename]).to be_a Tataru::Representations::OutputRepresentation
|
60
|
+
expect(dsl.representation.properties[:filename].resource_name).to eq 'other_resource'
|
61
|
+
expect(dsl.representation.properties[:filename].output_field_name).to eq :remote_id
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'throws error if nonexistent field' do
|
65
|
+
resource_desc = Tataru::BaseResourceDesc.new
|
66
|
+
allow(resource_desc).to receive(:immutable_fields) { [:filename] }
|
67
|
+
|
68
|
+
dsl = Tataru::ResourceDsl.new('somefile', resource_desc)
|
69
|
+
expect { dsl.age 'thing' }.to raise_error NoMethodError
|
70
|
+
end
|
71
|
+
end
|