Skip to content

Commit

Permalink
#1169 front tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 8, 2024
2 parents 563a8d0 + fb56334 commit c9a5d94
Show file tree
Hide file tree
Showing 20 changed files with 278 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- master
jobs:
codecov:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/xcop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: xcop
- master
jobs:
xcop:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: g4s8/xcop-action@master
Expand Down
16 changes: 8 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ source 'https://rubygems.org'
gem 'glogin', '0.13.0'
gem 'haml', '6.3.0'
gem 'iri', '0.7.0'
gem 'loog', '0.3.1'
gem 'minitest', '5.18.1', require: false
gem 'loog', '0.5.1'
gem 'minitest', '5.20.0', require: false
gem 'pgtk', '0.8.1'
gem 'rack', '2.2.4'
gem 'rack', '2.2.8'
gem 'rack-ssl', '1.4.1'
gem 'rack-test', '2.1.0'
gem 'rake', '13.0.6', require: false
gem 'rake', '13.1.0', require: false
gem 'relative_time', '1.1.0'
gem 'rerun', '0.14.0', require: false
gem 'rspec-rails', '6.0.3', require: false
gem 'rubocop', '1.56.0', require: false
gem 'rubocop-rspec', '2.23.2', require: false
gem 'rspec-rails', '6.1.0', require: false
gem 'rubocop', '1.59.0', require: false
gem 'rubocop-rspec', '2.26.1', require: false
gem 'sass', '3.7.4'
gem 'sentry-raven', '3.1.2'
gem 'simplecov', '0.22.0'
gem 'sinatra', '3.0.6'
gem 'sinatra-contrib', '3.0.6'
gem 'sprockets', '4.2.0'
gem 'sprockets', '4.2.1'
gem 'telebot', '0.1.2'
gem 'thin', '1.8.2'
gem 'xcop', '0.7.1'
45 changes: 22 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.1)
backtrace (0.4.0)
base58 (0.2.3)
base64 (0.1.1)
base64 (0.2.0)
bigdecimal (3.1.5)
builder (3.2.4)
coercible (1.0.0)
Expand Down Expand Up @@ -101,8 +101,8 @@ GEM
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
loog (0.3.1)
minitest (5.18.1)
loog (0.5.1)
minitest (5.20.0)
multi_json (1.15.0)
multipart-post (2.3.0)
mustermann (3.0.0)
Expand All @@ -112,7 +112,7 @@ GEM
racc (~> 1.4)
openssl (3.2.0)
parallel (1.24.0)
parser (3.2.2.4)
parser (3.3.0.1)
ast (~> 2.4.1)
racc
pg (1.5.4)
Expand All @@ -124,7 +124,7 @@ GEM
psych (5.1.2)
stringio
racc (1.7.3)
rack (2.2.4)
rack (2.2.8)
rack-protection (3.0.6)
rack
rack-session (1.0.2)
Expand Down Expand Up @@ -152,7 +152,7 @@ GEM
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.0.6)
rake (13.1.0)
random-port (0.6.0)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
Expand All @@ -162,7 +162,7 @@ GEM
regexp_parser (2.8.3)
relative_time (1.1.0)
i18n
reline (0.4.1)
reline (0.4.2)
io-console (~> 0.5)
rerun (0.14.0)
listen (~> 3.0)
Expand All @@ -175,7 +175,7 @@ GEM
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.3)
rspec-rails (6.1.0)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
Expand All @@ -184,16 +184,15 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.56.0)
base64 (~> 0.1.1)
rubocop (1.59.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
Expand All @@ -202,8 +201,8 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.25.0)
rubocop (~> 1.33)
rubocop-rspec (2.23.2)
rubocop (~> 1.33)
rubocop-rspec (2.26.1)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
Expand Down Expand Up @@ -233,7 +232,7 @@ GEM
sinatra (= 3.0.6)
tilt (~> 2.0)
slop (4.10.1)
sprockets (4.2.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
stringio (3.1.0)
Expand Down Expand Up @@ -271,24 +270,24 @@ DEPENDENCIES
glogin (= 0.13.0)
haml (= 6.3.0)
iri (= 0.7.0)
loog (= 0.3.1)
minitest (= 5.18.1)
loog (= 0.5.1)
minitest (= 5.20.0)
pgtk (= 0.8.1)
rack (= 2.2.4)
rack (= 2.2.8)
rack-ssl (= 1.4.1)
rack-test (= 2.1.0)
rake (= 13.0.6)
rake (= 13.1.0)
relative_time (= 1.1.0)
rerun (= 0.14.0)
rspec-rails (= 6.0.3)
rubocop (= 1.56.0)
rubocop-rspec (= 2.23.2)
rspec-rails (= 6.1.0)
rubocop (= 1.59.0)
rubocop-rspec (= 2.26.1)
sass (= 3.7.4)
sentry-raven (= 3.1.2)
simplecov (= 0.22.0)
sinatra (= 3.0.6)
sinatra-contrib (= 3.0.6)
sprockets (= 4.2.0)
sprockets (= 4.2.1)
telebot (= 0.1.2)
thin (= 1.8.2)
xcop (= 0.7.1)
Expand Down
30 changes: 18 additions & 12 deletions front/front_login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,41 @@
@locals = {
http_start: Time.now,
ver: Nb::VERSION,
login_link: settings.glogin.login_uri,
github_login_link: settings.glogin.login_uri,
request_ip: request.ip
}
cookies[:glogin] = params[:glogin] if params[:glogin]
if cookies[:glogin]
cookies[:identity] = params[:identity] if params[:identity]
if cookies[:identity]
begin
@locals[:user] = GLogin::Cookie::Closed.new(
cookies[:glogin],
identity = GLogin::Cookie::Closed.new(
cookies[:identity],
settings.config['github']['encryption_secret'],
context
).to_user
).to_user[:id]
human = humans.take(identity)
@locals[:human] = human
human.create unless human.exists?
rescue GLogin::Codec::DecodingError
cookies.delete(:glogin)
cookies.delete(:identity)
end
end
end

get '/github-callback' do
code = params[:code]
error(400) if code.nil?
cookies[:glogin] = GLogin::Cookie::Open.new(
settings.glogin.user(code),
login = settings.glogin.user(code)[:login]
identity = login
humans.create(identity) unless humans.github?(login)
cookies[:identity] = GLogin::Cookie::Open.new(
identity,
settings.config['github']['encryption_secret'],
context
).to_s
flash('/', 'You have been logged in')
flash(iri.cut('/'), 'You have been logged in')
end

get '/logout' do
cookies.delete(:glogin)
flash('/', 'You have been logged out')
cookies.delete(:identity)
flash(iri.cut('/'), 'You have been logged out')
end
2 changes: 1 addition & 1 deletion front/front_misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
status 503
e = env['sinatra.error']
if e.is_a?(Nb::Urror)
flash(@locals[:user] ? '/ranked' : '/', e.message, color: 'darkred')
flash(@locals[:human] ? iri.cut('/inbox') : iri.cut('/'), e.message, color: 'darkred')
else
Raven.capture_exception(e)
haml(
Expand Down
6 changes: 3 additions & 3 deletions front/front_telegram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

get '/telegram' do
id = params[:id].to_i
telechats.add(id, current_user)
telepost("We identified you as [@#{current_user}](https://netbout.com/u/#{current_user}), thanks!")
telechats.add(id, current_human)
telepost("We identified you as [@#{current_human}](https://netbout.com/u/#{current_human}), thanks!")
flash('/', "Your account linked with Telegram chat ##{id}, thanks!")
end

Expand All @@ -42,7 +42,7 @@ def telebot
@telebot ||= Telebot::Client.new(settings.config['telegram']['token'])
end

def telepost(msg, chat = telechats.chat_of(current_user), reply_markup: nil)
def telepost(msg, chat = telechats.chat_of(current_human), reply_markup: nil)
return unless settings.config['telegram']
telechats.posted(msg, chat)
telebot.send_message(
Expand Down
4 changes: 3 additions & 1 deletion liquibase/2024/001-initial-schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ SOFTWARE.
<sql>
CREATE TABLE human (
identity VARCHAR(32) PRIMARY KEY,
github VARCHAR(64),
telechat INT,
created TIMESTAMPTZ DEFAULT now() NOT NULL
);
CREATE INDEX idx_human1 ON human (telechat);
CREATE INDEX idx_human2 ON human (created);
CREATE INDEX idx_human2 ON human (github);
CREATE INDEX idx_human3 ON human (created);
</sql>
<sql>
CREATE TABLE bout (
Expand Down
35 changes: 24 additions & 11 deletions netbout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
require 'yaml'
require_relative 'objects/urror'

if ENV['RACK_ENV'] != 'test'
unless ENV['RACK_ENV'] == 'test'
require 'rack/ssl'
use Rack::SSL
end
Expand All @@ -65,7 +65,7 @@
end
config = YAML.safe_load(File.open(f))
end
if ENV['RACK_ENV'] != 'test'
unless ENV['RACK_ENV'] == 'test'
Raven.configure do |c|
c.dsn = config['sentry']
require_relative 'objects/version'
Expand All @@ -74,7 +74,7 @@
end
set :bind, '0.0.0.0'
set :server, :thin
set :show_exceptions, true
set :show_exceptions, false
set :raise_errors, true
set :dump_errors, true
set :config, config
Expand All @@ -101,7 +101,7 @@
end

get '/' do
flash('/inbox') if @locals[:user]
flash(iri.cut('/inbox')) if @locals[:human]
haml :index, layout: :layout, locals: merged(
title: '/'
)
Expand All @@ -111,28 +111,41 @@
offset = [(params[:offset] || '0').to_i, 0].max
limit = (params[:limit] || '10').to_i
query = params[:q] || ''
haml :ranked, layout: :layout, locals: merged(
haml :inbox, layout: :layout, locals: merged(
title: '/inbox',
query: query,
limit: limit,
offset: offset
)
end

get '/start' do
haml :start, layout: :layout, locals: merged(
title: '/start'
)
end

post '/start' do
title = params[:title]
bout = current_human.bouts.start(title)
id = bout.id
flash(iri.cut('/b').append(id), "Bout ##{id} was started")
end

get '/terms' do
haml :terms, layout: :layout, locals: merged(
title: '/terms'
)
end

def current_user
redirect '/' unless @locals[:user]
@locals[:user][:id].downcase
def current_human
redirect iri.cut('/') unless @locals[:human]
@locals[:human]
end

def users
require_relative 'objects/users'
@users ||= Nb::Users.new(settings.pgsql)
def humans
require_relative 'objects/humans'
@humans ||= Nb::Humans.new(settings.pgsql)
end

def iri
Expand Down
Loading

0 comments on commit c9a5d94

Please sign in to comment.