added slug for seeds

This commit is contained in:
Skud
2013-07-23 21:14:24 +10:00
parent adceb61679
commit bdc267b044
4 changed files with 24 additions and 2 deletions

View File

@@ -1,6 +1,10 @@
class Seed < ActiveRecord::Base
extend FriendlyId
friendly_id :seed_slug, use: :slugged
attr_accessible :owner_id, :crop_id, :description, :quantity, :plant_before,
:tradable_to
:tradable_to, :slug
belongs_to :crop
belongs_to :owner, :class_name => 'Member', :foreign_key => 'owner_id'
@@ -19,4 +23,8 @@ class Seed < ActiveRecord::Base
return true
end
end
def seed_slug
"#{owner.login_name}-#{crop.system_name}".downcase.gsub(' ', '-')
end
end

View File

@@ -0,0 +1,6 @@
class AddSlugToSeed < ActiveRecord::Migration
def change
add_column :seeds, :slug, :string
add_index :seeds, :slug, unique: true
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 => 20130723103128) do
ActiveRecord::Schema.define(:version => 20130723110702) do
create_table "account_types", :force => true do |t|
t.string "name", :null => false
@@ -243,6 +243,9 @@ ActiveRecord::Schema.define(:version => 20130723103128) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "tradable_to", :default => "nowhere"
t.string "slug"
end
add_index "seeds", ["slug"], :name => "index_seeds_on_slug", :unique => true
end

View File

@@ -10,6 +10,11 @@ describe Seed do
@seed.save.should be_true
end
it "should have a slug" do
@seed.save
@seed.slug.should match(/member\d+-magic-bean/)
end
context 'quantity' do
it 'allows integer quantities' do
@seed = FactoryGirl.build(:seed, :quantity => 99)