Permalink
Browse files

more specs and fixed previous

  • Loading branch information...
1 parent 396e83a commit 3820ef42e19f2677733c9909c54f2f4ec06ea228 @saturnflyer committed Sep 15, 2008
Showing with 10 additions and 7 deletions.
  1. +4 −7 app/models/sibling_tags.rb
  2. +6 −0 spec/models/sibling_tags_spec.rb
View
@@ -91,9 +91,7 @@ module SiblingTags
<pre><code><r:siblings:next [by="published_at|title"] [order="asc|desc"] [status="published|all"]/>...</r:siblings:next></code></pre>
}
tag 'siblings:next' do |tag|
- if tag.locals.page = find_next_sibling(tag)
- tag.expand
- end
+ tag.expand if tag.locals.page = find_next_sibling(tag)
end
desc %{
@@ -107,9 +105,7 @@ module SiblingTags
[status="published|all"]/>...</r:siblings:previous></code></pre>
}
tag 'siblings:previous' do |tag|
- if tag.locals.page = find_previous_sibling(tag)
- tag.expand
- end
+ tag.expand if tag.locals.page = find_previous_sibling(tag)
end
private
@@ -124,7 +120,8 @@ def find_next_sibling(tag)
def find_previous_sibling(tag)
if tag.locals.page.parent
tag.attr['adjacent'] = 'previous'
- tag.locals.page.parent.children.find(:first, adjacent_siblings_find_options(tag))
+ sorted = tag.locals.page.parent.children.find(:all, adjacent_siblings_find_options(tag))
+ sorted.last unless sorted.blank?
end
end
@@ -54,6 +54,9 @@
it 'should not output its contents if the current page has siblings, but not next in order' do
page(:bashful).should render('<r:siblings:next>true</r:siblings:next>').as('')
end
+ it "should set the scoped page to the previous page in order" do
+ page(:doc).should render('<r:siblings:next><r:title /></r:siblings:next>').as('Bashful')
+ end
end
describe "<r:siblings:previous>" do
@@ -66,6 +69,9 @@
it 'should not output its contents if the current page has siblings, but not previous in order' do
page(:sneezy).should render('<r:siblings:previous>true</r:siblings:previous>').as('')
end
+ it "should set the scoped page to the previous page in order" do
+ page(:doc).should render('<r:siblings:previous><r:title /></r:siblings:previous>').as('Dopey')
+ end
end
describe "<r:sibling:if_next>" do

0 comments on commit 3820ef4

Please sign in to comment.