From e85cb4598db71803b76ca093f216c28181f0f603 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 12:38:44 +0100 Subject: [PATCH 01/47] Add alternate name model. --- app/models/alternate_name.rb | 5 +++++ .../20141018111015_create_alternate_names.rb | 11 +++++++++++ db/schema.rb | 11 ++++++++++- spec/factories/alternate_names.rb | 14 ++++++++++++++ spec/models/alternate_name_spec.rb | 11 +++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/models/alternate_name.rb create mode 100644 db/migrate/20141018111015_create_alternate_names.rb create mode 100644 spec/factories/alternate_names.rb create mode 100644 spec/models/alternate_name_spec.rb diff --git a/app/models/alternate_name.rb b/app/models/alternate_name.rb new file mode 100644 index 000000000..fb92a2bc9 --- /dev/null +++ b/app/models/alternate_name.rb @@ -0,0 +1,5 @@ +class AlternateName < ActiveRecord::Base + attr_accessible :crop_id, :name, :creator_id + belongs_to :crop + belongs_to :creator, :class_name => 'Member' +end diff --git a/db/migrate/20141018111015_create_alternate_names.rb b/db/migrate/20141018111015_create_alternate_names.rb new file mode 100644 index 000000000..8a63471c8 --- /dev/null +++ b/db/migrate/20141018111015_create_alternate_names.rb @@ -0,0 +1,11 @@ +class CreateAlternateNames < ActiveRecord::Migration + def change + create_table :alternate_names do |t| + t.string :name, :null => false + t.integer :crop_id, :null => false + t.integer :creator_id, :null => false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9292a6fbb..39a68cab2 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 => 20141002022459) do +ActiveRecord::Schema.define(:version => 20141018111015) do create_table "account_types", :force => true do |t| t.string "name", :null => false @@ -29,6 +29,14 @@ ActiveRecord::Schema.define(:version => 20141002022459) do t.datetime "updated_at", :null => false end + create_table "alternate_names", :force => true do |t| + t.string "name", :null => false + t.integer "crop_id", :null => false + t.integer "creator_id", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "authentications", :force => true do |t| t.integer "member_id", :null => false t.string "provider", :null => false @@ -154,6 +162,7 @@ ActiveRecord::Schema.define(:version => 20141002022459) do t.text "bio" t.integer "plantings_count" t.boolean "newsletter" + t.boolean "send_planting_reminder", :default => true end add_index "members", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true diff --git a/spec/factories/alternate_names.rb b/spec/factories/alternate_names.rb new file mode 100644 index 000000000..72c73d99c --- /dev/null +++ b/spec/factories/alternate_names.rb @@ -0,0 +1,14 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :alternate_name do + association :crop, factory: :crop + name "alternate name" + creator + + factory :alternate_tomato do + association :crop, factory: :tomato + name "alternative tomato" + end + end +end diff --git a/spec/models/alternate_name_spec.rb b/spec/models/alternate_name_spec.rb new file mode 100644 index 000000000..f91d6dc1f --- /dev/null +++ b/spec/models/alternate_name_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe AlternateName do + before (:each) do + @an = FactoryGirl.create(:alternate_tomato) + end + + it 'should save a basic alternate name' do + @an.save.should be_true + end +end From 83fa291060dc005b9965c1717c2c6c4bb1a628c6 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 13:49:57 +0100 Subject: [PATCH 02/47] Fetch alternate names for a crop. --- app/models/crop.rb | 1 + spec/models/alternate_name_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/models/crop.rb b/app/models/crop.rb index 387936d91..fa99ed90c 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -8,6 +8,7 @@ class Crop < ActiveRecord::Base :allow_destroy => true, :reject_if => :all_blank + has_many :alternate_names has_many :plantings has_many :photos, :through => :plantings has_many :seeds diff --git a/spec/models/alternate_name_spec.rb b/spec/models/alternate_name_spec.rb index f91d6dc1f..e7772dca0 100644 --- a/spec/models/alternate_name_spec.rb +++ b/spec/models/alternate_name_spec.rb @@ -8,4 +8,17 @@ describe AlternateName do it 'should save a basic alternate name' do @an.save.should be_true end + + it 'should be possible to add multiple alternate names to a crop' do + crop = @an.crop + an2 = AlternateName.create( + :name => "really alternative tomato", + :crop_id => crop.id, + :creator_id => @an.creator.id + ) + crop.alternate_names << an2 + crop.alternate_names.should include @an + crop.alternate_names.should include an2 + end + end From 627587ee1b5468bf719e978a850b85be4627bd5a Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 14:19:09 +0100 Subject: [PATCH 03/47] Show alternate names on crop page --- app/views/crops/show.html.haml | 6 ++++++ spec/factories/alternate_names.rb | 8 ++++---- spec/factories/crop.rb | 3 +++ spec/features/crop_spec.rb | 10 ++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 spec/features/crop_spec.rb diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index 670a0d438..b031ec5b2 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -72,6 +72,12 @@ - if can? :edit, @crop = link_to 'Add', new_scientific_name_path( :crop_id => @crop.id ), { :class => 'btn btn-default btn-xs' } + %h4 Alternate names + %ul + - @crop.alternate_names.each do |an| + %li + = an.name + = render :partial => 'varieties', :locals => { :crop => @crop } = render :partial => 'grown_for', :locals => { :crop => @crop } diff --git a/spec/factories/alternate_names.rb b/spec/factories/alternate_names.rb index 72c73d99c..1c14d60ac 100644 --- a/spec/factories/alternate_names.rb +++ b/spec/factories/alternate_names.rb @@ -2,13 +2,13 @@ FactoryGirl.define do factory :alternate_name do - association :crop, factory: :crop name "alternate name" + crop creator - factory :alternate_tomato do - association :crop, factory: :tomato - name "alternative tomato" + factory :alternate_eggplant do + association :crop, factory: :eggplant + name "aubergine" end end end diff --git a/spec/factories/crop.rb b/spec/factories/crop.rb index 975e8d323..c6839e983 100644 --- a/spec/factories/crop.rb +++ b/spec/factories/crop.rb @@ -40,6 +40,9 @@ FactoryGirl.define do name "popcorn" end + factory :eggplant do + name "eggplant" + end # This should have a name that is alphabetically earlier than :uppercase # crop to ensure that the ordering tests work. diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb new file mode 100644 index 000000000..9a2bb273b --- /dev/null +++ b/spec/features/crop_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +feature "Alternate names" do + let(:alternate_eggplant) { FactoryGirl.create(:alternate_eggplant) } + + scenario "Display alternate names on crop page" do + visit crop_path(alternate_eggplant.crop) + expect(page).to have_content alternate_eggplant.name + end +end From ae27a0a5b56a8c481e852346500a239959f79a7a Mon Sep 17 00:00:00 2001 From: Skud Date: Sat, 18 Oct 2014 14:38:00 +0100 Subject: [PATCH 04/47] Added some additional hierarchy around cherry tomatoes --- db/seeds/crops-11-tomatoes.csv | 78 +++++++++++++++++----------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/db/seeds/crops-11-tomatoes.csv b/db/seeds/crops-11-tomatoes.csv index eb28aaa79..acb39a039 100644 --- a/db/seeds/crops-11-tomatoes.csv +++ b/db/seeds/crops-11-tomatoes.csv @@ -1,41 +1,41 @@ -adoration tomato,,https://en.wikipedia.org/wiki/Adoration_%28Tomato%29,tomato, -alicante tomato,,https://en.wikipedia.org/wiki/Alicante_%28tomato%29,tomato, -Amish paste tomato,,http://en.wikipedia.org/wiki/Amish_Paste,tomato, -azoychka tomato,,https://en.wikipedia.org/wiki/Azoychka%28Tomato%29,tomato, -beefsteak tomato,,https://en.wikipedia.org/wiki/Beefsteak_(tomato),tomato, -better boy tomato,,https://en.wikipedia.org/wiki/Better_Boy,tomato, -big rainbow tomato,,https://en.wikipedia.org/wiki/Big_Rainbow_(Tomato),tomato, -Blaby special tomato,,https://en.wikipedia.org/wiki/Blaby_Special_(Tomato),tomato, -black krim tomato,,https://en.wikipedia.org/wiki/Black_Krim_%28tomato%29,tomato, -brandywine tomato,,https://en.wikipedia.org/wiki/Brandywine_(tomato),tomato, -campari tomato,,https://en.wikipedia.org/wiki/Campari_tomato,tomato, -Cherokee purple tomato,,https://en.wikipedia.org/wiki/Cherokee_purple,tomato, +adoration tomato,,https://en.wikipedia.org/wiki/Adoration_%28Tomato%29,tomato +alicante tomato,,https://en.wikipedia.org/wiki/Alicante_%28tomato%29,tomato +Amish paste tomato,,http://en.wikipedia.org/wiki/Amish_Paste,tomato +Aunt Ruby's German green tomato,,http://en.wikipedia.org/wiki/Aunt_Ruby%27s_German_Green,tomato +azoychka tomato,,https://en.wikipedia.org/wiki/Azoychka%28Tomato%29,tomato +beefsteak tomato,,https://en.wikipedia.org/wiki/Beefsteak_(tomato),tomato +better boy tomato,,https://en.wikipedia.org/wiki/Better_Boy,tomato +big rainbow tomato,,https://en.wikipedia.org/wiki/Big_Rainbow_(Tomato),tomato +Blaby special tomato,,https://en.wikipedia.org/wiki/Blaby_Special_(Tomato),tomato +black krim tomato,,https://en.wikipedia.org/wiki/Black_Krim_%28tomato%29,tomato +brandywine tomato,,https://en.wikipedia.org/wiki/Brandywine_(tomato),tomato +campari tomato,,https://en.wikipedia.org/wiki/Campari_tomato,tomato +celebrity tomato,,http://en.wikipedia.org/wiki/Celebrity_(tomato),tomato +Cherokee purple tomato,,https://en.wikipedia.org/wiki/Cherokee_purple,tomato +cherry tomato,Solanum lycopersicum var. cerasiforme,http://en.wikipedia.org/wiki/Cherry_tomato,tomato currant tomato,solanum pimpinellifolium,https://en.wikipedia.org/wiki/Solanum_pimpinellifolium, -early girl tomato,,https://en.wikipedia.org/wiki/Early_Girl,tomato, -Fourth of July tomato,,https://en.wikipedia.org/wiki/Fourth_of_July_(tomato_variety),tomato, -garden peach tomato,,https://en.wikipedia.org/wiki/Garden_peach_tomato,tomato, -green zebra tomato,,https://en.wikipedia.org/wiki/Green_Zebra,tomato, -hillbilly tomato,,http://en.wikipedia.org/wiki/Hillbilly_(tomato),tomato, -jubilee tomato,,http://en.wikipedia.org/wiki/Jubilee_(tomato),tomato, -lillian's yellow tomato,,http://en.wikipedia.org/wiki/Lillian%27s_Yellow_(tomato),tomato, -Matt's wild cherry tomato,,http://en.wikipedia.org/wiki/Matt%27s_Wild_Cherry,tomato, -mortgage lifter tomato,,http://en.wikipedia.org/wiki/Mortgage_Lifter,tomato, -Mr. Stripey tomato,,http://en.wikipedia.org/wiki/Mr._Stripey,tomato, -Roma tomato,,http://en.wikipedia.org/wiki/Roma_tomato,tomato, -San Marzano tomato,,http://en.wikipedia.org/wiki/San_Marzano_tomato,tomato, -Santorini tomato,,http://en.wikipedia.org/wiki/Santorini_(tomato),tomato, -stupice tomato,,http://en.wikipedia.org/wiki/Super_Sweet_100,tomato, -tigerella tomato,,http://en.wikipedia.org/wiki/Tigerella,tomato, -tomaccio tomato,,http://en.wikipedia.org/wiki/Tomaccio_(tomato),tomato, +early girl tomato,,https://en.wikipedia.org/wiki/Early_Girl,tomato +Fourth of July tomato,,https://en.wikipedia.org/wiki/Fourth_of_July_(tomato_variety),tomato +garden peach tomato,,https://en.wikipedia.org/wiki/Garden_peach_tomato,tomato +grape tomato,,http://en.wikipedia.org/wiki/Grape_tomato,tomato +green zebra tomato,,https://en.wikipedia.org/wiki/Green_Zebra,tomato +Hanover tomato,,http://en.wikipedia.org/wiki/Hanover_tomato,tomato +hillbilly tomato,,http://en.wikipedia.org/wiki/Hillbilly_(tomato),tomato +jubilee tomato,,http://en.wikipedia.org/wiki/Jubilee_(tomato),tomato +lillian's yellow tomato,,http://en.wikipedia.org/wiki/Lillian%27s_Yellow_(tomato),tomato +marglobe tomato,,http://en.wikipedia.org/wiki/Marglobe,tomato +Matt's wild cherry tomato,,http://en.wikipedia.org/wiki/Matt%27s_Wild_Cherry,cherry tomato +mortgage lifter tomato,,http://en.wikipedia.org/wiki/Mortgage_Lifter,tomato +Mr. Stripey tomato,,http://en.wikipedia.org/wiki/Mr._Stripey,tomato +pear tomato,,http://en.wikipedia.org/wiki/Pear_tomato,tomato +Roma tomato,,http://en.wikipedia.org/wiki/Roma_tomato,tomato +San Marzano tomato,,http://en.wikipedia.org/wiki/San_Marzano_tomato,tomato +Santorini tomato,,http://en.wikipedia.org/wiki/Santorini_(tomato),cherry tomato +stupice tomato,,http://en.wikipedia.org/wiki/Super_Sweet_100,tomato +super sweet 100 tomato,,http://en.wikipedia.org/wiki/Super_Sweet_100,cherry tomato +three sisters tomato,,http://en.wikipedia.org/wiki/Three_Sisters_(tomato),tomato +tigerella tomato,,http://en.wikipedia.org/wiki/Tigerella,tomato +tomaccio tomato,,http://en.wikipedia.org/wiki/Tomaccio_(tomato),cherry tomato +tomberry,,http://en.wikipedia.org/wiki/Tomberry,tomato traveller tomato,,http://en.wikipedia.org/wiki/Traveller_(tomato),tomato -three sisters tomato,,http://en.wikipedia.org/wiki/Three_Sisters_(tomato),tomato, -Hanover tomato,,http://en.wikipedia.org/wiki/Hanover_tomato,tomato, -celebrity tomato,,http://en.wikipedia.org/wiki/Celebrity_(tomato),tomato, -tomberry,,http://en.wikipedia.org/wiki/Tomberry,tomato, -super sweet 100 tomato,,http://en.wikipedia.org/wiki/Super_Sweet_100,tomato, -marglobe tomato,,http://en.wikipedia.org/wiki/Marglobe,tomato, -grape tomato,,http://en.wikipedia.org/wiki/Grape_tomato,tomato, -cherry tomato,,http://en.wikipedia.org/wiki/Cherry_tomato,tomato, -Aunt Ruby's German green tomato,,http://en.wikipedia.org/wiki/Aunt_Ruby%27s_German_Green,tomato, -white queen tomato,,http://en.wikipedia.org/wiki/White_Queen_tomato,tomato, -pear tomato,,http://en.wikipedia.org/wiki/Pear_tomato,tomato, +white queen tomato,,http://en.wikipedia.org/wiki/White_Queen_tomato,tomato From 7e4b51d1cb0656c1b3f4293c6732ce9c1a4d0c11 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 15:18:23 +0100 Subject: [PATCH 05/47] Add "Edit" link for alternate names on crops page. --- app/controllers/alternate_names_controller.rb | 8 +++++++ app/models/ability.rb | 1 + app/views/crops/show.html.haml | 2 ++ config/routes.rb | 1 + spec/features/crop_spec.rb | 23 +++++++++++++++++++ 5 files changed, 35 insertions(+) create mode 100644 app/controllers/alternate_names_controller.rb diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb new file mode 100644 index 000000000..23028693c --- /dev/null +++ b/app/controllers/alternate_names_controller.rb @@ -0,0 +1,8 @@ +class AlternateNamesController < ApplicationController + load_and_authorize_resource + + # GET /alternate_names/1/edit + def edit + @alternate_name = AlternateName.find(params[:id]) + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index e33f4a022..3e76c6738 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -40,6 +40,7 @@ class Ability can :wrangle, Crop can :manage, Crop can :manage, ScientificName + can :manage, AlternateName end # can create & destroy their own authentications against other sites. diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index b031ec5b2..c7d02d8c3 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -77,6 +77,8 @@ - @crop.alternate_names.each do |an| %li = an.name + - if can? :edit, an + = link_to 'Edit', edit_alternate_name_path(an), { :class => 'btn btn-default btn-xs' } = render :partial => 'varieties', :locals => { :crop => @crop } diff --git a/config/routes.rb b/config/routes.rb index 0d645a1be..ac6885e54 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,6 +28,7 @@ Growstuff::Application.routes.draw do match '/posts/author/:author' => 'posts#index', :as => 'posts_by_author' resources :scientific_names + resources :alternate_names match 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops' match 'crops/hierarchy' => 'crops#hierarchy', :as => 'crops_hierarchy' diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index 9a2bb273b..3b61c3ec5 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -7,4 +7,27 @@ feature "Alternate names" do visit crop_path(alternate_eggplant.crop) expect(page).to have_content alternate_eggplant.name end + + context "User is a crop wrangler" do + let!(:crop_wranglers) { FactoryGirl.create_list(:crop_wrangling_member, 3) } + let(:member){crop_wranglers.first} + + before :each do + visit root_path + click_link 'Sign in' + fill_in 'Login', with: member.login_name + fill_in 'Password', with: member.password + click_button 'Sign in' + page.should have_content member.login_name + end + + scenario "Crop wranglers can edit alternate names" do + visit crop_path(alternate_eggplant.crop) + expect(page).to have_content "CROP WRANGLER" + expect(page).to have_content alternate_eggplant.name + expect(page).to have_link "Edit", :href => edit_alternate_name_path(alternate_eggplant) + end + + end + end From cdf6d4b09ae6e289441076146c6516ced79b3b51 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 15:29:21 +0100 Subject: [PATCH 06/47] Delete alternate name button on crops page. --- app/views/crops/show.html.haml | 2 ++ spec/features/crop_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index c7d02d8c3..5d74f6d8a 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -79,6 +79,8 @@ = an.name - if can? :edit, an = link_to 'Edit', edit_alternate_name_path(an), { :class => 'btn btn-default btn-xs' } + - if can? :destroy, an + = link_to 'Delete', an, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' = render :partial => 'varieties', :locals => { :crop => @crop } diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index 3b61c3ec5..9f825015f 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -28,6 +28,12 @@ feature "Alternate names" do expect(page).to have_link "Edit", :href => edit_alternate_name_path(alternate_eggplant) end + scenario "Crop wranglers can delete alternate names" do + visit crop_path(alternate_eggplant.crop) + expect(page).to have_link "Delete", + href: alternate_name_path(alternate_eggplant) + end + end end From 77d1d067fa0fa6d74accda5f54795633574ff579 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 15:35:57 +0100 Subject: [PATCH 07/47] Crop wranglers can add alternate names --- app/views/crops/show.html.haml | 3 +++ spec/features/crop_spec.rb | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index 5d74f6d8a..ad5abab1b 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -81,6 +81,9 @@ = link_to 'Edit', edit_alternate_name_path(an), { :class => 'btn btn-default btn-xs' } - if can? :destroy, an = link_to 'Delete', an, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' + %p + - if can? :edit, @crop + = link_to 'Add', new_alternate_name_path( :crop_id => @crop.id ), { :class => 'btn btn-default btn-xs' } = render :partial => 'varieties', :locals => { :crop => @crop } diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index 9f825015f..52620da81 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -34,6 +34,12 @@ feature "Alternate names" do href: alternate_name_path(alternate_eggplant) end + scenario "Crop wranglers can add alternate names" do + crop = alternate_eggplant.crop + visit crop_path(crop) + expect(page).to have_link "Add", + href: new_alternate_name_path(crop_id: crop.id) + end end end From 10f6214c6ced4a8a1a1bfdc421486f1bb2d689e9 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 16:34:38 +0100 Subject: [PATCH 08/47] Views for adding/editing alternate names. --- app/controllers/alternate_names_controller.rb | 12 +++++++++ app/views/alternate_names/_form.html.haml | 25 +++++++++++++++++++ app/views/alternate_names/edit.html.haml | 9 +++++++ app/views/alternate_names/new.html.haml | 3 +++ spec/features/crop_spec.rb | 13 ++++++++++ 5 files changed, 62 insertions(+) create mode 100644 app/views/alternate_names/_form.html.haml create mode 100644 app/views/alternate_names/edit.html.haml create mode 100644 app/views/alternate_names/new.html.haml diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb index 23028693c..b28e51f34 100644 --- a/app/controllers/alternate_names_controller.rb +++ b/app/controllers/alternate_names_controller.rb @@ -5,4 +5,16 @@ class AlternateNamesController < ApplicationController def edit @alternate_name = AlternateName.find(params[:id]) end + + # GET /alternate_names/new + # GET /alternate_names/new.json + def new + @alternate_name = AlternateName.new + @crop = Crop.find_by_id(params[:crop_id]) || Crop.new + + respond_to do |format| + format.html # new.html.haml + format.json { render json: @alternate_name } + end + end end diff --git a/app/views/alternate_names/_form.html.haml b/app/views/alternate_names/_form.html.haml new file mode 100644 index 000000000..7d6f9abd5 --- /dev/null +++ b/app/views/alternate_names/_form.html.haml @@ -0,0 +1,25 @@ += form_for @alternate_name, :html => {:class => 'form-horizontal', :role => "form"} do |f| + - if @alternate_name.errors.any? + #error_explanation + %h2= "#{pluralize(@alternate_name.errors.count, "error")} prohibited this alternate_name from being saved:" + %ul + - @alternate_name.errors.full_messages.each do |msg| + %li= msg + + %p + %span.help-block + For detailed crop wrangling guidelines, please consult the + =link_to "crop wrangling guide", "http://wiki.growstuff.org/index.php/Crop_wrangling" + on the Growstuff wiki. + + .form-group + = f.label :crop_id, :class => 'control-label col-md-2' + .col-md-8 + = collection_select(:alternate_name, :crop_id, Crop.all, :id, :name, { :selected => @alternate_name.crop_id || @crop.id }, :class => 'form-control') + .form-group + = f.label :name, :class => 'control-label col-md-2' + .col-md-8 + = f.text_field :name, :class => 'form-control' + .form-group + .form-actions.col-md-offset-2.col-md-8 + = f.submit 'Save', :class => 'btn btn-primary' diff --git a/app/views/alternate_names/edit.html.haml b/app/views/alternate_names/edit.html.haml new file mode 100644 index 000000000..0818bb0ff --- /dev/null +++ b/app/views/alternate_names/edit.html.haml @@ -0,0 +1,9 @@ +- content_for :title, "Edit alternate name" + +%p + Added by + = @alternate_name.creator + = distance_of_time_in_words(@alternate_name.created_at, Time.zone.now) + ago. + += render 'form' diff --git a/app/views/alternate_names/new.html.haml b/app/views/alternate_names/new.html.haml new file mode 100644 index 000000000..7c51473b7 --- /dev/null +++ b/app/views/alternate_names/new.html.haml @@ -0,0 +1,3 @@ +- content_for :title, "New alternate name" + += render 'form' diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index 52620da81..ecaa6b224 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -40,6 +40,19 @@ feature "Alternate names" do expect(page).to have_link "Add", href: new_alternate_name_path(crop_id: crop.id) end + + scenario "The add-alternate-name page works" do + crop = alternate_eggplant.crop + visit new_alternate_name_path(crop_id: crop.id) + expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" + end + + scenario "The edit-alternate-name page works" do + crop = alternate_eggplant.crop + visit edit_alternate_name_path(alternate_eggplant) + expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" + end + end end From 37eb2a0e34e105de0a49826ad07e0c4a19723d17 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 16:49:27 +0100 Subject: [PATCH 09/47] Show alternate names on their own page. --- app/controllers/alternate_names_controller.rb | 11 +++++++++++ app/views/alternate_names/show.html.haml | 13 +++++++++++++ spec/features/crop_spec.rb | 5 +++++ 3 files changed, 29 insertions(+) create mode 100644 app/views/alternate_names/show.html.haml diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb index b28e51f34..af53f9350 100644 --- a/app/controllers/alternate_names_controller.rb +++ b/app/controllers/alternate_names_controller.rb @@ -6,6 +6,17 @@ class AlternateNamesController < ApplicationController @alternate_name = AlternateName.find(params[:id]) end + # GET /alternate_names/1 + # GET /alternate_names/1.json + def show + @alternate_name = AlternateName.find(params[:id]) + + respond_to do |format| + format.html # show.html.haml + format.json { render json: @alternate_name } + end + end + # GET /alternate_names/new # GET /alternate_names/new.json def new diff --git a/app/views/alternate_names/show.html.haml b/app/views/alternate_names/show.html.haml new file mode 100644 index 000000000..2f7db7f14 --- /dev/null +++ b/app/views/alternate_names/show.html.haml @@ -0,0 +1,13 @@ +%p#notice= notice + +%p + %b Alternate name: + = @alternate_name.name +%p + %b Crop: + = link_to @alternate_name.crop + +- if can? :edit, @alternate_name + = link_to 'Edit', edit_alternate_name_path(@alternate_name), :class => 'btn btn-default btn-xs' +\| += link_to 'Back', alternate_names_path diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index ecaa6b224..83b9ff5c8 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -41,6 +41,11 @@ feature "Alternate names" do href: new_alternate_name_path(crop_id: crop.id) end + scenario "The show-alternate-name page works" do + visit alternate_name_path(alternate_eggplant) + expect(page).to have_content alternate_eggplant.crop.name + end + scenario "The add-alternate-name page works" do crop = alternate_eggplant.crop visit new_alternate_name_path(crop_id: crop.id) From eacfadae20850d18b49a39134c3d02f8a39a68be Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 16:51:43 +0100 Subject: [PATCH 10/47] Make editing alternate names actually do something. --- app/controllers/alternate_names_controller.rb | 16 ++++++++++++++++ spec/features/crop_spec.rb | 3 +++ 2 files changed, 19 insertions(+) diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb index af53f9350..857233fa0 100644 --- a/app/controllers/alternate_names_controller.rb +++ b/app/controllers/alternate_names_controller.rb @@ -28,4 +28,20 @@ class AlternateNamesController < ApplicationController format.json { render json: @alternate_name } end end + + # PUT /alternate_names/1 + # PUT /alternate_names/1.json + def update + @alternate_name = AlternateName.find(params[:id]) + + respond_to do |format| + if @alternate_name.update_attributes(params[:alternate_name]) + format.html { redirect_to @alternate_name.crop, notice: 'Alternate name was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @alternate_name.errors, status: :unprocessable_entity } + end + end + end end diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index 83b9ff5c8..e0f6a6773 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -56,6 +56,9 @@ feature "Alternate names" do crop = alternate_eggplant.crop visit edit_alternate_name_path(alternate_eggplant) expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" + fill_in 'Name', with: "alternative aubergine" + click_on "Save" + expect(page).to have_content "alternative aubergine" end end From b0096035813b70817921342e92bfe2ef4c415b53 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 16:54:02 +0100 Subject: [PATCH 11/47] Fix link to crop on alternate name page --- app/views/alternate_names/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/alternate_names/show.html.haml b/app/views/alternate_names/show.html.haml index 2f7db7f14..67dfc9a37 100644 --- a/app/views/alternate_names/show.html.haml +++ b/app/views/alternate_names/show.html.haml @@ -5,7 +5,7 @@ = @alternate_name.name %p %b Crop: - = link_to @alternate_name.crop + = link_to @alternate_name.crop, @alternate_name.crop - if can? :edit, @alternate_name = link_to 'Edit', edit_alternate_name_path(@alternate_name), :class => 'btn btn-default btn-xs' From edf2f36bcd48ea10eeb76ccd2ec149ed9309588e Mon Sep 17 00:00:00 2001 From: Cesy Avon Date: Sat, 18 Oct 2014 16:58:23 +0100 Subject: [PATCH 12/47] Upgrading to ruby 2.1.2 --- .ruby-version | 2 +- Gemfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index 3e3c2f1e5..eca07e4c1 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.1.1 +2.1.2 diff --git a/Gemfile b/Gemfile index d463e130e..2360041eb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby "2.1.1" +ruby "2.1.2" gem 'bundler', '>=1.1.5' From c7c85aaa664498002928d75e3a0f27995ad1ea3c Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 17:03:54 +0100 Subject: [PATCH 13/47] Creation and deletion of alternate names --- app/controllers/alternate_names_controller.rb | 30 +++++++++++++++++++ spec/features/crop_spec.rb | 3 ++ 2 files changed, 33 insertions(+) diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb index 857233fa0..c7a0ac910 100644 --- a/app/controllers/alternate_names_controller.rb +++ b/app/controllers/alternate_names_controller.rb @@ -29,6 +29,23 @@ class AlternateNamesController < ApplicationController end end + # POST /alternate_names + # POST /alternate_names.json + def create + params[:alternate_name][:creator_id] = current_member.id + @alternate_name = AlternateName.new(params[:alternate_name]) + + respond_to do |format| + if @alternate_name.save + format.html { redirect_to @alternate_name.crop, notice: 'Alternate name was successfully created.' } + format.json { render json: @alternate_name, status: :created, location: @alternate_name } + else + format.html { render action: "new" } + format.json { render json: @alternate_name.errors, status: :unprocessable_entity } + end + end + end + # PUT /alternate_names/1 # PUT /alternate_names/1.json def update @@ -44,4 +61,17 @@ class AlternateNamesController < ApplicationController end end end + + # DELETE /alternate_names/1 + # DELETE /alternate_names/1.json + def destroy + @alternate_name = AlternateName.find(params[:id]) + @crop = @alternate_name.crop + @alternate_name.destroy + + respond_to do |format| + format.html { redirect_to @crop } + format.json { head :no_content } + end + end end diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index e0f6a6773..28fd35f2c 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -50,6 +50,9 @@ feature "Alternate names" do crop = alternate_eggplant.crop visit new_alternate_name_path(crop_id: crop.id) expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" + fill_in 'Name', with: "not an aubergine" + click_on "Save" + expect(page).to have_content "not an aubergine" end scenario "The edit-alternate-name page works" do From dc2cf5275c7b9ed51fce35e29134416f42e1ed67 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 17:30:22 +0100 Subject: [PATCH 14/47] Fix model tests for alternate names. --- spec/models/alternate_name_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/models/alternate_name_spec.rb b/spec/models/alternate_name_spec.rb index e7772dca0..f7acd0efc 100644 --- a/spec/models/alternate_name_spec.rb +++ b/spec/models/alternate_name_spec.rb @@ -1,24 +1,22 @@ require 'spec_helper' describe AlternateName do - before (:each) do - @an = FactoryGirl.create(:alternate_tomato) - end + let(:an) { FactoryGirl.create(:alternate_eggplant) } it 'should save a basic alternate name' do - @an.save.should be_true + expect(an.save).to be_true end it 'should be possible to add multiple alternate names to a crop' do - crop = @an.crop + crop = an.crop an2 = AlternateName.create( :name => "really alternative tomato", :crop_id => crop.id, - :creator_id => @an.creator.id + :creator_id => an.creator.id ) crop.alternate_names << an2 - crop.alternate_names.should include @an - crop.alternate_names.should include an2 + expect(crop.alternate_names).to include an + expect(crop.alternate_names).to include an2 end end From 8a97aa1a9bc1170856205469971eb1d78e637f21 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 17:34:33 +0100 Subject: [PATCH 15/47] Delete redundant old-style test. --- spec/features/crop_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index 28fd35f2c..db89af134 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -18,7 +18,6 @@ feature "Alternate names" do fill_in 'Login', with: member.login_name fill_in 'Password', with: member.password click_button 'Sign in' - page.should have_content member.login_name end scenario "Crop wranglers can edit alternate names" do From 96d2fa1cb6739842bb13eee63573c0d9ad48db19 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 17:41:52 +0100 Subject: [PATCH 16/47] Put alternate names controller in standard order. --- app/controllers/alternate_names_controller.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb index c7a0ac910..34aa738d3 100644 --- a/app/controllers/alternate_names_controller.rb +++ b/app/controllers/alternate_names_controller.rb @@ -1,9 +1,15 @@ class AlternateNamesController < ApplicationController load_and_authorize_resource - # GET /alternate_names/1/edit - def edit - @alternate_name = AlternateName.find(params[:id]) + # GET /scientific_names + # GET /scientific_names.json + def index + @scientific_names = ScientificName.all + + respond_to do |format| + format.html # index.html.haml + format.json { render json: @scientific_names } + end end # GET /alternate_names/1 @@ -29,6 +35,11 @@ class AlternateNamesController < ApplicationController end end + # GET /alternate_names/1/edit + def edit + @alternate_name = AlternateName.find(params[:id]) + end + # POST /alternate_names # POST /alternate_names.json def create From 0ae68737c3769babfa12c492aa795e0eac374097 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 17:43:59 +0100 Subject: [PATCH 17/47] Use login_as helper method in altname feature tests. --- spec/features/crop_spec.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index db89af134..89e81eeb2 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -13,11 +13,7 @@ feature "Alternate names" do let(:member){crop_wranglers.first} before :each do - visit root_path - click_link 'Sign in' - fill_in 'Login', with: member.login_name - fill_in 'Password', with: member.password - click_button 'Sign in' + login_as(member) end scenario "Crop wranglers can edit alternate names" do From c447c1cb3a4abb459e8be0f3f0e1bde001251f5c Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 17:49:13 +0100 Subject: [PATCH 18/47] Make edit-altname test more featurey. --- app/views/crops/show.html.haml | 50 ++++++++++++++++++---------------- spec/features/crop_spec.rb | 19 +++++-------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index ad5abab1b..2c9413795 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -59,31 +59,33 @@ - if can? :destroy, @crop = link_to 'Delete crop', @crop, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' - %h4 Scientific names - %ul - - @crop.scientific_names.each do |sn| - %li - = sn.scientific_name - - if can? :edit, sn - = link_to 'Edit', edit_scientific_name_path(sn), { :class => 'btn btn-default btn-xs' } - - if can? :destroy, sn - = link_to 'Delete', sn, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' - %p - - if can? :edit, @crop - = link_to 'Add', new_scientific_name_path( :crop_id => @crop.id ), { :class => 'btn btn-default btn-xs' } + .scientific_names + %h4 Scientific names + %ul + - @crop.scientific_names.each do |sn| + %li + = sn.scientific_name + - if can? :edit, sn + = link_to 'Edit', edit_scientific_name_path(sn), { :class => 'btn btn-default btn-xs' } + - if can? :destroy, sn + = link_to 'Delete', sn, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' + %p + - if can? :edit, @crop + = link_to 'Add', new_scientific_name_path( :crop_id => @crop.id ), { :class => 'btn btn-default btn-xs' } - %h4 Alternate names - %ul - - @crop.alternate_names.each do |an| - %li - = an.name - - if can? :edit, an - = link_to 'Edit', edit_alternate_name_path(an), { :class => 'btn btn-default btn-xs' } - - if can? :destroy, an - = link_to 'Delete', an, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' - %p - - if can? :edit, @crop - = link_to 'Add', new_alternate_name_path( :crop_id => @crop.id ), { :class => 'btn btn-default btn-xs' } + .alternate_names + %h4 Alternate names + %ul + - @crop.alternate_names.each do |an| + %li + = an.name + - if can? :edit, an + = link_to 'Edit', edit_alternate_name_path(an), { :class => 'btn btn-default btn-xs' } + - if can? :destroy, an + = link_to 'Delete', an, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' + %p + - if can? :edit, @crop + = link_to 'Add', new_alternate_name_path( :crop_id => @crop.id ), { :class => 'btn btn-default btn-xs' } = render :partial => 'varieties', :locals => { :crop => @crop } diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index 89e81eeb2..be8c21b9c 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' feature "Alternate names" do let(:alternate_eggplant) { FactoryGirl.create(:alternate_eggplant) } + let(:crop) { alternate_eggplant.crop } scenario "Display alternate names on crop page" do visit crop_path(alternate_eggplant.crop) @@ -17,10 +18,15 @@ feature "Alternate names" do end scenario "Crop wranglers can edit alternate names" do - visit crop_path(alternate_eggplant.crop) + visit crop_path(crop) expect(page).to have_content "CROP WRANGLER" expect(page).to have_content alternate_eggplant.name expect(page).to have_link "Edit", :href => edit_alternate_name_path(alternate_eggplant) + within('.alternate_names') { click_on "Edit" } + expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" + fill_in 'Name', with: "alternative aubergine" + click_on "Save" + expect(page).to have_content "alternative aubergine" end scenario "Crop wranglers can delete alternate names" do @@ -30,7 +36,6 @@ feature "Alternate names" do end scenario "Crop wranglers can add alternate names" do - crop = alternate_eggplant.crop visit crop_path(crop) expect(page).to have_link "Add", href: new_alternate_name_path(crop_id: crop.id) @@ -42,7 +47,6 @@ feature "Alternate names" do end scenario "The add-alternate-name page works" do - crop = alternate_eggplant.crop visit new_alternate_name_path(crop_id: crop.id) expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" fill_in 'Name', with: "not an aubergine" @@ -50,15 +54,6 @@ feature "Alternate names" do expect(page).to have_content "not an aubergine" end - scenario "The edit-alternate-name page works" do - crop = alternate_eggplant.crop - visit edit_alternate_name_path(alternate_eggplant) - expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" - fill_in 'Name', with: "alternative aubergine" - click_on "Save" - expect(page).to have_content "alternative aubergine" - end - end end From 110ae99d8384e59b0848685cde118c6442fbf98b Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 17:55:56 +0100 Subject: [PATCH 19/47] Fix and test altname index page. --- app/controllers/alternate_names_controller.rb | 8 ++++---- spec/features/crop_spec.rb | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb index 34aa738d3..9d1496e9a 100644 --- a/app/controllers/alternate_names_controller.rb +++ b/app/controllers/alternate_names_controller.rb @@ -1,14 +1,14 @@ class AlternateNamesController < ApplicationController load_and_authorize_resource - # GET /scientific_names - # GET /scientific_names.json + # GET /alternate_names + # GET /alternate_names.json def index - @scientific_names = ScientificName.all + @alternate_names = AlternateName.all respond_to do |format| format.html # index.html.haml - format.json { render json: @scientific_names } + format.json { render json: @alternate_names } end end diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index be8c21b9c..d8e2f31a1 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' feature "Alternate names" do - let(:alternate_eggplant) { FactoryGirl.create(:alternate_eggplant) } + let!(:alternate_eggplant) { FactoryGirl.create(:alternate_eggplant) } let(:crop) { alternate_eggplant.crop } scenario "Display alternate names on crop page" do @@ -9,6 +9,11 @@ feature "Alternate names" do expect(page).to have_content alternate_eggplant.name end + scenario "Index page for alternate names" do + visit alternate_names_path + expect(page).to have_content alternate_eggplant.name + end + context "User is a crop wrangler" do let!(:crop_wranglers) { FactoryGirl.create_list(:crop_wrangling_member, 3) } let(:member){crop_wranglers.first} From 52fd2b86d64b8e8e360d6ec38d3dc1c889f136aa Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 18:01:54 +0100 Subject: [PATCH 20/47] Test altname deletion end-to-end. --- spec/features/crop_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index d8e2f31a1..6cd26b891 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -38,6 +38,8 @@ feature "Alternate names" do visit crop_path(alternate_eggplant.crop) expect(page).to have_link "Delete", href: alternate_name_path(alternate_eggplant) + within('.alternate_names') { click_on "Delete" } + expect(page).to_not have_content alternate_eggplant.name end scenario "Crop wranglers can add alternate names" do From 792062e0d25b7de5a00e2ccb7d0aad156a81f093 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 18:02:59 +0100 Subject: [PATCH 21/47] Make add-altname test more featurey. --- spec/features/crop_spec.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/spec/features/crop_spec.rb b/spec/features/crop_spec.rb index 6cd26b891..3c648f763 100644 --- a/spec/features/crop_spec.rb +++ b/spec/features/crop_spec.rb @@ -46,6 +46,11 @@ feature "Alternate names" do visit crop_path(crop) expect(page).to have_link "Add", href: new_alternate_name_path(crop_id: crop.id) + within('.alternate_names') { click_on "Add" } + expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" + fill_in 'Name', with: "not an aubergine" + click_on "Save" + expect(page).to have_content "not an aubergine" end scenario "The show-alternate-name page works" do @@ -53,14 +58,6 @@ feature "Alternate names" do expect(page).to have_content alternate_eggplant.crop.name end - scenario "The add-alternate-name page works" do - visit new_alternate_name_path(crop_id: crop.id) - expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" - fill_in 'Name', with: "not an aubergine" - click_on "Save" - expect(page).to have_content "not an aubergine" - end - end end From 006bc54f3f935cfb59404ad8d081aa18310a5dba Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sat, 18 Oct 2014 18:13:04 +0100 Subject: [PATCH 22/47] Oops, add the altname index HAML file. --- app/views/alternate_names/index.html.haml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/views/alternate_names/index.html.haml diff --git a/app/views/alternate_names/index.html.haml b/app/views/alternate_names/index.html.haml new file mode 100644 index 000000000..60a83bde2 --- /dev/null +++ b/app/views/alternate_names/index.html.haml @@ -0,0 +1,23 @@ +%h1 Listing alternate_names + +- if can? :create, AlternateName + %p= link_to 'New Alternate name', new_alternate_name_path, :class => 'btn btn-primary' + +%table + %tr + %th Alternate name + %th Crop + %th + %th + + - @alternate_names.each do |alternate_name| + %tr + %td= link_to alternate_name.name, alternate_name + %td= alternate_name.crop + %td= link_to 'Show', alternate_name + %td + - if can? :edit, alternate_name + = link_to 'Edit', edit_alternate_name_path(alternate_name), :class => 'btn btn-default btn-xs' + %td + - if can? :destroy, alternate_name + = link_to 'Delete', alternate_name, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' From 1d3c24ae277c14e00aa9aa0a6bc9a20016a96f81 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 11:28:51 +0100 Subject: [PATCH 23/47] Use content_for :title on altname index page. --- app/views/alternate_names/index.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/alternate_names/index.html.haml b/app/views/alternate_names/index.html.haml index 60a83bde2..5cc1f69d0 100644 --- a/app/views/alternate_names/index.html.haml +++ b/app/views/alternate_names/index.html.haml @@ -1,7 +1,7 @@ -%h1 Listing alternate_names +- content_for :title, "Listing alternate names" - if can? :create, AlternateName - %p= link_to 'New Alternate name', new_alternate_name_path, :class => 'btn btn-primary' + %p= link_to 'New alternate name', new_alternate_name_path, :class => 'btn btn-primary' %table %tr From 3a797d4434ada4a34e7f0c98ce9d8826e4867d50 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 11:42:49 +0100 Subject: [PATCH 24/47] Use content_for :title in scientific names index. --- app/views/scientific_names/index.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/scientific_names/index.html.haml b/app/views/scientific_names/index.html.haml index 28cd84710..e0752b156 100644 --- a/app/views/scientific_names/index.html.haml +++ b/app/views/scientific_names/index.html.haml @@ -1,4 +1,4 @@ -%h1 Listing scientific_names +- content_for :title, "Listing scientific names" - if can? :create, ScientificName %p= link_to 'New Scientific name', new_scientific_name_path, :class => 'btn btn-primary' From d0f7169c59d9ced87722c88b1ba90abebaed914c Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 11:50:21 +0100 Subject: [PATCH 25/47] Put alternate name features in their own file. --- spec/features/{crop_spec.rb => alternate_name_spec.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/features/{crop_spec.rb => alternate_name_spec.rb} (100%) diff --git a/spec/features/crop_spec.rb b/spec/features/alternate_name_spec.rb similarity index 100% rename from spec/features/crop_spec.rb rename to spec/features/alternate_name_spec.rb From 29d53a8f8b5fcd52c624264afb044103969ec9a6 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 12:02:31 +0100 Subject: [PATCH 26/47] Test for notices in altname CRUD features. --- app/controllers/alternate_names_controller.rb | 4 +++- spec/features/alternate_name_spec.rb | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/alternate_names_controller.rb b/app/controllers/alternate_names_controller.rb index 9d1496e9a..ea8a8f76c 100644 --- a/app/controllers/alternate_names_controller.rb +++ b/app/controllers/alternate_names_controller.rb @@ -81,7 +81,9 @@ class AlternateNamesController < ApplicationController @alternate_name.destroy respond_to do |format| - format.html { redirect_to @crop } + format.html { + redirect_to @crop, notice: 'Alternate name was successfully deleted.' + } format.json { head :no_content } end end diff --git a/spec/features/alternate_name_spec.rb b/spec/features/alternate_name_spec.rb index 3c648f763..a58e1c365 100644 --- a/spec/features/alternate_name_spec.rb +++ b/spec/features/alternate_name_spec.rb @@ -32,6 +32,7 @@ feature "Alternate names" do fill_in 'Name', with: "alternative aubergine" click_on "Save" expect(page).to have_content "alternative aubergine" + expect(page).to have_content 'Alternate name was successfully updated' end scenario "Crop wranglers can delete alternate names" do @@ -40,6 +41,7 @@ feature "Alternate names" do href: alternate_name_path(alternate_eggplant) within('.alternate_names') { click_on "Delete" } expect(page).to_not have_content alternate_eggplant.name + expect(page).to have_content 'Alternate name was successfully deleted' end scenario "Crop wranglers can add alternate names" do @@ -51,6 +53,7 @@ feature "Alternate names" do fill_in 'Name', with: "not an aubergine" click_on "Save" expect(page).to have_content "not an aubergine" + expect(page).to have_content 'Alternate name was successfully created' end scenario "The show-alternate-name page works" do From 82a61387a3b49bc6630bd7d5b4c6571a3c9773d8 Mon Sep 17 00:00:00 2001 From: Skud Date: Sun, 19 Oct 2014 12:23:19 +0100 Subject: [PATCH 27/47] Improved layout of member profile page In doing this, I added some content areas for all pages on the site: 1) subtitle 2) buttonbar These are intended to help standardise the layout of all pages. On the member page, the subtitle is the location, and the buttonbar has links like "edit profile", "upgrade account", etc (or if looking at someone else's page, then "send message" etc). I also implemented subtitle/buttonbar on the crop detail page (the subtitle is the default scientific name). The rest is just refactoring and tests. I've removed some view tests and put them in feature tests instead. --- app/assets/stylesheets/overrides.css.less | 15 ++ app/views/crops/show.html.haml | 22 +- app/views/gardens/new.html.haml | 2 +- app/views/layouts/application.html.haml | 13 +- app/views/members/_avatar.html.haml | 2 +- app/views/members/_bio.html.haml | 9 + app/views/members/_contact.html.haml | 17 ++ app/views/members/_gardens.html.haml | 27 +++ app/views/members/_stats.html.haml | 23 ++ app/views/members/show.html.haml | 115 +++------- app/views/scientific_names/index.html.haml | 2 +- spec/features/crop_wranglers_spec.rb | 11 +- spec/features/crops/crop_detail_page_spec.rb | 32 +++ spec/features/member_profile_spec.rb | 132 ++++++++++++ spec/views/crops/show.html.haml_spec.rb | 21 -- spec/views/members/show.html.haml_spec.rb | 214 ------------------- 16 files changed, 308 insertions(+), 349 deletions(-) create mode 100644 app/views/members/_bio.html.haml create mode 100644 app/views/members/_contact.html.haml create mode 100644 app/views/members/_gardens.html.haml create mode 100644 app/views/members/_stats.html.haml create mode 100644 spec/features/crops/crop_detail_page_spec.rb create mode 100644 spec/features/member_profile_spec.rb delete mode 100644 spec/views/members/show.html.haml_spec.rb diff --git a/app/assets/stylesheets/overrides.css.less b/app/assets/stylesheets/overrides.css.less index 7b9952c5d..5826d5c4c 100644 --- a/app/assets/stylesheets/overrides.css.less +++ b/app/assets/stylesheets/overrides.css.less @@ -36,6 +36,21 @@ h2 { font-size: 150%; } +#headingarea { + border-bottom: 1px solid lighten(@brown, 50%) +} + +/* +#subtitle { + color: lighten(@brown, 30%); + margin-top: 0px; + padding-top: 0px; + padding-left: 1em; + font-style: italic; + font-weight: normal; +} +*/ + h3 { font-size: 120%; } diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index 670a0d438..c67cb12ce 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -1,18 +1,18 @@ - content_for :title, @crop.name +- content_for :subtitle, @crop.default_scientific_name +- content_for :buttonbar do + - if can? :create, Planting + = link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-default' + + - if can? :create, Harvest + = link_to "Harvest this", new_harvest_path(:crop_id => @crop.id), :class => 'btn btn-default' + + - if can? :create, Seed + = link_to 'Add seeds to stash', new_seed_path(:params => { :crop_id => @crop.id }), :class => 'btn btn-default' + .row .col-md-9 - %p - - if can? :create, Planting - = link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-primary' - - else - = render :partial => 'shared/signin_signup', :locals => { :to => 'plant this crop' } - - - if can? :create, Harvest - = link_to "Harvest this", new_harvest_path(:crop_id => @crop.id), :class => 'btn btn-primary' - - - if can? :create, Seed - = link_to 'Add seeds to stash', new_seed_path(:params => { :crop_id => @crop.id }), :class => 'btn btn-primary' = render :partial => 'photos', :locals => { :crop => @crop } diff --git a/app/views/gardens/new.html.haml b/app/views/gardens/new.html.haml index 3e7ee5f67..4fdc839b1 100644 --- a/app/views/gardens/new.html.haml +++ b/app/views/gardens/new.html.haml @@ -1,3 +1,3 @@ -%h1 New garden +- content_for :title, "New garden" = render 'form' diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 7ff38d7c2..559daa608 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -8,8 +8,17 @@ .container .row .col-md-12 - - if content_for?(:title) - %h1= yield(:title) + #headingarea + - if content_for?(:title) + %h1#title + = yield(:title) + - if content_for?(:subtitle) + %small= yield(:subtitle) + + - if content_for?(:buttonbar) + %p + .btn-group + = yield(:buttonbar) - if notice .alert.alert-success = notice diff --git a/app/views/members/_avatar.html.haml b/app/views/members/_avatar.html.haml index c56c8768a..25c0e3140 100644 --- a/app/views/members/_avatar.html.haml +++ b/app/views/members/_avatar.html.haml @@ -5,5 +5,5 @@ :size => defined?(size) ? size : 150, | :default => :identicon }), | :alt => '', | - :class => 'img-rounded img-responsive' ), | + :class => 'img-rounded img-responsive avatar' ), | member_path(member) diff --git a/app/views/members/_bio.html.haml b/app/views/members/_bio.html.haml new file mode 100644 index 000000000..3858d224c --- /dev/null +++ b/app/views/members/_bio.html.haml @@ -0,0 +1,9 @@ +%h2 All about #{member.login_name} +- if member.bio.blank? + - if can? :edit, member + = link_to "Add a bio to complete your profile." + - else + #{member.login_name} hasn't written a bio yet. +- else + :growstuff_markdown + #{ strip_tags member.bio } diff --git a/app/views/members/_contact.html.haml b/app/views/members/_contact.html.haml new file mode 100644 index 000000000..e5d24327b --- /dev/null +++ b/app/views/members/_contact.html.haml @@ -0,0 +1,17 @@ +- if twitter_auth || flickr_auth || member.show_email + %h4 Contact + + - if twitter_auth + %p + = image_tag "twitter_32.png", :size => "32x32", :alt => 'Twitter logo' + =link_to twitter_auth.name, "http://twitter.com/#{twitter_auth.name}" + + - if flickr_auth + %p + = 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 + %p + Email: + = mail_to member.email diff --git a/app/views/members/_gardens.html.haml b/app/views/members/_gardens.html.haml new file mode 100644 index 000000000..89ed8f83e --- /dev/null +++ b/app/views/members/_gardens.html.haml @@ -0,0 +1,27 @@ +%h2 #{member.login_name}'s gardens +.tabbable + %ul.nav.nav-tabs + - first_garden = true + - member.gardens.each do |g| + %li{:class => first_garden ? 'active' : '' } + - first_garden = false + = link_to g.name, "#garden#{g.id}", 'data-toggle' => 'tab' + - if current_member == member + %li= link_to 'New Garden', new_garden_path + .tab-content + - first_garden = true + - member.gardens.each do |g| + + %div{:class => ['tab-pane', first_garden ? 'active' : ''], :id => "garden#{g.id}"} + - first_garden = false + + %div + :growstuff_markdown + #{ strip_tags g.description } + + %h3 What's planted here? + - g.featured_plantings.each do |p| + = render :partial => "plantings/thumbnail", :locals => { :planting => p, :hide_description => true } + + %p + = link_to "More about this garden...", url_for(g) diff --git a/app/views/members/_stats.html.haml b/app/views/members/_stats.html.haml new file mode 100644 index 000000000..38d6b96c3 --- /dev/null +++ b/app/views/members/_stats.html.haml @@ -0,0 +1,23 @@ +%h3 Activity + +%ul + %li + - if member.plantings.count > 0 + = link_to pluralize(member.plantings.count, "planting"), plantings_by_owner_path(:owner => member) + - else + 0 plantings + %li + - if member.harvests.count > 0 + = link_to pluralize(member.harvests.count, "harvest"), harvests_by_owner_path(:owner => member) + - else + 0 harvests + %li + - if member.seeds.count > 0 + = link_to pluralize(member.seeds.count, "seeds"), seeds_by_owner_path(:owner => member) + - else + 0 seeds + %li + - if member.posts.count > 0 + = link_to pluralize(member.posts.count, "post"), posts_by_author_path(:author => member) + - else + 0 posts diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index acbcb8c34..317caae1b 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -1,15 +1,28 @@ -- content_for :title, "#{@member.login_name}" -- content_for :member_rss_login_name, "#{@member.login_name}" -- content_for :member_rss_slug, "#{@member.slug}" +- content_for :title, @member.login_name +- content_for :subtitle, @member.location +- content_for :buttonbar do + - if can? :update, @member + = link_to 'Edit profile', edit_member_registration_path, :class => 'btn btn-default' + - if @member == current_member && !@member.is_paid? + = link_to "Upgrade account", shop_path, :class => 'btn btn-default' + -if can? :create, Notification and current_member != @member + =link_to 'Send message', new_notification_path(:recipient_id => @member.id), :class => 'btn btn-default' + +- content_for :member_rss_login_name, @member.login_name +- content_for :member_rss_slug, @member.slug .row - .col-md-3 - = render :partial => "members/avatar", :locals => { :member => @member } - -if can? :create, Notification and current_member != @member - %p - %br/ - =link_to 'Send Message', new_notification_path(:recipient_id => @member.id), :class => 'btn btn-primary' + .col-md-9 + + = render :partial => "bio", :locals => { :member => @member } + + = render :partial => "gardens", :locals => { :member => @member } + + .col-md-3 + = render :partial => "avatar", :locals => { :member => @member } + + %h3 Account details %p %strong Member since: @@ -20,86 +33,6 @@ = @member.account_type account - - if @member == current_member && !@member.is_paid? - = link_to "Upgrade", shop_path, :class => 'btn btn-primary btn-xs' + = render :partial => "contact", :locals => { :member => @member, :twitter_auth => @twitter_auth, :flickr_auth => @flickr_auth } - - if @twitter_auth || @flickr_auth || @member.show_email - %h4 Contact - - - if @twitter_auth - %p - = image_tag "twitter_32.png", :size => "32x32", :alt => 'Twitter logo' - =link_to @twitter_auth.name, "http://twitter.com/#{@twitter_auth.name}" - - - if @flickr_auth - %p - = 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 - %p - Email: - = mail_to @member.email - - - if @member.location.to_s != '' - %h4 Location - %p - = link_to image_tag("http://maps.google.com/maps/api/staticmap?size=200x200&maptype=roadmap&sensor=false&markers=color:green|label:A|#{@member.latitude},#{@member.longitude}&zoom=12", :alt => "Map showing #{@member.location}", :width => 200, :height => 200 ), place_path(@member.location) - %br/ - = link_to @member.location, place_path(@member.location) - - .col-md-9 - %p - - if can? :update, @member - %p - = link_to 'Edit your profile', "edit", :class => 'btn btn-primary' - - if @member.bio - %h2 Bio - :growstuff_markdown - #{ strip_tags @member.bio } - %h2 Gardens - .tabbable - %ul.nav.nav-tabs - - first_garden = true - - @member.gardens.each do |g| - %li{:class => first_garden ? 'active' : '' } - - first_garden = false - = link_to g.name, "#garden#{g.id}", 'data-toggle' => 'tab' - - if current_member == @member - %li= link_to 'New Garden', '#garden_new', 'data-toggle' => 'tab' - .tab-content - - first_garden = true - - @member.gardens.each do |g| - - %div{:class => ['tab-pane', first_garden ? 'active' : ''], :id => "garden#{g.id}"} - - first_garden = false - - %div - :growstuff_markdown - #{ strip_tags g.description } - - %h3 What's planted here? - - g.featured_plantings.each do |p| - = render :partial => "plantings/thumbnail", :locals => { :planting => p, :hide_description => true } - - %p - = link_to "More about this garden...", url_for(g) - - - if current_member == @member - %div{:class => 'tab-pane', :id => "garden_new"} - %h3 Create a new garden - = render 'gardens/form' - - %h3 Seeds - %p - - if @member.seeds.count > 0 - = link_to pluralize(@member.seeds.count, "variety"), seeds_path(:owner_id => @member.id) - - else - No seeds yet. - - %h3 Posts - - if @member.posts.count > 0 - - @member.posts.each do |post| - = render :partial => "posts/single", :locals => { :post => post, :subject => true } - - else - %p Nothing posted yet. + = render :partial => "stats", :locals => { :member => @member } diff --git a/app/views/scientific_names/index.html.haml b/app/views/scientific_names/index.html.haml index 28cd84710..8a5ae901d 100644 --- a/app/views/scientific_names/index.html.haml +++ b/app/views/scientific_names/index.html.haml @@ -1,4 +1,4 @@ -%h1 Listing scientific_names +-content_for :title, "Listing scientific_names" - if can? :create, ScientificName %p= link_to 'New Scientific name', new_scientific_name_path, :class => 'btn btn-primary' diff --git a/spec/features/crop_wranglers_spec.rb b/spec/features/crop_wranglers_spec.rb index 80475bd18..32c96e639 100644 --- a/spec/features/crop_wranglers_spec.rb +++ b/spec/features/crop_wranglers_spec.rb @@ -4,16 +4,13 @@ feature "crop wranglers" do context "signed in member" do let!(:crop_wranglers) { FactoryGirl.create_list(:crop_wrangling_member, 3) } let(:member){crop_wranglers.first} - before :each do - visit root_path - click_link 'Sign in' - fill_in 'Login', with: member.login_name - fill_in 'Password', with: member.password - click_button 'Sign in' - page.should have_content member.login_name + + background do + login_as(member) end scenario "crop wranglers are listed on the crop wrangler page" do + visit root_path click_link 'Crop Wrangling' within '.crop_wranglers' do diff --git a/spec/features/crops/crop_detail_page_spec.rb b/spec/features/crops/crop_detail_page_spec.rb new file mode 100644 index 000000000..a941cb075 --- /dev/null +++ b/spec/features/crops/crop_detail_page_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +feature "crop detail page" do + + let(:crop) { FactoryGirl.create(:crop) } + + context "signed in member" do + let(:member) { FactoryGirl.create(:member) } + + background do + login_as(member) + end + + context "action buttons" do + + background do + visit crop_path(crop) + end + + scenario "has a link to plant the crop" do + expect(page).to have_link "Plant this", :href => new_planting_path(:crop_id => crop.id) + end + scenario "has a link to harvest the crop" do + expect(page).to have_link "Harvest this", :href => new_harvest_path(:crop_id => crop.id) + end + scenario "has a link to add seeds" do + expect(page).to have_link "Add seeds to stash", :href => new_seed_path(:crop_id => crop.id) + end + + end + end +end diff --git a/spec/features/member_profile_spec.rb b/spec/features/member_profile_spec.rb new file mode 100644 index 000000000..88f29548a --- /dev/null +++ b/spec/features/member_profile_spec.rb @@ -0,0 +1,132 @@ +require 'spec_helper' + +feature "member profile" do + + context "signed out member" do + let(:member) { FactoryGirl.create(:member) } + + scenario "basic details on member profile page" do + visit member_path(member) + expect(page).to have_css("h1", :text => member.login_name) + expect(page).to have_content member.bio + expect(page).to have_content "Member since: #{member.created_at.to_s(:date)}" + expect(page).to have_content "Account type: Free account" + expect(page).to have_content "#{member.login_name}'s gardens" + expect(page).to have_link "More about this garden...", :href => garden_path(member.gardens.first) + end + + scenario "no bio" do + member.bio = nil + member.save + visit member_path(member) + expect(page).to have_content "hasn't written a bio yet" + end + + scenario "gravatar" do + visit member_path(member) + expect(page).to have_css "img.avatar" + end + + context "location" do + scenario "member has set location" do + london_member = FactoryGirl.create(:london_member) + visit member_path(london_member) + expect(page).to have_css("h1>small", :text => london_member.location) + end + + scenario "member has not set location" do + visit member_path(member) + expect(page).not_to have_css("h1>small") + end + end + + context "email privacy" do + scenario "public email address" do + public_member = FactoryGirl.create(:public_member) + visit member_path(public_member) + expect(page).to have_content public_member.email + end + scenario "private email address" do + visit member_path(member) + expect(page).not_to have_content member.email + end + end + + context "activity stats" do + + scenario "with no activity" do + visit member_path(member) + expect(page).to have_content "Activity" + expect(page).to have_content "0 plantings" + expect(page).to have_content "0 harvests" + expect(page).to have_content "0 seeds" + expect(page).to have_content "0 posts" + end + + scenario "with some activity" do + FactoryGirl.create_list(:planting, 2, :owner => member) + FactoryGirl.create_list(:harvest, 3, :owner => member) + FactoryGirl.create_list(:seed, 4, :owner => member) + FactoryGirl.create_list(:post, 5, :author => member) + visit member_path(member) + expect(page).to have_link "2 plantings", :href => plantings_by_owner_path(:owner => member) + expect(page).to have_link "3 harvests", :href => harvests_by_owner_path(:owner => member) + expect(page).to have_link "4 seeds", :href => seeds_by_owner_path(:owner => member) + expect(page).to have_link "5 posts", :href => posts_by_author_path(:author => member) + end + + end + + scenario "twitter link" do + twitter_auth = FactoryGirl.create(:authentication, :member => member) + visit member_path(member) + expect(page).to have_link twitter_auth.name, :href => "http://twitter.com/#{twitter_auth.name}" + end + + scenario "flickr link" do + flickr_auth = FactoryGirl.create(:flickr_authentication, :member => member) + visit member_path(member) + expect(page).to have_link flickr_auth.name, :href => "http://flickr.com/photos/#{flickr_auth.uid}" + end + + end + + context "signed in member" do + let(:member) { FactoryGirl.create(:member) } + let(:other_member) { FactoryGirl.create(:member) } + + background do + login_as(member) + end + + context "your own profile page" do + background do + visit member_path(member) + end + + scenario "has a link to create new garden" do + expect(page).to have_link "New Garden", :href => new_garden_path + end + + scenario "has a button to edit profile" do + expect(page).to have_link "Edit profile", :href => edit_member_registration_path + end + + scenario "has a button to upgrade account" do + expect(page).to have_link "Upgrade account", :href => shop_path + end + + end + + context "someone else's profile page" do + background do + visit member_path(other_member) + end + + scenario "has a private message button" do + expect(page).to have_link "Send message", :href => new_notification_path(:recipient_id => other_member.id) + end + end + + end +end diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 1ef461508..ca6166721 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -185,11 +185,6 @@ describe "crops/show" do end - it 'tells you to sign in/sign up' do - render - rendered.should contain 'Sign in or sign up to plant' - end - context 'logged in' do before(:each) do @member = FactoryGirl.create(:member) @@ -198,22 +193,6 @@ describe "crops/show" do render end - it "shows a plant this button" do - rendered.should contain "Plant this" - end - - it "shows a harvest this button" do - rendered.should contain "Harvest this" - end - - it "links to the right crop in the new planting link" do - assert_select("a[href=#{new_planting_path}?crop_id=#{@crop.id}]") - end - - it "links to the right crop in the new harvest link" do - assert_select("a[href=#{new_harvest_path}?crop_id=#{@crop.id}]") - end - it { rendered.should contain "Nobody has planted this crop yet" } it { rendered.should contain "Nobody has harvested this crop yet" } diff --git a/spec/views/members/show.html.haml_spec.rb b/spec/views/members/show.html.haml_spec.rb deleted file mode 100644 index f6c0279d6..000000000 --- a/spec/views/members/show.html.haml_spec.rb +++ /dev/null @@ -1,214 +0,0 @@ -require 'spec_helper' - -describe "members/show" do - before(:each) do - controller.stub(:current_user) { nil } - @member = FactoryGirl.create(:member) - @garden = FactoryGirl.create(:garden, :owner => @member) - end - - context "the basics" do - before(:each) do - render - end - - it "shows the bio" do - assert_select "h2", "Bio" - rendered.should contain @member.bio - end - - it "shows account creation date" do - @time = @member.created_at - rendered.should contain "Member since" - rendered.should contain @time.strftime("%B %d, %Y") - end - - it "shows account type" do - rendered.should contain "Free account" - end - - it "contains a gravatar icon" do - assert_select "img", :src => /gravatar\.com\/avatar/ - end - end - - context 'no bio' do - before(:each) do - @member = FactoryGirl.create(:no_bio_member) - render - end - - it "doesn't show the bio" do - rendered.should_not contain "Bio" - end - end - - context 'twitter' do - context "no twitter" do - it "doesn't show twitter link" do - render - assert_select "a[href^=http://twitter.com/]", :count => 0 - end - end - context 'has twitter' do - it "shows twitter link" do - @twitter_auth = FactoryGirl.create(:authentication, :member => @member) - render - assert_select "a", :href => "http://twitter.com/#{@twitter_auth.name}" - end - end - end - - context 'flickr' do - context "no flickr" do - it "doesn't show flickr link" do - render - assert_select "a[href^=http://flickr.com/]", :count => 0 - end - end - context 'has flickr' do - it "shows flickr link" do - @flickr_auth = FactoryGirl.create(:flickr_authentication, :member => @member) - render - assert_select "a", :href => "http://flickr.com/photos/#{@flickr_auth.uid}" - end - end - end - - context "gardens and plantings" do - before(:each) do - @planting = FactoryGirl.create(:planting, :garden => @garden) - render - end - - it "shows the auto-created garden" 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.name - end - - it "doesn't show the note about random plantings" do - rendered.should_not contain "Note: these are a random selection" - end - - it "doesn't show the email address" do - rendered.should_not contain @member.email - end - - it "does not contain a 'New Garden' link" do - assert_select "a[href=#garden_new]", false - end - - it "does not contain a 'New Garden' tab" do - assert_select "#garden_new", false - end - end - - context "signed in member" do - before(:each) do - sign_in @member - controller.stub(:current_user) { @member } - render - end - - it "contains a 'New Garden' link" do - assert_select "a[href=#garden_new]", :text => "New Garden" - end - - it "contains an edit settings button" do - rendered.should contain "Edit your profile" - end - - it "asks you to upgrade your account" do - rendered.should contain "Upgrade" - end - - it "contains no send message button" do - rendered.should_not contain "Send Message" - end - end - - context "signed in as different member" do - before(:each) do - @member2 = FactoryGirl.create(:member) - sign_in @member2 - controller.stub(:current_user) { @member2 } - render - end - - it "does not contain a 'New Garden' link" do - assert_select "a[href=#garden_new]", false - end - - it "does not contain a 'New Garden' tab" do - assert_select "#garden_new", false - end - - it "contains no edit settings button" do - rendered.should_not contain "Edit Settings" - end - - it "contains a send message button" do - rendered.should contain "Send Message" - end - end - - context "public member" do - before(:each) do - @member = FactoryGirl.create(:public_member) - render - end - - it "shows the email address" do - rendered.should contain @member.email - end - - it "doesn't show a send message button" do - rendered.should_not contain "Send Message" - end - end - - context "geolocations" do - before(:each) do - @member = FactoryGirl.create(:london_member) - render - end - it "shows the location" do - rendered.should contain @member.location - end - it "shows a map" do - assert_select "img", :src => /maps\.google\.com/ - end - - it 'includes a link to places page' do - assert_select 'a', :href => place_path(@member.location) - end - end - - context "no location stated" do - before(:each) do - @member = FactoryGirl.create(:member) - render - end - it "doesn't have a location" do - @member.location.to_s.should eq '' - end - it "doesn't show the location" do - rendered.should_not contain "Location:" - end - it "doesn't show a map" do - assert_select "img[src*=maps]", false - end - end - -end From e613907506c39491bb14cbb8246c5841621f3a7e Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 13:21:30 +0100 Subject: [PATCH 28/47] Check status codes on page visits. --- spec/features/alternate_name_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/features/alternate_name_spec.rb b/spec/features/alternate_name_spec.rb index a58e1c365..086584c40 100644 --- a/spec/features/alternate_name_spec.rb +++ b/spec/features/alternate_name_spec.rb @@ -6,6 +6,7 @@ feature "Alternate names" do scenario "Display alternate names on crop page" do visit crop_path(alternate_eggplant.crop) + expect(page.status_code).to equal 200 expect(page).to have_content alternate_eggplant.name end @@ -24,13 +25,16 @@ feature "Alternate names" do scenario "Crop wranglers can edit alternate names" do visit crop_path(crop) + expect(page.status_code).to equal 200 expect(page).to have_content "CROP WRANGLER" expect(page).to have_content alternate_eggplant.name expect(page).to have_link "Edit", :href => edit_alternate_name_path(alternate_eggplant) within('.alternate_names') { click_on "Edit" } + expect(page.status_code).to equal 200 expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" fill_in 'Name', with: "alternative aubergine" click_on "Save" + expect(page.status_code).to equal 200 expect(page).to have_content "alternative aubergine" expect(page).to have_content 'Alternate name was successfully updated' end @@ -40,6 +44,7 @@ feature "Alternate names" do expect(page).to have_link "Delete", href: alternate_name_path(alternate_eggplant) within('.alternate_names') { click_on "Delete" } + expect(page.status_code).to equal 200 expect(page).to_not have_content alternate_eggplant.name expect(page).to have_content 'Alternate name was successfully deleted' end @@ -49,15 +54,18 @@ feature "Alternate names" do expect(page).to have_link "Add", href: new_alternate_name_path(crop_id: crop.id) within('.alternate_names') { click_on "Add" } + expect(page.status_code).to equal 200 expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" fill_in 'Name', with: "not an aubergine" click_on "Save" + expect(page.status_code).to equal 200 expect(page).to have_content "not an aubergine" expect(page).to have_content 'Alternate name was successfully created' end scenario "The show-alternate-name page works" do visit alternate_name_path(alternate_eggplant) + expect(page.status_code).to equal 200 expect(page).to have_content alternate_eggplant.crop.name end From 41566d39f31fc3a6592ede74ae7fb6ecd856e4fa Mon Sep 17 00:00:00 2001 From: Skud Date: Sun, 19 Oct 2014 13:50:43 +0100 Subject: [PATCH 29/47] Added map to member profile page --- app/assets/javascripts/members.js.erb | 30 +++++++++++++++++++++++ app/assets/stylesheets/overrides.css.less | 4 +++ app/controllers/members_controller.rb | 2 ++ app/views/members/_account.html.haml | 12 +++++++++ app/views/members/_map.html.haml | 5 ++++ app/views/members/show.html.haml | 16 ++---------- spec/features/member_profile_spec.rb | 17 +++++++++++++ 7 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 app/assets/javascripts/members.js.erb create mode 100644 app/views/members/_account.html.haml create mode 100644 app/views/members/_map.html.haml diff --git a/app/assets/javascripts/members.js.erb b/app/assets/javascripts/members.js.erb new file mode 100644 index 000000000..a3f29904d --- /dev/null +++ b/app/assets/javascripts/members.js.erb @@ -0,0 +1,30 @@ +if (document.getElementById("membermap") !== null) { + mapbox_map_id = "<%= Rails.env == 'test' ? 0 : Growstuff::Application.config.mapbox_map_id %>"; + mapbox_base_url = "https://c.tiles.mapbox.com/v3/" + mapbox_map_id + "/{z}/{x}/{y}.png"; + + L.Icon.Default.imagePath = '/assets' + + + $.getJSON(location.pathname + '.json', function(member) { + console.log(JSON.stringify(member.latitude)); + if (member.latitude && member.longitude) { + membermap = L.map('membermap').setView([member.latitude, member.longitude], 4); + + L.tileLayer(mapbox_base_url, { + attribution: 'Map data © OpenStreetMap contributors under ODbL | Map imagery © Mapbox', + maxZoom: 18 + }).addTo(membermap); + console.log("found lat and long") + marker = new L.Marker(new L.LatLng(member.latitude, member.longitude)); + + member_url = "/members/" + member.slug; + member_link = "" + member.login_name + ""; + + where = "

" + member.location + "

"; + + marker.bindPopup(member_link + where).openPopup(); + marker.addTo(membermap); + } + }); + +} diff --git a/app/assets/stylesheets/overrides.css.less b/app/assets/stylesheets/overrides.css.less index 5826d5c4c..a4ac0587f 100644 --- a/app/assets/stylesheets/overrides.css.less +++ b/app/assets/stylesheets/overrides.css.less @@ -113,6 +113,10 @@ p.stats { height: 500px; } +#membermap { + height: 250px; +} + .member-location { font-size: small; font-style: italic; diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index ab3de0001..247ac1c8b 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -10,6 +10,7 @@ class MembersController < ApplicationController respond_to do |format| format.html # index.html.haml + format.json { render :json => @members.to_json(:only => [:id, :login_name, :slug, :bio, :created_at, :location, :latitude, :longitude]) } end end @@ -25,6 +26,7 @@ class MembersController < ApplicationController respond_to do |format| format.html # show.html.haml + format.json { render :json => @member.to_json(:only => [:id, :login_name, :bio, :created_at, :slug, :location, :latitude, :longitude]) } format.rss { render( :layout => false, :locals => { :member => @member } diff --git a/app/views/members/_account.html.haml b/app/views/members/_account.html.haml new file mode 100644 index 000000000..37ff0c699 --- /dev/null +++ b/app/views/members/_account.html.haml @@ -0,0 +1,12 @@ +%h3 Account details + +%p + %strong Member since: + = member.created_at.to_s(:date) + +%p + %strong Account type: + = member.account_type + account + + diff --git a/app/views/members/_map.html.haml b/app/views/members/_map.html.haml new file mode 100644 index 000000000..d98792501 --- /dev/null +++ b/app/views/members/_map.html.haml @@ -0,0 +1,5 @@ +- if member.latitude and member.longitude + %div#membermap + %p + See other members near + = link_to member.location, place_path(member.location) diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 317caae1b..edf4d0b68 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -15,24 +15,12 @@ .col-md-9 + = render :partial => "map", :locals => { :member => @member } = render :partial => "bio", :locals => { :member => @member } - = render :partial => "gardens", :locals => { :member => @member } .col-md-3 = render :partial => "avatar", :locals => { :member => @member } - - %h3 Account details - - %p - %strong Member since: - = @member.created_at.to_s(:date) - - %p - %strong Account type: - = @member.account_type - account - + = render :partial => "account", :locals => { :member => @member } = render :partial => "contact", :locals => { :member => @member, :twitter_auth => @twitter_auth, :flickr_auth => @flickr_auth } - = render :partial => "stats", :locals => { :member => @member } diff --git a/spec/features/member_profile_spec.rb b/spec/features/member_profile_spec.rb index 88f29548a..809b052a8 100644 --- a/spec/features/member_profile_spec.rb +++ b/spec/features/member_profile_spec.rb @@ -32,11 +32,28 @@ feature "member profile" do london_member = FactoryGirl.create(:london_member) visit member_path(london_member) expect(page).to have_css("h1>small", :text => london_member.location) + expect(page).to have_css("#membermap") + expect(page).to have_content "See other members near #{london_member.location}" end scenario "member has not set location" do visit member_path(member) expect(page).not_to have_css("h1>small") + expect(page).not_to have_css("#membermap") + expect(page).not_to have_content "See other members near" + end + + end + + context "email privacy" do + scenario "public email address" do + public_member = FactoryGirl.create(:public_member) + visit member_path(public_member) + expect(page).to have_content public_member.email + end + scenario "private email address" do + visit member_path(member) + expect(page).not_to have_content member.email end end From 16677a3b8637e09c348409f97ec2f5188fd26abc Mon Sep 17 00:00:00 2001 From: Skud Date: Sun, 19 Oct 2014 14:04:32 +0100 Subject: [PATCH 30/47] Removed underline on header area --- app/assets/stylesheets/overrides.css.less | 4 ---- app/views/layouts/application.html.haml | 11 +++++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/overrides.css.less b/app/assets/stylesheets/overrides.css.less index a4ac0587f..8b9938c33 100644 --- a/app/assets/stylesheets/overrides.css.less +++ b/app/assets/stylesheets/overrides.css.less @@ -36,10 +36,6 @@ h2 { font-size: 150%; } -#headingarea { - border-bottom: 1px solid lighten(@brown, 50%) -} - /* #subtitle { color: lighten(@brown, 30%); diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 559daa608..a3e1fd1d5 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -8,12 +8,11 @@ .container .row .col-md-12 - #headingarea - - if content_for?(:title) - %h1#title - = yield(:title) - - if content_for?(:subtitle) - %small= yield(:subtitle) + - if content_for?(:title) + %h1#title + = yield(:title) + - if content_for?(:subtitle) + %small= yield(:subtitle) - if content_for?(:buttonbar) %p From f468a8b77b9b55a6e5255bab0a2f25376b45c0c8 Mon Sep 17 00:00:00 2001 From: Skud Date: Sun, 19 Oct 2014 14:04:55 +0100 Subject: [PATCH 31/47] Changed all h1 to content_for :title --- app/views/account_types/edit.html.haml | 2 +- app/views/account_types/index.html.haml | 2 +- app/views/account_types/new.html.haml | 2 +- app/views/accounts/edit.html.haml | 2 +- app/views/accounts/index.html.haml | 2 +- app/views/accounts/new.html.haml | 2 +- app/views/authentications/index.html.haml | 2 +- app/views/plant_parts/edit.html.haml | 2 +- app/views/plant_parts/new.html.haml | 2 +- app/views/products/edit.html.haml | 2 +- app/views/products/index.html.haml | 2 +- app/views/products/new.html.haml | 2 +- app/views/roles/edit.html.haml | 2 +- app/views/roles/index.html.haml | 2 +- app/views/roles/new.html.haml | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/views/account_types/edit.html.haml b/app/views/account_types/edit.html.haml index e8d328a21..79f11726d 100644 --- a/app/views/account_types/edit.html.haml +++ b/app/views/account_types/edit.html.haml @@ -1,4 +1,4 @@ -%h1 Editing account_type +-content_for :title, "Editing account type" = render 'form' diff --git a/app/views/account_types/index.html.haml b/app/views/account_types/index.html.haml index a27434af4..5fc8a3f05 100644 --- a/app/views/account_types/index.html.haml +++ b/app/views/account_types/index.html.haml @@ -1,4 +1,4 @@ -%h1 Listing account_types +- content_for :title, "Listing account types" %table %tr diff --git a/app/views/account_types/new.html.haml b/app/views/account_types/new.html.haml index bf85a1baf..92d309715 100644 --- a/app/views/account_types/new.html.haml +++ b/app/views/account_types/new.html.haml @@ -1,4 +1,4 @@ -%h1 New account_type +- content_for :title, "New account type" = render 'form' diff --git a/app/views/accounts/edit.html.haml b/app/views/accounts/edit.html.haml index 5b4039cfa..ef8d08801 100644 --- a/app/views/accounts/edit.html.haml +++ b/app/views/accounts/edit.html.haml @@ -1,4 +1,4 @@ -%h1 Editing account +- content_for :title, "Editing account" = render 'form' diff --git a/app/views/accounts/index.html.haml b/app/views/accounts/index.html.haml index 66345747f..1dfef6438 100644 --- a/app/views/accounts/index.html.haml +++ b/app/views/accounts/index.html.haml @@ -1,4 +1,4 @@ -%h1 Listing accounts +- content_for :title, "Listing accounts" %table %tr diff --git a/app/views/accounts/new.html.haml b/app/views/accounts/new.html.haml index 489317b27..9430cc2ed 100644 --- a/app/views/accounts/new.html.haml +++ b/app/views/accounts/new.html.haml @@ -1,4 +1,4 @@ -%h1 New account +- content_for :title, "New account" = render 'form' diff --git a/app/views/authentications/index.html.haml b/app/views/authentications/index.html.haml index 61cd83250..3bb1607f1 100644 --- a/app/views/authentications/index.html.haml +++ b/app/views/authentications/index.html.haml @@ -1,4 +1,4 @@ -%h1 Linked accounts on other sites +- content_for :title, "Linked accounts on other sites" - if @authentications - unless @authentications.empty? diff --git a/app/views/plant_parts/edit.html.haml b/app/views/plant_parts/edit.html.haml index 6add25fb3..f17252ef8 100644 --- a/app/views/plant_parts/edit.html.haml +++ b/app/views/plant_parts/edit.html.haml @@ -1,4 +1,4 @@ -%h1 Editing plant_part +- content_for :title, "Editing plant part" = render 'form' diff --git a/app/views/plant_parts/new.html.haml b/app/views/plant_parts/new.html.haml index 604c38a04..e0d446dcb 100644 --- a/app/views/plant_parts/new.html.haml +++ b/app/views/plant_parts/new.html.haml @@ -1,4 +1,4 @@ -%h1 New plant_part +- content_for :title, "New plant part" = render 'form' diff --git a/app/views/products/edit.html.haml b/app/views/products/edit.html.haml index 9c16087ea..84ebcb870 100644 --- a/app/views/products/edit.html.haml +++ b/app/views/products/edit.html.haml @@ -1,4 +1,4 @@ -%h1 Editing product +- content_for :title, "Editing product" = render 'form' diff --git a/app/views/products/index.html.haml b/app/views/products/index.html.haml index 61940aaa8..17053aeca 100644 --- a/app/views/products/index.html.haml +++ b/app/views/products/index.html.haml @@ -1,4 +1,4 @@ -%h1 Listing products +- content_for :title, "Listing products" %table %tr diff --git a/app/views/products/new.html.haml b/app/views/products/new.html.haml index 71ed863eb..57b944d9a 100644 --- a/app/views/products/new.html.haml +++ b/app/views/products/new.html.haml @@ -1,4 +1,4 @@ -%h1 New product +- content_for :title, "New product" = render 'form' diff --git a/app/views/roles/edit.html.haml b/app/views/roles/edit.html.haml index 427975d14..83520111b 100644 --- a/app/views/roles/edit.html.haml +++ b/app/views/roles/edit.html.haml @@ -1,4 +1,4 @@ -%h1 Editing role +- content_for :title, "Editing role" = render 'form' diff --git a/app/views/roles/index.html.haml b/app/views/roles/index.html.haml index ae51b2d36..8548645c4 100644 --- a/app/views/roles/index.html.haml +++ b/app/views/roles/index.html.haml @@ -1,4 +1,4 @@ -%h1 Listing roles +- content_for :title, "Listing roles" - if can? :create, Role %p= link_to 'New Role', new_role_path, :class => 'btn btn-primary' diff --git a/app/views/roles/new.html.haml b/app/views/roles/new.html.haml index 6e07588dd..30aae3fe1 100644 --- a/app/views/roles/new.html.haml +++ b/app/views/roles/new.html.haml @@ -1,4 +1,4 @@ -%h1 New role +- content_for :title, "New role" = render 'form' From 496c070efd3d88415a3af9708880366193d5fe02 Mon Sep 17 00:00:00 2001 From: Skud Date: Sun, 19 Oct 2014 14:14:24 +0100 Subject: [PATCH 32/47] Tweaked layout of crop page sidebar --- app/views/crops/_find_seeds.html.haml | 4 +++- app/views/crops/_harvests.html.haml | 8 ++++---- app/views/crops/_plantings.html.haml | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/views/crops/_find_seeds.html.haml b/app/views/crops/_find_seeds.html.haml index db7c5b4b7..9b7797144 100644 --- a/app/views/crops/_find_seeds.html.haml +++ b/app/views/crops/_find_seeds.html.haml @@ -8,7 +8,9 @@ %li = link_to "#{seed.owner} will trade #{seed.tradable_to}.", seed_path(seed) = render :partial => 'members/location', :locals => { :member => seed.owner } + %p + = link_to "View all #{crop.name} seeds", seeds_by_crop_path(crop) - if current_member - = link_to "List your seeds to trade.", new_seed_path() + = link_to "List achiote seeds to trade", new_seed_path(:crop_id => crop.id) - else = render :partial => 'shared/signin_signup', :locals => { :to => 'list your seeds to trade' } diff --git a/app/views/crops/_harvests.html.haml b/app/views/crops/_harvests.html.haml index d10f57d06..bac61e580 100644 --- a/app/views/crops/_harvests.html.haml +++ b/app/views/crops/_harvests.html.haml @@ -11,11 +11,11 @@ %small = distance_of_time_in_words(harvest.created_at, Time.zone.now) ago. - %p.col-md-offset-1 - = link_to "See all #{crop.name} harvests", harvests_by_crop_path(crop) + %p + = link_to "View all #{crop.name} harvests", harvests_by_crop_path(crop) - if current_member - %p.col-md-offset-1 - = link_to "Track your #{crop.name} harvests.", new_harvest_path(:crop_id => crop.id) + %p + = link_to "Harvest #{crop.name}", new_harvest_path(:crop_id => crop.id) - else = render :partial => 'shared/signin_signup', :locals => { :to => "track your #{crop.name} harvests" } diff --git a/app/views/crops/_plantings.html.haml b/app/views/crops/_plantings.html.haml index 72bce5608..85a2ff88a 100644 --- a/app/views/crops/_plantings.html.haml +++ b/app/views/crops/_plantings.html.haml @@ -11,11 +11,11 @@ %small = distance_of_time_in_words(planting.created_at, Time.zone.now) ago. - %p.col-md-offset-1 - = link_to "See all #{crop.name} plantings", plantings_by_crop_path(crop) + %p + = link_to "View all #{crop.name} plantings", plantings_by_crop_path(crop) - if current_member - %p.col-md-offset-1 - = link_to "Track your #{crop.name} plantings.", new_planting_path(:crop_id => crop.id) + %p + = link_to "Plant #{crop.name}", new_planting_path(:crop_id => crop.id) - else = render :partial => 'shared/signin_signup', :locals => { :to => "track your #{crop.name} plantings" } From dc1afb8913903760aada7f90a7f153222bac4c3e Mon Sep 17 00:00:00 2001 From: Skud Date: Sun, 19 Oct 2014 14:25:47 +0100 Subject: [PATCH 33/47] Added seeds_by_crop_path routes and stuff --- app/controllers/plantings_controller.rb | 6 +++--- app/controllers/seeds_controller.rb | 3 +++ app/views/harvests/index.html.haml | 4 ++-- app/views/seeds/index.html.haml | 6 +++--- config/routes.rb | 1 + spec/controllers/member_controller_spec.rb | 8 ++++---- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index 62eaf5b79..b08fe98fd 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -9,11 +9,11 @@ class PlantingsController < ApplicationController @owner = Member.find_by_slug(params[:owner]) @crop = Crop.find_by_slug(params[:crop]) if @owner - @plantings = @owner.plantings.includes(:owner, :crop, :garden) + @plantings = @owner.plantings.includes(:owner, :crop, :garden).paginate(:page => params[:page]) elsif @crop - @plantings = @crop.plantings.includes(:owner, :crop, :garden) + @plantings = @crop.plantings.includes(:owner, :crop, :garden).paginate(:page => params[:page]) else - @plantings = Planting.includes(:owner, :crop, :garden) + @plantings = Planting.includes(:owner, :crop, :garden).paginate(:page => params[:page]) end respond_to do |format| diff --git a/app/controllers/seeds_controller.rb b/app/controllers/seeds_controller.rb index 30918b12e..03960624b 100644 --- a/app/controllers/seeds_controller.rb +++ b/app/controllers/seeds_controller.rb @@ -7,8 +7,11 @@ class SeedsController < ApplicationController # GET /seeds.json def index @owner = Member.find_by_slug(params[:owner]) + @crop = Crop.find_by_slug(params[:crop]) if @owner @seeds = @owner.seeds.includes(:owner, :crop).paginate(:page => params[:page]) + elsif @crop + @seeds = @crop.seeds.includes(:owner, :crop).paginate(:page => params[:page]) else @seeds = Seed.includes(:owner, :crop).paginate(:page => params[:page]) end diff --git a/app/views/harvests/index.html.haml b/app/views/harvests/index.html.haml index f80ce0dd5..f50129c9a 100644 --- a/app/views/harvests/index.html.haml +++ b/app/views/harvests/index.html.haml @@ -10,11 +10,11 @@ %p - if @owner == current_member = link_to 'Add harvest', new_harvest_path, :class => 'btn btn-primary' - = link_to "View everyone's harvests", harvests_path, :class => 'btn' + = link_to "View everyone's harvests", harvests_path, :class => 'btn btn-default' - else # everyone's harvests = link_to 'Add harvest', new_harvest_path, :class => 'btn btn-primary' - if current_member - = link_to 'View your harvests', harvests_by_owner_path(:owner => current_member.slug), :class => 'btn' + = link_to 'View your harvests', harvests_by_owner_path(:owner => current_member.slug), :class => 'btn btn-default' - else = render :partial => 'shared/signin_signup', :locals => { :to => 'track your harvests' } diff --git a/app/views/seeds/index.html.haml b/app/views/seeds/index.html.haml index faee35465..9993e83ec 100644 --- a/app/views/seeds/index.html.haml +++ b/app/views/seeds/index.html.haml @@ -1,4 +1,4 @@ -- content_for :title, @owner ? "#{@owner}'s seeds" : "Everyone's seeds" +- content_for :title, @owner ? "#{@owner}'s seeds" : @crop ? "Everyone's #{@crop.name} seeds" : "Everyone's seeds" %p #{ENV['GROWSTUFF_SITE_NAME']} helps you track your seed @@ -10,11 +10,11 @@ %p - if @owner == current_member = link_to 'Add seeds', new_seed_path, :class => 'btn btn-primary' - = link_to "View everyone's seeds", seeds_path, :class => 'btn' + = link_to "View everyone's seeds", seeds_path, :class => 'btn btn-default' - else # everyone's seeds = link_to 'Add seeds', new_seed_path, :class => 'btn btn-primary' - if current_member - = link_to 'View your seeds', seeds_by_owner_path(:owner => current_member.slug), :class => 'btn' + = link_to 'View your seeds', seeds_by_owner_path(:owner => current_member.slug), :class => 'btn btn-default' - else = render :partial => 'shared/signin_signup', :locals => { :to => 'add seeds to your stash' } diff --git a/config/routes.rb b/config/routes.rb index 0d645a1be..bdef427d4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,7 @@ Growstuff::Application.routes.draw do resources :seeds match '/seeds/owner/:owner' => 'seeds#index', :as => 'seeds_by_owner' + match '/seeds/crop/:crop' => 'seeds#index', :as => 'seeds_by_crop' resources :harvests match '/harvests/owner/:owner' => 'harvests#index', :as => 'harvests_by_owner' diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 906a12b82..ff5a0ae42 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -17,17 +17,17 @@ describe MembersController do end describe "GET JSON index" do - it "does NOT provide JSON for members" do + it "provides JSON for members" do get :index, :format => 'json' - response.should_not be_success + response.should be_success end end describe "GET show" do - it "does NOT provide JSON for member profile" do + it "provides JSON for member profile" do get :show, { :id => @member.id , :format => 'json' } - response.should_not be_success + response.should be_success end it "assigns @posts with the member's posts" do From 1daee9612c9d1f00d0eccf918c125164c7e2c30f Mon Sep 17 00:00:00 2001 From: emmawinston Date: Sun, 19 Oct 2014 14:52:10 +0100 Subject: [PATCH 34/47] Changed set to album on photo page --- app/views/photos/new.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/photos/new.html.haml b/app/views/photos/new.html.haml index bc3eb35df..7b89997be 100644 --- a/app/views/photos/new.html.haml +++ b/app/views/photos/new.html.haml @@ -13,7 +13,7 @@ - if @sets and @sets.length > 0 %p = form_tag(new_photo_path, :method => :get, :class => 'form-inline') do - = label_tag :set, "Choose a photo set:", :class => 'control-label' + = label_tag :set, "Choose a photo album:", :class => 'control-label' = select_tag :set, options_for_select(@sets, @current_set), :class => 'input-large' = hidden_field_tag :type, @type = hidden_field_tag :id, @id @@ -36,4 +36,3 @@ You must =link_to "connect your account to Flickr", '/auth/flickr' to add photos. - From e5cd14cd4539a884e2d862f66baff7e2eb51b315 Mon Sep 17 00:00:00 2001 From: emmawinston Date: Sun, 19 Oct 2014 14:56:44 +0100 Subject: [PATCH 35/47] Added myself to the contributors file --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index cdec8a25a..650f8c321 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -47,3 +47,4 @@ submit the change with your pull request. - Cheri Allen / [cherimarie](https://github.com/cherimarie) - Maki Sugita / [macckii](https:://github.com/macckii) - Shiho Takagi / [oshiho3](https://github.com/oshiho3) +- Emma Winston / [emmawinston](https://github.com/emmawinston) From ef8d55230157516674d1f34592b1be7f66616c19 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 15:06:34 +0100 Subject: [PATCH 36/47] Update Ruby to 2.1.2 in .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f65de9cb5..7ed73fce0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ language: ruby env: GROWSTUFF_SITE_NAME="Growstuff (travis)" RAILS_SECRET_TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' bundler_args: --without development production staging rvm: - - 2.1.1 + - 2.1.2 before_script: - psql -c 'create database growstuff_test;' -U postgres script: From 2aabcce70d9cfcb734410ebd8783308ead4959f6 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 12:13:17 +0100 Subject: [PATCH 37/47] Feature tests for scientific names. --- spec/features/scientific_name_spec.rb | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 spec/features/scientific_name_spec.rb diff --git a/spec/features/scientific_name_spec.rb b/spec/features/scientific_name_spec.rb new file mode 100644 index 000000000..5a3a82989 --- /dev/null +++ b/spec/features/scientific_name_spec.rb @@ -0,0 +1,66 @@ +require 'spec_helper' + +feature "Scientific names" do + let!(:zea_mays) { FactoryGirl.create(:zea_mays) } + let(:crop) { zea_mays.crop } + + scenario "Display scientific names on crop page" do + visit crop_path(zea_mays.crop) + expect(page).to have_content zea_mays.scientific_name + end + + scenario "Index page for scientific names" do + visit scientific_names_path + expect(page).to have_content zea_mays.scientific_name + end + + context "User is a crop wrangler" do + let!(:crop_wranglers) { FactoryGirl.create_list(:crop_wrangling_member, 3) } + let(:member){crop_wranglers.first} + + before :each do + login_as(member) + end + + scenario "Crop wranglers can edit scientific names" do + visit crop_path(crop) + expect(page).to have_content "CROP WRANGLER" + expect(page).to have_content zea_mays.scientific_name + expect(page).to have_link "Edit", :href => edit_scientific_name_path(zea_mays) + within('.scientific_names') { click_on "Edit" } + expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" + fill_in 'Scientific name', with: "Zea mirabila" + click_on "Save" + expect(page).to have_content "Zea mirabila" + expect(page).to have_content 'Scientific name was successfully updated' + end + + scenario "Crop wranglers can delete scientific names" do + visit crop_path(zea_mays.crop) + expect(page).to have_link "Delete", + href: scientific_name_path(zea_mays) + within('.scientific_names') { click_on "Delete" } + expect(page).to_not have_content zea_mays.scientific_name + expect(page).to have_content 'Scientific name was successfully deleted' + end + + scenario "Crop wranglers can add scientific names" do + visit crop_path(crop) + expect(page).to have_link "Add", + href: new_scientific_name_path(crop_id: crop.id) + within('.scientific_names') { click_on "Add" } + expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" + fill_in 'Scientific name', with: "Zea mirabila" + click_on "Save" + expect(page).to have_content "Zea mirabila" + expect(page).to have_content 'Scientific name was successfully created' + end + + scenario "The show-scientific-name page works" do + visit scientific_name_path(zea_mays) + expect(page).to have_content zea_mays.crop.name + end + + end + +end From 6de2112c4d042e95d0555d9b0ac8018ac6606cb2 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 12:16:05 +0100 Subject: [PATCH 38/47] Display note on successful sciname deletion. --- app/controllers/scientific_names_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/scientific_names_controller.rb b/app/controllers/scientific_names_controller.rb index 202c3942c..3911a6618 100644 --- a/app/controllers/scientific_names_controller.rb +++ b/app/controllers/scientific_names_controller.rb @@ -83,7 +83,9 @@ class ScientificNamesController < ApplicationController @scientific_name.destroy respond_to do |format| - format.html { redirect_to @crop } + format.html { + redirect_to @crop, notice: 'Scientific name was successfully deleted.' + } format.json { head :no_content } end end From 56b7d89d9ea709033ae5d74eba182a0c694240bb Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 12:19:55 +0100 Subject: [PATCH 39/47] Link scinames to crops, don't show numeric crop IDs --- app/views/scientific_names/show.html.haml | 2 +- spec/features/scientific_name_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/scientific_names/show.html.haml b/app/views/scientific_names/show.html.haml index 23e3a3c47..a3efe2d6f 100644 --- a/app/views/scientific_names/show.html.haml +++ b/app/views/scientific_names/show.html.haml @@ -5,7 +5,7 @@ = @scientific_name.scientific_name %p %b Crop: - = @scientific_name.crop_id + = link_to @scientific_name.crop, @scientific_name.crop = link_to 'Edit', edit_scientific_name_path(@scientific_name), :class => 'btn btn-default btn-xs' \| diff --git a/spec/features/scientific_name_spec.rb b/spec/features/scientific_name_spec.rb index 5a3a82989..01093a9c2 100644 --- a/spec/features/scientific_name_spec.rb +++ b/spec/features/scientific_name_spec.rb @@ -58,7 +58,8 @@ feature "Scientific names" do scenario "The show-scientific-name page works" do visit scientific_name_path(zea_mays) - expect(page).to have_content zea_mays.crop.name + expect(page).to have_link zea_mays.crop.name, + href: crop_path(zea_mays.crop) end end From b17aaf262dc04b916e46269d32362ba4ac74683a Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 19 Oct 2014 12:25:41 +0100 Subject: [PATCH 40/47] Test HTTP statuses in sciname feature tests This makes it easier to tell the difference between "test failed because the expected content isn't there" and "test failed because the whole page is broken". It also guards against "test passed incorrectly because the expected content was part of the error message". --- spec/features/scientific_name_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/features/scientific_name_spec.rb b/spec/features/scientific_name_spec.rb index 01093a9c2..1fda79d42 100644 --- a/spec/features/scientific_name_spec.rb +++ b/spec/features/scientific_name_spec.rb @@ -6,11 +6,13 @@ feature "Scientific names" do scenario "Display scientific names on crop page" do visit crop_path(zea_mays.crop) + expect(page.status_code).to equal 200 expect(page).to have_content zea_mays.scientific_name end scenario "Index page for scientific names" do visit scientific_names_path + expect(page.status_code).to equal 200 expect(page).to have_content zea_mays.scientific_name end @@ -24,10 +26,12 @@ feature "Scientific names" do scenario "Crop wranglers can edit scientific names" do visit crop_path(crop) + expect(page.status_code).to equal 200 expect(page).to have_content "CROP WRANGLER" expect(page).to have_content zea_mays.scientific_name expect(page).to have_link "Edit", :href => edit_scientific_name_path(zea_mays) within('.scientific_names') { click_on "Edit" } + expect(page.status_code).to equal 200 expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" fill_in 'Scientific name', with: "Zea mirabila" click_on "Save" @@ -40,6 +44,7 @@ feature "Scientific names" do expect(page).to have_link "Delete", href: scientific_name_path(zea_mays) within('.scientific_names') { click_on "Delete" } + expect(page.status_code).to equal 200 expect(page).to_not have_content zea_mays.scientific_name expect(page).to have_content 'Scientific name was successfully deleted' end @@ -49,15 +54,18 @@ feature "Scientific names" do expect(page).to have_link "Add", href: new_scientific_name_path(crop_id: crop.id) within('.scientific_names') { click_on "Add" } + expect(page.status_code).to equal 200 expect(page).to have_css "option[value='#{crop.id}'][selected=selected]" fill_in 'Scientific name', with: "Zea mirabila" click_on "Save" + expect(page.status_code).to equal 200 expect(page).to have_content "Zea mirabila" expect(page).to have_content 'Scientific name was successfully created' end scenario "The show-scientific-name page works" do visit scientific_name_path(zea_mays) + expect(page.status_code).to equal 200 expect(page).to have_link zea_mays.crop.name, href: crop_path(zea_mays.crop) end From 58f1bca68362148bf15abec10c6a1b6062b5c198 Mon Sep 17 00:00:00 2001 From: Skud Date: Sun, 19 Oct 2014 16:51:08 +0100 Subject: [PATCH 41/47] removed spurious console.log calls --- app/assets/javascripts/members.js.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/assets/javascripts/members.js.erb b/app/assets/javascripts/members.js.erb index a3f29904d..f55f35732 100644 --- a/app/assets/javascripts/members.js.erb +++ b/app/assets/javascripts/members.js.erb @@ -6,7 +6,6 @@ if (document.getElementById("membermap") !== null) { $.getJSON(location.pathname + '.json', function(member) { - console.log(JSON.stringify(member.latitude)); if (member.latitude && member.longitude) { membermap = L.map('membermap').setView([member.latitude, member.longitude], 4); @@ -14,7 +13,6 @@ if (document.getElementById("membermap") !== null) { attribution: 'Map data © OpenStreetMap contributors under ODbL | Map imagery © Mapbox', maxZoom: 18 }).addTo(membermap); - console.log("found lat and long") marker = new L.Marker(new L.LatLng(member.latitude, member.longitude)); member_url = "/members/" + member.slug; From a25eb2d631ef1a8319237580f0c8bf4879e180de Mon Sep 17 00:00:00 2001 From: Skud Date: Sun, 19 Oct 2014 16:52:45 +0100 Subject: [PATCH 42/47] Deleted old view tests for crops --- spec/views/crops/show.html.haml_spec.rb | 242 ------------------------ 1 file changed, 242 deletions(-) delete mode 100644 spec/views/crops/show.html.haml_spec.rb diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb deleted file mode 100644 index ca6166721..000000000 --- a/spec/views/crops/show.html.haml_spec.rb +++ /dev/null @@ -1,242 +0,0 @@ -require 'spec_helper' - -describe "crops/show" do - before(:each) do - controller.stub(:current_user) { nil } - @crop = FactoryGirl.create(:maize, - :scientific_names => [ FactoryGirl.create(:zea_mays) ] - ) - assign(:crop, @crop) - @author = FactoryGirl.create(:member) - page = 1 - per_page = 2 - total_entries = 2 - @posts = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| - pager.replace([ - @post1 = FactoryGirl.create(:post, :author => @author, :body => "Post it!" ), - @post2 = FactoryGirl.create(:post, :author => @author, :body => "Done!" ) - ]) - end - end - - context 'photos' do - before(:each) do - @planting = FactoryGirl.create(:planting, :crop => @crop) - @photo1 = FactoryGirl.create(:photo) - @photo2 = FactoryGirl.create(:photo) - @photo3 = FactoryGirl.create(:photo) - @planting.photos << [@photo1, @photo2, @photo3] - render - end - - it 'shows 3 photos across the top of the page' do - assert_select "div.thumbnail>a>img", :count => 3 - end - - it 'links to the photo detail page' do - assert_select "a[href=#{photo_path(@photo1)}]" - end - - it 'links to the photo owner' do - assert_select "a[href=#{member_path(@photo1.owner)}]" - end - end - - context "map" do - it "has a map" do - render - assert_select("div#cropmap") - end - - it "explains what's shown on the map" do - render - rendered.should contain "Only plantings by members who have set their locations are shown on this map" - end - - it "shows a 'set your location' link to people who need to" do - @nowhere = FactoryGirl.create(:member) - sign_in @nowhere - controller.stub(:current_user) { @nowhere } - render - rendered.should contain "Set your location" - end - - it "doesn't show 'set your location' to people who have one" do - @somewhere = FactoryGirl.create(:london_member) - sign_in @somewhere - controller.stub(:current_user) { @somewhere } - render - rendered.should_not contain "Set your location" - end - - end - - it "shows the wikipedia URL" do - render - assert_select("a[href=#{@crop.en_wikipedia_url}]", 'Wikipedia (English)') - end - - it "shows the scientific name" do - render - rendered.should contain "Scientific names" - rendered.should contain "Zea mays" - end - - context "seeds available for trade" do - before(:each) do - @owner1 = FactoryGirl.create(:london_member) - @owner2 = FactoryGirl.create(:member) # no location - @seed1 = FactoryGirl.create(:tradable_seed, :owner => @owner1, :crop => @crop) - @seed2 = FactoryGirl.create(:tradable_seed, :owner => @owner2, :crop => @crop) - render - end - - it "shows a heading" do - rendered.should contain "Find seeds" - end - - it "shows a list of people with seeds to trade" do - @crop.seeds.each do |seed| - assert_select "a[href=#{seed_path(seed)}]" - end - end - end - - context "harvests" do - before(:each) do - @owner1 = FactoryGirl.create(:london_member) - @h1 = FactoryGirl.create(:harvest, :owner => @owner1, :crop => @crop) - @h2 = FactoryGirl.create(:harvest, :owner => @owner1, :crop => @crop) - render - end - - it "shows a heading" do - rendered.should contain "Harvests" - end - - it "shows a list of people who have harvested this crop" do - @crop.harvests.each do |harvest| - assert_select "a[href=#{harvest_path(harvest)}]" - end - end - end - - context "no seeds available for trade" do - it "shows a heading" do - render - rendered.should contain "Find seeds" - end - - it "suggests you trade seeds" do - render - rendered.should contain "There are no seeds available to trade." - end - end - - context "has plantings" do - before(:each) do - @owner = FactoryGirl.create(:london_member) - @planting = FactoryGirl.create(:planting, - :crop => @crop, - :owner => @owner - ) - @crop.reload # to pick up latest plantings_count - end - - it "links to people who are growing this crop" do - render - rendered.should contain @owner.login_name - rendered.should contain @owner.location - end - end - - context "has posts" do - it "links to posts" do - render - @posts.each do |p| - rendered.should contain p.author.login_name - rendered.should contain p.subject - rendered.should contain p.body - end - end - - it "contains two gravatar icons" do - render - assert_select "img", :src => /gravatar\.com\/avatar/, :count => 2 - end - end - - context 'varieties' do - before(:each) do - @popcorn = FactoryGirl.create(:popcorn, :parent_id => @crop.id) - @ubercrop = FactoryGirl.create(:crop, :name => 'ubercrop') - @crop.parent_id = @ubercrop.id - @crop.save - render - end - - it 'shows popcorn as a child variety' do - rendered.should contain @popcorn.name - end - - it 'shows parent crop' do - rendered.should contain @ubercrop.name - end - - end - - context 'logged in' do - before(:each) do - @member = FactoryGirl.create(:member) - sign_in @member - controller.stub(:current_user) { @member } - render - end - - it { rendered.should contain "Nobody has planted this crop yet" } - it { rendered.should contain "Nobody has harvested this crop yet" } - - context "should have a link to" do - before do - FactoryGirl.create(:planting, :crop => @crop) - FactoryGirl.create(:harvest, :crop => @crop) - @crop.reload - render - end - - it "show all plantings by the crop link" do - assert_select("a[href=#{plantings_by_crop_path @crop}]") - end - - it "show all harvests by the crop link" do - assert_select("a[href=#{harvests_by_crop_path @crop}]") - end - end - - - - end - - context "logged in and crop wrangler" do - - before(:each) do - @member = FactoryGirl.create(:crop_wrangling_member) - sign_in @member - controller.stub(:current_user) { @member } - render - end - - it "links to the edit crop form" do - assert_select "a[href=#{edit_crop_path(@crop)}]", :text => "Edit crop" - end - - it "links to the add scientific name form" do - assert_select "a[href^=#{new_scientific_name_path}]", :text => "Add" - end - - it "links to the edit scientific name form" do - assert_select "a[href=#{edit_scientific_name_path(@crop.scientific_names.first)}]", :text => "Edit" - end - end - -end From ab449a65f8ca261abc6b16d10986d4939eddec93 Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Mon, 20 Oct 2014 21:27:39 +1100 Subject: [PATCH 43/47] remove 'to be translated' message from ja locale file --- config/locales/ja.yml | 75 +------------------------------------------ 1 file changed, 1 insertion(+), 74 deletions(-) diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 1f2fe3247..925a54399 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -2,77 +2,4 @@ ja: home: blurb: intro: "%{site_name}はガーデナーのコミュニティです。" - perks: "翻訳中" - sign_up: "翻訳中" - already_html: "翻訳中" - sign_in_linktext: "翻訳中" - - crops: - our_crops: "翻訳中" - recently_planted: "翻訳中" - recently_added: "翻訳中" - view_all: "翻訳中" - - discuss: - discussion: "翻訳中" - forums: "翻訳中" - view_all: "翻訳中" - - keep_in_touch: - keep_in_touch: "翻訳中" - twitter_html: "翻訳中" - twitter_linktext: "翻訳中" - blog_html: "翻訳中" - blog_linktext: "翻訳中" - newsletter_html: "翻訳中" - newsletter_linktext: "翻訳中" - - members: - title: "翻訳中" - view_all: "翻訳中" - - open: - open_source_title: "翻訳中" - open_source_body_html: "翻訳中" - why_linktext: "翻訳中" - github_linktext: "翻訳中" - open_data_title: "翻訳中" - open_data_body_html: "翻訳中" - creative_commons_linktext: "翻訳中" - wiki_linktext: "翻訳中" - api_docs_linktext: "翻訳中" - get_involved_title: "翻訳中" - get_involved_body_html: "翻訳中" - talk_linktext: "翻訳中" - wiki_linktext: "翻訳中" - support_title: "翻訳中" - support_body_html: "翻訳中" - ad_free_linktext: "翻訳中" - - - seeds: - title: "翻訳中" - owner: "翻訳中" - crop: "翻訳中" - description: "翻訳中" - trade_to: "翻訳中" - from: "翻訳中" - unspecified: "翻訳中" - details: "翻訳中" - view_all: "翻訳中" - - stats: - message_html: "翻訳中" - member_linktext: "翻訳中" - number_crops_linktext: "翻訳中" - number_plantings_linktext: "翻訳中" - number_gardens_linktext: "翻訳中" - - index: - welcome: "翻訳中" - plant: "翻訳中" - harvest: "翻訳中" - add_seeds: "翻訳中" - post: "翻訳中" - edit_profile: "翻訳中" - + \ No newline at end of file From c244da8b73c98945d49340ede84946bfbcbf291b Mon Sep 17 00:00:00 2001 From: Taylor Griffin Date: Tue, 21 Oct 2014 07:24:08 +1100 Subject: [PATCH 44/47] make English fallback language --- Gemfile | 3 --- Gemfile.lock | 8 -------- config/application.rb | 8 ++++++-- config/initializers/locale.rb | 4 ---- 4 files changed, 6 insertions(+), 17 deletions(-) delete mode 100644 config/initializers/locale.rb diff --git a/Gemfile b/Gemfile index 2360041eb..124c1f4f9 100644 --- a/Gemfile +++ b/Gemfile @@ -80,9 +80,6 @@ gem 'flickraw' # To use debugger group :development do - # Installation of the debugger gem fails on Travis CI, - # so we don't use it in the test environment - gem 'debugger' # A debugger and irb alternative. Pry doesn't play nice # with unicorn, so start a Webrick server when debugging # with Pry diff --git a/Gemfile.lock b/Gemfile.lock index fae16d6ad..6f6b7d1a5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,7 +77,6 @@ GEM coffee-script-source execjs coffee-script-source (1.8.0) - columnize (0.8.9) commonjs (0.2.7) compass (0.12.7) chunky_png (~> 1.2) @@ -96,12 +95,6 @@ GEM dalli (2.7.2) database_cleaner (1.3.0) debug_inspector (0.0.2) - debugger (1.6.8) - columnize (>= 0.3.1) - debugger-linecache (~> 1.2.0) - debugger-ruby_core_source (~> 1.3.5) - debugger-linecache (1.2.0) - debugger-ruby_core_source (1.3.5) devise (3.2.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -336,7 +329,6 @@ DEPENDENCIES csv_shaper dalli database_cleaner (~> 1.3.0) - debugger devise (~> 3.2.0) factory_girl_rails (~> 4.0) figaro diff --git a/config/application.rb b/config/application.rb index 6bbe1fe7d..5b01d3aa8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -31,8 +31,12 @@ module Growstuff config.active_record.default_timezone = :local # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de + I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')] + I18n.default_locale = :en + # rails will fallback to config.i18n.default_locale translation + config.i18n.fallbacks = true + # rails will fallback to en, no matter what is set as config.i18n.default_locale + config.i18n.fallbacks = [:en] # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb deleted file mode 100644 index fb251b800..000000000 --- a/config/initializers/locale.rb +++ /dev/null @@ -1,4 +0,0 @@ -I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')] -I18n.default_locale = :en - - \ No newline at end of file From 6921119301a71389c6d5cbfcd5e847e440a0f449 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 2 Nov 2014 22:21:32 +0000 Subject: [PATCH 45/47] Make Capybara actually hit the server. Background: http://talk.growstuff.org/t/mysteriously-broken-feature-tests/120 @oshiho3's suggested fix didn't work, so I tried all the suggestions at http://stackoverflow.com/questions/6536503/capybara-with-subdomains-default-host until I found one that fixed the problem. --- config/environments/test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/environments/test.rb b/config/environments/test.rb index 6f49b5ef0..6fb8cad3e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -86,3 +86,7 @@ Geocoder::Lookup::Test.add_stub( # Unknown location Geocoder::Lookup::Test.add_stub( "Tatooine", []) + +Capybara.configure do |config| + config.always_include_port = true +end From b9891688878e12746b8d62fa17219854f373a213 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Sun, 2 Nov 2014 22:47:14 +0000 Subject: [PATCH 46/47] Fix "shared example group previously defined" warning We were getting the warning ``` WARNING: Shared example group 'crop suggest' has been previously defined at: /Users/miles/src/growstuff/spec/features/shared_examples/crop_suggest_spec.rb:3 ...and you are now defining it at: /Users/miles/src/growstuff/spec/features/shared_examples/crop_suggest_spec.rb:3 The new definition will overwrite the original one. ``` Following the suggestion at https://github.com/rspec/rspec-core/issues/828#issuecomment-38789977, I've renamed crop_suggest_spec.rb to crop_suggest.rb, which made the error go away without reducing the number of tests run. RSpec must have thought it was a spec file and loaded it directly, then loaded it again when it was first required by an actual spec file. --- .../shared_examples/{crop_suggest_spec.rb => crop_suggest.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/features/shared_examples/{crop_suggest_spec.rb => crop_suggest.rb} (100%) diff --git a/spec/features/shared_examples/crop_suggest_spec.rb b/spec/features/shared_examples/crop_suggest.rb similarity index 100% rename from spec/features/shared_examples/crop_suggest_spec.rb rename to spec/features/shared_examples/crop_suggest.rb From 2426c51951f0148a287fa41019623ef78b85cfb6 Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 11 Nov 2014 19:29:32 +1100 Subject: [PATCH 47/47] Fixed bug in deleting unused photos ... and wow, my tests were really not testing what I thought they were testing :-/ --- app/models/photo.rb | 2 +- spec/models/photo_spec.rb | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index 32679eeed..862b9d28b 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -14,7 +14,7 @@ class Photo < ActiveRecord::Base # remove photos that aren't used by anything def destroy_if_unused - unless plantings.size > 0 and harvests.size > 0 + unless plantings.size > 0 or harvests.size > 0 self.destroy end end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 2a0b1d5ff..f17127301 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -39,16 +39,20 @@ describe Photo do expect(lambda { photo.reload }).to raise_error ActiveRecord::RecordNotFound end - it 'they are no longer used by plantings' do + it 'they are used by plantings but not harvests' do + harvest.photos << photo planting.photos << photo - planting.destroy # photo is now no longer used by anything - expect(lambda { photo.reload }).to raise_error ActiveRecord::RecordNotFound + harvest.destroy # photo is now used by harvest but not planting + photo.destroy_if_unused + expect(lambda { photo.reload }).not_to raise_error ActiveRecord::RecordNotFound end - it 'they are no longer used by harvests' do + it 'they are used by harvests but not plantings' do harvest.photos << photo - harvest.destroy # photo is now no longer used by anything - expect(lambda { photo.reload }).to raise_error ActiveRecord::RecordNotFound + planting.photos << photo + planting.destroy # photo is now used by harvest but not planting + photo.destroy_if_unused + expect(lambda { photo.reload }).not_to raise_error ActiveRecord::RecordNotFound end it 'they are no longer used by anything' do @@ -59,11 +63,14 @@ describe Photo do planting.destroy # photo is still used by harvest photo.reload - expect(photo).to be_an_instance_of Photo expect(photo.plantings.size).to eq 0 expect(photo.harvests.size).to eq 1 harvest.destroy # photo is now no longer used by anything + photo.reload + expect(photo.plantings.size).to eq 0 + expect(photo.harvests.size).to eq 0 + photo.destroy_if_unused expect(lambda { photo.reload }).to raise_error ActiveRecord::RecordNotFound end