fixturizer 0.4.1 → 0.4.3
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/fixturizer.gemspec +1 -1
- data/lib/fixturizer/adapters/mongoid.rb +17 -19
- data/lib/fixturizer/configuration.rb +215 -1
- data/lib/fixturizer/engines/models.rb +22 -27
- data/lib/fixturizer/rake/rules/configuration.rake +15 -0
- data/lib/fixturizer/rspec/helpers/database.rb +2 -2
- data/lib/fixturizer/services.rb +16 -0
- data/samples/Gemfile +2 -2
- data/samples/app.rb +12 -1
- data/samples/config/rules.yml +23 -7
- data/samples/spec/app_spec.rb +11 -11
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cc92b66c50911ec30ffd277772939fb652d9b88e3dc33fa2b1cdbccb01aa776
|
4
|
+
data.tar.gz: 7cce30b3455b91e6e32fbdede70a1637e8b063f7b1bf3e02cce8e4e39d0bdbcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e213a056cc0d54acc95ef428a47125cc1a48a733e6065fc30a0bcee7b50c88c873b4eac799b3d9e4e4813439ba5cdc0f67c4396f33f46ac68e926451aa9ee13
|
7
|
+
data.tar.gz: 4ed4d832360555326fc93d16ef9c8413f506c250e39dfa7e56adf7cb65de20f1405812c6b3683ee00e5d4e2d937d1163c5de0cae13f276a60dd316d3e3eb454c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
data/fixturizer.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
|
32
32
|
spec.add_dependency 'mongoid', '~> 9.0'
|
33
33
|
spec.add_dependency 'rake', '~> 13.0'
|
34
|
-
spec.add_dependency 'rspec', '~> 3.
|
34
|
+
spec.add_dependency 'rspec', '~> 3.13.0'
|
35
35
|
spec.add_dependency 'version', '~> 1.1'
|
36
36
|
|
37
37
|
spec.add_development_dependency 'bundle-audit', '~> 0.1.0'
|
@@ -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
|
+
belong = record.dig(:belong,:to)
|
12
|
+
by = record.dig(:belong,:by)
|
13
|
+
pattern = record.dig(:belong,:search_by)
|
14
|
+
if link.is_a? Symbol then
|
15
|
+
model = Object.const_get(@models[belong][:class]).find_by(**pattern).send by
|
16
|
+
model.create!(record[:data]) unless model.where(@models[belong][:unicity] => record[:data][@models[belong][: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,:belong]
|
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? :belong
|
201
|
+
unless record[:belong].is_a? Hash then
|
202
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:collection[#{i}]/:belong 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}]/:belong not have key :#{verb} defined" unless record[:belong].include? verb
|
206
|
+
@status[:error].push "//:fixtures/:models/:definitions/:#{name}/:collection[#{i}]/:belong/:#{verb} is not a #{type}" unless record[:belong][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,37 @@ 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
|
+
belong = item.dig(:belong)
|
58
|
+
res[:belong] = belong if belong
|
59
|
+
have = item.dig(:have)
|
60
|
+
res[:have] = have if have
|
61
|
+
data.push res
|
62
|
+
|
68
63
|
end
|
69
|
-
data
|
64
|
+
return data
|
70
65
|
end
|
71
66
|
end
|
72
67
|
end
|
@@ -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
|
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'
|
@@ -43,9 +44,24 @@ module Fixturizer
|
|
43
44
|
service(type: :serializers, name:, parameters:)
|
44
45
|
end
|
45
46
|
|
47
|
+
def linter(filename: @@settings.configuration_filename)
|
48
|
+
Fixturizer::ConfigurationLinter.new filename: filename
|
49
|
+
end
|
50
|
+
|
46
51
|
class << self
|
47
52
|
alias get instance
|
48
53
|
alias init instance
|
49
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
|
+
|
50
66
|
end
|
51
67
|
end
|
data/samples/Gemfile
CHANGED
@@ -7,11 +7,11 @@ gem 'rackup', '~> 2.1'
|
|
7
7
|
gem 'sinatra', '~> 4.0.0'
|
8
8
|
|
9
9
|
group :test, :development do
|
10
|
-
gem 'fixturizer'
|
10
|
+
gem 'fixturizer'
|
11
11
|
gem 'rack-rest-rspec', '~> 0.0.3'
|
12
12
|
gem 'rack-test', '~> 2.0.2'
|
13
13
|
gem 'rake', '~> 13.0'
|
14
|
-
gem 'rspec', '~> 3.
|
14
|
+
gem 'rspec', '~> 3.13.0'
|
15
15
|
end
|
16
16
|
|
17
17
|
gem 'mongoid', '~> 9.0'
|
data/samples/app.rb
CHANGED
@@ -16,8 +16,18 @@ class Post
|
|
16
16
|
field :title, type: String
|
17
17
|
field :body, type: String
|
18
18
|
has_many :comments
|
19
|
+
has_one :type
|
19
20
|
end
|
20
21
|
|
22
|
+
|
23
|
+
class Type
|
24
|
+
include Mongoid::Document
|
25
|
+
field :name, type: String
|
26
|
+
field :description, type: String
|
27
|
+
belongs_to :post, optional: true
|
28
|
+
end
|
29
|
+
|
30
|
+
|
21
31
|
class Comment
|
22
32
|
include Mongoid::Document
|
23
33
|
field :name, type: String
|
@@ -37,7 +47,8 @@ class Application < Sinatra::Base
|
|
37
47
|
get '/posts/:post_id' do |post_id|
|
38
48
|
post = Post.find(post_id)
|
39
49
|
post.attributes.merge(
|
40
|
-
comments: post.comments
|
50
|
+
comments: post.comments,
|
51
|
+
type: post.type
|
41
52
|
).to_json
|
42
53
|
end
|
43
54
|
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)"
|
@@ -22,18 +23,34 @@
|
|
22
23
|
:models:
|
23
24
|
:type: :mongoid
|
24
25
|
:order:
|
26
|
+
- :types
|
25
27
|
- :posts
|
26
28
|
- :comments
|
27
29
|
:definitions:
|
30
|
+
:types:
|
31
|
+
:class: Type
|
32
|
+
:unicity: :name
|
33
|
+
:collection:
|
34
|
+
- :attributes:
|
35
|
+
:name: News
|
36
|
+
:description: A fresh news
|
37
|
+
- :attributes:
|
38
|
+
:name: Reaction
|
39
|
+
:description: An instant reaction
|
28
40
|
:posts:
|
29
41
|
:rules:
|
30
42
|
:body: :preserve_body
|
31
43
|
:class: Post
|
32
|
-
:unicity: :
|
44
|
+
:unicity: :title
|
33
45
|
:collection:
|
34
46
|
- :attributes:
|
35
47
|
:title: First post Title
|
36
48
|
:body: First Post Body
|
49
|
+
# :have:
|
50
|
+
# :linked: :types
|
51
|
+
# :by: :type
|
52
|
+
# :search_by:
|
53
|
+
# :name: News
|
37
54
|
- :attributes:
|
38
55
|
:title: Second post Title
|
39
56
|
:body:
|
@@ -44,9 +61,8 @@
|
|
44
61
|
- :attributes:
|
45
62
|
:name: test name
|
46
63
|
:message: test message
|
47
|
-
:
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
:
|
52
|
-
:pkey: :id
|
64
|
+
:belong:
|
65
|
+
:to: :posts
|
66
|
+
:by: :comments
|
67
|
+
:search_by:
|
68
|
+
:title: First post Title
|
data/samples/spec/app_spec.rb
CHANGED
@@ -81,17 +81,17 @@ RSpec.describe 'Test Fixturizer' do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
84
|
+
context 'Database : drop and populate' do
|
85
|
+
it 'must be possible to drop database with helper ' do
|
86
|
+
expect(database.drop).to be true
|
87
|
+
end
|
88
|
+
it 'must be possible to populate database with helper ' do
|
89
|
+
expect(database.populate).to be true
|
90
|
+
end
|
91
|
+
|
92
|
+
it { expect(database).to be_correctly_dropped }
|
93
|
+
it { expect(database).to be_correctly_populated }
|
94
|
+
end
|
95
95
|
|
96
96
|
context 'Serializers : test ' do
|
97
97
|
it 'must be possible to serialize data to JSON' do
|
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.3
|
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-
|
12
|
+
date: 2024-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 3.
|
48
|
+
version: 3.13.0
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 3.
|
55
|
+
version: 3.13.0
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: version
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -214,6 +214,7 @@ files:
|
|
214
214
|
- lib/fixturizer/getters/json.rb
|
215
215
|
- lib/fixturizer/getters/yaml.rb
|
216
216
|
- lib/fixturizer/rake/manage.rb
|
217
|
+
- lib/fixturizer/rake/rules/configuration.rake
|
217
218
|
- lib/fixturizer/rake/rules/database.rake
|
218
219
|
- lib/fixturizer/rspec/helpers/database.rb
|
219
220
|
- lib/fixturizer/rspec/helpers/datasets.rb
|