tynn 2.0.0.alpha → 2.0.0.beta1

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.
@@ -7,7 +7,7 @@ class SecureHeadersTest < Minitest::Test
7
7
  HEADERS = Tynn::SecureHeaders::HEADERS
8
8
 
9
9
  def setup
10
- @app = Class.new(Tynn)
10
+ @app = new_app
11
11
  end
12
12
 
13
13
  def test_dont_override_default_headers
@@ -5,22 +5,22 @@ require_relative "../lib/tynn/session"
5
5
 
6
6
  class SessionTest < Minitest::Test
7
7
  def setup
8
- @app = Class.new(Tynn)
8
+ @app = new_app
9
9
  end
10
10
 
11
11
  def test_raise_error_if_secret_is_empty
12
- assert_raises { @app.plugin(Tynn::Session) }
12
+ assert_raises(Tynn::Error) { @app.plugin(Tynn::Session) }
13
13
  end
14
14
 
15
15
  def test_raise_error_if_secret_is_short
16
- assert_raises { @app.plugin(Tynn::Session, secret: "__not_secure__") }
16
+ assert_raises(Tynn::Error) { @app.plugin(Tynn::Session, secret: "__not_secure__") }
17
17
  end
18
18
 
19
19
  def test_set_and_get_session
20
20
  @app.plugin(Tynn::Session, secret: SecureRandom.hex(64))
21
21
 
22
22
  @app.define do
23
- get do
23
+ on get do
24
24
  session[:foo] = "foo"
25
25
 
26
26
  res.write(session[:foo])
@@ -30,7 +30,7 @@ class SessionTest < Minitest::Test
30
30
  ts = Tynn::Test.new(@app)
31
31
  ts.get("/")
32
32
 
33
- assert_equal "foo", ts.res.body
33
+ assert_equal "foo", ts.res.body.join
34
34
  assert_equal "foo", ts.req.session["foo"]
35
35
  end
36
36
 
@@ -38,7 +38,7 @@ class SessionTest < Minitest::Test
38
38
  @app.plugin(Tynn::Session, secret: SecureRandom.hex(64))
39
39
 
40
40
  @app.define do
41
- get do
41
+ on get do
42
42
  session[:foo] = "foo"
43
43
  end
44
44
  end
@@ -4,7 +4,7 @@ require_relative "helper"
4
4
 
5
5
  class SettingsTest < Minitest::Test
6
6
  def setup
7
- @app = Class.new(Tynn)
7
+ @app = new_app
8
8
  end
9
9
 
10
10
  def test_set_and_get
@@ -39,8 +39,8 @@ class SettingsTest < Minitest::Test
39
39
  def test_inheritance
40
40
  @app.set(:foo, "foo")
41
41
 
42
- @child1 = Class.new(@app)
43
- @child2 = Class.new(@child1)
42
+ @child1 = new_app(parent: @app)
43
+ @child2 = new_app(parent: @child1)
44
44
 
45
45
  assert_equal "foo", @child1.settings[:foo]
46
46
  assert_equal "foo", @child2.settings[:foo]
@@ -5,7 +5,7 @@ require_relative "../lib/tynn/ssl"
5
5
 
6
6
  class SSLTest < Minitest::Test
7
7
  def setup
8
- @app = Class.new(Tynn)
8
+ @app = new_app
9
9
  end
10
10
 
11
11
  def test_redirect_to_https
@@ -65,7 +65,7 @@ class SSLTest < Minitest::Test
65
65
  ts.get("/", {}, "HTTPS" => "on")
66
66
 
67
67
  assert_equal 200, ts.res.status
68
- assert_equal "secure", ts.res.body
68
+ assert_equal "secure", ts.res.body.join
69
69
  end
70
70
 
71
71
  def test_set_hsts_header_with_defaults
@@ -113,7 +113,7 @@ class SSLTest < Minitest::Test
113
113
  @app.plugin(Tynn::SSL, hsts: false)
114
114
 
115
115
  @app.define do
116
- get do
116
+ on get do
117
117
  res.set_cookie("first", "cookie", secure: false)
118
118
  res.set_cookie("other", "cookie", http_only: true)
119
119
  res.set_cookie("secure", "cookie", secure: true)
@@ -5,7 +5,7 @@ require_relative "../lib/tynn/static"
5
5
 
6
6
  class StaticTest < Minitest::Test
7
7
  def setup
8
- @app = Class.new(Tynn)
8
+ @app = new_app
9
9
  end
10
10
 
11
11
  def test_serve_static_files_ok
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tynn
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Rodriguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-16 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.x
27
27
  - !ruby/object:Gem::Dependency
28
- name: syro
28
+ name: seg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
33
+ version: '0.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.1'
40
+ version: '0.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: erubis
42
+ name: hmote
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.7'
47
+ version: '1.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.7'
54
+ version: '1.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '11.0'
83
- - !ruby/object:Gem::Dependency
84
- name: tilt
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.0'
97
83
  description: A thin library for web development in Ruby
98
84
  email: hello@frodsan.com
99
85
  executables: []
@@ -104,18 +90,18 @@ files:
104
90
  - README.md
105
91
  - lib/tynn.rb
106
92
  - lib/tynn/base.rb
107
- - lib/tynn/default_headers.rb
108
93
  - lib/tynn/environment.rb
94
+ - lib/tynn/errors.rb
109
95
  - lib/tynn/json.rb
110
96
  - lib/tynn/render.rb
111
97
  - lib/tynn/request.rb
112
98
  - lib/tynn/response.rb
113
99
  - lib/tynn/secure_headers.rb
114
100
  - lib/tynn/session.rb
115
- - lib/tynn/settings.rb
116
101
  - lib/tynn/ssl.rb
117
102
  - lib/tynn/static.rb
118
103
  - lib/tynn/test.rb
104
+ - lib/tynn/utils.rb
119
105
  - lib/tynn/version.rb
120
106
  - test/default_headers_test.rb
121
107
  - test/environment_test.rb
@@ -125,6 +111,8 @@ files:
125
111
  - test/plugin_test.rb
126
112
  - test/render_test.rb
127
113
  - test/request_headers_test.rb
114
+ - test/request_test.rb
115
+ - test/response_test.rb
128
116
  - test/routing_test.rb
129
117
  - test/secure_headers_test.rb
130
118
  - test/session_test.rb
@@ -164,6 +152,8 @@ test_files:
164
152
  - test/plugin_test.rb
165
153
  - test/render_test.rb
166
154
  - test/request_headers_test.rb
155
+ - test/request_test.rb
156
+ - test/response_test.rb
167
157
  - test/routing_test.rb
168
158
  - test/secure_headers_test.rb
169
159
  - test/session_test.rb
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Tynn
4
- # Adds support to set default headers for responses.
5
- #
6
- # require "tynn"
7
- # require "tynn/test"
8
- #
9
- # Tynn.set(:default_headers, {
10
- # "Content-Type" => "application/json"
11
- # })
12
- #
13
- # Tynn.define { }
14
- #
15
- # app = Tynn::Test.new
16
- # app.get("/")
17
- #
18
- # app.res.headers
19
- # # => { "Content-Type" => "application/json" }
20
- #
21
- # This plugin is included by default.
22
- #
23
- module DefaultHeaders
24
- def self.setup(app) # :nodoc:
25
- app.set(:default_headers, {})
26
- end
27
-
28
- module ClassMethods
29
- # Returns a Hash with the default headers.
30
- #
31
- # Tynn.set(:default_headers, {
32
- # "Content-Type" => "application/json"
33
- # })
34
- #
35
- # Tynn.default_headers["Content-Type"]
36
- # # => "application/json"
37
- #
38
- def default_headers
39
- settings[:default_headers]
40
- end
41
- end
42
-
43
- module InstanceMethods # :nodoc:
44
- # Overrides Syro's default implementation of default headers.
45
- def default_headers
46
- Hash[self.class.default_headers]
47
- end
48
- end
49
- end
50
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Tynn
4
- # It provides a settings API for applications and plugins.
5
- #
6
- # require "tynn"
7
- #
8
- # module AppName
9
- # def self.setup(app, app_name)
10
- # app.settings[:app_name] = app_name
11
- # end
12
- #
13
- # module ClassMethods
14
- # def app_name
15
- # settings[:app_name]
16
- # end
17
- # end
18
- # end
19
- #
20
- # Tynn.plugin(AppName, "MyApp")
21
- #
22
- # Tynn.app_name
23
- # # => "MyApp"
24
- #
25
- # Tynn.set(:app_name, "MyAwesomeApp")
26
- #
27
- # Tynn.app_name
28
- # # => "MyAwesomeApp"
29
- #
30
- # # This plugin is included by default.
31
- #
32
- module Settings
33
- def self.deepclone(hash) # :nodoc:
34
- default_proc, hash.default_proc = hash.default_proc, nil
35
-
36
- Marshal.load(Marshal.dump(hash))
37
- ensure
38
- hash.default_proc = default_proc
39
- end
40
-
41
- module ClassMethods
42
- # Copies settings into the subclass. If a setting is not found,
43
- # checks parent's settings.
44
- def inherited(subclass) # :nodoc:
45
- subclass.settings.replace(Tynn::Settings.deepclone(settings))
46
- subclass.settings.default_proc = proc { |h, k| h[k] = settings[k] }
47
- end
48
-
49
- # Returns a Hash with the application settings.
50
- #
51
- # Tynn.set(:environment, :development)
52
- #
53
- # Tynn.settings
54
- # # => { :environment => :development }
55
- #
56
- def settings
57
- @settings ||= {}
58
- end
59
-
60
- # Sets an <tt>option</tt> to the given </tt>value</tt>. If a setting
61
- # with the <tt>option</tt> key exists and is a hash value, it merges
62
- # the stored hash with <tt>value</tt>.
63
- #
64
- # Tynn.set(:environment, :staging)
65
- #
66
- # Tynn.settings[:environment]
67
- # # => :staging
68
- #
69
- # Tynn.default_headers
70
- # # => { "Content-Type" => "text/html" }
71
- #
72
- # Tynn.set(:default_headers, "X-Frame-Options" => "DENY")
73
- #
74
- # Tynn.default_headers
75
- # # => { "Content-Type" => "text/html", "X-Frame-Options" => "DENY" }
76
- #
77
- def set(option, value)
78
- v = settings[option]
79
-
80
- if Hash === v
81
- set!(option, v.merge(value))
82
- else
83
- set!(option, value)
84
- end
85
- end
86
-
87
- # Sets an <tt>option</tt> to the given </tt>value</tt>.
88
- #
89
- # Tynn.set!(:environment, :staging)
90
- #
91
- # Tynn.settings[:environment]
92
- # # => :staging
93
- #
94
- # Tynn.default_headers
95
- # # => { "Content-Type" => "text/html" }
96
- #
97
- # Tynn.set!(:default_headers, "X-Frame-Options" => "DENY")
98
- #
99
- # Tynn.default_headers
100
- # # => { "X-Frame-Options" => "DENY" }
101
- #
102
- def set!(option, value)
103
- settings[option] = value
104
- end
105
- end
106
- end
107
- end