joshbuddy-usher 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/usher.rb +5 -3
- data/spec/generate_spec.rb +5 -0
- data/spec/rails/recognize_spec.rb +1 -1
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/usher.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
|
3
|
+
require 'cgi'
|
3
4
|
require 'usher/node'
|
4
5
|
require 'usher/route'
|
5
6
|
require 'usher/grapher'
|
@@ -162,7 +163,8 @@ class Usher
|
|
162
163
|
def generate_url(route, params = {}, options = {})
|
163
164
|
check_variables = options.key?(:check_variables) ? options.delete(:check_variables) : false
|
164
165
|
delimiter = options.key?(:delimiter) ? options.delete(:delimiter) : @delimiters.first
|
165
|
-
|
166
|
+
extra_params = options.key?(:extra_params) ? options.delete(:extra_params) : {}
|
167
|
+
|
166
168
|
path = case route
|
167
169
|
when Symbol
|
168
170
|
@named_routes[route]
|
@@ -174,10 +176,10 @@ class Usher
|
|
174
176
|
route
|
175
177
|
end
|
176
178
|
raise UnrecognizedException.new unless path
|
177
|
-
params_hash =
|
179
|
+
params_hash = extra_params
|
178
180
|
param_list = case params
|
179
181
|
when Hash
|
180
|
-
params_hash
|
182
|
+
params_hash.merge!(params)
|
181
183
|
path.dynamic_parts.collect{|k| params_hash.delete(k.name) {|el| raise MissingParameterException.new(k.name)} }
|
182
184
|
when Array
|
183
185
|
path.dynamic_parts.size == params.size ? params : raise(MissingParameterException.new("got #{params.size} arguments, expected #{path.dynamic_parts.size}"))
|
data/spec/generate_spec.rb
CHANGED
@@ -43,6 +43,11 @@ describe "Usher URL generation" do
|
|
43
43
|
route_set.generate_url(:sample, {:first => 'maz', :second => 'zoo', :third => 'zanz'}).should == '/sample/maz/zoo?third=zanz'
|
44
44
|
end
|
45
45
|
|
46
|
+
it "should generate append extra hash variables to the end (when the first parts are an array)" do
|
47
|
+
route_set.add_named_route(:sample, '/sample/:first/:second', :controller => 'sample')
|
48
|
+
['/sample/maz/zoo?four=jane&third=zanz', '/sample/maz/zoo?third=zanz&four=jane'].include?(route_set.generate_url(:sample, ['maz', 'zoo'], :extra_params => {:third => 'zanz', :four => 'jane'})).should == true
|
49
|
+
end
|
50
|
+
|
46
51
|
it "should generate append extra hash variables to the end using [] syntax if its an array" do
|
47
52
|
route_set.add_named_route(:sample, '/sample/:first/:second', :controller => 'sample')
|
48
53
|
route_set.generate_url(:sample, {:first => 'maz', :second => 'zoo', :third => ['zanz', 'susie']}).should == '/sample/maz/zoo?third%5B%5D=zanz&third%5B%5D=susie'
|
@@ -52,7 +52,7 @@ describe "Usher (for rails) route recognition" do
|
|
52
52
|
|
53
53
|
it "should raise based upon an invalid route" do
|
54
54
|
route_set.add_named_route(:sample, '/sample', :controller => 'sample', :action => 'test')
|
55
|
-
proc { route_set.recognize(build_request_mock('/test/asdqwe', :post, {})) }.should raise_error
|
55
|
+
proc { route_set.recognize(build_request_mock('/test/asdqwe', :post, {})) }.should raise_error
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should add /:controller and /:controller/:action if /:controller/:action/:id is added" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joshbuddy-usher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|