Skip to content

Commit

Permalink
#1169 front test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 5, 2024
1 parent db14b70 commit 563a8d0
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 21 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
source 'https://rubygems.org'

gem 'glogin', '0.13.0'
gem 'haml', '5.0.4'
gem 'haml', '6.3.0'
gem 'iri', '0.7.0'
gem 'loog', '0.3.1'
gem 'minitest', '5.18.1', require: false
gem 'minitest-reporters', '1.6.0', require: false
gem 'pgtk', '0.8.1'
gem 'rack', '2.2.4'
gem 'rack-ssl', '1.4.1'
Expand Down
14 changes: 4 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
ansi (1.5.0)
ast (2.4.2)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
Expand Down Expand Up @@ -82,8 +81,9 @@ GEM
glogin (0.13.0)
base58 (>= 0.2)
openssl (>= 2.0)
haml (5.0.4)
temple (>= 0.8.0)
haml (6.3.0)
temple (>= 0.8.2)
thor
tilt
i18n (1.14.1)
concurrent-ruby (~> 1.0)
Expand All @@ -103,11 +103,6 @@ GEM
nokogiri (>= 1.12.0)
loog (0.3.1)
minitest (5.18.1)
minitest-reporters (1.6.0)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_json (1.15.0)
multipart-post (2.3.0)
mustermann (3.0.0)
Expand Down Expand Up @@ -274,11 +269,10 @@ PLATFORMS

DEPENDENCIES
glogin (= 0.13.0)
haml (= 5.0.4)
haml (= 6.3.0)
iri (= 0.7.0)
loog (= 0.3.1)
minitest (= 5.18.1)
minitest-reporters (= 1.6.0)
pgtk (= 0.8.1)
rack (= 2.2.4)
rack-ssl (= 1.4.1)
Expand Down
2 changes: 1 addition & 1 deletion front/front_misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

get '/version' do
content_type 'text/plain'
require_relative 'objects/version'
require_relative '../objects/version'
Nb::VERSION
end

Expand Down
12 changes: 8 additions & 4 deletions netbout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
end

configure do
Haml::Options.defaults[:format] = :xhtml
config = {
'github' => {
'client_id' => '?',
Expand All @@ -57,9 +56,14 @@
'sentry' => ''
}
unless ENV['RACK_ENV'] == 'test'
cfg = File.join(File.dirname(__FILE__), 'config.yml')
raise "The #{cfg} file must exist or you should set RACK_ENV to 'test' " unless File.exist?(cfg)
config = YAML.safe_load(File.open())
f = File.join(File.dirname(__FILE__), 'config.yml')
unless File.exist?(f)
raise [
"The config file #{f} is absent, can't start the app. ",
"If you are running in a staging/testing mode, set RACK_ENV envirornemt variable to 'test'"
].join
end
config = YAML.safe_load(File.open(f))
end
if ENV['RACK_ENV'] != 'test'
Raven.configure do |c|
Expand Down
3 changes: 0 additions & 3 deletions test/test__helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
require 'simplecov'
SimpleCov.start

require 'minitest/reporters'
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]

require 'yaml'
require 'minitest/autorun'
require 'pgtk/pool'
Expand Down
72 changes: 72 additions & 0 deletions test/test_netbout.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

# (The MIT License)
#
# Copyright (c) 2009-2024 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'minitest/autorun'
require 'rack/test'
require_relative 'test__helper'
require_relative '../netbout'
require_relative '../objects/nb'

module Rack
module Test
class Session
def default_env
{ 'REMOTE_ADDR' => '127.0.0.1', 'HTTPS' => 'on' }.merge(headers_for_env)
end
end
end
end

# Test of web front.
# Author:: Yegor Bugayenko ([email protected])
# Copyright:: Copyright (c) 2009-2024 Yegor Bugayenko
# License:: MIT
class Nb::AppTest < Minitest::Test
include Rack::Test::Methods

def app
Sinatra::Application
end

def test_renders_pages
pages = [
'/version',
'/robots.txt',
'/',
'/logo.svg'
]
pages.each do |p|
get(p)
assert(last_response.ok?, last_response.body)
end
end

def test_not_found
['/unknown_path', '/js/x/y/z/not-found.js', '/css/a/b/c/not-found.css'].each do |p|
get(p)
assert_equal(404, last_response.status, last_response.body)
assert_equal('text/html;charset=utf-8', last_response.content_type)
end
end
end
2 changes: 1 addition & 1 deletion views/layout.haml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
%p{style: 'background-color:' + flash_color + ';color:white;padding:.1em .5em;border-radius:4px;width:100%;'}
= flash_msg
%article
= yield
!= yield
%footer.small.gray
%nav
%ul
Expand Down

0 comments on commit 563a8d0

Please sign in to comment.