From 759903761dfea28093959d5964baba8bc87cd493 Mon Sep 17 00:00:00 2001 From: gnattery Date: Mon, 1 Apr 2013 15:53:41 +1100 Subject: [PATCH] sort plantings --- app/models/planting.rb | 2 ++ db/schema.rb | 9 --------- spec/models/planting_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index 5fd3e86a2..ab312f122 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -13,6 +13,8 @@ class Planting < ActiveRecord::Base :to => :crop, :prefix => true + default_scope order("created_at desc") + SUNNINESS_VALUES = %w(sun semi-shade shade) validates :sunniness, :inclusion => { :in => SUNNINESS_VALUES, :message => "%{value} is not a valid sunniness value" }, diff --git a/db/schema.rb b/db/schema.rb index c652f0a99..b354a3da0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -112,15 +112,6 @@ ActiveRecord::Schema.define(:version => 20130329045744) do t.datetime "updated_at", :null => false end - create_table "payments", :force => true do |t| - t.integer "payer_id" - t.decimal "amount" - t.date "paid_period_begins" - t.date "paid_period_ends" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - create_table "plantings", :force => true do |t| t.integer "garden_id", :null => false t.integer "crop_id", :null => false diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 591932385..8dcffbdbd 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -19,6 +19,12 @@ describe Planting do @planting.location.should match /^member\d+'s Springfield Community Garden$/ end + it "sorts plantings in descending order of creation" do + @planting1 = FactoryGirl.create(:planting) + @planting2 = FactoryGirl.create(:planting) + Planting.first.should eq @planting2 + end + it "should have a slug" do @planting.slug.should match /^member\d+-springfield-community-garden-tomato$/ end