Skip to content

Commit

Permalink
Start on the show meal action.
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed May 30, 2009
1 parent daa93d7 commit 0439c3e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
4 changes: 4 additions & 0 deletions eee.rb
Expand Up @@ -16,6 +16,10 @@
include Eee::Helpers
end

get %r{/meals/(\d+)/(\d+)/(\d+)} do |year, month, day|
end


get %r{/meals/(\d+)/(\d+)} do |year, month|
url = "#{@@db}/_design/meals/_view/by_month?group=true&key=%22#{year}-#{month}%22"
data = RestClient.get url
Expand Down
29 changes: 27 additions & 2 deletions features/browse_meals.feature
Expand Up @@ -36,6 +36,31 @@ Feature: Browse Meals
Scenario: Browsing a meal on a specific date

Given a "Focaccia!" meal enjoyed on March 3, 2009
When I view the meal
And a "Focaccia" recipe from March 3, 2009
When I view the "Focaccia!" meal
Then I should see the "Focaccia!" title
And I should see a link to the "Focaccia" recipe in the menu
When I click the "March" link
Then I should see "Focaccia!" in the list of meals
When I click the "Focaccia" link
And I click the "2009" link
Then I should see "Focaccia!" in the list of meals
When I click the "Focaccia!" link
And I click the "Focaccia" link
Then I should see the "Focaccia" recipe

Scenario: Navigating between meals

Given a "Focaccia!" meal enjoyed on March 3, 2009
And a "Star Wars: The Dinner" meal enjoyed on February 28, 2009
And "Pumpkin is a Very Exciting Vegetable" meal enjoyed on December 3, 2008
When I view the "Focaccia!" meal
Then I should see the "Focaccia!" title
When I click "Star Wars: The Dinner"
Then I should see the "Star Wars: The Dinner" title
When I click "Pumpkin is a Very Exciting Vegetable"
Then I should see the "Pumpkin is a Very Exciting Vegetable" title
When I click "Star Wars: The Dinner"
Then I should see the "Star Wars: The Dinner" title
When I click "Focaccia!"
Then I should see the "Focaccia!" title
And I should be able to follow a link to the list of meals in March of 2009
4 changes: 2 additions & 2 deletions features/recipe_search.feature
Expand Up @@ -52,7 +52,7 @@ Feature: Search for recipes
Scenario: Paginating results

Given 50 yummy recipes
And a 0.5 second wait to allow the search index to be updated
And a 1 second wait to allow the search index to be updated
When I search for "yummy"
Then I should see 20 results
And I should see 3 pages of results
Expand All @@ -75,7 +75,7 @@ Feature: Search for recipes
Scenario: Sorting (name, date, preparation time, number of ingredients)

Given 50 "delicious" recipes with ascending names, dates, preparation times, and number of ingredients
And a 0.5 second wait to allow the search index to be updated
And a 1 second wait to allow the search index to be updated
When I search for "delicious"
Then I should see 20 results
When I click the "Name" column header
Expand Down
11 changes: 8 additions & 3 deletions features/step_definitions/meal_details.rb
@@ -1,8 +1,8 @@
Given /^a "([^\"]*)" meal enjoyed in (.+)$/ do |title, date_str|
Given /^a "([^\"]*)" meal enjoyed [io]n (.+)$/ do |title, date_str|
date = (date_str =~ /^\s*(\d+)\s*$/) ?
Date.new($1.to_i, 5, 13) : Date.parse(date_str)

permalink = "id-#{date.to_s}"
@meal_permalink = date.to_s

meal = {
:title => title,
Expand All @@ -14,7 +14,7 @@
:menu => []
}

RestClient.put "#{@@db}/#{permalink}",
RestClient.put "#{@@db}/#{@meal_permalink}",
meal.to_json,
:content_type => 'application/json'
end
Expand All @@ -29,6 +29,11 @@
response.status.should == 200
end

When /^I view the "([^\"]*)" meal$/ do |arg1|
visit("/meals/#{@meal_permalink.gsub(/-/, '/')}")
response.status.should == 200
end

When /^I follow the link to the list of meals in (.+)$/ do |date|
click_link date
end
Expand Down
16 changes: 16 additions & 0 deletions features/step_definitions/recipe_details.rb
Expand Up @@ -134,6 +134,22 @@
:content_type => 'application/json'
end

Given /^a "([^\"]*)" recipe from (.+)$/ do |title, date_str|
date = Date.parse(date_str)
@recipe_permalink = date.to_s + "-" + title.downcase.gsub(/\W/, '-')

recipe = {
:title => title,
:date => date,
:summary => "#{title} summary",
:instructions => "#{title} instructions"
}

RestClient.put "#{@@db}/#{@recipe_permalink}",
recipe.to_json,
:content_type => 'application/json'
end

When /^I view the recipe$/ do
visit("/recipes/#{@permalink}")
end
Expand Down
7 changes: 7 additions & 0 deletions spec/eee_spec.rb
Expand Up @@ -92,6 +92,13 @@
get "/meals/2009/05"
end
end

describe "GET /meals/YYYY/MM/DD" do
it "should respond OK" do
get "/meals/2009/05/28"
response.should be_ok
end
end
end

describe "a CouchDB recipe" do
Expand Down

0 comments on commit 0439c3e

Please sign in to comment.