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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aac283c9566f5b74f5c0c8b1d174e01904f536778f6988f6dbf8d64cbe7d3534
4
- data.tar.gz: cb55911646494e39c98df07349f105453d63ea79509f030686f1b3177b5ef733
3
+ metadata.gz: cf7a1159047eed0d85251205266b374018fc8f7c7b7c312f91db96eb632a87ae
4
+ data.tar.gz: 965f93e4be42f6207e00647b2d456451425421b04eea4d7ceea984c5a2a7ce98
5
5
  SHA512:
6
- metadata.gz: b4a3ab904e5f5136c69550b27919c2fc78297f95b82159721837bbf7bf771459c09f901e6de0acd44427f86b2cf3a41b85cb6fba4b36729b5c363192647a5cc5
7
- data.tar.gz: f2ca679fc8c541f66c8523ca1964e0d5b624310ac197e0c719c828219379d925bca3c315614f0616edb2548915700ad815479f9e06a4983ea6c8dc0733c23343
6
+ metadata.gz: 0ef1bea30d4ce6398a6eb0f2df942ecb26ad25f9828339b8fb3e9067c18fe07a7bb7220ddba5ae3596c313d2202dd06dabaf40cf51ec370754b69796386d72f0
7
+ data.tar.gz: 2f46d5b7386d853503abc3b95576f1fbea6fe602f5a1608e4812a7639568ee50f303f2bed11daa0632ab344b3bd717757cbc4f9aff05c3f894926fb2a2f3fc0c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.2
data/lib/dependencies.rb CHANGED
@@ -7,3 +7,4 @@ require 'logger'
7
7
  require 'mongoid'
8
8
  require 'fixturizer/version'
9
9
  require 'yaml'
10
+ require 'json'
@@ -3,30 +3,28 @@
3
3
  module Fixturizer
4
4
  module Adapters
5
5
  module Mongoid
6
- def injector(model_infos:, item:)
7
- model = Object.const_get(model_infos[:class])
8
- model.create!(item) unless model.where(model_infos[:unicity] => item[model_infos[:unicity]]).exists?
9
- end
10
-
11
- def binder(item:)
12
- result = {}
13
- item.each do |element|
14
- model_class = @models[element[:collection]][:class]
15
- model = Object.const_get(model_class)
16
- if element[:index].include?(:at)
17
- result[element[:fkey]] = model.all[element[:index][:at] - 1][element[:pkey]].to_s
18
- elsif element[:index].include?(:search_key)
19
- raise 'Links configuration failure' unless element[:index].include?(:for)
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
- generate_data
22
- inject_data
20
+ generate
21
+ inject
23
22
  true
24
23
  end
25
24
 
26
- def generate_data
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 |key|
40
- @generated[key] = generate_collection(name: key)
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 inject_data
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 = @models[name][:collection].dup
62
- data.each do |item|
63
- dataset = {}
64
- dataset[:definition] = item[:attributes]
65
- dataset[:rules] = @models[name][:rules]
66
- item[:attributes] =
67
- Fixturizer::Services.get.engine(name: :dataset, parameters: { dataset: }).generate
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
- # Fixturizer::Engines::Models::new(filename: './config/rules.yml').drop_database
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
+
@@ -12,7 +12,7 @@ module Fixturizer
12
12
  options[:to_file] = to_file
13
13
  Fixturizer::Services.get.serializer(name: format,
14
14
  parameters: {
15
- data:, options:
15
+ data: data, options: options
16
16
  }).apply
17
17
  end
18
18
  end
@@ -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
@@ -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
@@ -6,4 +6,5 @@ require_relative 'fixturizer/configuration'
6
6
  require_relative 'fixturizer/adapters/init'
7
7
  require_relative 'fixturizer/engines/init'
8
8
  require_relative 'fixturizer/serializers/init'
9
+ require_relative 'fixturizer/getters/init'
9
10
  require_relative 'fixturizer/services'
data/samples/Gemfile CHANGED
@@ -7,7 +7,7 @@ gem 'rackup', '~> 2.1'
7
7
  gem 'sinatra', '~> 4.0.0'
8
8
 
9
9
  group :test, :development do
10
- gem 'fixturizer', '~> 0.1.0'
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'
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
@@ -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: :id
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
- :links:
48
- - :collection: :posts
49
- :index:
50
- :at: 1
51
- :fkey: :post
52
- :pkey: :id
48
+ :link:
49
+ :to: :posts
50
+ :by: :comments
51
+ :search_by:
52
+ :title: First post Title
@@ -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
@@ -0,0 +1,10 @@
1
+ {
2
+ "body": "test Body",
3
+ "list": [
4
+ "one",
5
+ 2,
6
+ {
7
+ "three": 3
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,6 @@
1
+ ---
2
+ body: test Body
3
+ list:
4
+ - "one"
5
+ - 2
6
+ - {three: 3}
@@ -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.0
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-16 00:00:00.000000000 Z
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: