Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add Creel::Helpers; add #translate_path

  • Loading branch information...
commit 849b286d51d34caa59920414220c64bf00f98089 1 parent 034a3c9
@bleything authored
View
1  lib/creel.rb
@@ -1,5 +1,6 @@
$: << File.expand_path("..", __FILE__)
+require 'creel/helpers'
require 'creel/ui'
module Creel
View
13 lib/creel/helpers.rb
@@ -0,0 +1,13 @@
+module Creel
+ module Helpers
+
+ ### translates a path into a collection name
+ def translate_path( path )
+ path = [path].flatten.join('_')
+
+ return "root" if path.empty? or path == "/"
+ return path.gsub( %r(/), '_' )
+ end
+
+ end
+end
View
1  lib/creel/ui.rb
@@ -2,6 +2,7 @@
module Creel
class UI < Sinatra::Base
+ include Creel::Helpers
### GET /any/url => generic text response
get '*' do
View
26 test/test_creel_helpers.rb
@@ -0,0 +1,26 @@
+require "minitest/autorun"
+require "creel/helpers"
+
+class TestCreelHelpers < MiniTest::Unit::TestCase
+ def setup
+ @t = Object.new
+ @t.extend Creel::Helpers
+ end
+
+ def test_translate_path_returns_root_for_empty_string
+ assert_equal "root", @t.translate_path( [''] )
+ end
+
+ def test_translate_path_returns_root_for_single_slash
+ assert_equal "root", @t.translate_path( ['/'] )
+ end
+
+ def test_translate_path_joins_arrays_with_underscores
+ assert_equal "foo_bar", @t.translate_path( %w(foo bar) )
+ end
+
+ def test_translate_path_replaces_slashes_with_underscores
+ assert_equal "foo_bar", @t.translate_path( "foo/bar" )
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.