Skip to content

Commit

Permalink
adding Ingredient and StepIngredient models
Browse files Browse the repository at this point in the history
  • Loading branch information
wrburgess committed May 9, 2013
1 parent 0349482 commit b043afc
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@
* ember
* rubymotion
* ios

## API

5 changes: 5 additions & 0 deletions app/models/ingredient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Ingredient < ActiveRecord::Base
attr_accessible :name, :description

has_many :step_ingredients
end
8 changes: 8 additions & 0 deletions app/models/step_ingredient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class StepIngredient < ActiveRecord::Base
attr_accessible :volume

validates_presence_of :step_id, :ingredient_id

belongs_to :step
belongs_to :ingredient
end
17 changes: 15 additions & 2 deletions db/migrate/20130301220049_setup_initial_schema.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class SetupInitialSchema < ActiveRecord::Migration

def change
create_table "recipes", :force => true do |t|
t.string "name", :null => false
Expand All @@ -16,6 +15,20 @@ def change
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end

create_table "ingredients", :force => true do |t|
t.string "name", :null => false
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "step_ingredients", :force => true do |t|
t.integer "step_id", :null => false
t.integer "ingredient_id", :null => false
t.string "volume"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
end
15 changes: 15 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,28 @@

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

create_table "ingredients", :force => true do |t|
t.string "name", :null => false
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "recipes", :force => true do |t|
t.string "name", :null => false
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "step_ingredients", :force => true do |t|
t.integer "step_id", :null => false
t.integer "ingredient_id", :null => false
t.string "volume"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "steps", :force => true do |t|
t.string "name", :null => false
t.string "description"
Expand Down
8 changes: 8 additions & 0 deletions spec/factories/ingredients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryGirl.define do

factory :ingredient do
name "Salt"
description "It's kind of salty"
end

end
7 changes: 7 additions & 0 deletions spec/factories/step_ingredients.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :step_ingredient do
step
ingredient
volume "1 piece"
end
end
11 changes: 11 additions & 0 deletions spec/models/ingredient_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

describe Ingredient do

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

it { should have_many(:step_ingredients) }

end
20 changes: 20 additions & 0 deletions spec/models/step_ingredient_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'

describe StepIngredient do

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

it 'is invalid without a step_id' do
FactoryGirl.build(:step_ingredient, step_id: nil).should_not be_valid
end

it 'is invalid without an ingredient_id' do
FactoryGirl.build(:step_ingredient, ingredient_id: nil).should_not be_valid
end

it { should belong_to(:step) }
it { should belong_to(:ingredient) }

end

0 comments on commit b043afc

Please sign in to comment.