nephos-server 0.5.2 → 0.5.4

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: 0339bf695959f0e5b19b9b73609e561dfb496f23
4
- data.tar.gz: ed4d9148e39b2540a88d5160d38dfe8d36499d3a
3
+ metadata.gz: 1e8ff75ee49a1ab28b80920721ad356542a82547
4
+ data.tar.gz: 54a400165ee4401da84a727cf8e95ed2992d3a6a
5
5
  SHA512:
6
- metadata.gz: db650e2505b3f6a3b54efdfc5d1dfa4da006bed596f54a2b615928c0f676dd626da8a2c6a49073914080566254ddc325cc6d27291c4d09f8e19a82a94fdc1c4a
7
- data.tar.gz: 6a05e3f8d9d0ece9e41faf43218e6741f30b29246add62032094a7650217a68f5186736e8d358a1e0e8ae52374cf566c4c23259c29919c72440f9e7d8491039a
6
+ metadata.gz: 0660a8e017d4824933c80dee460daa445f16a544a7fca14372849a867561e8b028650fd8dc7fe0988434e1d031e018f92699a2f89572a079ecfc646daad1d3e9
7
+ data.tar.gz: f17a9dafdc7d4d1bb976c099f078c1439a5037c0586fd2abf9a800c97c91ec0744c293b528e240c16b32f6372ddab435d74259a0b22528c4bf3e9b5b38aa9b75
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ v0.5.4
2
+ * fix regression on empty response
3
+ * add unitary tests
4
+ * improve gemspec
5
+ * fix severe regression on responder
6
+ * fix environment bug
7
+
8
+ v0.5.3
9
+ * add continuous integration with gitlab
10
+ * fix executables requirements to be testable
11
+ * add cookies management
12
+
1
13
  v0.5.2
2
14
  * fix regression on content-type from v0.4
3
15
 
@@ -0,0 +1,109 @@
1
+ # Render API
2
+
3
+ ## Understand the API
4
+
5
+ The render API is a simple system to allows you to render HTTP responses to a client.
6
+ The API allows you to customize differents parts of the response:
7
+
8
+ - HTTP status
9
+ - HTTP Content-Type
10
+ - Content
11
+
12
+ The API use the returns of the Controllers methods to build the HTTP responses.
13
+
14
+
15
+ ## Use the API
16
+
17
+ To use the API, you have to create a new controller.
18
+ The controller must be placed or requires in the ``app/`` directory,
19
+ via a ``file.rb`` file.
20
+ It must contain a class, wich inherit from ``Nephos::Controller``.
21
+ Each public method can be an entry point, defined in the ``routes.rb`` file.
22
+ [Routing doc](GUIDE_ROUTING.md).
23
+
24
+ In the controller, you can use few helpers,
25
+ like the method ``params()``, ``env()``, and ``infos()``
26
+
27
+ The methods used as entry point must return a ``Hash`` described in the following lines.
28
+ It may optionnaly be an ``Integer``, to return only a status, or ``:empty``.
29
+
30
+ ## Options
31
+
32
+ The returns of a Controller method can include the following keys:
33
+
34
+ - :plain
35
+ - :html
36
+ - :json
37
+ - :content
38
+ - :type
39
+ - :status
40
+
41
+ Example:
42
+
43
+ ```ruby
44
+ class MyController < Nephos::Controller
45
+ def create
46
+ return {json: {id: 1, name: "Data"}, status: 201}
47
+ end
48
+ def index
49
+ return {type: "text/plain", content: "All your data"}
50
+ end
51
+ def coucou
52
+ return {status: 404}
53
+ end
54
+ end
55
+ ```
56
+
57
+ The following sections will describe how each key works and modify the HTTP response.
58
+
59
+ ### Content
60
+
61
+ The ``:content`` key must be associated with a ``String`` (or ``Hash`` is json).
62
+
63
+ **Optionnal**:
64
+ a default value is provided, based on the ``:status`` if no ``:content`` if specified.
65
+
66
+ ### Type
67
+
68
+ The ``:type`` key has to be associated with a ``String`` matching with **"kind/type"**.
69
+
70
+ **Optionnal**:
71
+ the default value is ``text/plain``
72
+
73
+ Kinds and Types (called type and sub-type by w3c) are described here:
74
+ [the w3c documentation](http://www.w3.org/Protocols/rfc1341/4_Content-Type.html)
75
+
76
+ #### Kind:
77
+
78
+ - image
79
+ - text
80
+ - ...
81
+
82
+ #### Type:
83
+
84
+ - plain
85
+ - javascript
86
+ - jpeg
87
+ - ...
88
+
89
+
90
+ ### Status
91
+
92
+ The ``:status`` key is associable with an Integer. It must represent the HTTP status code.
93
+
94
+ **Optionnal**:
95
+ The default value is 200.
96
+
97
+ [The complete HTTP status code list](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)
98
+
99
+
100
+ ### Plain, HTML, JSON
101
+
102
+ The keys ``:plain``, ``:html``, ``:json`` can replace both ``:content`` ``:type``.
103
+ It is associated like ``:content`` and **replace automaticaly the type**.
104
+
105
+ key | type
106
+ ---|---
107
+ :plain|text/plain
108
+ :html|text/html
109
+ :json|text/javascript
@@ -0,0 +1,21 @@
1
+ # Sequel
2
+
3
+ Sequel is an orm and database connector.
4
+ It is easy to use and configure.
5
+
6
+ It handles connection with DB, sql request creation, caching, etc.
7
+
8
+ [Sequel documentation](http://sequel.jeremyevans.net/documentation.html)
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ gem install sequel
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ require 'sequel'
20
+ DB = Sequel.connect(ENV['DATABASE_URL'])
21
+ ```
@@ -0,0 +1,7 @@
1
+ # Controller Guide
2
+
3
+ ## Intern architecture
4
+
5
+ ### Cookies
6
+
7
+ You can set cookies and get them via ``cookies`` in the body of the controller.
@@ -0,0 +1,44 @@
1
+ # Generator Guide
2
+
3
+ The ``ngenerator`` is a lite application designed to make easier the application management.
4
+
5
+ Actually, it allows you to create new application and controller.
6
+
7
+ ## Usage
8
+
9
+ ```bash
10
+ ngenerator --mode <options>
11
+ ```
12
+
13
+ ### Generate new application
14
+
15
+ ```bash
16
+ ngenerator --application <name>
17
+ ```
18
+
19
+ Create a directory name ``<name>``, initialize a git repository and create basic files.
20
+
21
+ ### Generate new controller
22
+
23
+ ```bash
24
+ ngenerator --controller <name>
25
+ ```
26
+
27
+ Generate a file ``/app/<downcasename_controller.rb>`` with a class named ``CapitalizeNameController`` inherited by ``Nephos::Controller``.
28
+
29
+ ### Generate new route
30
+
31
+ ```bash
32
+ ngenerator --route VERB "/url" "Controller#Method" # or also
33
+ ngenerator --route VERB "/url" Controller Method
34
+ ```
35
+
36
+ Generate a new route based on the parameters, added to the ``routes.rb`` file.
37
+
38
+ ### Remove a route
39
+
40
+ ```bash
41
+ ngenerator --rm --route VERB "/url" "Controller#Method"
42
+ ```
43
+
44
+ It will remove a route, generator by the generator, from the ``routes.rb`` file.
@@ -0,0 +1,67 @@
1
+ # Routing Guide
2
+
3
+ ## How the routes are inputed by the client ?
4
+
5
+ Each HTTP request made by the client will contains a **REQUEST_URI** value.
6
+ The web server receive this information, and will choose what to do,
7
+ based on the rules you will define.
8
+
9
+ ## How to define the rules ?
10
+
11
+ You have to write the rules in the ``/routes.rb`` file.
12
+ Few helpers are provided to make the job easier.
13
+ They will be described in the following section.
14
+
15
+ ## The helpers
16
+
17
+ As every HTTP request requires an HTTP verb, there is 4 helpers to handle them.
18
+ ``get``, ``post``, ``put``, ``add_route``. Indeed, there is 3 main verbs (GET POST PUT).
19
+ But as you can need to create other verbs (DELETE, PATCH, ...), we allows you to handle them.
20
+
21
+ ### add_route
22
+
23
+ The method ``add_route`` take 2 arguments.
24
+
25
+ 1. verb (has to be a string, upcase as possible, like **GET**)
26
+ 2. option (a **Hash** with 3 required keys)
27
+
28
+ The option argument must contains the 3 following keys:
29
+
30
+ - ``:url``: the url to handle (client input)
31
+ - ``:controller``: the controller to use
32
+ - ``:method``: the method of the controller that will be used to compute and render a result to the client.
33
+
34
+ As example, yuo can write:
35
+
36
+ ```ruby
37
+ add_route "GET", url: "/tmp", controller: "MyController", method: "tmp"
38
+ ```
39
+
40
+ ### get post put
41
+
42
+ Theses 3 helpers allows you to use ``add_route`` without the first argument.
43
+
44
+ ### resource
45
+
46
+ This method takes 1 parameter and 1 block.
47
+ The parameter is a partial url, and the bloc, other routes.
48
+
49
+ Resource can be chained many times.
50
+ For Example, you can do this:
51
+
52
+ ```ruby
53
+ resource "user" do
54
+ resource "informations" do
55
+ get url: "/index", controller: "UserController", method: "show" # /user/informations/index
56
+ end
57
+ end
58
+ ```
59
+
60
+ It will generate the route ``/home/index``, calling the ``MainController#root`` method.
61
+
62
+
63
+ ## URL Parameters
64
+
65
+ **TODO**
66
+
67
+ place a ``/:param`` in your route. The parameter will be placed in the controller in the ``params`` method
@@ -0,0 +1,20 @@
1
+ # Slim
2
+
3
+ Slim is a HTML templating langage, simple to implement in the Nephos Server.
4
+ [Slim documentation](http://slim-lang.com)
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ gem install slim
10
+ ```
11
+
12
+ ## Usage in Nephos Server
13
+
14
+ ```ruby
15
+ class UserController < Nephos::Controller
16
+ def show
17
+ #TODO: read a file, use slim with parameters
18
+ end
19
+ end
20
+ ```
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Nephos Ruby Server
2
2
 
3
+ [![Gitlab Tests](https://gitlab.com/ci/projects/8973/status.png?ref=master)](https://gitlab.com/ci/projects/8973?ref=master)
4
+
3
5
  [![GitHub version](https://badge.fury.io/gh/pouleta%2FNephosRubyServer.svg)](http://badge.fury.io/gh/pouleta%2FNephosRubyServer)
4
6
 
5
7
  [![Gem Version](https://badge.fury.io/rb/nephos-server.svg)](http://badge.fury.io/rb/nephos-server)
@@ -51,6 +53,7 @@ Theses guides will provide you knowlegde about everything you can use in the app
51
53
  - [Generator GUIDE](DOCUMENTATION/GUIDE_GENERATOR.md)
52
54
  - [Render API](DOCUMENTATION/API_RENDER.md)
53
55
  - [Router GUIDE](DOCUMENTATION/GUIDE_ROUTER.md)
56
+ - [Controller GUIDE](DOCUMENTATION/GUIDE_CONTROLLER.md)
54
57
  - [Code documentation on RubyDoc.info](http://www.rubydoc.info/gems/nephos-server/toplevel) -> **Note: you can also generate local documentation via yard**
55
58
 
56
59
  ## Examples
@@ -68,7 +71,8 @@ The basic code of a controller can be generated via ``ngenerator controller NAME
68
71
 
69
72
  ```ruby
70
73
  class Example < Nephos::Controller
71
- def root
74
+ def root
75
+ cookies["last_visit"] = Time.now
72
76
  if params["index"] == "true"
73
77
  return {plain: "index"}
74
78
  else
@@ -114,15 +118,13 @@ end
114
118
  # Developers: Roadmap
115
119
 
116
120
  ## TODO v0.5
117
- - cookies, ...
118
- - usage of rack parsers (Rack::Request.new(env) etc.)
119
- - improved code documentation
120
121
 
121
122
  ## TODO v0.6
122
123
  - startable as daemon
123
124
  - hooks for controller
124
125
  - feature to change HTTP header from controller
125
126
  - customisable default 404 errors and 500 errors
127
+ - functionnal tests
126
128
 
127
129
  ## v1 requierements
128
130
  - Environement, Daemons, Port, Listen Host, Routables, Arguments
data/app/main.rb CHANGED
@@ -50,9 +50,23 @@ class MainController < Nephos::Controller
50
50
  end
51
51
  end
52
52
 
53
- require 'pry'
53
+ def add_cookie
54
+ cookies["UN_COOKIE_VAUT:"] = "UN BON MOMENT !"
55
+ {plain: "cookie set"}
56
+ end
57
+
58
+ def get_cookies
59
+ {json: cookies.to_h}
60
+ end
61
+
62
+ # require 'pry'
54
63
  def debug
55
- binding.pry
64
+ # binding.pry
65
+ {}
66
+ end
67
+
68
+ def err500
69
+ tessssssssss
56
70
  end
57
71
 
58
72
  end
data/bin/nephos-generator CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'colorize'
4
4
  require 'optparse'
5
5
 
6
- require 'nephos-server/version'
7
- require 'nephos-server/bin-helpers'
6
+ require_relative '../lib/nephos-server/version'
7
+ require_relative '../lib/nephos-server/bin-helpers'
8
8
 
9
9
  GEMFILE = <<EOF
10
10
  source 'https://rubygems.org'
data/bin/nephos-server CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'colorize'
4
4
  require 'optparse'
5
5
 
6
- require 'nephos-server/version'
7
- require 'nephos-server/bin-helpers'
6
+ require_relative '../lib/nephos-server/bin-helpers'
7
+ require_relative '../lib/nephos-server/version'
8
8
 
9
9
  class RoutingError < StandardError; end
10
10
 
@@ -37,6 +37,8 @@ begin
37
37
 
38
38
  end.parse!
39
39
 
40
+ Nephos.env = $server_env
41
+
40
42
  Dir.chdir(opts[0]) if not opts.empty?
41
43
 
42
44
  if $test
data/bin/nephos-status CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'colorize'
4
4
  require 'optparse'
5
5
 
6
- require 'nephos-server/version'
7
- require 'nephos-server/bin-helpers'
6
+ require_relative '../lib/nephos-server/version'
7
+ require_relative '../lib/nephos-server/bin-helpers'
8
8
 
9
9
  opt = OptionParser.new do |opts|
10
10
  opts.banner = "Usage<#{Nephos::VERSION}>: nephos-status [appli directory]"
@@ -7,6 +7,7 @@ module Nephos
7
7
  class Controller
8
8
 
9
9
  attr_reader :env, :infos, :callpath, :params, :cookies
10
+ attr_reader :req
10
11
 
11
12
  # @param env [Hash] env extracted from the http request
12
13
  # @param parsed [Hash] pre-parsed env with parameters, ...
@@ -18,13 +19,14 @@ module Nephos
18
19
  raise ArgumentError, "Invalid Parsed. :params must be associated with a Hash" unless parsed[:params].is_a? Hash
19
20
  raise ArgumentError, "Invalid Callpath. :params must be associated with an Array" unless callpath[:params].is_a? Array
20
21
  @env= env
22
+ @req= Rack::Request.new(env)
21
23
  @infos= parsed
22
24
  @callpath= callpath
23
25
  @params= parsed[:params]
24
26
  @params.merge! Hash[callpath[:params].zip @infos[:path]]
25
27
  @params.select!{|k,v| not k.to_s.empty?}
26
28
  @params = Params.new(@params)
27
- @cookies = Params.new()
29
+ @cookies = Params.new(@req.cookies)
28
30
  end
29
31
 
30
32
  end
@@ -11,11 +11,30 @@ module Nephos
11
11
 
12
12
  ROUTES = []
13
13
 
14
- # @param arg [Hash or Symbol]
14
+ # @param args Contain the controller and the method to call on it
15
15
  #
16
16
  # Shortcut to #{Nephos::Responder.render}
17
- def self.render arg
18
- Responder.render arg
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
22
+ end
23
+
24
+ def self.error(code, err=nil)
25
+ if ENV["ENVIRONMENT"].to_s.match(/prod(uction)?/)
26
+ return render(status: code)
27
+ elsif err
28
+ msg = err
29
+ if msg.is_a? Exception
30
+ msg = err.message + "\n"
31
+ msg += "--- Backtrace ---\n" + err.backtrace.join("\n") + "\n" if Nephos.env != "production"
32
+ end
33
+ return render(status: code,
34
+ content: "Error: #{code}\n#{msg}")
35
+ else
36
+ return render(status: code)
37
+ end
19
38
  end
20
39
 
21
40
  # @param path [Array]
@@ -35,19 +54,8 @@ module Nephos
35
54
  return {route: route, verb: verb, from: from, path: path, params: params}
36
55
  end
37
56
 
38
- def self.error(code, err=nil)
39
- if ENV["ENVIRONMENT"].to_s.match(/prod(uction)?/)
40
- return render(status: code)
41
- elsif err
42
- #TODO: improve this
43
- return render(status: code, content: "Error: #{code}\n" + (err.is_a?(String) ? err : err.message))
44
- else
45
- return render(status: code)
46
- end
47
- end
48
-
49
- # Interface which handle the client query (stored in env), calls the
50
- # {Controller} method (using the routes) and render it's return
57
+ # Interface which handle the client query (stored in env), create a new
58
+ # {Controller} instance, and call the render on it
51
59
  def self.execute(env)
52
60
  begin
53
61
  route = URI.parse(env['REQUEST_URI'])
@@ -61,7 +69,7 @@ module Nephos
61
69
  return error(404, "404 not found \"#{route}\"") if call.nil?
62
70
  begin
63
71
  controller = Module.const_get(call[:controller]).new(env, parsed, call)
64
- return render(controller.send(call[:method]))
72
+ return render(controller, call[:method])
65
73
  rescue => err
66
74
  return error(500, err)
67
75
  end
@@ -62,16 +62,32 @@ module Nephos
62
62
  params
63
63
  end
64
64
 
65
- # @param params [Hash, Symbol]
65
+ def self.empty_resp
66
+ resp = Rack::Response.new
67
+ resp.status = 204
68
+ resp["Content-Type"] = ct_specific({type: PRESET_CT[:plain]})
69
+ resp
70
+ end
71
+
72
+ def self.render_from_controller controller, method_to_call
73
+ params = controller.send method_to_call
74
+ resp = Responder.render(params)
75
+ controller.cookies.each do |k, v|
76
+ resp.set_cookie k, v
77
+ end
78
+ return resp
79
+ end
80
+
81
+ # @param controller [Controller]
82
+ # @param method_to_call [Symbol]
66
83
  def self.render params
67
- return [204, ct_specific({type: PRESET_CT[:plain]}), [""]] if params == :empty
84
+ return Responder.empty_resp if params == :empty
68
85
  return render(status: params) if params.is_a? Integer
69
- params = set_default_params(params)
70
86
  resp = Rack::Response.new
87
+ params = set_default_params(params)
71
88
  resp.status = params[:status]
72
89
  resp["Content-Type"] = params[:type]
73
90
  resp.body = [params[:content]]
74
- #resp.set_cookies ...
75
91
  return resp
76
92
  end
77
93
 
@@ -3,7 +3,13 @@ module Nephos
3
3
  VERSION = File.read(VERSION_FILE).strip
4
4
 
5
5
  @@env = $server_env
6
+
6
7
  def self.env
7
8
  @@env
8
9
  end
10
+
11
+ def self.env= env
12
+ @@env = env
13
+ end
14
+
9
15
  end
@@ -4,30 +4,37 @@ Gem::Specification.new do |s|
4
4
  s.date = Time.now.getgm.to_s.split.first
5
5
  s.summary = File.read("CHANGELOG").match(/^v[^\n]+\n((\t[^\n]+\n)+)/m)[1].split("\t").join
6
6
  s.description = ' a minimalist server, based on rack/puma, with routing, rendering, and controllers. Designed for quick api.'
7
- s.authors = [
8
- 'poulet_a'
9
- ]
10
- s.email = 'poulet_a@epitech.eu',
7
+ s.authors = ['poulet_a']
8
+ s.email = ['poulet_a@epitech.eu']
11
9
  s.files = %w(
12
10
  lib/nephos-server.rb
13
- lib/nephos-server/version.rb
14
11
  lib/nephos-server/basic_errors.rb
15
- lib/nephos-server/params.rb
16
- lib/nephos-server/controller.rb
17
12
  lib/nephos-server/bin-helpers.rb
18
- lib/nephos-server/server/main.rb
19
- lib/nephos-server/server/responder.rb
13
+ lib/nephos-server/controller.rb
14
+ lib/nephos-server/params.rb
20
15
  lib/nephos-server/router/main.rb
21
16
  lib/nephos-server/router/load.rb
22
17
  lib/nephos-server/router/helpers.rb
18
+ lib/nephos-server/server/main.rb
19
+ lib/nephos-server/server/responder.rb
20
+ lib/nephos-server/version.rb
21
+
23
22
  README.md
23
+ DOCUMENTATION/API_RENDER.md
24
+ DOCUMENTATION/GUIDE_CONTROLLER.md
25
+ DOCUMENTATION/GUIDE_GENERATOR.md
26
+ DOCUMENTATION/GUIDE_ROUTER.md
27
+ DOCUMENTATION/DATABASE/SEQUEL.md
28
+ DOCUMENTATION/TEMPLATING/SLIM.md
24
29
  CHANGELOG
30
+
25
31
  Rakefile
26
32
  Procfile
27
33
  Gemfile
28
34
  Gemfile.lock
29
35
  nephos-server.gemspec
30
36
  version
37
+
31
38
  test/test.rb
32
39
  test/responder.rb
33
40
  test/router.rb
@@ -35,6 +42,7 @@ test/params.rb
35
42
  test/controller.rb
36
43
  test/generator.rb
37
44
  routes.rb
45
+
38
46
  app/dataset.rb
39
47
  app/image.jpg
40
48
  app/main.rb
data/routes.rb CHANGED
@@ -20,3 +20,7 @@ get url: "/hello", controller: "MainController", method: "hello"
20
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
+
24
+ get url: "/get_cookies", controller: "MainController", method: "get_cookies"
25
+ get url: "/add_cookie", controller: "MainController", method: "add_cookie"
26
+ get url: "/err500", controller: "MainController", method: "err500"
data/test/generator.rb CHANGED
@@ -3,7 +3,7 @@ class TestNephosServerGenerator < Test::Unit::TestCase
3
3
  def test_generator_application
4
4
  `rm -rf /tmp/nephos-server-test 2> /tmp/null`
5
5
 
6
- `./bin/nephos-generator -a /tmp/nephos-server-test --no-build --no-git`
6
+ `./bin/nephos-generator --test -a /tmp/nephos-server-test --no-build --no-git`
7
7
  assert(Dir.exists? "/tmp/nephos-server-test")
8
8
  assert(File.exists? "/tmp/nephos-server-test/Gemfile")
9
9
  assert(File.exists? "/tmp/nephos-server-test/routes.rb")
data/test/responder.rb CHANGED
@@ -2,7 +2,7 @@ class TestNephosServerResponder < Test::Unit::TestCase
2
2
 
3
3
  def test_content_type
4
4
  assert_equal(
5
- {'Content-type' => "KIND/TYPE" "; charset=" "CHARSET"},
5
+ "KIND/TYPE" "; charset=" "CHARSET",
6
6
  Nephos::Responder.content_type("KIND", "TYPE", "CHARSET")
7
7
  )
8
8
  end
@@ -79,11 +79,36 @@ class TestNephosServerResponder < Test::Unit::TestCase
79
79
  assert_equal json, p5[:type]
80
80
  end
81
81
 
82
- def test_render_empty
83
- assert_equal(
84
- [204, Nephos::Responder.ct_specific({type: "text/plain"}), [""]],
85
- Nephos::Responder.render(:empty)
86
- )
82
+ 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: "")
90
+ assert_equal(204, r1.status)
91
+ assert_equal(200, r2.status)
92
+ assert_equal(201, r3.status)
93
+ assert_equal(202, r4.status)
94
+ assert_equal(200, r5.status)
95
+ assert_equal(200, r6.status)
96
+ assert_equal(200, r7.status)
97
+ end
98
+
99
+ 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>")
103
+ assert_equal(201, r1.status)
104
+ assert_equal("text/plain; charset=UTF-8", r1["Content-type"])
105
+ assert_equal(["plaaaain"], r1.body)
106
+ assert_equal(201, r2.status)
107
+ assert_equal("application/json; charset=UTF-8", r2["Content-type"])
108
+ assert_equal(["{\"data\":[1,2]}"], r2.body)
109
+ assert_equal(201, r3.status)
110
+ assert_equal("text/html; charset=UTF-8", r3["Content-type"])
111
+ assert_equal(["<p>p</p>"], r3.body)
87
112
  end
88
113
 
89
114
  end
data/version CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.4
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.2
4
+ version: 0.5.4
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-25 00:00:00.000000000 Z
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nomorebeer
@@ -70,38 +70,6 @@ description: " a minimalist server, based on rack/puma, with routing, rendering,
70
70
  controllers. Designed for quick api."
71
71
  email:
72
72
  - poulet_a@epitech.eu
73
- - - lib/nephos-server.rb
74
- - lib/nephos-server/version.rb
75
- - lib/nephos-server/basic_errors.rb
76
- - lib/nephos-server/params.rb
77
- - lib/nephos-server/controller.rb
78
- - lib/nephos-server/bin-helpers.rb
79
- - lib/nephos-server/server/main.rb
80
- - lib/nephos-server/server/responder.rb
81
- - lib/nephos-server/router/main.rb
82
- - lib/nephos-server/router/load.rb
83
- - lib/nephos-server/router/helpers.rb
84
- - README.md
85
- - CHANGELOG
86
- - Rakefile
87
- - Procfile
88
- - Gemfile
89
- - Gemfile.lock
90
- - nephos-server.gemspec
91
- - version
92
- - test/test.rb
93
- - test/responder.rb
94
- - test/router.rb
95
- - test/params.rb
96
- - test/controller.rb
97
- - test/generator.rb
98
- - routes.rb
99
- - app/dataset.rb
100
- - app/image.jpg
101
- - app/main.rb
102
- - bin/nephos-server
103
- - bin/nephos-generator
104
- - bin/nephos-status
105
73
  executables:
106
74
  - nephos-server
107
75
  - nephos-generator
@@ -110,6 +78,12 @@ extensions: []
110
78
  extra_rdoc_files: []
111
79
  files:
112
80
  - CHANGELOG
81
+ - DOCUMENTATION/API_RENDER.md
82
+ - DOCUMENTATION/DATABASE/SEQUEL.md
83
+ - DOCUMENTATION/GUIDE_CONTROLLER.md
84
+ - DOCUMENTATION/GUIDE_GENERATOR.md
85
+ - DOCUMENTATION/GUIDE_ROUTER.md
86
+ - DOCUMENTATION/TEMPLATING/SLIM.md
113
87
  - Gemfile
114
88
  - Gemfile.lock
115
89
  - Procfile
@@ -164,6 +138,7 @@ rubyforge_project:
164
138
  rubygems_version: 2.4.8
165
139
  signing_key:
166
140
  specification_version: 4
167
- summary: "* fix regression on content-type from v0.4"
141
+ summary: "* fix regression on empty response * add unitary tests * improve gemspec
142
+ * fix severe regression on responder * fix environment bug"
168
143
  test_files: []
169
144
  has_rdoc: