Skip to content

Commit

Permalink
Recipes are now grouped by tags. View should use a presenter. See #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
aCandidMind committed Oct 15, 2014
1 parent 431d5e6 commit 21e98a0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
4 changes: 3 additions & 1 deletion app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class RecipesController < ApplicationController
# GET /recipes
# GET /recipes.json
def index
@recipes = Recipe.all
# list recipes grouped by tag
#TODO Building a presenter here, would clean up the view. See issue #2.
@tags = RocketTag::Tag.all
end

# GET /recipes/1
Expand Down
1 change: 1 addition & 0 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Recipe < ActiveRecord::Base

include Votable
attr_taggable :topics

has_and_belongs_to_many :projects, join_table: :recipes_projects

Expand Down
22 changes: 11 additions & 11 deletions app/views/recipes/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
= link_to 'New Recipe', new_recipe_path

%section#recipes
- @recipes.each do |recipe|
%article
%h2= link_to recipe.name, recipe
.description= recipe.description
.actions
= link_to 'Edit', edit_recipe_path(recipe)
= link_to 'Destroy', recipe, method: :delete, data: {confirm: 'Are you sure?'}




- @tags.each do |tag|
%section{id: tag.name.parameterize('_'), class: 'tag'}
%h1= tag.name
- tag.taggings.each do |tagging|
- recipe = tagging.taggable
%article
%h3= link_to recipe.name, recipe
.description= recipe.description
.actions
= link_to 'Edit', edit_recipe_path(recipe)
= link_to 'Destroy', recipe, method: :delete, data: {confirm: 'Are you sure?'}
18 changes: 18 additions & 0 deletions test/acceptance/tagging_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'test_helper'
require 'tag_steps'

feature "Recipe Topic Tags" do
include TagSteps

given(:recipe) { recipes(:one) }

scenario "tagging a recipe makes it appear under that tag section" do
tag_name = "Planning Tools & Disaster Management"
tag_as_id = tag_name.parameterize('_')
tag_recipe(tag_name)
visit recipes_path
within "##{tag_as_id}.tag" do
assert_content(recipe.name)
end
end
end
8 changes: 8 additions & 0 deletions test/tag_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module TagSteps
def tag_recipe(tag)
recipe.topics = [tag]
recipe.save!
recipe.reload
recipe.topics.must_include(tag.downcase)
end
end

0 comments on commit 21e98a0

Please sign in to comment.