From d1e3f8ce32e1da10c3ad265a9ed5ea709484a562 Mon Sep 17 00:00:00 2001 From: gnattery Date: Fri, 18 Jan 2013 15:11:11 +1100 Subject: [PATCH] Added description field to gardens --- app/models/garden.rb | 2 +- app/views/gardens/_form.html.haml | 3 +++ app/views/gardens/edit.html.haml | 7 +------ app/views/gardens/show.html.haml | 4 ++++ app/views/members/show.html.haml | 4 ++++ .../20130118031942_add_description_to_gardens.rb | 5 +++++ db/schema.rb | 11 ++++++----- spec/factories/garden.rb | 1 + spec/models/garden_spec.rb | 4 ++++ spec/views/gardens/edit.html.haml_spec.rb | 1 + spec/views/gardens/new.html.haml_spec.rb | 1 + spec/views/gardens/show.html.haml_spec.rb | 8 ++++++++ spec/views/members/show.html.haml_spec.rb | 8 ++++++++ 13 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20130118031942_add_description_to_gardens.rb diff --git a/app/models/garden.rb b/app/models/garden.rb index 0e0f7addd..1caf223be 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -2,7 +2,7 @@ class Garden < ActiveRecord::Base extend FriendlyId friendly_id :garden_slug, use: :slugged - attr_accessible :name, :slug, :owner_id + attr_accessible :name, :slug, :owner_id, :description belongs_to :owner, :class_name => 'Member', :foreign_key => 'owner_id' has_many :plantings, :order => 'created_at DESC' has_many :crops, :through => :plantings diff --git a/app/views/gardens/_form.html.haml b/app/views/gardens/_form.html.haml index 6dfeb15bd..2b0945328 100644 --- a/app/views/gardens/_form.html.haml +++ b/app/views/gardens/_form.html.haml @@ -9,5 +9,8 @@ .control_group = f.label "Garden name: ", :class => 'control-label' .controls= f.text_field :name + .control-group + = f.label 'Description', :class => 'control-label' + .controls= f.text_area :description, :rows => 6 .form-actions = f.submit 'Save', :class => 'btn' diff --git a/app/views/gardens/edit.html.haml b/app/views/gardens/edit.html.haml index 1e42cc4d9..8ec00236c 100644 --- a/app/views/gardens/edit.html.haml +++ b/app/views/gardens/edit.html.haml @@ -2,12 +2,7 @@ - if member_signed_in? - if current_member == @garden.owner - = form_for @garden, :html => {:class => "form-horizontal"} do |f| - .control-group - = f.label :name, :class => "control-label" - .controls= f.text_field :name - .form-actions - = f.submit "Save", :class => 'btn' + = render "form" - else .alert You aren't allowed to edit this garden. - else diff --git a/app/views/gardens/show.html.haml b/app/views/gardens/show.html.haml index 3f55f24e2..5795a5105 100644 --- a/app/views/gardens/show.html.haml +++ b/app/views/gardens/show.html.haml @@ -18,6 +18,10 @@ = link_to 'New', new_garden_path, :class => 'btn' .span9 + %div + :markdown + #{@garden.description} + - if current_member == @garden.owner %p= link_to "Plant something", new_planting_path(:garden_id => @garden.id), :class => 'btn btn-large btn-primary' diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index f0dbc2601..efb6cedf3 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -26,6 +26,10 @@ %div{:class => ['tab-pane', first_garden ? 'active' : ''], :id => "garden#{g.id}"} - first_garden = false + %div + :markdown + #{g.description} + %h3 What's planted here? - g.featured_plantings.each do |p| = render :partial => "plantings/thumbnail", :locals => { :planting => p, :hide_description => true } diff --git a/db/migrate/20130118031942_add_description_to_gardens.rb b/db/migrate/20130118031942_add_description_to_gardens.rb new file mode 100644 index 000000000..30bb33c7e --- /dev/null +++ b/db/migrate/20130118031942_add_description_to_gardens.rb @@ -0,0 +1,5 @@ +class AddDescriptionToGardens < ActiveRecord::Migration + def change + add_column :gardens, :description, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 9c3cef982..36ef483fb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130113095802) do +ActiveRecord::Schema.define(:version => 20130118031942) do create_table "crops", :force => true do |t| t.string "system_name", :null => false @@ -25,11 +25,12 @@ ActiveRecord::Schema.define(:version => 20130113095802) do add_index "crops", ["system_name"], :name => "index_crops_on_system_name" create_table "gardens", :force => true do |t| - t.string "name", :null => false + t.string "name", :null => false t.integer "owner_id" - t.string "slug", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.string "slug", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.text "description" end add_index "gardens", ["owner_id"], :name => "index_gardens_on_user_id" diff --git a/spec/factories/garden.rb b/spec/factories/garden.rb index af94e173d..12d95040f 100644 --- a/spec/factories/garden.rb +++ b/spec/factories/garden.rb @@ -1,6 +1,7 @@ FactoryGirl.define do factory :garden do name 'Springfield Community Garden' + description "This is a **totally** cool garden" owner end end diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index bc558ef4f..e93e6f656 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -10,6 +10,10 @@ describe Garden do @garden.garden_slug.should == "member1-springfield-community-garden" end + it "should have a description" do + @garden.description.should == "This is a **totally** cool garden" + end + it "should have an owner" do @garden.owner.should be_an_instance_of Member end diff --git a/spec/views/gardens/edit.html.haml_spec.rb b/spec/views/gardens/edit.html.haml_spec.rb index 72ed49865..880e4d2dc 100644 --- a/spec/views/gardens/edit.html.haml_spec.rb +++ b/spec/views/gardens/edit.html.haml_spec.rb @@ -23,6 +23,7 @@ describe "gardens/edit" do # Run the generator again with the --webrat flag if you want to use webrat matchers assert_select "form", :action => gardens_path(@garden), :method => "post" do assert_select "input#garden_name", :name => "garden[name]" + assert_select "textarea#garden_description", :name => "garden[description]" end end end diff --git a/spec/views/gardens/new.html.haml_spec.rb b/spec/views/gardens/new.html.haml_spec.rb index a7cc596ab..eeaf68e93 100644 --- a/spec/views/gardens/new.html.haml_spec.rb +++ b/spec/views/gardens/new.html.haml_spec.rb @@ -11,6 +11,7 @@ describe "gardens/new" do # Run the generator again with the --webrat flag if you want to use webrat matchers assert_select "form", :action => gardens_path, :method => "post" do assert_select "input#garden_name", :name => "garden[name]" + assert_select "textarea#garden_description", :name => "garden[description]" end end end diff --git a/spec/views/gardens/show.html.haml_spec.rb b/spec/views/gardens/show.html.haml_spec.rb index 924b7d9f6..4544f9c60 100644 --- a/spec/views/gardens/show.html.haml_spec.rb +++ b/spec/views/gardens/show.html.haml_spec.rb @@ -9,6 +9,14 @@ describe "gardens/show" do render end + it 'should show the description' do + rendered.should contain "totally cool garden" + end + + it 'renders markdown in the description' do + assert_select "strong", "totally" + end + it 'should show plantings on the garden page' do rendered.should contain @planting.crop.system_name end diff --git a/spec/views/members/show.html.haml_spec.rb b/spec/views/members/show.html.haml_spec.rb index d360303c7..0e8720d48 100644 --- a/spec/views/members/show.html.haml_spec.rb +++ b/spec/views/members/show.html.haml_spec.rb @@ -24,6 +24,14 @@ describe "members/show" do assert_select "li.active>a", :text => "Garden" end + it 'shows the garden description' do + rendered.should contain "totally cool garden" + end + + it 'renders markdown in the garden description' do + assert_select "strong", "totally" + end + it "shows the plantings in the garden" do rendered.should contain @planting.crop.system_name end