mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-27 03:02:43 -04:00
Merge pull request #91 from gnattery/friendly-plantings
Friendly plantings
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,4 +3,4 @@
|
||||
/tmp/*
|
||||
.pt
|
||||
.*.sw*
|
||||
|
||||
*~
|
||||
|
||||
@@ -8,8 +8,7 @@ class Garden < ActiveRecord::Base
|
||||
has_many :crops, :through => :plantings
|
||||
|
||||
def garden_slug
|
||||
formatted_name = name.downcase.gsub(' ', '-')
|
||||
"#{owner.login_name}-#{formatted_name}"
|
||||
"#{owner.login_name}-#{name}".downcase.gsub(' ', '-')
|
||||
end
|
||||
|
||||
# featured plantings returns the most recent 4 plantings for a garden,
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
class Planting < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :planting_slug, use: :slugged
|
||||
|
||||
attr_accessible :crop_id, :description, :garden_id, :planted_at, :quantity
|
||||
|
||||
belongs_to :garden
|
||||
belongs_to :crop
|
||||
|
||||
def planting_slug
|
||||
"#{owner.login_name}-#{garden.name}-#{crop.system_name}".downcase.gsub(' ', '-')
|
||||
end
|
||||
|
||||
def location
|
||||
return "#{garden.owner.login_name}'s #{garden.name}"
|
||||
end
|
||||
|
||||
6
db/migrate/20130118043431_add_slug_to_plantings.rb
Normal file
6
db/migrate/20130118043431_add_slug_to_plantings.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class AddSlugToPlantings < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :plantings, :slug, :string
|
||||
add_index :plantings, :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 => 20130118031942) do
|
||||
ActiveRecord::Schema.define(:version => 20130118043431) do
|
||||
|
||||
create_table "crops", :force => true do |t|
|
||||
t.string "system_name", :null => false
|
||||
@@ -75,8 +75,11 @@ ActiveRecord::Schema.define(:version => 20130118031942) do
|
||||
t.text "description"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "slug"
|
||||
end
|
||||
|
||||
add_index "plantings", ["slug"], :name => "index_plantings_on_slug", :unique => true
|
||||
|
||||
create_table "posts", :force => true do |t|
|
||||
t.integer "author_id", :null => false
|
||||
t.string "subject", :null => false
|
||||
|
||||
@@ -2,8 +2,11 @@ require 'spec_helper'
|
||||
|
||||
describe PlantingsController do
|
||||
|
||||
def valid_attributes
|
||||
{ :garden_id => 1, :crop_id => 1 }
|
||||
def valid_attributes
|
||||
{
|
||||
:garden_id => FactoryGirl.create(:garden).id,
|
||||
:crop_id => FactoryGirl.create(:crop).id
|
||||
}
|
||||
end
|
||||
|
||||
def valid_session
|
||||
|
||||
@@ -7,7 +7,7 @@ describe Garden do
|
||||
end
|
||||
|
||||
it "should have a slug" do
|
||||
@garden.garden_slug.should == "member1-springfield-community-garden"
|
||||
@garden.slug.should == "member1-springfield-community-garden"
|
||||
end
|
||||
|
||||
it "should have a description" do
|
||||
|
||||
@@ -19,4 +19,8 @@ describe Planting do
|
||||
@planting.location.should match /^member1's Springfield Community Garden$/
|
||||
end
|
||||
|
||||
it "should have a slug" do
|
||||
@planting.slug.should == "member1-springfield-community-garden-tomato"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user