Skip to content

Commit

Permalink
converting naming of 'formula' to 'recipe'
Browse files Browse the repository at this point in the history
  • Loading branch information
wrburgess committed May 8, 2013
1 parent ac17d91 commit 51d07d8
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 35 deletions.
11 changes: 0 additions & 11 deletions app/controllers/api/v1/formulas_controller.rb

This file was deleted.

11 changes: 11 additions & 0 deletions app/controllers/api/v1/recipes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Api::V1::RecipesController < ApiController

def index
respond_with Recipe.all
end

def show
respond_with Recipe.find(params[:id])
end

end
2 changes: 1 addition & 1 deletion app/models/formula.rb → app/models/recipe.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Formula < ActiveRecord::Base
class Recipe < ActiveRecord::Base
attr_accessible :name, :description

has_many :steps
Expand Down
2 changes: 1 addition & 1 deletion app/models/step.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Step < ActiveRecord::Base
attr_accessible :name, :description, :weight

belongs_to :formula
belongs_to :recipe
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class FormulaSerializer < ActiveModel::Serializer
class RecipeSerializer < ActiveModel::Serializer
attributes :id, :name, :description
has_many :steps
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace :api do
namespace :v1 do
resources :formulas
resources :recipes
end
end

Expand Down
2 changes: 1 addition & 1 deletion db/fill/formulas.csv → db/fill/recipes.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name,description
Grandma's Super Meatloaf,Meatloaf that will make your heart stop
Old Fashioned Ham Hock,Pork that only a momma would love
BBQ Ribs and Macaroni,"Smoque is better, but you can make this at home"
Chicken Noodle Soup,For that time you have the flu
Chicken Noodle Soup,For that time you have the flu
2 changes: 1 addition & 1 deletion db/fill/steps.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name,description,weight,formula_id
name,description,weight,recipe_id
step1,stir the pot,1,1
step2,spice the meat,2,1
step3,clean the table,3,1
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20130301220049_setup_initial_schema.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SetupInitialSchema < ActiveRecord::Migration

def change
create_table "formulas", :force => true do |t|
create_table "recipes", :force => true do |t|
t.string "name", :null => false
t.string "description"
t.datetime "created_at", :null => false
Expand All @@ -12,7 +12,7 @@ def change
t.string "name", :null => false
t.string "description"
t.integer "weight", :null => false, :default => 0
t.integer "formula_id", :null => false
t.integer "recipe_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

ActiveRecord::Schema.define(:version => 20130301220049) do

create_table "formulas", :force => true do |t|
create_table "recipes", :force => true do |t|
t.string "name", :null => false
t.string "description"
t.datetime "created_at", :null => false
Expand All @@ -24,7 +24,7 @@
t.string "name", :null => false
t.string "description"
t.integer "weight", :default => 0, :null => false
t.integer "formula_id", :null => false
t.integer "recipe_id", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
Expand Down
8 changes: 4 additions & 4 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'csv'

CSV.foreach("#{Rails.root}/db/fill/formulas.csv", :headers => :first_row) do |row|
Formula.create!(name: row[0], description: row[1])
puts "Formula created: #{row[0]}, #{row[1]}"
CSV.foreach("#{Rails.root}/db/fill/recipes.csv", :headers => :first_row) do |row|
Recipe.create!(name: row[0], description: row[1])
puts "Recipe created: #{row[0]}, #{row[1]}"
end

CSV.foreach("#{Rails.root}/db/fill/steps.csv", :headers => :first_row) do |row|
Step.create!({ name: row[0], description: row[1], weight: row[2], formula_id: row[3] }, without_protection: true)
Step.create!({ name: row[0], description: row[1], weight: row[2], recipe_id: row[3] }, without_protection: true)
puts "Step created: #{row[0]}, #{row[1]}, #{row[2]}, #{row[3]}"
end
4 changes: 2 additions & 2 deletions design/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Timer
* Note

## Formula
## Recipe

has_many :steps
has_many :ingredients, :through => :steps
Expand All @@ -24,7 +24,7 @@ has_many :tools, :through => :steps

## Step

belongs_to :formula
belongs_to :recipe
has_many :ingredients
has_many :tools

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require_relative '../../../spec_helper'

describe Api::V1::FormulasController do
describe Api::V1::RecipesController do

before do
FactoryGirl.create(:formula)
FactoryGirl.create(:recipe)
end

it 'should get show' do
get :show, id: Formula.first.id, format: :json
get :show, id: Recipe.first.id, format: :json
response.should be_success
end

Expand Down
2 changes: 1 addition & 1 deletion spec/factories/formulas.rb → spec/factories/recipes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryGirl.define do

factory :formula do
factory :recipe do
name "Peanut Butter and Jelly Sandwich"
description "A sandwich with peanut butter and grape jelly"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name "First step"
description "Lay out two pieces of bread"
weight 1
formula
recipe
end

end
4 changes: 2 additions & 2 deletions spec/models/formula_spec.rb → spec/models/recipe_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'

describe Formula do
describe Recipe do

it 'has a valid factory' do
FactoryGirl.create(:formula).should be_valid
FactoryGirl.create(:recipe).should be_valid
end

it { should have_many(:steps) }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
FactoryGirl.create(:step).should be_valid
end

it { should belong_to(:formula) }
it { should belong_to(:recipe) }

end

0 comments on commit 51d07d8

Please sign in to comment.