fixturizer 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/dependencies.rb +1 -0
- data/lib/fixturizer/adapters/mongoid.rb +17 -19
- data/lib/fixturizer/configuration.rb +215 -1
- data/lib/fixturizer/engines/models.rb +20 -27
- data/lib/fixturizer/getters/init.rb +28 -0
- data/lib/fixturizer/getters/json.rb +16 -0
- data/lib/fixturizer/getters/yaml.rb +16 -0
- data/lib/fixturizer/rake/rules/configuration.rake +15 -0
- data/lib/fixturizer/rake/rules/database.rake +2 -1
- data/lib/fixturizer/rspec/helpers/getter.rb +24 -0
- data/lib/fixturizer/rspec/helpers/serializer.rb +1 -1
- data/lib/fixturizer/services.rb +20 -0
- data/lib/fixturizer/settings.rb +2 -1
- data/lib/fixturizer.rb +1 -0
- data/samples/Gemfile +1 -1
- data/samples/Rakefile +7 -0
- data/samples/config/rules.yml +7 -7
- data/samples/spec/app_spec.rb +34 -0
- data/samples/spec/fixtures/data.json +10 -0
- data/samples/spec/fixtures/data.yml +6 -0
- data/samples/spec/spec_helper.rb +6 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf7a1159047eed0d85251205266b374018fc8f7c7b7c312f91db96eb632a87ae
|
4
|
+
data.tar.gz: 965f93e4be42f6207e00647b2d456451425421b04eea4d7ceea984c5a2a7ce98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ef1bea30d4ce6398a6eb0f2df942ecb26ad25f9828339b8fb3e9067c18fe07a7bb7220ddba5ae3596c313d2202dd06dabaf40cf51ec370754b69796386d72f0
|
7
|
+
data.tar.gz: 2f46d5b7386d853503abc3b95576f1fbea6fe602f5a1608e4812a7639568ee50f303f2bed11daa0632ab344b3bd717757cbc4f9aff05c3f894926fb2a2f3fc0c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/lib/dependencies.rb
CHANGED
@@ -3,30 +3,28 @@
|
|
3
3
|
module Fixturizer
|
4
4
|
module Adapters
|
5
5
|
module Mongoid
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
6
|
+
def inject_data
|
7
|
+
list = (@orders.is_a? Array)? @order : @generated.keys
|
8
|
+
list.each do |name|
|
9
|
+
records = @generated[name]
|
10
|
+
records.each do |record|
|
11
|
+
link = record.dig(:link,:to)
|
12
|
+
by = record.dig(:link,:by)
|
13
|
+
pattern = record.dig(:link,:search_by)
|
14
|
+
if link.is_a? Symbol then
|
15
|
+
model = Object.const_get(@models[link][:class]).find_by(**pattern).send by
|
16
|
+
model.create!(record[:data]) unless model.where(@models[link][:unicity] => record[:data][@models[link][:unicity]]).exists?
|
17
|
+
else
|
18
|
+
model = Object.const_get(@models[name][:class])
|
19
|
+
model.create!(record[:data]) unless model.where(@models[name][:unicity] => record[:data][@models[name][:unicity]]).exists?
|
20
|
+
end
|
20
21
|
|
21
|
-
result[element[:fkey]] =
|
22
|
-
model.where({ element[:index][:search_key] => element[:index][:for] }).first[element[:pkey]]
|
23
|
-
else
|
24
|
-
raise 'Links configuration failure'
|
25
22
|
end
|
23
|
+
|
26
24
|
end
|
27
|
-
result
|
28
25
|
end
|
29
26
|
|
27
|
+
|
30
28
|
def drop_database
|
31
29
|
::Mongoid.purge!
|
32
30
|
true
|
@@ -1,10 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'yaml'
|
4
|
+
|
3
5
|
module Fixturizer
|
4
6
|
class Configuration
|
5
|
-
attr_reader :rules, :models, :datasets, :models_order, :models_type
|
7
|
+
attr_reader :rules, :models, :datasets, :models_order, :models_type, :filename
|
6
8
|
|
7
9
|
def initialize(filename:)
|
10
|
+
@filename = filename
|
8
11
|
@content = read_file(filename:)
|
9
12
|
@rules = @content[:fixtures][:rules]
|
10
13
|
@models_type = @content[:fixtures].dig(:models, :type)
|
@@ -19,4 +22,215 @@ module Fixturizer
|
|
19
22
|
YAML.load(File.readlines(filename).join)
|
20
23
|
end
|
21
24
|
end
|
25
|
+
|
26
|
+
class ConfigurationLinter
|
27
|
+
attr_reader :content
|
28
|
+
|
29
|
+
KEYS_BY_LEVEL = {:fixtures => [:rules,:models,:datasets],
|
30
|
+
:dataset => [:definition, :rules],
|
31
|
+
:models => [:type, :order, :definitions],
|
32
|
+
:model_definition => [:rules,:class,:unicity, :collection],
|
33
|
+
:collection => [:attributes,:links]
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
def initialize(filename:)
|
39
|
+
@status = {status: :ok, warn: [], error: [], cleaned: []}
|
40
|
+
@filename = filename
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def display
|
45
|
+
puts "Running linter for Configuration file : #{@filename} :"
|
46
|
+
validate
|
47
|
+
puts " => Status : #{@status[:status].to_s.upcase} "
|
48
|
+
unless @status[:error].empty? then
|
49
|
+
puts "Errors : "
|
50
|
+
@status[:error].each do |error|
|
51
|
+
puts " * #{error}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
unless @status[:warn].empty? then
|
55
|
+
puts "Warnings : "
|
56
|
+
@status[:warn].each do |warning|
|
57
|
+
puts " * #{warning}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def validate!
|
64
|
+
validate
|
65
|
+
unless @status[:status] == :ok
|
66
|
+
puts "Configuration error, run rake fixturizer:configuration:lint to show"
|
67
|
+
exit 10
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def validate
|
75
|
+
begin
|
76
|
+
@content = read_file filename: @filename
|
77
|
+
[:validate_root,:validate_section, :validate_rules,:validate_datasets,:validate_models].each do |method|
|
78
|
+
self.send method if @status[:status] = :ok
|
79
|
+
end
|
80
|
+
rescue RuntimeError => e
|
81
|
+
@status[:status] = :ko
|
82
|
+
@status[:error].push "Malformed YAML file #{e.message}"
|
83
|
+
rescue Errno::ENOENT
|
84
|
+
@status[:status] = :ko
|
85
|
+
@status[:error].push "Missing YAML file"
|
86
|
+
rescue NoMethodError => e
|
87
|
+
@status[:status] = :ko
|
88
|
+
@status[:error].push "Malformed YAML file #{e.message}"
|
89
|
+
end
|
90
|
+
return @status
|
91
|
+
end
|
92
|
+
|
93
|
+
def read_file(filename:)
|
94
|
+
YAML.load(File.readlines(filename).join)
|
95
|
+
end
|
96
|
+
|
97
|
+
def validate_root
|
98
|
+
if @content.dig(:fixtures).nil?
|
99
|
+
@status[:error].push "General root error : key is not Symbol :fixtures or empty"
|
100
|
+
@status[:status] = :ko
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def validate_section
|
105
|
+
full_nil = []
|
106
|
+
[:datasets,:rules,:models].each do |root|
|
107
|
+
unless @content.dig(:fixtures, root).is_a? Hash or @content.dig(:fixtures,root).nil?
|
108
|
+
@status[:error].push "//:fixtures/#{root} is not a Hash"
|
109
|
+
@status[:status] = :ko
|
110
|
+
end
|
111
|
+
full_nil.push root if @content.dig(:fixtures,root).nil?
|
112
|
+
end
|
113
|
+
if full_nil.size == 3
|
114
|
+
@status[:error].push "All sections are empty : #{full_nil}"
|
115
|
+
@status[:status] = :ko
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def validate_rules
|
120
|
+
return if @content.dig(:fixtures,:rules).nil?
|
121
|
+
count = @status[:error].size
|
122
|
+
@content.dig(:fixtures,:rules).each do |name, rule|
|
123
|
+
@status[:error].push "//:fixtures/:rules/:#{name} is not a Symbol" unless name.is_a? Symbol
|
124
|
+
@status[:error].push "//:fixtures/:rules/:#{name} record is not a Hash" unless rule.is_a? Hash
|
125
|
+
@status[:error].push "//:fixtures/:rules/:#{name} not have key :proc defined" unless rule.include? :proc
|
126
|
+
@status[:error].push "//:fixtures/:rules/:#{name}/:proc is not a String" unless rule[:proc].is_a? String
|
127
|
+
if rule.include? :preserve then
|
128
|
+
@status[:error].push "//:fixtures/:rules/:#{name} have key :preserve but it's not a Boolean" unless [true, false].include? rule[:preserve]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
@status[:status] = (@status[:error].size > count)? :ko : @status[:status]
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
def validate_datasets
|
136
|
+
return if @content.dig(:fixtures,:datasets).nil?
|
137
|
+
count = @status[:error].size
|
138
|
+
@content.dig(:fixtures,:datasets).each do |name, dataset|
|
139
|
+
@status[:error].push "//:fixtures/:datasets/:#{name} is not a Symbol" unless name.is_a? Symbol
|
140
|
+
@status[:error].push "//:fixtures/:datasets/:#{name} record is not a Hash" unless dataset.is_a? Hash
|
141
|
+
@status[:error].push "//:fixtures/:datasets/:#{name} not have key :definition defined" unless dataset.include? :definition
|
142
|
+
@status[:error].push "//:fixtures/:datasets/:#{name}/:definition is nil" if dataset[:definition].nil?
|
143
|
+
if dataset.include? :rules then
|
144
|
+
@status[:error].push "//:fixtures/:datasets/:#{name} have key :rules but it's not a Hash" unless dataset[:rules].is_a? Hash
|
145
|
+
dataset[:rules].each do |key,value|
|
146
|
+
@status[:error].push "//:fixtures/:datasets/:#{name}/:rules/#{key} is not a Symbol" unless key.is_a? Symbol
|
147
|
+
unless value.is_a? Symbol
|
148
|
+
@status[:error].push "//:fixtures/:datasets/:#{name}/:rules/#{key} value (#{value}) is not a Symbol"
|
149
|
+
else
|
150
|
+
@status[:warn].push "//:fixtures/:datasets/:#{name}/:rules/#{key} is useless" if deep_find_key(key,dataset[:definition]).empty?
|
151
|
+
end
|
152
|
+
@status[:error].push "//:fixtures/:datasets/:#{name}/:rules/#{key} set but no rules exist" unless @content.dig(:fixtures,:rules).include? value
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
@status[:status] = (@status[:error].size > count)? :ko : @status[:status]
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
def validate_models
|
163
|
+
return if @content.dig(:fixtures,:models).nil?
|
164
|
+
count = @status[:error].size
|
165
|
+
model_config = @content.dig(:fixtures,:models)
|
166
|
+
unless model_config.is_a? Hash
|
167
|
+
@status[:error].push "//:fixtures/:models record is not a Hash"
|
168
|
+
else
|
169
|
+
@status[:error].push "//:fixtures/:models/ not have key :type defined" unless model_config.include? :type
|
170
|
+
@status[:error].push "//:fixtures/:models/:type is not a symbol" unless model_config[:type].is_a? Symbol
|
171
|
+
@status[:error].push "//:fixtures/:models/ not have key :definitions defined" unless model_config.include? :definitions
|
172
|
+
unless model_config[:definitions].is_a? Hash then
|
173
|
+
@status[:error].push "//:fixtures/:models/:definitions is not a Hash"
|
174
|
+
else
|
175
|
+
@content.dig(:fixtures,:models,:definitions).each do |name, definitions|
|
176
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name} is not a Symbol" unless name.is_a? Symbol
|
177
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name} not have key :class defined" unless definitions.include? :class
|
178
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:class is not a String" unless definitions[:class].is_a? String
|
179
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name} not have key :unicity defined" unless definitions.include? :unicity
|
180
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:unicity is not a Symbol" unless definitions[:unicity].is_a? Symbol
|
181
|
+
if definitions.include? :rules then
|
182
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name} have key :rules but it's not a Hash" unless definitions[:rules].is_a? Hash
|
183
|
+
definitions[:rules].each do |key,value|
|
184
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:rules/#{key} is not a Symbol" unless key.is_a? Symbol
|
185
|
+
unless value.is_a? Symbol
|
186
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:rules/#{key} value (#{value}) is not a Symbol"
|
187
|
+
else
|
188
|
+
@status[:warn].push "//:fixtures/:models/:definitions/:#{name}/:rules/#{key} is useless" if deep_find_key(key,definitions[:collection]).empty?
|
189
|
+
end
|
190
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:rules/#{key} set but no rules exist" unless @content.dig(:fixtures,:rules).include? value
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name} not have key :collection defined" unless definitions.include? :collection
|
195
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:collection is not a Array" unless definitions[:collection].is_a? Array
|
196
|
+
if definitions.include? :collection then
|
197
|
+
definitions.dig(:collection).each_with_index do |record,i|
|
198
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:collection[#{i}] not have key :attributes defined" unless record.include? :attributes
|
199
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:collection[#{i}]/:attributes is not a Hash" unless record[:attributes].is_a? Hash
|
200
|
+
if record.include? :link
|
201
|
+
unless record[:link].is_a? Hash then
|
202
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:collection[#{i}]/:link is set but is not a Hash"
|
203
|
+
else
|
204
|
+
{to: Symbol, by: Symbol, search_by: Hash}.each do |verb,type|
|
205
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:collection[#{i}]/:link not have key :#{verb} defined" unless record[:link].include? verb
|
206
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:collection[#{i}]/:link/:#{verb} is not a #{type}" unless record[:link][verb].is_a? type
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
@status[:status] = (@status[:error].size > count)? :ko : @status[:status]
|
216
|
+
end
|
217
|
+
|
218
|
+
def deep_find_key(key, object)
|
219
|
+
found = []
|
220
|
+
if object.respond_to?(:key?) && object.key?(key)
|
221
|
+
found << key
|
222
|
+
end
|
223
|
+
if object.is_a? Enumerable
|
224
|
+
found << object.collect { |*a| deep_find_key(key, a.last) }
|
225
|
+
end
|
226
|
+
found.flatten.compact
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
end
|
233
|
+
|
22
234
|
end
|
235
|
+
|
236
|
+
|
@@ -5,11 +5,10 @@ module Fixturizer
|
|
5
5
|
class Models
|
6
6
|
ADAPTERS = { mongoid: ::Fixturizer::Adapters::Mongoid }.freeze
|
7
7
|
|
8
|
-
attr_reader :generated
|
8
|
+
attr_reader :generated, :order, :models
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
@configuration = Fixturizer::Services.get.configuration
|
12
|
-
@rules = @configuration.rules
|
13
12
|
@models = @configuration.models
|
14
13
|
@order = @configuration.models_order
|
15
14
|
@type = @configuration.models_type
|
@@ -18,12 +17,12 @@ module Fixturizer
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def populate
|
21
|
-
|
22
|
-
|
20
|
+
generate
|
21
|
+
inject
|
23
22
|
true
|
24
23
|
end
|
25
24
|
|
26
|
-
def
|
25
|
+
def generate
|
27
26
|
@generated.clear
|
28
27
|
raise 'Order field format missmatch, not an array' unless @order.nil? || @order.is_a?(Array)
|
29
28
|
|
@@ -32,41 +31,35 @@ module Fixturizer
|
|
32
31
|
|
33
32
|
@order.each do |item|
|
34
33
|
raise "Definition #{item} not found in models definitions" unless @models.include?(item)
|
35
|
-
|
36
|
-
@generated[item] = generate_collection(name: item)
|
34
|
+
@generated[item] = generate_collection(name: item)
|
37
35
|
end
|
38
36
|
else
|
39
|
-
@models.each_key do |
|
40
|
-
@generated[
|
37
|
+
@models.each_key do |item|
|
38
|
+
@generated[item] = generate_collection(name: item)
|
41
39
|
end
|
40
|
+
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
def
|
44
|
+
def inject
|
46
45
|
raise 'Data not generated' if @generated.empty?
|
47
|
-
|
48
|
-
@generated.each do |key, value|
|
49
|
-
model_infos = @models[key].dup
|
50
|
-
model_infos.delete(:collection)
|
51
|
-
value.each do |item|
|
52
|
-
item[:attributes].merge!(binder(item: item[:links])) if item.include?(:links)
|
53
|
-
injector model_infos:, item: item[:attributes]
|
54
|
-
end
|
55
|
-
end
|
46
|
+
inject_data
|
56
47
|
end
|
57
48
|
|
58
49
|
private
|
59
50
|
|
60
51
|
def generate_collection(name:)
|
61
|
-
data =
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
item
|
67
|
-
|
52
|
+
data = []
|
53
|
+
@models[name][:collection].each do |item|
|
54
|
+
res = {data: Fixturizer::Services.get.engine(name: :dataset, parameters: { dataset:
|
55
|
+
{ definition: item[:attributes], rules: @models[name][:rules]}
|
56
|
+
}).generate }
|
57
|
+
link = item.dig(:link)
|
58
|
+
res[:link] = link if link
|
59
|
+
data.push res
|
60
|
+
|
68
61
|
end
|
69
|
-
data
|
62
|
+
return data
|
70
63
|
end
|
71
64
|
end
|
72
65
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturizer
|
4
|
+
module Getters
|
5
|
+
class Template
|
6
|
+
attr_reader :filename, :data
|
7
|
+
|
8
|
+
def initialize(filename:, options: nil)
|
9
|
+
@filename = filename
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def retrieve
|
14
|
+
raise "Abstract template, don't use"
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_file(file)
|
18
|
+
return File.readlines(file).join
|
19
|
+
rescue Errno::EACCES
|
20
|
+
puts "Error: Permission denied to read the file #{file}."
|
21
|
+
rescue StandardError => e
|
22
|
+
puts "Error: #{e.message}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Dir["#{File.dirname(__FILE__)}/*.rb"].each { |file| require file unless File.basename(file) == 'init.rb' }
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturizer
|
4
|
+
module Getters
|
5
|
+
class Json < Template
|
6
|
+
def retrieve
|
7
|
+
result = nil
|
8
|
+
data = read_file(@filename)
|
9
|
+
result = JSON.parse(data, symbolize_names: @options[:symbolize])
|
10
|
+
return result
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturizer
|
4
|
+
module Getters
|
5
|
+
class Yaml < Template
|
6
|
+
def retrieve
|
7
|
+
result = nil
|
8
|
+
data = read_file(@filename)
|
9
|
+
result = YAML.load(data, symbolize_names: @options[:symbolize])
|
10
|
+
return result
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :fixturizer do
|
4
|
+
namespace :configuration do
|
5
|
+
desc 'Check the configuration file'
|
6
|
+
task :lint do
|
7
|
+
filename = (ENV['FIXTURIZER_CONFIGURATION_FILE'].is_a? String)?
|
8
|
+
ENV['FIXTURIZER_CONFIGURATION_FILE'] :
|
9
|
+
Fixturizer::Services.settings.configuration_filename
|
10
|
+
Fixturizer::Services.get.linter(filename: filename).display
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -5,12 +5,13 @@ namespace :fixturizer do
|
|
5
5
|
desc 'Drop database'
|
6
6
|
task :drop do
|
7
7
|
Fixturizer::Services.get.engine(name: :models).drop_database
|
8
|
-
|
8
|
+
puts "Database successfully dropped" if Fixturizer::Services.settings.verbose
|
9
9
|
end
|
10
10
|
|
11
11
|
desc 'Populate database'
|
12
12
|
task :populate do
|
13
13
|
Fixturizer::Services.get.engine(name: :models).populate
|
14
|
+
puts "Database successfully populated" if Fixturizer::Services.settings.verbose
|
14
15
|
end
|
15
16
|
|
16
17
|
desc 'Check database connection'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fixturizer
|
4
|
+
module Rspec
|
5
|
+
module Helpers
|
6
|
+
class Getter
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def from(format:, symbolize: true, file: )
|
10
|
+
options = {symbolize: symbolize}
|
11
|
+
Fixturizer::Services.get.getter(name: format,
|
12
|
+
parameters: {
|
13
|
+
filename: file, options: options
|
14
|
+
}).retrieve
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_content
|
22
|
+
Fixturizer::Rspec::Helpers::Getter.instance
|
23
|
+
end
|
24
|
+
|
data/lib/fixturizer/services.rb
CHANGED
@@ -15,6 +15,7 @@ module Fixturizer
|
|
15
15
|
attr_reader :configuration, :log
|
16
16
|
|
17
17
|
def initialize
|
18
|
+
linter(filename: @@settings.configuration_filename).validate! unless detect_rake_lint
|
18
19
|
@configuration = Fixturizer::Configuration.new filename: @@settings.configuration_filename
|
19
20
|
@log = Logger.new(Fixturizer::Services.settings.log_target)
|
20
21
|
log.info 'Starting new Fixturing'
|
@@ -35,13 +36,32 @@ module Fixturizer
|
|
35
36
|
service(type: :engines, name:, parameters:)
|
36
37
|
end
|
37
38
|
|
39
|
+
def getter(name:, parameters: nil)
|
40
|
+
service(type: :getters, name:, parameters:)
|
41
|
+
end
|
42
|
+
|
38
43
|
def serializer(name:, parameters: nil)
|
39
44
|
service(type: :serializers, name:, parameters:)
|
40
45
|
end
|
41
46
|
|
47
|
+
def linter(filename: @@settings.configuration_filename)
|
48
|
+
Fixturizer::ConfigurationLinter.new filename: filename
|
49
|
+
end
|
50
|
+
|
42
51
|
class << self
|
43
52
|
alias get instance
|
44
53
|
alias init instance
|
45
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def detect_rake_lint
|
59
|
+
res = false
|
60
|
+
if defined?(Rake)
|
61
|
+
res = true if Rake.application.top_level_tasks.first == "fixturizer:configuration:lint"
|
62
|
+
end
|
63
|
+
return res
|
64
|
+
end
|
65
|
+
|
46
66
|
end
|
47
67
|
end
|
data/lib/fixturizer/settings.rb
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
module Fixturizer
|
4
4
|
class Settings
|
5
|
-
attr_accessor :configuration_filename, :log_target
|
5
|
+
attr_accessor :configuration_filename, :log_target, :verbose
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@configuration_filename = './config/rules.yml'
|
9
9
|
@log_target = '/tmp/fixturizer.log'
|
10
|
+
@verbose = false
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
data/lib/fixturizer.rb
CHANGED
data/samples/Gemfile
CHANGED
data/samples/Rakefile
CHANGED
@@ -19,3 +19,10 @@ task :routes do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
require 'fixturizer/rake/manage'
|
22
|
+
|
23
|
+
|
24
|
+
Fixturizer::Services.configure do |settings|
|
25
|
+
settings.configuration_filename = './config/rules.yml'
|
26
|
+
settings.log_target = '/tmp/fixturizer.log'
|
27
|
+
settings.verbose = (ENV['VERBOSE'])? true : false
|
28
|
+
end
|
data/samples/config/rules.yml
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
- "two"
|
14
14
|
:rules:
|
15
15
|
:body: :body
|
16
|
+
|
16
17
|
:rules:
|
17
18
|
:body:
|
18
19
|
:proc: "SecureRandom.urlsafe_base64(64)"
|
@@ -29,7 +30,7 @@
|
|
29
30
|
:rules:
|
30
31
|
:body: :preserve_body
|
31
32
|
:class: Post
|
32
|
-
:unicity: :
|
33
|
+
:unicity: :title
|
33
34
|
:collection:
|
34
35
|
- :attributes:
|
35
36
|
:title: First post Title
|
@@ -44,9 +45,8 @@
|
|
44
45
|
- :attributes:
|
45
46
|
:name: test name
|
46
47
|
:message: test message
|
47
|
-
:
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
:
|
52
|
-
:pkey: :id
|
48
|
+
:link:
|
49
|
+
:to: :posts
|
50
|
+
:by: :comments
|
51
|
+
:search_by:
|
52
|
+
:title: First post Title
|
data/samples/spec/app_spec.rb
CHANGED
@@ -131,4 +131,38 @@ RSpec.describe 'Test Fixturizer' do
|
|
131
131
|
File.unlink(filename)
|
132
132
|
end
|
133
133
|
end
|
134
|
+
|
135
|
+
|
136
|
+
context 'Getters : test ' do
|
137
|
+
it 'must be possible to get content data from YAML file' do
|
138
|
+
filename = './spec/fixtures/data.yml'
|
139
|
+
result = get_content.from file: filename, format: :yaml
|
140
|
+
expect(result[:body]).to eq "test Body"
|
141
|
+
expect(result[:list].size).to eq 3
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'must be possible to get content data from YAML file without symbols keys' do
|
145
|
+
filename = './spec/fixtures/data.yml'
|
146
|
+
result = get_content.from file: filename, format: :yaml, symbolize: false
|
147
|
+
expect(result["body"]).to eq "test Body"
|
148
|
+
expect(result["list"].size).to eq 3
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'must be possible to get content data from JSON file' do
|
152
|
+
filename = './spec/fixtures/data.json'
|
153
|
+
result = get_content.from file: filename, format: :json
|
154
|
+
expect(result[:body]).to eq "test Body"
|
155
|
+
expect(result[:list].size).to eq 3
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'must be possible to get content data from JSON file without symbols keys' do
|
159
|
+
filename = './spec/fixtures/data.json'
|
160
|
+
result = get_content.from file: filename, format: :json, symbolize: false
|
161
|
+
expect(result["body"]).to eq "test Body"
|
162
|
+
expect(result["list"].size).to eq 3
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
|
134
168
|
end
|
data/samples/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'fixturizer/rspec/prepare'
|
5
|
+
|
6
|
+
Fixturizer::Services.configure do |settings|
|
7
|
+
settings.configuration_filename = './config/rules.yml'
|
8
|
+
settings.log_target = '/tmp/fixturizer.log'
|
9
|
+
end
|
10
|
+
|
5
11
|
require_relative '../app'
|
6
12
|
|
7
13
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fixturizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre ALPHONSE
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-05-
|
12
|
+
date: 2024-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -210,10 +210,15 @@ files:
|
|
210
210
|
- lib/fixturizer/engines/init.rb
|
211
211
|
- lib/fixturizer/engines/models.rb
|
212
212
|
- lib/fixturizer/engines/records.rb
|
213
|
+
- lib/fixturizer/getters/init.rb
|
214
|
+
- lib/fixturizer/getters/json.rb
|
215
|
+
- lib/fixturizer/getters/yaml.rb
|
213
216
|
- lib/fixturizer/rake/manage.rb
|
217
|
+
- lib/fixturizer/rake/rules/configuration.rake
|
214
218
|
- lib/fixturizer/rake/rules/database.rake
|
215
219
|
- lib/fixturizer/rspec/helpers/database.rb
|
216
220
|
- lib/fixturizer/rspec/helpers/datasets.rb
|
221
|
+
- lib/fixturizer/rspec/helpers/getter.rb
|
217
222
|
- lib/fixturizer/rspec/helpers/records.rb
|
218
223
|
- lib/fixturizer/rspec/helpers/serializer.rb
|
219
224
|
- lib/fixturizer/rspec/matchers/database_be_correctly_dropped.rb
|
@@ -232,6 +237,8 @@ files:
|
|
232
237
|
- samples/config.ru
|
233
238
|
- samples/config/rules.yml
|
234
239
|
- samples/spec/app_spec.rb
|
240
|
+
- samples/spec/fixtures/data.json
|
241
|
+
- samples/spec/fixtures/data.yml
|
235
242
|
- samples/spec/spec_helper.rb
|
236
243
|
homepage: https://github.com/Ultragreen/fixturizer
|
237
244
|
licenses:
|