Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
109 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters