wd_sinatra 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Weasel Diesel Sinatra Changelog
2
+
3
+
4
+ ## 0.1.0
5
+
6
+ * Updated `sinatra_config.rb` to automatically store exceptions in
7
+ `rack.exception` so rack middleware like airbrake can properly make
8
+ use of the exceptions without exposing any details to the end users.
9
+
10
+ * Added support for documenting the service params as they are defined.
11
+ (thanks rwfowler)
12
+
13
+ ```ruby
14
+ service.params do |p|
15
+ p.string :email, :doc => "Email address of the recipient."
16
+ end
17
+ ```
18
+
19
+ * Started porting test helpers to facilitate API testing.
20
+
21
+ * Updated the guard files. (thanks drnic)
@@ -3,17 +3,11 @@ require 'test/unit'
3
3
  require 'rack'
4
4
  require 'rack/test'
5
5
  require 'json'
6
+ require 'weasel_diesel'
6
7
  require 'json_response_verification'
7
- require File.join(File.dirname(__FILE__), '..', 'lib', 'bootloader')
8
8
 
9
- require 'minitest/autorun'
10
-
11
- ENV['NO_PRINT_ROUTES'] = 'true'
12
- Bootloader.start
13
9
  WeaselDiesel.send(:include, JSONResponseVerification)
14
10
 
15
- ActiveRecord::Base.logger = nil
16
-
17
11
  class Requester
18
12
  include ::Rack::Test::Methods
19
13
 
@@ -26,8 +20,12 @@ module TestApi
26
20
  module_function
27
21
 
28
22
  URL_PLACEHOLDER = /\/*(:[a-z A-Z _]+)\/*/
29
- INTERNAL_X_HEADER = AuthHelpers::INTERNAL_X_HEADER[/HTTP_(.*)/, 1] # strip the header marker added by Rack
30
- MOBILE_X_HEADER = AuthHelpers::MOBILE_X_HEADER[/HTTP_(.*)/, 1] # strip the header marker added by Rack
23
+ if defined?(AuthHelpers::INTERNAL_X_HEADER)
24
+ INTERNAL_X_HEADER = AuthHelpers::INTERNAL_X_HEADER[/HTTP_(.*)/, 1] # strip the header marker added by Rack
25
+ end
26
+ if defined?(AuthHelpers::MOBILE_X_HEADER)
27
+ MOBILE_X_HEADER = AuthHelpers::MOBILE_X_HEADER[/HTTP_(.*)/, 1] # strip the header marker added by Rack
28
+ end
31
29
 
32
30
  def request(verb, uri, params={}, headers=nil)
33
31
  params ||= {}
@@ -178,27 +176,3 @@ class JsonWrapperResponse
178
176
 
179
177
  def_delegators :rest_response, :code, :headers, :raw_headers, :cookies, :status, :errors
180
178
  end
181
-
182
-
183
- # Custom assertions
184
- def assert_api_response(response=nil, message=nil)
185
- response ||= TestApi.json_response
186
- print response.rest_response.errors if response.status === 500
187
- assert response.success?, message || ["Body: #{response.rest_response.body}", "Errors: #{response.errors}", "Status code: #{response.status}"].join("\n")
188
- service = WSList.all.find{|s| s.verb == response.verb && s.url == response.uri[1..-1]}
189
- raise "Service for (#{response.verb.upcase} #{response.uri[1..-1]}) not found" unless service
190
- unless service.response.nodes.empty?
191
- assert response.body.is_a?(Hash), "Invalid JSON response:\n#{response.body}"
192
- valid, errors = service.validate_hash_response(response.body)
193
- assert valid, errors.join(" & ") || message
194
- end
195
- end
196
-
197
- def assert_api_response_with_redirection(redirection_url=nil)
198
- response = TestApi.json_response
199
- print response.rest_response.errors if response.status === 500
200
- assert response.status == 302, "Redirection expect, but got #{response.status}"
201
- if redirection_url
202
- assert response.headers["location"], redirection_url
203
- end
204
- end
@@ -0,0 +1,26 @@
1
+ require 'wd_sinatra/test_helpers'
2
+
3
+ module TestUnitHelpers
4
+ # Custom assertions
5
+ def assert_api_response(response=nil, message=nil)
6
+ response ||= TestApi.json_response
7
+ print response.rest_response.errors if response.status === 500
8
+ assert response.success?, message || ["Body: #{response.rest_response.body}", "Errors: #{response.errors}", "Status code: #{response.status}"].join("\n")
9
+ service = WSList.all.find{|s| s.verb == response.verb && s.url == response.uri[1..-1]}
10
+ raise "Service for (#{response.verb.upcase} #{response.uri[1..-1]}) not found" unless service
11
+ unless service.response.nodes.empty?
12
+ assert response.body.is_a?(Hash), "Invalid JSON response:\n#{response.body}"
13
+ valid, errors = service.validate_hash_response(response.body)
14
+ assert valid, errors.join(" & ") || message
15
+ end
16
+ end
17
+
18
+ def assert_api_response_with_redirection(redirection_url=nil)
19
+ response = TestApi.json_response
20
+ print response.rest_response.errors if response.status === 500
21
+ assert response.status == 302, "Redirection expect, but got #{response.status}"
22
+ if redirection_url
23
+ assert response.headers["location"], redirection_url
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module WD
2
2
  module Sinatra
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/templates/Guardfile CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  guard 'puma' do
5
5
  watch('Gemfile.lock')
6
- watch(%r{^config|lib/.*})
6
+ watch(%r{^config|lib|api/.*})
7
7
  end
8
8
 
9
9
  guard 'minitest', :test_file_patterns => '*_test.rb' do
@@ -10,3 +10,9 @@ set :raise_errors, false
10
10
  # enable that option to run by calling this file automatically (without using the config.ru file)
11
11
  # enable :run
12
12
  use Rack::ContentLength
13
+
14
+ # Store the caught exception in the rack env so it can be used
15
+ # by 3rd party apps like airbrake.
16
+ error(Sinatra::Base::Exception) do |exception|
17
+ @env['rack.exception'] = exception
18
+ end
@@ -72,7 +72,7 @@
72
72
  <% api.send(rule_meth).each do |rule| %>
73
73
  <li>
74
74
  <span class='label notice'><%= rule.name %></span> of type <span class='label success'><%= rule.options[:type] || 'String' %></span>
75
- <% if desc = api.doc.params_doc[rule.name.to_sym] %>
75
+ <% if desc = (api.doc.params_doc[rule.name.to_sym] || rule.options[:doc]) %>
76
76
  <%= desc %>&nbsp;
77
77
  <% end %>
78
78
  <% if options = rule.options[:options] %>
metadata CHANGED
@@ -1,48 +1,62 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wd_sinatra
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Matt Aimonetti
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-05-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: weasel_diesel
16
- requirement: &70130821083780 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
22
32
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70130821083780
25
- - !ruby/object:Gem::Dependency
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
26
35
  name: thor
27
- requirement: &70130821083360 !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
28
38
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
33
46
  type: :runtime
34
- prerelease: false
35
- version_requirements: *70130821083360
36
- description: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra
37
- apps using the Weasel Diesel DSL
38
- email:
47
+ version_requirements: *id002
48
+ description: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra apps using the Weasel Diesel DSL
49
+ email:
39
50
  - mattaimonetti@gmail.com
40
- executables:
51
+ executables:
41
52
  - wd_sinatra
42
53
  extensions: []
54
+
43
55
  extra_rdoc_files: []
44
- files:
56
+
57
+ files:
45
58
  - .gitignore
59
+ - CHANGELOG.md
46
60
  - Gemfile
47
61
  - LICENSE
48
62
  - README.md
@@ -52,6 +66,7 @@ files:
52
66
  - lib/wd_sinatra/app_loader.rb
53
67
  - lib/wd_sinatra/sinatra_ext.rb
54
68
  - lib/wd_sinatra/test_helpers.rb
69
+ - lib/wd_sinatra/test_unit_helpers.rb
55
70
  - lib/wd_sinatra/version.rb
56
71
  - templates/Gemfile
57
72
  - templates/Guardfile
@@ -127,28 +142,36 @@ files:
127
142
  - wd-sinatra.gemspec
128
143
  homepage: https://github.com/mattetti/wd_sinatra
129
144
  licenses: []
145
+
130
146
  post_install_message:
131
147
  rdoc_options: []
132
- require_paths:
148
+
149
+ require_paths:
133
150
  - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
151
+ required_ruby_version: !ruby/object:Gem::Requirement
135
152
  none: false
136
- requirements:
137
- - - ! '>='
138
- - !ruby/object:Gem::Version
139
- version: '0'
140
- required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ hash: 3
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
161
  none: false
142
- requirements:
143
- - - ! '>='
144
- - !ruby/object:Gem::Version
145
- version: '0'
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ hash: 3
166
+ segments:
167
+ - 0
168
+ version: "0"
146
169
  requirements: []
170
+
147
171
  rubyforge_project:
148
- rubygems_version: 1.8.16
172
+ rubygems_version: 1.8.18
149
173
  signing_key:
150
174
  specification_version: 3
151
- summary: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra apps
152
- using the Weasel Diesel DSL
175
+ summary: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra apps using the Weasel Diesel DSL
153
176
  test_files: []
154
- has_rdoc:
177
+