From 439c42104b6fee90a63fa2422f212eaf32cdc281 Mon Sep 17 00:00:00 2001 From: Dhruv Kapadia Date: Mon, 21 Jun 2010 12:39:31 -0400 Subject: [PATCH] Copying creator information from Item model --- db/migrate/20100621162849_add_creator_to_choices.rb | 13 +++++++++++++ spec/models/choice_spec.rb | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20100621162849_add_creator_to_choices.rb diff --git a/db/migrate/20100621162849_add_creator_to_choices.rb b/db/migrate/20100621162849_add_creator_to_choices.rb new file mode 100644 index 0000000..094e522 --- /dev/null +++ b/db/migrate/20100621162849_add_creator_to_choices.rb @@ -0,0 +1,13 @@ +class AddCreatorToChoices < ActiveRecord::Migration + def self.up + add_column :choices, :creator_id, :integer + Choice.find(:all, :include => [:item]).each do |c| + c.creator_id = c.item.creator_id + c.save + end + end + + def self.down + remove_column :choices, :creator_id + end +end diff --git a/spec/models/choice_spec.rb b/spec/models/choice_spec.rb index 54348a4..0b2b6ca 100644 --- a/spec/models/choice_spec.rb +++ b/spec/models/choice_spec.rb @@ -4,8 +4,7 @@ describe Choice do it {should belong_to :question} it {should belong_to :item} - #uncomment after adding creator to choice model - #it {should belong_to :creator} + it {should belong_to :creator} it {should have_many :flags} it {should have_many :votes} it {should have_many :prompts_on_the_left} -- libgit2 0.21.2