diff --git a/Gemfile b/Gemfile index 3f4318236..3802d0dde 100644 --- a/Gemfile +++ b/Gemfile @@ -79,7 +79,6 @@ gem 'bootstrap-datepicker-rails' gem 'omniauth' gem 'omniauth-twitter' gem 'omniauth-flickr' -gem 'authbuttons-rails' # for phusion passenger (i.e. mod_rails) on the server gem 'passenger' diff --git a/Gemfile.lock b/Gemfile.lock index 35ab7f28b..6493ad58b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,7 +29,6 @@ GEM i18n (= 0.6.1) multi_json (~> 1.0) arel (3.0.2) - authbuttons-rails (0.1.2) bcrypt-ruby (3.0.1) bluecloth (2.2.0) bootstrap-datepicker-rails (1.0.0) @@ -233,7 +232,6 @@ PLATFORMS ruby DEPENDENCIES - authbuttons-rails bluecloth bootstrap-datepicker-rails bundler (>= 1.1.5) diff --git a/app/assets/images/flickr_32.png b/app/assets/images/flickr_32.png new file mode 100644 index 000000000..82a350e22 Binary files /dev/null and b/app/assets/images/flickr_32.png differ diff --git a/app/assets/images/twitter_32.png b/app/assets/images/twitter_32.png new file mode 100644 index 000000000..550232344 Binary files /dev/null and b/app/assets/images/twitter_32.png differ diff --git a/app/models/crop.rb b/app/models/crop.rb index 99db0166c..105afe0b5 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -1,9 +1,14 @@ class Crop < ActiveRecord::Base extend FriendlyId friendly_id :system_name, use: :slugged - attr_accessible :en_wikipedia_url, :system_name + attr_accessible :en_wikipedia_url, :system_name, :parent_id + has_many :scientific_names has_many :plantings + + belongs_to :parent, :class_name => 'Crop' + has_many :varieties, :class_name => 'Crop', :foreign_key => 'parent_id' + default_scope order("lower(system_name) asc") validates :en_wikipedia_url, diff --git a/app/views/crops/_form.html.haml b/app/views/crops/_form.html.haml index a225c1a92..2b75de0b6 100644 --- a/app/views/crops/_form.html.haml +++ b/app/views/crops/_form.html.haml @@ -22,5 +22,10 @@ .controls = f.text_field :en_wikipedia_url %span.help-inline Link to this crop's page on the English language Wikipedia. + .control-group + = f.label :parent_id, 'Parent crop', :class => 'control-label' + .controls + = collection_select(:crop, :parent_id, Crop.all, :id, :system_name, {:include_blank => true}) + %span.help-inline Optional. For setting up crop hierarchies for varieties etc. .form-actions = f.submit 'Save', :class => 'btn btn-primary' diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index 8756bea56..f9a08a076 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -2,6 +2,19 @@ .row .span9 + - if @crop.parent + %p + = @crop.system_name + is a variety of + = succeed "." do + = link_to @crop.parent, @crop.parent + - if @crop.varieties.count > 0 + %p + Varieties of + = succeed ":" do + = @crop.system_name + != @crop.varieties.map{ |c| link_to c, c }.join(", ") + - if @crop.plantings_count > 0 %p Planted diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index d8a36e1ce..14733b9a6 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -53,6 +53,7 @@ - else =link_to 'Connect to Twitter', '/auth/twitter' %p + = image_tag "flickr_32.png", :size => "32x32", :alt => 'Flickr logo' - if @flickr_auth You are connected to Flickr as = succeed "." do diff --git a/app/views/members/nearby.html.haml b/app/views/members/nearby.html.haml index cbcf51da6..059196ae2 100644 --- a/app/views/members/nearby.html.haml +++ b/app/views/members/nearby.html.haml @@ -7,7 +7,7 @@ = label_tag :distance, "Find members within", :class => 'control-label' = text_field_tag :distance, @distance, :class => 'input-mini' = select_tag :units, options_for_select({"miles" => :mi, "km" => :km}, @units), :class => 'input-small' - = label_tag :location, "miles of", :class => 'control-label' + = label_tag :location, "of", :class => 'control-label' = text_field_tag :location, @location = submit_tag "Search", :class => 'btn btn-primary' diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 8da927ede..8610257d1 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -33,7 +33,7 @@ - if @flickr_auth %p - Flickr: + = image_tag "flickr_32.png", :size => "32x32", :alt => 'Flickr logo' =link_to @flickr_auth.name, "http://flickr.com/photos/#{@flickr_auth.uid}" - if @member.show_email diff --git a/db/migrate/20130514124515_add_parent_to_crop.rb b/db/migrate/20130514124515_add_parent_to_crop.rb new file mode 100644 index 000000000..8a6019808 --- /dev/null +++ b/db/migrate/20130514124515_add_parent_to_crop.rb @@ -0,0 +1,5 @@ +class AddParentToCrop < ActiveRecord::Migration + def change + add_column :crops, :parent_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 7a372a776..cdb66dc42 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -56,6 +56,7 @@ ActiveRecord::Schema.define(:version => 20130518002942) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "slug" + t.integer "parent_id" end add_index "crops", ["slug"], :name => "index_crops_on_slug", :unique => true diff --git a/spec/factories/crop.rb b/spec/factories/crop.rb index 4ae2367d0..76fd31433 100644 --- a/spec/factories/crop.rb +++ b/spec/factories/crop.rb @@ -30,6 +30,16 @@ FactoryGirl.define do system_name "Pear" end + # for testing varieties + factory :roma do + system_name "Roma tomato" + end + + factory :popcorn do + system_name "popcorn" + end + + # This should have a name that is alphabetically earlier than :uppercase # crop to ensure that the ordering tests work. factory :lowercasecrop do diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index aca3d2681..bea69ed01 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -60,4 +60,13 @@ describe Crop do @crop = FactoryGirl.build(:tomato, :en_wikipedia_url => 'http://en.wikipedia.org/wiki/SomePage') @crop.should be_valid end + + context 'varieties' do + it 'has a crop hierarchy' do + @tomato = FactoryGirl.create(:tomato) + @roma = FactoryGirl.create(:roma, :parent_id => @tomato.id) + @roma.parent.should eq @tomato + @tomato.varieties.should eq [@roma] + end + end end diff --git a/spec/views/crops/new.html.haml_spec.rb b/spec/views/crops/new.html.haml_spec.rb index 4016a27a3..73e22dacc 100644 --- a/spec/views/crops/new.html.haml_spec.rb +++ b/spec/views/crops/new.html.haml_spec.rb @@ -14,6 +14,7 @@ describe "crops/new" do assert_select "form", :action => crops_path, :method => "post" do assert_select "input#crop_system_name", :name => "crop[system_name]" assert_select "input#crop_en_wikipedia_url", :name => "crop[en_wikipedia_url]" + assert_select "select#crop_parent_id", :name => "crop[parent_id]" end end diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 81099aabd..0b34be50e 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -44,6 +44,25 @@ describe "crops/show" do rendered.should contain "Springfield Community Garden" end + context 'varieties' do + before(:each) do + @popcorn = FactoryGirl.create(:popcorn, :parent_id => @crop.id) + @ubercrop = FactoryGirl.create(:crop, :system_name => 'ubercrop') + @crop.parent_id = @ubercrop.id + @crop.save + render + end + + it 'shows popcorn as a child variety' do + rendered.should contain @popcorn.system_name + end + + it 'shows parent crop' do + rendered.should contain @ubercrop.system_name + end + + end + context "logged in and crop wrangler" do before(:each) do