mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-24 09:43:24 -04:00
Merge pull request #117 from pozorvlak/prettier-plantings
Prettier plantings
This commit is contained in:
@@ -14,4 +14,17 @@ class Crop < ActiveRecord::Base
|
||||
def to_s
|
||||
return system_name
|
||||
end
|
||||
|
||||
def default_scientific_name
|
||||
if scientific_names.count > 0
|
||||
return scientific_names.first.scientific_name
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def plantings_count
|
||||
return plantings.count
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -27,7 +27,10 @@ class Garden < ActiveRecord::Base
|
||||
end
|
||||
|
||||
return unique_plantings[0..3]
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -7,12 +7,17 @@ class Planting < ActiveRecord::Base
|
||||
belongs_to :garden
|
||||
belongs_to :crop
|
||||
|
||||
delegate :default_scientific_name,
|
||||
:plantings_count,
|
||||
:to => :crop,
|
||||
:prefix => true
|
||||
|
||||
def planting_slug
|
||||
"#{owner.login_name}-#{garden.name}-#{crop.system_name}".downcase.gsub(' ', '-')
|
||||
"#{owner.login_name}-#{garden}-#{crop}".downcase.gsub(' ', '-')
|
||||
end
|
||||
|
||||
def location
|
||||
return "#{garden.owner.login_name}'s #{garden.name}"
|
||||
return "#{garden.owner.login_name}'s #{garden}"
|
||||
end
|
||||
|
||||
def owner
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
=content_for :title, "#{@garden.owner}'s #{@garden.name}"
|
||||
=content_for :title, "#{@garden.owner}'s #{@garden}"
|
||||
|
||||
.row
|
||||
.span3
|
||||
@@ -9,9 +9,9 @@
|
||||
- @garden.owner.gardens.each do |othergarden|
|
||||
%li
|
||||
- if @garden == othergarden
|
||||
= @garden.name
|
||||
= @garden
|
||||
- else
|
||||
= link_to "#{othergarden.name}", garden_path(othergarden)
|
||||
= link_to "#{othergarden}", garden_path(othergarden)
|
||||
|
||||
- if can? :edit, @garden
|
||||
= link_to 'Edit', edit_garden_path(@garden), :class => 'btn'
|
||||
|
||||
@@ -1,17 +1,52 @@
|
||||
=content_for :title, "#{@planting.crop} in #{@planting.location}"
|
||||
|
||||
%p#notice= notice
|
||||
.row
|
||||
.span6
|
||||
%p
|
||||
%b Planted:
|
||||
= @planting.planted_at ? @planting.planted_at.to_s(:date) : "not specified"
|
||||
- if can? :edit, @planting
|
||||
%small
|
||||
= link_to 'Edit', edit_planting_path(@planting)
|
||||
%p
|
||||
%b Where:
|
||||
=link_to "#{@planting.owner}'s", @planting.owner
|
||||
=link_to @planting.garden, @planting.garden
|
||||
- if @planting.owner.location
|
||||
= "(#{@planting.owner.location})"
|
||||
%p
|
||||
%b Quantity:
|
||||
= @planting.quantity != 0 ? @planting.quantity : "not specified"
|
||||
- if can? :edit, @planting
|
||||
%small
|
||||
= link_to 'Edit', edit_planting_path(@planting)
|
||||
.span6
|
||||
.well
|
||||
%h3
|
||||
= link_to @planting.crop, @planting.crop
|
||||
- if can? :create, Planting
|
||||
= link_to 'Plant this', new_planting_path, :class => 'btn'
|
||||
|
||||
%p
|
||||
%b Planted at:
|
||||
= @planting.planted_at ? @planting.planted_at : "not specified"
|
||||
%p
|
||||
%b Quantity:
|
||||
= @planting.quantity != 0 ? @planting.quantity : "not specified"
|
||||
%p
|
||||
%b Description:
|
||||
:markdown
|
||||
#{ @planting.description != "" ? @planting.description : "No description." }
|
||||
%p
|
||||
%b Scientific name:
|
||||
= @planting.crop_default_scientific_name
|
||||
%p
|
||||
%b
|
||||
Planted
|
||||
= pluralize(@planting.crop_plantings_count, "time")
|
||||
by Growstuff members
|
||||
|
||||
%h2 Pictures
|
||||
.row
|
||||
- (1..6).each do
|
||||
.span2
|
||||
= image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded')
|
||||
|
||||
%h2
|
||||
Notes
|
||||
|
||||
:markdown
|
||||
#{ @planting.description != "" ? @planting.description : "No description given." }
|
||||
|
||||
- if can? :edit, @planting
|
||||
= link_to 'Edit', edit_planting_path(@planting), :class => 'btn'
|
||||
= link_to 'Edit', edit_planting_path(@planting)
|
||||
|
||||
11
db/schema.rb
11
db/schema.rb
@@ -45,7 +45,7 @@ ActiveRecord::Schema.define(:version => 20130222060730) do
|
||||
|
||||
create_table "gardens", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.integer "owner_id", :null => false
|
||||
t.integer "owner_id"
|
||||
t.string "slug", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
@@ -97,14 +97,13 @@ ActiveRecord::Schema.define(:version => 20130222060730) do
|
||||
|
||||
create_table "notifications", :force => true do |t|
|
||||
t.integer "sender_id"
|
||||
t.integer "recipient_id", :null => false
|
||||
t.integer "recipient_id", :null => false
|
||||
t.string "subject"
|
||||
t.text "body"
|
||||
t.boolean "read", :default => false
|
||||
t.integer "notification_type"
|
||||
t.boolean "read", :default => false
|
||||
t.integer "post_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "plantings", :force => true do |t|
|
||||
|
||||
@@ -50,4 +50,18 @@ describe Crop do
|
||||
Crop.first.should == lowercase
|
||||
end
|
||||
end
|
||||
|
||||
it 'finds a default scientific name' do
|
||||
@c = FactoryGirl.create(:tomato)
|
||||
@c.default_scientific_name.should eq nil
|
||||
@sn = FactoryGirl.create(:solanum_lycopersicum, :crop => @c)
|
||||
@c.default_scientific_name.should eq @sn.scientific_name
|
||||
end
|
||||
|
||||
it 'counts plantings' do
|
||||
@c = FactoryGirl.create(:tomato)
|
||||
@c.plantings_count.should eq 0
|
||||
FactoryGirl.create(:planting, :crop => @c)
|
||||
@c.plantings_count.should eq 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +18,10 @@ describe Garden do
|
||||
@garden.owner.should be_an_instance_of Member
|
||||
end
|
||||
|
||||
it "should stringify as its name" do
|
||||
@garden.to_s.should == @garden.name
|
||||
end
|
||||
|
||||
context "featured plantings" do
|
||||
before :each do
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
|
||||
@@ -1,26 +1,49 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "plantings/show" do
|
||||
before(:each) do
|
||||
controller.stub(:current_user) { nil }
|
||||
@member = FactoryGirl.create(:member)
|
||||
def create_planting_for(member)
|
||||
@garden = FactoryGirl.create(:garden, :owner => @member)
|
||||
@crop = FactoryGirl.create(:tomato)
|
||||
@planting = assign(:planting,
|
||||
FactoryGirl.create(:planting, :garden => @garden, :crop => @crop)
|
||||
)
|
||||
render
|
||||
end
|
||||
|
||||
it "renders the quantity planted" do
|
||||
rendered.should match(/3/)
|
||||
context "no location set" do
|
||||
before(:each) do
|
||||
controller.stub(:current_user) { nil }
|
||||
@member = FactoryGirl.create(:member)
|
||||
create_planting_for(@member)
|
||||
render
|
||||
end
|
||||
|
||||
it "renders the quantity planted" do
|
||||
rendered.should match(/3/)
|
||||
end
|
||||
|
||||
it "renders the description" do
|
||||
rendered.should match(/This is a/)
|
||||
end
|
||||
|
||||
it "renders markdown in the description" do
|
||||
assert_select "em", "really"
|
||||
end
|
||||
|
||||
it "doesn't contain a () if no location is set" do
|
||||
rendered.should_not contain "()"
|
||||
end
|
||||
end
|
||||
|
||||
it "renders the description" do
|
||||
rendered.should match(/This is a/)
|
||||
end
|
||||
context "location set" do
|
||||
before(:each) do
|
||||
controller.stub(:current_user) { nil }
|
||||
@member = FactoryGirl.create(:geolocated_member)
|
||||
create_planting_for(@member)
|
||||
render
|
||||
end
|
||||
|
||||
it "renders markdown in the description" do
|
||||
assert_select "em", "really"
|
||||
it "shows the member's location in parentheses" do
|
||||
rendered.should contain "(#{@member.location})"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user