rubypitaya 2.9.3 → 2.10.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: ea061a423e6810b67f1a1256c58ca9f37b1f0494abe0808f999a3b1b4db2a955
4
- data.tar.gz: ca8eb926d63d2331911e835c9d06e167092dea7be8f5e7433530ae50a9bea674
3
+ metadata.gz: f715584daee7e41961573298815c7491f05318788e930e8b0de6f414b7a587f0
4
+ data.tar.gz: 4f58032331e851a38f9eae43a15567a1442dd5833c3b6d4bea5ea2103f2d98f5
5
5
  SHA512:
6
- metadata.gz: 72ca0233433069c86b70fb0235bb7dcd47441cac23bf994019456f16a130b60e0f6801ed4d1fe1c3bfa12cce4c6f3bab7821fe49fd4167bef2f6a11a5bc62f8c
7
- data.tar.gz: 77a113fb20486be58a6403c421553955dd8e451f76d2ae4ab788f4ffeefb04d10a99f9e7f72a9d3a5eb00e484076d226008afa5365068c4a9a87e80f279efd7d
6
+ metadata.gz: 2961139116024ceb46fbedb687b62c3f6a74ea4c665516e17df9e3eac4777a4b32318d0e5e187a60f4505cdd70493222a5489b570ea7d2ea6aaec76ae60bc1f1
7
+ data.tar.gz: e428979eadc827613e1fc47e1948451d4e0af1b5c18c1eb325c5f241cf6b7ff29da013646303e73f94e7c2fd8f0a7098be8a8dec1c39667708d180eabf526508
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.9.3'
3
+ gem 'rubypitaya', '2.10.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.12.2'
@@ -70,7 +70,7 @@ GEM
70
70
  rspec-support (~> 3.8.0)
71
71
  rspec-support (3.8.3)
72
72
  ruby2_keywords (0.0.2)
73
- rubypitaya (2.9.3)
73
+ rubypitaya (2.10.0)
74
74
  activerecord (= 6.0.2)
75
75
  etcdv3 (= 0.10.2)
76
76
  eventmachine (= 1.2.7)
@@ -108,7 +108,7 @@ DEPENDENCIES
108
108
  listen (= 3.2.1)
109
109
  pry (= 0.12.2)
110
110
  rspec (= 3.8.0)
111
- rubypitaya (= 2.9.3)
111
+ rubypitaya (= 2.10.0)
112
112
 
113
113
  BUNDLED WITH
114
114
  1.17.2
@@ -71,6 +71,10 @@ db-drop:
71
71
  db-reset:
72
72
  @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:reset
73
73
 
74
+ ## Setup test database
75
+ db-test-setup:
76
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:test:setup
77
+
74
78
  ## + Deployment commands
75
79
 
76
80
  ## Build image to production environment
@@ -16,7 +16,7 @@ namespace :db do
16
16
  ActiveRecord::Base.connection.create_database(database_config.database_name)
17
17
  ActiveRecord::Base.connection.close
18
18
 
19
- puts 'Database created.'
19
+ puts "Database #{database_config.database_name} created."
20
20
  end
21
21
 
22
22
  desc 'Migrate the database'
@@ -32,7 +32,8 @@ namespace :db do
32
32
  ActiveRecord::Migrator.migrations_paths = migrations_paths
33
33
  ActiveRecord::Tasks::DatabaseTasks.migrate
34
34
  ActiveRecord::Base.connection.close
35
- puts 'Database migrated.'
35
+
36
+ puts "Database #{database_config.database_name} migrated."
36
37
  end
37
38
 
38
39
  desc 'Rollback migrations'
@@ -72,7 +73,7 @@ namespace :db do
72
73
  ActiveRecord::Base.connection.drop_database(database_config.database_name)
73
74
  ActiveRecord::Base.connection.close
74
75
 
75
- puts 'Database deleted.'
76
+ puts "Database #{database_config.database_name} deleted."
76
77
  end
77
78
 
78
79
  desc 'migration status'
@@ -90,8 +91,6 @@ namespace :db do
90
91
  puts "#{status.center(8)} #{version.ljust(14)} #{name}"
91
92
  end
92
93
  ActiveRecord::Base.connection.close
93
-
94
- puts 'Rollback done.'
95
94
  end
96
95
 
97
96
  desc 'Reset the database'
@@ -102,4 +101,17 @@ namespace :db do
102
101
 
103
102
  puts 'Database reset finish.'
104
103
  end
104
+
105
+ namespace :test do
106
+ desc 'Setup test database'
107
+ task :setup do
108
+ ENV['RUBYPITAYA_ENV'] = 'test'
109
+
110
+ Rake::Task['db:drop'].invoke
111
+ Rake::Task['db:create'].invoke
112
+ Rake::Task['db:migrate'].invoke
113
+
114
+ puts 'Database reset finish.'
115
+ end
116
+ end
105
117
  end
@@ -18,6 +18,7 @@ Gem.find_files('rubypitaya/**/*.rb').each do |path|
18
18
  require path unless path.end_with?('spec.rb') ||
19
19
  path.include?('db/migration') ||
20
20
  path.include?('core/templates') ||
21
+ path.include?('core/spec-helpers') ||
21
22
  path.include?('app-template')
22
23
  end
23
24
 
@@ -0,0 +1,19 @@
1
+ require 'rubypitaya/core/spec-helpers/rubypitaya_spec_helper'
2
+
3
+ module MyApp
4
+
5
+ RSpec.describe 'HelloWorldHandler', type: :request do
6
+ context 'sayHello' do
7
+ it 'success' do
8
+ request("rubypitaya.helloWorldHandler.sayHello")
9
+
10
+ expected_response = {
11
+ code: 'RP-200',
12
+ data: { message: 'Hello!' }
13
+ }
14
+
15
+ expect(response).to eq(expected_response)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,50 @@
1
+ require 'rubypitaya/core/spec-helpers/rubypitaya_spec_helper'
2
+
3
+ module MyApp
4
+
5
+ RSpec.describe 'PlayerHandler', type: :request do
6
+ context 'authenticate' do
7
+ it 'create_new_user' do
8
+ setup = {'initial_player.wallet.gold' => 10}
9
+ config = {'initial_player' => {'name' => 'Guest'}}
10
+
11
+ set_setup(setup)
12
+ set_config(config)
13
+
14
+ params = {}
15
+ request("rubypitaya.playerHandler.authenticate", params)
16
+
17
+ player = ::MyApp::Player.last
18
+
19
+ expect(response[:code]).to eq('RP-200')
20
+ expect(response[:data][:name]).to eq('Guest')
21
+ expect(response[:data][:gold]).to eq(10)
22
+
23
+ expect(::User.count).to eq(1)
24
+ expect(::MyApp::Player.count).to eq(1)
25
+ expect(player.name).to eq('Guest')
26
+ expect(player.gold).to eq(10)
27
+ end
28
+ end
29
+
30
+ context 'getInfo' do
31
+ it 'success' do
32
+ player = ::MyApp::Player.create(name: 'Someone', gold: 12, user: User.new)
33
+
34
+ authenticate(player.user_id)
35
+
36
+ request("rubypitaya.playerHandler.getInfo")
37
+
38
+ expect(response[:code]).to eq('RP-200')
39
+ expect(response[:data]).to eq(player.to_hash)
40
+ end
41
+
42
+ it 'error_not_authenticated' do
43
+ request("rubypitaya.playerHandler.getInfo")
44
+
45
+ expect(response[:code]).to eq(RubyPitaya::StatusCodes::CODE_NOT_AUTHENTICATED)
46
+ expect(response[:msg]).to eq('Not authenticated')
47
+ end
48
+ end
49
+ end
50
+ end
@@ -24,11 +24,6 @@ module RubyPitaya
24
24
  @config.dig(*split_key)
25
25
  end
26
26
 
27
- def get_config_from_env_var(key)
28
- env_key = key.gsub('.', '_').upcase
29
- ENV.fetch(env_key) { nil }
30
- end
31
-
32
27
  def auto_reload
33
28
  require 'listen'
34
29
 
@@ -48,6 +43,11 @@ module RubyPitaya
48
43
 
49
44
  private
50
45
 
46
+ def get_config_from_env_var(key)
47
+ env_key = key.gsub('.', '_').upcase
48
+ ENV.fetch(env_key) { nil }
49
+ end
50
+
51
51
  def load_config_file(configs_folder_path, file_path)
52
52
  config_text = File.open(file_path, &:read)
53
53
  config_hash = YAML.load(ERB.new(config_text).result)
@@ -0,0 +1,24 @@
1
+ module RubyPitaya
2
+
3
+ class ConfigSpecHelper
4
+
5
+ def initialize
6
+ @config_mock = {}
7
+ end
8
+
9
+ def [](key)
10
+ @config_mock[key]
11
+ end
12
+
13
+ def auto_reload
14
+ end
15
+
16
+ def config_mock=(value)
17
+ @config_mock = value
18
+ end
19
+
20
+ def config_core_override=(value)
21
+ config_mock = value
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,79 @@
1
+ require 'rubypitaya/core/handler_router'
2
+ require 'rubypitaya/core/redis_connector'
3
+ require 'rubypitaya/core/spec-helpers/setup_spec_helper'
4
+ require 'rubypitaya/core/spec-helpers/config_spec_helper'
5
+ require 'rubypitaya/core/spec-helpers/postman_spec_helper'
6
+
7
+ module RubyPitaya
8
+
9
+ module HandlerSpecHelper
10
+
11
+ def initialize(context)
12
+ @@context = context
13
+
14
+ @@bll = InstanceHolder.new
15
+ @@log = Logger.new('/dev/null')
16
+ @@setup = SetupSpecHelper.new
17
+ @@config = ConfigSpecHelper.new
18
+ @@session = Session.new
19
+ @@postman = PostmanSpecHelper.new
20
+
21
+ @@response = {}
22
+
23
+ initialize_redis
24
+
25
+ @@handler_router ||= HandlerRouter.new()
26
+
27
+
28
+ @@initializer_content = InitializerContent.new(@@bll,
29
+ @@log,
30
+ @@redis_connector.redis,
31
+ @@setup,
32
+ @@config)
33
+ @@initializer_broadcast = InitializerBroadcast.new
34
+ @@initializer_broadcast.run(@@initializer_content)
35
+ end
36
+
37
+ def request(route, params = {})
38
+ handler_name, action_name = route.split('.')[1..-1]
39
+
40
+ @@response = @@handler_router.call(handler_name, action_name, @@session,
41
+ @@postman, @@redis_connector.redis,
42
+ @@setup, @@config, @@bll, @@log, params)
43
+ end
44
+
45
+ def response
46
+ @@response
47
+ end
48
+
49
+ def authenticate(user_id)
50
+ @@session.uid = user_id
51
+ end
52
+
53
+ def set_config(config)
54
+ @@config.config_mock = config
55
+ end
56
+
57
+ def set_setup(setup)
58
+ @@setup.setup_mock = setup
59
+ end
60
+
61
+ def set_postman(postman)
62
+ @@postman.postman_mock = postman
63
+ end
64
+
65
+ private
66
+
67
+ def initialize_redis
68
+ @@redis_connector ||= nil
69
+
70
+ if @@redis_connector.nil?
71
+ redis_address = ENV['REDIS_URL']
72
+ @@redis_connector = RedisConnector.new(redis_address)
73
+ @@redis_connector.connect
74
+ end
75
+
76
+ @@redis_connector.redis.flushall
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,21 @@
1
+ module RubyPitaya
2
+
3
+ class PostmanSpecHelper
4
+
5
+ def initialize
6
+ @postman_mock = nil
7
+ end
8
+
9
+ def bind_session(session)
10
+ response = @postman_mock&.bind_session(session)
11
+ response ||= {}
12
+ response
13
+ end
14
+
15
+ def push_to_user(uid, message_route, payload)
16
+ response = @postman_mock&.push_to_user(uid, message_route, payload)
17
+ response ||= {}
18
+ response
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ require 'rspec'
2
+ require 'active_record'
3
+
4
+ require 'rubypitaya/core/database_config'
5
+ require 'rubypitaya/core/spec-helpers/handler_spec_helper'
6
+
7
+ ENV['RUBYPITAYA_ENV'] = 'test'
8
+
9
+ # Database connection
10
+ environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
11
+ database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
12
+ ActiveRecord::Base.establish_connection(database_config.connection_data)
13
+ # ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
14
+ # ActiveSupport::LogSubscriber.colorize_logging = true
15
+
16
+ connection_data = database_config.connection_data
17
+ migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
18
+ migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
19
+ migrations_paths += [RubyPitaya::Path::MIGRATIONS_FOLDER_PATH]
20
+ ActiveRecord::Migrator.migrations_paths = migrations_paths
21
+ ActiveRecord::Migration.maintain_test_schema!
22
+
23
+ # Loading core files
24
+ Gem.find_files('rubypitaya/**/*.rb').each do |path|
25
+ require path unless path.end_with?('spec.rb') ||
26
+ path.include?('db/migration') ||
27
+ path.include?('core/templates') ||
28
+ path.include?('core/spec-helpers') ||
29
+ path.include?('app-template')
30
+ end
31
+
32
+ # Loading application files
33
+ app_folder_paths = RubyPitaya::Path::Plugins::APP_FOLDER_PATHS + [RubyPitaya::Path::APP_FOLDER_PATH]
34
+ app_folder_paths.each do |app_folder_path|
35
+ app_files_path = File.join(app_folder_path, '**/*.rb')
36
+
37
+ Dir[app_files_path].each do |path|
38
+ require path unless path.end_with?('spec.rb') ||
39
+ path.include?('db/migration')
40
+ end
41
+ end
42
+
43
+ RSpec.configure do |config|
44
+ config.include RubyPitaya::HandlerSpecHelper
45
+
46
+ config.before(:each) do
47
+ ActiveRecord::Base.descendants.each { |c| c.delete_all unless c == ActiveRecord::SchemaMigration }
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ module RubyPitaya
2
+
3
+ class SetupSpecHelper
4
+
5
+ def initialize
6
+ @setup_mock = {}
7
+ end
8
+
9
+ def [](key)
10
+ @setup_mock[key]
11
+ end
12
+
13
+ def auto_reload
14
+ end
15
+
16
+ def setup_mock=(value)
17
+ @setup_mock = value
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '2.9.3'
2
+ VERSION = '2.10.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: 2.9.3
4
+ version: 2.10.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: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -274,6 +274,8 @@ files:
274
274
  - "./lib/rubypitaya/app-template/kubernetes/statefulset-nats.yaml"
275
275
  - "./lib/rubypitaya/app-template/kubernetes/statefulset-postgres.yaml"
276
276
  - "./lib/rubypitaya/app-template/kubernetes/statefulset-redis.yaml"
277
+ - "./lib/rubypitaya/app-template/spec/hello_world_handler_spec.rb"
278
+ - "./lib/rubypitaya/app-template/spec/player_handler_spec.rb"
277
279
  - "./lib/rubypitaya/core/app/models/user.rb"
278
280
  - "./lib/rubypitaya/core/application_files_importer.rb"
279
281
  - "./lib/rubypitaya/core/config.rb"
@@ -298,6 +300,11 @@ files:
298
300
  - "./lib/rubypitaya/core/routes_base.rb"
299
301
  - "./lib/rubypitaya/core/session.rb"
300
302
  - "./lib/rubypitaya/core/setup.rb"
303
+ - "./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb"
304
+ - "./lib/rubypitaya/core/spec-helpers/handler_spec_helper.rb"
305
+ - "./lib/rubypitaya/core/spec-helpers/postman_spec_helper.rb"
306
+ - "./lib/rubypitaya/core/spec-helpers/rubypitaya_spec_helper.rb"
307
+ - "./lib/rubypitaya/core/spec-helpers/setup_spec_helper.rb"
301
308
  - "./lib/rubypitaya/core/status_codes.rb"
302
309
  - "./lib/rubypitaya/core/templates/template_migration.rb.erb"
303
310
  - "./lib/rubypitaya/version.rb"