Commit 0c419eec authored by Terence Lee's avatar Terence Lee

Merge pull request #5 from ojacobson/to_regex-tests

Verify to_regex in tests.
parents 5ebdbba7 fc128f43
...@@ -25,7 +25,7 @@ class NginxConfig ...@@ -25,7 +25,7 @@ class NginxConfig
end end
json["clean_urls"] ||= false json["clean_urls"] ||= false
json["routes"] ||= {} json["routes"] ||= {}
json["routes"] = Hash[json["routes"].map { |route, target| [to_regex(route), target] }] json["routes"] = Hash[json["routes"].map { |route, target| [self.class.to_regex(route), target] }]
json["redirects"] ||= {} json["redirects"] ||= {}
json["error_page"] ||= nil json["error_page"] ||= nil
json.each do |key, value| json.each do |key, value|
...@@ -37,8 +37,7 @@ class NginxConfig ...@@ -37,8 +37,7 @@ class NginxConfig
binding binding
end end
private def self.to_regex(path)
def to_regex(path)
segments = [] segments = []
while !path.empty? while !path.empty?
if path[0...2] == '**' if path[0...2] == '**'
...@@ -57,6 +56,7 @@ class NginxConfig ...@@ -57,6 +56,7 @@ class NginxConfig
end end
end end
if __FILE__ == $0
erb = ERB.new(File.read(TEMPLATE)).result(NginxConfig.new(USER_CONFIG).context) erb = ERB.new(File.read(TEMPLATE)).result(NginxConfig.new(USER_CONFIG).context)
File.write(NGINX_CONFIG, erb) File.write(NGINX_CONFIG, erb)
end
require_relative "spec_helper"
load File.join(File.dirname(__FILE__), '../scripts/config/make-config')
RSpec.describe "NginxConfig#to_regex" do
samples = [
['/foo/', '/foo/'],
['/foo/*', '/foo/[^/]*'],
['/foo/**', '/foo/.*'],
['/cache/*', '/cache/[^/]*'],
]
samples.each do |(input, output)|
it "converts #{input} to #{output}" do
result = NginxConfig.to_regex(input)
expect(result).to eq output
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment