Skip to content

Commit

Permalink
More tests for dynasnips.
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyatom committed May 12, 2011
1 parent 73ea05e commit daa9f4b
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 41 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -9,7 +9,7 @@ PATH
rack (>= 0.9.1)
rack-test (>= 0.5.7)
ratom (>= 0.3.5)
soup (>= 1.0.6)
soup (>= 1.0.8)

GEM
remote: http://rubygems.org/
Expand Down Expand Up @@ -39,7 +39,7 @@ GEM
launchy (0.4.0)
configuration (>= 0.0.5)
rake (>= 0.8.1)
libxml-ruby (2.0.4)
libxml-ruby (2.0.5)
mime-types (1.16)
mocha (0.9.10)
rake
Expand All @@ -58,7 +58,7 @@ GEM
ffi (>= 1.0.7)
json_pure
rubyzip
soup (1.0.6)
soup (1.0.8)
xpath (0.1.3)
nokogiri (~> 1.3)

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -54,7 +54,7 @@ if Object.const_defined?(:Gem)

# All the other gems we need.
s.add_dependency("rack", ">= 0.9.1")
s.add_dependency("soup", ">= 1.0.6")
s.add_dependency("soup", ">= 1.0.8")
s.add_dependency("ratom", ">= 0.3.5")
s.add_dependency("RedCloth", ">= 4.1.1")
s.add_dependency("BlueCloth", ">= 1.0.0")
Expand Down
4 changes: 1 addition & 3 deletions pristine_app/soups/base/start.snip
Expand Up @@ -14,9 +14,7 @@

<h2>Adding your content</h2>

<p>This is the {link_to start} snip, which is the default home page. You can find this content in `start.snip`.</p>

<p>You should replace this content with whatever you want on your site's home page.</p>
<p>This is the {link_to start} snip, which is the default home page. You can find this content in <code>soups/base/start.snip</code>. You should replace this content with whatever you want on your site's home page.</p>

<p>Good luck!</p>
</div>
4 changes: 2 additions & 2 deletions pristine_app/soups/system/index.rb
Expand Up @@ -2,10 +2,10 @@

class Index < Dynasnip
def get(*args)
list = app.soup.instance_eval { @backend }.send(:all_snips).sort_by { |a| a.updated_at || Time.at(0) }.reverse.map { |snip|
list = app.soup.all_snips.sort_by { |a| a.updated_at || Time.at(0) }.reverse.map { |snip|
"<li>{link_to #{snip.name}}</li>"
}
"<ol>#{list}</ol>"
%{<ol id="index">#{list}</ol>}
end

self
Expand Down
40 changes: 40 additions & 0 deletions test/pristine_app/current_snip_test.rb
@@ -0,0 +1,40 @@
require "test_helper"

context "The current_snip dynasnip" do
should "render the snip from the current request" do
set_main_template "<layout>{current_snip}</layout>"
create_snip :name => "test", :content => "test"

visit "/test"

assert page.has_css?("layout", :content => "test")
end

should "render a given attribute of the current snip" do
create_snip :name => "test", :content => "this is my {current_snip part}", :part => "underbelly"
visit "/test"
assert page.has_content?("this is my underbelly")
end

should "render based on the requested snip, not the including snip" do
create_snip :name => "test", :content => "this is my {current_snip part}", :part => "underbelly"
create_snip :name => "blah", :content => "{test}", :part => "flange"
visit "/blah"
assert page.has_content?("this is my flange")
end

context "when the requested snip is missing" do
setup do
set_main_template "<layout>{current_snip}</layout>"
visit "/monkey"
end

should "render an explanatory message" do
assert page.has_content?(%{Couldn't find snip "monkey"})
end

should "set the response code to 404" do
assert_equal 404, page.status_code
end
end
end
34 changes: 34 additions & 0 deletions test/pristine_app/index_test.rb
@@ -0,0 +1,34 @@
require "test_helper"

context "The index dynasnip" do
should "render links to every snip with the most recently updated first" do
app.soup.stubs(:all_snips).returns([
snip(:name => "alpha", :updated_at => Time.at(10)),
snip(:name => "beta", :updated_at => Time.at(20)),
snip(:name => "gamma", :updated_at => Time.at(40)),
snip(:name => "delta", :updated_at => Time.at(30))
])

visit "/index"
links = page.all("ol#index li a").map { |l| l.text }
assert_equal %w(gamma delta beta alpha), links
end

should "order snips without updated_at as if they were updated a long time ago" do
app.soup.stubs(:all_snips).returns([
snip(:name => "alpha", :updated_at => Time.at(10)),
snip(:name => "beta", :updated_at => Time.at(20)),
snip(:name => "gamma")
])

visit "/index"
links = page.all("ol#index li a").map { |l| l.text }
assert_equal %w(beta alpha gamma), links
end

private

def snip(attributes)
Soup::Snip.new(attributes, nil)
end
end
1 change: 1 addition & 0 deletions test/pristine_app/test_helper.rb
@@ -1,6 +1,7 @@
$LOAD_PATH.unshift(File.expand_path("../../../lib"), __FILE__)
require "bundler/setup"
require "kintama"
require "kintama/mocha"
require "vanilla/test_helper"
require 'capybara'
require 'capybara/dsl'
Expand Down
59 changes: 27 additions & 32 deletions vanilla.gemspec
Expand Up @@ -6,7 +6,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["James Adam"]
s.date = %q{2011-05-11}
s.date = %q{2011-05-12}
s.default_executable = %q{vanilla}
s.email = %q{james@lazyatom.com.com}
s.executables = ["vanilla"]
Expand All @@ -17,33 +17,30 @@ Gem::Specification.new do |s|
"Rakefile",
"README",
".gemtest",
"test/configuration_test.rb",
"test/dynasnip_test.rb",
"test/dynasnips",
"test/dynasnips/link_to_current_snip_test.rb",
"test/dynasnips/link_to_test.rb",
"test/dynasnips/page_title_test.rb",
"test/core",
"test/core/configuration_test.rb",
"test/core/dynasnip_test.rb",
"test/core/renderers",
"test/core/renderers/base_renderer_test.rb",
"test/core/renderers/erb_renderer_test.rb",
"test/core/renderers/haml_renderer_test.rb",
"test/core/renderers/markdown_renderer_test.rb",
"test/core/renderers/raw_renderer_test.rb",
"test/core/renderers/ruby_renderer_test.rb",
"test/core/routing_test.rb",
"test/core/snip_inclusion_test.rb",
"test/core/snip_reference_parser_test.rb",
"test/core/test_helper.rb",
"test/core/vanilla_app_test.rb",
"test/core/vanilla_presenting_test.rb",
"test/core/vanilla_request_test.rb",
"test/pristine_app",
"test/pristine_app/capybara-20110511143347.html",
"test/pristine_app/index_test.rb",
"test/pristine_app/link_to_current_snip_test.rb",
"test/pristine_app/link_to_test.rb",
"test/pristine_app/page_title_test.rb",
"test/pristine_app/soups",
"test/pristine_app/soups/base",
"test/pristine_app/soups/system",
"test/pristine_app/raw_test.rb",
"test/pristine_app/test_helper.rb",
"test/renderers",
"test/renderers/base_renderer_test.rb",
"test/renderers/erb_renderer_test.rb",
"test/renderers/haml_renderer_test.rb",
"test/renderers/markdown_renderer_test.rb",
"test/renderers/raw_renderer_test.rb",
"test/renderers/ruby_renderer_test.rb",
"test/routing_test.rb",
"test/snip_inclusion_test.rb",
"test/snip_reference_parser_test.rb",
"test/test_helper.rb",
"test/vanilla_app_test.rb",
"test/vanilla_presenting_test.rb",
"test/vanilla_request_test.rb",
"lib/vanilla",
"lib/vanilla/app.rb",
"lib/vanilla/config.rb",
Expand All @@ -62,9 +59,6 @@ Gem::Specification.new do |s|
"lib/vanilla/request.rb",
"lib/vanilla/routing.rb",
"lib/vanilla/snip_reference_parser.rb",
"lib/vanilla/soups",
"lib/vanilla/soups/base",
"lib/vanilla/soups/system",
"lib/vanilla/static.rb",
"lib/vanilla/test_helper.rb",
"lib/vanilla.rb",
Expand Down Expand Up @@ -107,6 +101,7 @@ Gem::Specification.new do |s|
"pristine_app/soups/tutorial/tutorial-dynasnips.snip.markdown",
"pristine_app/soups/tutorial/tutorial-layout.snip",
"pristine_app/soups/tutorial/tutorial-links.snip",
"pristine_app/soups/tutorial/tutorial-removing.snip.markdown",
"pristine_app/soups/tutorial/tutorial-renderers.snip.markdown",
"pristine_app/soups/tutorial/tutorial.snip.markdown",
"pristine_app/soups/tutorial/vanilla-rb.snip",
Expand All @@ -118,15 +113,15 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--main", "README"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{vanilla}
s.rubygems_version = %q{1.5.0}
s.rubygems_version = %q{1.4.1}
s.summary = %q{A bliki-type web content thing.}

if s.respond_to? :specification_version then
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rack>, [">= 0.9.1"])
s.add_runtime_dependency(%q<soup>, [">= 1.0.6"])
s.add_runtime_dependency(%q<soup>, [">= 1.0.8"])
s.add_runtime_dependency(%q<ratom>, [">= 0.3.5"])
s.add_runtime_dependency(%q<RedCloth>, [">= 4.1.1"])
s.add_runtime_dependency(%q<BlueCloth>, [">= 1.0.0"])
Expand All @@ -139,7 +134,7 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<launchy>, [">= 0"])
else
s.add_dependency(%q<rack>, [">= 0.9.1"])
s.add_dependency(%q<soup>, [">= 1.0.6"])
s.add_dependency(%q<soup>, [">= 1.0.8"])
s.add_dependency(%q<ratom>, [">= 0.3.5"])
s.add_dependency(%q<RedCloth>, [">= 4.1.1"])
s.add_dependency(%q<BlueCloth>, [">= 1.0.0"])
Expand All @@ -153,7 +148,7 @@ Gem::Specification.new do |s|
end
else
s.add_dependency(%q<rack>, [">= 0.9.1"])
s.add_dependency(%q<soup>, [">= 1.0.6"])
s.add_dependency(%q<soup>, [">= 1.0.8"])
s.add_dependency(%q<ratom>, [">= 0.3.5"])
s.add_dependency(%q<RedCloth>, [">= 4.1.1"])
s.add_dependency(%q<BlueCloth>, [">= 1.0.0"])
Expand Down

0 comments on commit daa9f4b

Please sign in to comment.