I have to admit that rspec is still a bit intimidating, so I'm not sure this is exactly the sort of spec you were looking for. Feel free to point out everything that's wrong here and I'll try again.

===
--- standard_tags_spec.rb
+++ standard_tags_spec.rb
@@ -383,6 +383,13 @@
it '<r:random> should render a randomly selected contained <r:option>' do page.should render("<r:random> <r:option>1</r:option> <r:option>2</r:option> <r:option>3</r:option> </r:random>").matching(/ ^(1|2|3)$/)
   end
+
+  describe "<r:option>" do
+    it "should render each option before returning" do
+      page(:parent)
+ page.should render('<r:random><r:children:each><r:option><r:title /></r:option></ r:children:each></r:random>').matching(/^(Child|Child\ 2|Child\ 3)$/)
+    end
+  end

   it '<r:comment> should render nothing it contains' do
page.should render('just a <r:comment>small </ r:comment>test').as('just a test')

===

The failure is:

expected "<r:random><r:children:each><r:option><r:title /></ r:option></r:children:each></r:random>"
    to render and match /^(Child|Child\ 2|Child\ 3)$/, but got "Parent"

On 2008/06/07, at 20:35, Sean Cribbs wrote:

Actually, I just answered my own question. We should really be rendering the contents of <r:option> at each pass, rather than passing the block back. The reason is that local context (tag.locals) will be potentially lost when you render the block after selecting the option. However, a spec that demonstrates the difference would be appreciated!

Sean

Sean Cribbs wrote:
This one has always been a mystery to me, however I believe it has to do with tag blocks versus expands. I imagine, however, we could produce a failing spec to demonstrate what is unexpected about the behavior. Any takers?

Sean

john muhl wrote:
On 2008/06/07, at 16:49, Andrew Neil wrote:

On 6 Jun 2008, at 01:01, john muhl wrote:

I'd like to insert part of a random subpage into the sidebar and figured it'd be a good fit for the <r:random> tag but so far am having very little luck. I've tried:

<r:random>
<r:children:each>
<r:option><r:title/></r:option>
</r:children:each>
</r:random>

I thought of an alternative approach which might be easier to implement. Here is an example:

<r:find url="/quotations">
<r:children:each limit="1" order="rand">
    <r:content part="body"/>
</r:children:each>
</r:find>

This doesn't work at the moment, because the order attribute can only be asc or desc. I think it would be pretty easy to add the option for random order though.

I was going to try putting together a patch to add "rand" as an order option, but as far as I can tell the "ASC" and "DESC" ordering is part of ActiveRecord and that seems like the wrong place to apply a patch for Radiant. Am I way off base here or are the ordering options, in fact, part of ActiveRecord?
_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant




_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to