Skip to content

Commit

Permalink
Allow configuration of which snip is the root
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyatom committed Nov 23, 2009
1 parent 61cd607 commit 47c8020
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -25,7 +25,7 @@ if Object.const_defined?(:Gem)

# Change these as appropriate
s.name = "vanilla"
s.version = "1.9.13.3"
s.version = "1.9.14"
s.summary = "A bliki-type web content thing."
s.author = "James Adam"
s.email = "james@lazyatom.com.com"
Expand Down
2 changes: 1 addition & 1 deletion lib/vanilla/request.rb
Expand Up @@ -72,7 +72,7 @@ def uri_path(request)
def request_uri_parts(request)
case CGI.unescape(uri_path(request))
when URL_ROOT
['start', nil, 'html']
[@app.config[:root_snip] || 'start', nil, 'html']
when URL_SNIP
[$1, nil, $3]
when URL_SNIP_AND_PART
Expand Down
26 changes: 15 additions & 11 deletions test/test_helper.rb
Expand Up @@ -19,51 +19,55 @@ def setup_clean_environment
@app.soup << CurrentSnip.snip_attributes
create_snip :name => "system", :main_template => "{current_snip}"
end

def response_for(url)
@app.call(mock_env_for_url(url))
end

def response_body_for(url)
response_for(url)[2].body[0]
end

def response_code_for(url)
response_for(url)[0]
end

def assert_response_body(expected, uri)
assert_equal expected, response_body_for(uri)
end

def set_main_template(template_content)
system = @app.soup["system"] || Snip.new({:name => "system"}, @app.soup)
system.main_template = template_content
system.save
end

def create_snip(params)
s = Snip.new(params, @app.soup)
s.save
s
end

def mock_env_for_url(url)
Rack::MockRequest.env_for(url)
end

def mock_request(url)
Rack::Request.new(mock_env_for_url(url))
end

def test_config_file
File.join(File.dirname(__FILE__), "tmp", "config.yml")
end


def test_config(options={})
File.open(test_config_file, 'w') { |f| f.write({:soup => soup_path}.update(options).to_yaml) }
end

def soup_path
File.expand_path(File.join(File.dirname(__FILE__), "tmp", "soup"))
end

def clear_soup
FileUtils.rm_rf(soup_path)
end
Expand All @@ -76,4 +80,4 @@ class Vanilla::TestCase < Test::Unit::TestCase
def setup
setup_clean_environment
end
end
end
25 changes: 24 additions & 1 deletion test/vanilla_request_test.rb
@@ -1,6 +1,29 @@
require File.join(File.dirname(__FILE__), "test_helper")

class VanillaRequestTest < Vanilla::TestCase
context "when requesting the root" do
setup { @request = Vanilla::Request.new(mock_env_for_url("/"), @app) }

should "set snip to 'start' by default" do
assert_equal "start", @request.snip_name
end

should "set format to 'html'" do
assert_equal "html", @request.format
end

context "with a start snip configuration set" do
setup do
test_config(:root_snip => "custom")
@app = Vanilla::App.new(test_config_file)
end

should "use specified snip as default" do
assert_equal "custom", Vanilla::Request.new(mock_env_for_url("/"), @app).snip_name
end
end
end

context "when requesting urls" do
setup { @request = Vanilla::Request.new(mock_env_for_url("/snip"), @app) }

Expand Down Expand Up @@ -67,7 +90,7 @@ class VanillaRequestTest < Vanilla::TestCase
end
end

context "when requested with a _method paramter" do
context "when requested with a _method parameter" do
should "return the method using the parameter" do
assert_equal 'put', Vanilla::Request.new(mock_env_for_url("/snip?_method=put"), @app).method
end
Expand Down
2 changes: 1 addition & 1 deletion vanilla.gemspec
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = %q{vanilla}
s.version = "1.9.13.3"
s.version = "1.9.14"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["James Adam"]
Expand Down

0 comments on commit 47c8020

Please sign in to comment.