vanilla 1.9.13.2 → 1.9.14
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +11 -10
- data/lib/vanilla/request.rb +1 -1
- data/test/base_renderer_test.rb +40 -0
- data/test/dynasnip_test.rb +31 -0
- data/test/erb_renderer_test.rb +31 -0
- data/test/markdown_renderer_test.rb +33 -0
- data/test/raw_renderer_test.rb +23 -0
- data/test/ruby_renderer_test.rb +59 -0
- data/{spec/spec_helper.rb → test/test_helper.rb} +27 -14
- data/test/tmp/config.yml +2 -0
- data/{spec → test}/tmp/soup/current_snip.yml +2 -2
- data/test/tmp/soup/system.yml +5 -0
- data/test/vanilla_app_test.rb +73 -0
- data/test/vanilla_presenting_test.rb +82 -0
- data/test/vanilla_request_test.rb +98 -0
- metadata +26 -17
- data/spec/dynasnip_spec.rb +0 -28
- data/spec/renderers/base_renderer_spec.rb +0 -40
- data/spec/renderers/erb_renderer_spec.rb +0 -27
- data/spec/renderers/markdown_renderer_spec.rb +0 -29
- data/spec/renderers/raw_renderer_spec.rb +0 -21
- data/spec/renderers/ruby_renderer_spec.rb +0 -59
- data/spec/renderers/vanilla_app_detecting_renderer_spec.rb +0 -35
- data/spec/tmp/config.yml +0 -2
- data/spec/tmp/soup/system.yml +0 -5
- data/spec/vanilla_app_spec.rb +0 -38
- data/spec/vanilla_presenting_spec.rb +0 -84
- data/spec/vanilla_request_spec.rb +0 -73
data/Rakefile
CHANGED
@@ -2,14 +2,14 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
|
|
2
2
|
require 'vanilla'
|
3
3
|
load File.join(File.dirname(__FILE__), *%w[lib tasks vanilla.rake])
|
4
4
|
|
5
|
-
|
6
|
-
require 'spec/rake/spectask'
|
7
|
-
Spec::Rake::SpecTask.new do |t|
|
8
|
-
t.spec_opts = %w(--format specdoc --colour)
|
9
|
-
t.libs = ["spec"]
|
10
|
-
end
|
5
|
+
task :default => :test
|
11
6
|
|
12
|
-
|
7
|
+
require "rake/testtask"
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << "test"
|
10
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
11
|
+
t.verbose = true
|
12
|
+
end
|
13
13
|
|
14
14
|
require "rubygems"
|
15
15
|
require "rake/gempackagetask"
|
@@ -25,7 +25,7 @@ if Object.const_defined?(:Gem)
|
|
25
25
|
|
26
26
|
# Change these as appropriate
|
27
27
|
s.name = "vanilla"
|
28
|
-
s.version = "1.9.
|
28
|
+
s.version = "1.9.14"
|
29
29
|
s.summary = "A bliki-type web content thing."
|
30
30
|
s.author = "James Adam"
|
31
31
|
s.email = "james@lazyatom.com.com"
|
@@ -36,7 +36,7 @@ if Object.const_defined?(:Gem)
|
|
36
36
|
s.rdoc_options = %w(--main README)
|
37
37
|
|
38
38
|
# Add any extra files to include in the gem
|
39
|
-
s.files = %w(config.example.yml config.ru Rakefile README README_FOR_APP) + Dir.glob("{
|
39
|
+
s.files = %w(config.example.yml config.ru Rakefile README README_FOR_APP) + Dir.glob("{test,lib,bin,public}/**/*")
|
40
40
|
s.executables = ['vanilla']
|
41
41
|
s.require_paths = ["lib"]
|
42
42
|
|
@@ -49,7 +49,8 @@ if Object.const_defined?(:Gem)
|
|
49
49
|
s.add_dependency("treetop", ">= 1.4.1")
|
50
50
|
s.add_dependency("warden", ">= 0.5.2")
|
51
51
|
|
52
|
-
s.add_development_dependency("
|
52
|
+
s.add_development_dependency("shoulda") # add any other gems for testing/development
|
53
|
+
s.add_development_dependency("mocha")
|
53
54
|
|
54
55
|
# If you want to publish automatically to rubyforge, you'll may need
|
55
56
|
# to tweak this, and the publishing task below too.
|
data/lib/vanilla/request.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class BaseRendererTest < Vanilla::TestCase
|
4
|
+
context "in general" do
|
5
|
+
setup do
|
6
|
+
create_snip(:name => "test", :content => "content content", :part => "part content")
|
7
|
+
end
|
8
|
+
|
9
|
+
should "render the contents part of the snip as it is" do
|
10
|
+
assert_response_body "content content", "/test"
|
11
|
+
end
|
12
|
+
|
13
|
+
should "render the specified part of the snip" do
|
14
|
+
assert_response_body "part content", "/test/part"
|
15
|
+
end
|
16
|
+
|
17
|
+
should "include the contents of a referenced snip" do
|
18
|
+
create_snip(:name => "snip_with_inclusions", :content => "loading {test}")
|
19
|
+
assert_response_body "loading content content", "/snip_with_inclusions"
|
20
|
+
end
|
21
|
+
|
22
|
+
should "perform snip inclusion when rendering a part" do
|
23
|
+
create_snip(:name => "snip_with_inclusions", :content => "other content", :part => "loading {test}")
|
24
|
+
assert_response_body "loading content content", "/snip_with_inclusions/part"
|
25
|
+
end
|
26
|
+
|
27
|
+
should "include other snips using their renderers" do
|
28
|
+
create_snip(:name => "including_snip", :content => "lets include {another_snip}")
|
29
|
+
create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
|
30
|
+
assert_equal "lets include <b>blah</b>", response_body_for("/including_snip").gsub(/\s+/, ' ')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when trying to include a missing snip" do
|
35
|
+
should "return a string describing the missing snip" do
|
36
|
+
create_snip(:name => 'blah', :content => 'include a {missing_snip}')
|
37
|
+
assert_response_body "include a [snip 'missing_snip' cannot be found]", "/blah"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
require 'vanilla/dynasnip'
|
3
|
+
|
4
|
+
class DynasnipTest < Vanilla::TestCase
|
5
|
+
|
6
|
+
context "when storing attributes" do
|
7
|
+
|
8
|
+
class ::TestDyna < Dynasnip
|
9
|
+
attribute :test_attribute, "test attribute content"
|
10
|
+
end
|
11
|
+
|
12
|
+
should "make the attribute available as an instance method" do
|
13
|
+
assert_equal "test attribute content", TestDyna.new(@app).test_attribute
|
14
|
+
end
|
15
|
+
|
16
|
+
should "store the attribute in the soup" do
|
17
|
+
@app.soup << TestDyna.snip_attributes
|
18
|
+
assert_equal "test attribute content", @app.soup['test_dyna'].test_attribute
|
19
|
+
end
|
20
|
+
|
21
|
+
should "allow the attribute to be overriden by the soup contents" do
|
22
|
+
@app.soup << TestDyna.snip_attributes
|
23
|
+
snip = @app.soup['test_dyna']
|
24
|
+
snip.test_attribute = "altered content"
|
25
|
+
snip.save
|
26
|
+
|
27
|
+
assert_equal "altered content", TestDyna.new(@app).test_attribute
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class ErbRendererTest < Vanilla::TestCase
|
4
|
+
context "when rendering" do
|
5
|
+
should "insert evaluated Erb content into the snip" do
|
6
|
+
erb_snip(:name => "test", :content => "<%= 1 + 2 %>")
|
7
|
+
assert_response_body "3", "/test"
|
8
|
+
end
|
9
|
+
|
10
|
+
should "evaluate Erb content in the snip" do
|
11
|
+
erb_snip(:name => "test", :content => "<% if false %>monkey<% else %>donkey<% end %>")
|
12
|
+
assert_response_body "donkey", "/test"
|
13
|
+
end
|
14
|
+
|
15
|
+
should "expose the snip as an instance variable" do
|
16
|
+
erb_snip(:name => "test", :content => "<%= @snip.name %>")
|
17
|
+
assert_response_body "test", "/test"
|
18
|
+
end
|
19
|
+
|
20
|
+
should "expose the app as an instance variable" do
|
21
|
+
erb_snip(:name => "test", :content => "<%= @app.class.name %>")
|
22
|
+
assert_response_body "Vanilla::App", "/test"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def erb_snip(params)
|
29
|
+
create_snip(params.merge(:render_as => "Erb"))
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class MarkdownRendererTest < Vanilla::TestCase
|
4
|
+
context "when rendering" do
|
5
|
+
should "return the snip contents rendered via Markdown" do
|
6
|
+
content = <<Markdown
|
7
|
+
# markdown
|
8
|
+
|
9
|
+
* totally
|
10
|
+
* [rocks](http://www.example.com)!
|
11
|
+
Markdown
|
12
|
+
markdown_snip(:name => "test", :content => content)
|
13
|
+
assert_response_body BlueCloth.new(content).to_html, "/test"
|
14
|
+
end
|
15
|
+
|
16
|
+
should "include other snips using their renderers" do
|
17
|
+
markdown_snip(:name => "test", :content => <<-Markdown
|
18
|
+
# markdown
|
19
|
+
|
20
|
+
and so lets include {another_snip}
|
21
|
+
Markdown
|
22
|
+
)
|
23
|
+
create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
|
24
|
+
assert_equal "<h1>markdown</h1> <p>and so lets include <b>blah</b></p>", response_body_for("/test").gsub(/\s+/, ' ')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def markdown_snip(attributes)
|
31
|
+
create_snip(attributes.merge(:render_as => "Markdown"))
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class RawRendererTest < Vanilla::TestCase
|
4
|
+
context "when rendering" do
|
5
|
+
setup do
|
6
|
+
@snip = create_snip(:name => "test", :content => "raw content", :part => "raw part")
|
7
|
+
set_main_template "<tag>{current_snip}</tag>"
|
8
|
+
end
|
9
|
+
|
10
|
+
should "render the contents part of the snip as it is" do
|
11
|
+
assert_response_body "raw content", "/test.raw"
|
12
|
+
end
|
13
|
+
|
14
|
+
should "render the specified part of the snip" do
|
15
|
+
assert_response_body "raw part", "/test/part.raw"
|
16
|
+
end
|
17
|
+
|
18
|
+
should "not perform any snip inclusion" do
|
19
|
+
create_snip(:name => "snip_with_inclusions", :content => "loading {another_snip}")
|
20
|
+
assert_response_body "loading {another_snip}", "/snip_with_inclusions.raw"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class RubyRendererTest < Vanilla::TestCase
|
4
|
+
context "when rendering normally" do
|
5
|
+
class ::TestDyna < Dynasnip
|
6
|
+
def handle(*args)
|
7
|
+
'handle called'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
setup do
|
12
|
+
@app.soup << TestDyna.snip_attributes
|
13
|
+
end
|
14
|
+
|
15
|
+
should "render the result of the handle method" do
|
16
|
+
assert_response_body 'handle called', "/test_dyna"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when responding restfully" do
|
21
|
+
class ::RestishDyna < Dynasnip
|
22
|
+
def get(*args)
|
23
|
+
'get called'
|
24
|
+
end
|
25
|
+
def post(*args)
|
26
|
+
'post called'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
setup do
|
31
|
+
@app.soup << RestishDyna.snip_attributes
|
32
|
+
end
|
33
|
+
|
34
|
+
should "render the result of the get method on GET requests" do
|
35
|
+
assert_response_body 'get called', "/restish_dyna"
|
36
|
+
end
|
37
|
+
|
38
|
+
should "render the result of the post method on POST requests" do
|
39
|
+
assert_response_body 'post called', "/restish_dyna?_method=post"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when knowing about enclosing snips" do
|
44
|
+
class ::Encloser < Dynasnip
|
45
|
+
def handle(*args)
|
46
|
+
"enclosing snip is #{enclosing_snip.name}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
setup do
|
51
|
+
@app.soup << Encloser.snip_attributes
|
52
|
+
create_snip(:name => "test", :content => "{encloser}")
|
53
|
+
end
|
54
|
+
|
55
|
+
should "know about the snip that called this dynasnip" do
|
56
|
+
assert_response_body 'enclosing snip is test', "/test"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
2
|
+
require "rubygems"
|
2
3
|
require "vanilla"
|
3
|
-
require "
|
4
|
+
require "test/unit"
|
5
|
+
require "shoulda"
|
6
|
+
require "mocha"
|
4
7
|
require "fileutils"
|
5
8
|
require "rack/mock"
|
6
9
|
|
@@ -16,31 +19,35 @@ module Vanilla
|
|
16
19
|
@app.soup << CurrentSnip.snip_attributes
|
17
20
|
create_snip :name => "system", :main_template => "{current_snip}"
|
18
21
|
end
|
19
|
-
|
22
|
+
|
20
23
|
def response_for(url)
|
21
24
|
@app.call(mock_env_for_url(url))
|
22
25
|
end
|
23
|
-
|
26
|
+
|
24
27
|
def response_body_for(url)
|
25
28
|
response_for(url)[2].body[0]
|
26
29
|
end
|
27
|
-
|
30
|
+
|
28
31
|
def response_code_for(url)
|
29
32
|
response_for(url)[0]
|
30
33
|
end
|
31
|
-
|
34
|
+
|
35
|
+
def assert_response_body(expected, uri)
|
36
|
+
assert_equal expected, response_body_for(uri)
|
37
|
+
end
|
38
|
+
|
32
39
|
def set_main_template(template_content)
|
33
40
|
system = @app.soup["system"] || Snip.new({:name => "system"}, @app.soup)
|
34
41
|
system.main_template = template_content
|
35
42
|
system.save
|
36
43
|
end
|
37
|
-
|
44
|
+
|
38
45
|
def create_snip(params)
|
39
46
|
s = Snip.new(params, @app.soup)
|
40
47
|
s.save
|
41
48
|
s
|
42
49
|
end
|
43
|
-
|
50
|
+
|
44
51
|
def mock_env_for_url(url)
|
45
52
|
Rack::MockRequest.env_for(url)
|
46
53
|
end
|
@@ -48,23 +55,29 @@ module Vanilla
|
|
48
55
|
def mock_request(url)
|
49
56
|
Rack::Request.new(mock_env_for_url(url))
|
50
57
|
end
|
51
|
-
|
58
|
+
|
52
59
|
def test_config_file
|
53
60
|
File.join(File.dirname(__FILE__), "tmp", "config.yml")
|
54
61
|
end
|
55
|
-
|
62
|
+
|
63
|
+
def test_config(options={})
|
64
|
+
File.open(test_config_file, 'w') { |f| f.write({:soup => soup_path}.update(options).to_yaml) }
|
65
|
+
end
|
66
|
+
|
56
67
|
def soup_path
|
57
68
|
File.expand_path(File.join(File.dirname(__FILE__), "tmp", "soup"))
|
58
69
|
end
|
59
|
-
|
70
|
+
|
60
71
|
def clear_soup
|
61
72
|
FileUtils.rm_rf(soup_path)
|
62
73
|
end
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
66
|
-
|
67
|
-
|
68
|
-
config.before { setup_clean_environment }
|
69
|
-
end
|
77
|
+
class Vanilla::TestCase < Test::Unit::TestCase
|
78
|
+
include Vanilla::Test
|
70
79
|
|
80
|
+
def setup
|
81
|
+
setup_clean_environment
|
82
|
+
end
|
83
|
+
end
|
data/test/tmp/config.yml
ADDED
@@ -1,8 +1,7 @@
|
|
1
1
|
CurrentSnip--- # Soup attributes
|
2
|
+
:updated_at: 2009-11-23 22:14:50.820298 +00:00
|
2
3
|
:name: current_snip
|
3
4
|
:render_as: Ruby
|
4
|
-
:created_at: 2009-10-12 17:39:26.752915 +01:00
|
5
|
-
:updated_at: 2009-10-12 17:39:26.752917 +01:00
|
6
5
|
:usage: |-
|
7
6
|
The current_snip dyna normally returns the result of rendering the snip named by the
|
8
7
|
'snip' value in the parameters. This way, it can be used in templates to place the currently
|
@@ -13,3 +12,4 @@ CurrentSnip--- # Soup attributes
|
|
13
12
|
{current_snip name}
|
14
13
|
|
15
14
|
will output the name of the current snip, or the name of the snip currently being edited.
|
15
|
+
:created_at: 2009-11-23 22:14:50.820288 +00:00
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class VanillaAppTest < Vanilla::TestCase
|
4
|
+
|
5
|
+
context "when behaving as a Rack application" do
|
6
|
+
should "return an array of status code, headers and response" do
|
7
|
+
create_snip(:name => "test", :content => "content")
|
8
|
+
result = @app.call(mock_env_for_url("/test.text"))
|
9
|
+
assert_kind_of Array, result
|
10
|
+
assert_equal 200, result[0]
|
11
|
+
assert_kind_of Hash, result[1]
|
12
|
+
result[2].each{ |output| assert_equal "content", output }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when being configured" do
|
17
|
+
should "load a config file from the current working directory by default" do
|
18
|
+
File.expects(:open).with("config.yml").returns(StringIO.new({:soup => soup_path}.to_yaml))
|
19
|
+
Vanilla::App.new
|
20
|
+
end
|
21
|
+
|
22
|
+
should "load a config file given" do
|
23
|
+
File.open("/tmp/vanilla_config.yml", "w") { |f| f.write({:soup => soup_path, :hello => true}.to_yaml) }
|
24
|
+
app = Vanilla::App.new("/tmp/vanilla_config.yml")
|
25
|
+
assert app.config[:hello]
|
26
|
+
end
|
27
|
+
|
28
|
+
should "allow saving of configuration to the same file it was loaded from" do
|
29
|
+
config_file = "/tmp/vanilla_config.yml"
|
30
|
+
File.open(config_file, "w") { |f| f.write({:soup => soup_path, :hello => true}.to_yaml) }
|
31
|
+
app = Vanilla::App.new(config_file)
|
32
|
+
app.config[:saved] = true
|
33
|
+
app.config.save!
|
34
|
+
|
35
|
+
config = YAML.load(File.open(config_file))
|
36
|
+
assert config[:saved]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when detecting the snip renderer" do
|
41
|
+
setup do
|
42
|
+
@app = Vanilla::App.new(test_config_file)
|
43
|
+
end
|
44
|
+
|
45
|
+
should "return the constant refered to in the render_as property of the snip" do
|
46
|
+
snip = create_snip(:name => "blah", :render_as => "Raw")
|
47
|
+
assert_equal Vanilla::Renderers::Raw, @app.renderer_for(snip)
|
48
|
+
end
|
49
|
+
|
50
|
+
should "return Vanilla::Renderers::Base if no render_as property exists" do
|
51
|
+
snip = create_snip(:name => "blah")
|
52
|
+
assert_equal Vanilla::Renderers::Base, @app.renderer_for(snip)
|
53
|
+
end
|
54
|
+
|
55
|
+
should "return Vanilla::Renderers::Base if the render_as property is blank" do
|
56
|
+
snip = create_snip(:name => "blah", :render_as => '')
|
57
|
+
assert_equal Vanilla::Renderers::Base, @app.renderer_for(snip)
|
58
|
+
end
|
59
|
+
|
60
|
+
should "raise an error if the specified renderer doesn't exist" do
|
61
|
+
snip = create_snip(:name => "blah", :render_as => "NonExistentClass")
|
62
|
+
assert_raises(NameError) { @app.renderer_for(snip) }
|
63
|
+
end
|
64
|
+
|
65
|
+
should "load constants outside of the Vanilla::Renderers module" do
|
66
|
+
class ::MyRenderer
|
67
|
+
end
|
68
|
+
|
69
|
+
snip = create_snip(:name => "blah", :render_as => "MyRenderer")
|
70
|
+
assert_equal MyRenderer, @app.renderer_for(snip)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class VanillaPresentingTest < Vanilla::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@app.soup << LinkTo.snip_attributes
|
7
|
+
set_main_template "<tag>{current_snip}</tag>"
|
8
|
+
create_snip :name => "test", :content => "blah {other_snip}", :part => 'part content'
|
9
|
+
create_snip :name => "other_snip", :content => "blah!"
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when presenting as HTML" do
|
13
|
+
should "render the snip's content in the system template if no format or part is given" do
|
14
|
+
assert_response_body "<tag>blah blah!</tag>", "/test"
|
15
|
+
end
|
16
|
+
|
17
|
+
should "render the snip's content in the system template if the HTML format is given" do
|
18
|
+
assert_response_body "<tag>blah blah!</tag>", "/test.html"
|
19
|
+
end
|
20
|
+
|
21
|
+
should "render the requested part within the main template when a part is given" do
|
22
|
+
assert_response_body "<tag>part content</tag>", "/test/part"
|
23
|
+
end
|
24
|
+
|
25
|
+
should "have a response code of 200" do
|
26
|
+
assert_equal 200, response_code_for("/test")
|
27
|
+
assert_equal 200, response_code_for("/test.html")
|
28
|
+
assert_equal 200, response_code_for("/test/part")
|
29
|
+
assert_equal 200, response_code_for("/test/part.html")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when presenting content as text" do
|
34
|
+
should "render the snip's content outside of the main template with its default renderer" do
|
35
|
+
assert_response_body "blah blah!", "/test.text"
|
36
|
+
end
|
37
|
+
|
38
|
+
should "render the snip part outside the main template when a format is given" do
|
39
|
+
assert_response_body "part content", "/test/part.text"
|
40
|
+
end
|
41
|
+
|
42
|
+
should "have a response code of 200" do
|
43
|
+
assert_equal 200, response_code_for("/test.text")
|
44
|
+
assert_equal 200, response_code_for("/test/part.text")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when presenting raw content" do
|
49
|
+
should "render the snips contents exactly as they are" do
|
50
|
+
assert_response_body "blah {other_snip}", "/test.raw"
|
51
|
+
end
|
52
|
+
|
53
|
+
should "render the snip content exactly even if a render_as attribute exists" do
|
54
|
+
assert_response_body "CurrentSnip", "/current_snip.raw"
|
55
|
+
end
|
56
|
+
|
57
|
+
should "render a snips part if requested" do
|
58
|
+
assert_response_body "part content", "/test/part.raw"
|
59
|
+
end
|
60
|
+
|
61
|
+
should "have a response code of 200" do
|
62
|
+
assert_equal 200, response_code_for("/test.raw")
|
63
|
+
assert_equal 200, response_code_for("/test/part.raw")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when a missing snip is requested" do
|
68
|
+
should "render missing snip content in the main template" do
|
69
|
+
assert_response_body "<tag>Couldn't find snip #{LinkTo.new(@app).handle("missing_snip")}</tag>", "/missing_snip"
|
70
|
+
end
|
71
|
+
|
72
|
+
should "have a 404 response code" do
|
73
|
+
assert_equal 404, response_code_for("/missing_snip")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when requesting an unknown format" do
|
78
|
+
should "return a 500 status code" do
|
79
|
+
assert_equal 500, response_code_for("/test.monkey")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class VanillaRequestTest < Vanilla::TestCase
|
4
|
+
context "when requesting the root" do
|
5
|
+
setup { @request = Vanilla::Request.new(mock_env_for_url("/"), @app) }
|
6
|
+
|
7
|
+
should "set snip to 'start' by default" do
|
8
|
+
assert_equal "start", @request.snip_name
|
9
|
+
end
|
10
|
+
|
11
|
+
should "set format to 'html'" do
|
12
|
+
assert_equal "html", @request.format
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with a start snip configuration set" do
|
16
|
+
setup do
|
17
|
+
test_config(:root_snip => "custom")
|
18
|
+
@app = Vanilla::App.new(test_config_file)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "use specified snip as default" do
|
22
|
+
assert_equal "custom", Vanilla::Request.new(mock_env_for_url("/"), @app).snip_name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when requesting urls" do
|
28
|
+
setup { @request = Vanilla::Request.new(mock_env_for_url("/snip"), @app) }
|
29
|
+
|
30
|
+
should "use the first segement as the snip name" do
|
31
|
+
assert_equal "snip", @request.snip_name
|
32
|
+
end
|
33
|
+
|
34
|
+
should "try to load the snip based on the snip name" do
|
35
|
+
@app.soup.expects(:[]).with('snip').returns(:snip)
|
36
|
+
assert_equal :snip, @request.snip
|
37
|
+
end
|
38
|
+
|
39
|
+
should "have no part if the url contains only a single segment" do
|
40
|
+
assert_equal nil, @request.part
|
41
|
+
end
|
42
|
+
|
43
|
+
should "have a default format of html" do
|
44
|
+
assert_equal 'html', @request.format
|
45
|
+
end
|
46
|
+
|
47
|
+
should "determine the request method" do
|
48
|
+
assert_equal 'get', @request.method
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when requesting a snip part" do
|
53
|
+
setup { @request = Vanilla::Request.new(mock_env_for_url("/snip/part"), @app) }
|
54
|
+
|
55
|
+
should "use the first segment as the snip, and the second segment as the part" do
|
56
|
+
assert_equal "snip", @request.snip_name
|
57
|
+
assert_equal "part", @request.part
|
58
|
+
end
|
59
|
+
|
60
|
+
should "have a default format of html" do
|
61
|
+
assert_equal "html", @request.format
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when requesting a snip with a format" do
|
66
|
+
setup { @request = Vanilla::Request.new(mock_env_for_url("/snip.raw"), @app) }
|
67
|
+
|
68
|
+
should "use the extension as the format" do
|
69
|
+
assert_equal "raw", @request.format
|
70
|
+
end
|
71
|
+
|
72
|
+
should "retain the filename part of the path as the snip" do
|
73
|
+
assert_equal "snip", @request.snip_name
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when requesting a snip part with a format" do
|
78
|
+
setup { @request = Vanilla::Request.new(mock_env_for_url("/snip/part.raw"), @app) }
|
79
|
+
|
80
|
+
should "use the extension as the format" do
|
81
|
+
assert_equal "raw", @request.format
|
82
|
+
end
|
83
|
+
|
84
|
+
should "retain the first segment of the path as the snip" do
|
85
|
+
assert_equal "snip", @request.snip_name
|
86
|
+
end
|
87
|
+
|
88
|
+
should "use the filename part of the second segment as the snip part" do
|
89
|
+
assert_equal "part", @request.part
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when requested with a _method parameter" do
|
94
|
+
should "return the method using the parameter" do
|
95
|
+
assert_equal 'put', Vanilla::Request.new(mock_env_for_url("/snip?_method=put"), @app).method
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Adam
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-23 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -83,7 +83,17 @@ dependencies:
|
|
83
83
|
version: 0.5.2
|
84
84
|
version:
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
|
-
name:
|
86
|
+
name: shoulda
|
87
|
+
type: :development
|
88
|
+
version_requirement:
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: mocha
|
87
97
|
type: :development
|
88
98
|
version_requirement:
|
89
99
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,20 +116,19 @@ files:
|
|
106
116
|
- Rakefile
|
107
117
|
- README
|
108
118
|
- README_FOR_APP
|
109
|
-
-
|
110
|
-
-
|
111
|
-
-
|
112
|
-
-
|
113
|
-
-
|
114
|
-
-
|
115
|
-
-
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
120
|
-
-
|
121
|
-
-
|
122
|
-
- spec/vanilla_request_spec.rb
|
119
|
+
- test/base_renderer_test.rb
|
120
|
+
- test/dynasnip_test.rb
|
121
|
+
- test/erb_renderer_test.rb
|
122
|
+
- test/markdown_renderer_test.rb
|
123
|
+
- test/raw_renderer_test.rb
|
124
|
+
- test/ruby_renderer_test.rb
|
125
|
+
- test/test_helper.rb
|
126
|
+
- test/tmp/config.yml
|
127
|
+
- test/tmp/soup/current_snip.yml
|
128
|
+
- test/tmp/soup/system.yml
|
129
|
+
- test/vanilla_app_test.rb
|
130
|
+
- test/vanilla_presenting_test.rb
|
131
|
+
- test/vanilla_request_test.rb
|
123
132
|
- lib/defensio.rb
|
124
133
|
- lib/tasks/vanilla.rake
|
125
134
|
- lib/vanilla/app.rb
|
data/spec/dynasnip_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
-
require 'vanilla/dynasnip'
|
3
|
-
|
4
|
-
describe Dynasnip, "when storing attributes" do
|
5
|
-
class TestDyna < Dynasnip
|
6
|
-
attribute :test_attribute, "test attribute content"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should make the attribute available as an instance method" do
|
10
|
-
p TestDyna.new(@app).test_attribute
|
11
|
-
TestDyna.new(@app).test_attribute.should == "test attribute content"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should store the attribute in the soup" do
|
15
|
-
@app.soup << TestDyna.snip_attributes
|
16
|
-
@app.soup['test_dyna'].test_attribute.should == "test attribute content"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should allow the attribute to be overriden by the soup contents" do
|
20
|
-
@app.soup << TestDyna.snip_attributes
|
21
|
-
snip = @app.soup['test_dyna']
|
22
|
-
snip.test_attribute = "altered content"
|
23
|
-
snip.save
|
24
|
-
|
25
|
-
TestDyna.new(@app).test_attribute.should == "altered content"
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
-
|
3
|
-
describe Vanilla::Renderers::Base do
|
4
|
-
describe "in general" do
|
5
|
-
before(:each) do
|
6
|
-
create_snip(:name => "test", :content => "content content", :part => "part content")
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should render the contents part of the snip as it is" do
|
10
|
-
response_body_for("/test").should == "content content"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should render the specified part of the snip" do
|
14
|
-
response_body_for("/test/part").should == "part content"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should include the contents of a referenced snip" do
|
18
|
-
create_snip(:name => "snip_with_inclusions", :content => "loading {test}")
|
19
|
-
response_body_for("/snip_with_inclusions").should == "loading content content"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should perform snip inclusion when rendering a part" do
|
23
|
-
create_snip(:name => "snip_with_inclusions", :content => "other content", :part => "loading {test}")
|
24
|
-
response_body_for("/snip_with_inclusions/part").should == "loading content content"
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should include other snips using their renderers" do
|
28
|
-
create_snip(:name => "including_snip", :content => "lets include {another_snip}")
|
29
|
-
create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
|
30
|
-
response_body_for("/including_snip").gsub(/\s+/, ' ').should == "lets include <b>blah</b>"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "when trying to include a missing snip" do
|
35
|
-
it "should return a string describing the missing snip" do
|
36
|
-
create_snip(:name => 'blah', :content => 'include a {missing_snip}')
|
37
|
-
response_body_for("/blah").should == "include a [snip 'missing_snip' cannot be found]"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
-
|
3
|
-
describe Vanilla::Renderers::Erb, "when rendering" do
|
4
|
-
def erb_snip(params)
|
5
|
-
create_snip(params.merge(:render_as => "Erb"))
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should insert evaluated Erb content into the snip" do
|
9
|
-
erb_snip(:name => "test", :content => "<%= 1 + 2 %>")
|
10
|
-
response_body_for("/test").should == "3"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should evaluate Erb content in the snip" do
|
14
|
-
erb_snip(:name => "test", :content => "<% if false %>monkey<% else %>donkey<% end %>")
|
15
|
-
response_body_for("/test").should == "donkey"
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should expose the snip as an instance variable" do
|
19
|
-
erb_snip(:name => "test", :content => "<%= @snip.name %>")
|
20
|
-
response_body_for("/test").should == "test"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "shoudl expose the app as an instance variable" do
|
24
|
-
erb_snip(:name => "test", :content => "<%= @app.class.name %>")
|
25
|
-
response_body_for("/test").should == "Vanilla::App"
|
26
|
-
end
|
27
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
-
|
3
|
-
describe Vanilla::Renderers::Markdown, "when rendering" do
|
4
|
-
def markdown_snip(attributes)
|
5
|
-
create_snip(attributes.merge(:render_as => "Markdown"))
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should return the snip contents rendered via Markdown" do
|
9
|
-
content = <<Markdown
|
10
|
-
# markdown
|
11
|
-
|
12
|
-
* totally
|
13
|
-
* [rocks](http://www.example.com)!
|
14
|
-
Markdown
|
15
|
-
markdown_snip(:name => "test", :content => content)
|
16
|
-
response_body_for("/test").should == BlueCloth.new(content).to_html
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should include other snips using their renderers" do
|
20
|
-
markdown_snip(:name => "test", :content => <<-Markdown
|
21
|
-
# markdown
|
22
|
-
|
23
|
-
and so lets include {another_snip}
|
24
|
-
Markdown
|
25
|
-
)
|
26
|
-
create_snip(:name => "another_snip", :content => "blah", :render_as => "Bold")
|
27
|
-
response_body_for("/test").gsub(/\s+/, ' ').should == "<h1>markdown</h1> <p>and so lets include <b>blah</b> </p>"
|
28
|
-
end
|
29
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
-
|
3
|
-
describe Vanilla::Renderers::Raw, "when rendering" do
|
4
|
-
before(:each) do
|
5
|
-
@snip = create_snip(:name => "test", :content => "raw content", :part => "raw part")
|
6
|
-
set_main_template "<tag>{current_snip}</tag>"
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should render the contents part of the snip as it is" do
|
10
|
-
response_body_for("/test.raw").should == "raw content"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should render the specified part of the snip" do
|
14
|
-
response_body_for("/test/part.raw").should == "raw part"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should not perform any snip inclusion" do
|
18
|
-
create_snip(:name => "snip_with_inclusions", :content => "loading {another_snip}")
|
19
|
-
response_body_for("/snip_with_inclusions.raw").should == "loading {another_snip}"
|
20
|
-
end
|
21
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
-
|
3
|
-
describe Vanilla::Renderers::Ruby do
|
4
|
-
describe "when rendering normally" do
|
5
|
-
class TestDyna < Dynasnip
|
6
|
-
def handle(*args)
|
7
|
-
'handle called'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:each) do
|
12
|
-
@app.soup << TestDyna.snip_attributes
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should render the result of the handle method" do
|
16
|
-
response_body_for("/test_dyna").should == 'handle called'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "when responding restfully" do
|
21
|
-
class RestishDyna < Dynasnip
|
22
|
-
def get(*args)
|
23
|
-
'get called'
|
24
|
-
end
|
25
|
-
def post(*args)
|
26
|
-
'post called'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
before(:each) do
|
31
|
-
@app.soup << RestishDyna.snip_attributes
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should render the result of the get method on GET requests" do
|
35
|
-
response_body_for("/restish_dyna").should == 'get called'
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should render the result of the post method on POST requests" do
|
39
|
-
response_body_for("/restish_dyna?_method=post") == 'post called'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "when knowing about enclosing snips" do
|
44
|
-
class Encloser < Dynasnip
|
45
|
-
def handle(*args)
|
46
|
-
"enclosing snip is #{enclosing_snip.name}"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
before(:each) do
|
51
|
-
@app.soup << Encloser.snip_attributes
|
52
|
-
create_snip(:name => "test", :content => "{encloser}")
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should know about the snip that called this dynasnip" do
|
56
|
-
response_body_for("/test").should == 'enclosing snip is test'
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
-
|
3
|
-
describe "when detecting the snip renderer" do
|
4
|
-
before(:each) do
|
5
|
-
@app = Vanilla::App.new
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should return the constant refered to in the render_as property of the snip" do
|
9
|
-
snip = create_snip(:name => "blah", :render_as => "Raw")
|
10
|
-
@app.renderer_for(snip).should == Vanilla::Renderers::Raw
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should return Vanilla::Renderers::Base if no render_as property exists" do
|
14
|
-
snip = create_snip(:name => "blah")
|
15
|
-
@app.renderer_for(snip).should == Vanilla::Renderers::Base
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should return Vanilla::Renderers::Base if the render_as property is blank" do
|
19
|
-
snip = create_snip(:name => "blah", :render_as => '')
|
20
|
-
@app.renderer_for(snip).should == Vanilla::Renderers::Base
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should raise an error if the specified renderer doesn't exist" do
|
24
|
-
snip = create_snip(:name => "blah", :render_as => "NonExistentClass")
|
25
|
-
lambda { @app.renderer_for(snip) }.should raise_error
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should load constants outside of the Vanilla::Renderers module" do
|
29
|
-
class ::MyRenderer
|
30
|
-
end
|
31
|
-
|
32
|
-
snip = create_snip(:name => "blah", :render_as => "MyRenderer")
|
33
|
-
@app.renderer_for(snip).should == MyRenderer
|
34
|
-
end
|
35
|
-
end
|
data/spec/tmp/config.yml
DELETED
data/spec/tmp/soup/system.yml
DELETED
data/spec/vanilla_app_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe Vanilla::App do
|
4
|
-
describe "when behaving as a Rack application" do
|
5
|
-
it "should return an array of status code, headers and response" do
|
6
|
-
create_snip(:name => "test", :content => "content")
|
7
|
-
result = @app.call(mock_env_for_url("/test.text"))
|
8
|
-
result.should be_a_kind_of(Array)
|
9
|
-
result[0].should == 200
|
10
|
-
result[1].should be_a_kind_of(Hash)
|
11
|
-
result[2].each{ |output| output.should == "content" }
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "when being configured" do
|
16
|
-
it "should load a config file from the current working directory by default" do
|
17
|
-
File.should_receive(:open).with("config.yml").and_return(StringIO.new({:soup => soup_path}.to_yaml))
|
18
|
-
Vanilla::App.new
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should load a config file given" do
|
22
|
-
File.open("/tmp/vanilla_config.yml", "w") { |f| f.write({:soup => soup_path, :hello => true}.to_yaml) }
|
23
|
-
app = Vanilla::App.new("/tmp/vanilla_config.yml")
|
24
|
-
app.config[:hello].should be_true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should allow saving of configuration to the same file it was loaded from" do
|
28
|
-
config_file = "/tmp/vanilla_config.yml"
|
29
|
-
File.open(config_file, "w") { |f| f.write({:soup => soup_path, :hello => true}.to_yaml) }
|
30
|
-
app = Vanilla::App.new(config_file)
|
31
|
-
app.config[:saved] = true
|
32
|
-
app.config.save!
|
33
|
-
|
34
|
-
config = YAML.load(File.open(config_file))
|
35
|
-
config[:saved].should be_true
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
-
|
3
|
-
describe Vanilla::App do
|
4
|
-
before(:each) do
|
5
|
-
@app.soup << LinkTo.snip_attributes
|
6
|
-
set_main_template "<tag>{current_snip}</tag>"
|
7
|
-
create_snip :name => "test", :content => "blah {other_snip}", :part => 'part content'
|
8
|
-
create_snip :name => "other_snip", :content => "blah!"
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "when presenting as HTML" do
|
12
|
-
it "should render the snip's content in the system template if no format or part is given" do
|
13
|
-
response_body_for("/test").should == "<tag>blah blah!</tag>"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should render the snip's content in the system template if the HTML format is given" do
|
17
|
-
response_body_for("/test.html").should == "<tag>blah blah!</tag>"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should render the requested part within the main template when a part is given" do
|
21
|
-
response_body_for("/test/part").should == "<tag>part content</tag>"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should have a response code of 200" do
|
25
|
-
response_code_for("/test").should == 200
|
26
|
-
response_code_for("/test.html").should == 200
|
27
|
-
response_code_for("/test/part").should == 200
|
28
|
-
response_code_for("/test/part.html").should == 200
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "when presenting content as text" do
|
33
|
-
it "should render the snip's content outside of the main template with its default renderer" do
|
34
|
-
response_body_for("/test.text").should == "blah blah!"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should render the snip part outside the main template when a format is given" do
|
38
|
-
response_body_for("/test/part.text").should == "part content"
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should have a response code of 200" do
|
42
|
-
response_code_for("/test.text").should == 200
|
43
|
-
response_code_for("/test/part.text").should == 200
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
describe "when presenting raw content" do
|
49
|
-
it "should render the snips contents exactly as they are" do
|
50
|
-
response_body_for("/test.raw").should == "blah {other_snip}"
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should render the snip content exactly even if a render_as attribute exists" do
|
54
|
-
response_body_for("/current_snip.raw").should == "CurrentSnip"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should render a snips part if requested" do
|
58
|
-
response_body_for("/test/part.raw").should == "part content"
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should have a response code of 200" do
|
62
|
-
response_code_for("/test.raw").should == 200
|
63
|
-
response_code_for("/test/part.raw").should == 200
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
describe "when a missing snip is requested" do
|
69
|
-
it "should render missing snip content in the main template" do
|
70
|
-
response_body_for("/missing_snip").should == "<tag>Couldn't find snip #{LinkTo.new(@app).handle("missing_snip")}</tag>"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should have a 404 response code" do
|
74
|
-
response_code_for("/missing_snip").should == 404
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
describe "when requesting an unknown format" do
|
80
|
-
it "should return a 500 status code" do
|
81
|
-
response_code_for("/test.monkey").should == 500
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
-
|
3
|
-
describe Vanilla::Request, "when requesting urls" do
|
4
|
-
before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip"), @app) }
|
5
|
-
|
6
|
-
it "should use the first segement as the snip name" do
|
7
|
-
@request.snip_name.should == "snip"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should try to load the snip based on the snip name" do
|
11
|
-
@app.soup.should_receive(:[]).with('snip').and_return(:snip)
|
12
|
-
@request.snip.should == :snip
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should have no part if the url contains only a single segment" do
|
16
|
-
@request.part.should == nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should have a default format of html" do
|
20
|
-
@request.format.should == 'html'
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should determine the request method" do
|
24
|
-
@request.method.should == 'get'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe Vanilla::Request, "when requesting a snip part" do
|
29
|
-
before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip/part"), @app) }
|
30
|
-
|
31
|
-
it "should use the first segment as the snip, and the second segment as the part" do
|
32
|
-
@request.snip_name.should == "snip"
|
33
|
-
@request.part.should == "part"
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should have a default format of html" do
|
37
|
-
@request.format.should == "html"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe Vanilla::Request, "when requesting a snip with a format" do
|
42
|
-
before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip.raw"), @app) }
|
43
|
-
|
44
|
-
it "should use the extension as the format" do
|
45
|
-
@request.format.should == "raw"
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should retain the filename part of the path as the snip" do
|
49
|
-
@request.snip_name.should == "snip"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe Vanilla::Request, "when requesting a snip part with a format" do
|
54
|
-
before(:each) { @request = Vanilla::Request.new(mock_env_for_url("/snip/part.raw"), @app) }
|
55
|
-
|
56
|
-
it "should use the extension as the format" do
|
57
|
-
@request.format.should == "raw"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should retain the first segment of the path as the snip" do
|
61
|
-
@request.snip_name.should == "snip"
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should use the filename part of the second segment as the snip part" do
|
65
|
-
@request.part.should == "part"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe Vanilla::Request, "when requested with a _method paramter" do
|
70
|
-
it "should return the method using the parameter" do
|
71
|
-
Vanilla::Request.new(mock_env_for_url("/snip?_method=put"), @app).method.should == 'put'
|
72
|
-
end
|
73
|
-
end
|