mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-04-23 00:12:03 -04:00
added slug for seeds
This commit is contained in:
@@ -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
|
||||
|
||||
6
db/migrate/20130723110702_add_slug_to_seed.rb
Normal file
6
db/migrate/20130723110702_add_slug_to_seed.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class AddSlugToSeed < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :seeds, :slug, :string
|
||||
add_index :seeds, :slug, unique: true
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user