wd_sinatra 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+ - ruby-head
9
+ - jruby-head
10
+ - ree
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: jruby-18mode
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Weasel Diesel Sinatra Changelog
2
2
 
3
+ ## 1.0.2
4
+ * Fixed a bug with the way sinatra routes are loaded. Because the routes
5
+ can contain a globing param, the loading had to be changed to be
6
+ smarter to globbing routes are loaded last.
7
+
3
8
  ## 1.0.1
4
9
  * Added dependency on `WeaselDiesel` `1.2.0` or greater since the API
5
10
  slightly changed.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in wd-sinatra.gemspec
4
+ gem 'backports', '2.3.0', :platform => 'ruby_18'
5
+ gem 'json', :platform => 'ruby_18'
4
6
  gemspec
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Weasel Diesel Sinatra
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/mattetti/wd-sinatra.png?branch=master)](https://next.travis-ci.org/mattetti/wd-sinatra)
4
+
3
5
  Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra apps using the Weasel Diesel DSL
4
6
 
5
7
 
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "."
7
+ t.libs << 'test'
8
+ t.pattern = "test/**/**.rb"
9
+ end
10
+
11
+ task :default => :test
data/lib/wd_sinatra.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require "wd_sinatra/version"
2
+ require 'wd_sinatra/app_loader'
3
+ require 'wd_sinatra/sinatra_ext'
4
+ require 'wd_sinatra/test_helpers'
5
+ require 'wd_sinatra/test_unit_helpers'
6
+ require 'wd_sinatra/ws_list_ext'
2
7
 
3
- module WD
4
- module Sinatra
5
- # Your code goes here...
6
- end
8
+ module WDSinatra
7
9
  end
@@ -106,7 +106,7 @@ module WDSinatra
106
106
  end
107
107
 
108
108
  def set_sinatra_routes
109
- WSList.all.sort.each{|api| api.load_sinatra_route }
109
+ WSList.sorted_for_sinatra_load.each{|api| api.load_sinatra_route }
110
110
  end
111
111
 
112
112
  def load_middleware
@@ -119,7 +119,7 @@ class WeaselDiesel
119
119
  env['wd.service'] = service
120
120
  service.handler.dispatch(self)
121
121
  end
122
-
122
+
123
123
  end
124
124
 
125
125
  end
@@ -1,5 +1,5 @@
1
1
  module WD
2
2
  module Sinatra
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,26 @@
1
+ # Reopening WSList to add custom methods specific to this library.
2
+ module WSList
3
+
4
+ # We want to load all routes with more globing routes last
5
+ def self.sorted_for_sinatra_load
6
+ globbing, no_globbing = all.partition{|ws| ws.url.include?(":") }
7
+
8
+ all.sort do |a,b|
9
+ a_colon_idx = a.url.index(":")
10
+ b_colon_idx = b.url.index(":")
11
+ a_length = a_colon_idx ? a_colon_idx + 1 : a.url.length
12
+ b_length = b_colon_idx ? b_colon_idx + 1 : b.url.length
13
+ if a_length == b_length
14
+ if a_colon_idx && !b_colon_idx
15
+ a_length -= 1
16
+ elsif b_colon_idx && !a_colon_idx
17
+ b_length -= 1
18
+ else
19
+ a_length = a.url.gsub(/\/$/, '').length
20
+ b_length = b.url.gsub(/\/$/, '').length
21
+ end
22
+ end
23
+ b_length <=> a_length
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ Bundler.setup
5
+ require 'test/unit'
6
+ if RUBY_VERSION.to_f < 1.9
7
+ require 'minitest/autorun'
8
+ end
9
+
10
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ require 'wd_sinatra'
12
+
@@ -0,0 +1,96 @@
1
+ require 'uri'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
3
+
4
+ class WsListExtTest < MiniTest::Unit::TestCase
5
+
6
+ def char_encoded(char)
7
+ enc = URI.escape(char)
8
+ enc = "(?:#{escaped(char, enc).join('|')})" if enc == char
9
+ enc = "(?:#{enc}|#{encoded('+')})" if char == " "
10
+ enc
11
+ end
12
+
13
+ def clear_ws_list
14
+ WSList.all.clear
15
+ assert WSList.all.length == 0
16
+ end
17
+
18
+ def add_test_services
19
+ WSList.add WeaselDiesel.new("/foo")
20
+ WSList.add WeaselDiesel.new("/foo/:bar")
21
+ WSList.add WeaselDiesel.new("/foo/bar/")
22
+ WSList.add WeaselDiesel.new("/foo/bart")
23
+ WSList.add WeaselDiesel.new("/foo/bar/:baz")
24
+ WSList.add WeaselDiesel.new("/foo/bar/bazz")
25
+ WSList.add WeaselDiesel.new("/foo/:id/bazz")
26
+ end
27
+
28
+ # A snapshot of a working sorting of url array
29
+ # The sorting doesn't have to actually be similar to that
30
+ # but this allows us to have a baseline to measure against in case
31
+ # of tests.
32
+ def expected_sorted_urls
33
+ [
34
+ "/foo/bar/bazz",
35
+ "/foo/bart",
36
+ "/foo/bar/",
37
+ "/foo/bar/:baz",
38
+ "/foo/:id/bazz",
39
+ "/foo/:bar",
40
+ "/foo"
41
+ ]
42
+ end
43
+
44
+ def matched_route(url_query, reference_urls)
45
+ sorted_regexps = reference_urls.map do |url|
46
+ ignore = ""
47
+ pattern = url.gsub(/[^\?\%\\\/\:\*\w]/){ |c|
48
+ ignore << escaped(c).join if c.match(/[\.@]/)
49
+ char_encoded(c)
50
+ }
51
+ pattern.gsub!(/((:\w+)|\*)/) do |match|
52
+ if match == "*"
53
+ "(.*?)"
54
+ else
55
+ "([^#{ignore}/?#]+)"
56
+ end
57
+ end
58
+ /\A#{pattern}\z/
59
+ end
60
+
61
+ # p sorted_regexps.inspect
62
+ regexp_match = sorted_regexps.detect{|r| r.match(url_query) }
63
+ if regexp_match
64
+ regexp_match.source[/\\A(.*?)\\z/, 1]
65
+ else
66
+ nil
67
+ end
68
+
69
+ end
70
+
71
+ def assert_route_matching(base_urls)
72
+ assert_equal "/foo", matched_route("/foo", base_urls), "Matching /foo to /foo Registered \n#{base_urls.join("\n")}\n"
73
+ assert_equal "/foo/bar/bazz", matched_route("/foo/bar/bazz", base_urls), "Matching /foo/bar/bazz to /foo/bar/bazz. Registered routes: \n#{base_urls.join("\n")}\n"
74
+ assert_equal "/foo/bart", matched_route("/foo/bart", base_urls)
75
+ assert_equal "/foo/bar/", matched_route("/foo/bar/", base_urls)
76
+ assert_equal "/foo/bar/([^/?#]+)", matched_route("/foo/bar/foo", base_urls)
77
+ assert_equal "/foo/([^/?#]+)", matched_route("/foo/baz", base_urls)
78
+ assert_equal nil, matched_route("/fooz", base_urls), "shouldn't match /fooz"
79
+ assert_equal nil, matched_route("/foo/bar/baz/baz", base_urls), "shouldn't match /foo/bar/baz/baz"
80
+ assert_equal nil, matched_route("/foo/", base_urls), "shouldn't match /foo/"
81
+ assert_equal "/foo/([^/?#]+)/bazz", matched_route("/foo/123/bazz", base_urls), "Should match /foo/123/bazz"
82
+ end
83
+
84
+ def test_route_matching_expectations
85
+ clear_ws_list
86
+ add_test_services
87
+ assert_route_matching(expected_sorted_urls)
88
+ end
89
+
90
+ def test_route_loading_and_matching
91
+ clear_ws_list
92
+ add_test_services
93
+ assert_route_matching(WSList.sorted_for_sinatra_load.map{|ws| ws.url})
94
+ end
95
+
96
+ end
data/wd-sinatra.gemspec CHANGED
@@ -15,8 +15,12 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = WD::Sinatra::VERSION
17
17
 
18
+ gem.add_dependency('rake')
18
19
  gem.add_dependency('weasel_diesel', ">= 1.2.0")
20
+ gem.add_dependency('rack')
21
+ gem.add_dependency('rack-test')
19
22
  gem.add_dependency('thor')
23
+ gem.add_dependency('minitest')
20
24
  end
21
25
 
22
26
 
metadata CHANGED
@@ -1,58 +1,120 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wd_sinatra
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 2
10
+ version: 1.0.2
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-10-26 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-10-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ requirement: *id001
33
+ prerelease: false
34
+ - !ruby/object:Gem::Dependency
15
35
  name: weasel_diesel
16
- requirement: !ruby/object:Gem::Requirement
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
17
37
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 31
42
+ segments:
43
+ - 1
44
+ - 2
45
+ - 0
21
46
  version: 1.2.0
22
47
  type: :runtime
48
+ requirement: *id002
23
49
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
50
+ - !ruby/object:Gem::Dependency
51
+ name: rack
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
25
53
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 1.2.0
30
- - !ruby/object:Gem::Dependency
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ requirement: *id003
63
+ prerelease: false
64
+ - !ruby/object:Gem::Dependency
65
+ name: rack-test
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :runtime
76
+ requirement: *id004
77
+ prerelease: false
78
+ - !ruby/object:Gem::Dependency
31
79
  name: thor
32
- requirement: !ruby/object:Gem::Requirement
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
33
81
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
38
89
  type: :runtime
90
+ requirement: *id005
39
91
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
92
+ - !ruby/object:Gem::Dependency
93
+ name: minitest
94
+ version_requirements: &id006 !ruby/object:Gem::Requirement
41
95
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- description: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra
47
- apps using the Weasel Diesel DSL
48
- email:
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :runtime
104
+ requirement: *id006
105
+ prerelease: false
106
+ description: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra apps using the Weasel Diesel DSL
107
+ email:
49
108
  - mattaimonetti@gmail.com
50
- executables:
109
+ executables:
51
110
  - wd_sinatra
52
111
  extensions: []
112
+
53
113
  extra_rdoc_files: []
54
- files:
114
+
115
+ files:
55
116
  - .gitignore
117
+ - .travis.yml
56
118
  - CHANGELOG.md
57
119
  - Gemfile
58
120
  - LICENSE
@@ -65,6 +127,7 @@ files:
65
127
  - lib/wd_sinatra/test_helpers.rb
66
128
  - lib/wd_sinatra/test_unit_helpers.rb
67
129
  - lib/wd_sinatra/version.rb
130
+ - lib/wd_sinatra/ws_list_ext.rb
68
131
  - templates/Gemfile
69
132
  - templates/Guardfile
70
133
  - templates/Rakefile
@@ -141,31 +204,42 @@ files:
141
204
  - templates/public/favicon.ico
142
205
  - templates/test/integration/hello_world_test.rb
143
206
  - templates/test/test_helpers.rb
207
+ - test/test_helper.rb
208
+ - test/ws_list_ext_test.rb
144
209
  - wd-sinatra.gemspec
145
210
  homepage: https://github.com/mattetti/wd-sinatra
146
211
  licenses: []
212
+
147
213
  post_install_message:
148
214
  rdoc_options: []
149
- require_paths:
215
+
216
+ require_paths:
150
217
  - lib
151
- required_ruby_version: !ruby/object:Gem::Requirement
218
+ required_ruby_version: !ruby/object:Gem::Requirement
152
219
  none: false
153
- requirements:
154
- - - ! '>='
155
- - !ruby/object:Gem::Version
156
- version: '0'
157
- required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ hash: 3
224
+ segments:
225
+ - 0
226
+ version: "0"
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
228
  none: false
159
- requirements:
160
- - - ! '>='
161
- - !ruby/object:Gem::Version
162
- version: '0'
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ hash: 3
233
+ segments:
234
+ - 0
235
+ version: "0"
163
236
  requirements: []
237
+
164
238
  rubyforge_project:
165
239
  rubygems_version: 1.8.24
166
240
  signing_key:
167
241
  specification_version: 3
168
- summary: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra apps
169
- using the Weasel Diesel DSL
170
- test_files: []
171
- has_rdoc:
242
+ summary: Weasel-Diesel Sinatra app gem, allowing you to generate/update sinatra apps using the Weasel Diesel DSL
243
+ test_files:
244
+ - test/test_helper.rb
245
+ - test/ws_list_ext_test.rb