Skip to content

Commit

Permalink
Category links (real links, not just a tags)
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed Jun 20, 2009
1 parent b4fafe8 commit 6195de9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
10 changes: 10 additions & 0 deletions features/step_definitions/site.rb
Expand Up @@ -121,8 +121,18 @@
click_link "Recipe for Meal 0"
end

When /^I click on the Italian category$/ do
click_link "Italian"
end


Then /^I should see the recipe page$/ do
response.should have_selector("h1",
:content => "Recipe for Meal 0")
end

Then /^I should see 5 Italian recipes$/ do
# 5 result rows + 1 header row
response.should have_selector("tr",
:count => 6)
end
7 changes: 4 additions & 3 deletions features/support/env.rb
Expand Up @@ -79,9 +79,10 @@
var ingredient_count = doc['preparations'] ? doc['preparations'].length : 0;
ret.field('sort_ingredient', zero_pad(ingredient_count, 5), 'yes', 'not_analyzed');
ret.field('date', doc['date'], 'yes');
ret.field('title', doc['title'], 'yes');
ret.field('prep_time', doc['prep_time'], 'yes');
ret.field('date', doc['date'], 'yes');
ret.field('title', doc['title'], 'yes');
ret.field('prep_time', doc['prep_time'], 'yes');
ret.field('category', (doc['tag_names'] || []).join(' '), 'yes');
return ret;
}
Expand Down
5 changes: 3 additions & 2 deletions helpers.rb
Expand Up @@ -26,13 +26,14 @@ def categories(context)

def recipe_category_link(recipe, category)
recipes = recipe.is_a?(Array) ? recipe : [recipe]
href = "/recipes/search?q=category:#{category.downcase}"
if recipes.any? { |r|
r['tag_names'] &&
r['tag_names'].include?(category.downcase)
}
%Q|<a class="active">#{category}</a>|
%Q|<a class="active" href="#{href}">#{category}</a>|
else
%Q|<a>#{category}</a>|
%Q|<a href="#{href}">#{category}</a>|
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/eee_helpers_spec.rb
Expand Up @@ -34,6 +34,11 @@
recipe_category_link(recipes, 'Italian').
should have_selector("a", :class => "active")
end
it "should link to the category search results" do
recipe_category_link({}, "Italian").
should have_selector("a",
:href => "/recipes/search?q=category:italian")
end
end

describe "wiki" do
Expand Down

0 comments on commit 6195de9

Please sign in to comment.