rubypitaya 2.8.0 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29b7ecc7e113e398e9295133b97a79f04af607848ba185db0005027af86b70c9
4
- data.tar.gz: 6ae5d8f4b78041e30bf8d362f443ce18a22bdc3fd1f909afb037622b9b4201b1
3
+ metadata.gz: f715584daee7e41961573298815c7491f05318788e930e8b0de6f414b7a587f0
4
+ data.tar.gz: 4f58032331e851a38f9eae43a15567a1442dd5833c3b6d4bea5ea2103f2d98f5
5
5
  SHA512:
6
- metadata.gz: 0a4209c6106cca1ecd8f88cb7dc6db0615c4bb3e1455d5b4319a986cb76c96a9359edd2f1189292724e64b2f8e4b38f5156854f2ba42476fa1fda9d4ae68c1b1
7
- data.tar.gz: 4fee00de34828c2810b64f4af518987c48963e5a9b48dd2e25b46accd31413b852e5f41ebcd55f989c467a342212c3f9888c07114147fee98371e18772497986
6
+ metadata.gz: 2961139116024ceb46fbedb687b62c3f6a74ea4c665516e17df9e3eac4777a4b32318d0e5e187a60f4505cdd70493222a5489b570ea7d2ea6aaec76ae60bc1f1
7
+ data.tar.gz: e428979eadc827613e1fc47e1948451d4e0af1b5c18c1eb325c5f241cf6b7ff29da013646303e73f94e7c2fd8f0a7098be8a8dec1c39667708d180eabf526508
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rubypitaya'
4
4
 
5
- COMMANDS = ['run', 'create']
5
+ COMMANDS = ['run', 'create', 'create-migration', 'add-plugin']
6
6
 
7
7
  def main
8
8
  if ARGV.size == 0 || !COMMANDS.include?(ARGV[0])
@@ -19,6 +19,14 @@ def main
19
19
  if command == 'create'
20
20
  command_create(ARGV)
21
21
  end
22
+
23
+ if command == 'create-migration'
24
+ command_create_migration(ARGV)
25
+ end
26
+
27
+ if command == 'add-plugin'
28
+ command_add_plugin(ARGV)
29
+ end
22
30
  end
23
31
 
24
32
  def command_run(argv)
@@ -40,11 +48,38 @@ def command_create(argv)
40
48
  puts "Project #{project_name} created!"
41
49
  end
42
50
 
51
+ def command_create_migration(argv)
52
+ if argv.size <= 1
53
+ show_help_create_migration()
54
+ exit(-1)
55
+ end
56
+
57
+ migration_name = argv[1]
58
+
59
+ migration_file_name = RubyPitaya::RubyPitaya.create_migration(migration_name)
60
+
61
+ puts "Migration #{migration_file_name} created!"
62
+ end
63
+
64
+ def command_add_plugin(argv)
65
+ if argv.size <= 1
66
+ show_help_add_plugin()
67
+ exit(-1)
68
+ end
69
+
70
+ plugin_git_link = argv[1]
71
+
72
+ plugin_name = RubyPitaya::RubyPitaya.add_plugin(plugin_git_link)
73
+
74
+ puts "Plugin #{plugin_name} added!"
75
+ end
76
+
43
77
  def show_help
44
78
  puts 'Usage: $ rubypitaya [COMMAND]'
45
79
  puts 'COMMAND:'
46
- puts ' run: - Run server'
47
- puts ' create: - Create project'
80
+ puts ' run: - Run server'
81
+ puts ' create: - Create project'
82
+ puts ' create-migration: - Create migration'
48
83
  puts ''
49
84
  end
50
85
 
@@ -53,4 +88,14 @@ def show_help_create
53
88
  puts ''
54
89
  end
55
90
 
91
+ def show_help_create_migration
92
+ puts 'Usage: $ rubypitaya create-migration [migration_name]'
93
+ puts ''
94
+ end
95
+
96
+ def show_help_add_plugin
97
+ puts 'Usage: $ rubypitaya create-migration [migration_name]'
98
+ puts ''
99
+ end
100
+
56
101
  main
@@ -1,3 +1,5 @@
1
+ require 'erb'
2
+ require 'ostruct'
1
3
  require 'fileutils'
2
4
 
3
5
  require 'rubypitaya/core/main'
@@ -16,5 +18,38 @@ module RubyPitaya
16
18
 
17
19
  FileUtils.cp_r app_template_path, project_path
18
20
  end
21
+
22
+ def self.create_migration(migration_name)
23
+ migration_name = "#{migration_name}_migration" unless migration_name.underscore.end_with?('migration')
24
+ migration_timestamp = Time.now.utc.to_i
25
+ migration_file_name = "#{migration_timestamp}_#{migration_name.underscore}.rb"
26
+ migration_class_name = migration_name.camelcase
27
+
28
+ template_struct = OpenStruct.new(
29
+ class_name: migration_class_name,
30
+ )
31
+
32
+ template = File.open(Path::MIGRATION_TEMPLATE_PATH, &:read)
33
+ template_result = ERB.new(template).result(template_struct.instance_eval { binding })
34
+
35
+ migration_file_path = File.join(Path::MIGRATIONS_FOLDER_PATH, migration_file_name)
36
+ File.open(migration_file_path, 'w') { |f| f.write(template_result) }
37
+
38
+ migration_file_name
39
+ end
40
+
41
+ def self.add_plugin(plugin_git_link)
42
+ Dir.mkdir(Path::PLUGINS_FOLDER_PATH) unless File.exists?(Path::PLUGINS_FOLDER_PATH)
43
+
44
+ plugin_name = plugin_git_link.scan(/.+\/(.+)\.git/).flatten.first
45
+ plugin_folder_path = File.join(Path::PLUGINS_FOLDER_PATH, plugin_name)
46
+ plugin_git_path = File.join(plugin_folder_path, '.git/')
47
+
48
+ FileUtils.rm_rf(plugin_folder_path) if File.exists?(plugin_folder_path)
49
+ `git -C #{Path::PLUGINS_FOLDER_PATH} clone #{plugin_git_link}`
50
+ FileUtils.rm_rf(plugin_git_path)
51
+
52
+ plugin_name
53
+ end
19
54
  end
20
55
  end
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.8.0'
3
+ gem 'rubypitaya', '2.10.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.12.2'
@@ -18,11 +18,11 @@ GEM
18
18
  etcdv3 (0.10.2)
19
19
  grpc (~> 1.17)
20
20
  eventmachine (1.2.7)
21
- ffi (1.13.1)
21
+ ffi (1.14.2)
22
22
  google-protobuf (3.14.0)
23
23
  googleapis-common-protos-types (1.0.5)
24
24
  google-protobuf (~> 3.11)
25
- grpc (1.32.0)
25
+ grpc (1.34.0)
26
26
  google-protobuf (~> 3.13)
27
27
  googleapis-common-protos-types (~> 1.0)
28
28
  i18n (1.8.5)
@@ -38,6 +38,7 @@ GEM
38
38
  ruby2_keywords (~> 0.0.1)
39
39
  nats (0.11.0)
40
40
  eventmachine (~> 1.2, >= 1.2)
41
+ ostruct (0.1.0)
41
42
  pg (0.21.0)
42
43
  protobuf (3.10.0)
43
44
  activesupport (>= 3.2)
@@ -69,11 +70,12 @@ GEM
69
70
  rspec-support (~> 3.8.0)
70
71
  rspec-support (3.8.3)
71
72
  ruby2_keywords (0.0.2)
72
- rubypitaya (2.8.0)
73
+ rubypitaya (2.10.0)
73
74
  activerecord (= 6.0.2)
74
75
  etcdv3 (= 0.10.2)
75
76
  eventmachine (= 1.2.7)
76
77
  nats (= 0.11.0)
78
+ ostruct (= 0.1.0)
77
79
  pg (= 0.21.0)
78
80
  protobuf (= 3.10.0)
79
81
  rake (= 10.0)
@@ -94,7 +96,7 @@ GEM
94
96
  thor (1.0.1)
95
97
  thread_safe (0.3.6)
96
98
  tilt (2.0.10)
97
- tzinfo (1.2.8)
99
+ tzinfo (1.2.9)
98
100
  thread_safe (~> 0.1)
99
101
  zeitwerk (2.4.2)
100
102
 
@@ -106,7 +108,7 @@ DEPENDENCIES
106
108
  listen (= 3.2.1)
107
109
  pry (= 0.12.2)
108
110
  rspec (= 3.8.0)
109
- rubypitaya (= 2.8.0)
111
+ rubypitaya (= 2.10.0)
110
112
 
111
113
  BUNDLED WITH
112
114
  1.17.2
@@ -4,6 +4,8 @@ KUBE_NAMESPACE ?= [put-your-namespace-here]
4
4
  KUBE_DEPLOYMENT_SERVER ?= rubypitaya
5
5
  KUBECONTEXT ?= ''
6
6
 
7
+ ## + Server Commands
8
+
7
9
  ## Run ruby pitaya metagame project
8
10
  run:
9
11
  @docker-compose run --service-ports --rm rubypitaya bundle exec rubypitaya run
@@ -12,14 +14,6 @@ run:
12
14
  build:
13
15
  @docker-compose build
14
16
 
15
- ## Kill all containers
16
- kill:
17
- @docker rm -f $$(docker-compose ps -aq)
18
-
19
- ## Run tests
20
- test:
21
- @docker-compose run --service-ports --rm rubypitaya bundle exec rspec
22
-
23
17
  ## Run ruby irb console
24
18
  console:
25
19
  @docker-compose run --service-ports --rm rubypitaya-console bundle exec ruby ./bin/console
@@ -28,6 +22,31 @@ console:
28
22
  bash:
29
23
  @docker-compose run --service-ports --rm rubypitaya bash
30
24
 
25
+ ## Run tests
26
+ test:
27
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rspec
28
+
29
+ ## Kill all containers
30
+ kill:
31
+ @docker rm -f $$(docker-compose ps -aq)
32
+
33
+ ## Update gems dependencies on Gemfile.lock
34
+ update-dependencies:
35
+ @rm -f Gemfile.lock
36
+ @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.6.6 bundle install
37
+
38
+ ## + Improve metagame
39
+
40
+ ## Create new migrgation. NAME=[migration-name]
41
+ create-migration:
42
+ @docker-compose run --service-ports --rm rubypitaya-console bundle exec rubypitaya create-migration $(NAME)
43
+
44
+ ## Add or update a plugim. GIT=[plugin-git-link]
45
+ add-plugin:
46
+ @docker-compose run --service-ports --rm rubypitaya-console bundle exec rubypitaya add-plugin $(GIT)
47
+
48
+ ## + Database Commands
49
+
31
50
  ## Create database
32
51
  db-create:
33
52
  @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:create
@@ -52,9 +71,11 @@ db-drop:
52
71
  db-reset:
53
72
  @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:reset
54
73
 
55
- ## Generate Gemfile.lock
56
- generate-gemfilelock:
57
- @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.6.6 bundle install
74
+ ## Setup test database
75
+ db-test-setup:
76
+ @docker-compose run --service-ports --rm rubypitaya bundle exec rake db:test:setup
77
+
78
+ ## + Deployment commands
58
79
 
59
80
  ## Build image to production environment
60
81
  prod-build-image:
@@ -73,7 +94,6 @@ prod-deploy-image:
73
94
  .PHONY: show-help
74
95
  show-help:
75
96
  @echo "$$(tput bold)Commands:$$(tput sgr0)"
76
- @echo
77
97
  @sed -n -e "/^## / { \
78
98
  h; \
79
99
  s/.*//; \
@@ -88,14 +108,16 @@ show-help:
88
108
  s/\\n/ /g; \
89
109
  p; \
90
110
  }" ${MAKEFILE_LIST} \
91
- | LC_ALL='C' sort --ignore-case \
92
111
  | awk -F '---' \
93
112
  -v ncol=$$(tput cols) \
94
- -v indent=22 \
113
+ -v indent=19 \
95
114
  -v col_on="$$(tput setaf 6)" \
96
115
  -v col_off="$$(tput sgr0)" \
97
116
  '{ \
98
117
  printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
118
+ if (length($$1) == 0) { \
119
+ printf "\n"; \
120
+ } \
99
121
  n = split($$2, words, " "); \
100
122
  line_length = ncol - indent; \
101
123
  for (i = 1; i <= n; i++) { \
@@ -108,3 +130,6 @@ show-help:
108
130
  } \
109
131
  printf "\n"; \
110
132
  }'
133
+
134
+
135
+
@@ -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
@@ -7,7 +7,9 @@ module MyApp
7
7
  def sayHello
8
8
  response = {
9
9
  code: 'RP-200',
10
- msg: 'Hello!'
10
+ data: {
11
+ message: 'Hello!'
12
+ }
11
13
  }
12
14
  end
13
15
  end
@@ -1,3 +1,5 @@
1
+ require 'rubypitaya/core/app/models/user'
2
+
1
3
  User.class_eval do
2
4
  # has_one :player
3
5
  end
@@ -6,18 +6,23 @@ require 'active_record'
6
6
  require 'rubypitaya'
7
7
  require 'rubypitaya/core/database_config'
8
8
 
9
+ # Database connection
9
10
  environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
10
11
  database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
11
12
  ActiveRecord::Base.establish_connection(database_config.connection_data)
12
13
  ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
13
14
  ActiveSupport::LogSubscriber.colorize_logging = true
14
15
 
16
+ # Loading core files
15
17
  Gem.find_files('rubypitaya/**/*.rb').each do |path|
16
18
  require path unless path.end_with?('spec.rb') ||
17
19
  path.include?('db/migration') ||
20
+ path.include?('core/templates') ||
21
+ path.include?('core/spec-helpers') ||
18
22
  path.include?('app-template')
19
23
  end
20
24
 
25
+ # Loading application files
21
26
  app_folder_paths = RubyPitaya::Path::Plugins::APP_FOLDER_PATHS + [RubyPitaya::Path::APP_FOLDER_PATH]
22
27
  app_folder_paths.each do |app_folder_path|
23
28
  app_files_path = File.join(app_folder_path, '**/*.rb')
@@ -28,7 +33,9 @@ app_folder_paths.each do |app_folder_path|
28
33
  end
29
34
  end
30
35
 
36
+ # Starting irb
31
37
  require 'irb'
32
38
  IRB.start(__FILE__)
33
39
 
40
+ # Closing database connection
34
41
  ActiveRecord::Base.connection.close
@@ -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
@@ -2,6 +2,7 @@ module RubyPitaya
2
2
 
3
3
  class Path
4
4
  APP_TEMPLATE_FOLDER_PATH = File.join(__dir__, '../app-template/')
5
+ MIGRATION_TEMPLATE_PATH = File.join(__dir__, 'templates/template_migration.rb.erb')
5
6
 
6
7
  DATABASE_CONFIG_PATH = File.join(Dir.pwd, 'config/database.yml')
7
8
 
@@ -10,11 +11,13 @@ module RubyPitaya
10
11
  APP_CONFIG_FOLDER_PATH = File.join(Dir.pwd, 'app/config/')
11
12
  APP_SETUP_FOLDER_PATH = File.join(Dir.pwd, 'app/setup/')
12
13
  MIGRATIONS_FOLDER_PATH = File.join(Dir.pwd, 'db/migration/')
14
+ PLUGINS_FOLDER_PATH = File.join(Dir.pwd, 'plugins/')
13
15
 
14
16
  ROUTES_FILE_PATH = File.join(Dir.pwd, 'config/routes.rb')
15
17
 
16
18
  HTTP_VIEWS_PATH = File.join(Dir.pwd, 'app/http/views')
17
19
 
20
+
18
21
  class Core
19
22
  APP_FOLDER_PATH = File.join(__dir__, 'app/')
20
23
  MIGRATIONS_FOLDER_PATH = File.join(__dir__, 'db/migration/')
@@ -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
@@ -0,0 +1,13 @@
1
+ require 'active_record'
2
+
3
+ class <%= class_name %> < ActiveRecord::Migration[5.1]
4
+
5
+ enable_extension 'pgcrypto'
6
+
7
+ def change
8
+ create_table :[table-name-here-in-plural], id: :uuid do |t|
9
+ # t.belongs_to :user, type: :uuid
10
+ t.timestamps null: false
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyPitaya
2
- VERSION = '2.8.0'
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.8.0
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-10 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
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: ostruct
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: sinatra-contrib
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -260,6 +274,8 @@ files:
260
274
  - "./lib/rubypitaya/app-template/kubernetes/statefulset-nats.yaml"
261
275
  - "./lib/rubypitaya/app-template/kubernetes/statefulset-postgres.yaml"
262
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"
263
279
  - "./lib/rubypitaya/core/app/models/user.rb"
264
280
  - "./lib/rubypitaya/core/application_files_importer.rb"
265
281
  - "./lib/rubypitaya/core/config.rb"
@@ -284,7 +300,13 @@ files:
284
300
  - "./lib/rubypitaya/core/routes_base.rb"
285
301
  - "./lib/rubypitaya/core/session.rb"
286
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"
287
308
  - "./lib/rubypitaya/core/status_codes.rb"
309
+ - "./lib/rubypitaya/core/templates/template_migration.rb.erb"
288
310
  - "./lib/rubypitaya/version.rb"
289
311
  - bin/rubypitaya
290
312
  homepage: https://gitlab.com/LucianoPC/ruby-pitaya