Skip to content

Commit

Permalink
user id isn't necessary since baby belongs to user
Browse files Browse the repository at this point in the history
  • Loading branch information
carvil committed Feb 26, 2012
1 parent b35400e commit dbbcfb9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
3 changes: 1 addition & 2 deletions app/models/stat.rb
@@ -1,6 +1,5 @@
class Stat < ActiveRecord::Base
belongs_to :user
belongs_to :baby

validates_presence_of :user_id, :baby_id
validates_presence_of :baby_id
end
5 changes: 5 additions & 0 deletions db/migrate/20120226174811_remove_user_id_from_stats.rb
@@ -0,0 +1,5 @@
class RemoveUserIdFromStats < ActiveRecord::Migration
def change
remove_column :stats, :user_id
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120212193024) do
ActiveRecord::Schema.define(:version => 20120226174811) do

create_table "babies", :force => true do |t|
t.string "name"
Expand All @@ -27,7 +27,6 @@
end

create_table "stats", :force => true do |t|
t.integer "user_id"
t.integer "baby_id"
t.float "height_in_meters"
t.integer "age_months"
Expand Down
18 changes: 0 additions & 18 deletions spec/models/stat_spec.rb
Expand Up @@ -18,36 +18,18 @@
context "given valid attributes" do
it "should save the stats" do
stats = FactoryGirl.build(:stat)
stats.user = user
stats.baby = baby
stats.valid?.should be_true
stats.save.should be_true
end
end

context "given no user" do
it "should not save the stats" do
stats = FactoryGirl.build(:stat)
stats.baby = baby
stats.valid?.should be_false
stats.save.should be_false
end
end

context "given no baby" do
it "should not save the stats" do
stats = FactoryGirl.build(:stat)
stats.user = user
stats.valid?.should be_false
stats.save.should be_false
end
end

context "given no baby and no user" do
it "should not save the stats" do
stats = FactoryGirl.build(:stat)
stats.valid?.should be_false
stats.save.should be_false
end
end
end

0 comments on commit dbbcfb9

Please sign in to comment.