rubypitaya 2.11.2 → 2.14.1
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 +4 -4
- data/bin/rubypitaya +1 -1
- data/lib/rubypitaya.rb +11 -0
- data/lib/rubypitaya/app-template/.gitlab-ci.yml +0 -1
- data/lib/rubypitaya/app-template/Gemfile +1 -1
- data/lib/rubypitaya/app-template/Gemfile.lock +2 -2
- data/lib/rubypitaya/app-template/Makefile +9 -9
- data/lib/rubypitaya/app-template/app/app_initializer.rb +39 -42
- data/lib/rubypitaya/app-template/app/bll/player_bll.rb +7 -10
- data/lib/rubypitaya/app-template/app/constants/status_codes.rb +19 -22
- data/lib/rubypitaya/app-template/app/handlers/hello_world_handler.rb +9 -12
- data/lib/rubypitaya/app-template/app/handlers/player_handler.rb +65 -68
- data/lib/rubypitaya/app-template/app/models/player.rb +9 -12
- data/lib/rubypitaya/app-template/config/routes.rb +1 -1
- data/lib/rubypitaya/app-template/docker-compose.yml +6 -0
- data/lib/rubypitaya/app-template/features/player.feature +5 -5
- data/lib/rubypitaya/app-template/features/step_definitions/application_steps.rb +2 -2
- data/lib/rubypitaya/app-template/features/step_definitions/rubypitaya_steps.rb +23 -9
- data/lib/rubypitaya/app-template/features/support/env.rb +7 -0
- data/lib/rubypitaya/app-template/spec/hello_world_handler_spec.rb +9 -12
- data/lib/rubypitaya/app-template/spec/player_handler_spec.rb +30 -33
- data/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb +0 -1
- data/lib/rubypitaya/core/spec-helpers/handler_spec_helper.rb +20 -0
- data/lib/rubypitaya/core/templates/template_migration.rb.erb +1 -1
- data/lib/rubypitaya/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6e77cbe864f72313b664b1bc09412eb1a4e72e585783c9926cb81f904e4fa1b
|
4
|
+
data.tar.gz: 1e1aa371b0ef4c57f19612b30706f154783ff4a3ad9c20d45571aedc03041e20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b930dcb7634a04e77424b0452580651af68127c63e326cd1917f6bed4ad39140bc7ae484f50a13e223bb994f23ef33a559fa6b2a6907d8031d589b7918ab4016
|
7
|
+
data.tar.gz: 711ae4f8291d2916111abaa5c82fe99e31901d731e38eece1a50627e2769054f06c63a44ca24c5b433bfdd3df5419629a2d4bfa3ceb101a8b9a9d435eb874034
|
data/bin/rubypitaya
CHANGED
data/lib/rubypitaya.rb
CHANGED
@@ -49,6 +49,17 @@ module RubyPitaya
|
|
49
49
|
`git -C #{Path::PLUGINS_FOLDER_PATH} clone #{plugin_git_link}`
|
50
50
|
FileUtils.rm_rf(plugin_git_path)
|
51
51
|
|
52
|
+
plugin_migrations_path = File.join(plugin_folder_path, 'db/migration/')
|
53
|
+
plugin_migrations_files = Dir[File.join(plugin_migrations_path, '*')]
|
54
|
+
base_migration_timestamp = Time.now.utc.to_i
|
55
|
+
|
56
|
+
plugin_migrations_files.each_with_index do |migration_file, i|
|
57
|
+
migration_timestamp = base_migration_timestamp + i
|
58
|
+
new_file = migration_file.gsub(/^(.+\/migration\/)\d+(_.+)$/, "\\1#{migration_timestamp}\\2")
|
59
|
+
|
60
|
+
File.rename(migration_file, new_file)
|
61
|
+
end
|
62
|
+
|
52
63
|
plugin_name
|
53
64
|
end
|
54
65
|
end
|
@@ -84,7 +84,7 @@ GEM
|
|
84
84
|
rspec-support (~> 3.8.0)
|
85
85
|
rspec-support (3.8.3)
|
86
86
|
ruby2_keywords (0.0.2)
|
87
|
-
rubypitaya (2.
|
87
|
+
rubypitaya (2.14.1)
|
88
88
|
activerecord (= 6.0.2)
|
89
89
|
etcdv3 (= 0.10.2)
|
90
90
|
eventmachine (= 1.2.7)
|
@@ -123,7 +123,7 @@ DEPENDENCIES
|
|
123
123
|
listen (= 3.2.1)
|
124
124
|
pry (= 0.12.2)
|
125
125
|
rspec (= 3.8.0)
|
126
|
-
rubypitaya (= 2.
|
126
|
+
rubypitaya (= 2.14.1)
|
127
127
|
|
128
128
|
BUNDLED WITH
|
129
129
|
1.17.2
|
@@ -47,41 +47,41 @@ update-dependencies:
|
|
47
47
|
|
48
48
|
## Create new migrgation. NAME=[migration-name]
|
49
49
|
create-migration:
|
50
|
-
@docker-compose run --service-ports --rm rubypitaya-
|
50
|
+
@docker-compose run --service-ports --rm rubypitaya-commands bundle exec rubypitaya create-migration $(NAME)
|
51
51
|
|
52
52
|
## Add or update a plugim. GIT=[plugin-git-link]
|
53
53
|
add-plugin:
|
54
|
-
@docker-compose run --service-ports --rm rubypitaya-
|
54
|
+
@docker-compose run --service-ports --rm rubypitaya-commands bundle exec rubypitaya add-plugin $(GIT)
|
55
55
|
|
56
56
|
## + Database Commands
|
57
57
|
|
58
58
|
## Create database
|
59
59
|
db-create:
|
60
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:create
|
60
|
+
@docker-compose run --service-ports --rm rubypitaya-commands bundle exec rake db:create
|
61
61
|
|
62
62
|
## Run migrations to database
|
63
63
|
db-migrate:
|
64
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:migrate
|
64
|
+
@docker-compose run --service-ports --rm rubypitaya-commands bundle exec rake db:migrate
|
65
65
|
|
66
66
|
## Show migrations status on database
|
67
67
|
db-migrate-status:
|
68
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:status
|
68
|
+
@docker-compose run --service-ports --rm rubypitaya-commands bundle exec rake db:status
|
69
69
|
|
70
70
|
## Rollback migrations STEP=1
|
71
71
|
db-rollback:
|
72
|
-
@docker-compose run --service-ports --rm -e STEP="$(STEP)" rubypitaya bundle exec rake db:rollback
|
72
|
+
@docker-compose run --service-ports --rm -e STEP="$(STEP)" rubypitaya-commands bundle exec rake db:rollback
|
73
73
|
|
74
74
|
## Drop database
|
75
75
|
db-drop:
|
76
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:drop
|
76
|
+
@docker-compose run --service-ports --rm rubypitaya-commands bundle exec rake db:drop
|
77
77
|
|
78
78
|
## Reset database
|
79
79
|
db-reset:
|
80
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:reset
|
80
|
+
@docker-compose run --service-ports --rm rubypitaya-commands bundle exec rake db:reset
|
81
81
|
|
82
82
|
## Setup test database
|
83
83
|
db-test-setup:
|
84
|
-
@docker-compose run --service-ports --rm rubypitaya bundle exec rake db:test:setup
|
84
|
+
@docker-compose run --service-ports --rm rubypitaya-commands bundle exec rake db:test:setup
|
85
85
|
|
86
86
|
## + Deployment commands
|
87
87
|
|
@@ -1,49 +1,46 @@
|
|
1
|
-
|
1
|
+
class AppInitializer < RubyPitaya::InitializerBase
|
2
2
|
|
3
|
-
|
3
|
+
# method: run
|
4
|
+
# parameter: initializer_content
|
5
|
+
# attributes:
|
6
|
+
# - bll
|
7
|
+
# - class: RubyPitaya::InstanceHolder
|
8
|
+
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/instance_holder.rb
|
9
|
+
# - methods:
|
10
|
+
# - add_instance(key, instance)
|
11
|
+
# - add any instance to any key
|
12
|
+
# - [](key)
|
13
|
+
# - get instance by key
|
14
|
+
# - redis
|
15
|
+
# - link: https://github.com/redis/redis-rb/
|
16
|
+
# - config
|
17
|
+
# - class: RubyPitaya::Config
|
18
|
+
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/config.rb
|
19
|
+
# - methods:
|
20
|
+
# - [](key)
|
21
|
+
# - get config file by config path
|
22
|
+
# - setup
|
23
|
+
# - class: RubyPitaya::Setup
|
24
|
+
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/setup.rb
|
25
|
+
# - methods:
|
26
|
+
# - [](key)
|
27
|
+
# - get config file by config path
|
28
|
+
# - log
|
29
|
+
# - class: Logger
|
30
|
+
# - link: https://ruby-doc.org/stdlib-2.6.4/libdoc/logger/rdoc/Logger.html
|
31
|
+
# - methods:
|
32
|
+
# - info
|
33
|
+
# - log information
|
4
34
|
|
5
|
-
|
6
|
-
|
7
|
-
# attributes:
|
8
|
-
# - bll
|
9
|
-
# - class: RubyPitaya::InstanceHolder
|
10
|
-
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/instance_holder.rb
|
11
|
-
# - methods:
|
12
|
-
# - add_instance(key, instance)
|
13
|
-
# - add any instance to any key
|
14
|
-
# - [](key)
|
15
|
-
# - get instance by key
|
16
|
-
# - redis
|
17
|
-
# - link: https://github.com/redis/redis-rb/
|
18
|
-
# - config
|
19
|
-
# - class: RubyPitaya::Config
|
20
|
-
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/config.rb
|
21
|
-
# - methods:
|
22
|
-
# - [](key)
|
23
|
-
# - get config file by config path
|
24
|
-
# - setup
|
25
|
-
# - class: RubyPitaya::Setup
|
26
|
-
# - link: https://gitlab.com/LucianoPC/ruby-pitaya/-/blob/master/lib/rubypitaya/core/setup.rb
|
27
|
-
# - methods:
|
28
|
-
# - [](key)
|
29
|
-
# - get config file by config path
|
30
|
-
# - log
|
31
|
-
# - class: Logger
|
32
|
-
# - link: https://ruby-doc.org/stdlib-2.6.4/libdoc/logger/rdoc/Logger.html
|
33
|
-
# - methods:
|
34
|
-
# - info
|
35
|
-
# - log information
|
35
|
+
def run(initializer_content)
|
36
|
+
bll = initializer_content.bll
|
36
37
|
|
37
|
-
|
38
|
-
bll = initializer_content.bll
|
38
|
+
playerBll = PlayerBLL.new
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
bll.add_instance(:player, playerBll)
|
43
|
-
end
|
40
|
+
bll.add_instance(:player, playerBll)
|
41
|
+
end
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
43
|
+
def self.path
|
44
|
+
__FILE__
|
48
45
|
end
|
49
46
|
end
|
@@ -1,14 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class PlayerBLL
|
1
|
+
class PlayerBLL
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
def create_new_player(setup, config)
|
4
|
+
name = config['initial_player']['name']
|
5
|
+
gold = setup['initial_player.wallet.gold']
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
7
|
+
player = Player.new(name: name, gold: gold, user: User.new)
|
8
|
+
player.save
|
9
|
+
player
|
13
10
|
end
|
14
11
|
end
|
@@ -1,25 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class StatusCodes
|
1
|
+
class StatusCodes
|
4
2
|
|
5
|
-
|
3
|
+
CODE_OK = RubyPitaya::StatusCodes::CODE_OK
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
5
|
+
################
|
6
|
+
## Existent Codes
|
7
|
+
################
|
8
|
+
## Success codes
|
9
|
+
#
|
10
|
+
# RubyPitaya::StatusCodes::CODE_OK = 'RP-200'
|
11
|
+
#
|
12
|
+
#
|
13
|
+
## Error codes
|
14
|
+
# RubyPitaya::StatusCodes::CODE_UNKNOWN = 'RP-000'
|
15
|
+
# RubyPitaya::StatusCodes::CODE_HANDLER_NOT_FOUND = 'RP-001'
|
16
|
+
# RubyPitaya::StatusCodes::CODE_ACTION_NOT_FOUND = 'RP-002'
|
17
|
+
# RubyPitaya::StatusCodes::CODE_NOT_AUTHENTICATED = 'RP-003'
|
18
|
+
# RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR = 'RP-004'
|
19
|
+
#
|
20
|
+
# RubyPitaya::StatusCodes::Connector::CODE_UNKNOWN = 'PIT-000'
|
21
|
+
################
|
25
22
|
end
|
@@ -1,16 +1,13 @@
|
|
1
|
-
|
1
|
+
class HelloWorldHandler < RubyPitaya::HandlerBase
|
2
2
|
|
3
|
-
|
3
|
+
non_authenticated_actions :sayHello
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
data: {
|
11
|
-
message: 'Hello!'
|
12
|
-
}
|
5
|
+
def sayHello
|
6
|
+
response = {
|
7
|
+
code: 'RP-200',
|
8
|
+
data: {
|
9
|
+
message: 'Hello!'
|
13
10
|
}
|
14
|
-
|
11
|
+
}
|
15
12
|
end
|
16
|
-
end
|
13
|
+
end
|
@@ -1,82 +1,79 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class PlayerHandler < RubyPitaya::HandlerBase
|
1
|
+
class PlayerHandler < RubyPitaya::HandlerBase
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
3
|
+
# class: HandlerBase
|
4
|
+
# attributes:
|
5
|
+
# - @bll
|
6
|
+
# - class: InstanceHolder
|
7
|
+
# - methods:
|
8
|
+
# - [](key)
|
9
|
+
# - info: get bll by key
|
10
|
+
#
|
11
|
+
# - @redis
|
12
|
+
# - link: https://github.com/redis/redis-rb/
|
13
|
+
#
|
14
|
+
# - @config
|
15
|
+
# - info: Hash with config json files inside of 'app/config'
|
16
|
+
# - example:
|
17
|
+
# Given you have the following file "app/config/initial_player.json"
|
18
|
+
# And this json content is {'name': 'Guest'}
|
19
|
+
# And you can get the initial player name
|
20
|
+
# Then you can run the following code: @config['initial_player']['name']
|
21
|
+
#
|
22
|
+
# - @params
|
23
|
+
# - info: Special hash with the request parameters
|
24
|
+
# - link: https://api.rubyonrails.org/classes/ActionController/Parameters.html
|
25
|
+
#
|
26
|
+
# - @session
|
27
|
+
# - attributes:
|
28
|
+
# - id :: session id
|
29
|
+
# - uid :: user id
|
30
|
+
# - data :: session data
|
31
|
+
# - metadata :: session data
|
32
|
+
# - frontend_id :: connector server id
|
33
|
+
#
|
34
|
+
# - @postman
|
35
|
+
# - info: Send messages to server and clients
|
36
|
+
# - methods:
|
37
|
+
# - bind_session(session)
|
38
|
+
# - info:
|
39
|
+
# Send a session to connector, you can use to set the userId
|
40
|
+
# of the session, for example you can set an userId on
|
41
|
+
# @session, like `@session.uid = '123'`, and then you can
|
42
|
+
# bind this session with `@postman.bind_session(@session)`
|
45
43
|
|
46
|
-
|
44
|
+
non_authenticated_actions :authenticate
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
def authenticate
|
47
|
+
user_id = @params[:userId]
|
50
48
|
|
51
|
-
|
52
|
-
|
49
|
+
player = Player.find_by_user_id(user_id)
|
50
|
+
player = @bll[:player].create_new_player(@setup, @config) if player.nil?
|
53
51
|
|
54
|
-
|
52
|
+
@session.uid = player.user_id
|
55
53
|
|
56
|
-
|
54
|
+
bind_session_response = @postman.bind_session(@session)
|
57
55
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
response = {
|
66
|
-
code: StatusCodes::CODE_OK,
|
67
|
-
data: player.to_hash,
|
56
|
+
unless bind_session_response.dig(:error, :code).nil?
|
57
|
+
return response = {
|
58
|
+
code: RubyPitaya::StatusCodes::CODE_AUTHENTICATION_ERROR,
|
59
|
+
msg: 'Error to authenticate',
|
68
60
|
}
|
69
61
|
end
|
70
62
|
|
71
|
-
|
72
|
-
|
63
|
+
response = {
|
64
|
+
code: StatusCodes::CODE_OK,
|
65
|
+
data: player.to_hash,
|
66
|
+
}
|
67
|
+
end
|
73
68
|
|
74
|
-
|
69
|
+
def getInfo
|
70
|
+
user_id = @session.uid
|
75
71
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
player = Player.find_by_user_id(user_id)
|
73
|
+
|
74
|
+
response = {
|
75
|
+
code: StatusCodes::CODE_OK,
|
76
|
+
data: player.to_hash,
|
77
|
+
}
|
81
78
|
end
|
82
79
|
end
|
@@ -1,19 +1,16 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
|
-
|
3
|
+
class Player < ActiveRecord::Base
|
4
4
|
|
5
|
-
|
5
|
+
belongs_to :user
|
6
6
|
|
7
|
-
|
7
|
+
validates_presence_of :name, :gold, :user
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
userId: user_id,
|
16
|
-
}
|
17
|
-
end
|
9
|
+
def to_hash
|
10
|
+
{
|
11
|
+
name: name,
|
12
|
+
gold: gold,
|
13
|
+
userId: user_id,
|
14
|
+
}
|
18
15
|
end
|
19
16
|
end
|
@@ -19,11 +19,11 @@ Feature: Player
|
|
19
19
|
Then server should response the following json:
|
20
20
|
"""
|
21
21
|
{
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
"code": "RP-200",
|
23
|
+
"data": {
|
24
|
+
"name": "Someone",
|
25
|
+
"gold": 15,
|
26
|
+
"userId": "00000000-0000-0000-0000-000000000001"
|
27
27
|
}
|
28
28
|
}
|
29
29
|
"""
|
@@ -1,5 +1,5 @@
|
|
1
1
|
Given(/^[Tt]he [Pp]layer ["'](.+)["'] is authenticated$/) do |player_name|
|
2
|
-
player =
|
2
|
+
player = Player.find_by_name(player_name)
|
3
3
|
@handler_helper.authenticate(player.user_id)
|
4
4
|
end
|
5
5
|
|
@@ -7,6 +7,6 @@ Given(/^[Tt]he following [Pp]layer[s]*[:]*$/) do |table|
|
|
7
7
|
player_hashes = table.hashes
|
8
8
|
player_hashes.each do |player_hash|
|
9
9
|
player_hash[:user] = User.new(id: player_hash[:user_id])
|
10
|
-
|
10
|
+
Player.create(player_hash)
|
11
11
|
end
|
12
12
|
end
|
@@ -1,10 +1,3 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
|
3
|
-
ENV['RUBYPITAYA_ENV'] = 'test'
|
4
|
-
|
5
|
-
require 'rubypitaya/core/helpers/setup_helper'
|
6
|
-
require 'rubypitaya/core/spec-helpers/handler_spec_helper_class'
|
7
|
-
|
8
1
|
Given(/^[Cc]lient call route ["'](.+)["']$/) do |route|
|
9
2
|
@handler_helper.request(route)
|
10
3
|
end
|
@@ -16,8 +9,8 @@ Given(/^[Ss]erver should response ["'](.+)["'] as ["'](.+)["']$/) do |response_k
|
|
16
9
|
end
|
17
10
|
|
18
11
|
Given(/^[Ss]erver should response the following json[:]*$/) do |expected_json|
|
19
|
-
expected_json =
|
20
|
-
response_json = @handler_helper.response
|
12
|
+
expected_json = JSON.generate(JSON.parse(expected_json.strip))
|
13
|
+
response_json = JSON.generate(@handler_helper.response)
|
21
14
|
|
22
15
|
expect(response_json).to eq(expected_json)
|
23
16
|
end
|
@@ -30,10 +23,31 @@ Given(/^[Cc]onfig key ["'](.+)["'] is ["'](.+)["']$/) do |key, value|
|
|
30
23
|
@handler_helper.add_config(key, value)
|
31
24
|
end
|
32
25
|
|
26
|
+
Given(/^[Cc]onfig is the following json[:]*$/) do |config_json|
|
27
|
+
config = JSON.parse(config_json)
|
28
|
+
@handler_helper.set_config(config)
|
29
|
+
end
|
30
|
+
|
33
31
|
Given(/^[Pp]rint server response$/) do
|
34
32
|
puts "response: #{@handler_helper.response}"
|
35
33
|
end
|
36
34
|
|
35
|
+
Given(/^(?:[Nn]ow\s)?[Tt]oday is ["'](.+)["']$/) do |date_text|
|
36
|
+
time_now = date_text.to_time
|
37
|
+
|
38
|
+
Time.stub(:now).and_return(time_now)
|
39
|
+
end
|
40
|
+
|
41
|
+
Given(/^[Tt]he [Uu]ser ["'](.+)["'] is authenticated$/) do |user_id|
|
42
|
+
@handler_helper.authenticate(user_id)
|
43
|
+
end
|
44
|
+
|
45
|
+
Given(/^[Tt]he following [Uu]ser[s]*[:]*$/) do |table|
|
46
|
+
table.hashes.each do |table_hash|
|
47
|
+
User.create(id: table_hash[:user_id])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
37
51
|
Before do
|
38
52
|
ActiveRecord::Base.descendants.each { |c| c.delete_all unless c == ActiveRecord::SchemaMigration }
|
39
53
|
@handler_helper = RubyPitaya::HandlerSpecHelperClass.new('cucumber')
|
@@ -1,19 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
RSpec.describe 'HelloWorldHandler', type: :request do
|
4
|
+
context 'sayHello' do
|
5
|
+
it 'success' do
|
6
|
+
request("rubypitaya.helloWorldHandler.sayHello")
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
8
|
+
expected_response = {
|
9
|
+
code: 'RP-200',
|
10
|
+
data: { message: 'Hello!' }
|
11
|
+
}
|
9
12
|
|
10
|
-
|
11
|
-
code: 'RP-200',
|
12
|
-
data: { message: 'Hello!' }
|
13
|
-
}
|
14
|
-
|
15
|
-
expect(response).to eq(expected_response)
|
16
|
-
end
|
13
|
+
expect(response).to eq(expected_response)
|
17
14
|
end
|
18
15
|
end
|
19
16
|
end
|
@@ -1,50 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
RSpec.describe 'PlayerHandler', type: :request do
|
4
|
+
context 'authenticate' do
|
5
|
+
it 'create_new_user' do
|
6
|
+
setup = {'initial_player' => {'wallet' => {'gold' => 10}}}
|
7
|
+
config = {'initial_player' => {'name' => 'Guest'}}
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
it 'create_new_user' do
|
8
|
-
setup = {'initial_player' => {'wallet' => {'gold' => 10}}}
|
9
|
-
config = {'initial_player' => {'name' => 'Guest'}}
|
9
|
+
set_setup(setup)
|
10
|
+
set_config(config)
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
params = {}
|
13
|
+
request("rubypitaya.playerHandler.authenticate", params)
|
13
14
|
|
14
|
-
|
15
|
-
request("rubypitaya.playerHandler.authenticate", params)
|
15
|
+
player = Player.last
|
16
16
|
|
17
|
-
|
17
|
+
expect(response[:code]).to eq('RP-200')
|
18
|
+
expect(response[:data][:name]).to eq('Guest')
|
19
|
+
expect(response[:data][:gold]).to eq(10)
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
21
|
+
expect(User.count).to eq(1)
|
22
|
+
expect(Player.count).to eq(1)
|
23
|
+
expect(player.name).to eq('Guest')
|
24
|
+
expect(player.gold).to eq(10)
|
28
25
|
end
|
26
|
+
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
context 'getInfo' do
|
29
|
+
it 'success' do
|
30
|
+
player = Player.create(name: 'Someone', gold: 12, user: User.new)
|
33
31
|
|
34
|
-
|
32
|
+
authenticate(player.user_id)
|
35
33
|
|
36
|
-
|
34
|
+
request("rubypitaya.playerHandler.getInfo")
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
expect(response[:code]).to eq('RP-200')
|
37
|
+
expect(response[:data]).to eq(player.to_hash)
|
38
|
+
end
|
41
39
|
|
42
|
-
|
43
|
-
|
40
|
+
it 'error_not_authenticated' do
|
41
|
+
request("rubypitaya.playerHandler.getInfo")
|
44
42
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
43
|
+
expect(response[:code]).to eq(RubyPitaya::StatusCodes::CODE_NOT_AUTHENTICATED)
|
44
|
+
expect(response[:msg]).to eq('Not authenticated')
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
@@ -70,6 +70,26 @@ module RubyPitaya
|
|
70
70
|
@@setup.add(*keys, value)
|
71
71
|
end
|
72
72
|
|
73
|
+
def get_bll
|
74
|
+
@@bll
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_log
|
78
|
+
@@log
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_session
|
82
|
+
@@session
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_postman
|
86
|
+
@@postman
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_redis
|
90
|
+
@@redis_connector.redis
|
91
|
+
end
|
92
|
+
|
73
93
|
private
|
74
94
|
|
75
95
|
def initialize_redis
|
data/lib/rubypitaya/version.rb
CHANGED
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.
|
4
|
+
version: 2.14.1
|
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: 2021-01-
|
11
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|