rubypitaya 3.14.0 → 3.15.0

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: bffdcf22b6825ba0654f97375e06f4910294b5f9690c00b7109fdaba3bf687fe
4
- data.tar.gz: 5a67d67b4094a7af3d879d0fddb7e23208d2d7bca233178112cfcff75405368a
3
+ metadata.gz: 8cbe5d3feb8670d5bf12a7fa24a1c825c05eaad6fb2f1c4146bc578098e1f85a
4
+ data.tar.gz: bb46b49c67003ce15aaa6d56e945b8fb8c4e86b14ff587dacea6bcce55e0ed31
5
5
  SHA512:
6
- metadata.gz: dddf9158f329df422d45dde7066dd3111b5da677d536f3ba25c9238571fddaced05df832728fa21495f40236f896e503307277a3f891032f03b99a6a78645d1f
7
- data.tar.gz: 88a4266ec4db9532093fac4cddbffccb84475ee37d3c245adfa44db599e10dffbe0bad5222ef76994ae26bc0228773166d5cfe8e289a7993d7cc60ed0d898156
6
+ metadata.gz: dacc15e4ff35c2697bcaf13636e5be9a61603c86c0ff9be9e53355eaf1b91266d9105ad1ee5dd7ffdfba057abb5e0670b304ca2cc34ecf7509aaae62112ac761
7
+ data.tar.gz: c9fdd57684fb5cfc34847aa41872d4df02e1bb67eac3d6220433c23ac1d8623bcdd4851cdd70dcb5c18f0c255e710d0266b56ab570bb34928eedc59029a9701c
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '3.14.0'
3
+ gem 'rubypitaya', '3.15.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.14.2'
@@ -94,7 +94,7 @@ GEM
94
94
  rspec-support (~> 3.12.0)
95
95
  rspec-support (3.12.0)
96
96
  ruby2_keywords (0.0.5)
97
- rubypitaya (3.14.0)
97
+ rubypitaya (3.15.0)
98
98
  activerecord (= 7.0.4)
99
99
  etcdv3 (= 0.11.5)
100
100
  google-protobuf (= 3.21.12)
@@ -132,7 +132,7 @@ DEPENDENCIES
132
132
  listen (= 3.8.0)
133
133
  pry (= 0.14.2)
134
134
  rspec (= 3.12.0)
135
- rubypitaya (= 3.14.0)
135
+ rubypitaya (= 3.15.0)
136
136
  sinatra-contrib (= 3.0.5)
137
137
 
138
138
  BUNDLED WITH
@@ -13,25 +13,18 @@ ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
13
13
  ActiveSupport::LogSubscriber.colorize_logging = true
14
14
 
15
15
  # Loading core files
16
- Gem.find_files('rubypitaya/**/*.rb').each do |path|
17
- require path unless path.end_with?('spec.rb') ||
18
- path.include?('app/migrations') ||
19
- path.include?('core/templates') ||
20
- path.include?('core/spec-helpers') ||
21
- path.include?('app-template')
22
- end
16
+ gem_files = Dir.glob('/app/rubypitaya/lib/rubypitaya/core/**/*.rb')
17
+ gem_files.select! {|file| !file[/.+spec.rb/] && !file[/.*(?:app\/migrations|core\/templates|core\/spec-helpers|app-template).*/]}
18
+ gem_files.each {|file| require file}
23
19
 
24
20
  # Loading application files
21
+ gem_files = []
25
22
  app_folder_paths = RubyPitaya::Path::Plugins::APP_FOLDER_PATHS + [RubyPitaya::Path::APP_FOLDER_PATH]
26
23
  app_folder_paths.each do |app_folder_path|
27
- app_files_path = File.join(app_folder_path, '**/*.rb')
28
-
29
- Dir[app_files_path].each do |path|
30
- require path unless path.end_with?('spec.rb') ||
31
- path.include?('app/migrations') ||
32
- path.include?('spec_helper.rb')
33
- end
24
+ gem_files += Dir.glob("#{app_folder_path}**/*.rb")
34
25
  end
26
+ gem_files.select! {|file| !file[/.+(?:spec.rb|spec_helper.rb)/] && !file[/.*app\/migrations.*/]}
27
+ gem_files.each {|file| require file}
35
28
 
36
29
  # Starting irb
37
30
  require 'irb'
@@ -1,11 +1,6 @@
1
- Given(/^the following User[s]?$/) do |table|
2
- table.hashes.each do |table_hash|
3
- User.create(id: table_hash[:user_id])
4
- end
5
- end
6
-
7
1
  Given(/^the User ["'](.+)["'] is authenticated$/) do |user_id|
8
- @app_helper.authenticate(user_id)
2
+ user = User.find(user_id)
3
+ @app_helper.authenticate(user.id)
9
4
  end
10
5
 
11
6
  Given(/^the setup key ["'](.+)["'] is ["'](.+)["']$/) do |key, value|
@@ -16,7 +11,7 @@ Given(/^the config key ["'](.+)["'] is ["'](.+)["']$/) do |key, value|
16
11
  @app_helper.add_config(key, value)
17
12
  end
18
13
 
19
- Given(/^the config is the following json*$/) do |config_json|
14
+ Given(/^the config is the following json$/) do |config_json|
20
15
  config = JSON.parse(config_json)
21
16
  @app_helper.set_config(config)
22
17
  end
@@ -44,28 +39,92 @@ end
44
39
  Then(/^the server response ["'](.+)["'] should be ["'](.+)["']$/) do |response_key, expected_value|
45
40
  response_value = @app_helper.response.dig(*response_key.split('.').map(&:to_sym))
46
41
 
42
+ response_value = to_string(response_value)
43
+ expected_value = to_string(expected_value)
44
+
47
45
  expect(response_value.to_s).to eq(expected_value)
48
46
  end
49
47
 
48
+ Then(/^the server response ["'](.+)["'] should not be ["'](.+)["']$/) do |response_key, expected_value|
49
+ response_value = @app_helper.response.dig(*response_key.split('.').map(&:to_sym))
50
+
51
+ response_value = to_string(response_value)
52
+ expected_value = to_string(expected_value)
53
+
54
+ expect(response_value.to_s).not_to eq(expected_value)
55
+ end
56
+
50
57
  Then(/^the server response(?: ["'](.+)["'])? should be the following json$/) do |response_key, expected_json_text|
51
- response_json = @app_helper.response
52
- response_json = @app_helper.response.dig(*response_key.split('.').map(&:to_sym)) unless response_key.blank?
58
+ response_hash = @app_helper.response
59
+ response_hash = @app_helper.response.dig(*response_key.split('.').map(&:to_sym)) unless response_key.blank?
60
+ expected_hash = JSON.parse(expected_json_text.strip)
53
61
 
54
- expected_json = JSON.parse(expected_json_text.strip, symbolize_names: true)
62
+ expected_json = JSON.generate(expected_hash)
63
+ response_json = JSON.generate(response_hash)
55
64
 
56
65
  expect(response_json).to eq(expected_json)
57
66
  end
58
67
 
59
68
  Then(/^the server response(?: ["'](.+)["'])? should contains the following json[:]?$/) do |response_key, expected_json_text|
60
- response_json = @app_helper.response
61
- response_json = @app_helper.response.dig(*response_key.split('.').map(&:to_sym)) unless response_key.blank?
69
+ response_hash = @app_helper.response
70
+ response_hash = @app_helper.response.dig(*response_key.split('.').map(&:to_sym)) unless response_key.blank?
71
+ expected_hash = JSON.parse(expected_json_text.strip, symbolize_names: true)
72
+
73
+ expected_hash = response_hash.deep_merge(expected_hash) do |key, response_value, expected_value|
74
+ next expected_value if response_value.class != Array
75
+
76
+ expect(response_value.size).to eq(expected_value.size), "Array '#{key}' doesn't have same size.\nexpected: #{expected_value.size}\n got: #{response_value.size}\n"
77
+
78
+ response_value.map.with_index do |_, i|
79
+ response_value[i].deep_merge(expected_value[i])
80
+ end
81
+ end
62
82
 
63
- expected_json = JSON.parse(expected_json_text.strip, symbolize_names: true)
64
- expected_json = response_json.deep_merge(expected_json)
83
+ expected_json = JSON.generate(expected_hash)
84
+ response_json = JSON.generate(response_hash)
65
85
 
66
86
  expect(response_json).to eq(expected_json)
67
87
  end
68
88
 
89
+ ###
90
+ # It validates a model field. Example:
91
+ #
92
+ # Given the following "Player"
93
+ # | id | name |
94
+ # | 00000000-0000-0000-0000-000000000001 | Jose |
95
+ # Then the "name" of the "Player" with "id" "00000000-0000-0000-0000-000000000001" should be "Jose"
96
+ Then(/^the ["'](.+)["'] of the ["'](.+)["'] with ["'](.+)["'] ["'](.+)["'] should be ["'](.+)["']$/) do |model_attribute, model_name, search_attribute_name, search_attribute_value, expected_value|
97
+ current_value = model_name.constantize.where(search_attribute_name => search_attribute_value).select(search_attribute_name).limit(1).pluck(model_attribute).first
98
+
99
+ current_value = to_string(current_value)
100
+ expected_value = to_string(expected_value)
101
+
102
+ expect(current_value).to eq(expected_value)
103
+ end
104
+
105
+ Then(/^the ["'](.+)["'] of the ["'](.+)["'] with ["'](.+)["'] ["'](.+)["'] should not be ["'](.+)["']$/) do |model_attribute, model_name, search_attribute_name, search_attribute_value, expected_value|
106
+ current_value = model_name.constantize.where(search_attribute_name => search_attribute_value).select(search_attribute_name).limit(1).pluck(model_attribute).first
107
+
108
+ current_value = to_string(current_value)
109
+ expected_value = to_string(expected_value)
110
+
111
+ expect(current_value).not_to eq(expected_value)
112
+ end
113
+
114
+
115
+ ###
116
+ # It count the number of models. Example
117
+ #
118
+ # Then the number of 'Users' should be 10
119
+ Then(/^the number of ["'](.+)["'] should be (\d+)$/) do |model_name, model_amount|
120
+ model_name = model_name.singularize
121
+
122
+ expected_value = model_amount
123
+ current_value = model_name.constantize.count
124
+
125
+ expect(current_value).to eq(expected_value)
126
+ end
127
+
69
128
  Given(/^print server response$/) do
70
129
  puts JSON.pretty_generate(@app_helper.response)
71
130
  end
@@ -10,4 +10,11 @@ RubyPitaya::AppSpecHelper.initialize_before_suite
10
10
 
11
11
  at_exit do
12
12
  RubyPitaya::AppSpecHelper.finalize_after_suite
13
- end
13
+ end
14
+
15
+ def to_string(value)
16
+ return value if value.class == String
17
+ return value.to_s if value.class == Integer
18
+ return 'nil' if value.nil?
19
+ value
20
+ end
@@ -11,6 +11,9 @@ module RubyPitaya
11
11
 
12
12
  @empty_hash = {}
13
13
  @result_cache = {}
14
+
15
+ @empty_hash.extend(ConfigHashExtension)
16
+ @result_cache.extend(ConfigHashExtension)
14
17
  end
15
18
 
16
19
  def [](key)
@@ -4,6 +4,8 @@ module RubyPitaya
4
4
 
5
5
  def initialize()
6
6
  @config = {}
7
+ @config.extend(ConfigHashExtension)
8
+
7
9
  configs_folder_paths = Path::Plugins::APP_CONFIG_FOLDER_PATHS + [Path::APP_CONFIG_FOLDER_PATH]
8
10
 
9
11
  configs_folder_paths.each do |configs_folder_path|
@@ -42,10 +44,11 @@ module RubyPitaya
42
44
  def load_config_file(configs_folder_path, file_path)
43
45
  config_text = File.open(file_path, &:read)
44
46
  config_hash = JSON.parse(config_text, symbolize_names: true)
47
+ config_hash.extend(ConfigHashExtension)
45
48
 
46
49
  file_name = file_path.sub(/^#{configs_folder_path}/, '')[0..-6]
47
50
 
48
- @config[file_name] = config_hash
51
+ @config[file_name.to_sym] = config_hash
49
52
 
50
53
  rescue Exception => error
51
54
  puts "ERROR: #{error}"
@@ -0,0 +1,17 @@
1
+ module RubyPitaya
2
+
3
+ module ConfigHashExtension
4
+ def [](key)
5
+ super(key.to_sym)
6
+ end
7
+
8
+ def fetch(*args)
9
+ args[0] = args[0].to_sym
10
+ super(*args)
11
+ end
12
+
13
+ def dig(*args)
14
+ super(*args.map(&:to_sym))
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '3.14.0'
2
+ VERSION = '3.15.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubypitaya
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.14.0
4
+ version: 3.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luciano Prestes Cavalcanti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-17 00:00:00.000000000 Z
11
+ date: 2023-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -330,6 +330,7 @@ files:
330
330
  - "./lib/rubypitaya/core/application_files_importer.rb"
331
331
  - "./lib/rubypitaya/core/config.rb"
332
332
  - "./lib/rubypitaya/core/config_core.rb"
333
+ - "./lib/rubypitaya/core/config_hash_extension.rb"
333
334
  - "./lib/rubypitaya/core/database_config.rb"
334
335
  - "./lib/rubypitaya/core/database_connector.rb"
335
336
  - "./lib/rubypitaya/core/etcd_connector.rb"