Added creator field to crops

This commit is contained in:
martyhines
2013-08-20 21:22:02 -04:00
parent a8a87fe458
commit e77f7fdf31
6 changed files with 17 additions and 3 deletions

View File

@@ -1,12 +1,13 @@
class Crop < ActiveRecord::Base
extend FriendlyId
friendly_id :system_name, use: :slugged
attr_accessible :en_wikipedia_url, :system_name, :parent_id
attr_accessible :en_wikipedia_url, :system_name, :parent_id, :creator_id
has_many :scientific_names
has_many :plantings
has_many :photos, :through => :plantings
has_many :seeds
belongs_to :creator, :class_name => 'Member'
belongs_to :parent, :class_name => 'Crop'
has_many :varieties, :class_name => 'Crop', :foreign_key => 'parent_id'

View File

@@ -0,0 +1,5 @@
class AddCreatorToCrops < ActiveRecord::Migration
def change
add_column :crops, :creator_id, :integer
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130819004549) do
ActiveRecord::Schema.define(:version => 20130821011352) do
create_table "account_types", :force => true do |t|
t.string "name", :null => false
@@ -58,6 +58,7 @@ ActiveRecord::Schema.define(:version => 20130819004549) do
t.string "slug"
t.integer "parent_id"
t.integer "plantings_count"
t.integer "creator_id"
end
add_index "crops", ["slug"], :name => "index_crops_on_slug", :unique => true
@@ -114,6 +115,7 @@ ActiveRecord::Schema.define(:version => 20130819004549) do
t.float "latitude"
t.float "longitude"
t.boolean "send_notification_email", :default => true
t.text "bio"
end
add_index "members", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true

View File

@@ -3,6 +3,7 @@ FactoryGirl.define do
factory :crop do
system_name "Magic bean"
en_wikipedia_url "http://en.wikipedia.org/wiki/Magic_bean"
creator
factory :tomato do
system_name "Tomato"

View File

@@ -2,7 +2,7 @@ FactoryGirl.define do
sequence(:email) { |n| "member#{n}@example.com" }
sequence(:login_name) { |n| "member#{n}" }
factory :member, aliases: [:author, :owner, :sender, :recipient] do
factory :member, aliases: [:author, :owner, :sender, :recipient, :creator] do
login_name { generate(:login_name) }
password 'password1'
email { generate(:email) }

View File

@@ -23,6 +23,11 @@ describe Crop do
@crop.to_s.should == 'Tomato'
"#{@crop}".should == 'Tomato'
end
it 'has a creator' do
@crop.save
@crop.creator.should be_an_instance_of Member
end
end
context 'invalid data' do