-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from elfassy/path_parameter_strategy
path parameters strategy
- Loading branch information
Showing
4 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module VersionCake | ||
class PathParameterStrategy < ExtractionStrategy | ||
|
||
def execute(request) | ||
if request.path_parameters.key? @@version_string.to_sym | ||
request.path_parameters[@@version_string.to_sym] | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require './test/test_helper' | ||
|
||
class PathParameterStrategyTest < ActiveSupport::TestCase | ||
setup do | ||
@strategy = VersionCake::PathParameterStrategy.new | ||
end | ||
|
||
test "a request with an api_version path parameter retrieves the version" do | ||
request = stub(:path_parameters => {:api_version => '11', :other => 'parameter'}) | ||
assert_equal 11, @strategy.extract(request) | ||
end | ||
|
||
test "a request without an api_version path parameter returns nil" do | ||
request = stub(:path_parameters => {:other => 'parameter', :another => 'parameter'}) | ||
assert_nil @strategy.extract(request) | ||
end | ||
end |