cuba 3.9.2 → 3.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7eab2e59d038c8c841524498b060412e0a608c7c
4
- data.tar.gz: 35004e311b5df0deed594667027096b375551f49
2
+ SHA256:
3
+ metadata.gz: 0dd5ceaab614b795ad92e63b73c2d1d3359455a7970c703a366c781fc2b983ea
4
+ data.tar.gz: aa14c451bcfff884a710dd41105f1fc1ec24d03ab2dfb3ec25b264f3a136f2c7
5
5
  SHA512:
6
- metadata.gz: 38acf4e7fb1a06a0709e2c907f974a3b2aa51776742e709ec1d0149fd08e8160a5a2388c4bb98adfe1590aaa0e0b87a0240cac7f9432bc9f21350f5db885458c
7
- data.tar.gz: db8ad6eecea1c976bc893c5cb20dada8926e2387a9a9c07c04ef835e6eccaaa48645aac8b62c5d70b66ab53ab835c44b68d437890b7a4233096eb4cb8048ab01
6
+ metadata.gz: 970cab90c32a0c39862e79087f5740debd0d5d264b6bca0c6d94d60fee73645dc34e9c634459d9c952316f6000328f23f137d2f908a4e6e08a7040fecf1f667d
7
+ data.tar.gz: cbc70d253a2951d31d6f82c0fb8bb25e687817d687a0508d8ddd960bec9f43d062b680bd9221503a58f60fb3d594b51ff51668f594e4022b04c416148169d5c1
data/.gems CHANGED
@@ -1,4 +1,4 @@
1
- cutest -v 1.2.2
2
- tilt -v 2.0.1
3
- rack-test -v 0.6.3
4
- rack -v 2.0.1
1
+ rack -v 2.2.3
2
+ rack-test -v 1.1.0
3
+ cutest -v 1.2.3
4
+ tilt -v 2.0.10
data/README.md CHANGED
@@ -761,7 +761,7 @@ Contributing
761
761
  ------------
762
762
 
763
763
  A good first step is to meet us on IRC and discuss ideas. If that's
764
- not possible, you can create an issue explaning the proposed change
764
+ not possible, you can create an issue explaining the proposed change
765
765
  and a use case. We pay a lot of attention to use cases, because our
766
766
  goal is to keep the code base simple. In many cases, the result of
767
767
  a conversation will be the creation of another tool, instead of the
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cuba"
3
- s.version = "3.9.2"
3
+ s.version = "3.9.3"
4
4
  s.summary = "Microframework for web applications."
5
5
  s.description = "Cuba is a microframework for web applications."
6
6
  s.authors = ["Michel Martens"]
@@ -1,3 +1,4 @@
1
+ require "delegate"
1
2
  require "rack"
2
3
 
3
4
  class Cuba
@@ -10,6 +11,12 @@ class Cuba
10
11
  class Response
11
12
  LOCATION = "Location".freeze
12
13
 
14
+ module ContentType
15
+ HTML = "text/html".freeze # :nodoc:
16
+ TEXT = "text/plain".freeze # :nodoc:
17
+ JSON = "application/json".freeze # :nodoc:
18
+ end
19
+
13
20
  attr_accessor :status
14
21
 
15
22
  attr :body
@@ -38,6 +45,24 @@ class Cuba
38
45
  @body << s
39
46
  end
40
47
 
48
+ # Write response body as text/plain
49
+ def text(str)
50
+ @headers[Rack::CONTENT_TYPE] = ContentType::TEXT
51
+ write(str)
52
+ end
53
+
54
+ # Write response body as text/html
55
+ def html(str)
56
+ @headers[Rack::CONTENT_TYPE] = ContentType::HTML
57
+ write(str)
58
+ end
59
+
60
+ # Write response body as application/json
61
+ def json(str)
62
+ @headers[Rack::CONTENT_TYPE] = ContentType::JSON
63
+ write(str)
64
+ end
65
+
41
66
  def redirect(path, status = 302)
42
67
  @headers[LOCATION] = path
43
68
  @status = status
@@ -30,3 +30,48 @@ test "tests don't fail when you don't specify an accept type" do
30
30
 
31
31
  assert_response body, ["Default action"]
32
32
  end
33
+
34
+ test "accept HTML mimetype" do
35
+ Cuba.define do
36
+ on accept("text/html") do
37
+ res.write Cuba::Response::ContentType::HTML
38
+ end
39
+ end
40
+
41
+ env = { "HTTP_ACCEPT" => "text/html",
42
+ "SCRIPT_NAME" => "/", "PATH_INFO" => "/post" }
43
+
44
+ _, _, body = Cuba.call(env)
45
+
46
+ assert_response body, ["text/html"]
47
+ end
48
+
49
+ test "accept TEXT mimetype" do
50
+ Cuba.define do
51
+ on accept("text/plain") do
52
+ res.write Cuba::Response::ContentType::TEXT
53
+ end
54
+ end
55
+
56
+ env = { "HTTP_ACCEPT" => "text/plain",
57
+ "SCRIPT_NAME" => "/", "PATH_INFO" => "/post" }
58
+
59
+ _, _, body = Cuba.call(env)
60
+
61
+ assert_response body, ["text/plain"]
62
+ end
63
+
64
+ test "accept JSON mimetype" do
65
+ Cuba.define do
66
+ on accept("application/json") do
67
+ res.write Cuba::Response::ContentType::JSON
68
+ end
69
+ end
70
+
71
+ env = { "HTTP_ACCEPT" => "application/json",
72
+ "SCRIPT_NAME" => "/", "PATH_INFO" => "/get" }
73
+
74
+ _, _, body = Cuba.call(env)
75
+
76
+ assert_response body, ["application/json"]
77
+ end
@@ -11,9 +11,9 @@ test "set cookie" do
11
11
 
12
12
  env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/" }
13
13
 
14
- _, headers, body = Cuba.call(env)
14
+ _, headers, body = Cuba.call(env)
15
15
 
16
- assert_equal "foo=bar\nbar=baz", headers["Set-Cookie"]
16
+ assert_equal "foo=bar\nbar=baz", headers["Set-Cookie"]
17
17
  end
18
18
 
19
19
  test "delete cookie" do
@@ -27,8 +27,8 @@ test "delete cookie" do
27
27
 
28
28
  env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/" }
29
29
 
30
- _, headers, body = Cuba.call(env)
30
+ _, headers, body = Cuba.call(env)
31
31
 
32
- assert_equal "foo=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000",
33
- headers["Set-Cookie"]
32
+ assert_equal "foo=; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 GMT",
33
+ headers["Set-Cookie"]
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuba
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.2
4
+ version: 3.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-17 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -137,7 +137,7 @@ homepage: https://github.com/soveran/cuba
137
137
  licenses:
138
138
  - MIT
139
139
  metadata: {}
140
- post_install_message:
140
+ post_install_message:
141
141
  rdoc_options: []
142
142
  require_paths:
143
143
  - lib
@@ -152,9 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  requirements: []
155
- rubyforge_project:
156
- rubygems_version: 2.6.11
157
- signing_key:
155
+ rubygems_version: 3.1.2
156
+ signing_key:
158
157
  specification_version: 4
159
158
  summary: Microframework for web applications.
160
159
  test_files: []