Skip to content

Commit

Permalink
Switch the individual recipes resource to separate date elements by s…
Browse files Browse the repository at this point in the history
…lashes instead of dashes to be consistent with the legacy site and the rest of the current site. Still have some failing Cucumber scenarios
  • Loading branch information
eee-c committed Oct 15, 2009
1 parent de9ecd3 commit d4cec1a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions eee.rb
Expand Up @@ -175,8 +175,8 @@
haml @results['total_rows'] == 0 ? :no_results : :search
end

get '/recipes/:permalink' do
data = RestClient.get "#{@@db}/#{params[:permalink]}"
get %r{/recipes/(\d+)/(\d+)/(\d+)/?(.*)} do |year, month, day, short_name|
data = RestClient.get "#{@@db}/#{year}-#{month}-#{day}-#{short_name}"
@recipe = JSON.parse(data)
etag(@recipe['_rev'])

Expand Down
2 changes: 1 addition & 1 deletion helpers.rb
Expand Up @@ -72,7 +72,7 @@ def wiki_recipe(text)
def recipe_link(link, title=nil)
permalink = link.gsub(/\//, '-')
recipe = JSON.parse(RestClient.get("#{_db}/#{permalink}"))
%Q|<a href="/recipes/#{recipe['_id']}">#{title || recipe['title']}</a>|
%Q|<a href="/recipes/#{recipe['_id'].gsub(/-/, '/')}">#{title || recipe['title']}</a>|
end

def meal_link(link, title=nil)
Expand Down
6 changes: 3 additions & 3 deletions spec/eee_helpers_spec.rb
Expand Up @@ -98,7 +98,7 @@

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

Expand All @@ -108,7 +108,7 @@

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

Expand Down Expand Up @@ -168,7 +168,7 @@
it "should link to recipe resource" do
recipe_link("2009-06-11-recipe").
should have_selector("a",
:href => "/recipes/2009-06-11-recipe")
:href => "/recipes/2009/06/11/recipe")
end
it "should be able to link with \"slash\" dates (e.g. 2009/06/11/recipe)" do
RestClient.
Expand Down
10 changes: 5 additions & 5 deletions spec/eee_spec.rb
Expand Up @@ -238,14 +238,14 @@
get "/meals/2009/09/25", { }, { 'HTTP_IF_NONE_MATCH' => '"1234"' }
end
end
describe 'GET /recipes/permalink' do
describe 'GET /recipes/YYYY/MM/DD/short_name' do
it "should etag with the CouchDB document's revision" do
RestClient.
should_receive(:get).
once.
and_return('{"_rev":1234}')

get "/recipes/foo", { }, { 'HTTP_IF_NONE_MATCH' => '"1234"' }
get "/recipes/2009/10/14", { }, { 'HTTP_IF_NONE_MATCH' => '"1234"' }
end
end
end
Expand All @@ -254,7 +254,7 @@
before (:each) do
@date = Date.today
@title = "Recipe Title"
@permalink = @date.to_s + "-" + @title.downcase.gsub(/\W/, '-')
@permalink = @date.to_s + "-" + @title.downcase.gsub(/\W/, '_')

RestClient.put "#{@@db}/#{@permalink}",
{ :title => @title,
Expand All @@ -269,9 +269,9 @@
RestClient.delete "#{@@db}/#{@permalink}?rev=#{recipe['_rev']}"
end

describe 'GET /recipes/permalink' do
describe 'GET /recipes/YYYY/MM/DD/short_name' do
it "should respond OK" do
get "/recipes/#{@permalink}"
get "/recipes/#{@permalink.gsub(/-/, '/')}"
last_response.should be_ok
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/views/meal_by_month.haml_spec.rb
Expand Up @@ -66,7 +66,7 @@

RestClient.
stub!(:get).
and_return('{"title":"Lemon Dressing"}')
and_return('{"_id":"foo","title":"Lemon Dressing"}')

render("/views/meal_by_month.haml")
response.should have_selector(".menu",
Expand Down

0 comments on commit d4cec1a

Please sign in to comment.