Skip to content

Commit

Permalink
Finish the recipe wikification specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed Apr 9, 2009
1 parent 2bbfd48 commit 5c61f4c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
13 changes: 12 additions & 1 deletion helpers.rb
Expand Up @@ -24,11 +24,22 @@ def wiki(original)
text = original.dup
text.gsub!(/\b(\d+)F/, "\\1° F")
text.gsub!(/\[kid:(\w+)\]/m) { |kid| kid_nicknames[$1] }
text.gsub!(/\[recipe:(\S+)\]/m) { |r| recipe_link($1) }
RedCloth.new(text).to_html
end

def kid_nicknames
{ }
@@kid_kicknames ||= JSON.parse(RestClient.get("#{_db}/kids"))
end

def _db
@@db
end

def recipe_link(permalink)
recipe = JSON.parse(RestClient.get("#{_db}/#{permalink}"))
%Q|<a href="/recipes/#{recipe['_id']}">#{recipe['title']}</a>|
end

end
end
25 changes: 18 additions & 7 deletions spec/eee_helpers_spec.rb
Expand Up @@ -22,13 +22,24 @@
wiki("250F").should contain("250° F")
end

it "should wikify kids names" do
self.stub!(:kid_nicknames).
and_return({"marsha" => "the oldest Brady girl"})
wiki("[kid:marsha]").should contain("the oldest Brady girl")
end
context "data stored in CouchDB" do
before(:each) do
self.stub!(:_db).and_return("http://example.org/couchdb")
end

it "should lookup kid nicknames" do
RestClient.stub!(:get).and_return('{"marsha":"the oldest Brady girl"}')
wiki("[kid:marsha]").should contain("the oldest Brady girl")
end

it "should lookup kid nicknames in CouchDB"
it "should wikify recipe URIs" do
RestClient.stub!(:get).
and_return('{"_id":"id-123","title":"Title"}')

it "should wikify recipe URIs"
wiki("[recipe:id-123]").
should have_selector("a",
:href => "/recipes/id-123",
:content => "Title")
end
end
end

0 comments on commit 5c61f4c

Please sign in to comment.