deas 0.33.0 → 0.34.0

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
2
  SHA1:
3
- metadata.gz: adc507d7ca21b98b7f24b336b303ebe5800a5902
4
- data.tar.gz: 85fc3d5b41048f51ce959d0b9fd0d630b28d477a
3
+ metadata.gz: cfa612b3fc472e3c8a14005ca567c2a20b901476
4
+ data.tar.gz: c6e19d87a4393a780da387f19a5698100ab80296
5
5
  SHA512:
6
- metadata.gz: 800d1d86aef361ab9f194f74fb83ea4951c4e45ce639c8dccf46378c3eb7daea7442045c3bbdedd6f9e238146a2a130c8b4c2b1b0234cf5d40e886eccb37ea0d
7
- data.tar.gz: 8a67207f27e0fb0e993207c7c5f4cc31c0d189086c66a5dbfc5c9aa0845d58cc5b7807caaf23f08386867c83160c649a4d75b664d1e99e26a44fb02f29600a7c
6
+ metadata.gz: 99c27beacb566a4f0361aadfd85c4d504c2bf11d0ed09112082f35ea115c37df3d69273da9482b27a9d0e50d6ef4eed1b2e3b1f8431eec5d50ffb053eb1e5622
7
+ data.tar.gz: 602b81f39fa49f1d92b244450248e7efc7515e06317c51b2ba951172ee9f67c29b4feb4ec7d14a30483bd0b5bfd6a68b03833848df85b6a5bbac7697fe65d409
data/lib/deas/server.rb CHANGED
@@ -29,7 +29,7 @@ module Deas::Server
29
29
  option :show_exceptions, NsOptions::Boolean, :default => false
30
30
  option :static_files, NsOptions::Boolean, :default => true
31
31
  option :reload_templates, NsOptions::Boolean, :default => false
32
- option :default_charset, String, :default => 'utf-8'
32
+ option :default_encoding, String, :default => 'utf-8'
33
33
 
34
34
  # server handling options
35
35
 
@@ -190,8 +190,8 @@ module Deas::Server
190
190
  self.configuration.logger *args
191
191
  end
192
192
 
193
- def default_charset(*args)
194
- self.configuration.default_charset *args
193
+ def default_encoding(*args)
194
+ self.configuration.default_encoding *args
195
195
  end
196
196
 
197
197
  def template_source(*args)
@@ -21,6 +21,7 @@ module Deas
21
21
  set :sessions, server_config.sessions
22
22
  set :static, server_config.static_files
23
23
  set :reload_templates, server_config.reload_templates
24
+ set :default_encoding, server_config.default_encoding
24
25
  set :logging, false
25
26
 
26
27
  # raise_errors and show_exceptions prevent Deas error handlers from
@@ -30,11 +31,16 @@ module Deas
30
31
  set :show_exceptions, false
31
32
 
32
33
  # custom settings
33
- set :deas_error_procs, server_config.error_procs
34
- set :deas_default_charset, server_config.default_charset
35
- set :logger, server_config.logger
36
- set :router, server_config.router
37
- set :template_source, server_config.template_source
34
+ set :deas_error_procs, server_config.error_procs
35
+ set :logger, server_config.logger
36
+ set :router, server_config.router
37
+ set :template_source, server_config.template_source
38
+
39
+ # TODO: rework with `server_config.default_encoding` once we move off of using Sinatra
40
+ # TODO: could maybe move into a deas-json mixin once off of Sinatra
41
+ # Add charset to json content type responses - by default only added to these:
42
+ # ["application/javascript", "application/xml", "application/xhtml+xml", /^text\//]
43
+ settings.add_charset << "application/json"
38
44
 
39
45
  server_config.settings.each{ |set_args| set *set_args }
40
46
  server_config.middlewares.each{ |use_args| use *use_args }
@@ -20,15 +20,7 @@ module Deas
20
20
  end
21
21
 
22
22
  def content_type(*args)
23
- return @sinatra_call.content_type if args.empty?
24
-
25
- opts, value = [
26
- args.last.kind_of?(::Hash) ? args.pop : {},
27
- args.first
28
- ]
29
- @sinatra_call.content_type(value, {
30
- :charset => @sinatra_call.settings.deas_default_charset
31
- }.merge(opts || {}))
23
+ @sinatra_call.content_type(*args)
32
24
  end
33
25
 
34
26
  def status(*args)
@@ -40,18 +32,23 @@ module Deas
40
32
  end
41
33
 
42
34
  def source_render(source, template_name, locals = nil)
43
- self.content_type(get_content_type(template_name)) if self.content_type.nil?
35
+ if self.content_type.nil?
36
+ self.content_type(get_content_type_ext(template_name) || 'html')
37
+ end
44
38
  super
45
39
  end
46
40
 
47
- def send_file(*args, &block)
48
- @sinatra_call.send_file(*args, &block)
41
+ def send_file(file_path, opts = nil, &block)
42
+ if self.content_type.nil?
43
+ self.content_type(get_content_type_ext(file_path))
44
+ end
45
+ @sinatra_call.send_file(file_path, opts || {}, &block)
49
46
  end
50
47
 
51
48
  private
52
49
 
53
- def get_content_type(template_name)
54
- File.extname(template_name)[1..-1] || 'html'
50
+ def get_content_type_ext(file_path)
51
+ File.extname(file_path)[1..-1]
55
52
  end
56
53
 
57
54
  end
@@ -9,7 +9,7 @@ module Deas
9
9
 
10
10
  class TestRunner < Runner
11
11
 
12
- attr_reader :return_value
12
+ attr_reader :response_value
13
13
 
14
14
  def initialize(handler_class, args = nil)
15
15
  if !handler_class.include?(Deas::ViewHandler)
@@ -29,11 +29,18 @@ module Deas
29
29
  })
30
30
  args.each{|key, value| self.handler.send("#{key}=", value) }
31
31
 
32
- @return_value = catch(:halt){ self.handler.init; nil }
32
+ @response_value = catch(:halt){ self.handler.init; nil }
33
+ end
34
+
35
+ # TODO: remove eventually
36
+ def return_value
37
+ warn "calling `return_value` on a test runner is deprecated - " \
38
+ "switch to `response_value` instead"
39
+ self.response_value
33
40
  end
34
41
 
35
42
  def run
36
- @return_value ||= catch(:halt){ self.handler.run }
43
+ @response_value ||= catch(:halt){ self.handler.run }
37
44
  end
38
45
 
39
46
  # Helpers
@@ -60,18 +67,27 @@ module Deas
60
67
  def redirect?; true; end
61
68
  end
62
69
 
63
- def content_type(value, opts={})
64
- ContentTypeArgs.new(value, opts)
70
+ def content_type(*args)
71
+ return @content_type if args.empty?
72
+ opts, value = [
73
+ args.last.kind_of?(Hash) ? args.pop : {},
74
+ args.last
75
+ ]
76
+ @content_type = ContentTypeArgs.new(value, opts)
65
77
  end
66
78
  ContentTypeArgs = Struct.new(:value, :opts)
67
79
 
68
- def status(value)
69
- StatusArgs.new(value)
80
+ def status(*args)
81
+ return @status if args.empty?
82
+ value = args.last
83
+ @status = StatusArgs.new(value)
70
84
  end
71
85
  StatusArgs = Struct.new(:value)
72
86
 
73
- def headers(value)
74
- HeadersArgs.new(value)
87
+ def headers(*args)
88
+ return @headers if args.empty?
89
+ value = args.last
90
+ @headers = HeadersArgs.new(value)
75
91
  end
76
92
  HeadersArgs = Struct.new(:value)
77
93
 
data/lib/deas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Deas
2
- VERSION = "0.33.0"
2
+ VERSION = "0.34.0"
3
3
  end
@@ -20,8 +20,11 @@ class FakeSinatraCall
20
20
  @router = Deas::Router.new
21
21
  @template_source = Deas::NullTemplateSource.new
22
22
 
23
+ @content_type = nil
24
+ @status = 200
25
+ @headers = {}
26
+
23
27
  @settings = OpenStruct.new({
24
- :deas_default_charset => 'utf-8',
25
28
  :logger => @logger,
26
29
  :router => @router,
27
30
  :template_source => @template_source
@@ -36,9 +39,25 @@ class FakeSinatraCall
36
39
  halt 302, { 'Location' => args[0] }
37
40
  end
38
41
 
39
- def content_type(*args); args; end
40
- def status(*args); args; end
41
- def headers(*args); args; end
42
+ def content_type(*args)
43
+ return @content_type if args.empty?
44
+ opts, value = [
45
+ args.last.kind_of?(Hash) ? args.pop : {},
46
+ args.last
47
+ ]
48
+ opts_value = opts.keys.map{ |k| "#{k}=#{opts[k]}" }.join(';')
49
+ @content_type = [value, opts_value].reject{ |v| v.to_s.empty? }.join(';')
50
+ end
51
+
52
+ def status(*args)
53
+ return @status if args.empty?
54
+ @status = args.last
55
+ end
56
+
57
+ def headers(*args)
58
+ return @headers if args.empty?
59
+ @headers = args.last
60
+ end
42
61
 
43
62
  def send_file(file_path, opts, &block)
44
63
  if block
@@ -48,7 +48,7 @@ class Deas::DeasRunner
48
48
  class RunTests < InitTests
49
49
  desc "and run"
50
50
  setup do
51
- @return_value = @runner.run
51
+ @response_value = @runner.run
52
52
  @handler = @runner.instance_variable_get("@handler")
53
53
  end
54
54
  subject{ @handler }
@@ -63,8 +63,8 @@ class Deas::DeasRunner
63
63
  assert_equal true, subject.run_bang_called
64
64
  end
65
65
 
66
- should "return the handler's run! return value" do
67
- assert_equal true, @return_value
66
+ should "use the handler's run! return value as its response value" do
67
+ assert_equal true, @response_value
68
68
  end
69
69
 
70
70
  end
@@ -21,7 +21,7 @@ class Deas::Server::Configuration
21
21
 
22
22
  should have_imeths :env, :root, :public_root, :views_root
23
23
  should have_imeths :dump_errors, :method_override, :sessions, :show_exceptions
24
- should have_imeths :static_files, :reload_templates, :default_charset
24
+ should have_imeths :static_files, :reload_templates, :default_encoding
25
25
 
26
26
  # server handling options
27
27
 
@@ -79,8 +79,8 @@ class Deas::Server::Configuration
79
79
  assert_nothing_raised{ config.root '/path/to/root'; config.validate! }
80
80
  end
81
81
 
82
- should "use `utf-8` as the default_charset by default" do
83
- assert_equal 'utf-8', subject.default_charset
82
+ should "use `utf-8` as the default encoding by default" do
83
+ assert_equal 'utf-8', subject.default_encoding
84
84
  end
85
85
 
86
86
  end
@@ -23,7 +23,7 @@ module Deas::Server
23
23
 
24
24
  # DSL for server handling settings
25
25
  should have_imeths :init, :error, :template_helpers, :template_helper?
26
- should have_imeths :use, :set, :verbose_logging, :logger, :default_charset
26
+ should have_imeths :use, :set, :verbose_logging, :logger, :default_encoding
27
27
  should have_imeths :template_source
28
28
 
29
29
  # DSL for server routing settings
@@ -93,8 +93,8 @@ module Deas::Server
93
93
  subject.template_source a_source
94
94
  assert_equal a_source, config.template_source
95
95
 
96
- subject.default_charset 'latin1'
97
- assert_equal 'latin1', config.default_charset
96
+ subject.default_encoding 'latin1'
97
+ assert_equal 'latin1', config.default_encoding
98
98
  end
99
99
 
100
100
  should "add and query helper modules" do
@@ -27,6 +27,7 @@ module Deas::SinatraApp
27
27
  c.show_exceptions = true
28
28
  c.static = true
29
29
  c.reload_templates = true
30
+ c.default_encoding = 'latin1'
30
31
  c.router = @router
31
32
  end
32
33
  @sinatra_app = Deas::SinatraApp.new(@configuration)
@@ -52,6 +53,7 @@ module Deas::SinatraApp
52
53
  assert_equal false, settings.sessions
53
54
  assert_equal true, settings.static
54
55
  assert_equal true, settings.reload_templates
56
+ assert_equal 'latin1', settings.default_encoding
55
57
  assert_instance_of Deas::NullLogger, settings.logger
56
58
  assert_instance_of Deas::Router, settings.router
57
59
  assert_instance_of Deas::NullTemplateSource, settings.template_source
@@ -60,6 +62,8 @@ module Deas::SinatraApp
60
62
  assert_equal false, settings.logging
61
63
  assert_equal false, settings.raise_errors
62
64
  assert_equal false, settings.show_exceptions
65
+
66
+ assert_includes "application/json", settings.add_charset
63
67
  end
64
68
  end
65
69
 
@@ -33,27 +33,27 @@ class Deas::SinatraRunner
33
33
  should have_imeths :run
34
34
 
35
35
  should "call the sinatra_call's halt with" do
36
- return_value = catch(:halt){ subject.halt('test') }
37
- assert_equal [ 'test' ], return_value
36
+ response_value = catch(:halt){ subject.halt('test') }
37
+ assert_equal [ 'test' ], response_value
38
38
  end
39
39
 
40
40
  should "call the sinatra_call's redirect method with" do
41
- return_value = catch(:halt){ subject.redirect('http://google.com') }
42
- expected = [ 302, { 'Location' => 'http://google.com' } ]
41
+ response_value = catch(:halt){ subject.redirect('http://google.com') }
42
+ exp = [ 302, { 'Location' => 'http://google.com' } ]
43
43
 
44
- assert_equal expected, return_value
44
+ assert_equal exp, response_value
45
45
  end
46
46
 
47
- should "call the sinatra_call's content_type method using the default_charset" do
48
- expected = @fake_sinatra_call.content_type('text/plain', :charset => 'utf-8')
49
- assert_equal expected, subject.content_type('text/plain')
50
-
51
- expected = @fake_sinatra_call.content_type('text/plain', :charset => 'latin1')
52
- assert_equal expected, subject.content_type('text/plain', :charset => 'latin1')
47
+ should "call the sinatra_call's content_type to set the response content type" do
48
+ args = ['txt', { :charset => 'latin1' }]
49
+ exp = @fake_sinatra_call.content_type(*args)
50
+ subject.content_type(*args)
51
+ assert_equal exp, subject.content_type
53
52
  end
54
53
 
55
54
  should "call the sinatra_call's status to set the response status" do
56
- assert_equal [422], subject.status(422)
55
+ subject.status(422)
56
+ assert_equal 422, subject.status
57
57
  end
58
58
 
59
59
  should "call the sinatra_call's headers to set the response headers" do
@@ -61,15 +61,18 @@ class Deas::SinatraRunner
61
61
  'a-header' => 'some value',
62
62
  'other' => 'other'
63
63
  }
64
- assert_equal [exp_headers], subject.headers(exp_headers)
64
+ subject.headers(exp_headers)
65
+ assert_equal exp_headers, subject.headers
65
66
  end
66
67
 
67
68
  should "call the sinatra_call's send_file to set the send files" do
68
69
  block_called = false
69
- args = subject.send_file('a/file', {:some => 'opts'}, &proc{ block_called = true })
70
- assert_equal 'a/file', args.file_path
70
+ args = subject.send_file('a/file.txt', {:some => 'opts'}, &proc{ block_called = true })
71
+ assert_equal 'a/file.txt', args.file_path
71
72
  assert_equal({:some => 'opts'}, args.options)
72
73
  assert_true block_called
74
+
75
+ assert_equal 'txt', subject.content_type
73
76
  end
74
77
 
75
78
  end
@@ -44,8 +44,9 @@ class Deas::TestRunner
44
44
  end
45
45
  subject{ @runner }
46
46
 
47
- should have_readers :return_value
47
+ should have_readers :response_value
48
48
  should have_imeths :run
49
+ should have_imeths :return_value # TODO: deprecated
49
50
 
50
51
  should "raise an invalid error when not passed a view handler" do
51
52
  assert_raises(Deas::InvalidServiceHandlerError) do
@@ -81,14 +82,21 @@ class Deas::TestRunner
81
82
  assert_true subject.handler.init_called
82
83
  end
83
84
 
84
- should "not set a return value on initialize" do
85
- assert_nil subject.return_value
85
+ should "not set a response value on initialize" do
86
+ assert_nil subject.response_value
86
87
  end
87
88
 
88
- should "set its return value to the return value of `run!` on run" do
89
- assert_nil subject.return_value
89
+ should "set its response value to the return value of `run!` on run" do
90
+ assert_nil subject.response_value
90
91
  subject.run
91
- assert_equal subject.handler.run!, subject.return_value
92
+ assert_equal subject.handler.run!, subject.response_value
93
+ end
94
+
95
+ # TODO: deprecated
96
+ should "alias its response value at `return_value`" do
97
+ assert_equal subject.response_value, subject.return_value
98
+ subject.run
99
+ assert_equal subject.response_value, subject.return_value
92
100
  end
93
101
 
94
102
  should "build halt args if halt is called" do
@@ -116,6 +124,8 @@ class Deas::TestRunner
116
124
  assert_respond_to meth, value
117
125
  end
118
126
  assert_equal 'something', value.value
127
+
128
+ assert_same value, subject.content_type
119
129
  end
120
130
 
121
131
  should "build status args if status is called" do
@@ -123,6 +133,8 @@ class Deas::TestRunner
123
133
  assert_kind_of StatusArgs, value
124
134
  assert_respond_to :value, value
125
135
  assert_equal 432, value.value
136
+
137
+ assert_same value, subject.status
126
138
  end
127
139
 
128
140
  should "build headers args if headers is called" do
@@ -131,6 +143,8 @@ class Deas::TestRunner
131
143
  assert_respond_to :value, value
132
144
  exp_val = {:some => 'thing'}
133
145
  assert_equal exp_val, value.value
146
+
147
+ assert_same value, subject.headers
134
148
  end
135
149
 
136
150
  should "build send file args if send file is called" do
@@ -225,9 +225,9 @@ module Deas::ViewHandler
225
225
  })
226
226
  runner.run
227
227
 
228
- assert_equal 200, runner.return_value.status
229
- assert_equal({ 'Content-Type' => 'text/plain' }, runner.return_value.headers)
230
- assert_equal 'test halting', runner.return_value.body
228
+ assert_equal 200, runner.response_value.status
229
+ assert_equal({ 'Content-Type' => 'text/plain' }, runner.response_value.headers)
230
+ assert_equal 'test halting', runner.response_value.body
231
231
  end
232
232
 
233
233
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.33.0
4
+ version: 0.34.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-14 00:00:00.000000000 Z
12
+ date: 2015-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ns-options