nephos-server 0.5.4 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e8ff75ee49a1ab28b80920721ad356542a82547
4
- data.tar.gz: 54a400165ee4401da84a727cf8e95ed2992d3a6a
3
+ metadata.gz: deb3406763cd858becf11305040bd3916c3151ef
4
+ data.tar.gz: 840624b4879a929ce7b1555d598b7555b28f1f50
5
5
  SHA512:
6
- metadata.gz: 0660a8e017d4824933c80dee460daa445f16a544a7fca14372849a867561e8b028650fd8dc7fe0988434e1d031e018f92699a2f89572a079ecfc646daad1d3e9
7
- data.tar.gz: f17a9dafdc7d4d1bb976c099f078c1439a5037c0586fd2abf9a800c97c91ec0744c293b528e240c16b32f6372ddab435d74259a0b22528c4bf3e9b5b38aa9b75
6
+ metadata.gz: 2ce1336de3d50ec9e9dc42b1c3dab71f071f61c87158770191a62b42642220156aa729446b739f2438e0f758dadc28781934e94ddf4dbd41eb0465d89ea6d865
7
+ data.tar.gz: a6c4b3d0cd26ed3d4c7f20d8ee81e4dee557df41d31b952225b9417cebcc075fc6b623f59c5b78351672fee16aad8c442918fb67064be51807826e94efdb98e0
data/CHANGELOG CHANGED
@@ -1,24 +1,29 @@
1
- v0.5.4
1
+ v0.6.1
2
+ * Improve daemons
3
+ * Improve Rakefile and tests structure
4
+ * Add few functional (router, server, generator) tests
5
+ * Add new unitary tests
6
+
7
+ v0.6.0
8
+ * Big change (ea49dfb0b429f03327447477bfee9bef30dda7ad) on the architecture, massive usage of Rack::Request, review the global architecture, update all unitary tests
9
+ * add hook before_action and after_action
10
+ * improve params
11
+ * improve controller error handlement with STDERR message
12
+ * server can be daemonized
13
+
14
+ v0.5
2
15
  * fix regression on empty response
3
16
  * add unitary tests
4
17
  * improve gemspec
5
18
  * fix severe regression on responder
6
19
  * fix environment bug
7
-
8
- v0.5.3
9
20
  * add continuous integration with gitlab
10
21
  * fix executables requirements to be testable
11
22
  * add cookies management
12
-
13
- v0.5.2
14
23
  * fix regression on content-type from v0.4
15
-
16
- v0.5.1
17
24
  * fix nephos gem (binaries can be used out of an application)
18
25
  * improve code documentation (annotations above the methods and classes)
19
26
  * fix content type for json to application/json
20
-
21
- v0.5.0
22
27
  * improve executables: version taking in count
23
28
 
24
29
  v0.4
data/README.md CHANGED
@@ -1,16 +1,6 @@
1
1
  # Nephos Ruby Server
2
-
3
- [![Gitlab Tests](https://gitlab.com/ci/projects/8973/status.png?ref=master)](https://gitlab.com/ci/projects/8973?ref=master)
4
-
5
- [![GitHub version](https://badge.fury.io/gh/pouleta%2FNephosRubyServer.svg)](http://badge.fury.io/gh/pouleta%2FNephosRubyServer)
6
-
7
2
  [![Gem Version](https://badge.fury.io/rb/nephos-server.svg)](http://badge.fury.io/rb/nephos-server)
8
3
 
9
- [![Code Climate](https://codeclimate.com/github/pouleta/NephosRubyServer/badges/gpa.svg)](https://codeclimate.com/github/pouleta/NephosRubyServer)
10
-
11
- [![Nephos Executables](https://badge.fury.io/rb/nephos.svg)](http://badge.fury.io/rb/nephos)
12
-
13
-
14
4
  This is a minimal web server, based on [rack](https://github.com/rack/rack) and [puma](https://github.com/puma/puma).
15
5
  It is written in ruby. It also gives you a minimal architecture
16
6
  to speed up your application bootstrap.
@@ -42,6 +32,8 @@ nserver -p 8080 -h 0.0.0.0 # start the server. port is not required, neither hos
42
32
  - ``-p``: port to listen
43
33
  - ``-h``: host to listen (network address)
44
34
  - ``-e``: environment (default is development, can be set to production)
35
+ - ``-d``: daemonize the process
36
+ - ``-k``: kill daemonized process
45
37
 
46
38
 
47
39
  # Documentation
@@ -121,7 +113,6 @@ end
121
113
 
122
114
  ## TODO v0.6
123
115
  - startable as daemon
124
- - hooks for controller
125
116
  - feature to change HTTP header from controller
126
117
  - customisable default 404 errors and 500 errors
127
118
  - functionnal tests
@@ -136,3 +127,11 @@ end
136
127
  - Api Creation
137
128
  - Database creation
138
129
  - Web HTML with templating
130
+
131
+ [![Gitlab Tests](https://gitlab.com/ci/projects/8973/status.png?ref=master)](https://gitlab.com/ci/projects/8973?ref=master)
132
+
133
+ [![GitHub version](https://badge.fury.io/gh/pouleta%2FNephosRubyServer.svg)](http://badge.fury.io/gh/pouleta%2FNephosRubyServer)
134
+
135
+ [![Code Climate](https://codeclimate.com/github/pouleta/NephosRubyServer/badges/gpa.svg)](https://codeclimate.com/github/pouleta/NephosRubyServer)
136
+
137
+ [![Nephos Executables](https://badge.fury.io/rb/nephos.svg)](http://badge.fury.io/rb/nephos)
data/Rakefile CHANGED
@@ -5,3 +5,16 @@ task :default => [:test]
5
5
  task :test do
6
6
  ruby "test/test.rb"
7
7
  end
8
+
9
+ namespace :test do
10
+
11
+ desc "Unitary tests. Fasts and on the sources."
12
+ task :test do
13
+ ruby "test/test.rb"
14
+ end
15
+
16
+ desc "Functional tests. Slow, test real the features under real conditions of usage."
17
+ task :functional do
18
+ ruby "test/functional.rb"
19
+ end
20
+ end
data/app/main.rb CHANGED
@@ -1,9 +1,26 @@
1
1
  class MainController < Nephos::Controller
2
2
 
3
+ before_action :fct_before_all
4
+ before_action :fct_before_root, :root
5
+ after_action :fct_after_root, :root
6
+
7
+ def fct_before_all
8
+ # puts "BEFORE ALL"
9
+ end
10
+
11
+ def fct_before_root
12
+ # puts "BEFORE"
13
+ end
14
+
15
+ def fct_after_root
16
+ # puts "AFTER"
17
+ end
18
+
3
19
  def root
20
+ # puts "ROOT"
4
21
  cookies["a"] = "b"
5
22
  cookies.delete("b").to_h
6
- puts cookies
23
+ # puts "Cookies from the root:", cookies
7
24
  {
8
25
  json: {
9
26
  list: $dataset,
@@ -39,7 +56,7 @@ class MainController < Nephos::Controller
39
56
 
40
57
  AUTH_IMG_EXT = %w(.jpg .jpeg .png .gif)
41
58
  def image
42
- dir = File.expand_path('controllers/')
59
+ dir = File.expand_path('app/')
43
60
  file = File.expand_path(params["image"], dir)
44
61
  if not file[0..(dir.size-1)] == dir or not AUTH_IMG_EXT.include?(File.extname(file))
45
62
  return {status: 500, content: "invalid path #{params['image']}"}
data/bin/nephos-server CHANGED
@@ -35,12 +35,30 @@ begin
35
35
  $test = true
36
36
  end
37
37
 
38
+ opts.on("-d", "--daemon", "Start in background") do
39
+ $daemon = true
40
+ end
41
+
42
+ opts.on("-k", "--kill", "Kill the daemon if started") do
43
+ $kill_daemon = true
44
+ end
45
+
38
46
  end.parse!
39
47
 
40
48
  Nephos.env = $server_env
41
49
 
42
50
  Dir.chdir(opts[0]) if not opts.empty?
43
51
 
52
+ if $kill_daemon
53
+ raise "No Daemon started" if not Nephos::Bin::Daemon.started?
54
+ puts "Daemon #{Nephos::Bin::Daemon.get_pid} stopped"
55
+ Nephos::Bin::Daemon.kill!
56
+ exit 0
57
+ end
58
+ if $daemon and Nephos::Bin::Daemon.started?
59
+ raise "Unable to start the server: the daemon #{Nephos::Bin::Daemon.get_pid} already exists"
60
+ end
61
+
44
62
  if $test
45
63
  require_relative "../lib/nephos-server"
46
64
  else
@@ -54,12 +72,19 @@ begin
54
72
  end
55
73
 
56
74
  puts "Running Nephos::Server version #{Nephos::VERSION} (#{Nephos.env})"
75
+ if $daemon
76
+ Nephos::Bin::Daemon.detach!
77
+ end
57
78
  Nephos::Server.start($server_port, $server_host)
58
79
 
59
80
  rescue RoutingError => err
60
81
  puts "Routing Error: Check out the documentation and `routes.rb` file.".yellow
61
82
  puts "#{err.class}: #{err.message}".red
83
+ puts "#{err.backtrace.join("\n")}".yellow if $debug
84
+ exit 1
62
85
 
63
86
  rescue => err
64
87
  puts "#{err.class}: #{err.message}".red
88
+ puts "#{err.backtrace.join("\n")}".yellow if $debug
89
+ exit 1
65
90
  end
@@ -1,4 +1,5 @@
1
1
  module Nephos
2
+
2
3
  module Bin
3
4
 
4
5
  # @param dir [String]
@@ -18,7 +19,45 @@ module Nephos
18
19
  return true
19
20
  end
20
21
 
22
+ module Daemon
23
+
24
+ def self.started?
25
+ get_pid != nil
26
+ end
27
+
28
+ def self.kill!
29
+ d = get_pid
30
+ return false unless d
31
+ begin
32
+ Process::kill(10, d)
33
+ rescue => err
34
+ raise "Cannot kill #{d} !"
35
+ ensure
36
+ File.delete(get_pid_file)
37
+ end
38
+ return true
39
+ end
40
+
41
+ def self.detach!
42
+ Process::daemon(true, false)
43
+ File.write(get_pid_file, Process::pid.to_s)
44
+ end
45
+
46
+ def self.get_pid_file
47
+ return ".pid"
48
+ end
49
+
50
+ def self.get_pid
51
+ return nil if not File.exists?(get_pid_file)
52
+ v = File.read(get_pid_file)
53
+ v = Integer(v) rescue nil
54
+ return v
55
+ end
56
+
57
+ end
58
+
21
59
  end
60
+
22
61
  end
23
62
 
24
63
  class BinError < StandardError; end
@@ -6,28 +6,80 @@ module Nephos
6
6
  # and the parameters.
7
7
  class Controller
8
8
 
9
- attr_reader :env, :infos, :callpath, :params, :cookies
10
- attr_reader :req
9
+ attr_reader :req, :callpath, :params, :cookies
11
10
 
12
11
  # @param env [Hash] env extracted from the http request
13
12
  # @param parsed [Hash] pre-parsed env with parameters, ...
14
- def initialize env={}, parsed={path: [], params: {}}, callpath={params: []}
15
- raise ArgumentError, "env must be a Hash" unless env.is_a? Hash
16
- raise ArgumentError, "parsed must be a Hash" unless parsed.is_a? Hash
17
- raise ArgumentError, "callpath must be a Hash" unless callpath.is_a? Hash
18
- raise ArgumentError, "Invalid Parsed. :path must be associated with an Array" unless parsed[:path].is_a? Array
19
- raise ArgumentError, "Invalid Parsed. :params must be associated with a Hash" unless parsed[:params].is_a? Hash
20
- raise ArgumentError, "Invalid Callpath. :params must be associated with an Array" unless callpath[:params].is_a? Array
21
- @env= env
22
- @req= Rack::Request.new(env)
23
- @infos= parsed
13
+ def initialize req, callpath
14
+ raise ArgumentError, "req must be a Rack::Request" unless req.is_a? Rack::Request
15
+ raise ArgumentError, "call must be a Hash" unless callpath.is_a? Hash
16
+ @req= req
24
17
  @callpath= callpath
25
- @params= parsed[:params]
26
- @params.merge! Hash[callpath[:params].zip @infos[:path]]
18
+ @params= req.params rescue {}
19
+
20
+ params = @req.path.split("/")
21
+ params.shift
22
+ @params.merge! Hash[callpath[:params].zip(params)]
27
23
  @params.select!{|k,v| not k.to_s.empty?}
24
+
25
+
28
26
  @params = Params.new(@params)
29
27
  @cookies = Params.new(@req.cookies)
30
28
  end
31
29
 
30
+ @@before_action = {:'*' => []}
31
+ @@after_action = {:'*' => []}
32
+
33
+ def self.parse_action_opts(opt)
34
+ if opt.nil?
35
+ return :'*'
36
+ elsif opt.is_a? Hash
37
+ raise "No implemented yet"
38
+ # parse :only and :except
39
+ elsif opt.is_a? String or opt.is_a? Symbol
40
+ return opt.to_sym
41
+ else
42
+ raise ArgumentError, "Invalid opts"
43
+ end
44
+ end
45
+
46
+ # @param method [Symbol]
47
+ # @param opt [Nil, Hash, String, Symbol] define which method will call "method"
48
+ # - if nil, then all call will trigger the event
49
+ # - if Hash, it will be parsed with rules :only and :except
50
+ # - if String or Symbol, it will be parsed as :only
51
+ def self.before_action(method, opt=nil)
52
+ call = parse_action_opts(opt)
53
+ @@before_action[call] ||= []
54
+ @@before_action[call] << method.to_sym
55
+ end
56
+
57
+ # see {#self.before_action}
58
+ def self.after_action(method, opt=nil)
59
+ call = parse_action_opts(opt)
60
+ @@after_action[call] ||= []
61
+ @@after_action[call] << method.to_sym
62
+ end
63
+
64
+ def execute_before_action(call)
65
+ call = call.to_sym
66
+ methods = []
67
+ methods += Array(@@before_action[call])
68
+ methods += @@before_action[:'*']
69
+ methods.each do |method|
70
+ self.send(method)
71
+ end
72
+ end
73
+
74
+ def execute_after_action(call)
75
+ call = call.to_sym
76
+ methods = []
77
+ methods += Array(@@after_action[call])
78
+ methods += @@after_action[:'*']
79
+ methods.each do |method|
80
+ self.send(method)
81
+ end
82
+ end
83
+
32
84
  end
33
85
  end
@@ -33,5 +33,9 @@ module Nephos
33
33
  return @hash
34
34
  end
35
35
 
36
+ def to_s
37
+ return to_h.to_s
38
+ end
39
+
36
40
  end
37
41
  end
@@ -1,5 +1,6 @@
1
1
  module Nephos
2
- module Router
2
+
3
+ class Router
3
4
 
4
5
  def self.add(what, verb)
5
6
  Nephos::Router::ROUTES << what.merge(verb: verb)
@@ -9,15 +10,13 @@ module Nephos
9
10
  end
10
11
 
11
12
  # @param what [Hash]
12
- #
13
- # TODO: doc
14
13
  def self.add_params!(what)
15
14
  params = what[:url].split('/').map do |p|
16
15
  p.match(/:\w+/) ? {p: "[^\/]+", name: p} : {p: p, name: nil}
17
16
  end
18
17
  url = params.map{|e| e[:p]}.join("/")
19
18
  url = "/" if url.empty?
20
- what[:match] = /^#{url}$/
19
+ what[:match] = /^#{url}\/*$/
21
20
  what[:params] = params.map{|e| e[:name] && e[:name][1..-1]}[1..-1] || []
22
21
  end
23
22
 
@@ -35,9 +34,6 @@ module Nephos
35
34
 
36
35
  # @param what [Hash]
37
36
  #
38
- # TODO:
39
- # - Improve instanciation test
40
- #
41
37
  # Check if:
42
38
  # - the what parameter contains a :controller
43
39
  # - this controller exists
@@ -53,7 +49,7 @@ module Nephos
53
49
  raise InvalidRouteController, "Class \"#{what[:controller]}\" is not a Nephos::Controller"
54
50
  end
55
51
  begin
56
- instance = controller.new
52
+ instance = controller.new(Rack::Request.new({}), {params: []})
57
53
  rescue => err
58
54
  raise InvalidRouteController, "Cannot initialize controller"
59
55
  end
@@ -77,6 +73,7 @@ module Nephos
77
73
  end
78
74
 
79
75
  end
76
+
80
77
  end
81
78
 
82
79
  require_relative 'helpers'
@@ -7,71 +7,59 @@ module Nephos
7
7
 
8
8
  # The {Router} provides an interface between the {Controller} and the client
9
9
  # queries.
10
- module Router
10
+ class Router
11
11
 
12
12
  ROUTES = []
13
13
 
14
- # @param args Contain the controller and the method to call on it
15
- #
16
- # Shortcut to #{Nephos::Responder.render}
17
- def self.render *args
18
- if args.first.is_a? Nephos::Controller
19
- return Responder.render_from_controller *args
20
- end
21
- return Responder.render *args
14
+ # @param opt [Hash] it contains optional parameters, via the keys (Symbol only)
15
+ # - :silent : if true, then there will be no puts on the stdin when a request is routed.
16
+ # Else, or by default, there will be information printed on stdin
17
+ def initialize(opt={})
18
+ @responder = Responder.new
19
+ @silent = !!opt[:silent]
22
20
  end
23
21
 
24
- def self.error(code, err=nil)
25
- if ENV["ENVIRONMENT"].to_s.match(/prod(uction)?/)
26
- return render(status: code)
22
+ # render the return of a call to Controller.new.method.
23
+ # Controller and method are stored on call via the keys :controller and :method
24
+ def render_controller req, call
25
+ return @responder.render_from_controller(req, call)
26
+ end
27
+
28
+ def render_error(req, code, err=nil)
29
+ if Nephos.env == "production"
30
+ return @responder.render(status: code)
27
31
  elsif err
28
32
  msg = err
29
33
  if msg.is_a? Exception
30
34
  msg = err.message + "\n"
31
- msg += "--- Backtrace ---\n" + err.backtrace.join("\n") + "\n" if Nephos.env != "production"
35
+ msg += "--- Backtrace ---\n" + err.backtrace.join("\n") + "\n"
32
36
  end
33
- return render(status: code,
34
- content: "Error: #{code}\n#{msg}")
37
+ return @responder.render(status: code, content: "Error: #{code}\n#{msg}")
35
38
  else
36
- return render(status: code)
39
+ return @responder.render(status: code)
37
40
  end
38
41
  end
39
42
 
40
43
  # @param path [Array]
41
44
  #
42
45
  # Find the right route to use from the url
43
- def self.parse_path path, verb
44
- route = File.join(["/"] + path)
45
- return ROUTES.find{|e| e[:match] =~ route and e[:verb] == verb}
46
- end
47
-
48
- def self.parse_env(env, route)
49
- verb = env["REQUEST_METHOD"]
50
- from = env["REMOTE_ADDR"]
51
- path = route.path.split("/").select{|e|not e.to_s.empty?}
52
- params = Rack::Request.new(env).params
53
- # Hash[route.query.to_s.split("&").map{|e| e.split("=")}]
54
- return {route: route, verb: verb, from: from, path: path, params: params}
46
+ def find_route req
47
+ return ROUTES.find{|e| e[:match] =~ req.path and e[:verb] == req.request_method}
55
48
  end
56
49
 
57
50
  # Interface which handle the client query (stored in env), create a new
58
51
  # {Controller} instance, and call the render on it
59
- def self.execute(env)
60
- begin
61
- route = URI.parse(env['REQUEST_URI'])
62
- rescue => err
63
- puts "uri err #{err.message}".red
64
- return error(500, err)
65
- end
66
- parsed = parse_env(env, route)
67
- puts "#{parsed[:from]} [#{parsed[:verb]}] \t ---> \t #{route}"
68
- call = parse_path(parsed[:path], parsed[:verb])
69
- return error(404, "404 not found \"#{route}\"") if call.nil?
52
+ def execute(req)
53
+ env = req.env
54
+ puts "#{req.env["REMOTE_ADDR"]} [#{req.request_method}] \t ---> \t #{req.path}" unless @silent
55
+ call = find_route(req)
56
+ return render_error(req, 404, "404 not found \"#{req.path}\"") if call.nil?
70
57
  begin
71
- controller = Module.const_get(call[:controller]).new(env, parsed, call)
72
- return render(controller, call[:method])
58
+ return render_controller(req, call)
73
59
  rescue => err
74
- return error(500, err)
60
+ STDERR.puts "Error: #{err.message}"
61
+ STDERR.puts err.backtrace
62
+ return render_error(req, 500, err)
75
63
  end
76
64
  end
77
65
 
@@ -3,19 +3,21 @@ require_relative 'responder'
3
3
  module Nephos
4
4
  class Server
5
5
 
6
- SERVER = lambda {|env| return Router.execute(env)}
7
-
8
6
  attr_accessor :port, :host
9
7
 
10
8
  # @param port [Integer] port to listen
11
9
  def initialize port="8080", host="0.0.0.0"
12
10
  @port = Integer(port)
13
11
  @host = host.to_s
12
+ @server = lambda {|env|
13
+ router = Router.new
14
+ return router.execute(Rack::Request.new(env))
15
+ }
14
16
  end
15
17
 
16
18
  # start the Rack server
17
19
  def start
18
- Rack::Server.start :app => SERVER, :Port => @port, :Host => @host
20
+ Rack::Server.start :app => @server, :Port => @port, :Host => @host
19
21
  end
20
22
 
21
23
  # start the Rack server on a instance of Nephos::Server
@@ -1,16 +1,17 @@
1
1
  module Nephos
2
- module Responder
2
+
3
+ class Responder
3
4
 
4
5
  class InvalidContentType < StandardError; end
5
6
 
6
7
  CT_CHARSET_PREFIX = '; charset='
7
8
 
8
- def self.content_type(kind, type, charset='UTF-8')
9
+ def content_type(kind, type, charset='UTF-8')
9
10
  "#{kind}/#{type}" + CT_CHARSET_PREFIX + charset
10
11
  end
11
12
 
12
13
  # @param params [Hash] containing :type => "kind/type", example: "text/html"
13
- def self.ct_specific(params)
14
+ def ct_specific(params)
14
15
  kind, type = params[:type].to_s.match(/^(\w+)\/(\w+)$/) && Regexp.last_match[1..2]
15
16
  if kind.nil? or type.nil?
16
17
  raise InvalidContentType, "params[:type] must match with \"kind/type\""
@@ -24,20 +25,19 @@ module Nephos
24
25
  json: "application/json",
25
26
  }
26
27
 
27
- private
28
28
  # if not :status entry, set to 200
29
- def self.set_default_params_status params
29
+ def set_default_params_status params
30
30
  params[:status] ||= 200
31
31
  end
32
32
 
33
- def self.set_default_params_type params
33
+ def set_default_params_type params
34
34
  if params[:type].nil?
35
35
  params[:type] = PRESET_CT[(params.keys & [:plain, :html, :json]).first || :plain]
36
36
  end
37
37
  params[:type] = ct_specific(params)
38
38
  end
39
39
 
40
- def self.set_default_params_content params
40
+ def set_default_params_content params
41
41
  type = (params.keys & [:plain, :html, :json, :content]).first
42
42
  if type.nil?
43
43
  if params[:status].to_s.match(/^[45]\d\d$/)
@@ -52,37 +52,44 @@ module Nephos
52
52
  params[:content] = params[type]
53
53
  end
54
54
  end
55
- public
56
55
 
57
56
  # Fill params with default parameters (status, plain errors)
58
- def self.set_default_params params
57
+ def set_default_params params
59
58
  set_default_params_status(params)
60
59
  set_default_params_type(params)
61
60
  set_default_params_content(params)
62
- params
61
+ return params
63
62
  end
64
63
 
65
- def self.empty_resp
64
+ def empty_resp
66
65
  resp = Rack::Response.new
67
66
  resp.status = 204
68
67
  resp["Content-Type"] = ct_specific({type: PRESET_CT[:plain]})
69
- resp
68
+ return resp
70
69
  end
71
70
 
72
- def self.render_from_controller controller, method_to_call
73
- params = controller.send method_to_call
74
- resp = Responder.render(params)
71
+ def render_from_controller req, call
72
+ controller = Module.const_get(call[:controller]).new(req, call)
73
+ method_to_call = call[:method]
74
+
75
+ controller.execute_before_action(method_to_call)
76
+ # puts "Call #{controller} # #{method_to_call}"
77
+ params = controller.send(method_to_call)
78
+ controller.execute_after_action(method_to_call)
79
+
80
+ # puts "--- Params #{params.class} ---", "<<", params, ">>"
81
+ resp = render(params)
75
82
  controller.cookies.each do |k, v|
76
83
  resp.set_cookie k, v
77
84
  end
78
85
  return resp
79
86
  end
80
87
 
81
- # @param controller [Controller]
82
- # @param method_to_call [Symbol]
83
- def self.render params
84
- return Responder.empty_resp if params == :empty
88
+ def render params
89
+ return empty_resp if params == :empty
85
90
  return render(status: params) if params.is_a? Integer
91
+ raise "Not a valid params argument" unless params.is_a? Hash
92
+
86
93
  resp = Rack::Response.new
87
94
  params = set_default_params(params)
88
95
  resp.status = params[:status]
@@ -92,4 +99,5 @@ module Nephos
92
99
  end
93
100
 
94
101
  end
102
+
95
103
  end
@@ -40,7 +40,10 @@ test/responder.rb
40
40
  test/router.rb
41
41
  test/params.rb
42
42
  test/controller.rb
43
- test/generator.rb
43
+ test/functional.rb
44
+ test/functional/server.rb
45
+ test/functional/generator.rb
46
+ test/functional/global.rb
44
47
  routes.rb
45
48
 
46
49
  app/dataset.rb
data/routes.rb CHANGED
@@ -17,7 +17,7 @@ get url: "/rm", controller: "MainController", method: "rm_url"
17
17
  get url: "/debug", controller: "MainController", method: "debug"
18
18
  get url: "/hello", controller: "MainController", method: "hello"
19
19
 
20
- get url: "/image", controller: "MainController", method: "image"
20
+ # get url: "/image", controller: "MainController", method: "image"
21
21
  get url: "/image/:image", controller: "MainController", method: "image"
22
22
  get url: "img/:image", controller: "MainController", method: "image"
23
23
 
data/test/controller.rb CHANGED
@@ -1,25 +1,30 @@
1
+ class ReqWithWritableParams < Rack::Request
2
+ def params
3
+ return Hash[@env["REQUEST_URI"].gsub(/.*\?(.+)/, '\1').split('&').map{|d| d.split('=')}]
4
+ end
5
+ end
6
+
1
7
  class TestNephosServerController < Test::Unit::TestCase
2
8
 
3
- def test_initialize_success
4
- assert Nephos::Controller.new()
5
- assert Nephos::Controller.new(env={}, {path: [], params: {}}, {params: []})
6
- end
9
+ def test_initialize
10
+ assert_raise do Nephos::Controller.new() end
11
+ assert_raise do Nephos::Controller.new({}) end
12
+ assert_raise do Nephos::Controller.new({}, {}) end
7
13
 
8
- def test_initialize_failure
9
- assert_raise do Nephos::Controller.new({}, {}, {}) end
10
- assert_raise do Nephos::Controller.new({}, {path: nil}, {}) end
11
- assert_raise do Nephos::Controller.new({}, {path: []}, {}) end
12
- assert_raise do Nephos::Controller.new({}, {path: [], params: {}}, {}) end
13
- assert_raise do Nephos::Controller.new({}, {path: [], params: {}}, {params: nil}) end
14
- assert_raise do Nephos::Controller.new({}, {path: nil, params: nil}, params: nil) end
15
- assert_raise do Nephos::Controller.new({}, {path: nil, params: {}}, {params: {}}) end
16
- assert_raise do Nephos::Controller.new({}, {path: [], params: nil}, {params: {}}) end
14
+ r = Rack::Request.new({})
15
+ assert_raise do Nephos::Controller.new() end
16
+ assert_raise do Nephos::Controller.new(r) end
17
+ assert_raise do Nephos::Controller.new(r, {}) end
18
+ assert do Nephos::Controller.new(r, {params: []}) end
17
19
  end
18
20
 
19
21
  def test_controller_params
20
- c = Nephos::Controller.new(env={}, {path: ["value"], params: {}}, {params: ["param"]})
21
- assert_equal "value", c.params[:param]
22
- assert_equal "value", c.params["param"]
22
+ r = ReqWithWritableParams.new({"REQUEST_METHOD"=>"GET",
23
+ "PATH_INFO"=>"/index",
24
+ "REQUEST_URI"=>"/uri?k=v"})
25
+ c = Nephos::Controller.new(r, {params: []})
26
+ assert_equal "v", c.params[:k]
27
+ assert_equal "v", c.params["k"]
23
28
  end
24
29
 
25
30
  end
@@ -0,0 +1,9 @@
1
+ require "test/unit"
2
+
3
+ require_relative "../lib/nephos-server"
4
+
5
+ require_relative 'functional/generator'
6
+ require_relative 'functional/server'
7
+ require_relative 'functional/global'
8
+
9
+ require_relative 'functional/router'
File without changes
@@ -0,0 +1,6 @@
1
+ class TestGlobal < Test::Unit::TestCase
2
+
3
+ def test_simpe_requests_on_app
4
+ end
5
+
6
+ end
@@ -0,0 +1,37 @@
1
+ class TestNephosServerBinServer < Test::Unit::TestCase
2
+
3
+ def test_daemon
4
+ # WARNING: be sure there is no instance before running theses tests
5
+
6
+ # test start and kill
7
+ `./bin/nephos-server --test -d`
8
+ assert_equal 0, $?.exitstatus
9
+ `./bin/nephos-server --test -k`
10
+ assert_equal 0, $?.exitstatus
11
+
12
+ # test kill after killed
13
+ `./bin/nephos-server --test -k`
14
+ assert_equal 1, $?.exitstatus
15
+ `./bin/nephos-server --test -k`
16
+ assert_equal 1, $?.exitstatus
17
+
18
+ # test start after killed
19
+ `./bin/nephos-server --test -d`
20
+ assert_equal 0, $?.exitstatus
21
+
22
+ # test start after started
23
+ `./bin/nephos-server --test -d`
24
+ assert_equal 1, $?.exitstatus
25
+ `./bin/nephos-server --test -d`
26
+ assert_equal 1, $?.exitstatus
27
+
28
+ # test kill after started N times
29
+ `./bin/nephos-server --test -k`
30
+ assert_equal 0, $?.exitstatus
31
+
32
+ # test kill after started N times and then killed
33
+ `./bin/nephos-server --test -k`
34
+ assert_equal 1, $?.exitstatus
35
+ end
36
+
37
+ end
data/test/responder.rb CHANGED
@@ -3,7 +3,7 @@ class TestNephosServerResponder < Test::Unit::TestCase
3
3
  def test_content_type
4
4
  assert_equal(
5
5
  "KIND/TYPE" "; charset=" "CHARSET",
6
- Nephos::Responder.content_type("KIND", "TYPE", "CHARSET")
6
+ Nephos::Responder.new.content_type("KIND", "TYPE", "CHARSET")
7
7
  )
8
8
  end
9
9
 
@@ -18,16 +18,25 @@ class TestNephosServerResponder < Test::Unit::TestCase
18
18
  p7 = {type: []}
19
19
  p8 = {type: nil}
20
20
  p9 = {}
21
- assert Nephos::Responder.ct_specific(p0)
22
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p1) end
23
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p2) end
24
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p3) end
25
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p4) end
26
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p5) end
27
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p6) end
28
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p7) end
29
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p8) end
30
- assert_raise Nephos::Responder::InvalidContentType do Nephos::Responder.ct_specific(p9) end
21
+ assert Nephos::Responder.new.ct_specific(p0)
22
+ assert_raise Nephos::Responder::InvalidContentType do
23
+ Nephos::Responder.new.ct_specific(p1) end
24
+ assert_raise Nephos::Responder::InvalidContentType do
25
+ Nephos::Responder.new.ct_specific(p2) end
26
+ assert_raise Nephos::Responder::InvalidContentType do
27
+ Nephos::Responder.new.ct_specific(p3) end
28
+ assert_raise Nephos::Responder::InvalidContentType do
29
+ Nephos::Responder.new.ct_specific(p4) end
30
+ assert_raise Nephos::Responder::InvalidContentType do
31
+ Nephos::Responder.new.ct_specific(p5) end
32
+ assert_raise Nephos::Responder::InvalidContentType do
33
+ Nephos::Responder.new.ct_specific(p6) end
34
+ assert_raise Nephos::Responder::InvalidContentType do
35
+ Nephos::Responder.new.ct_specific(p7) end
36
+ assert_raise Nephos::Responder::InvalidContentType do
37
+ Nephos::Responder.new.ct_specific(p8) end
38
+ assert_raise Nephos::Responder::InvalidContentType do
39
+ Nephos::Responder.new.ct_specific(p9) end
31
40
  end
32
41
 
33
42
  def test_set_default_params_status
@@ -35,10 +44,10 @@ class TestNephosServerResponder < Test::Unit::TestCase
35
44
  p2 = {status: 300}
36
45
  p3 = {status: nil}
37
46
  p4 = {}
38
- Nephos::Responder.set_default_params_status(p1)
39
- Nephos::Responder.set_default_params_status(p2)
40
- Nephos::Responder.set_default_params_status(p3)
41
- Nephos::Responder.set_default_params_status(p4)
47
+ Nephos::Responder.new.set_default_params_status(p1)
48
+ Nephos::Responder.new.set_default_params_status(p2)
49
+ Nephos::Responder.new.set_default_params_status(p3)
50
+ Nephos::Responder.new.set_default_params_status(p4)
42
51
  assert_equal({status: 200}, p1)
43
52
  assert_equal({status: 300}, p2)
44
53
  assert_equal({status: 200}, p3)
@@ -46,15 +55,15 @@ class TestNephosServerResponder < Test::Unit::TestCase
46
55
  end
47
56
 
48
57
  def test_set_default_params_type_1
49
- p_ref = {type: Nephos::Responder.ct_specific({type: "text/plain"})}
58
+ p_ref = {type: Nephos::Responder.new.ct_specific({type: "text/plain"})}
50
59
  p1 = {type: "text/plain"}
51
60
  p2 = {type: "text"}
52
61
  p3 = {type: "text/plain"}
53
- Nephos::Responder.set_default_params_type(p1)
62
+ Nephos::Responder.new.set_default_params_type(p1)
54
63
  assert_equal p1, p_ref
55
64
  assert_raise Nephos::Responder::InvalidContentType do
56
- Nephos::Responder.set_default_params_type(p2) end
57
- Nephos::Responder.set_default_params_type(p3)
65
+ Nephos::Responder.new.set_default_params_type(p2) end
66
+ Nephos::Responder.new.set_default_params_type(p3)
58
67
  assert_equal p_ref, p3
59
68
  end
60
69
 
@@ -64,14 +73,14 @@ class TestNephosServerResponder < Test::Unit::TestCase
64
73
  p3 = {json: "bla", plain: "bla"}
65
74
  p4 = {json: "bla", html: "bla"}
66
75
  p5 = {json: "bla"}
67
- Nephos::Responder.set_default_params_type(p1)
68
- Nephos::Responder.set_default_params_type(p2)
69
- Nephos::Responder.set_default_params_type(p3)
70
- Nephos::Responder.set_default_params_type(p4)
71
- Nephos::Responder.set_default_params_type(p5)
72
- plain = Nephos::Responder.ct_specific({type: "text/plain"})
73
- json = Nephos::Responder.ct_specific({type: "application/json"})
74
- html = Nephos::Responder.ct_specific({type: "text/html"})
76
+ Nephos::Responder.new.set_default_params_type(p1)
77
+ Nephos::Responder.new.set_default_params_type(p2)
78
+ Nephos::Responder.new.set_default_params_type(p3)
79
+ Nephos::Responder.new.set_default_params_type(p4)
80
+ Nephos::Responder.new.set_default_params_type(p5)
81
+ plain = Nephos::Responder.new.ct_specific({type: "text/plain"})
82
+ json = Nephos::Responder.new.ct_specific({type: "application/json"})
83
+ html = Nephos::Responder.new.ct_specific({type: "text/html"})
75
84
  assert_equal plain, p1[:type]
76
85
  assert_equal html, p2[:type]
77
86
  assert_equal json, p3[:type]
@@ -80,13 +89,13 @@ class TestNephosServerResponder < Test::Unit::TestCase
80
89
  end
81
90
 
82
91
  def test_render_simple
83
- r1 = Nephos::Responder.render(:empty)
84
- r2 = Nephos::Responder.render(200)
85
- r3 = Nephos::Responder.render(201)
86
- r4 = Nephos::Responder.render(status: 202)
87
- r5 = Nephos::Responder.render(plain: "")
88
- r6 = Nephos::Responder.render(json: "")
89
- r7 = Nephos::Responder.render(html: "")
92
+ r1 = Nephos::Responder.new.render(:empty)
93
+ r2 = Nephos::Responder.new.render(200)
94
+ r3 = Nephos::Responder.new.render(201)
95
+ r4 = Nephos::Responder.new.render(status: 202)
96
+ r5 = Nephos::Responder.new.render(plain: "")
97
+ r6 = Nephos::Responder.new.render(json: "")
98
+ r7 = Nephos::Responder.new.render(html: "")
90
99
  assert_equal(204, r1.status)
91
100
  assert_equal(200, r2.status)
92
101
  assert_equal(201, r3.status)
@@ -97,9 +106,9 @@ class TestNephosServerResponder < Test::Unit::TestCase
97
106
  end
98
107
 
99
108
  def test_render_advanced
100
- r1 = Nephos::Responder.render(status: 201, plain: "plaaaain")
101
- r2 = Nephos::Responder.render(status: 201, json: {data: [1, 2]})
102
- r3 = Nephos::Responder.render(status: 201, html: "<p>p</p>")
109
+ r1 = Nephos::Responder.new.render(status: 201, plain: "plaaaain")
110
+ r2 = Nephos::Responder.new.render(status: 201, json: {data: [1, 2]})
111
+ r3 = Nephos::Responder.new.render(status: 201, html: "<p>p</p>")
103
112
  assert_equal(201, r1.status)
104
113
  assert_equal("text/plain; charset=UTF-8", r1["Content-type"])
105
114
  assert_equal(["plaaaain"], r1.body)
data/test/router.rb CHANGED
@@ -20,6 +20,21 @@ class TestNephosServerRouter < Test::Unit::TestCase
20
20
  Nephos::Router::ROUTES.first
21
21
  end
22
22
 
23
+ def test_init_router
24
+ r1= Nephos::Router.new
25
+ r2= Nephos::Router.new({})
26
+ r3= Nephos::Router.new({silent: false})
27
+ r4= Nephos::Router.new({silent: true})
28
+ assert r1
29
+ assert_equal(false, r1.instance_variable_get(:@silent))
30
+ assert r2
31
+ assert_equal(false, r2.instance_variable_get(:@silent))
32
+ assert r3
33
+ assert_equal(false, r3.instance_variable_get(:@silent))
34
+ assert r4
35
+ assert_equal(true, r4.instance_variable_get(:@silent))
36
+ end
37
+
23
38
  def test_multi_routes
24
39
  reset_routes!
25
40
  get url: "/a", controller: "TestController", method: "method", silent: true
@@ -44,7 +59,7 @@ class TestNephosServerRouter < Test::Unit::TestCase
44
59
  assert_equal "GET", first[:verb]
45
60
  assert_equal "TestController", first[:controller]
46
61
  assert_equal "method", first[:method]
47
- assert_equal /^\/$/, first[:match]
62
+ assert_equal /^\/\/*$/, first[:match]
48
63
 
49
64
  reset_routes!
50
65
  post url: "/", controller: "TestController", method: "method", silent: true
@@ -52,7 +67,7 @@ class TestNephosServerRouter < Test::Unit::TestCase
52
67
  assert_equal "POST", first[:verb]
53
68
  assert_equal "TestController", first[:controller]
54
69
  assert_equal "method", first[:method]
55
- assert_equal /^\/$/, first[:match]
70
+ assert_equal /^\/\/*$/, first[:match]
56
71
 
57
72
  reset_routes!
58
73
  put url: "/", controller: "TestController", method: "method", silent: true
@@ -60,14 +75,14 @@ class TestNephosServerRouter < Test::Unit::TestCase
60
75
  assert_equal "PUT", first[:verb]
61
76
  assert_equal "TestController", first[:controller]
62
77
  assert_equal "method", first[:method]
63
- assert_equal /^\/$/, first[:match]
78
+ assert_equal /^\/\/*$/, first[:match]
64
79
  end
65
80
 
66
81
  def test_valid_routes_params
67
82
  reset_routes!
68
83
  get url: "/:what", controller: "TestController", method: "method", silent: true
69
84
  assert_equal "/:what", first[:url]
70
- assert_equal /^\/[^\/]+$/, first[:match]
85
+ assert_equal /^\/[^\/]+\/*$/, first[:match]
71
86
  end
72
87
 
73
88
  def test_valid_resources
@@ -87,7 +102,7 @@ class TestNephosServerRouter < Test::Unit::TestCase
87
102
  get url: "/:what", controller: "TestController", method: "method", silent: true
88
103
  end
89
104
  assert_equal "/home/:what", first[:url]
90
- assert_equal /^\/home\/[^\/]+$/, first[:match]
105
+ assert_equal /^\/home\/[^\/]+\/*$/, first[:match]
91
106
  end
92
107
 
93
108
  def test_valid_resources_params2
@@ -96,46 +111,75 @@ class TestNephosServerRouter < Test::Unit::TestCase
96
111
  get url: "/show", controller: "TestController", method: "method", silent: true
97
112
  end
98
113
  assert_equal "/:id/show", first[:url]
99
- assert_equal /^\/[^\/]+\/show$/, first[:match]
114
+ assert_equal /^\/[^\/]+\/show\/*$/, first[:match]
100
115
  end
101
116
 
117
+ REQ_GET_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index"})
118
+ REQ_POST_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"POST", "PATH_INFO"=>"/index"})
119
+ REQ_PUT_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"PUT", "PATH_INFO"=>"/index"})
120
+ REQ_GET_INDEXX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexx"})
121
+ REQ_GET_INDE = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/inde"})
122
+
102
123
  def test_routing_matching_simple
103
124
  reset_routes!
104
125
  get url: "/index", controller: "TestController", method: "method", silent: true
105
126
  post url: "/index", controller: "TestController", method: "method", silent: true
106
- assert(Nephos::Router::parse_path(["index"], "GET"))
107
- assert(Nephos::Router::parse_path(["index"], "POST"))
108
- assert(Nephos::Router::parse_path(["index"], "PUT") == nil)
109
- assert(Nephos::Router::parse_path(["indexx"], "GET") == nil)
110
- assert(Nephos::Router::parse_path(["inde"], "GET") == nil)
127
+ assert(Nephos::Router.new.find_route(REQ_GET_INDEX))
128
+ assert(Nephos::Router.new.find_route(REQ_POST_INDEX))
129
+ assert(!Nephos::Router.new.find_route(REQ_PUT_INDEX))
130
+ assert(!Nephos::Router.new.find_route(REQ_GET_INDEXX))
131
+ assert(!Nephos::Router.new.find_route(REQ_GET_INDE))
111
132
  end
112
133
 
134
+ REQ_GET_ID_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/id/index"})
135
+ REQ_GET_XXX_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/XXX/index"})
136
+ REQ_GET_ID = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/id"})
137
+ REQ_GET_XXX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/XXX"})
138
+ REQ_GET_INDEX_ID = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index/id"})
139
+
113
140
  def test_routing_matching_simple_with_arguments1
114
141
  reset_routes!
115
142
  get url: "/:id", controller: "TestController", method: "method1", silent: true
116
143
  get url: "/:id/index", controller: "TestController", method: "method2", silent: true
117
- assert(Nephos::Router::parse_path(["id", "index"], "GET"))
118
- assert(Nephos::Router::parse_path(["XXX", "index"], "GET"))
119
- assert(Nephos::Router::parse_path(["id"], "GET"))
120
- assert(Nephos::Router::parse_path(["XXX"], "GET"))
121
- assert(Nephos::Router::parse_path(["index", "id"], "GET") == nil)
144
+ assert(Nephos::Router.new.find_route(REQ_GET_ID_INDEX))
145
+ assert(Nephos::Router.new.find_route(REQ_GET_XXX_INDEX))
146
+ assert(Nephos::Router.new.find_route(REQ_GET_ID))
147
+ assert(Nephos::Router.new.find_route(REQ_GET_XXX))
148
+ assert(!Nephos::Router.new.find_route(REQ_GET_INDEX_ID))
122
149
  end
123
150
 
151
+ REQ_GET_IDX_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/idx/index"})
152
+ REQ_GET_XXX_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/XXX/index"})
153
+ REQ_GET_ID = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/id"})
154
+ REQ_GET_XXX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/XXX"})
155
+
156
+ REQ_GET_INDEX_ID = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index/id"})
157
+ REQ_GET_INDEX_XXX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index/XXX"})
158
+ REQ_POST_INDEX_XXX_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"POST", "PATH_INFO"=>"/index/XXX/index"})
159
+
160
+ REQ_GET_INDEX_XXX_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index/XXX/index"})
161
+ REQ_POST_INDEX_XXX_ID = Rack::Request.new({"REQUEST_METHOD"=>"POST", "PATH_INFO"=>"/index/XXX/id"})
162
+ REQ_POST_INDEX_XXX_XXX = Rack::Request.new({"REQUEST_METHOD"=>"POST", "PATH_INFO"=>"/index/XXX/XXX"})
163
+
164
+ # TODO : FIX
124
165
  def test_routing_matching_simple_with_arguments2
125
166
  reset_routes!
126
167
  get url: "/index", controller: "TestController", method: "method1", silent: true
127
168
  get url: "/index/:id", controller: "TestController", method: "method1", silent: true
128
169
  post url: "/index/:id/index", controller: "TestController", method: "method2", silent: true
129
- assert(Nephos::Router::parse_path(["id", "index"], "GET") == nil)
130
- assert(Nephos::Router::parse_path(["XXX", "index"], "GET") == nil)
131
- assert(Nephos::Router::parse_path(["id"], "GET") == nil)
132
- assert(Nephos::Router::parse_path(["XXX"], "GET") == nil)
133
- assert(Nephos::Router::parse_path(["index", "id"], "GET"))
134
- assert(Nephos::Router::parse_path(["index", "XXX"], "GET"))
135
- assert(Nephos::Router::parse_path(["index", "XXX", "index"], "POST"))
136
- assert(Nephos::Router::parse_path(["index", "XXX", "index"], "GET") == nil)
137
- assert(Nephos::Router::parse_path(["index", "XXX", "id"], "POST") == nil)
138
- assert(Nephos::Router::parse_path(["index", "XXX", "XXX"], "POST") == nil)
170
+
171
+ assert(!Nephos::Router.new.find_route(REQ_GET_IDX_INDEX))
172
+ assert(!Nephos::Router.new.find_route(REQ_GET_XXX_INDEX))
173
+ assert(!Nephos::Router.new.find_route(REQ_GET_ID))
174
+ assert(!Nephos::Router.new.find_route(REQ_GET_XXX))
175
+
176
+ assert(Nephos::Router.new.find_route(REQ_GET_INDEX_ID))
177
+ assert(Nephos::Router.new.find_route(REQ_GET_INDEX_XXX))
178
+ assert(Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_INDEX))
179
+
180
+ assert(!Nephos::Router.new.find_route(REQ_GET_INDEX_XXX_INDEX))
181
+ assert(!Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_ID))
182
+ assert(!Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_XXX))
139
183
  end
140
184
 
141
185
  end
data/test/test.rb CHANGED
@@ -6,4 +6,3 @@ require_relative 'responder'
6
6
  require_relative 'router'
7
7
  require_relative 'controller'
8
8
  require_relative 'params'
9
- require_relative 'generator'
data/version CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.6.1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nephos-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - poulet_a
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-26 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nomorebeer
@@ -109,7 +109,10 @@ files:
109
109
  - nephos-server.gemspec
110
110
  - routes.rb
111
111
  - test/controller.rb
112
- - test/generator.rb
112
+ - test/functional.rb
113
+ - test/functional/generator.rb
114
+ - test/functional/global.rb
115
+ - test/functional/server.rb
113
116
  - test/params.rb
114
117
  - test/responder.rb
115
118
  - test/router.rb
@@ -138,7 +141,7 @@ rubyforge_project:
138
141
  rubygems_version: 2.4.8
139
142
  signing_key:
140
143
  specification_version: 4
141
- summary: "* fix regression on empty response * add unitary tests * improve gemspec
142
- * fix severe regression on responder * fix environment bug"
144
+ summary: "* Improve daemons * Improve Rakefile and tests structure * Add few functional
145
+ (router, server, generator) tests * Add new unitary tests"
143
146
  test_files: []
144
147
  has_rdoc: