From 45ba5ff48a632e6e9d02e27bdbabd872f5e58265 Mon Sep 17 00:00:00 2001 From: Brandon Baker Date: Thu, 29 Nov 2018 10:54:04 -0700 Subject: [PATCH 001/124] creates containers, plots, and associations among gardens, plots, and containers --- app/controllers/containers_controller.rb | 58 +++++++++++++++++++ app/models/container.rb | 7 +++ app/models/garden.rb | 3 + app/models/plot.rb | 4 ++ app/views/containers/_form.html.haml | 13 +++++ app/views/containers/edit.html.haml | 7 +++ app/views/containers/index.html.haml | 21 +++++++ app/views/containers/new.html.haml | 5 ++ app/views/containers/show.html.haml | 9 +++ config/routes.rb | 1 + .../20181129171803_create_containers.rb | 9 +++ db/migrate/20181129171857_create_plots.rb | 10 ++++ db/schema.rb | 17 +++++- spec/factories/containers.rb | 5 ++ spec/factories/plots.rb | 6 ++ spec/models/container_spec.rb | 5 ++ spec/models/plot_spec.rb | 5 ++ spec/requests/containers_spec.rb | 10 ++++ spec/routing/containers_routing_spec.rb | 38 ++++++++++++ 19 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 app/controllers/containers_controller.rb create mode 100644 app/models/container.rb create mode 100644 app/models/plot.rb create mode 100644 app/views/containers/_form.html.haml create mode 100644 app/views/containers/edit.html.haml create mode 100644 app/views/containers/index.html.haml create mode 100644 app/views/containers/new.html.haml create mode 100644 app/views/containers/show.html.haml create mode 100644 db/migrate/20181129171803_create_containers.rb create mode 100644 db/migrate/20181129171857_create_plots.rb create mode 100644 spec/factories/containers.rb create mode 100644 spec/factories/plots.rb create mode 100644 spec/models/container_spec.rb create mode 100644 spec/models/plot_spec.rb create mode 100644 spec/requests/containers_spec.rb create mode 100644 spec/routing/containers_routing_spec.rb diff --git a/app/controllers/containers_controller.rb b/app/controllers/containers_controller.rb new file mode 100644 index 000000000..3e5506db7 --- /dev/null +++ b/app/controllers/containers_controller.rb @@ -0,0 +1,58 @@ +class ContainersController < ApplicationController + before_action :set_container, only: [:show, :edit, :update, :destroy] + + # GET /containers + def index + @containers = Container.all + end + + # GET /containers/1 + def show + end + + # GET /containers/new + def new + @container = Container.new + end + + # GET /containers/1/edit + def edit + end + + # POST /containers + def create + @container = Container.new(container_params) + + if @container.save + redirect_to @container, notice: 'Container was successfully created.' + else + render :new + end + end + + # PATCH/PUT /containers/1 + def update + if @container.update(container_params) + redirect_to @container, notice: 'Container was successfully updated.' + else + render :edit + end + end + + # DELETE /containers/1 + def destroy + @container.destroy + redirect_to containers_url, notice: 'Container was successfully destroyed.' + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_container + @container = Container.find(params[:id]) + end + + # Only allow a trusted parameter "white list" through. + def container_params + params.require(:container).permit(:description) + end +end diff --git a/app/models/container.rb b/app/models/container.rb new file mode 100644 index 000000000..2743cf9a9 --- /dev/null +++ b/app/models/container.rb @@ -0,0 +1,7 @@ +class Container < ActiveRecord::Base + + has_many :plots, dependent: :destroy + has_many :gardens, through: :plots + + validates :description, presence: true, uniqueness: true +end diff --git a/app/models/garden.rb b/app/models/garden.rb index 682796674..16458d046 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -8,6 +8,9 @@ class Garden < ActiveRecord::Base has_many :plantings, dependent: :destroy has_many :crops, through: :plantings + has_many :plots, dependent: :destroy + has_many :containers, through: :plots + # set up geocoding geocoded_by :location after_validation :geocode diff --git a/app/models/plot.rb b/app/models/plot.rb new file mode 100644 index 000000000..779f7e9eb --- /dev/null +++ b/app/models/plot.rb @@ -0,0 +1,4 @@ +class Plot < ActiveRecord::Base + belongs_to :garden + belongs_to :container +end diff --git a/app/views/containers/_form.html.haml b/app/views/containers/_form.html.haml new file mode 100644 index 000000000..25dff9445 --- /dev/null +++ b/app/views/containers/_form.html.haml @@ -0,0 +1,13 @@ += form_for @container do |f| + - if @container.errors.any? + #error_explanation + %h2= "#{pluralize(@container.errors.count, "error")} prohibited this container from being saved:" + %ul + - @container.errors.full_messages.each do |message| + %li= message + + .field + = f.label :description + = f.text_field :description + .actions + = f.submit 'Save' diff --git a/app/views/containers/edit.html.haml b/app/views/containers/edit.html.haml new file mode 100644 index 000000000..a1ba22545 --- /dev/null +++ b/app/views/containers/edit.html.haml @@ -0,0 +1,7 @@ +%h1 Editing container + += render 'form' + += link_to 'Show', @container +\| += link_to 'Back', containers_path diff --git a/app/views/containers/index.html.haml b/app/views/containers/index.html.haml new file mode 100644 index 000000000..d2e2fda34 --- /dev/null +++ b/app/views/containers/index.html.haml @@ -0,0 +1,21 @@ +%h1 Listing containers + +%table + %thead + %tr + %th Description + %th + %th + %th + + %tbody + - @containers.each do |container| + %tr + %td= container.description + %td= link_to 'Show', container + %td= link_to 'Edit', edit_container_path(container) + %td= link_to 'Destroy', container, method: :delete, data: { confirm: 'Are you sure?' } + +%br + += link_to 'New Container', new_container_path diff --git a/app/views/containers/new.html.haml b/app/views/containers/new.html.haml new file mode 100644 index 000000000..e4db982eb --- /dev/null +++ b/app/views/containers/new.html.haml @@ -0,0 +1,5 @@ +%h1 New container + += render 'form' + += link_to 'Back', containers_path diff --git a/app/views/containers/show.html.haml b/app/views/containers/show.html.haml new file mode 100644 index 000000000..11a7ab32c --- /dev/null +++ b/app/views/containers/show.html.haml @@ -0,0 +1,9 @@ +%p#notice= notice + +%p + %b Description: + = @container.description + += link_to 'Edit', edit_container_path(@container) +\| += link_to 'Back', containers_path diff --git a/config/routes.rb b/config/routes.rb index 52517f580..080855a49 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Growstuff::Application.routes.draw do + resources :containers get '/robots.txt' => 'robots#robots' resources :plant_parts diff --git a/db/migrate/20181129171803_create_containers.rb b/db/migrate/20181129171803_create_containers.rb new file mode 100644 index 000000000..8af213729 --- /dev/null +++ b/db/migrate/20181129171803_create_containers.rb @@ -0,0 +1,9 @@ +class CreateContainers < ActiveRecord::Migration + def change + create_table :containers do |t| + t.string :description + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20181129171857_create_plots.rb b/db/migrate/20181129171857_create_plots.rb new file mode 100644 index 000000000..4afece2fd --- /dev/null +++ b/db/migrate/20181129171857_create_plots.rb @@ -0,0 +1,10 @@ +class CreatePlots < ActiveRecord::Migration + def change + create_table :plots do |t| + t.references :garden, foreign_key: true + t.references :container, foreign_key: true + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 71338e4a2..d83fe9b02 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180401220637) do +ActiveRecord::Schema.define(version: 20181129171857) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -164,6 +164,12 @@ ActiveRecord::Schema.define(version: 20180401220637) do t.datetime "updated_at" end + create_table "containers", force: :cascade do |t| + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "crops", force: :cascade do |t| t.string "name", null: false t.string "en_wikipedia_url" @@ -416,6 +422,13 @@ ActiveRecord::Schema.define(version: 20180401220637) do add_index "plantings", ["slug"], name: "index_plantings_on_slug", unique: true, using: :btree + create_table "plots", force: :cascade do |t| + t.integer "garden_id" + t.integer "container_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "posts", force: :cascade do |t| t.integer "author_id", null: false t.string "subject", null: false @@ -472,5 +485,7 @@ ActiveRecord::Schema.define(version: 20180401220637) do add_foreign_key "harvests", "plantings" add_foreign_key "photographings", "photos" add_foreign_key "plantings", "seeds", column: "parent_seed_id", name: "parent_seed", on_delete: :nullify + add_foreign_key "plots", "containers" + add_foreign_key "plots", "gardens" add_foreign_key "seeds", "plantings", column: "parent_planting_id", name: "parent_planting", on_delete: :nullify end diff --git a/spec/factories/containers.rb b/spec/factories/containers.rb new file mode 100644 index 000000000..2ea319977 --- /dev/null +++ b/spec/factories/containers.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :container do + description { "MyString" } + end +end diff --git a/spec/factories/plots.rb b/spec/factories/plots.rb new file mode 100644 index 000000000..0f71b74a8 --- /dev/null +++ b/spec/factories/plots.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :plot do + garden { nil } + container { nil } + end +end diff --git a/spec/models/container_spec.rb b/spec/models/container_spec.rb new file mode 100644 index 000000000..c74f254d2 --- /dev/null +++ b/spec/models/container_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Container, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/plot_spec.rb b/spec/models/plot_spec.rb new file mode 100644 index 000000000..e7d018f46 --- /dev/null +++ b/spec/models/plot_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Plot, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/containers_spec.rb b/spec/requests/containers_spec.rb new file mode 100644 index 000000000..0f61eb278 --- /dev/null +++ b/spec/requests/containers_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Containers", type: :request do + describe "GET /containers" do + it "works! (now write some real specs)" do + get containers_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/containers_routing_spec.rb b/spec/routing/containers_routing_spec.rb new file mode 100644 index 000000000..d505cf5b9 --- /dev/null +++ b/spec/routing/containers_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe ContainersController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/containers").to route_to("containers#index") + end + + it "routes to #new" do + expect(:get => "/containers/new").to route_to("containers#new") + end + + it "routes to #show" do + expect(:get => "/containers/1").to route_to("containers#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/containers/1/edit").to route_to("containers#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/containers").to route_to("containers#create") + end + + it "routes to #update via PUT" do + expect(:put => "/containers/1").to route_to("containers#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/containers/1").to route_to("containers#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/containers/1").to route_to("containers#destroy", :id => "1") + end + end +end From c898a958a5728b238deac149b66707bfb4626f05 Mon Sep 17 00:00:00 2001 From: Brandon Baker Date: Thu, 29 Nov 2018 12:51:15 -0700 Subject: [PATCH 002/124] adds container to garden form --- app/controllers/gardens_controller.rb | 2 +- app/models/ability.rb | 4 ++++ app/models/container.rb | 1 - app/views/containers/_actions.html.haml | 11 +++++++++++ app/views/gardens/_form.html.haml | 7 +++++++ 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 app/views/containers/_actions.html.haml diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index ede5c2602..270cd6de2 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -62,7 +62,7 @@ class GardensController < ApplicationController def garden_params params.require(:garden).permit(:name, :slug, :description, :active, - :location, :latitude, :longitude, :area, :area_unit) + :location, :latitude, :longitude, :area, :area_unit, :container_ids => []) end def gardens diff --git a/app/models/ability.rb b/app/models/ability.rb index 4fd14340e..deff7c072 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -124,6 +124,10 @@ class Ability can :destroy, Follow cannot :destroy, Follow, followed_id: member.id # can't unfollow yourself + + cannot :create, Container + cannot :update, Container + cannot :destroy, Container end def admin_abilities(member) diff --git a/app/models/container.rb b/app/models/container.rb index 2743cf9a9..aade0deb9 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -1,5 +1,4 @@ class Container < ActiveRecord::Base - has_many :plots, dependent: :destroy has_many :gardens, through: :plots diff --git a/app/views/containers/_actions.html.haml b/app/views/containers/_actions.html.haml new file mode 100644 index 000000000..d26b9a7e7 --- /dev/null +++ b/app/views/containers/_actions.html.haml @@ -0,0 +1,11 @@ +- if can?(:create, container) && can?(:edit, container) && can?(:destroy, container) + .btn-group.container-actions + - if can? :edit, container + = render 'shared/buttons/edit', path: edit_container_path(container) + - if can? :destroy, container + .pull-right= render 'shared/buttons/delete', path: container_path(container) + + - if can? :create, container + = link_to new_container_path, class: 'btn btn-default btn-xs' do + %span.glyphicon.glyphicon-grain{ title: "Create new container" } + Create new container diff --git a/app/views/gardens/_form.html.haml b/app/views/gardens/_form.html.haml index 05afdb42b..e7fbc52e3 100644 --- a/app/views/gardens/_form.html.haml +++ b/app/views/gardens/_form.html.haml @@ -43,6 +43,13 @@ .col-md-2 = f.select(:area_unit, Garden::AREA_UNITS_VALUES, { include_blank: false }, class: 'form-control') + .form-group + = f.label :container, class: 'control-label col-md-2' + .col-md-2 + = f.collection_check_boxes(:container_ids, Container.all, :id, :description) do |c| + = c.label class:"checkbox-inline" do + = c.check_box + c.text + .form-group = f.label :active, 'Active? ', class: 'control-label col-md-2' .col-md-8 From 5f6852b45cd6b6c0372c07534538c2fd25a50e30 Mon Sep 17 00:00:00 2001 From: Brandon Baker Date: Thu, 29 Nov 2018 13:22:35 -0700 Subject: [PATCH 003/124] adds basic specs for container and adds a plot spec for garden --- app/models/container.rb | 8 +++++++- spec/models/container_spec.rb | 22 ++++++++++++++++++++-- spec/models/garden_spec.rb | 11 +++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/models/container.rb b/app/models/container.rb index aade0deb9..aaed24aba 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -2,5 +2,11 @@ class Container < ActiveRecord::Base has_many :plots, dependent: :destroy has_many :gardens, through: :plots - validates :description, presence: true, uniqueness: true + validates :description, + format: { + with: /\A\w+[\w ()]+\z/ + }, + length: { maximum: 255 }, + presence: true, + uniqueness: true end diff --git a/spec/models/container_spec.rb b/spec/models/container_spec.rb index c74f254d2..4cc3b0374 100644 --- a/spec/models/container_spec.rb +++ b/spec/models/container_spec.rb @@ -1,5 +1,23 @@ require 'rails_helper' -RSpec.describe Container, type: :model do - pending "add some examples to (or delete) #{__FILE__}" +describe Container do + it "should have a description" do + container = FactoryBot.build(:container, description: "organic") + container.should be_valid + end + + it "doesn't allow a nil description" do + container = FactoryBot.build(:container, description: nil) + container.should_not be_valid + end + + it "doesn't allow a blank description" do + container = FactoryBot.build(:container, description: "") + container.should_not be_valid + end + + it "doesn't allow a description with only spaces" do + garden = FactoryBot.build(:container, description: " ") + garden.should_not be_valid + end end diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 839ef3445..bb9e6bcc7 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' describe Garden do let(:owner) { FactoryBot.create(:member) } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } + let(:container ) { FactoryBot.create(:container, description: "aquaponic") } it "should have a slug" do garden.slug.should match(/member\d+-springfield-community-garden/) @@ -103,6 +104,16 @@ describe Garden do Planting.count.should eq(all - 2) end + it "destroys plots when deleted" do + garden = FactoryBot.create(:garden, owner: owner) + @plot1 = FactoryBot.create(:plot, garden: garden, container: container) + @plot2 = FactoryBot.create(:plot, garden: garden, container: container) + garden.plots.size.should eq(2) + all = Plot.count + garden.destroy + Plot.count.should eq(all - 2) + end + context 'area' do it 'allows numeric area' do garden = FactoryBot.build(:garden, area: 33) From f5abc592f117e52932c4ca38558ae2e9384c8afb Mon Sep 17 00:00:00 2001 From: Brandon Baker Date: Thu, 29 Nov 2018 14:30:02 -0700 Subject: [PATCH 004/124] cleans up rubocop violations --- app/controllers/containers_controller.rb | 23 ++++++++++------------- app/controllers/gardens_controller.rb | 2 +- spec/models/garden_spec.rb | 2 +- spec/routing/containers_routing_spec.rb | 23 +++++++++-------------- 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/app/controllers/containers_controller.rb b/app/controllers/containers_controller.rb index 3e5506db7..5e4489486 100644 --- a/app/controllers/containers_controller.rb +++ b/app/controllers/containers_controller.rb @@ -1,5 +1,5 @@ class ContainersController < ApplicationController - before_action :set_container, only: [:show, :edit, :update, :destroy] + before_action :authenticate_member!, except: %i(index show) # GET /containers def index @@ -7,8 +7,7 @@ class ContainersController < ApplicationController end # GET /containers/1 - def show - end + def show; end # GET /containers/new def new @@ -16,8 +15,7 @@ class ContainersController < ApplicationController end # GET /containers/1/edit - def edit - end + def edit; end # POST /containers def create @@ -46,13 +44,12 @@ class ContainersController < ApplicationController end private - # Use callbacks to share common setup or constraints between actions. - def set_container - @container = Container.find(params[:id]) - end - # Only allow a trusted parameter "white list" through. - def container_params - params.require(:container).permit(:description) - end + def set_container + @container = Container.find(params[:id]) + end + + def container_params + params.require(:container).permit(:description) + end end diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index 270cd6de2..7d4d77b39 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -62,7 +62,7 @@ class GardensController < ApplicationController def garden_params params.require(:garden).permit(:name, :slug, :description, :active, - :location, :latitude, :longitude, :area, :area_unit, :container_ids => []) + :location, :latitude, :longitude, :area, :area_unit, container_ids: []) end def gardens diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index bb9e6bcc7..ce3857f10 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Garden do let(:owner) { FactoryBot.create(:member) } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } - let(:container ) { FactoryBot.create(:container, description: "aquaponic") } + let(:container) { FactoryBot.create(:container, description: "aquaponic") } it "should have a slug" do garden.slug.should match(/member\d+-springfield-community-garden/) diff --git a/spec/routing/containers_routing_spec.rb b/spec/routing/containers_routing_spec.rb index d505cf5b9..3ef83d891 100644 --- a/spec/routing/containers_routing_spec.rb +++ b/spec/routing/containers_routing_spec.rb @@ -1,38 +1,33 @@ require "rails_helper" -RSpec.describe ContainersController, type: :routing do +describe ContainersController do describe "routing" do it "routes to #index" do - expect(:get => "/containers").to route_to("containers#index") + get("/containers").should route_to("containers#index") end it "routes to #new" do - expect(:get => "/containers/new").to route_to("containers#new") + get("/containers/new").should route_to("containers#new") end it "routes to #show" do - expect(:get => "/containers/1").to route_to("containers#show", :id => "1") + get("/containers/1").should route_to("containers#show", id: "1") end it "routes to #edit" do - expect(:get => "/containers/1/edit").to route_to("containers#edit", :id => "1") + get("/containers/1/edit").should route_to("containers#edit", id: "1") end - it "routes to #create" do - expect(:post => "/containers").to route_to("containers#create") + post("/containers").should route_to("containers#create") end - it "routes to #update via PUT" do - expect(:put => "/containers/1").to route_to("containers#update", :id => "1") - end - - it "routes to #update via PATCH" do - expect(:patch => "/containers/1").to route_to("containers#update", :id => "1") + it "routes to #update" do + put("/containers/1").should route_to("containers#update", id: "1") end it "routes to #destroy" do - expect(:delete => "/containers/1").to route_to("containers#destroy", :id => "1") + delete("/containers/1").should route_to("containers#destroy", id: "1") end end end From 02174a0acbfe5685fa6fc7269ba376c407ab9e72 Mon Sep 17 00:00:00 2001 From: Brandon Baker Date: Fri, 30 Nov 2018 11:56:58 -0700 Subject: [PATCH 005/124] builds views for containers --- app/controllers/containers_controller.rb | 5 ++-- app/models/ability.rb | 4 +++ app/models/container.rb | 14 ++++----- app/views/containers/_actions.html.haml | 18 +++++------ app/views/containers/_form.html.haml | 19 ++++++++---- app/views/containers/_thumbnail.html.haml | 7 +++++ app/views/containers/edit.html.haml | 9 ++---- app/views/containers/index.html.haml | 30 ++++++++----------- app/views/containers/new.html.haml | 7 ++--- app/views/containers/show.html.haml | 17 ++++++----- .../controllers/containers_controller_spec.rb | 11 +++++++ spec/factories/containers.rb | 2 +- spec/factories/plots.rb | 4 +-- spec/models/plot_spec.rb | 14 +++++++-- 14 files changed, 97 insertions(+), 64 deletions(-) create mode 100644 app/views/containers/_thumbnail.html.haml create mode 100644 spec/controllers/containers_controller_spec.rb diff --git a/app/controllers/containers_controller.rb b/app/controllers/containers_controller.rb index 5e4489486..bfb87fb9d 100644 --- a/app/controllers/containers_controller.rb +++ b/app/controllers/containers_controller.rb @@ -1,9 +1,10 @@ class ContainersController < ApplicationController - before_action :authenticate_member!, except: %i(index show) + # before_action :authenticate_member!, except: %i(index show) + load_and_authorize_resource # GET /containers def index - @containers = Container.all + @containers = Container.all.paginate(page: params[:page]) end # GET /containers/1 diff --git a/app/models/ability.rb b/app/models/ability.rb index deff7c072..dcc3b8300 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -42,6 +42,10 @@ class Ability can :read, AlternateName do |an| an.crop.approved? end + + cannot :create, Container + cannot :update, Container + cannot :destroy, Container end def member_abilities(member) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength diff --git a/app/models/container.rb b/app/models/container.rb index aaed24aba..96eece04f 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -2,11 +2,11 @@ class Container < ActiveRecord::Base has_many :plots, dependent: :destroy has_many :gardens, through: :plots - validates :description, - format: { - with: /\A\w+[\w ()]+\z/ - }, - length: { maximum: 255 }, - presence: true, - uniqueness: true + validates :description, presence: true, uniqueness: true + + def subtitler(container) + num = container.gardens.uniq.count + s = (num > 1 || num == 0) ? "s are" : " is" + return "#{num.to_s} garden#{s} using this container" + end end diff --git a/app/views/containers/_actions.html.haml b/app/views/containers/_actions.html.haml index d26b9a7e7..662630b75 100644 --- a/app/views/containers/_actions.html.haml +++ b/app/views/containers/_actions.html.haml @@ -1,11 +1,9 @@ -- if can?(:create, container) && can?(:edit, container) && can?(:destroy, container) - .btn-group.container-actions - - if can? :edit, container - = render 'shared/buttons/edit', path: edit_container_path(container) - - if can? :destroy, container - .pull-right= render 'shared/buttons/delete', path: container_path(container) +.btn-group.container-actions + = render 'shared/buttons/edit', path: edit_container_path(container) + .pull-right + = render 'shared/buttons/delete', path: container_path(container) - - if can? :create, container - = link_to new_container_path, class: 'btn btn-default btn-xs' do - %span.glyphicon.glyphicon-grain{ title: "Create new container" } - Create new container +- if can? :create, container + = link_to new_container_path, class: 'btn btn-default btn-xs' do + %span.glyphicon.glyphicon-grain{ title: "Create new container" } + Create new container diff --git a/app/views/containers/_form.html.haml b/app/views/containers/_form.html.haml index 25dff9445..45d5b4c6d 100644 --- a/app/views/containers/_form.html.haml +++ b/app/views/containers/_form.html.haml @@ -1,4 +1,4 @@ -= form_for @container do |f| += form_for @container, html: { class: 'form-horizontal', role: "form" } do |f| - if @container.errors.any? #error_explanation %h2= "#{pluralize(@container.errors.count, "error")} prohibited this container from being saved:" @@ -6,8 +6,15 @@ - @container.errors.full_messages.each do |message| %li= message - .field - = f.label :description - = f.text_field :description - .actions - = f.submit 'Save' + %h2 Basic information + + .form-group + = f.label :description, class: 'control-label col-md-2' + .col-md-8 + = f.text_field :description, class: 'form-control' + %span.help-block + The name for the container, i.e. "organic", in English (required). + + .form-group + .form-actions.col-md-offset-2.col-md-8 + = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/containers/_thumbnail.html.haml b/app/views/containers/_thumbnail.html.haml new file mode 100644 index 000000000..ff235a90e --- /dev/null +++ b/app/views/containers/_thumbnail.html.haml @@ -0,0 +1,7 @@ +- cache cache_key_for(Container, container.id) do + .thumbnail + .container-thumbnail + - if container + .containerinfo + .containername + = link_to container.description, container diff --git a/app/views/containers/edit.html.haml b/app/views/containers/edit.html.haml index a1ba22545..ee890d6b7 100644 --- a/app/views/containers/edit.html.haml +++ b/app/views/containers/edit.html.haml @@ -1,7 +1,4 @@ -%h1 Editing container +- content_for :title, "Edit Container" -= render 'form' - -= link_to 'Show', @container -\| -= link_to 'Back', containers_path +- if can? :update, @container + = render 'form' diff --git a/app/views/containers/index.html.haml b/app/views/containers/index.html.haml index d2e2fda34..040a892bc 100644 --- a/app/views/containers/index.html.haml +++ b/app/views/containers/index.html.haml @@ -1,21 +1,17 @@ -%h1 Listing containers +- content_for :title, 'Containers' -%table - %thead - %tr - %th Description - %th - %th - %th +%p + #{ENV['GROWSTUFF_SITE_NAME']} tracks who's growing what, where. + View any container page to see which of our members have used it. - %tbody - - @containers.each do |container| - %tr - %td= container.description - %td= link_to 'Show', container - %td= link_to 'Edit', edit_container_path(container) - %td= link_to 'Destroy', container, method: :delete, data: { confirm: 'Are you sure?' } +.row + - @containers.each do |container| + .col-md-2.six-across + = render partial: "thumbnail", locals: { container: container } -%br +- if can? :create, Container + %div + = link_to 'New Container', new_container_path, class: 'btn btn-primary' -= link_to 'New Container', new_container_path +.pagination + = will_paginate @containers diff --git a/app/views/containers/new.html.haml b/app/views/containers/new.html.haml index e4db982eb..b6e92973a 100644 --- a/app/views/containers/new.html.haml +++ b/app/views/containers/new.html.haml @@ -1,5 +1,4 @@ -%h1 New container +- content_for :title, "New Container" -= render 'form' - -= link_to 'Back', containers_path +- if can? :create, @container + = render 'form' diff --git a/app/views/containers/show.html.haml b/app/views/containers/show.html.haml index 11a7ab32c..615403575 100644 --- a/app/views/containers/show.html.haml +++ b/app/views/containers/show.html.haml @@ -1,9 +1,12 @@ -%p#notice= notice +- content_for :title, @container.description.capitalize +- content_for :subtitle, @container.subtitler(@container) -%p - %b Description: - = @container.description +- if can?(:create, @container) && can?(:edit, @container) && can?(:destroy, @container) + - content_for :buttonbar do + = render 'containers/actions', container: @container -= link_to 'Edit', edit_container_path(@container) -\| -= link_to 'Back', containers_path +- if @container.gardens.uniq.empty? + %p There are no gardens to display. +- else + - @container.gardens.uniq.each do |garden| + = render 'gardens/overview', garden: garden diff --git a/spec/controllers/containers_controller_spec.rb b/spec/controllers/containers_controller_spec.rb new file mode 100644 index 000000000..2a66cecd8 --- /dev/null +++ b/spec/controllers/containers_controller_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe ContainersController, type: :controller do + include Devise::Test::ControllerHelpers + let(:valid_params) { { description: 'My second Container' } } + + let(:container) { FactoryBot.create :container } + + let(:member) { FactoryBot.create(:member) } + let(:admin_member) { FactoryBot.create(:admin) } +end diff --git a/spec/factories/containers.rb b/spec/factories/containers.rb index 2ea319977..f6b9f8cc4 100644 --- a/spec/factories/containers.rb +++ b/spec/factories/containers.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :container do - description { "MyString" } + description { "homemade swamp" } end end diff --git a/spec/factories/plots.rb b/spec/factories/plots.rb index 0f71b74a8..9193888f3 100644 --- a/spec/factories/plots.rb +++ b/spec/factories/plots.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :plot do - garden { nil } - container { nil } + garden { garden } + container { container } end end diff --git a/spec/models/plot_spec.rb b/spec/models/plot_spec.rb index e7d018f46..c18bc9122 100644 --- a/spec/models/plot_spec.rb +++ b/spec/models/plot_spec.rb @@ -1,5 +1,15 @@ require 'rails_helper' -RSpec.describe Plot, type: :model do - pending "add some examples to (or delete) #{__FILE__}" +describe Plot do + let(:owner) { FactoryBot.create(:member) } + let(:garden) { FactoryBot.create(:garden, owner: owner, name: "Magic Beanstalk") } + let(:container) { FactoryBot.create(:container, description: "vertical") } + let(:plot) { FactoryBot.create(:plot, garden: garden, container: container) } + + context "has valid attributes" do + it "should have a garden and container" do + plot.garden.should == garden + plot.container.should == container + end + end end From f35284c403815cfa15c843f376de2cf89619a4e4 Mon Sep 17 00:00:00 2001 From: Brandon Baker Date: Sat, 1 Dec 2018 14:08:11 -0700 Subject: [PATCH 006/124] adds more basic specs --- app/models/container.rb | 4 +- app/views/containers/_actions.html.haml | 5 -- app/views/layouts/_header.html.haml | 1 + config/locales/en.yml | 3 + .../controllers/containers_controller_spec.rb | 81 ++++++++++++++++++- spec/models/container_spec.rb | 18 ++++- spec/models/plot_spec.rb | 12 +-- spec/views/containers/edit.html.haml_spec.rb | 17 ++++ spec/views/containers/new.html.haml_spec.rb | 17 ++++ spec/views/containers/show.html.haml_spec.rb | 17 ++++ 10 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 spec/views/containers/edit.html.haml_spec.rb create mode 100644 spec/views/containers/new.html.haml_spec.rb create mode 100644 spec/views/containers/show.html.haml_spec.rb diff --git a/app/models/container.rb b/app/models/container.rb index 96eece04f..b55141205 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -6,7 +6,7 @@ class Container < ActiveRecord::Base def subtitler(container) num = container.gardens.uniq.count - s = (num > 1 || num == 0) ? "s are" : " is" - return "#{num.to_s} garden#{s} using this container" + s = num > 1 || num.zero? ? "s are" : " is" + "#{num} garden#{s} using this container" end end diff --git a/app/views/containers/_actions.html.haml b/app/views/containers/_actions.html.haml index 662630b75..95bf704fe 100644 --- a/app/views/containers/_actions.html.haml +++ b/app/views/containers/_actions.html.haml @@ -2,8 +2,3 @@ = render 'shared/buttons/edit', path: edit_container_path(container) .pull-right = render 'shared/buttons/delete', path: container_path(container) - -- if can? :create, container - = link_to new_container_path, class: 'btn btn-default btn-xs' do - %span.glyphicon.glyphicon-grain{ title: "Create new container" } - Create new container diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index d2b8fd01c..ff9aa6553 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -38,6 +38,7 @@ %li= link_to t('.seeds'), seeds_path %li= link_to t('.plantings'), plantings_path %li= link_to t('.harvests'), harvests_path + %li= link_to t('.containers'), containers_path %li.dropdown< %a.dropdown-toggle{ 'data-toggle': 'dropdown', href: members_path } = t('.community') diff --git a/config/locales/en.yml b/config/locales/en.yml index c494975e7..1fccfbc49 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -144,6 +144,8 @@ en: browse_members: Browse Members community: Community community_map: Community Map + container: Container + containers: Containers crop_wrangling: Crop Wrangling crops: Crops current_memberlogin_name: "%{current_memberlogin_name}" @@ -229,6 +231,7 @@ en: planting: Please sign in or sign up to plant something. post: Please sign in or sign up to post. seed: Please sign in or sign up to add seeds. + container: Not authorized. Only admins can create containers. manage: all: Not authorized to %{action} %{subject}. read: diff --git a/spec/controllers/containers_controller_spec.rb b/spec/controllers/containers_controller_spec.rb index 2a66cecd8..8fe2951cf 100644 --- a/spec/controllers/containers_controller_spec.rb +++ b/spec/controllers/containers_controller_spec.rb @@ -3,9 +3,88 @@ require 'rails_helper' RSpec.describe ContainersController, type: :controller do include Devise::Test::ControllerHelpers let(:valid_params) { { description: 'My second Container' } } - let(:container) { FactoryBot.create :container } let(:member) { FactoryBot.create(:member) } let(:admin_member) { FactoryBot.create(:admin) } + + context "when not signed in" do + describe 'GET new' do + before { get :new, id: container.to_param } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'PUT create' do + before { put :create, container: valid_params } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'changing existing records' do + before do + allow(Container).to receive(:find).and_return(:container) + expect(container).not_to receive(:save) + expect(container).not_to receive(:save!) + expect(container).not_to receive(:update) + expect(container).not_to receive(:update!) + expect(container).not_to receive(:destroy) + end + + describe 'GET edit' do + before { get :edit, id: container.to_param } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'POST update' do + before { post :update, id: container.to_param, container: valid_params } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'DELETE' do + before { delete :destroy, id: container.to_param, params: { container: valid_params } } + + it { expect(response).to redirect_to(root_path) } + end + end + end + + context "when signed in as a member" do + before(:each) { sign_in member } + + let!(:member) { FactoryBot.create(:member) } + + describe "for any container" do + let(:any_container) { double('container') } + + before do + expect(Container).to receive(:find).and_return(:any_container) + expect(any_container).not_to receive(:save) + expect(any_container).not_to receive(:save!) + expect(any_container).not_to receive(:update) + expect(any_container).not_to receive(:update!) + expect(any_container).not_to receive(:destroy) + end + + describe 'GET edit' do + before { get :edit, id: any_container.to_param } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'POST update' do + before { post :update, id: any_container.to_param, container: valid_params } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'DELETE' do + before { delete :destroy, id: any_container.to_param, params: { container: valid_params } } + + it { expect(response).to redirect_to(root_path) } + end + end + end end diff --git a/spec/models/container_spec.rb b/spec/models/container_spec.rb index 4cc3b0374..bac3e8e30 100644 --- a/spec/models/container_spec.rb +++ b/spec/models/container_spec.rb @@ -1,6 +1,10 @@ require 'rails_helper' describe Container do + let(:owner) { FactoryBot.create(:member) } + let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Free Carrots') } + let(:container) { FactoryBot.create(:container, description: "fake hole in the ground") } + it "should have a description" do container = FactoryBot.build(:container, description: "organic") container.should be_valid @@ -17,7 +21,17 @@ describe Container do end it "doesn't allow a description with only spaces" do - garden = FactoryBot.build(:container, description: " ") - garden.should_not be_valid + container = FactoryBot.build(:container, description: " ") + container.should_not be_valid + end + + it "destroys plots when deleted" do + container = FactoryBot.create(:container, description: "Massive Flower Pot") + @plot1 = FactoryBot.create(:plot, garden: garden, container: container) + @plot2 = FactoryBot.create(:plot, garden: garden, container: container) + container.plots.size.should eq(2) + all = Plot.count + container.destroy + Plot.count.should eq(all - 2) end end diff --git a/spec/models/plot_spec.rb b/spec/models/plot_spec.rb index c18bc9122..4a3a16724 100644 --- a/spec/models/plot_spec.rb +++ b/spec/models/plot_spec.rb @@ -2,14 +2,16 @@ require 'rails_helper' describe Plot do let(:owner) { FactoryBot.create(:member) } - let(:garden) { FactoryBot.create(:garden, owner: owner, name: "Magic Beanstalk") } - let(:container) { FactoryBot.create(:container, description: "vertical") } + let(:garden) { FactoryBot.create(:garden) } + let(:container) { FactoryBot.create(:container) } let(:plot) { FactoryBot.create(:plot, garden: garden, container: container) } context "has valid attributes" do - it "should have a garden and container" do - plot.garden.should == garden - plot.container.should == container + it "should have a garden" do + plot.garden.description.should == "This is a **totally** cool garden" + end + it "should have a container" do + plot.container.description.should == "homemade swamp" end end end diff --git a/spec/views/containers/edit.html.haml_spec.rb b/spec/views/containers/edit.html.haml_spec.rb new file mode 100644 index 000000000..3b9d61737 --- /dev/null +++ b/spec/views/containers/edit.html.haml_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe "containers/edit" do + before(:each) do + @owner = FactoryBot.create(:admin_member) + sign_in @owner + controller.stub(:current_user) { @owner } + @container = assign(:container, FactoryBot.create(:container)) + render + end + + it "renders the edit container form" do + assert_select "form", action: containers_path, method: "post" do + assert_select "input#container_description", name: "container[description]" + end + end +end diff --git a/spec/views/containers/new.html.haml_spec.rb b/spec/views/containers/new.html.haml_spec.rb new file mode 100644 index 000000000..f56d956fb --- /dev/null +++ b/spec/views/containers/new.html.haml_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe "containers/new" do + before(:each) do + @owner = FactoryBot.create(:admin_member) + sign_in @owner + controller.stub(:current_user) { @owner } + @container = assign(:container, FactoryBot.create(:container)) + render + end + + it "renders new container form" do + assert_select "form", action: containers_path, method: "post" do + assert_select "input#container_description", name: "container[description]" + end + end +end diff --git a/spec/views/containers/show.html.haml_spec.rb b/spec/views/containers/show.html.haml_spec.rb new file mode 100644 index 000000000..a18ffdd66 --- /dev/null +++ b/spec/views/containers/show.html.haml_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe "containers/show" do + subject { render } + + let!(:container) { FactoryBot.create(:container, description: "Hot Sauce") } + + before do + controller.stub(:current_user) { nil } + assign(:container, container) + render + end + + describe "renders a container with no gardens" do + it { is_expected.to have_content "There are no gardens to display." } + end +end From bb97082868eddeff4260526d0a891af8f11a2af1 Mon Sep 17 00:00:00 2001 From: Brandon Baker Date: Sat, 1 Dec 2018 19:46:49 -0700 Subject: [PATCH 007/124] adds friendly_id to containers --- app/controllers/containers_controller.rb | 2 +- app/models/container.rb | 7 +++++++ db/migrate/20181201213214_add_slug_to_containers.rb | 6 ++++++ db/schema.rb | 3 ++- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20181201213214_add_slug_to_containers.rb diff --git a/app/controllers/containers_controller.rb b/app/controllers/containers_controller.rb index bfb87fb9d..69458da16 100644 --- a/app/controllers/containers_controller.rb +++ b/app/controllers/containers_controller.rb @@ -51,6 +51,6 @@ class ContainersController < ApplicationController end def container_params - params.require(:container).permit(:description) + params.require(:container).permit(:description, :slug) end end diff --git a/app/models/container.rb b/app/models/container.rb index b55141205..483c6b318 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -1,9 +1,16 @@ class Container < ActiveRecord::Base + extend FriendlyId + friendly_id :container_slug, use: %i(slugged finders) + has_many :plots, dependent: :destroy has_many :gardens, through: :plots validates :description, presence: true, uniqueness: true + def container_slug + "#{self.description}".gsub!(/[^A-Za-z ]/, '') + end + def subtitler(container) num = container.gardens.uniq.count s = num > 1 || num.zero? ? "s are" : " is" diff --git a/db/migrate/20181201213214_add_slug_to_containers.rb b/db/migrate/20181201213214_add_slug_to_containers.rb new file mode 100644 index 000000000..882c3550e --- /dev/null +++ b/db/migrate/20181201213214_add_slug_to_containers.rb @@ -0,0 +1,6 @@ +class AddSlugToContainers < ActiveRecord::Migration + def change + add_column :containers, :slug, :string + add_index :containers, :slug, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index d83fe9b02..2883ea4aa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20181129171857) do +ActiveRecord::Schema.define(version: 20181201213214) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -168,6 +168,7 @@ ActiveRecord::Schema.define(version: 20181129171857) do t.string "description" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "slug" end create_table "crops", force: :cascade do |t| From 178c6cd944e8cf3b8f1ce428d13aed7e53779ab4 Mon Sep 17 00:00:00 2001 From: Brandon Baker Date: Thu, 6 Dec 2018 15:51:00 -0700 Subject: [PATCH 008/124] fixes bug in setting slug on container --- app/models/container.rb | 4 ++-- db/schema.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/container.rb b/app/models/container.rb index 483c6b318..205b4f401 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -1,6 +1,6 @@ class Container < ActiveRecord::Base extend FriendlyId - friendly_id :container_slug, use: %i(slugged finders) + friendly_id :description, use: %i(slugged finders) has_many :plots, dependent: :destroy has_many :gardens, through: :plots @@ -8,7 +8,7 @@ class Container < ActiveRecord::Base validates :description, presence: true, uniqueness: true def container_slug - "#{self.description}".gsub!(/[^A-Za-z ]/, '') + description.gsub!(/[^A-Za-z ]/, '') end def subtitler(container) diff --git a/db/schema.rb b/db/schema.rb index 2883ea4aa..159c393cf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -171,6 +171,8 @@ ActiveRecord::Schema.define(version: 20181201213214) do t.string "slug" end + add_index "containers", ["slug"], name: "index_containers_on_slug", unique: true, using: :btree + create_table "crops", force: :cascade do |t| t.string "name", null: false t.string "en_wikipedia_url" From 9a88a9f7e0c17894e7d589c152be0f56f590fd73 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 30 Dec 2018 16:58:33 +1300 Subject: [PATCH 009/124] Remove trailing whitespace --- app/views/containers/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/containers/_form.html.haml b/app/views/containers/_form.html.haml index 45d5b4c6d..f4fd7e8ba 100644 --- a/app/views/containers/_form.html.haml +++ b/app/views/containers/_form.html.haml @@ -7,7 +7,7 @@ %li= message %h2 Basic information - + .form-group = f.label :description, class: 'control-label col-md-2' .col-md-8 From f7d989bb61a203d0df54121d0cf833908103cbe3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 18 Jan 2019 14:31:35 +1300 Subject: [PATCH 010/124] Squashed migrations and set as Rails4.2 --- .../20181129171803_create_containers.rb | 10 ++- db/migrate/20181129171857_create_plots.rb | 10 --- .../20181201213214_add_slug_to_containers.rb | 6 -- db/schema.rb | 63 +++++++++---------- 4 files changed, 36 insertions(+), 53 deletions(-) delete mode 100644 db/migrate/20181129171857_create_plots.rb delete mode 100644 db/migrate/20181201213214_add_slug_to_containers.rb diff --git a/db/migrate/20181129171803_create_containers.rb b/db/migrate/20181129171803_create_containers.rb index 8af213729..a57f9e941 100644 --- a/db/migrate/20181129171803_create_containers.rb +++ b/db/migrate/20181129171803_create_containers.rb @@ -1,9 +1,15 @@ -class CreateContainers < ActiveRecord::Migration +class CreateContainers < ActiveRecord::Migration[4.2] def change create_table :containers do |t| t.string :description - t.timestamps null: false end + create_table :plots do |t| + t.references :garden, foreign_key: true + t.references :container, foreign_key: true + t.timestamps null: false + end + add_column :containers, :slug, :string + add_index :containers, :slug, unique: true end end diff --git a/db/migrate/20181129171857_create_plots.rb b/db/migrate/20181129171857_create_plots.rb deleted file mode 100644 index 4afece2fd..000000000 --- a/db/migrate/20181129171857_create_plots.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreatePlots < ActiveRecord::Migration - def change - create_table :plots do |t| - t.references :garden, foreign_key: true - t.references :container, foreign_key: true - - t.timestamps null: false - end - end -end diff --git a/db/migrate/20181201213214_add_slug_to_containers.rb b/db/migrate/20181201213214_add_slug_to_containers.rb deleted file mode 100644 index 882c3550e..000000000 --- a/db/migrate/20181201213214_add_slug_to_containers.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddSlugToContainers < ActiveRecord::Migration - def change - add_column :containers, :slug, :string - add_index :containers, :slug, unique: true - end -end diff --git a/db/schema.rb b/db/schema.rb index 31d059264..12fe28171 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20181201213214) do +ActiveRecord::Schema.define(version: 2018_11_29_171803) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -38,8 +38,8 @@ ActiveRecord::Schema.define(version: 20181201213214) do create_table "comfy_cms_blocks", id: :serial, force: :cascade do |t| t.string "identifier", null: false t.text "content" - t.string "blockable_type" t.integer "blockable_id" + t.string "blockable_type" t.datetime "created_at" t.datetime "updated_at" t.index ["blockable_id", "blockable_type"], name: "index_comfy_cms_blocks_on_blockable_id_and_blockable_type" @@ -153,15 +153,14 @@ ActiveRecord::Schema.define(version: 20181201213214) do t.datetime "updated_at" end - create_table "containers", force: :cascade do |t| - t.string "description" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "slug" + create_table "containers", id: :serial, force: :cascade do |t| + t.string "description" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "slug" + t.index ["slug"], name: "index_containers_on_slug", unique: true end - add_index "containers", ["slug"], name: "index_containers_on_slug", unique: true, using: :btree - create_table "crops", id: :serial, force: :cascade do |t| t.string "name", null: false t.string "en_wikipedia_url" @@ -258,8 +257,8 @@ ActiveRecord::Schema.define(version: 20181201213214) do create_table "likes", id: :serial, force: :cascade do |t| t.integer "member_id" - t.string "likeable_type" t.integer "likeable_id" + t.string "likeable_type" t.string "categories", array: true t.datetime "created_at" t.datetime "updated_at" @@ -389,31 +388,6 @@ ActiveRecord::Schema.define(version: 20181201213214) do t.text "description" t.datetime "created_at" t.datetime "updated_at" - t.string "slug" - t.string "sunniness" - t.string "planted_from" - t.integer "owner_id" - t.boolean "finished", default: false - t.date "finished_at" - t.integer "lifespan" - t.integer "days_to_first_harvest" - t.integer "days_to_last_harvest" - t.integer "parent_seed_id" - end - - add_index "plantings", ["slug"], name: "index_plantings_on_slug", unique: true, using: :btree - - create_table "plots", force: :cascade do |t| - t.integer "garden_id" - t.integer "container_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - create_table "posts", force: :cascade do |t| - t.integer "author_id", null: false - t.string "subject", null: false - t.text "body", null: false t.string "slug" t.string "sunniness" t.string "planted_from" @@ -427,6 +401,25 @@ ActiveRecord::Schema.define(version: 20181201213214) do t.index ["slug"], name: "index_plantings_on_slug", unique: true end + create_table "plots", id: :serial, force: :cascade do |t| + t.integer "garden_id" + t.integer "container_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "posts", id: :serial, force: :cascade do |t| + t.integer "author_id", null: false + t.string "subject", null: false + t.text "body", null: false + t.datetime "created_at" + t.datetime "updated_at" + t.string "slug" + t.integer "forum_id" + t.index ["created_at", "author_id"], name: "index_posts_on_created_at_and_author_id" + t.index ["slug"], name: "index_posts_on_slug", unique: true + end + create_table "roles", id: :serial, force: :cascade do |t| t.string "name", null: false t.text "description" From 6273fa684c0cfe13035f0976e13da3781c84501a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 18 Jan 2019 14:34:47 +1300 Subject: [PATCH 011/124] Models (plot and container) need to sub class ApplicationRecord --- app/models/container.rb | 2 +- app/models/plot.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/container.rb b/app/models/container.rb index 205b4f401..a36b2099d 100644 --- a/app/models/container.rb +++ b/app/models/container.rb @@ -1,4 +1,4 @@ -class Container < ActiveRecord::Base +class Container < ApplicationRecord extend FriendlyId friendly_id :description, use: %i(slugged finders) diff --git a/app/models/plot.rb b/app/models/plot.rb index 779f7e9eb..c253e3d58 100644 --- a/app/models/plot.rb +++ b/app/models/plot.rb @@ -1,4 +1,4 @@ -class Plot < ActiveRecord::Base +class Plot < ApplicationRecord belongs_to :garden belongs_to :container end From 9a24bb2fc30402798b4848f68f63f0324abea8b1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 26 Feb 2019 07:24:40 +0000 Subject: [PATCH 012/124] Bump capybara from 3.13.2 to 3.14.0 Bumps [capybara](https://github.com/teamcapybara/capybara) from 3.13.2 to 3.14.0. - [Release notes](https://github.com/teamcapybara/capybara/releases) - [Changelog](https://github.com/teamcapybara/capybara/blob/master/History.md) - [Commits](https://github.com/teamcapybara/capybara/compare/3.13.2...3.14.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 30c309ce2..524d17366 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,7 +80,7 @@ GEM uniform_notifier (~> 1.11) byebug (10.0.2) cancancan (2.3.0) - capybara (3.13.2) + capybara (3.14.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) From da32a2caf163edb33314a67406e0403b86543eec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Wed, 6 Mar 2019 04:49:06 +0000 Subject: [PATCH 013/124] Bump newrelic_rpm from 6.0.0.351 to 6.1.0.352 Bumps [newrelic_rpm](https://github.com/newrelic/rpm) from 6.0.0.351 to 6.1.0.352. - [Release notes](https://github.com/newrelic/rpm/releases) - [Changelog](https://github.com/newrelic/rpm/blob/master/CHANGELOG.md) - [Commits](https://github.com/newrelic/rpm/compare/6.0.0.351...6.1.0.352) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 524d17366..2fbb57c03 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -294,7 +294,7 @@ GEM multi_json (1.11.3) multi_xml (0.6.0) multipart-post (2.0.0) - newrelic_rpm (6.0.0.351) + newrelic_rpm (6.1.0.352) nio4r (2.3.1) nokogiri (1.10.1) mini_portile2 (~> 2.4.0) From ea5b622225a04b5264fd49e8be897bbd6f53fb35 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 11 Mar 2019 10:43:45 +0000 Subject: [PATCH 014/124] Bump byebug from 10.0.2 to 11.0.0 Bumps [byebug](https://github.com/deivid-rodriguez/byebug) from 10.0.2 to 11.0.0. - [Release notes](https://github.com/deivid-rodriguez/byebug/releases) - [Changelog](https://github.com/deivid-rodriguez/byebug/blob/master/CHANGELOG.md) - [Commits](https://github.com/deivid-rodriguez/byebug/compare/v10.0.2...v11.0.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2fbb57c03..1a0f6367c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,7 +78,7 @@ GEM bullet (5.9.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) - byebug (10.0.2) + byebug (11.0.0) cancancan (2.3.0) capybara (3.14.0) addressable From b49a59bf72b7df8d423c584dedc299bc72ca4d6e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 11 Mar 2019 11:10:14 +0000 Subject: [PATCH 015/124] Bump haml-rails from 1.0.0 to 2.0.0 Bumps [haml-rails](https://github.com/indirect/haml-rails) from 1.0.0 to 2.0.0. - [Release notes](https://github.com/indirect/haml-rails/releases) - [Commits](https://github.com/indirect/haml-rails/compare/v1.0.0...v2.0.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1a0f6367c..b15dbff9d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -194,12 +194,12 @@ GEM highline tilt trollop (= 1.16.2) - haml-rails (1.0.0) - actionpack (>= 4.0.1) - activesupport (>= 4.0.1) + haml-rails (2.0.0) + actionpack (>= 5.1) + activesupport (>= 5.1) haml (>= 4.0.6, < 6.0) html2haml (>= 1.0.1) - railties (>= 4.0.1) + railties (>= 5.1) haml_lint (0.28.0) haml (>= 4.0, < 5.1) rainbow @@ -467,7 +467,7 @@ GEM activesupport (>= 4.0) sprockets (>= 3.0.0) sysexits (1.2.0) - temple (0.8.0) + temple (0.8.1) term-ansicolor (1.7.0) tins (~> 1.0) terminal-table (1.8.0) From cbf4e0a61a043cf47ba44af330cddf46852d7fa5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 12 Mar 2019 08:23:58 +0000 Subject: [PATCH 016/124] Bump faker from 1.9.2 to 1.9.3 Bumps [faker](https://github.com/stympy/faker) from 1.9.2 to 1.9.3. - [Release notes](https://github.com/stympy/faker/releases) - [Changelog](https://github.com/stympy/faker/blob/master/CHANGELOG.md) - [Commits](https://github.com/stympy/faker/compare/v1.9.2...v1.9.3) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index b15dbff9d..f48b25d97 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -164,7 +164,7 @@ GEM factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faker (1.9.2) + faker (1.9.3) i18n (>= 0.7) faraday (0.15.4) multipart-post (>= 1.2, < 3) From da997ae5384db10f128ec571e44e15ba76979b93 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Tue, 12 Mar 2019 22:23:34 +0000 Subject: [PATCH 017/124] Auto corrected by following Lint Ruby RSpec/AlignLeftLetBrace --- spec/controllers/comments_controller_spec.rb | 8 ++++---- spec/controllers/harvests_controller_spec.rb | 12 ++++++------ spec/controllers/likes_controller_spec.rb | 6 +++--- .../photo_associations_controller_spec.rb | 2 +- spec/controllers/photos_controller_spec.rb | 18 +++++++++--------- spec/controllers/plantings_controller_spec.rb | 8 ++++---- spec/features/admin/forums_spec.rb | 2 +- spec/features/cms_spec.rb | 2 +- .../comments/commenting_a_comment_spec.rb | 2 +- spec/features/crops/alternate_name_spec.rb | 2 +- spec/features/crops/browse_crops_spec.rb | 6 +++--- spec/features/crops/creating_a_crop_spec.rb | 2 +- spec/features/crops/crop_detail_page_spec.rb | 2 +- spec/features/crops/crop_photos_spec.rb | 4 ++-- spec/features/crops/crop_wranglers_spec.rb | 6 +++--- .../crops/crop_wrangling_button_spec.rb | 2 +- spec/features/crops/delete_crop_spec.rb | 4 ++-- spec/features/crops/request_new_crop_spec.rb | 4 ++-- spec/features/crops/requested_crops_spec.rb | 2 +- spec/features/crops/show_spec.rb | 6 +++--- spec/features/gardens/gardens_index_spec.rb | 2 +- spec/features/gardens_spec.rb | 6 +++--- spec/features/harvests/browse_harvests_spec.rb | 2 +- .../harvests/harvesting_a_crop_spec.rb | 8 ++++---- spec/features/home/home_spec.rb | 4 ++-- spec/features/likeable_spec.rb | 4 ++-- spec/features/member_profile_spec.rb | 4 ++-- spec/features/members/deletion_spec.rb | 18 +++++++++--------- spec/features/notifications_spec.rb | 2 +- spec/features/places/searching_a_place_spec.rb | 8 ++++---- spec/features/planting_reminder_spec.rb | 2 +- spec/features/scientific_name_spec.rb | 2 +- spec/features/seeds/seed_photos.rb | 2 +- spec/features/shared_examples/append_date.rb | 2 +- spec/features/shared_examples/crop_suggest.rb | 6 +++--- spec/features/signin_spec.rb | 6 +++--- spec/features/unsubscribing_spec.rb | 2 +- spec/helpers/buttons_helper_spec.rb | 6 +++--- spec/helpers/photos_helper_spec.rb | 12 ++++++------ spec/mailers/notifier_spec.rb | 2 +- spec/models/ability_spec.rb | 2 +- spec/models/alternate_name_spec.rb | 2 +- spec/models/crop_spec.rb | 18 +++++++++--------- spec/models/garden_spec.rb | 10 +++++----- spec/models/like_spec.rb | 2 +- spec/models/member_spec.rb | 2 +- spec/models/photo_spec.rb | 10 +++++----- spec/models/planting_spec.rb | 8 ++++---- spec/models/post_spec.rb | 2 +- spec/models/seed_spec.rb | 6 +++--- spec/requests/api/v1/crop_request_spec.rb | 2 +- spec/requests/api/v1/harvest_request_spec.rb | 2 +- spec/requests/api/v1/photos_request_spec.rb | 2 +- spec/requests/api/v1/plantings_request_spec.rb | 2 +- spec/requests/api/v1/seeds_request_spec.rb | 2 +- spec/views/crops/_grown_for.html.haml_spec.rb | 2 +- spec/views/photos/show.html.haml_spec.rb | 6 +++--- spec/views/plantings/show.html.haml_spec.rb | 2 +- .../scientific_names/edit.html.haml_spec.rb | 2 +- spec/views/seeds/new.html.haml_spec.rb | 2 +- spec/views/seeds/show.html.haml_spec.rb | 2 +- 61 files changed, 144 insertions(+), 144 deletions(-) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 2961288dc..3454f33f6 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -57,7 +57,7 @@ describe CommentsController do before { get :edit, params: { id: comment.to_param } } describe "my comment" do - let!(:comment) { FactoryBot.create :comment, author: member, post: post } + let!(:comment) { FactoryBot.create :comment, author: member, post: post } let!(:old_comment) { FactoryBot.create(:comment, post: post, created_at: Time.zone.yesterday) } it "assigns previous comments as @comments" do @@ -90,10 +90,10 @@ describe CommentsController do end describe "attempting to change post_id" do - let(:post) { FactoryBot.create :post, subject: 'our post' } - let(:other_post) { FactoryBot.create :post, subject: 'the other post' } + let(:post) { FactoryBot.create :post, subject: 'our post' } + let(:other_post) { FactoryBot.create :post, subject: 'the other post' } let(:valid_attributes) { { post_id: other_post.id, body: "kōrero" } } - let(:comment) { FactoryBot.create :comment, author: member, post: post } + let(:comment) { FactoryBot.create :comment, author: member, post: post } it "does not change post_id" do comment.reload diff --git a/spec/controllers/harvests_controller_spec.rb b/spec/controllers/harvests_controller_spec.rb index 6853ff477..5e393c59a 100644 --- a/spec/controllers/harvests_controller_spec.rb +++ b/spec/controllers/harvests_controller_spec.rb @@ -13,10 +13,10 @@ describe HarvestsController do end describe "GET index" do - let!(:member1) { FactoryBot.create(:member) } - let(:member2) { FactoryBot.create(:member) } - let(:tomato) { FactoryBot.create(:tomato) } - let(:maize) { FactoryBot.create(:maize) } + let!(:member1) { FactoryBot.create(:member) } + let(:member2) { FactoryBot.create(:member) } + let(:tomato) { FactoryBot.create(:tomato) } + let(:maize) { FactoryBot.create(:maize) } let!(:harvest1) { FactoryBot.create(:harvest, owner_id: member1.id, crop_id: tomato.id) } let!(:harvest2) { FactoryBot.create(:harvest, owner_id: member2.id, crop_id: maize.id) } @@ -127,7 +127,7 @@ describe HarvestsController do describe "not my planting" do let(:not_my_planting) { FactoryBot.create(:planting) } - let(:harvest) { FactoryBot.create(:harvest) } + let(:harvest) { FactoryBot.create(:harvest) } describe "does not save planting_id" do before do @@ -183,7 +183,7 @@ describe HarvestsController do describe "not my planting" do let(:not_my_planting) { FactoryBot.create(:planting) } - let(:harvest) { FactoryBot.create(:harvest) } + let(:harvest) { FactoryBot.create(:harvest) } describe "does not save planting_id" do before do diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index a62c8a9cb..e16d5669d 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' describe LikesController do - let(:like) { FactoryBot.create :like, member: member } - let(:member) { FactoryBot.create(:member) } + let(:like) { FactoryBot.create :like, member: member } + let(:member) { FactoryBot.create(:member) } let(:blogpost) { FactoryBot.create(:post) } - let(:mypost) { FactoryBot.create(:post, author: member) } + let(:mypost) { FactoryBot.create(:post, author: member) } before { sign_in member } diff --git a/spec/controllers/photo_associations_controller_spec.rb b/spec/controllers/photo_associations_controller_spec.rb index 269e90079..311fa01c3 100644 --- a/spec/controllers/photo_associations_controller_spec.rb +++ b/spec/controllers/photo_associations_controller_spec.rb @@ -16,7 +16,7 @@ describe PhotoAssociationsController do describe "my harvest my photo" do let(:harvest) { FactoryBot.create :harvest, owner: member } - let(:photo) { FactoryBot.create :photo, owner: member } + let(:photo) { FactoryBot.create :photo, owner: member } it "removes link" do expect { delete :destroy, params: valid_params }.to change { photo.harvests.count }.by(-1) diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index d81f775f1..18a4d720a 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -15,8 +15,8 @@ describe PhotosController do describe 'crop photos' do let!(:photo) { FactoryBot.create :photo, owner: member } let!(:crop_photo) { FactoryBot.create :photo, owner: member } - let!(:planting) { FactoryBot.create :planting, crop: crop, owner: member } - let!(:crop) { FactoryBot.create :crop } + let!(:planting) { FactoryBot.create :planting, crop: crop, owner: member } + let!(:crop) { FactoryBot.create :crop } before do planting.photos << crop_photo @@ -30,10 +30,10 @@ describe PhotosController do describe "GET new" do let(:tomato) { FactoryBot.create(:tomato) } let(:planting) { FactoryBot.create(:planting, crop: tomato, owner: member) } - let(:garden) { FactoryBot.create(:garden, owner: member) } - let(:harvest) { FactoryBot.create(:harvest, owner: member) } - let(:member) { FactoryBot.create(:member) } - let!(:auth) { FactoryBot.create(:flickr_authentication, member: member) } + let(:garden) { FactoryBot.create(:garden, owner: member) } + let(:harvest) { FactoryBot.create(:harvest, owner: member) } + let(:member) { FactoryBot.create(:member) } + let!(:auth) { FactoryBot.create(:flickr_authentication, member: member) } before do sign_in member @@ -77,10 +77,10 @@ describe PhotosController do end let(:member) { FactoryBot.create(:member) } - let(:garden) { FactoryBot.create(:garden, owner: member) } + let(:garden) { FactoryBot.create(:garden, owner: member) } let(:planting) { FactoryBot.create(:planting, garden: garden, owner: member) } - let(:harvest) { FactoryBot.create(:harvest, owner: member) } - let(:photo) { FactoryBot.create(:photo, owner: member) } + let(:harvest) { FactoryBot.create(:harvest, owner: member) } + let(:photo) { FactoryBot.create(:photo, owner: member) } describe "with valid params" do before { controller.stub(:current_member) { member } } diff --git a/spec/controllers/plantings_controller_spec.rb b/spec/controllers/plantings_controller_spec.rb index d0a5c11a6..4efe2356c 100644 --- a/spec/controllers/plantings_controller_spec.rb +++ b/spec/controllers/plantings_controller_spec.rb @@ -11,10 +11,10 @@ describe PlantingsController do end describe "GET index" do - let!(:member1) { FactoryBot.create(:member) } - let!(:member2) { FactoryBot.create(:member) } - let!(:tomato) { FactoryBot.create(:tomato) } - let!(:maize) { FactoryBot.create(:maize) } + let!(:member1) { FactoryBot.create(:member) } + let!(:member2) { FactoryBot.create(:member) } + let!(:tomato) { FactoryBot.create(:tomato) } + let!(:maize) { FactoryBot.create(:maize) } let!(:planting1) { FactoryBot.create :planting, crop: tomato, owner: member1, created_at: 1.day.ago } let!(:planting2) { FactoryBot.create :planting, crop: maize, owner: member2, created_at: 5.days.ago } diff --git a/spec/features/admin/forums_spec.rb b/spec/features/admin/forums_spec.rb index 87f44f26d..988d4462e 100644 --- a/spec/features/admin/forums_spec.rb +++ b/spec/features/admin/forums_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' feature "forums", js: true do context "as an admin user" do let(:member) { create :admin_member } - let(:forum) { create :forum } + let(:forum) { create :forum } background do login_as member diff --git a/spec/features/cms_spec.rb b/spec/features/cms_spec.rb index 176c531a8..b3370cfbd 100644 --- a/spec/features/cms_spec.rb +++ b/spec/features/cms_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' feature "cms admin" do - let(:member) { create :member } + let(:member) { create :member } let(:admin_member) { create :admin_member } scenario "can't view CMS admin if not signed in" do diff --git a/spec/features/comments/commenting_a_comment_spec.rb b/spec/features/comments/commenting_a_comment_spec.rb index 75024ffb6..67856f9e0 100644 --- a/spec/features/comments/commenting_a_comment_spec.rb +++ b/spec/features/comments/commenting_a_comment_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature 'Commenting on a post' do let(:member) { create :member } - let(:post) { create :post, author: member } + let(:post) { create :post, author: member } background do login_as member diff --git a/spec/features/crops/alternate_name_spec.rb b/spec/features/crops/alternate_name_spec.rb index e3b36c4a8..89780154d 100644 --- a/spec/features/crops/alternate_name_spec.rb +++ b/spec/features/crops/alternate_name_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Alternate names", js: true do let!(:alternate_eggplant) { create :alternate_eggplant } - let(:crop) { alternate_eggplant.crop } + let(:crop) { alternate_eggplant.crop } scenario "Display alternate names on crop page" do visit crop_path(alternate_eggplant.crop) diff --git a/spec/features/crops/browse_crops_spec.rb b/spec/features/crops/browse_crops_spec.rb index 72e63c8fd..1b945c058 100644 --- a/spec/features/crops/browse_crops_spec.rb +++ b/spec/features/crops/browse_crops_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' feature "browse crops" do - let(:tomato) { create :tomato } - let(:maize) { create :maize } - let(:pending_crop) { create :crop_request } + let(:tomato) { create :tomato } + let(:maize) { create :maize } + let(:pending_crop) { create :crop_request } let(:rejected_crop) { create :rejected_crop } scenario "has a form for sorting by" do diff --git a/spec/features/crops/creating_a_crop_spec.rb b/spec/features/crops/creating_a_crop_spec.rb index e03179933..d1c4a9eee 100644 --- a/spec/features/crops/creating_a_crop_spec.rb +++ b/spec/features/crops/creating_a_crop_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Crop - " do let!(:crop_wrangler) { FactoryBot.create :crop_wrangling_member } - let!(:member) { FactoryBot.create :member } + let!(:member) { FactoryBot.create :member } background do login_as member diff --git a/spec/features/crops/crop_detail_page_spec.rb b/spec/features/crops/crop_detail_page_spec.rb index 6f9cba615..7a3155403 100644 --- a/spec/features/crops/crop_detail_page_spec.rb +++ b/spec/features/crops/crop_detail_page_spec.rb @@ -153,7 +153,7 @@ feature "crop detail page", js: true do context "seed quantity for a crop" do let(:member) { create :member } - let(:seed) { create :seed, crop: crop, quantity: 20, owner: member } + let(:seed) { create :seed, crop: crop, quantity: 20, owner: member } scenario "User not signed in" do visit crop_path(seed.crop) diff --git a/spec/features/crops/crop_photos_spec.rb b/spec/features/crops/crop_photos_spec.rb index fae5f84fe..f84442358 100644 --- a/spec/features/crops/crop_photos_spec.rb +++ b/spec/features/crops/crop_photos_spec.rb @@ -8,8 +8,8 @@ feature "crop detail page", js: true do let!(:crop) { FactoryBot.create :crop } let!(:planting) { FactoryBot.create :planting, crop: crop, owner: member } - let!(:harvest) { FactoryBot.create :harvest, crop: crop, owner: member } - let!(:seed) { FactoryBot.create :seed, crop: crop, owner: member } + let!(:harvest) { FactoryBot.create :harvest, crop: crop, owner: member } + let!(:seed) { FactoryBot.create :seed, crop: crop, owner: member } let!(:photo1) { FactoryBot.create(:photo, owner: member) } let!(:photo2) { FactoryBot.create(:photo, owner: member) } diff --git a/spec/features/crops/crop_wranglers_spec.rb b/spec/features/crops/crop_wranglers_spec.rb index 4dc8633ac..8cd5018f3 100644 --- a/spec/features/crops/crop_wranglers_spec.rb +++ b/spec/features/crops/crop_wranglers_spec.rb @@ -3,10 +3,10 @@ require 'rails_helper' feature "crop wranglers", js: true do context "signed in wrangler" do let!(:crop_wranglers) { create_list :crop_wrangling_member, 3 } - let(:wrangler) { crop_wranglers.first } - let!(:crops) { create_list :crop, 2 } + let(:wrangler) { crop_wranglers.first } + let!(:crops) { create_list :crop, 2 } let!(:requested_crop) { create :crop_request } - let!(:rejected_crop) { create :rejected_crop } + let!(:rejected_crop) { create :rejected_crop } background { login_as wrangler } diff --git a/spec/features/crops/crop_wrangling_button_spec.rb b/spec/features/crops/crop_wrangling_button_spec.rb index ede88f003..50be98988 100644 --- a/spec/features/crops/crop_wrangling_button_spec.rb +++ b/spec/features/crops/crop_wrangling_button_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "crop wrangling button" do let(:crop_wrangler) { create :crop_wrangling_member } - let(:member) { create :member } + let(:member) { create :member } context "crop wrangling button" do background do diff --git a/spec/features/crops/delete_crop_spec.rb b/spec/features/crops/delete_crop_spec.rb index 6890c07f8..117e2de3e 100644 --- a/spec/features/crops/delete_crop_spec.rb +++ b/spec/features/crops/delete_crop_spec.rb @@ -2,8 +2,8 @@ require 'rails_helper' feature "Delete crop spec" do context "As a crop wrangler" do - let(:wrangler) { FactoryBot.create :crop_wrangling_member } - let!(:pending_crop) { FactoryBot.create :crop_request } + let(:wrangler) { FactoryBot.create :crop_wrangling_member } + let!(:pending_crop) { FactoryBot.create :crop_request } let!(:approved_crop) { FactoryBot.create :crop } background { login_as wrangler } diff --git a/spec/features/crops/request_new_crop_spec.rb b/spec/features/crops/request_new_crop_spec.rb index 9cccac4f8..6d4061f7e 100644 --- a/spec/features/crops/request_new_crop_spec.rb +++ b/spec/features/crops/request_new_crop_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Requesting a new crop" do context "As a regular member" do - let(:member) { create :member } + let(:member) { create :member } let!(:wrangler) { create :crop_wrangling_member } background do @@ -21,7 +21,7 @@ feature "Requesting a new crop" do context "As a crop wrangler" do let(:wrangler) { create :crop_wrangling_member } - let!(:crop) { create :crop_request } + let!(:crop) { create :crop_request } let!(:already_approved) { create :crop } background { login_as wrangler } diff --git a/spec/features/crops/requested_crops_spec.rb b/spec/features/crops/requested_crops_spec.rb index 15226efe4..042a3dff7 100644 --- a/spec/features/crops/requested_crops_spec.rb +++ b/spec/features/crops/requested_crops_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' feature "Crop - " do - let(:member) { create :member } + let(:member) { create :member } let!(:requested_crop) { create :crop, requester: member, approval_status: 'pending', name: 'puha for dinner' } background do diff --git a/spec/features/crops/show_spec.rb b/spec/features/crops/show_spec.rb index e7bfc0358..90c675211 100644 --- a/spec/features/crops/show_spec.rb +++ b/spec/features/crops/show_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' feature "browse crops" do - let(:tomato) { create :tomato } - let(:maize) { create :maize } - let(:pending_crop) { create :crop_request } + let(:tomato) { create :tomato } + let(:maize) { create :maize } + let(:pending_crop) { create :crop_request } let(:rejected_crop) { create :rejected_crop } scenario "Show crop info" do diff --git a/spec/features/gardens/gardens_index_spec.rb b/spec/features/gardens/gardens_index_spec.rb index 0c29e3df6..2e559cd50 100644 --- a/spec/features/gardens/gardens_index_spec.rb +++ b/spec/features/gardens/gardens_index_spec.rb @@ -72,7 +72,7 @@ feature "Gardens#index", :js do describe 'badges' do let(:garden) { member.gardens.first } let(:member) { FactoryBot.create :member, login_name: 'robbieburns' } - let(:crop) { FactoryBot.create :crop } + let(:crop) { FactoryBot.create :crop } before do # time to harvest = 50 day diff --git a/spec/features/gardens_spec.rb b/spec/features/gardens_spec.rb index ab88ea9ea..b436e947c 100644 --- a/spec/features/gardens_spec.rb +++ b/spec/features/gardens_spec.rb @@ -2,9 +2,9 @@ require 'rails_helper' feature "Planting a crop", js: true do # name is aaa to ensure it is ordered first - let!(:garden) { create :garden, name: 'aaa' } - let!(:planting) { create :planting, garden: garden, owner: garden.owner, planted_at: Date.parse("2013-3-10") } - let!(:tomato) { create :tomato } + let!(:garden) { create :garden, name: 'aaa' } + let!(:planting) { create :planting, garden: garden, owner: garden.owner, planted_at: Date.parse("2013-3-10") } + let!(:tomato) { create :tomato } let!(:finished_planting) { create :finished_planting, owner: garden.owner, garden: garden, crop: tomato } background do diff --git a/spec/features/harvests/browse_harvests_spec.rb b/spec/features/harvests/browse_harvests_spec.rb index cadbc19e7..597565aed 100644 --- a/spec/features/harvests/browse_harvests_spec.rb +++ b/spec/features/harvests/browse_harvests_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' feature "browse harvests" do subject { page } - let!(:member) { create :member } + let!(:member) { create :member } let!(:harvest) { create :harvest, owner: member } background { login_as member } diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index a39c54c8a..7173658bb 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -2,10 +2,10 @@ require 'rails_helper' require 'custom_matchers' feature "Harvesting a crop", :js, :elasticsearch do - let(:member) { create :member } - let!(:maize) { create :maize } + let(:member) { create :member } + let!(:maize) { create :maize } let!(:plant_part) { create :plant_part } - let(:planting) { create :planting, crop: maize, owner: member } + let(:planting) { create :planting, crop: maize, owner: member } background do login_as member @@ -93,7 +93,7 @@ feature "Harvesting a crop", :js, :elasticsearch do end context "Editing a harvest" do - let(:existing_harvest) { create :harvest, crop: maize, owner: member } + let(:existing_harvest) { create :harvest, crop: maize, owner: member } let!(:other_plant_part) { create :plant_part, name: 'chocolate' } background do diff --git a/spec/features/home/home_spec.rb b/spec/features/home/home_spec.rb index 812f84710..4036cb957 100644 --- a/spec/features/home/home_spec.rb +++ b/spec/features/home/home_spec.rb @@ -9,11 +9,11 @@ feature "home page" do let(:crop) { FactoryBot.create :crop, created_at: 1.day.ago } let(:planting) { FactoryBot.create :planting, owner: member, crop: crop } - let(:seed) { FactoryBot.create :tradable_seed, owner: member, crop: crop } + let(:seed) { FactoryBot.create :tradable_seed, owner: member, crop: crop } let(:harvest) { FactoryBot.create :harvest, owner: member, crop: crop } let!(:tradable_seed) { FactoryBot.create :tradable_seed, finished: false } - let!(:finished_seed) { FactoryBot.create :tradable_seed, finished: true } + let!(:finished_seed) { FactoryBot.create :tradable_seed, finished: true } let!(:untradable_seed) { FactoryBot.create :untradable_seed } background do diff --git a/spec/features/likeable_spec.rb b/spec/features/likeable_spec.rb index f0bfd15a8..a45b9a1d8 100644 --- a/spec/features/likeable_spec.rb +++ b/spec/features/likeable_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' feature 'Likeable', js: true do - let(:member) { FactoryBot.create(:member) } + let(:member) { FactoryBot.create(:member) } let(:another_member) { FactoryBot.create(:london_member) } - let(:post) { FactoryBot.create(:post) } + let(:post) { FactoryBot.create(:post) } context 'logged in member' do background do diff --git a/spec/features/member_profile_spec.rb b/spec/features/member_profile_spec.rb index ab1a1fdbc..56d7d1fae 100644 --- a/spec/features/member_profile_spec.rb +++ b/spec/features/member_profile_spec.rb @@ -103,8 +103,8 @@ feature "member profile", js: true do context "signed in member" do let(:member) { create :member } - let(:other_member) { create :member } - let(:admin_member) { create :admin_member } + let(:other_member) { create :member } + let(:admin_member) { create :admin_member } let(:crop_wrangler) { create :crop_wrangling_member } background do diff --git a/spec/features/members/deletion_spec.rb b/spec/features/members/deletion_spec.rb index 3e5cb2e88..65570e1ca 100644 --- a/spec/features/members/deletion_spec.rb +++ b/spec/features/members/deletion_spec.rb @@ -2,15 +2,15 @@ require 'rails_helper' feature "member deletion" do context "with activity and followers" do - let(:member) { FactoryBot.create(:member) } - let(:other_member) { FactoryBot.create(:member) } - let(:memberpost) { FactoryBot.create(:post, author: member) } + let(:member) { FactoryBot.create(:member) } + let(:other_member) { FactoryBot.create(:member) } + let(:memberpost) { FactoryBot.create(:post, author: member) } let(:othermemberpost) { FactoryBot.create(:post, author: other_member) } - let!(:planting) { FactoryBot.create(:planting, owner: member) } - let!(:harvest) { FactoryBot.create(:harvest, owner: member) } - let!(:seed) { FactoryBot.create(:seed, owner: member) } - let!(:secondgarden) { FactoryBot.create(:garden, owner: member) } - let(:admin) { FactoryBot.create(:admin_member) } + let!(:planting) { FactoryBot.create(:planting, owner: member) } + let!(:harvest) { FactoryBot.create(:harvest, owner: member) } + let!(:seed) { FactoryBot.create(:seed, owner: member) } + let!(:secondgarden) { FactoryBot.create(:garden, owner: member) } + let(:admin) { FactoryBot.create(:admin_member) } background do login_as(member) @@ -141,7 +141,7 @@ feature "member deletion" do context "for a crop wrangler" do let(:member) { FactoryBot.create(:crop_wrangling_member) } let(:otherwrangler) { FactoryBot.create(:crop_wrangling_member) } - let(:crop) { FactoryBot.create(:crop, creator: member) } + let(:crop) { FactoryBot.create(:crop, creator: member) } FactoryBot.create(:cropbot) let!(:ex_wrangler) { FactoryBot.create(:crop_wrangling_member, login_name: "ex_wrangler") } diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 05e6e2b9a..b0ed36c6e 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' feature "Notifications", :js do - let(:sender) { create :member } + let(:sender) { create :member } let(:recipient) { create :member, login_name: 'beyonce' } context "On existing notification" do diff --git a/spec/features/places/searching_a_place_spec.rb b/spec/features/places/searching_a_place_spec.rb index fb11308b5..bec7cde68 100644 --- a/spec/features/places/searching_a_place_spec.rb +++ b/spec/features/places/searching_a_place_spec.rb @@ -1,10 +1,10 @@ require "rails_helper" feature "User searches" do - let(:member) { create :member, location: "Philippines" } - let!(:maize) { create :maize } - let(:garden) { create :garden, owner: member } - let!(:seed1) { create :seed, owner: member } + let(:member) { create :member, location: "Philippines" } + let!(:maize) { create :maize } + let(:garden) { create :garden, owner: member } + let!(:seed1) { create :seed, owner: member } let!(:planting) { create :planting, garden: garden, owner: member, planted_at: Date.parse("2013-3-10") } scenario "with a valid place" do diff --git a/spec/features/planting_reminder_spec.rb b/spec/features/planting_reminder_spec.rb index 3b407c3df..53f0993da 100644 --- a/spec/features/planting_reminder_spec.rb +++ b/spec/features/planting_reminder_spec.rb @@ -3,7 +3,7 @@ require 'capybara/email/rspec' feature "Planting reminder email", :js do let(:member) { create :member } - let(:mail) { Notifier.planting_reminder(member) } + let(:mail) { Notifier.planting_reminder(member) } # Unfortunately, we can't use the default url options for ActionMailer as configured in # test.rb, since this isn't a mailer spec. diff --git a/spec/features/scientific_name_spec.rb b/spec/features/scientific_name_spec.rb index d6daf709b..009d9d3f7 100644 --- a/spec/features/scientific_name_spec.rb +++ b/spec/features/scientific_name_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Scientific names", js: true do let!(:zea_mays) { create :zea_mays } - let(:crop) { zea_mays.crop } + let(:crop) { zea_mays.crop } scenario "Display scientific names on crop page" do visit crop_path(zea_mays.crop) diff --git a/spec/features/seeds/seed_photos.rb b/spec/features/seeds/seed_photos.rb index ff8fd1db0..089d4b181 100644 --- a/spec/features/seeds/seed_photos.rb +++ b/spec/features/seeds/seed_photos.rb @@ -9,7 +9,7 @@ feature "Seeds", :js do end let(:member) { FactoryBot.create :member } - let!(:seed) { FactoryBot.create :seed, owner: member } + let!(:seed) { FactoryBot.create :seed, owner: member } it { is_expected.to have_content 'Add photo' } diff --git a/spec/features/shared_examples/append_date.rb b/spec/features/shared_examples/append_date.rb index fcb6d515b..843730ff7 100644 --- a/spec/features/shared_examples/append_date.rb +++ b/spec/features/shared_examples/append_date.rb @@ -1,6 +1,6 @@ shared_examples "append date" do let(:this_month) { Time.zone.today.strftime("%B") } - let(:this_year) { Time.zone.today.strftime("%Y") } + let(:this_year) { Time.zone.today.strftime("%Y") } background { visit path } diff --git a/spec/features/shared_examples/crop_suggest.rb b/spec/features/shared_examples/crop_suggest.rb index 0d2e688a1..2c86fea0d 100644 --- a/spec/features/shared_examples/crop_suggest.rb +++ b/spec/features/shared_examples/crop_suggest.rb @@ -1,10 +1,10 @@ require 'rails_helper' shared_examples "crop suggest" do |resource| - let!(:pea) { create :crop, name: 'pea' } - let!(:pear) { create :pear } + let!(:pea) { create :crop, name: 'pea' } + let!(:pear) { create :pear } let!(:tomato) { create :tomato } - let!(:roma) { create :roma } + let!(:roma) { create :roma } background { sync_elasticsearch [pea, pear, maize, tomato] } diff --git a/spec/features/signin_spec.rb b/spec/features/signin_spec.rb index 7f362abf3..2f9f1c1c7 100644 --- a/spec/features/signin_spec.rb +++ b/spec/features/signin_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' feature "signin", js: true do - let(:member) { FactoryBot.create :member } - let(:recipient) { FactoryBot.create :member } - let(:wrangler) { FactoryBot.create :crop_wrangling_member } + let(:member) { FactoryBot.create :member } + let(:recipient) { FactoryBot.create :member } + let(:wrangler) { FactoryBot.create :crop_wrangling_member } let(:notification) { FactoryBot.create :notification, recipient: recipient } def login diff --git a/spec/features/unsubscribing_spec.rb b/spec/features/unsubscribing_spec.rb index 8244d207a..812dc8266 100644 --- a/spec/features/unsubscribing_spec.rb +++ b/spec/features/unsubscribing_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' require 'capybara/email/rspec' feature "unsubscribe" do - let(:member) { create :member } + let(:member) { create :member } let(:notification) { create :notification } background do diff --git a/spec/helpers/buttons_helper_spec.rb b/spec/helpers/buttons_helper_spec.rb index d16d01f0e..b2112740e 100644 --- a/spec/helpers/buttons_helper_spec.rb +++ b/spec/helpers/buttons_helper_spec.rb @@ -13,10 +13,10 @@ require 'rails_helper' RSpec.describe ButtonsHelper, type: :helper do before { allow(self).to receive(:can?).and_return(true) } - let(:garden) { FactoryBot.create :garden } + let(:garden) { FactoryBot.create :garden } let(:planting) { FactoryBot.create :planting } - let(:harvest) { FactoryBot.create :harvest } - let(:seed) { FactoryBot.create :seed } + let(:harvest) { FactoryBot.create :harvest } + let(:seed) { FactoryBot.create :seed } describe 'add_photo_button' do it { expect(add_photo_button(garden)).to include "/photos/new?id=#{garden.id}&type=garden" } diff --git a/spec/helpers/photos_helper_spec.rb b/spec/helpers/photos_helper_spec.rb index 0533b6058..d52bf74c9 100644 --- a/spec/helpers/photos_helper_spec.rb +++ b/spec/helpers/photos_helper_spec.rb @@ -5,13 +5,13 @@ describe PhotosHelper do let(:garden) { FactoryBot.create :garden } - let(:garden_photo) { FactoryBot.create(:photo, thumbnail_url: 'garden.jpg', owner: garden.owner) } - let(:planting) { FactoryBot.create :planting, crop: crop, owner: garden.owner } + let(:garden_photo) { FactoryBot.create(:photo, thumbnail_url: 'garden.jpg', owner: garden.owner) } + let(:planting) { FactoryBot.create :planting, crop: crop, owner: garden.owner } let(:planting_photo) { FactoryBot.create(:photo, thumbnail_url: 'planting.jpg', owner: garden.owner) } - let(:harvest) { FactoryBot.create :harvest, crop: crop, owner: garden.owner } - let(:harvest_photo) { FactoryBot.create(:photo, thumbnail_url: 'harvest.jpg', owner: garden.owner) } - let(:seed) { FactoryBot.create :seed, crop: crop, owner: garden.owner } - let(:seed_photo) { FactoryBot.create(:photo, thumbnail_url: 'seed.jpg', owner: garden.owner) } + let(:harvest) { FactoryBot.create :harvest, crop: crop, owner: garden.owner } + let(:harvest_photo) { FactoryBot.create(:photo, thumbnail_url: 'harvest.jpg', owner: garden.owner) } + let(:seed) { FactoryBot.create :seed, crop: crop, owner: garden.owner } + let(:seed_photo) { FactoryBot.create(:photo, thumbnail_url: 'seed.jpg', owner: garden.owner) } describe "crops" do subject { crop_image_path(crop) } diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 27677eab6..8b1494c0b 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe Notifier do describe "notifications" do let(:notification) { FactoryBot.create(:notification) } - let(:mail) { Notifier.notify(notification) } + let(:mail) { Notifier.notify(notification) } it 'sets the subject correctly' do mail.subject.should == notification.subject diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index 7fa8bf9c6..e6fc1c709 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' require 'cancan/matchers' describe Ability do - let(:member) { FactoryBot.create(:member) } + let(:member) { FactoryBot.create(:member) } let(:ability) { Ability.new(member) } context "notifications" do diff --git a/spec/models/alternate_name_spec.rb b/spec/models/alternate_name_spec.rb index b7c4303e9..380904164 100644 --- a/spec/models/alternate_name_spec.rb +++ b/spec/models/alternate_name_spec.rb @@ -21,7 +21,7 @@ describe AlternateName do describe 'relationships' do let(:alternate_name) { FactoryBot.create :alternate_name, crop: crop, creator: member } - let(:crop) { FactoryBot.create :crop } + let(:crop) { FactoryBot.create :crop } let(:member) { FactoryBot.create :member } it { expect(alternate_name.crop).to eq crop } diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 35a429656..f035bcdbf 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' describe Crop do - let(:pp2) { FactoryBot.create(:plant_part) } - let(:pp1) { FactoryBot.create(:plant_part) } + let(:pp2) { FactoryBot.create(:plant_part) } + let(:pp1) { FactoryBot.create(:plant_part) } let(:maize) { FactoryBot.create(:maize) } context 'all fields present' do let(:crop) { FactoryBot.create(:tomato) } @@ -48,8 +48,8 @@ describe Crop do end context 'popularity' do - let(:tomato) { FactoryBot.create(:tomato) } - let(:maize) { FactoryBot.create(:maize) } + let(:tomato) { FactoryBot.create(:tomato) } + let(:maize) { FactoryBot.create(:maize) } let(:cucumber) { FactoryBot.create(:crop, name: 'cucumber') } before do @@ -337,9 +337,9 @@ describe Crop do end context "harvests" do - let(:h1) { FactoryBot.create(:harvest, crop: maize, plant_part: pp1) } - let(:h2) { FactoryBot.create(:harvest, crop: maize, plant_part: pp2) } - let!(:crop) { FactoryBot.create(:crop) } + let(:h1) { FactoryBot.create(:harvest, crop: maize, plant_part: pp1) } + let(:h2) { FactoryBot.create(:harvest, crop: maize, plant_part: pp2) } + let!(:crop) { FactoryBot.create(:crop) } let!(:harvest) { FactoryBot.create(:harvest, crop: crop) } it "has harvests" do @@ -544,8 +544,8 @@ describe Crop do context "crop-post association" do let!(:tomato) { FactoryBot.create(:tomato) } - let!(:maize) { FactoryBot.create(:maize) } - let!(:post) { FactoryBot.create(:post, body: "[maize](crop)[tomato](crop)[tomato](crop)") } + let!(:maize) { FactoryBot.create(:maize) } + let!(:post) { FactoryBot.create(:post, body: "[maize](crop)[tomato](crop)[tomato](crop)") } describe "destroying a crop" do before do diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 67c462bb6..9ebcbdfb8 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Garden do - let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } + let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } it "has a slug" do @@ -57,10 +57,10 @@ describe Garden do context "featured plantings" do let(:tomato) { FactoryBot.create(:tomato) } - let(:maize) { FactoryBot.create(:maize) } - let(:chard) { FactoryBot.create(:chard) } - let(:apple) { FactoryBot.create(:apple) } - let(:pear) { FactoryBot.create(:pear) } + let(:maize) { FactoryBot.create(:maize) } + let(:chard) { FactoryBot.create(:chard) } + let(:apple) { FactoryBot.create(:apple) } + let(:pear) { FactoryBot.create(:pear) } let(:walnut) { FactoryBot.create(:walnut) } it "fetches < 4 featured plantings if insufficient exist" do diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb index 6c47dcddb..7a199e584 100644 --- a/spec/models/like_spec.rb +++ b/spec/models/like_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe 'like' do let(:member) { FactoryBot.create(:member) } - let(:post) { FactoryBot.create(:post) } + let(:post) { FactoryBot.create(:post) } context 'existing like' do before do diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 0f015ae3f..ffe4f7544 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -175,7 +175,7 @@ describe 'member' do context 'roles' do let(:member) { FactoryBot.create(:member) } - let(:role) { FactoryBot.create(:role) } + let(:role) { FactoryBot.create(:role) } before do member.roles << role diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index a839b6758..c262c473a 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -1,13 +1,13 @@ require 'rails_helper' describe Photo do - let(:photo) { FactoryBot.create(:photo, owner: member) } + let(:photo) { FactoryBot.create(:photo, owner: member) } let(:member) { FactoryBot.create(:member) } describe 'add/delete functionality' do let(:planting) { FactoryBot.create(:planting, owner: member) } let(:harvest) { FactoryBot.create(:harvest, owner: member) } - let(:garden) { FactoryBot.create(:garden, owner: member) } + let(:garden) { FactoryBot.create(:garden, owner: member) } context "adds photos" do it 'to a planting' do @@ -129,15 +129,15 @@ describe Photo do describe 'scopes' do let(:harvest_crop) { FactoryBot.create :crop } - let!(:harvest) { FactoryBot.create :harvest, owner: member, crop: harvest_crop } + let!(:harvest) { FactoryBot.create :harvest, owner: member, crop: harvest_crop } let!(:harvest_photo) { FactoryBot.create :photo, owner: member } let(:planting_crop) { FactoryBot.create :crop } - let!(:planting) { FactoryBot.create :planting, owner: member, crop: planting_crop } + let!(:planting) { FactoryBot.create :planting, owner: member, crop: planting_crop } let!(:planting_photo) { FactoryBot.create :photo, owner: member } let(:seed_crop) { FactoryBot.create :crop } - let!(:seed) { FactoryBot.create :seed, owner: member, crop: seed_crop } + let!(:seed) { FactoryBot.create :seed, owner: member, crop: seed_crop } let!(:seed_photo) { FactoryBot.create :photo, owner: member } before do harvest.photos << harvest_photo diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 1ff33dccd..9c5b02eaf 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' describe Planting do - let(:crop) { FactoryBot.create(:tomato) } + let(:crop) { FactoryBot.create(:tomato) } let(:garden_owner) { FactoryBot.create(:member, login_name: 'hatupatu') } - let(:garden) { FactoryBot.create(:garden, owner: garden_owner, name: 'Springfield Community Garden') } - let(:planting) { FactoryBot.create(:planting, crop: crop, garden: garden, owner: garden.owner) } + let(:garden) { FactoryBot.create(:garden, owner: garden_owner, name: 'Springfield Community Garden') } + let(:planting) { FactoryBot.create(:planting, crop: crop, garden: garden, owner: garden.owner) } let(:finished_planting) do FactoryBot.create :planting, planted_at: 4.days.ago, finished_at: 2.days.ago, finished: true end @@ -72,7 +72,7 @@ describe Planting do end describe 'child crop uses parent data' do - let(:child_crop) { FactoryBot.create :crop, parent: crop, name: 'child' } + let(:child_crop) { FactoryBot.create :crop, parent: crop, name: 'child' } let(:child_planting) { FactoryBot.create :planting, crop: child_crop, planted_at: 30.days.ago } # not data for this crop diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 7d79a62a7..127f1ad7e 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -134,7 +134,7 @@ describe Post do let!(:tomato) { FactoryBot.create(:tomato) } let!(:maize) { FactoryBot.create(:maize) } let!(:chard) { FactoryBot.create(:chard) } - let!(:post) { FactoryBot.create(:post, body: "[maize](crop)[tomato](crop)[tomato](crop)") } + let!(:post) { FactoryBot.create(:post, body: "[maize](crop)[tomato](crop)[tomato](crop)") } it "is generated" do expect(tomato.posts).to eq [post] diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index 5991d336b..83f3f1cb8 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe Seed do let(:owner) { FactoryBot.create :owner, login_name: 'tamateapokaiwhenua' } - let(:seed) { FactoryBot.build(:seed, owner: owner) } + let(:seed) { FactoryBot.build(:seed, owner: owner) } it 'saves a basic seed' do seed.save.should be(true) @@ -162,7 +162,7 @@ describe Seed do context 'ancestry' do let(:parent_planting) { FactoryBot.create :planting } - let(:seed) { FactoryBot.create :seed, parent_planting: parent_planting, owner: parent_planting.owner } + let(:seed) { FactoryBot.create :seed, parent_planting: parent_planting, owner: parent_planting.owner } it "seed has a parent planting" do expect(seed.parent_planting).to eq(parent_planting) @@ -181,7 +181,7 @@ describe Seed do end describe 'scopes' do - let!(:seed) { FactoryBot.create(:seed) } + let!(:seed) { FactoryBot.create(:seed) } let!(:finished_seed) { FactoryBot.create(:finished_seed) } describe 'has finished scope' do diff --git a/spec/requests/api/v1/crop_request_spec.rb b/spec/requests/api/v1/crop_request_spec.rb index 662b27c46..6d8353d69 100644 --- a/spec/requests/api/v1/crop_request_spec.rb +++ b/spec/requests/api/v1/crop_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Plantings', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:crop) { FactoryBot.create :crop } + let!(:crop) { FactoryBot.create :crop } let(:crop_encoded_as_json_api) do { "id" => crop.id.to_s, "type" => "crops", diff --git a/spec/requests/api/v1/harvest_request_spec.rb b/spec/requests/api/v1/harvest_request_spec.rb index 5b1c9b0a8..597714060 100644 --- a/spec/requests/api/v1/harvest_request_spec.rb +++ b/spec/requests/api/v1/harvest_request_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe 'Harvests', type: :request do subject { JSON.parse response.body } - let(:headers) { { 'Accept' => 'application/vnd.api+json' } } + let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let!(:harvest) { FactoryBot.create :harvest } let(:harvest_encoded_as_json_api) do { "id" => harvest.id.to_s, diff --git a/spec/requests/api/v1/photos_request_spec.rb b/spec/requests/api/v1/photos_request_spec.rb index 833e5499c..118aa4fcc 100644 --- a/spec/requests/api/v1/photos_request_spec.rb +++ b/spec/requests/api/v1/photos_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Photos', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:photo) { FactoryBot.create :photo } + let!(:photo) { FactoryBot.create :photo } let(:photo_encoded_as_json_api) do { "id" => photo.id.to_s, "type" => "photos", diff --git a/spec/requests/api/v1/plantings_request_spec.rb b/spec/requests/api/v1/plantings_request_spec.rb index 0a9ca54dc..2085fd85f 100644 --- a/spec/requests/api/v1/plantings_request_spec.rb +++ b/spec/requests/api/v1/plantings_request_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe 'Plantings', type: :request do subject { JSON.parse response.body } - let(:headers) { { 'Accept' => 'application/vnd.api+json' } } + let(:headers) { { 'Accept' => 'application/vnd.api+json' } } let!(:planting) { FactoryBot.create :planting } let(:planting_encoded_as_json_api) do { "id" => planting.id.to_s, diff --git a/spec/requests/api/v1/seeds_request_spec.rb b/spec/requests/api/v1/seeds_request_spec.rb index 000d55e14..3bde1af9d 100644 --- a/spec/requests/api/v1/seeds_request_spec.rb +++ b/spec/requests/api/v1/seeds_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Photos', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:seed) { FactoryBot.create :seed } + let!(:seed) { FactoryBot.create :seed } let(:seed_encoded_as_json_api) do { "id" => seed.id.to_s, "type" => "seeds", diff --git a/spec/views/crops/_grown_for.html.haml_spec.rb b/spec/views/crops/_grown_for.html.haml_spec.rb index ccb04b28d..0aef069c3 100644 --- a/spec/views/crops/_grown_for.html.haml_spec.rb +++ b/spec/views/crops/_grown_for.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "crops/_grown_for" do - let(:crop) { FactoryBot.create(:crop) } + let(:crop) { FactoryBot.create(:crop) } let(:plant_path) { FactoryBot.create(:plant_part) } let!(:harvest) do FactoryBot.create(:harvest, diff --git a/spec/views/photos/show.html.haml_spec.rb b/spec/views/photos/show.html.haml_spec.rb index 162477aa5..fb3ad8859 100644 --- a/spec/views/photos/show.html.haml_spec.rb +++ b/spec/views/photos/show.html.haml_spec.rb @@ -10,10 +10,10 @@ describe "photos/show" do let(:member) { FactoryBot.create :member } - let(:harvest) { FactoryBot.create :harvest, owner: member } + let(:harvest) { FactoryBot.create :harvest, owner: member } let(:planting) { FactoryBot.create :planting, owner: member } - let(:seed) { FactoryBot.create :seed, owner: member } - let(:garden) { FactoryBot.create :garden, owner: member } + let(:seed) { FactoryBot.create :seed, owner: member } + let(:garden) { FactoryBot.create :garden, owner: member } shared_examples "photo data renders" do it "shows the image" do diff --git a/spec/views/plantings/show.html.haml_spec.rb b/spec/views/plantings/show.html.haml_spec.rb index 1d12e6f6d..dfd503743 100644 --- a/spec/views/plantings/show.html.haml_spec.rb +++ b/spec/views/plantings/show.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "plantings/show" do - let(:crop) { FactoryBot.create(:tomato) } + let(:crop) { FactoryBot.create(:tomato) } let(:member) { FactoryBot.create(:member) } let(:garden) { FactoryBot.create(:garden, owner: member) } let(:planting) do diff --git a/spec/views/scientific_names/edit.html.haml_spec.rb b/spec/views/scientific_names/edit.html.haml_spec.rb index 5cf1b6fe6..7c2a9de1e 100644 --- a/spec/views/scientific_names/edit.html.haml_spec.rb +++ b/spec/views/scientific_names/edit.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe "scientific_names/edit" do context "logged in" do - let(:member) { FactoryBot.create(:member) } + let(:member) { FactoryBot.create(:member) } let(:scientific_name) { FactoryBot.create(:zea_mays, creator: member) } before do diff --git a/spec/views/seeds/new.html.haml_spec.rb b/spec/views/seeds/new.html.haml_spec.rb index 2a132c432..6b6d6e48d 100644 --- a/spec/views/seeds/new.html.haml_spec.rb +++ b/spec/views/seeds/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "seeds/new" do - let!(:seed) { FactoryBot.create(:seed, owner: member) } + let!(:seed) { FactoryBot.create(:seed, owner: member) } let!(:member) { FactoryBot.create(:member) } before do diff --git a/spec/views/seeds/show.html.haml_spec.rb b/spec/views/seeds/show.html.haml_spec.rb index 2426495be..cd7507601 100644 --- a/spec/views/seeds/show.html.haml_spec.rb +++ b/spec/views/seeds/show.html.haml_spec.rb @@ -17,7 +17,7 @@ describe "seeds/show" do context "tradable" do context 'with location' do let!(:owner) { FactoryBot.create(:london_member) } - let!(:seed) { FactoryBot.create(:tradable_seed, owner: owner) } + let!(:seed) { FactoryBot.create(:tradable_seed, owner: owner) } let!(:member) { FactoryBot.create(:member) } before do From 5145ead93b392aa68d2561a7a334508993aa8ff2 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Tue, 12 Mar 2019 22:51:12 +0000 Subject: [PATCH 018/124] Auto corrected by following Lint Ruby RSpecEmptyLine --- spec/controllers/comments_controller_spec.rb | 1 + spec/controllers/crops_controller_spec.rb | 8 ++++++++ spec/controllers/likes_controller_spec.rb | 1 + spec/controllers/photos_controller_spec.rb | 3 +++ spec/features/photos/show_photo_spec.rb | 4 ++++ spec/features/signout_spec.rb | 1 + spec/models/crop_spec.rb | 1 + spec/models/photo_spec.rb | 1 + 8 files changed, 20 insertions(+) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 3454f33f6..07f5ad149 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -36,6 +36,7 @@ describe CommentsController do before { get :new, params: { post_id: post.id } } let(:old_comment) { FactoryBot.create(:comment, post: post) } + it "picks up post from params" do expect(assigns(:post)).to eq(post) end diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index 112d768cd..b683715a3 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -11,11 +11,14 @@ describe CropsController do describe 'fetches the crop wrangler homepage' do context 'anonymous' do before { get :wrangle } + it { is_expected.not_to be_success } end + context 'wrangler' do include_context 'login as wrangler' before { get :wrangle } + it { is_expected.to be_success } it { is_expected.to render_template("crops/wrangle") } it { expect(assigns[:crop_wranglers]).to eq(Role.crop_wranglers) } @@ -28,6 +31,7 @@ describe CropsController do context 'wrangler' do include_context 'login as wrangler' before { get :hierarchy } + it { is_expected.to be_success } it { is_expected.to render_template("crops/hierarchy") } end @@ -55,13 +59,17 @@ describe CropsController do describe 'DELETE destroy' do let!(:crop) { FactoryBot.create :crop } + subject { delete :destroy, params: { slug: crop.to_param } } + context 'not logged in' do it { expect { subject }.not_to change { Crop.count } } end + context 'logged in as member' do it { expect { subject }.not_to change { Crop.count } } end + context 'wrangler' do include_context 'login as wrangler' it { expect { subject }.to change { Crop.count }.by -1 } diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index e16d5669d..516cc368f 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -10,6 +10,7 @@ describe LikesController do describe "POST create" do before { post :create, params: { post_id: blogpost.id, format: :json } } + it { expect(response.content_type).to eq "application/json" } it { expect(Like.last.likeable_id).to eq(blogpost.id) } diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 18a4d720a..5b5f5f23c 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -8,7 +8,9 @@ describe PhotosController do describe 'GET index' do describe 'all photos' do let!(:photo) { FactoryBot.create :photo } + before { get :index } + it { expect(assigns(:photos)).to eq [photo] } end @@ -22,6 +24,7 @@ describe PhotosController do planting.photos << crop_photo get :index, params: { crop_slug: crop.to_param } end + it { expect(assigns(:crop)).to eq crop } it { expect(assigns(:photos)).to eq [crop_photo] } end diff --git a/spec/features/photos/show_photo_spec.rb b/spec/features/photos/show_photo_spec.rb index c2a23f3a7..973aa349a 100644 --- a/spec/features/photos/show_photo_spec.rb +++ b/spec/features/photos/show_photo_spec.rb @@ -15,6 +15,7 @@ feature "show photo page" do planting.photos << photo visit photo_path(photo) end + it { expect(page).to have_link "#{planting.crop.name} planting in #{planting.garden.name} by #{planting.owner}", href: planting_path(planting) @@ -32,6 +33,7 @@ feature "show photo page" do harvest.photos << photo visit photo_path(photo) end + it { expect(page).to have_link "#{harvest.crop.name} harvest by #{harvest.owner}", href: harvest_path(harvest) } it { expect(page).to have_link harvest.crop.name } end @@ -46,6 +48,7 @@ feature "show photo page" do garden.photos << photo visit photo_path(photo) end + it { expect(page).to have_link "garden named \"#{garden.name}\" by #{garden.owner}", href: garden_path(garden) } end end @@ -59,6 +62,7 @@ feature "show photo page" do seed.photos << photo visit photo_path(photo) end + it { expect(page).to have_link "#{seed.crop.name} seeds belonging to #{seed.owner}", href: seed_path(seed) } it { expect(page).to have_link seed.crop.name } end diff --git a/spec/features/signout_spec.rb b/spec/features/signout_spec.rb index 2b020a4c2..2ccfd17dc 100644 --- a/spec/features/signout_spec.rb +++ b/spec/features/signout_spec.rb @@ -4,6 +4,7 @@ feature "signout" do let(:member) { create :member } let(:path) {} + scenario "redirect to previous page after signout" do visit crops_path # some random page click_link 'Sign in' diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index f035bcdbf..bb808fb68 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -4,6 +4,7 @@ describe Crop do let(:pp2) { FactoryBot.create(:plant_part) } let(:pp1) { FactoryBot.create(:plant_part) } let(:maize) { FactoryBot.create(:maize) } + context 'all fields present' do let(:crop) { FactoryBot.create(:tomato) } diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index c262c473a..920d57f19 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -139,6 +139,7 @@ describe Photo do let(:seed_crop) { FactoryBot.create :crop } let!(:seed) { FactoryBot.create :seed, owner: member, crop: seed_crop } let!(:seed_photo) { FactoryBot.create :photo, owner: member } + before do harvest.photos << harvest_photo planting.photos << planting_photo From fca035e537dde326ab49472ab847aaea147b91b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 12 Mar 2019 22:47:44 +0000 Subject: [PATCH 019/124] Bump rubocop from 0.64.0 to 0.65.0 Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.64.0 to 0.65.0. - [Release notes](https://github.com/rubocop-hq/rubocop/releases) - [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.64.0...v0.65.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f48b25d97..348f90af0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -323,7 +323,7 @@ GEM omniauth-oauth (~> 1.1) rack orm_adapter (0.5.0) - parallel (1.13.0) + parallel (1.14.0) paranoia (2.4.1) activerecord (>= 4.0, < 5.3) parser (2.6.0.0) @@ -337,6 +337,7 @@ GEM cliver (~> 0.3.1) websocket-driver (>= 0.2.0) powerpack (0.1.2) + psych (3.1.0) public_suffix (3.0.3) puma (3.12.0) rack (2.0.6) @@ -415,11 +416,12 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.64.0) + rubocop (0.65.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5, != 2.5.1.1) powerpack (~> 0.1) + psych (>= 3.1.0) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.4.0) From f488e0aeb141200f048cf4960f3dd68520b0453f Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Wed, 13 Mar 2019 00:47:26 +0000 Subject: [PATCH 020/124] Auto corrected by following Lint Ruby RSpec/ExpectChange --- spec/controllers/crops_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index b683715a3..d510ce92a 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -63,16 +63,16 @@ describe CropsController do subject { delete :destroy, params: { slug: crop.to_param } } context 'not logged in' do - it { expect { subject }.not_to change { Crop.count } } + it { expect { subject }.not_to change(Crop, :count) } end context 'logged in as member' do - it { expect { subject }.not_to change { Crop.count } } + it { expect { subject }.not_to change(Crop, :count) } end context 'wrangler' do include_context 'login as wrangler' - it { expect { subject }.to change { Crop.count }.by -1 } + it { expect { subject }.to change(Crop, :count).by -1 } end end end From e7713ab24bb746690132493faad2eb1a2a4b1c14 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Wed, 13 Mar 2019 00:47:15 +0000 Subject: [PATCH 021/124] Auto corrected by following Lint Ruby RSpec/AlignRightLetBrace --- spec/controllers/comments_controller_spec.rb | 8 ++++---- spec/controllers/harvests_controller_spec.rb | 14 +++++++------- spec/controllers/likes_controller_spec.rb | 6 +++--- .../photo_associations_controller_spec.rb | 2 +- spec/controllers/photos_controller_spec.rb | 16 ++++++++-------- spec/controllers/plantings_controller_spec.rb | 8 ++++---- spec/controllers/robots_controller_spec.rb | 2 +- spec/features/admin/forums_spec.rb | 2 +- spec/features/cms_spec.rb | 2 +- .../comments/commenting_a_comment_spec.rb | 2 +- spec/features/crops/alternate_name_spec.rb | 2 +- spec/features/crops/browse_crops_spec.rb | 6 +++--- spec/features/crops/creating_a_crop_spec.rb | 2 +- spec/features/crops/crop_detail_page_spec.rb | 2 +- spec/features/crops/crop_photos_spec.rb | 4 ++-- spec/features/crops/crop_wranglers_spec.rb | 8 ++++---- .../features/crops/crop_wrangling_button_spec.rb | 2 +- spec/features/crops/delete_crop_spec.rb | 4 ++-- spec/features/crops/request_new_crop_spec.rb | 4 ++-- spec/features/crops/requested_crops_spec.rb | 2 +- spec/features/crops/show_spec.rb | 6 +++--- spec/features/gardens/gardens_index_spec.rb | 2 +- spec/features/gardens_spec.rb | 6 +++--- spec/features/harvests/browse_harvests_spec.rb | 2 +- spec/features/harvests/harvesting_a_crop_spec.rb | 8 ++++---- spec/features/home/home_spec.rb | 4 ++-- spec/features/likeable_spec.rb | 4 ++-- spec/features/member_profile_spec.rb | 4 ++-- spec/features/members/deletion_spec.rb | 16 ++++++++-------- spec/features/members_list_spec.rb | 2 +- spec/features/notifications_spec.rb | 2 +- spec/features/places/searching_a_place_spec.rb | 8 ++++---- spec/features/planting_reminder_spec.rb | 2 +- spec/features/plantings/planting_a_crop_spec.rb | 4 ++-- spec/features/scientific_name_spec.rb | 2 +- spec/features/seeds/adding_seeds_spec.rb | 2 +- spec/features/seeds/seed_photos.rb | 2 +- spec/features/shared_examples/crop_suggest.rb | 6 +++--- spec/features/signin_spec.rb | 6 +++--- spec/features/unsubscribing_spec.rb | 2 +- spec/helpers/buttons_helper_spec.rb | 6 +++--- spec/helpers/photos_helper_spec.rb | 12 ++++++------ spec/mailers/notifier_spec.rb | 8 ++++---- spec/models/ability_spec.rb | 2 +- spec/models/alternate_name_spec.rb | 2 +- spec/models/crop_spec.rb | 14 +++++++------- spec/models/garden_spec.rb | 10 +++++----- spec/models/like_spec.rb | 2 +- spec/models/member_spec.rb | 2 +- spec/models/photo_spec.rb | 10 +++++----- spec/models/planting_spec.rb | 8 ++++---- spec/models/post_spec.rb | 4 ++-- spec/models/seed_spec.rb | 6 +++--- spec/requests/api/v1/crop_request_spec.rb | 2 +- spec/requests/api/v1/gardens_request_spec.rb | 2 +- spec/requests/api/v1/harvest_request_spec.rb | 2 +- spec/requests/api/v1/member_request_spec.rb | 2 +- spec/requests/api/v1/photos_request_spec.rb | 2 +- spec/requests/api/v1/plantings_request_spec.rb | 2 +- spec/requests/api/v1/seeds_request_spec.rb | 2 +- spec/views/crops/_grown_for.html.haml_spec.rb | 2 +- spec/views/photos/show.html.haml_spec.rb | 8 ++++---- spec/views/plantings/index.html.haml_spec.rb | 6 +++--- spec/views/plantings/show.html.haml_spec.rb | 4 ++-- .../scientific_names/edit.html.haml_spec.rb | 2 +- spec/views/seeds/new.html.haml_spec.rb | 2 +- spec/views/seeds/show.html.haml_spec.rb | 2 +- 67 files changed, 157 insertions(+), 157 deletions(-) diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 07f5ad149..ed5b8ad86 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -58,7 +58,7 @@ describe CommentsController do before { get :edit, params: { id: comment.to_param } } describe "my comment" do - let!(:comment) { FactoryBot.create :comment, author: member, post: post } + let!(:comment) { FactoryBot.create :comment, author: member, post: post } let!(:old_comment) { FactoryBot.create(:comment, post: post, created_at: Time.zone.yesterday) } it "assigns previous comments as @comments" do @@ -91,9 +91,9 @@ describe CommentsController do end describe "attempting to change post_id" do - let(:post) { FactoryBot.create :post, subject: 'our post' } - let(:other_post) { FactoryBot.create :post, subject: 'the other post' } - let(:valid_attributes) { { post_id: other_post.id, body: "kōrero" } } + let(:post) { FactoryBot.create :post, subject: 'our post' } + let(:other_post) { FactoryBot.create :post, subject: 'the other post' } + let(:valid_attributes) { { post_id: other_post.id, body: "kōrero" } } let(:comment) { FactoryBot.create :comment, author: member, post: post } it "does not change post_id" do diff --git a/spec/controllers/harvests_controller_spec.rb b/spec/controllers/harvests_controller_spec.rb index 5e393c59a..e45f2c4c2 100644 --- a/spec/controllers/harvests_controller_spec.rb +++ b/spec/controllers/harvests_controller_spec.rb @@ -13,12 +13,12 @@ describe HarvestsController do end describe "GET index" do - let!(:member1) { FactoryBot.create(:member) } - let(:member2) { FactoryBot.create(:member) } - let(:tomato) { FactoryBot.create(:tomato) } - let(:maize) { FactoryBot.create(:maize) } + let!(:member1) { FactoryBot.create(:member) } + let(:member2) { FactoryBot.create(:member) } + let(:tomato) { FactoryBot.create(:tomato) } + let(:maize) { FactoryBot.create(:maize) } let!(:harvest1) { FactoryBot.create(:harvest, owner_id: member1.id, crop_id: tomato.id) } - let!(:harvest2) { FactoryBot.create(:harvest, owner_id: member2.id, crop_id: maize.id) } + let!(:harvest2) { FactoryBot.create(:harvest, owner_id: member2.id, crop_id: maize.id) } describe "assigns all harvests as @harvests" do before { get :index, params: {} } @@ -127,7 +127,7 @@ describe HarvestsController do describe "not my planting" do let(:not_my_planting) { FactoryBot.create(:planting) } - let(:harvest) { FactoryBot.create(:harvest) } + let(:harvest) { FactoryBot.create(:harvest) } describe "does not save planting_id" do before do @@ -183,7 +183,7 @@ describe HarvestsController do describe "not my planting" do let(:not_my_planting) { FactoryBot.create(:planting) } - let(:harvest) { FactoryBot.create(:harvest) } + let(:harvest) { FactoryBot.create(:harvest) } describe "does not save planting_id" do before do diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index 516cc368f..5527a595e 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' describe LikesController do - let(:like) { FactoryBot.create :like, member: member } - let(:member) { FactoryBot.create(:member) } - let(:blogpost) { FactoryBot.create(:post) } + let(:like) { FactoryBot.create :like, member: member } + let(:member) { FactoryBot.create(:member) } + let(:blogpost) { FactoryBot.create(:post) } let(:mypost) { FactoryBot.create(:post, author: member) } before { sign_in member } diff --git a/spec/controllers/photo_associations_controller_spec.rb b/spec/controllers/photo_associations_controller_spec.rb index 311fa01c3..9cfe11a96 100644 --- a/spec/controllers/photo_associations_controller_spec.rb +++ b/spec/controllers/photo_associations_controller_spec.rb @@ -16,7 +16,7 @@ describe PhotoAssociationsController do describe "my harvest my photo" do let(:harvest) { FactoryBot.create :harvest, owner: member } - let(:photo) { FactoryBot.create :photo, owner: member } + let(:photo) { FactoryBot.create :photo, owner: member } it "removes link" do expect { delete :destroy, params: valid_params }.to change { photo.harvests.count }.by(-1) diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 5b5f5f23c..c2848f528 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -16,9 +16,9 @@ describe PhotosController do describe 'crop photos' do let!(:photo) { FactoryBot.create :photo, owner: member } - let!(:crop_photo) { FactoryBot.create :photo, owner: member } + let!(:crop_photo) { FactoryBot.create :photo, owner: member } let!(:planting) { FactoryBot.create :planting, crop: crop, owner: member } - let!(:crop) { FactoryBot.create :crop } + let!(:crop) { FactoryBot.create :crop } before do planting.photos << crop_photo @@ -33,9 +33,9 @@ describe PhotosController do describe "GET new" do let(:tomato) { FactoryBot.create(:tomato) } let(:planting) { FactoryBot.create(:planting, crop: tomato, owner: member) } - let(:garden) { FactoryBot.create(:garden, owner: member) } - let(:harvest) { FactoryBot.create(:harvest, owner: member) } - let(:member) { FactoryBot.create(:member) } + let(:garden) { FactoryBot.create(:garden, owner: member) } + let(:harvest) { FactoryBot.create(:harvest, owner: member) } + let(:member) { FactoryBot.create(:member) } let!(:auth) { FactoryBot.create(:flickr_authentication, member: member) } before do @@ -80,10 +80,10 @@ describe PhotosController do end let(:member) { FactoryBot.create(:member) } - let(:garden) { FactoryBot.create(:garden, owner: member) } + let(:garden) { FactoryBot.create(:garden, owner: member) } let(:planting) { FactoryBot.create(:planting, garden: garden, owner: member) } - let(:harvest) { FactoryBot.create(:harvest, owner: member) } - let(:photo) { FactoryBot.create(:photo, owner: member) } + let(:harvest) { FactoryBot.create(:harvest, owner: member) } + let(:photo) { FactoryBot.create(:photo, owner: member) } describe "with valid params" do before { controller.stub(:current_member) { member } } diff --git a/spec/controllers/plantings_controller_spec.rb b/spec/controllers/plantings_controller_spec.rb index 4efe2356c..5438b109b 100644 --- a/spec/controllers/plantings_controller_spec.rb +++ b/spec/controllers/plantings_controller_spec.rb @@ -11,10 +11,10 @@ describe PlantingsController do end describe "GET index" do - let!(:member1) { FactoryBot.create(:member) } - let!(:member2) { FactoryBot.create(:member) } - let!(:tomato) { FactoryBot.create(:tomato) } - let!(:maize) { FactoryBot.create(:maize) } + let!(:member1) { FactoryBot.create(:member) } + let!(:member2) { FactoryBot.create(:member) } + let!(:tomato) { FactoryBot.create(:tomato) } + let!(:maize) { FactoryBot.create(:maize) } let!(:planting1) { FactoryBot.create :planting, crop: tomato, owner: member1, created_at: 1.day.ago } let!(:planting2) { FactoryBot.create :planting, crop: maize, owner: member2, created_at: 5.days.ago } diff --git a/spec/controllers/robots_controller_spec.rb b/spec/controllers/robots_controller_spec.rb index e8917aa29..15ab05d82 100644 --- a/spec/controllers/robots_controller_spec.rb +++ b/spec/controllers/robots_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe RobotsController do describe '#robots' do - let(:production_filename) { 'config/robots.txt' } + let(:production_filename) { 'config/robots.txt' } let(:staging_filename) { 'config/robots.staging.txt' } before do diff --git a/spec/features/admin/forums_spec.rb b/spec/features/admin/forums_spec.rb index 988d4462e..8cfce4915 100644 --- a/spec/features/admin/forums_spec.rb +++ b/spec/features/admin/forums_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' feature "forums", js: true do context "as an admin user" do let(:member) { create :admin_member } - let(:forum) { create :forum } + let(:forum) { create :forum } background do login_as member diff --git a/spec/features/cms_spec.rb b/spec/features/cms_spec.rb index b3370cfbd..405f77f18 100644 --- a/spec/features/cms_spec.rb +++ b/spec/features/cms_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' feature "cms admin" do - let(:member) { create :member } + let(:member) { create :member } let(:admin_member) { create :admin_member } scenario "can't view CMS admin if not signed in" do diff --git a/spec/features/comments/commenting_a_comment_spec.rb b/spec/features/comments/commenting_a_comment_spec.rb index 67856f9e0..6c195e518 100644 --- a/spec/features/comments/commenting_a_comment_spec.rb +++ b/spec/features/comments/commenting_a_comment_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' feature 'Commenting on a post' do - let(:member) { create :member } + let(:member) { create :member } let(:post) { create :post, author: member } background do diff --git a/spec/features/crops/alternate_name_spec.rb b/spec/features/crops/alternate_name_spec.rb index 89780154d..716a26bc2 100644 --- a/spec/features/crops/alternate_name_spec.rb +++ b/spec/features/crops/alternate_name_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Alternate names", js: true do let!(:alternate_eggplant) { create :alternate_eggplant } - let(:crop) { alternate_eggplant.crop } + let(:crop) { alternate_eggplant.crop } scenario "Display alternate names on crop page" do visit crop_path(alternate_eggplant.crop) diff --git a/spec/features/crops/browse_crops_spec.rb b/spec/features/crops/browse_crops_spec.rb index 1b945c058..c9a6335ec 100644 --- a/spec/features/crops/browse_crops_spec.rb +++ b/spec/features/crops/browse_crops_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' feature "browse crops" do - let(:tomato) { create :tomato } - let(:maize) { create :maize } - let(:pending_crop) { create :crop_request } + let(:tomato) { create :tomato } + let(:maize) { create :maize } + let(:pending_crop) { create :crop_request } let(:rejected_crop) { create :rejected_crop } scenario "has a form for sorting by" do diff --git a/spec/features/crops/creating_a_crop_spec.rb b/spec/features/crops/creating_a_crop_spec.rb index d1c4a9eee..64eff3628 100644 --- a/spec/features/crops/creating_a_crop_spec.rb +++ b/spec/features/crops/creating_a_crop_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Crop - " do let!(:crop_wrangler) { FactoryBot.create :crop_wrangling_member } - let!(:member) { FactoryBot.create :member } + let!(:member) { FactoryBot.create :member } background do login_as member diff --git a/spec/features/crops/crop_detail_page_spec.rb b/spec/features/crops/crop_detail_page_spec.rb index 7a3155403..6386c7044 100644 --- a/spec/features/crops/crop_detail_page_spec.rb +++ b/spec/features/crops/crop_detail_page_spec.rb @@ -152,7 +152,7 @@ feature "crop detail page", js: true do end context "seed quantity for a crop" do - let(:member) { create :member } + let(:member) { create :member } let(:seed) { create :seed, crop: crop, quantity: 20, owner: member } scenario "User not signed in" do diff --git a/spec/features/crops/crop_photos_spec.rb b/spec/features/crops/crop_photos_spec.rb index f84442358..0d7d1fbee 100644 --- a/spec/features/crops/crop_photos_spec.rb +++ b/spec/features/crops/crop_photos_spec.rb @@ -8,8 +8,8 @@ feature "crop detail page", js: true do let!(:crop) { FactoryBot.create :crop } let!(:planting) { FactoryBot.create :planting, crop: crop, owner: member } - let!(:harvest) { FactoryBot.create :harvest, crop: crop, owner: member } - let!(:seed) { FactoryBot.create :seed, crop: crop, owner: member } + let!(:harvest) { FactoryBot.create :harvest, crop: crop, owner: member } + let!(:seed) { FactoryBot.create :seed, crop: crop, owner: member } let!(:photo1) { FactoryBot.create(:photo, owner: member) } let!(:photo2) { FactoryBot.create(:photo, owner: member) } diff --git a/spec/features/crops/crop_wranglers_spec.rb b/spec/features/crops/crop_wranglers_spec.rb index 8cd5018f3..f9db489b2 100644 --- a/spec/features/crops/crop_wranglers_spec.rb +++ b/spec/features/crops/crop_wranglers_spec.rb @@ -3,10 +3,10 @@ require 'rails_helper' feature "crop wranglers", js: true do context "signed in wrangler" do let!(:crop_wranglers) { create_list :crop_wrangling_member, 3 } - let(:wrangler) { crop_wranglers.first } - let!(:crops) { create_list :crop, 2 } - let!(:requested_crop) { create :crop_request } - let!(:rejected_crop) { create :rejected_crop } + let(:wrangler) { crop_wranglers.first } + let!(:crops) { create_list :crop, 2 } + let!(:requested_crop) { create :crop_request } + let!(:rejected_crop) { create :rejected_crop } background { login_as wrangler } diff --git a/spec/features/crops/crop_wrangling_button_spec.rb b/spec/features/crops/crop_wrangling_button_spec.rb index 50be98988..bf285ba66 100644 --- a/spec/features/crops/crop_wrangling_button_spec.rb +++ b/spec/features/crops/crop_wrangling_button_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "crop wrangling button" do let(:crop_wrangler) { create :crop_wrangling_member } - let(:member) { create :member } + let(:member) { create :member } context "crop wrangling button" do background do diff --git a/spec/features/crops/delete_crop_spec.rb b/spec/features/crops/delete_crop_spec.rb index 117e2de3e..f1302c784 100644 --- a/spec/features/crops/delete_crop_spec.rb +++ b/spec/features/crops/delete_crop_spec.rb @@ -3,8 +3,8 @@ require 'rails_helper' feature "Delete crop spec" do context "As a crop wrangler" do let(:wrangler) { FactoryBot.create :crop_wrangling_member } - let!(:pending_crop) { FactoryBot.create :crop_request } - let!(:approved_crop) { FactoryBot.create :crop } + let!(:pending_crop) { FactoryBot.create :crop_request } + let!(:approved_crop) { FactoryBot.create :crop } background { login_as wrangler } diff --git a/spec/features/crops/request_new_crop_spec.rb b/spec/features/crops/request_new_crop_spec.rb index 6d4061f7e..1374d1176 100644 --- a/spec/features/crops/request_new_crop_spec.rb +++ b/spec/features/crops/request_new_crop_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Requesting a new crop" do context "As a regular member" do - let(:member) { create :member } + let(:member) { create :member } let!(:wrangler) { create :crop_wrangling_member } background do @@ -22,7 +22,7 @@ feature "Requesting a new crop" do context "As a crop wrangler" do let(:wrangler) { create :crop_wrangling_member } let!(:crop) { create :crop_request } - let!(:already_approved) { create :crop } + let!(:already_approved) { create :crop } background { login_as wrangler } diff --git a/spec/features/crops/requested_crops_spec.rb b/spec/features/crops/requested_crops_spec.rb index 042a3dff7..2ab750fe7 100644 --- a/spec/features/crops/requested_crops_spec.rb +++ b/spec/features/crops/requested_crops_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' feature "Crop - " do - let(:member) { create :member } + let(:member) { create :member } let!(:requested_crop) { create :crop, requester: member, approval_status: 'pending', name: 'puha for dinner' } background do diff --git a/spec/features/crops/show_spec.rb b/spec/features/crops/show_spec.rb index 90c675211..cc5ff75db 100644 --- a/spec/features/crops/show_spec.rb +++ b/spec/features/crops/show_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' feature "browse crops" do - let(:tomato) { create :tomato } - let(:maize) { create :maize } - let(:pending_crop) { create :crop_request } + let(:tomato) { create :tomato } + let(:maize) { create :maize } + let(:pending_crop) { create :crop_request } let(:rejected_crop) { create :rejected_crop } scenario "Show crop info" do diff --git a/spec/features/gardens/gardens_index_spec.rb b/spec/features/gardens/gardens_index_spec.rb index 2e559cd50..b5b929df1 100644 --- a/spec/features/gardens/gardens_index_spec.rb +++ b/spec/features/gardens/gardens_index_spec.rb @@ -72,7 +72,7 @@ feature "Gardens#index", :js do describe 'badges' do let(:garden) { member.gardens.first } let(:member) { FactoryBot.create :member, login_name: 'robbieburns' } - let(:crop) { FactoryBot.create :crop } + let(:crop) { FactoryBot.create :crop } before do # time to harvest = 50 day diff --git a/spec/features/gardens_spec.rb b/spec/features/gardens_spec.rb index b436e947c..504ecda49 100644 --- a/spec/features/gardens_spec.rb +++ b/spec/features/gardens_spec.rb @@ -2,10 +2,10 @@ require 'rails_helper' feature "Planting a crop", js: true do # name is aaa to ensure it is ordered first - let!(:garden) { create :garden, name: 'aaa' } + let!(:garden) { create :garden, name: 'aaa' } let!(:planting) { create :planting, garden: garden, owner: garden.owner, planted_at: Date.parse("2013-3-10") } - let!(:tomato) { create :tomato } - let!(:finished_planting) { create :finished_planting, owner: garden.owner, garden: garden, crop: tomato } + let!(:tomato) { create :tomato } + let!(:finished_planting) { create :finished_planting, owner: garden.owner, garden: garden, crop: tomato } background do login_as garden.owner diff --git a/spec/features/harvests/browse_harvests_spec.rb b/spec/features/harvests/browse_harvests_spec.rb index 597565aed..b2409c122 100644 --- a/spec/features/harvests/browse_harvests_spec.rb +++ b/spec/features/harvests/browse_harvests_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' feature "browse harvests" do subject { page } - let!(:member) { create :member } + let!(:member) { create :member } let!(:harvest) { create :harvest, owner: member } background { login_as member } diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index 7173658bb..f30d12baa 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -2,9 +2,9 @@ require 'rails_helper' require 'custom_matchers' feature "Harvesting a crop", :js, :elasticsearch do - let(:member) { create :member } - let!(:maize) { create :maize } - let!(:plant_part) { create :plant_part } + let(:member) { create :member } + let!(:maize) { create :maize } + let!(:plant_part) { create :plant_part } let(:planting) { create :planting, crop: maize, owner: member } background do @@ -94,7 +94,7 @@ feature "Harvesting a crop", :js, :elasticsearch do context "Editing a harvest" do let(:existing_harvest) { create :harvest, crop: maize, owner: member } - let!(:other_plant_part) { create :plant_part, name: 'chocolate' } + let!(:other_plant_part) { create :plant_part, name: 'chocolate' } background do visit harvest_path(existing_harvest) diff --git a/spec/features/home/home_spec.rb b/spec/features/home/home_spec.rb index 4036cb957..7376de882 100644 --- a/spec/features/home/home_spec.rb +++ b/spec/features/home/home_spec.rb @@ -10,11 +10,11 @@ feature "home page" do let(:planting) { FactoryBot.create :planting, owner: member, crop: crop } let(:seed) { FactoryBot.create :tradable_seed, owner: member, crop: crop } - let(:harvest) { FactoryBot.create :harvest, owner: member, crop: crop } + let(:harvest) { FactoryBot.create :harvest, owner: member, crop: crop } let!(:tradable_seed) { FactoryBot.create :tradable_seed, finished: false } let!(:finished_seed) { FactoryBot.create :tradable_seed, finished: true } - let!(:untradable_seed) { FactoryBot.create :untradable_seed } + let!(:untradable_seed) { FactoryBot.create :untradable_seed } background do # Add photos, so they can appear on home page diff --git a/spec/features/likeable_spec.rb b/spec/features/likeable_spec.rb index a45b9a1d8..d1b637e0d 100644 --- a/spec/features/likeable_spec.rb +++ b/spec/features/likeable_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' feature 'Likeable', js: true do - let(:member) { FactoryBot.create(:member) } + let(:member) { FactoryBot.create(:member) } let(:another_member) { FactoryBot.create(:london_member) } - let(:post) { FactoryBot.create(:post) } + let(:post) { FactoryBot.create(:post) } context 'logged in member' do background do diff --git a/spec/features/member_profile_spec.rb b/spec/features/member_profile_spec.rb index 56d7d1fae..a548c7eb0 100644 --- a/spec/features/member_profile_spec.rb +++ b/spec/features/member_profile_spec.rb @@ -103,8 +103,8 @@ feature "member profile", js: true do context "signed in member" do let(:member) { create :member } - let(:other_member) { create :member } - let(:admin_member) { create :admin_member } + let(:other_member) { create :member } + let(:admin_member) { create :admin_member } let(:crop_wrangler) { create :crop_wrangling_member } background do diff --git a/spec/features/members/deletion_spec.rb b/spec/features/members/deletion_spec.rb index 65570e1ca..3c392cb4c 100644 --- a/spec/features/members/deletion_spec.rb +++ b/spec/features/members/deletion_spec.rb @@ -2,15 +2,15 @@ require 'rails_helper' feature "member deletion" do context "with activity and followers" do - let(:member) { FactoryBot.create(:member) } - let(:other_member) { FactoryBot.create(:member) } - let(:memberpost) { FactoryBot.create(:post, author: member) } + let(:member) { FactoryBot.create(:member) } + let(:other_member) { FactoryBot.create(:member) } + let(:memberpost) { FactoryBot.create(:post, author: member) } let(:othermemberpost) { FactoryBot.create(:post, author: other_member) } - let!(:planting) { FactoryBot.create(:planting, owner: member) } - let!(:harvest) { FactoryBot.create(:harvest, owner: member) } - let!(:seed) { FactoryBot.create(:seed, owner: member) } - let!(:secondgarden) { FactoryBot.create(:garden, owner: member) } - let(:admin) { FactoryBot.create(:admin_member) } + let!(:planting) { FactoryBot.create(:planting, owner: member) } + let!(:harvest) { FactoryBot.create(:harvest, owner: member) } + let!(:seed) { FactoryBot.create(:seed, owner: member) } + let!(:secondgarden) { FactoryBot.create(:garden, owner: member) } + let(:admin) { FactoryBot.create(:admin_member) } background do login_as(member) diff --git a/spec/features/members_list_spec.rb b/spec/features/members_list_spec.rb index 01b6ee8bd..184efbfb6 100644 --- a/spec/features/members_list_spec.rb +++ b/spec/features/members_list_spec.rb @@ -4,7 +4,7 @@ feature "members list" do context "list all members" do let!(:member1) { create :member, login_name: "Archaeopteryx", confirmed_at: Time.zone.parse('2013-02-10') } let!(:member2) { create :member, login_name: "Zephyrosaurus", confirmed_at: Time.zone.parse('2014-01-11') } - let!(:member3) { create :member, login_name: "Testingname", confirmed_at: Time.zone.parse('2014-05-09') } + let!(:member3) { create :member, login_name: "Testingname", confirmed_at: Time.zone.parse('2014-05-09') } scenario "default alphabetical sort" do visit members_path diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index b0ed36c6e..a5c544552 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' feature "Notifications", :js do - let(:sender) { create :member } + let(:sender) { create :member } let(:recipient) { create :member, login_name: 'beyonce' } context "On existing notification" do diff --git a/spec/features/places/searching_a_place_spec.rb b/spec/features/places/searching_a_place_spec.rb index bec7cde68..7a2d12898 100644 --- a/spec/features/places/searching_a_place_spec.rb +++ b/spec/features/places/searching_a_place_spec.rb @@ -1,10 +1,10 @@ require "rails_helper" feature "User searches" do - let(:member) { create :member, location: "Philippines" } - let!(:maize) { create :maize } - let(:garden) { create :garden, owner: member } - let!(:seed1) { create :seed, owner: member } + let(:member) { create :member, location: "Philippines" } + let!(:maize) { create :maize } + let(:garden) { create :garden, owner: member } + let!(:seed1) { create :seed, owner: member } let!(:planting) { create :planting, garden: garden, owner: member, planted_at: Date.parse("2013-3-10") } scenario "with a valid place" do diff --git a/spec/features/planting_reminder_spec.rb b/spec/features/planting_reminder_spec.rb index 53f0993da..e13803182 100644 --- a/spec/features/planting_reminder_spec.rb +++ b/spec/features/planting_reminder_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' require 'capybara/email/rspec' feature "Planting reminder email", :js do - let(:member) { create :member } + let(:member) { create :member } let(:mail) { Notifier.planting_reminder(member) } # Unfortunately, we can't use the default url options for ActionMailer as configured in diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 386ee6407..8cb70fc5a 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -2,8 +2,8 @@ require "rails_helper" require 'custom_matchers' feature "Planting a crop", :js, :elasticsearch do - let(:member) { FactoryBot.create :member } - let!(:maize) { FactoryBot.create :maize } + let(:member) { FactoryBot.create :member } + let!(:maize) { FactoryBot.create :maize } let(:garden) { FactoryBot.create :garden, owner: member } let!(:planting) do FactoryBot.create :planting, garden: garden, owner: member, planted_at: Date.parse("2013-03-10") diff --git a/spec/features/scientific_name_spec.rb b/spec/features/scientific_name_spec.rb index 009d9d3f7..3844a3a07 100644 --- a/spec/features/scientific_name_spec.rb +++ b/spec/features/scientific_name_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature "Scientific names", js: true do let!(:zea_mays) { create :zea_mays } - let(:crop) { zea_mays.crop } + let(:crop) { zea_mays.crop } scenario "Display scientific names on crop page" do visit crop_path(zea_mays.crop) diff --git a/spec/features/seeds/adding_seeds_spec.rb b/spec/features/seeds/adding_seeds_spec.rb index f87d8f59d..2964a5ab3 100644 --- a/spec/features/seeds/adding_seeds_spec.rb +++ b/spec/features/seeds/adding_seeds_spec.rb @@ -3,7 +3,7 @@ require 'custom_matchers' feature "Seeds", :js, :elasticsearch do let(:member) { create :member } - let!(:maize) { create :maize } + let!(:maize) { create :maize } background do login_as member diff --git a/spec/features/seeds/seed_photos.rb b/spec/features/seeds/seed_photos.rb index 089d4b181..60746d98b 100644 --- a/spec/features/seeds/seed_photos.rb +++ b/spec/features/seeds/seed_photos.rb @@ -8,7 +8,7 @@ feature "Seeds", :js do page end - let(:member) { FactoryBot.create :member } + let(:member) { FactoryBot.create :member } let!(:seed) { FactoryBot.create :seed, owner: member } it { is_expected.to have_content 'Add photo' } diff --git a/spec/features/shared_examples/crop_suggest.rb b/spec/features/shared_examples/crop_suggest.rb index 2c86fea0d..b646ba7df 100644 --- a/spec/features/shared_examples/crop_suggest.rb +++ b/spec/features/shared_examples/crop_suggest.rb @@ -2,9 +2,9 @@ require 'rails_helper' shared_examples "crop suggest" do |resource| let!(:pea) { create :crop, name: 'pea' } - let!(:pear) { create :pear } - let!(:tomato) { create :tomato } - let!(:roma) { create :roma } + let!(:pear) { create :pear } + let!(:tomato) { create :tomato } + let!(:roma) { create :roma } background { sync_elasticsearch [pea, pear, maize, tomato] } diff --git a/spec/features/signin_spec.rb b/spec/features/signin_spec.rb index 2f9f1c1c7..07fd6a130 100644 --- a/spec/features/signin_spec.rb +++ b/spec/features/signin_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' feature "signin", js: true do - let(:member) { FactoryBot.create :member } - let(:recipient) { FactoryBot.create :member } - let(:wrangler) { FactoryBot.create :crop_wrangling_member } + let(:member) { FactoryBot.create :member } + let(:recipient) { FactoryBot.create :member } + let(:wrangler) { FactoryBot.create :crop_wrangling_member } let(:notification) { FactoryBot.create :notification, recipient: recipient } def login diff --git a/spec/features/unsubscribing_spec.rb b/spec/features/unsubscribing_spec.rb index 812dc8266..3f7843034 100644 --- a/spec/features/unsubscribing_spec.rb +++ b/spec/features/unsubscribing_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' require 'capybara/email/rspec' feature "unsubscribe" do - let(:member) { create :member } + let(:member) { create :member } let(:notification) { create :notification } background do diff --git a/spec/helpers/buttons_helper_spec.rb b/spec/helpers/buttons_helper_spec.rb index b2112740e..b9bdc41a2 100644 --- a/spec/helpers/buttons_helper_spec.rb +++ b/spec/helpers/buttons_helper_spec.rb @@ -13,10 +13,10 @@ require 'rails_helper' RSpec.describe ButtonsHelper, type: :helper do before { allow(self).to receive(:can?).and_return(true) } - let(:garden) { FactoryBot.create :garden } + let(:garden) { FactoryBot.create :garden } let(:planting) { FactoryBot.create :planting } - let(:harvest) { FactoryBot.create :harvest } - let(:seed) { FactoryBot.create :seed } + let(:harvest) { FactoryBot.create :harvest } + let(:seed) { FactoryBot.create :seed } describe 'add_photo_button' do it { expect(add_photo_button(garden)).to include "/photos/new?id=#{garden.id}&type=garden" } diff --git a/spec/helpers/photos_helper_spec.rb b/spec/helpers/photos_helper_spec.rb index d52bf74c9..60a6cbc59 100644 --- a/spec/helpers/photos_helper_spec.rb +++ b/spec/helpers/photos_helper_spec.rb @@ -5,13 +5,13 @@ describe PhotosHelper do let(:garden) { FactoryBot.create :garden } - let(:garden_photo) { FactoryBot.create(:photo, thumbnail_url: 'garden.jpg', owner: garden.owner) } - let(:planting) { FactoryBot.create :planting, crop: crop, owner: garden.owner } + let(:garden_photo) { FactoryBot.create(:photo, thumbnail_url: 'garden.jpg', owner: garden.owner) } + let(:planting) { FactoryBot.create :planting, crop: crop, owner: garden.owner } let(:planting_photo) { FactoryBot.create(:photo, thumbnail_url: 'planting.jpg', owner: garden.owner) } - let(:harvest) { FactoryBot.create :harvest, crop: crop, owner: garden.owner } - let(:harvest_photo) { FactoryBot.create(:photo, thumbnail_url: 'harvest.jpg', owner: garden.owner) } - let(:seed) { FactoryBot.create :seed, crop: crop, owner: garden.owner } - let(:seed_photo) { FactoryBot.create(:photo, thumbnail_url: 'seed.jpg', owner: garden.owner) } + let(:harvest) { FactoryBot.create :harvest, crop: crop, owner: garden.owner } + let(:harvest_photo) { FactoryBot.create(:photo, thumbnail_url: 'harvest.jpg', owner: garden.owner) } + let(:seed) { FactoryBot.create :seed, crop: crop, owner: garden.owner } + let(:seed_photo) { FactoryBot.create(:photo, thumbnail_url: 'seed.jpg', owner: garden.owner) } describe "crops" do subject { crop_image_path(crop) } diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 8b1494c0b..791137c59 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe Notifier do describe "notifications" do let(:notification) { FactoryBot.create(:notification) } - let(:mail) { Notifier.notify(notification) } + let(:mail) { Notifier.notify(notification) } it 'sets the subject correctly' do mail.subject.should == notification.subject @@ -45,7 +45,7 @@ describe Notifier do describe "new crop request" do let(:member) { FactoryBot.create(:crop_wrangling_member) } - let(:crop) { FactoryBot.create(:crop_request) } + let(:crop) { FactoryBot.create(:crop_request) } let(:mail) { Notifier.new_crop_request(member, crop) } it 'sets the subject correctly' do @@ -67,7 +67,7 @@ describe Notifier do describe "crop approved" do let(:member) { FactoryBot.create(:member) } - let(:crop) { FactoryBot.create(:crop) } + let(:crop) { FactoryBot.create(:crop) } let(:mail) { Notifier.crop_request_approved(member, crop) } it 'sets the subject correctly' do @@ -95,7 +95,7 @@ describe Notifier do describe "crop rejected" do let(:member) { FactoryBot.create(:member) } - let(:crop) { FactoryBot.create(:rejected_crop) } + let(:crop) { FactoryBot.create(:rejected_crop) } let(:mail) { Notifier.crop_request_rejected(member, crop) } it 'sets the subject correctly' do diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index e6fc1c709..9a2ad8e29 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -3,7 +3,7 @@ require 'cancan/matchers' describe Ability do let(:member) { FactoryBot.create(:member) } - let(:ability) { Ability.new(member) } + let(:ability) { Ability.new(member) } context "notifications" do it 'member can view their own notifications' do diff --git a/spec/models/alternate_name_spec.rb b/spec/models/alternate_name_spec.rb index 380904164..f7123d701 100644 --- a/spec/models/alternate_name_spec.rb +++ b/spec/models/alternate_name_spec.rb @@ -21,7 +21,7 @@ describe AlternateName do describe 'relationships' do let(:alternate_name) { FactoryBot.create :alternate_name, crop: crop, creator: member } - let(:crop) { FactoryBot.create :crop } + let(:crop) { FactoryBot.create :crop } let(:member) { FactoryBot.create :member } it { expect(alternate_name.crop).to eq crop } diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index bb808fb68..4cd9c3fc1 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Crop do let(:pp2) { FactoryBot.create(:plant_part) } let(:pp1) { FactoryBot.create(:plant_part) } - let(:maize) { FactoryBot.create(:maize) } + let(:maize) { FactoryBot.create(:maize) } context 'all fields present' do let(:crop) { FactoryBot.create(:tomato) } @@ -49,8 +49,8 @@ describe Crop do end context 'popularity' do - let(:tomato) { FactoryBot.create(:tomato) } - let(:maize) { FactoryBot.create(:maize) } + let(:tomato) { FactoryBot.create(:tomato) } + let(:maize) { FactoryBot.create(:maize) } let(:cucumber) { FactoryBot.create(:crop, name: 'cucumber') } before do @@ -340,8 +340,8 @@ describe Crop do context "harvests" do let(:h1) { FactoryBot.create(:harvest, crop: maize, plant_part: pp1) } let(:h2) { FactoryBot.create(:harvest, crop: maize, plant_part: pp2) } - let!(:crop) { FactoryBot.create(:crop) } - let!(:harvest) { FactoryBot.create(:harvest, crop: crop) } + let!(:crop) { FactoryBot.create(:crop) } + let!(:harvest) { FactoryBot.create(:harvest, crop: crop) } it "has harvests" do expect(crop.harvests).to eq [harvest] @@ -544,8 +544,8 @@ describe Crop do end context "crop-post association" do - let!(:tomato) { FactoryBot.create(:tomato) } - let!(:maize) { FactoryBot.create(:maize) } + let!(:tomato) { FactoryBot.create(:tomato) } + let!(:maize) { FactoryBot.create(:maize) } let!(:post) { FactoryBot.create(:post, body: "[maize](crop)[tomato](crop)[tomato](crop)") } describe "destroying a crop" do diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 9ebcbdfb8..e538c2d1a 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Garden do - let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } + let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } it "has a slug" do @@ -57,10 +57,10 @@ describe Garden do context "featured plantings" do let(:tomato) { FactoryBot.create(:tomato) } - let(:maize) { FactoryBot.create(:maize) } - let(:chard) { FactoryBot.create(:chard) } - let(:apple) { FactoryBot.create(:apple) } - let(:pear) { FactoryBot.create(:pear) } + let(:maize) { FactoryBot.create(:maize) } + let(:chard) { FactoryBot.create(:chard) } + let(:apple) { FactoryBot.create(:apple) } + let(:pear) { FactoryBot.create(:pear) } let(:walnut) { FactoryBot.create(:walnut) } it "fetches < 4 featured plantings if insufficient exist" do diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb index 7a199e584..363585aea 100644 --- a/spec/models/like_spec.rb +++ b/spec/models/like_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe 'like' do let(:member) { FactoryBot.create(:member) } - let(:post) { FactoryBot.create(:post) } + let(:post) { FactoryBot.create(:post) } context 'existing like' do before do diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index ffe4f7544..16ad228fb 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -175,7 +175,7 @@ describe 'member' do context 'roles' do let(:member) { FactoryBot.create(:member) } - let(:role) { FactoryBot.create(:role) } + let(:role) { FactoryBot.create(:role) } before do member.roles << role diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 920d57f19..d71a6cd1c 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -2,12 +2,12 @@ require 'rails_helper' describe Photo do let(:photo) { FactoryBot.create(:photo, owner: member) } - let(:member) { FactoryBot.create(:member) } + let(:member) { FactoryBot.create(:member) } describe 'add/delete functionality' do let(:planting) { FactoryBot.create(:planting, owner: member) } let(:harvest) { FactoryBot.create(:harvest, owner: member) } - let(:garden) { FactoryBot.create(:garden, owner: member) } + let(:garden) { FactoryBot.create(:garden, owner: member) } context "adds photos" do it 'to a planting' do @@ -130,15 +130,15 @@ describe Photo do describe 'scopes' do let(:harvest_crop) { FactoryBot.create :crop } let!(:harvest) { FactoryBot.create :harvest, owner: member, crop: harvest_crop } - let!(:harvest_photo) { FactoryBot.create :photo, owner: member } + let!(:harvest_photo) { FactoryBot.create :photo, owner: member } let(:planting_crop) { FactoryBot.create :crop } let!(:planting) { FactoryBot.create :planting, owner: member, crop: planting_crop } - let!(:planting_photo) { FactoryBot.create :photo, owner: member } + let!(:planting_photo) { FactoryBot.create :photo, owner: member } let(:seed_crop) { FactoryBot.create :crop } let!(:seed) { FactoryBot.create :seed, owner: member, crop: seed_crop } - let!(:seed_photo) { FactoryBot.create :photo, owner: member } + let!(:seed_photo) { FactoryBot.create :photo, owner: member } before do harvest.photos << harvest_photo diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 9c5b02eaf..c128c0e6e 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' describe Planting do - let(:crop) { FactoryBot.create(:tomato) } - let(:garden_owner) { FactoryBot.create(:member, login_name: 'hatupatu') } + let(:crop) { FactoryBot.create(:tomato) } + let(:garden_owner) { FactoryBot.create(:member, login_name: 'hatupatu') } let(:garden) { FactoryBot.create(:garden, owner: garden_owner, name: 'Springfield Community Garden') } - let(:planting) { FactoryBot.create(:planting, crop: crop, garden: garden, owner: garden.owner) } + let(:planting) { FactoryBot.create(:planting, crop: crop, garden: garden, owner: garden.owner) } let(:finished_planting) do FactoryBot.create :planting, planted_at: 4.days.ago, finished_at: 2.days.ago, finished: true end @@ -72,7 +72,7 @@ describe Planting do end describe 'child crop uses parent data' do - let(:child_crop) { FactoryBot.create :crop, parent: crop, name: 'child' } + let(:child_crop) { FactoryBot.create :crop, parent: crop, name: 'child' } let(:child_planting) { FactoryBot.create :planting, crop: child_crop, planted_at: 30.days.ago } # not data for this crop diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 127f1ad7e..b39d4aff0 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -132,8 +132,8 @@ describe Post do context "crop-post association" do let!(:tomato) { FactoryBot.create(:tomato) } - let!(:maize) { FactoryBot.create(:maize) } - let!(:chard) { FactoryBot.create(:chard) } + let!(:maize) { FactoryBot.create(:maize) } + let!(:chard) { FactoryBot.create(:chard) } let!(:post) { FactoryBot.create(:post, body: "[maize](crop)[tomato](crop)[tomato](crop)") } it "is generated" do diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index 83f3f1cb8..a2dae3155 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe Seed do let(:owner) { FactoryBot.create :owner, login_name: 'tamateapokaiwhenua' } - let(:seed) { FactoryBot.build(:seed, owner: owner) } + let(:seed) { FactoryBot.build(:seed, owner: owner) } it 'saves a basic seed' do seed.save.should be(true) @@ -161,7 +161,7 @@ describe Seed do end context 'ancestry' do - let(:parent_planting) { FactoryBot.create :planting } + let(:parent_planting) { FactoryBot.create :planting } let(:seed) { FactoryBot.create :seed, parent_planting: parent_planting, owner: parent_planting.owner } it "seed has a parent planting" do @@ -181,7 +181,7 @@ describe Seed do end describe 'scopes' do - let!(:seed) { FactoryBot.create(:seed) } + let!(:seed) { FactoryBot.create(:seed) } let!(:finished_seed) { FactoryBot.create(:finished_seed) } describe 'has finished scope' do diff --git a/spec/requests/api/v1/crop_request_spec.rb b/spec/requests/api/v1/crop_request_spec.rb index 6d8353d69..893d527c9 100644 --- a/spec/requests/api/v1/crop_request_spec.rb +++ b/spec/requests/api/v1/crop_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Plantings', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:crop) { FactoryBot.create :crop } + let!(:crop) { FactoryBot.create :crop } let(:crop_encoded_as_json_api) do { "id" => crop.id.to_s, "type" => "crops", diff --git a/spec/requests/api/v1/gardens_request_spec.rb b/spec/requests/api/v1/gardens_request_spec.rb index 8426dfcb2..127513607 100644 --- a/spec/requests/api/v1/gardens_request_spec.rb +++ b/spec/requests/api/v1/gardens_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Gardens', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:garden) { FactoryBot.create :garden } + let!(:garden) { FactoryBot.create :garden } let(:garden_encoded_as_json_api) do { "id" => garden.id.to_s, "type" => "gardens", diff --git a/spec/requests/api/v1/harvest_request_spec.rb b/spec/requests/api/v1/harvest_request_spec.rb index 597714060..18a1fe4ab 100644 --- a/spec/requests/api/v1/harvest_request_spec.rb +++ b/spec/requests/api/v1/harvest_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Harvests', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:harvest) { FactoryBot.create :harvest } + let!(:harvest) { FactoryBot.create :harvest } let(:harvest_encoded_as_json_api) do { "id" => harvest.id.to_s, "type" => "harvests", diff --git a/spec/requests/api/v1/member_request_spec.rb b/spec/requests/api/v1/member_request_spec.rb index 9178f91cc..efc5a1feb 100644 --- a/spec/requests/api/v1/member_request_spec.rb +++ b/spec/requests/api/v1/member_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Members', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:member) { FactoryBot.create :member } + let!(:member) { FactoryBot.create :member } let(:member_encoded_as_json_api) do { "id" => member.id.to_s, "type" => "members", diff --git a/spec/requests/api/v1/photos_request_spec.rb b/spec/requests/api/v1/photos_request_spec.rb index 118aa4fcc..82959eb0d 100644 --- a/spec/requests/api/v1/photos_request_spec.rb +++ b/spec/requests/api/v1/photos_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Photos', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:photo) { FactoryBot.create :photo } + let!(:photo) { FactoryBot.create :photo } let(:photo_encoded_as_json_api) do { "id" => photo.id.to_s, "type" => "photos", diff --git a/spec/requests/api/v1/plantings_request_spec.rb b/spec/requests/api/v1/plantings_request_spec.rb index 2085fd85f..9137f8b39 100644 --- a/spec/requests/api/v1/plantings_request_spec.rb +++ b/spec/requests/api/v1/plantings_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Plantings', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:planting) { FactoryBot.create :planting } + let!(:planting) { FactoryBot.create :planting } let(:planting_encoded_as_json_api) do { "id" => planting.id.to_s, "type" => "plantings", diff --git a/spec/requests/api/v1/seeds_request_spec.rb b/spec/requests/api/v1/seeds_request_spec.rb index 3bde1af9d..90d3da22a 100644 --- a/spec/requests/api/v1/seeds_request_spec.rb +++ b/spec/requests/api/v1/seeds_request_spec.rb @@ -4,7 +4,7 @@ RSpec.describe 'Photos', type: :request do subject { JSON.parse response.body } let(:headers) { { 'Accept' => 'application/vnd.api+json' } } - let!(:seed) { FactoryBot.create :seed } + let!(:seed) { FactoryBot.create :seed } let(:seed_encoded_as_json_api) do { "id" => seed.id.to_s, "type" => "seeds", diff --git a/spec/views/crops/_grown_for.html.haml_spec.rb b/spec/views/crops/_grown_for.html.haml_spec.rb index 0aef069c3..239b26dfd 100644 --- a/spec/views/crops/_grown_for.html.haml_spec.rb +++ b/spec/views/crops/_grown_for.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "crops/_grown_for" do - let(:crop) { FactoryBot.create(:crop) } + let(:crop) { FactoryBot.create(:crop) } let(:plant_path) { FactoryBot.create(:plant_part) } let!(:harvest) do FactoryBot.create(:harvest, diff --git a/spec/views/photos/show.html.haml_spec.rb b/spec/views/photos/show.html.haml_spec.rb index fb3ad8859..a4a275751 100644 --- a/spec/views/photos/show.html.haml_spec.rb +++ b/spec/views/photos/show.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe "photos/show" do let(:photo) { FactoryBot.create :photo, owner: member } - let(:crops) { FactoryBot.create_list :crop, 2 } + let(:crops) { FactoryBot.create_list :crop, 2 } before do @photo = photo @crops = crops @@ -10,10 +10,10 @@ describe "photos/show" do let(:member) { FactoryBot.create :member } - let(:harvest) { FactoryBot.create :harvest, owner: member } + let(:harvest) { FactoryBot.create :harvest, owner: member } let(:planting) { FactoryBot.create :planting, owner: member } - let(:seed) { FactoryBot.create :seed, owner: member } - let(:garden) { FactoryBot.create :garden, owner: member } + let(:seed) { FactoryBot.create :seed, owner: member } + let(:garden) { FactoryBot.create :garden, owner: member } shared_examples "photo data renders" do it "shows the image" do diff --git a/spec/views/plantings/index.html.haml_spec.rb b/spec/views/plantings/index.html.haml_spec.rb index 792c2b5e5..e65a5b642 100644 --- a/spec/views/plantings/index.html.haml_spec.rb +++ b/spec/views/plantings/index.html.haml_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' describe "plantings/index" do - let(:member) { FactoryBot.create(:member) } + let(:member) { FactoryBot.create(:member) } let(:garden) { FactoryBot.create(:garden, owner: member) } - let(:tomato) { FactoryBot.create(:tomato) } - let(:maize) { FactoryBot.create(:maize) } + let(:tomato) { FactoryBot.create(:tomato) } + let(:maize) { FactoryBot.create(:maize) } before do controller.stub(:current_user) { nil } diff --git a/spec/views/plantings/show.html.haml_spec.rb b/spec/views/plantings/show.html.haml_spec.rb index dfd503743..016a29182 100644 --- a/spec/views/plantings/show.html.haml_spec.rb +++ b/spec/views/plantings/show.html.haml_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' describe "plantings/show" do - let(:crop) { FactoryBot.create(:tomato) } - let(:member) { FactoryBot.create(:member) } + let(:crop) { FactoryBot.create(:tomato) } + let(:member) { FactoryBot.create(:member) } let(:garden) { FactoryBot.create(:garden, owner: member) } let(:planting) do FactoryBot.create(:planting, garden: garden, crop: crop, diff --git a/spec/views/scientific_names/edit.html.haml_spec.rb b/spec/views/scientific_names/edit.html.haml_spec.rb index 7c2a9de1e..b497b44e7 100644 --- a/spec/views/scientific_names/edit.html.haml_spec.rb +++ b/spec/views/scientific_names/edit.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe "scientific_names/edit" do context "logged in" do - let(:member) { FactoryBot.create(:member) } + let(:member) { FactoryBot.create(:member) } let(:scientific_name) { FactoryBot.create(:zea_mays, creator: member) } before do diff --git a/spec/views/seeds/new.html.haml_spec.rb b/spec/views/seeds/new.html.haml_spec.rb index 6b6d6e48d..fc40236e5 100644 --- a/spec/views/seeds/new.html.haml_spec.rb +++ b/spec/views/seeds/new.html.haml_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe "seeds/new" do let!(:seed) { FactoryBot.create(:seed, owner: member) } - let!(:member) { FactoryBot.create(:member) } + let!(:member) { FactoryBot.create(:member) } before do sign_in member diff --git a/spec/views/seeds/show.html.haml_spec.rb b/spec/views/seeds/show.html.haml_spec.rb index cd7507601..1c2e88442 100644 --- a/spec/views/seeds/show.html.haml_spec.rb +++ b/spec/views/seeds/show.html.haml_spec.rb @@ -18,7 +18,7 @@ describe "seeds/show" do context 'with location' do let!(:owner) { FactoryBot.create(:london_member) } let!(:seed) { FactoryBot.create(:tradable_seed, owner: owner) } - let!(:member) { FactoryBot.create(:member) } + let!(:member) { FactoryBot.create(:member) } before do assign(:seed, seed) From 89e75ffbee6f477d58ba6f7e33d3a3ec3e80aca3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Thu, 14 Mar 2019 07:24:01 +0000 Subject: [PATCH 022/124] Bump flickraw from 0.9.9 to 0.9.10 Bumps [flickraw](https://github.com/hanklords/flickraw) from 0.9.9 to 0.9.10. - [Release notes](https://github.com/hanklords/flickraw/releases) - [Commits](https://github.com/hanklords/flickraw/compare/V0.9.9...V0.9.10) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 348f90af0..39a1a16e8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -171,7 +171,7 @@ GEM ffi (1.9.25) figaro (1.1.1) thor (~> 0.14) - flickraw (0.9.9) + flickraw (0.9.10) font-awesome-sass (5.6.1) sassc (>= 1.11) friendly_id (5.2.5) From d8be8d0c4801662f57c8e64a970519caf6188d0a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Thu, 14 Mar 2019 08:39:17 +0000 Subject: [PATCH 023/124] Bump unicorn from 5.4.1 to 5.5.0 Bumps [unicorn](https://bogomips.org/unicorn/) from 5.4.1 to 5.5.0. Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 39a1a16e8..9584d6363 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -485,7 +485,7 @@ GEM uglifier (4.1.20) execjs (>= 0.3.0, < 3) unicode-display_width (1.4.1) - unicorn (5.4.1) + unicorn (5.5.0) kgio (~> 2.6) raindrops (~> 0.7) uniform_notifier (1.12.1) From 50ade63429909c13b41ec47f391217953b785491 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Thu, 14 Mar 2019 10:08:49 +0000 Subject: [PATCH 024/124] Auto corrected by following Lint Ruby RSpec/LeadingSubject --- spec/controllers/crops_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index d510ce92a..c3ca128eb 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -58,9 +58,9 @@ describe CropsController do end describe 'DELETE destroy' do + subject { delete :destroy, params: { slug: crop.to_param } } let!(:crop) { FactoryBot.create :crop } - subject { delete :destroy, params: { slug: crop.to_param } } context 'not logged in' do it { expect { subject }.not_to change(Crop, :count) } From f41ecbc68b487e437cdd741a0705a16291e4dbaf Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Thu, 14 Mar 2019 10:11:03 +0000 Subject: [PATCH 025/124] Auto corrected by following Lint Ruby EmptyLine --- spec/controllers/crops_controller_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index c3ca128eb..cb8e5a502 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -61,7 +61,6 @@ describe CropsController do subject { delete :destroy, params: { slug: crop.to_param } } let!(:crop) { FactoryBot.create :crop } - context 'not logged in' do it { expect { subject }.not_to change(Crop, :count) } end From f52daa12c5c1166c2ff83750fb045015943eb2a4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 18 Mar 2019 07:55:49 +0000 Subject: [PATCH 026/124] Bump dalli from 2.7.9 to 2.7.10 Bumps [dalli](https://github.com/petergoldstein/dalli) from 2.7.9 to 2.7.10. - [Release notes](https://github.com/petergoldstein/dalli/releases) - [Changelog](https://github.com/petergoldstein/dalli/blob/master/History.md) - [Commits](https://github.com/petergoldstein/dalli/compare/v2.7.9...v2.7.10) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9584d6363..86a669f2e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -132,7 +132,7 @@ GEM crass (1.0.4) csv_shaper (1.3.0) activesupport (>= 3.0.0) - dalli (2.7.9) + dalli (2.7.10) database_cleaner (1.7.0) devise (4.6.1) bcrypt (~> 3.0) From 4d062964b64b0dcfc31761d21e7ce2dc73e7e57a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 18 Mar 2019 11:17:15 +0000 Subject: [PATCH 027/124] Bump comfortable_mexican_sofa from 2.0.17 to 2.0.18 Bumps [comfortable_mexican_sofa](https://github.com/comfy/comfortable-mexican-sofa) from 2.0.17 to 2.0.18. - [Release notes](https://github.com/comfy/comfortable-mexican-sofa/releases) - [Commits](https://github.com/comfy/comfortable-mexican-sofa/compare/v2.0.17...v2.0.18) Signed-off-by: dependabot[bot] --- Gemfile.lock | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 86a669f2e..435ad5b6b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -108,7 +108,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - comfortable_mexican_sofa (2.0.17) + comfortable_mexican_sofa (2.0.18) active_link_to (>= 1.0.0) comfy_bootstrap_form (>= 4.0.0) haml-rails (>= 1.0.0) @@ -118,7 +118,7 @@ GEM mini_magick (>= 4.8.0) rails (>= 5.2.0) rails-i18n (>= 5.0.0) - sass-rails (>= 5.0.0) + sassc-rails (>= 2.0.0) comfy_bootstrap_form (4.0.6) rails (>= 5.0.0) concurrent-ruby (1.1.5) @@ -262,7 +262,7 @@ GEM kaminari-core (= 1.1.1) kaminari-core (1.1.1) kgio (2.11.2) - kramdown (1.17.0) + kramdown (2.1.0) launchy (2.4.3) addressable (~> 2.3) leaflet-rails (1.3.1) @@ -286,7 +286,7 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2018.0812) mimemagic (0.3.3) - mini_magick (4.9.2) + mini_magick (4.9.3) mini_mime (1.0.1) mini_portile2 (2.4.0) minitest (5.11.3) @@ -370,7 +370,7 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - rails-i18n (5.1.2) + rails-i18n (5.1.3) i18n (>= 0.7, < 2) railties (>= 5.0, < 6) rails_12factor (0.0.3) @@ -430,10 +430,10 @@ GEM ruby-progressbar (1.10.0) ruby-units (2.3.1) ruby_dep (1.5.0) - ruby_parser (3.12.0) + ruby_parser (3.13.0) sexp_processor (~> 4.9) rubyzip (1.2.2) - sass (3.7.2) + sass (3.7.3) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) @@ -447,10 +447,16 @@ GEM sassc (2.0.0) ffi (~> 1.9.6) rake + sassc-rails (2.1.0) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt selenium-webdriver (3.141.0) childprocess (~> 0.5) rubyzip (~> 1.2, >= 1.2.2) - sexp_processor (4.11.0) + sexp_processor (4.12.0) sidekiq (5.2.5) connection_pool (~> 2.2, >= 2.2.2) rack (>= 1.5.0) From fe6f6046e4c5fd3ec8d335d0b10f43fae0daede8 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Tue, 19 Mar 2019 07:22:50 +0000 Subject: [PATCH 028/124] Auto corrected by following Lint Ruby RSpecEmptyLine --- spec/controllers/crops_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index cb8e5a502..d9dce9b9e 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -59,6 +59,7 @@ describe CropsController do describe 'DELETE destroy' do subject { delete :destroy, params: { slug: crop.to_param } } + let!(:crop) { FactoryBot.create :crop } context 'not logged in' do From 0f1c6ae3b6f0017e6273042553033702ea4ca879 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 19 Mar 2019 20:28:24 +0000 Subject: [PATCH 029/124] Bump byebug from 11.0.0 to 11.0.1 Bumps [byebug](https://github.com/deivid-rodriguez/byebug) from 11.0.0 to 11.0.1. - [Release notes](https://github.com/deivid-rodriguez/byebug/releases) - [Changelog](https://github.com/deivid-rodriguez/byebug/blob/master/CHANGELOG.md) - [Commits](https://github.com/deivid-rodriguez/byebug/compare/v11.0.0...v11.0.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 435ad5b6b..51b60dac6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -78,7 +78,7 @@ GEM bullet (5.9.0) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) - byebug (11.0.0) + byebug (11.0.1) cancancan (2.3.0) capybara (3.14.0) addressable From d07c97b6a67dbedd5b75fd57ee2fa9789bd4df8a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 17 Mar 2019 15:19:04 +1300 Subject: [PATCH 030/124] Add filters for the members api --- app/resources/api/v1/member_resource.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/resources/api/v1/member_resource.rb b/app/resources/api/v1/member_resource.rb index b5b0a94a0..4013aeea4 100644 --- a/app/resources/api/v1/member_resource.rb +++ b/app/resources/api/v1/member_resource.rb @@ -7,9 +7,13 @@ module Api has_many :plantings has_many :harvests has_many :seeds + has_many :photos attribute :login_name + attribute :slug + + filters :login_name, :slug end end end From 6559645265356328f752cdc107b1d060e2c1f283 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 18 Mar 2019 13:24:47 +1300 Subject: [PATCH 031/124] update spec --- spec/requests/api/v1/member_request_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/requests/api/v1/member_request_spec.rb b/spec/requests/api/v1/member_request_spec.rb index efc5a1feb..f869af9b2 100644 --- a/spec/requests/api/v1/member_request_spec.rb +++ b/spec/requests/api/v1/member_request_spec.rb @@ -53,7 +53,8 @@ RSpec.describe 'Members', type: :request do let(:attributes) do { - "login-name" => member.login_name + "login-name" => member.login_name, + "slug" => member.slug } end From 62f2fa134df1acc2367296af43ca99e6d83c8bea Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 18 Mar 2019 13:25:11 +1300 Subject: [PATCH 032/124] Set planting.finished as a boolean --- app/resources/api/v1/planting_resource.rb | 2 +- db/migrate/20190317023129_finished_boolean.rb | 8 ++++++++ db/schema.rb | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190317023129_finished_boolean.rb diff --git a/app/resources/api/v1/planting_resource.rb b/app/resources/api/v1/planting_resource.rb index 030f57892..dce3aaf7d 100644 --- a/app/resources/api/v1/planting_resource.rb +++ b/app/resources/api/v1/planting_resource.rb @@ -30,7 +30,7 @@ module Api filter :planted_from filter :garden filter :owner - filter :finished, default: nil + filter :finished attribute :percentage_grown def percentage_grown diff --git a/db/migrate/20190317023129_finished_boolean.rb b/db/migrate/20190317023129_finished_boolean.rb new file mode 100644 index 000000000..5f8601fca --- /dev/null +++ b/db/migrate/20190317023129_finished_boolean.rb @@ -0,0 +1,8 @@ +class FinishedBoolean < ActiveRecord::Migration[5.2] + def change + Planting.where('finished_at < now()').update_all(finished: true) + Planting.where(finished: nil).update_all(finished: false) + change_column_null :plantings, :finished, false + change_column_default :plantings, :finished, from: nil, to: false + end +end diff --git a/db/schema.rb b/db/schema.rb index d2d475824..5c98e630d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_01_30_090437) do +ActiveRecord::Schema.define(version: 2019_03_17_023129) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -385,7 +385,7 @@ ActiveRecord::Schema.define(version: 2019_01_30_090437) do t.string "sunniness" t.string "planted_from" t.integer "owner_id" - t.boolean "finished", default: false + t.boolean "finished", default: false, null: false t.date "finished_at" t.integer "lifespan" t.integer "days_to_first_harvest" From 45f22c1b45430c4bb3179c1ad36ca8bc7ec4f5b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 19 Mar 2019 21:39:40 +0000 Subject: [PATCH 033/124] Bump responders from 2.4.0 to 2.4.1 Bumps [responders](https://github.com/plataformatec/responders) from 2.4.0 to 2.4.1. - [Release notes](https://github.com/plataformatec/responders/releases) - [Changelog](https://github.com/plataformatec/responders/blob/master/CHANGELOG.md) - [Commits](https://github.com/plataformatec/responders/compare/v2.4.0...v2.4.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 51b60dac6..92d61cf8a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -392,9 +392,9 @@ GEM ffi (~> 1.0) redis (4.1.0) regexp_parser (1.3.0) - responders (2.4.0) - actionpack (>= 4.2.0, < 5.3) - railties (>= 4.2.0, < 5.3) + responders (2.4.1) + actionpack (>= 4.2.0, < 6.0) + railties (>= 4.2.0, < 6.0) rspec-activemodel-mocks (1.1.0) activemodel (>= 3.0) activesupport (>= 3.0) From afc769aa5f707505adfcd42be656c04b1cf0cd44 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 19 Mar 2019 21:51:56 +0000 Subject: [PATCH 034/124] Bump rubocop from 0.65.0 to 0.66.0 Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.65.0 to 0.66.0. - [Release notes](https://github.com/rubocop-hq/rubocop/releases) - [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.65.0...v0.66.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 92d61cf8a..80773f3bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -336,7 +336,6 @@ GEM capybara (>= 2.1, < 4) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) - powerpack (0.1.2) psych (3.1.0) public_suffix (3.0.3) puma (3.12.0) @@ -416,15 +415,14 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.65.0) + rubocop (0.66.0) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5, != 2.5.1.1) - powerpack (~> 0.1) psych (>= 3.1.0) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.4.0) + unicode-display_width (>= 1.4.0, < 1.6) rubocop-rspec (1.32.0) rubocop (>= 0.60.0) ruby-progressbar (1.10.0) @@ -490,7 +488,7 @@ GEM thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) - unicode-display_width (1.4.1) + unicode-display_width (1.5.0) unicorn (5.5.0) kgio (~> 2.6) raindrops (~> 0.7) From 5395aefa660592de90dfba00f2c78add3ce6d315 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 20:48:51 +1300 Subject: [PATCH 035/124] Rename containers to garden types --- app/controllers/containers_controller.rb | 56 ------------------- app/controllers/garden_types_controller.rb | 51 +++++++++++++++++ app/controllers/gardens_controller.rb | 2 +- app/models/ability.rb | 12 ++-- app/models/container.rb | 19 ------- app/models/garden.rb | 2 +- app/models/garden_type.rb | 19 +++++++ app/models/plot.rb | 4 -- app/views/containers/_actions.html.haml | 4 -- app/views/containers/_form.html.haml | 20 ------- app/views/containers/_thumbnail.html.haml | 7 --- app/views/containers/edit.html.haml | 4 -- app/views/containers/index.html.haml | 17 ------ app/views/containers/new.html.haml | 4 -- app/views/containers/show.html.haml | 12 ---- app/views/garden_types/_actions.html.haml | 4 ++ app/views/garden_types/_form.html.haml | 20 +++++++ app/views/garden_types/_thumbnail.html.haml | 7 +++ app/views/garden_types/edit.html.haml | 4 ++ app/views/garden_types/index.html.haml | 17 ++++++ app/views/garden_types/new.html.haml | 4 ++ app/views/garden_types/show.html.haml | 12 ++++ app/views/gardens/_form.html.haml | 10 ++-- app/views/layouts/_header.html.haml | 2 +- config/routes.rb | 2 +- .../20181129171803_create_containers.rb | 15 ----- .../20190326063855_create_garden_types.rb | 17 ++++++ db/schema.rb | 28 ++++------ spec/factories/containers.rb | 5 -- spec/factories/garden_types.rb | 5 ++ spec/factories/plots.rb | 6 -- spec/models/container_spec.rb | 37 ------------ spec/models/garden_type.rb | 37 ++++++++++++ spec/models/plot_spec.rb | 17 ------ ...ontainers_spec.rb => garden_types_spec.rb} | 6 +- spec/views/containers/edit.html.haml_spec.rb | 2 +- spec/views/containers/new.html.haml_spec.rb | 2 +- 37 files changed, 228 insertions(+), 264 deletions(-) delete mode 100644 app/controllers/containers_controller.rb create mode 100644 app/controllers/garden_types_controller.rb delete mode 100644 app/models/container.rb create mode 100644 app/models/garden_type.rb delete mode 100644 app/models/plot.rb delete mode 100644 app/views/containers/_actions.html.haml delete mode 100644 app/views/containers/_form.html.haml delete mode 100644 app/views/containers/_thumbnail.html.haml delete mode 100644 app/views/containers/edit.html.haml delete mode 100644 app/views/containers/index.html.haml delete mode 100644 app/views/containers/new.html.haml delete mode 100644 app/views/containers/show.html.haml create mode 100644 app/views/garden_types/_actions.html.haml create mode 100644 app/views/garden_types/_form.html.haml create mode 100644 app/views/garden_types/_thumbnail.html.haml create mode 100644 app/views/garden_types/edit.html.haml create mode 100644 app/views/garden_types/index.html.haml create mode 100644 app/views/garden_types/new.html.haml create mode 100644 app/views/garden_types/show.html.haml delete mode 100644 db/migrate/20181129171803_create_containers.rb create mode 100644 db/migrate/20190326063855_create_garden_types.rb delete mode 100644 spec/factories/containers.rb create mode 100644 spec/factories/garden_types.rb delete mode 100644 spec/factories/plots.rb delete mode 100644 spec/models/container_spec.rb create mode 100644 spec/models/garden_type.rb delete mode 100644 spec/models/plot_spec.rb rename spec/requests/{containers_spec.rb => garden_types_spec.rb} (55%) diff --git a/app/controllers/containers_controller.rb b/app/controllers/containers_controller.rb deleted file mode 100644 index 69458da16..000000000 --- a/app/controllers/containers_controller.rb +++ /dev/null @@ -1,56 +0,0 @@ -class ContainersController < ApplicationController - # before_action :authenticate_member!, except: %i(index show) - load_and_authorize_resource - - # GET /containers - def index - @containers = Container.all.paginate(page: params[:page]) - end - - # GET /containers/1 - def show; end - - # GET /containers/new - def new - @container = Container.new - end - - # GET /containers/1/edit - def edit; end - - # POST /containers - def create - @container = Container.new(container_params) - - if @container.save - redirect_to @container, notice: 'Container was successfully created.' - else - render :new - end - end - - # PATCH/PUT /containers/1 - def update - if @container.update(container_params) - redirect_to @container, notice: 'Container was successfully updated.' - else - render :edit - end - end - - # DELETE /containers/1 - def destroy - @container.destroy - redirect_to containers_url, notice: 'Container was successfully destroyed.' - end - - private - - def set_container - @container = Container.find(params[:id]) - end - - def container_params - params.require(:container).permit(:description, :slug) - end -end diff --git a/app/controllers/garden_types_controller.rb b/app/controllers/garden_types_controller.rb new file mode 100644 index 000000000..5fade528a --- /dev/null +++ b/app/controllers/garden_types_controller.rb @@ -0,0 +1,51 @@ +class GardenTypesController < ApplicationController + respond_to :html, :json + load_and_authorize_resource + + # GET /garden_types + def index + @garden_types = GardenType.all.paginate(page: params[:page]) + respond_with @garden_types + end + + # GET /garden_types/1 + def show + respond_with @garden_type + end + + # GET /garden_types/new + def new + @garden_type = GardenType.new + end + + # GET /garden_types/1/edit + def edit; end + + # POST /garden_types + def create + @garden_type = GardenType.create(garden_type_params) + respond_with(@garden_type) + end + + # PATCH/PUT /garden_types/1 + def update + @garden_type.update(garden_type_params) + respond_with @garden_type + end + + # DELETE /garden_types/1 + def destroy + @garden_type.destroy + respond_with @garden_type + end + + private + + def set_garden_type + @garden_type = GardenType.find(params[:id]) + end + + def garden_type_params + params.require(:garden_type).permit(:description, :slug) + end +end diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index 9aaa253f1..82ed8d2a4 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -67,6 +67,6 @@ class GardensController < ApplicationController def garden_params params.require(:garden).permit(:name, :slug, :description, :active, - :location, :latitude, :longitude, :area, :area_unit, container_ids: []) + :location, :latitude, :longitude, :area, :area_unit, :garden_type_id) end end diff --git a/app/models/ability.rb b/app/models/ability.rb index dcc3b8300..66c48a8c4 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -43,9 +43,9 @@ class Ability an.crop.approved? end - cannot :create, Container - cannot :update, Container - cannot :destroy, Container + cannot :create, GardenType + cannot :update, GardenType + cannot :destroy, GardenType end def member_abilities(member) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength @@ -129,9 +129,9 @@ class Ability can :destroy, Follow cannot :destroy, Follow, followed_id: member.id # can't unfollow yourself - cannot :create, Container - cannot :update, Container - cannot :destroy, Container + cannot :create, GardenType + cannot :update, GardenType + cannot :destroy, GardenType end def admin_abilities(member) diff --git a/app/models/container.rb b/app/models/container.rb deleted file mode 100644 index a36b2099d..000000000 --- a/app/models/container.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Container < ApplicationRecord - extend FriendlyId - friendly_id :description, use: %i(slugged finders) - - has_many :plots, dependent: :destroy - has_many :gardens, through: :plots - - validates :description, presence: true, uniqueness: true - - def container_slug - description.gsub!(/[^A-Za-z ]/, '') - end - - def subtitler(container) - num = container.gardens.uniq.count - s = num > 1 || num.zero? ? "s are" : " is" - "#{num} garden#{s} using this container" - end -end diff --git a/app/models/garden.rb b/app/models/garden.rb index 4e2e13efa..b64b7375b 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -9,7 +9,7 @@ class Garden < ApplicationRecord has_many :crops, through: :plantings has_many :plots, dependent: :destroy - has_many :containers, through: :plots + belongs_to :garden_type, required: false # set up geocoding geocoded_by :location diff --git a/app/models/garden_type.rb b/app/models/garden_type.rb new file mode 100644 index 000000000..da84bf01e --- /dev/null +++ b/app/models/garden_type.rb @@ -0,0 +1,19 @@ +class GardenType < ApplicationRecord + extend FriendlyId + friendly_id :name, use: %i(slugged finders) + + has_many :gardens + + validates :name, presence: true, uniqueness: true + validates :slug, presence: true, uniqueness: true + + def garden_type_slug + name.gsub!(/[^A-Za-z ]/, '') + end + + def subtitler(container) + num = container.gardens.uniq.count + s = num > 1 || num.zero? ? "s are" : " is" + "#{num} garden#{s} using this container" + end +end diff --git a/app/models/plot.rb b/app/models/plot.rb deleted file mode 100644 index c253e3d58..000000000 --- a/app/models/plot.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Plot < ApplicationRecord - belongs_to :garden - belongs_to :container -end diff --git a/app/views/containers/_actions.html.haml b/app/views/containers/_actions.html.haml deleted file mode 100644 index 95bf704fe..000000000 --- a/app/views/containers/_actions.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -.btn-group.container-actions - = render 'shared/buttons/edit', path: edit_container_path(container) - .pull-right - = render 'shared/buttons/delete', path: container_path(container) diff --git a/app/views/containers/_form.html.haml b/app/views/containers/_form.html.haml deleted file mode 100644 index f4fd7e8ba..000000000 --- a/app/views/containers/_form.html.haml +++ /dev/null @@ -1,20 +0,0 @@ -= form_for @container, html: { class: 'form-horizontal', role: "form" } do |f| - - if @container.errors.any? - #error_explanation - %h2= "#{pluralize(@container.errors.count, "error")} prohibited this container from being saved:" - %ul - - @container.errors.full_messages.each do |message| - %li= message - - %h2 Basic information - - .form-group - = f.label :description, class: 'control-label col-md-2' - .col-md-8 - = f.text_field :description, class: 'form-control' - %span.help-block - The name for the container, i.e. "organic", in English (required). - - .form-group - .form-actions.col-md-offset-2.col-md-8 - = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/containers/_thumbnail.html.haml b/app/views/containers/_thumbnail.html.haml deleted file mode 100644 index ff235a90e..000000000 --- a/app/views/containers/_thumbnail.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -- cache cache_key_for(Container, container.id) do - .thumbnail - .container-thumbnail - - if container - .containerinfo - .containername - = link_to container.description, container diff --git a/app/views/containers/edit.html.haml b/app/views/containers/edit.html.haml deleted file mode 100644 index ee890d6b7..000000000 --- a/app/views/containers/edit.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -- content_for :title, "Edit Container" - -- if can? :update, @container - = render 'form' diff --git a/app/views/containers/index.html.haml b/app/views/containers/index.html.haml deleted file mode 100644 index 040a892bc..000000000 --- a/app/views/containers/index.html.haml +++ /dev/null @@ -1,17 +0,0 @@ -- content_for :title, 'Containers' - -%p - #{ENV['GROWSTUFF_SITE_NAME']} tracks who's growing what, where. - View any container page to see which of our members have used it. - -.row - - @containers.each do |container| - .col-md-2.six-across - = render partial: "thumbnail", locals: { container: container } - -- if can? :create, Container - %div - = link_to 'New Container', new_container_path, class: 'btn btn-primary' - -.pagination - = will_paginate @containers diff --git a/app/views/containers/new.html.haml b/app/views/containers/new.html.haml deleted file mode 100644 index b6e92973a..000000000 --- a/app/views/containers/new.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -- content_for :title, "New Container" - -- if can? :create, @container - = render 'form' diff --git a/app/views/containers/show.html.haml b/app/views/containers/show.html.haml deleted file mode 100644 index 615403575..000000000 --- a/app/views/containers/show.html.haml +++ /dev/null @@ -1,12 +0,0 @@ -- content_for :title, @container.description.capitalize -- content_for :subtitle, @container.subtitler(@container) - -- if can?(:create, @container) && can?(:edit, @container) && can?(:destroy, @container) - - content_for :buttonbar do - = render 'containers/actions', container: @container - -- if @container.gardens.uniq.empty? - %p There are no gardens to display. -- else - - @container.gardens.uniq.each do |garden| - = render 'gardens/overview', garden: garden diff --git a/app/views/garden_types/_actions.html.haml b/app/views/garden_types/_actions.html.haml new file mode 100644 index 000000000..9dcf04028 --- /dev/null +++ b/app/views/garden_types/_actions.html.haml @@ -0,0 +1,4 @@ +.btn-group.garden_type-actions + = render 'shared/buttons/edit', path: edit_garden_type_path(garden_type) + .pull-right + = render 'shared/buttons/delete', path: garden_type_path(garden_type) diff --git a/app/views/garden_types/_form.html.haml b/app/views/garden_types/_form.html.haml new file mode 100644 index 000000000..a6d84885a --- /dev/null +++ b/app/views/garden_types/_form.html.haml @@ -0,0 +1,20 @@ += form_for @garden_type, html: { class: 'form-horizontal', role: "form" } do |f| + - if @garden_type.errors.any? + #error_explanation + %h2= "#{pluralize(@garden_type.errors.count, "error")} prohibited this garden_type from being saved:" + %ul + - @garden_type.errors.full_messages.each do |message| + %li= message + + %h2 Basic information + + .form-group + = f.label :name, class: 'control-label col-md-2' + .col-md-8 + = f.text_field :name, class: 'form-control' + %span.help-block + The name for the garden_type, i.e. "organic", in English (required). + + .form-group + .form-actions.col-md-offset-2.col-md-8 + = f.submit 'Save', class: 'btn btn-primary' diff --git a/app/views/garden_types/_thumbnail.html.haml b/app/views/garden_types/_thumbnail.html.haml new file mode 100644 index 000000000..1004ac019 --- /dev/null +++ b/app/views/garden_types/_thumbnail.html.haml @@ -0,0 +1,7 @@ +- cache cache_key_for(GardenType, garden_type.id) do + .thumbnail + .garden_type-thumbnail + - if garden_type + .garden_typeinfo + .garden_typename + = link_to garden_type.name, garden_type diff --git a/app/views/garden_types/edit.html.haml b/app/views/garden_types/edit.html.haml new file mode 100644 index 000000000..1ec811b50 --- /dev/null +++ b/app/views/garden_types/edit.html.haml @@ -0,0 +1,4 @@ +- content_for :title, "Edit GardenType" + +- if can? :update, @garden_type + = render 'form' diff --git a/app/views/garden_types/index.html.haml b/app/views/garden_types/index.html.haml new file mode 100644 index 000000000..49352bc4c --- /dev/null +++ b/app/views/garden_types/index.html.haml @@ -0,0 +1,17 @@ +- content_for :title, 'GardenTypes' + +%p + #{ENV['GROWSTUFF_SITE_NAME']} tracks who's growing what, where. + View any garden_type page to see which of our members have used it. + +.row + - @garden_types.each do |garden_type| + .col-md-2.six-across + = render partial: "thumbnail", locals: { garden_type: garden_type } + +- if can? :create, GardenType + %div + = link_to 'New GardenType', new_garden_type_path, class: 'btn btn-primary' + +.pagination + = will_paginate @garden_types diff --git a/app/views/garden_types/new.html.haml b/app/views/garden_types/new.html.haml new file mode 100644 index 000000000..a898fef65 --- /dev/null +++ b/app/views/garden_types/new.html.haml @@ -0,0 +1,4 @@ +- content_for :title, "New GardenType" + +- if can? :create, @garden_type + = render 'form' diff --git a/app/views/garden_types/show.html.haml b/app/views/garden_types/show.html.haml new file mode 100644 index 000000000..cd9575965 --- /dev/null +++ b/app/views/garden_types/show.html.haml @@ -0,0 +1,12 @@ +- content_for :title, @garden_type.name.capitalize +- content_for :subtitle, @garden_type.subtitler(@garden_type) + +- if can?(:create, @garden_type) && can?(:edit, @garden_type) && can?(:destroy, @garden_type) + - content_for :buttonbar do + = render 'garden_types/actions', garden_type: @garden_type + +- if @garden_type.gardens.uniq.empty? + %p There are no gardens to display. +- else + - @garden_type.gardens.uniq.each do |garden| + = render 'gardens/overview', garden: garden diff --git a/app/views/gardens/_form.html.haml b/app/views/gardens/_form.html.haml index e7fbc52e3..b5510fad9 100644 --- a/app/views/gardens/_form.html.haml +++ b/app/views/gardens/_form.html.haml @@ -44,11 +44,13 @@ = f.select(:area_unit, Garden::AREA_UNITS_VALUES, { include_blank: false }, class: 'form-control') .form-group - = f.label :container, class: 'control-label col-md-2' + = f.label :garden_type, class: 'control-label col-md-2' .col-md-2 - = f.collection_check_boxes(:container_ids, Container.all, :id, :description) do |c| - = c.label class:"checkbox-inline" do - = c.check_box + c.text + = collection_select(:garden, :garden_type_id, + GardenType.all.order(:name), + :id, :name, + selected: @garden.garden_type_id, + class: 'form-control') .form-group = f.label :active, 'Active? ', class: 'control-label col-md-2' diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 2197507b4..9daa7c14b 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -30,7 +30,7 @@ %li= link_to t('.seeds'), seeds_path %li= link_to t('.plantings'), plantings_path %li= link_to t('.harvests'), harvests_path - %li= link_to t('.containers'), containers_path + %li= link_to t('.garden_types'), garden_types_path %li.dropdown< %a.dropdown-toggle{ 'data-toggle': 'dropdown', href: members_path } = t('.community') diff --git a/config/routes.rb b/config/routes.rb index 5939326ff..ff1687d52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do get '/robots.txt' => 'robots#robots' - resources :containers + resources :garden_types resources :plant_parts devise_for :members, controllers: { diff --git a/db/migrate/20181129171803_create_containers.rb b/db/migrate/20181129171803_create_containers.rb deleted file mode 100644 index a57f9e941..000000000 --- a/db/migrate/20181129171803_create_containers.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateContainers < ActiveRecord::Migration[4.2] - def change - create_table :containers do |t| - t.string :description - t.timestamps null: false - end - create_table :plots do |t| - t.references :garden, foreign_key: true - t.references :container, foreign_key: true - t.timestamps null: false - end - add_column :containers, :slug, :string - add_index :containers, :slug, unique: true - end -end diff --git a/db/migrate/20190326063855_create_garden_types.rb b/db/migrate/20190326063855_create_garden_types.rb new file mode 100644 index 000000000..7e3af2322 --- /dev/null +++ b/db/migrate/20190326063855_create_garden_types.rb @@ -0,0 +1,17 @@ +class CreateGardenTypes < ActiveRecord::Migration[5.2] + def change + create_table :garden_types do |t| + t.text :name, null: false, unique: true + t.text :slug, null: false, unique: true + t.timestamps null: false + end + add_column :gardens, :garden_type_id, :integer + add_index :gardens, :garden_type_id + ['organic', 'conventional', 'container', 'vertical', 'greenhouse', 'rooftop', 'no-dig', 'raised bed', + 'wicking bed', 'permaculture', 'hydroponic', 'aquaponic', 'orchard', 'food forest', + 'biodynamic'].each do |name| + say "Creating #{name}" + GardenType.create! name: name + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 84e6a994d..d0e1ac43e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_03_17_023129) do +ActiveRecord::Schema.define(version: 2019_03_26_063855) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -153,14 +153,6 @@ ActiveRecord::Schema.define(version: 2019_03_17_023129) do t.datetime "updated_at" end - create_table "containers", id: :serial, force: :cascade do |t| - t.string "description" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "slug" - t.index ["slug"], name: "index_containers_on_slug", unique: true - end - create_table "crops", id: :serial, force: :cascade do |t| t.string "name", null: false t.string "en_wikipedia_url" @@ -208,6 +200,13 @@ ActiveRecord::Schema.define(version: 2019_03_17_023129) do t.index ["slug"], name: "index_forums_on_slug", unique: true end + create_table "garden_types", force: :cascade do |t| + t.text "name", null: false + t.text "slug", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "gardens", id: :serial, force: :cascade do |t| t.string "name", null: false t.integer "owner_id" @@ -221,6 +220,8 @@ ActiveRecord::Schema.define(version: 2019_03_17_023129) do t.float "longitude" t.decimal "area" t.string "area_unit" + t.integer "garden_type_id" + t.index ["garden_type_id"], name: "index_gardens_on_garden_type_id" t.index ["owner_id"], name: "index_gardens_on_owner_id" t.index ["slug"], name: "index_gardens_on_slug", unique: true end @@ -402,13 +403,6 @@ ActiveRecord::Schema.define(version: 2019_03_17_023129) do t.index ["slug"], name: "index_plantings_on_slug", unique: true end - create_table "plots", id: :serial, force: :cascade do |t| - t.integer "garden_id" - t.integer "container_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - create_table "posts", id: :serial, force: :cascade do |t| t.integer "author_id", null: false t.string "subject", null: false @@ -463,7 +457,5 @@ ActiveRecord::Schema.define(version: 2019_03_17_023129) do add_foreign_key "photographings", "crops" add_foreign_key "photographings", "photos" add_foreign_key "plantings", "seeds", column: "parent_seed_id", name: "parent_seed", on_delete: :nullify - add_foreign_key "plots", "containers" - add_foreign_key "plots", "gardens" add_foreign_key "seeds", "plantings", column: "parent_planting_id", name: "parent_planting", on_delete: :nullify end diff --git a/spec/factories/containers.rb b/spec/factories/containers.rb deleted file mode 100644 index f6b9f8cc4..000000000 --- a/spec/factories/containers.rb +++ /dev/null @@ -1,5 +0,0 @@ -FactoryBot.define do - factory :container do - description { "homemade swamp" } - end -end diff --git a/spec/factories/garden_types.rb b/spec/factories/garden_types.rb new file mode 100644 index 000000000..942fd7932 --- /dev/null +++ b/spec/factories/garden_types.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :garden_type do + name { "homemade swamp" } + end +end diff --git a/spec/factories/plots.rb b/spec/factories/plots.rb deleted file mode 100644 index 9193888f3..000000000 --- a/spec/factories/plots.rb +++ /dev/null @@ -1,6 +0,0 @@ -FactoryBot.define do - factory :plot do - garden { garden } - container { container } - end -end diff --git a/spec/models/container_spec.rb b/spec/models/container_spec.rb deleted file mode 100644 index bac3e8e30..000000000 --- a/spec/models/container_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'rails_helper' - -describe Container do - let(:owner) { FactoryBot.create(:member) } - let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Free Carrots') } - let(:container) { FactoryBot.create(:container, description: "fake hole in the ground") } - - it "should have a description" do - container = FactoryBot.build(:container, description: "organic") - container.should be_valid - end - - it "doesn't allow a nil description" do - container = FactoryBot.build(:container, description: nil) - container.should_not be_valid - end - - it "doesn't allow a blank description" do - container = FactoryBot.build(:container, description: "") - container.should_not be_valid - end - - it "doesn't allow a description with only spaces" do - container = FactoryBot.build(:container, description: " ") - container.should_not be_valid - end - - it "destroys plots when deleted" do - container = FactoryBot.create(:container, description: "Massive Flower Pot") - @plot1 = FactoryBot.create(:plot, garden: garden, container: container) - @plot2 = FactoryBot.create(:plot, garden: garden, container: container) - container.plots.size.should eq(2) - all = Plot.count - container.destroy - Plot.count.should eq(all - 2) - end -end diff --git a/spec/models/garden_type.rb b/spec/models/garden_type.rb new file mode 100644 index 000000000..d237e6055 --- /dev/null +++ b/spec/models/garden_type.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +describe GardenType do + let(:owner) { FactoryBot.create(:member) } + let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Free Carrots') } + let(:container) { FactoryBot.create(:container, name: "fake hole in the ground") } + + it "should have a name" do + container = FactoryBot.build(:container, name: "organic") + container.should be_valid + end + + it "doesn't allow a nil name" do + container = FactoryBot.build(:container, name: nil) + container.should_not be_valid + end + + it "doesn't allow a blank name" do + container = FactoryBot.build(:container, name: "") + container.should_not be_valid + end + + it "doesn't allow a name with only spaces" do + container = FactoryBot.build(:container, name: " ") + container.should_not be_valid + end + + it "destroys plots when deleted" do + container = FactoryBot.create(:container, name: "Massive Flower Pot") + @plot1 = FactoryBot.create(:plot, garden: garden, container: container) + @plot2 = FactoryBot.create(:plot, garden: garden, container: container) + container.plots.size.should eq(2) + all = Plot.count + container.destroy + Plot.count.should eq(all - 2) + end +end diff --git a/spec/models/plot_spec.rb b/spec/models/plot_spec.rb deleted file mode 100644 index 4a3a16724..000000000 --- a/spec/models/plot_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'rails_helper' - -describe Plot do - let(:owner) { FactoryBot.create(:member) } - let(:garden) { FactoryBot.create(:garden) } - let(:container) { FactoryBot.create(:container) } - let(:plot) { FactoryBot.create(:plot, garden: garden, container: container) } - - context "has valid attributes" do - it "should have a garden" do - plot.garden.description.should == "This is a **totally** cool garden" - end - it "should have a container" do - plot.container.description.should == "homemade swamp" - end - end -end diff --git a/spec/requests/containers_spec.rb b/spec/requests/garden_types_spec.rb similarity index 55% rename from spec/requests/containers_spec.rb rename to spec/requests/garden_types_spec.rb index 0f61eb278..fbacd0491 100644 --- a/spec/requests/containers_spec.rb +++ b/spec/requests/garden_types_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' -RSpec.describe "Containers", type: :request do - describe "GET /containers" do +RSpec.describe "GardenTypes", type: :request do + describe "GET /garden_types" do it "works! (now write some real specs)" do - get containers_path + get garden_types_path expect(response).to have_http_status(200) end end diff --git a/spec/views/containers/edit.html.haml_spec.rb b/spec/views/containers/edit.html.haml_spec.rb index 3b9d61737..f47a8492d 100644 --- a/spec/views/containers/edit.html.haml_spec.rb +++ b/spec/views/containers/edit.html.haml_spec.rb @@ -10,7 +10,7 @@ describe "containers/edit" do end it "renders the edit container form" do - assert_select "form", action: containers_path, method: "post" do + assert_select "form", action: garden_types_path, method: "post" do assert_select "input#container_description", name: "container[description]" end end diff --git a/spec/views/containers/new.html.haml_spec.rb b/spec/views/containers/new.html.haml_spec.rb index f56d956fb..28fa68c84 100644 --- a/spec/views/containers/new.html.haml_spec.rb +++ b/spec/views/containers/new.html.haml_spec.rb @@ -10,7 +10,7 @@ describe "containers/new" do end it "renders new container form" do - assert_select "form", action: containers_path, method: "post" do + assert_select "form", action: garden_types_path, method: "post" do assert_select "input#container_description", name: "container[description]" end end From b446e44ac0d4f723635458aaaa16ae93ebb8c7b4 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:00:34 +1300 Subject: [PATCH 036/124] Moved garden types to admin menu --- app/views/admin/index.html.haml | 2 ++ app/views/layouts/_header.html.haml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/admin/index.html.haml b/app/views/admin/index.html.haml index e7b164280..ba67f1ec2 100644 --- a/app/views/admin/index.html.haml +++ b/app/views/admin/index.html.haml @@ -5,10 +5,12 @@ .row .col-md-4 %h2 Site admin + %ul#site_admin %li= link_to "Roles", roles_path %li= link_to "Forums", forums_path %li= link_to "CMS", comfy_admin_cms_path + %li= link_to t('.garden_types'), garden_types_path .col-md-4 %h2 Crop data admin diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 9daa7c14b..2b188afd5 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -30,7 +30,6 @@ %li= link_to t('.seeds'), seeds_path %li= link_to t('.plantings'), plantings_path %li= link_to t('.harvests'), harvests_path - %li= link_to t('.garden_types'), garden_types_path %li.dropdown< %a.dropdown-toggle{ 'data-toggle': 'dropdown', href: members_path } = t('.community') From b51072fd003e28ae787d522c701b8f011cae051b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:05:13 +1300 Subject: [PATCH 037/124] Update test from containers to garden_types --- spec/routing/containers_routing_spec.rb | 33 ------------------- spec/routing/garden_types_routing_spec.rb | 33 +++++++++++++++++++ spec/views/containers/show.html.haml_spec.rb | 17 ---------- .../edit.html.haml_spec.rb | 8 ++--- .../new.html.haml_spec.rb | 8 ++--- .../views/garden_types/show.html.haml_spec.rb | 17 ++++++++++ 6 files changed, 58 insertions(+), 58 deletions(-) delete mode 100644 spec/routing/containers_routing_spec.rb create mode 100644 spec/routing/garden_types_routing_spec.rb delete mode 100644 spec/views/containers/show.html.haml_spec.rb rename spec/views/{containers => garden_types}/edit.html.haml_spec.rb (52%) rename spec/views/{containers => garden_types}/new.html.haml_spec.rb (53%) create mode 100644 spec/views/garden_types/show.html.haml_spec.rb diff --git a/spec/routing/containers_routing_spec.rb b/spec/routing/containers_routing_spec.rb deleted file mode 100644 index 3ef83d891..000000000 --- a/spec/routing/containers_routing_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require "rails_helper" - -describe ContainersController do - describe "routing" do - it "routes to #index" do - get("/containers").should route_to("containers#index") - end - - it "routes to #new" do - get("/containers/new").should route_to("containers#new") - end - - it "routes to #show" do - get("/containers/1").should route_to("containers#show", id: "1") - end - - it "routes to #edit" do - get("/containers/1/edit").should route_to("containers#edit", id: "1") - end - - it "routes to #create" do - post("/containers").should route_to("containers#create") - end - - it "routes to #update" do - put("/containers/1").should route_to("containers#update", id: "1") - end - - it "routes to #destroy" do - delete("/containers/1").should route_to("containers#destroy", id: "1") - end - end -end diff --git a/spec/routing/garden_types_routing_spec.rb b/spec/routing/garden_types_routing_spec.rb new file mode 100644 index 000000000..986af7b70 --- /dev/null +++ b/spec/routing/garden_types_routing_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +describe GardenTypesController do + describe "routing" do + it "routes to #index" do + get("/garden_types").should route_to("garden_types#index") + end + + it "routes to #new" do + get("/garden_types/new").should route_to("garden_types#new") + end + + it "routes to #show" do + get("/garden_types/1").should route_to("garden_types#show", id: "1") + end + + it "routes to #edit" do + get("/garden_types/1/edit").should route_to("garden_types#edit", id: "1") + end + + it "routes to #create" do + post("/garden_types").should route_to("garden_types#create") + end + + it "routes to #update" do + put("/garden_types/1").should route_to("garden_types#update", id: "1") + end + + it "routes to #destroy" do + delete("/garden_types/1").should route_to("garden_types#destroy", id: "1") + end + end +end diff --git a/spec/views/containers/show.html.haml_spec.rb b/spec/views/containers/show.html.haml_spec.rb deleted file mode 100644 index a18ffdd66..000000000 --- a/spec/views/containers/show.html.haml_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'rails_helper' - -describe "containers/show" do - subject { render } - - let!(:container) { FactoryBot.create(:container, description: "Hot Sauce") } - - before do - controller.stub(:current_user) { nil } - assign(:container, container) - render - end - - describe "renders a container with no gardens" do - it { is_expected.to have_content "There are no gardens to display." } - end -end diff --git a/spec/views/containers/edit.html.haml_spec.rb b/spec/views/garden_types/edit.html.haml_spec.rb similarity index 52% rename from spec/views/containers/edit.html.haml_spec.rb rename to spec/views/garden_types/edit.html.haml_spec.rb index f47a8492d..495f6ed99 100644 --- a/spec/views/containers/edit.html.haml_spec.rb +++ b/spec/views/garden_types/edit.html.haml_spec.rb @@ -1,17 +1,17 @@ require 'rails_helper' -describe "containers/edit" do +describe "garden_types/edit" do before(:each) do @owner = FactoryBot.create(:admin_member) sign_in @owner controller.stub(:current_user) { @owner } - @container = assign(:container, FactoryBot.create(:container)) + @garden_type = assign(:garden_type, FactoryBot.create(:garden_type)) render end - it "renders the edit container form" do + it "renders the edit garden_type form" do assert_select "form", action: garden_types_path, method: "post" do - assert_select "input#container_description", name: "container[description]" + assert_select "input#garden_type_description", name: "garden_type[description]" end end end diff --git a/spec/views/containers/new.html.haml_spec.rb b/spec/views/garden_types/new.html.haml_spec.rb similarity index 53% rename from spec/views/containers/new.html.haml_spec.rb rename to spec/views/garden_types/new.html.haml_spec.rb index 28fa68c84..757a0d166 100644 --- a/spec/views/containers/new.html.haml_spec.rb +++ b/spec/views/garden_types/new.html.haml_spec.rb @@ -1,17 +1,17 @@ require 'rails_helper' -describe "containers/new" do +describe "garden_types/new" do before(:each) do @owner = FactoryBot.create(:admin_member) sign_in @owner controller.stub(:current_user) { @owner } - @container = assign(:container, FactoryBot.create(:container)) + @garden_type = assign(:garden_type, FactoryBot.create(:garden_type)) render end - it "renders new container form" do + it "renders new garden_type form" do assert_select "form", action: garden_types_path, method: "post" do - assert_select "input#container_description", name: "container[description]" + assert_select "input#garden_type_description", name: "garden_type[description]" end end end diff --git a/spec/views/garden_types/show.html.haml_spec.rb b/spec/views/garden_types/show.html.haml_spec.rb new file mode 100644 index 000000000..f0ea804ae --- /dev/null +++ b/spec/views/garden_types/show.html.haml_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe "garden_types/show" do + subject { render } + + let!(:garden_type) { FactoryBot.create(:garden_type, description: "Hot Sauce") } + + before do + controller.stub(:current_user) { nil } + assign(:garden_type, garden_type) + render + end + + describe "renders a garden_type with no gardens" do + it { is_expected.to have_content "There are no gardens to display." } + end +end From 721a8694a0f5554aaf3adc5858d6b3d8432975d4 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:09:26 +1300 Subject: [PATCH 038/124] Removing plots --- app/models/garden.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/garden.rb b/app/models/garden.rb index b64b7375b..c25cc69b4 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -8,7 +8,6 @@ class Garden < ApplicationRecord has_many :plantings, dependent: :destroy has_many :crops, through: :plantings - has_many :plots, dependent: :destroy belongs_to :garden_type, required: false # set up geocoding From 629ffa198233da7c0fe30f9c10c8118cf2a9046e Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:10:40 +1300 Subject: [PATCH 039/124] Update translations --- config/locales/en.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 0c6bb119d..d1076dc0c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -202,8 +202,8 @@ en: browse_members: Browse Members community: Community community_map: Community Map - container: Container - containers: Containers + garden_type: Garden Type + garden_types: Garden Types crop_wrangling: Crop Wrangling crops: Crops current_memberlogin_name: "%{current_memberlogin_name}" @@ -311,7 +311,7 @@ en: planting: Please sign in or sign up to plant something. post: Please sign in or sign up to post. seed: Please sign in or sign up to add seeds. - container: Not authorized. Only admins can create containers. + garden_type: Not authorized. Only admins can create garden types. manage: all: Not authorized to %{action} %{subject}. read: From cc88f5c6c7050a76e31b84c0b7aaa2fba1196ac8 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:11:25 +1300 Subject: [PATCH 040/124] Update subtitler --- app/models/garden_type.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/garden_type.rb b/app/models/garden_type.rb index da84bf01e..bf093a6e7 100644 --- a/app/models/garden_type.rb +++ b/app/models/garden_type.rb @@ -11,9 +11,9 @@ class GardenType < ApplicationRecord name.gsub!(/[^A-Za-z ]/, '') end - def subtitler(container) - num = container.gardens.uniq.count + def subtitler(garden_type) + num = garden_type.gardens.uniq.count s = num > 1 || num.zero? ? "s are" : " is" - "#{num} garden#{s} using this container" + "#{num} garden#{s} using this garden type" end end From c71da41d435eb81a0276f866d8129badc7d4360d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:12:20 +1300 Subject: [PATCH 041/124] Update controller spec --- .../controllers/containers_controller_spec.rb | 90 ------------------- .../garden_types_controller_spec.rb | 90 +++++++++++++++++++ 2 files changed, 90 insertions(+), 90 deletions(-) delete mode 100644 spec/controllers/containers_controller_spec.rb create mode 100644 spec/controllers/garden_types_controller_spec.rb diff --git a/spec/controllers/containers_controller_spec.rb b/spec/controllers/containers_controller_spec.rb deleted file mode 100644 index 8fe2951cf..000000000 --- a/spec/controllers/containers_controller_spec.rb +++ /dev/null @@ -1,90 +0,0 @@ -require 'rails_helper' - -RSpec.describe ContainersController, type: :controller do - include Devise::Test::ControllerHelpers - let(:valid_params) { { description: 'My second Container' } } - let(:container) { FactoryBot.create :container } - - let(:member) { FactoryBot.create(:member) } - let(:admin_member) { FactoryBot.create(:admin) } - - context "when not signed in" do - describe 'GET new' do - before { get :new, id: container.to_param } - - it { expect(response).to redirect_to(root_path) } - end - - describe 'PUT create' do - before { put :create, container: valid_params } - - it { expect(response).to redirect_to(root_path) } - end - - describe 'changing existing records' do - before do - allow(Container).to receive(:find).and_return(:container) - expect(container).not_to receive(:save) - expect(container).not_to receive(:save!) - expect(container).not_to receive(:update) - expect(container).not_to receive(:update!) - expect(container).not_to receive(:destroy) - end - - describe 'GET edit' do - before { get :edit, id: container.to_param } - - it { expect(response).to redirect_to(root_path) } - end - - describe 'POST update' do - before { post :update, id: container.to_param, container: valid_params } - - it { expect(response).to redirect_to(root_path) } - end - - describe 'DELETE' do - before { delete :destroy, id: container.to_param, params: { container: valid_params } } - - it { expect(response).to redirect_to(root_path) } - end - end - end - - context "when signed in as a member" do - before(:each) { sign_in member } - - let!(:member) { FactoryBot.create(:member) } - - describe "for any container" do - let(:any_container) { double('container') } - - before do - expect(Container).to receive(:find).and_return(:any_container) - expect(any_container).not_to receive(:save) - expect(any_container).not_to receive(:save!) - expect(any_container).not_to receive(:update) - expect(any_container).not_to receive(:update!) - expect(any_container).not_to receive(:destroy) - end - - describe 'GET edit' do - before { get :edit, id: any_container.to_param } - - it { expect(response).to redirect_to(root_path) } - end - - describe 'POST update' do - before { post :update, id: any_container.to_param, container: valid_params } - - it { expect(response).to redirect_to(root_path) } - end - - describe 'DELETE' do - before { delete :destroy, id: any_container.to_param, params: { container: valid_params } } - - it { expect(response).to redirect_to(root_path) } - end - end - end -end diff --git a/spec/controllers/garden_types_controller_spec.rb b/spec/controllers/garden_types_controller_spec.rb new file mode 100644 index 000000000..59e148680 --- /dev/null +++ b/spec/controllers/garden_types_controller_spec.rb @@ -0,0 +1,90 @@ +require 'rails_helper' + +RSpec.describe GardenTypesController, type: :controller do + include Devise::Test::ControllerHelpers + let(:valid_params) { { description: 'My second GardenType' } } + let(:garden_type) { FactoryBot.create :garden_type } + + let(:member) { FactoryBot.create(:member) } + let(:admin_member) { FactoryBot.create(:admin) } + + context "when not signed in" do + describe 'GET new' do + before { get :new, id: garden_type.to_param } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'PUT create' do + before { put :create, garden_type: valid_params } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'changing existing records' do + before do + allow(GardenType).to receive(:find).and_return(:garden_type) + expect(garden_type).not_to receive(:save) + expect(garden_type).not_to receive(:save!) + expect(garden_type).not_to receive(:update) + expect(garden_type).not_to receive(:update!) + expect(garden_type).not_to receive(:destroy) + end + + describe 'GET edit' do + before { get :edit, id: garden_type.to_param } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'POST update' do + before { post :update, id: garden_type.to_param, garden_type: valid_params } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'DELETE' do + before { delete :destroy, id: garden_type.to_param, params: { garden_type: valid_params } } + + it { expect(response).to redirect_to(root_path) } + end + end + end + + context "when signed in as a member" do + before(:each) { sign_in member } + + let!(:member) { FactoryBot.create(:member) } + + describe "for any garden_type" do + let(:any_garden_type) { double('garden_type') } + + before do + expect(GardenType).to receive(:find).and_return(:any_garden_type) + expect(any_garden_type).not_to receive(:save) + expect(any_garden_type).not_to receive(:save!) + expect(any_garden_type).not_to receive(:update) + expect(any_garden_type).not_to receive(:update!) + expect(any_garden_type).not_to receive(:destroy) + end + + describe 'GET edit' do + before { get :edit, id: any_garden_type.to_param } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'POST update' do + before { post :update, id: any_garden_type.to_param, garden_type: valid_params } + + it { expect(response).to redirect_to(root_path) } + end + + describe 'DELETE' do + before { delete :destroy, id: any_garden_type.to_param, params: { garden_type: valid_params } } + + it { expect(response).to redirect_to(root_path) } + end + end + end +end From 63edfa36df935b627a08d0c6231a5e637d205e7f Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:13:12 +1300 Subject: [PATCH 042/124] Gardens have garden_Types in specs --- spec/models/garden_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 841eaa78d..1f2b9580c 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Garden do let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } - let(:container) { FactoryBot.create(:container, description: "aquaponic") } + let(:garden_type) { FactoryBot.create(:garden_type, description: "aquaponic") } it "has a slug" do garden.slug.should match(/hatupatu-springfield-community-garden/) @@ -106,8 +106,8 @@ describe Garden do it "destroys plots when deleted" do garden = FactoryBot.create(:garden, owner: owner) - @plot1 = FactoryBot.create(:plot, garden: garden, container: container) - @plot2 = FactoryBot.create(:plot, garden: garden, container: container) + @plot1 = FactoryBot.create(:plot, garden: garden, garden_type: garden_type) + @plot2 = FactoryBot.create(:plot, garden: garden, garden_type: garden_type) garden.plots.size.should eq(2) all = Plot.count garden.destroy From 1fe5f67aa14da3db25fa4136db196b42bace150f Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:14:31 +1300 Subject: [PATCH 043/124] Update garden_type model spec --- spec/models/garden_type.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/spec/models/garden_type.rb b/spec/models/garden_type.rb index d237e6055..e3d4f4ddf 100644 --- a/spec/models/garden_type.rb +++ b/spec/models/garden_type.rb @@ -3,35 +3,35 @@ require 'rails_helper' describe GardenType do let(:owner) { FactoryBot.create(:member) } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Free Carrots') } - let(:container) { FactoryBot.create(:container, name: "fake hole in the ground") } + let(:garden_type) { FactoryBot.create(:garden_type, name: "fake hole in the ground") } it "should have a name" do - container = FactoryBot.build(:container, name: "organic") - container.should be_valid + garden_type = FactoryBot.build(:garden_type, name: "organic") + garden_type.should be_valid end it "doesn't allow a nil name" do - container = FactoryBot.build(:container, name: nil) - container.should_not be_valid + garden_type = FactoryBot.build(:garden_type, name: nil) + garden_type.should_not be_valid end it "doesn't allow a blank name" do - container = FactoryBot.build(:container, name: "") - container.should_not be_valid + garden_type = FactoryBot.build(:garden_type, name: "") + garden_type.should_not be_valid end it "doesn't allow a name with only spaces" do - container = FactoryBot.build(:container, name: " ") - container.should_not be_valid + garden_type = FactoryBot.build(:garden_type, name: " ") + garden_type.should_not be_valid end it "destroys plots when deleted" do - container = FactoryBot.create(:container, name: "Massive Flower Pot") - @plot1 = FactoryBot.create(:plot, garden: garden, container: container) - @plot2 = FactoryBot.create(:plot, garden: garden, container: container) - container.plots.size.should eq(2) + garden_type = FactoryBot.create(:garden_type, name: "Massive Flower Pot") + @plot1 = FactoryBot.create(:plot, garden: garden, garden_type: garden_type) + @plot2 = FactoryBot.create(:plot, garden: garden, garden_type: garden_type) + garden_type.plots.size.should eq(2) all = Plot.count - container.destroy + garden_type.destroy Plot.count.should eq(all - 2) end end From 48022fb541219bc0dc5ecc4b7d4cad19f669f22d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:18:14 +1300 Subject: [PATCH 044/124] nullify gardens.garden_type when garden_type is destroyed --- app/models/garden_type.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/garden_type.rb b/app/models/garden_type.rb index bf093a6e7..c31bbf128 100644 --- a/app/models/garden_type.rb +++ b/app/models/garden_type.rb @@ -2,7 +2,7 @@ class GardenType < ApplicationRecord extend FriendlyId friendly_id :name, use: %i(slugged finders) - has_many :gardens + has_many :gardens, dependent: :nullify validates :name, presence: true, uniqueness: true validates :slug, presence: true, uniqueness: true From e5ee89c86577f10de7357febafd00573d7f91b09 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:43:34 +1300 Subject: [PATCH 045/124] garden_types.description becomes garden_type.name --- spec/controllers/garden_types_controller_spec.rb | 2 +- spec/models/garden_spec.rb | 6 +++--- spec/views/garden_types/edit.html.haml_spec.rb | 2 +- spec/views/garden_types/new.html.haml_spec.rb | 2 +- spec/views/garden_types/show.html.haml_spec.rb | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/controllers/garden_types_controller_spec.rb b/spec/controllers/garden_types_controller_spec.rb index 59e148680..31ae830b1 100644 --- a/spec/controllers/garden_types_controller_spec.rb +++ b/spec/controllers/garden_types_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' RSpec.describe GardenTypesController, type: :controller do include Devise::Test::ControllerHelpers - let(:valid_params) { { description: 'My second GardenType' } } + let(:valid_params) { { name: 'My second GardenType' } } let(:garden_type) { FactoryBot.create :garden_type } let(:member) { FactoryBot.create(:member) } diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 1f2b9580c..1ed9deabb 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -3,14 +3,14 @@ require 'rails_helper' describe Garden do let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } - let(:garden_type) { FactoryBot.create(:garden_type, description: "aquaponic") } + let(:garden_type) { FactoryBot.create(:garden_type, name: "aquaponic") } it "has a slug" do garden.slug.should match(/hatupatu-springfield-community-garden/) end - it "has a description" do - garden.description.should == "This is a **totally** cool garden" + it "has a name" do + garden.name.should == "This is a **totally** cool garden" end it "doesn't allow a nil name" do diff --git a/spec/views/garden_types/edit.html.haml_spec.rb b/spec/views/garden_types/edit.html.haml_spec.rb index 495f6ed99..3ee8f4a2d 100644 --- a/spec/views/garden_types/edit.html.haml_spec.rb +++ b/spec/views/garden_types/edit.html.haml_spec.rb @@ -11,7 +11,7 @@ describe "garden_types/edit" do it "renders the edit garden_type form" do assert_select "form", action: garden_types_path, method: "post" do - assert_select "input#garden_type_description", name: "garden_type[description]" + assert_select "input#garden_type_name", name: "garden_type[name]" end end end diff --git a/spec/views/garden_types/new.html.haml_spec.rb b/spec/views/garden_types/new.html.haml_spec.rb index 757a0d166..bf888a61e 100644 --- a/spec/views/garden_types/new.html.haml_spec.rb +++ b/spec/views/garden_types/new.html.haml_spec.rb @@ -11,7 +11,7 @@ describe "garden_types/new" do it "renders new garden_type form" do assert_select "form", action: garden_types_path, method: "post" do - assert_select "input#garden_type_description", name: "garden_type[description]" + assert_select "input#garden_type_name", name: "garden_type[name]" end end end diff --git a/spec/views/garden_types/show.html.haml_spec.rb b/spec/views/garden_types/show.html.haml_spec.rb index f0ea804ae..10b4d83a8 100644 --- a/spec/views/garden_types/show.html.haml_spec.rb +++ b/spec/views/garden_types/show.html.haml_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe "garden_types/show" do subject { render } - let!(:garden_type) { FactoryBot.create(:garden_type, description: "Hot Sauce") } + let!(:garden_type) { FactoryBot.create(:garden_type, name: "Hot Sauce") } before do controller.stub(:current_user) { nil } From 8a900b2e8778d022bede8bd5ed3b85b1a0c1d928 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 21:48:38 +1300 Subject: [PATCH 046/124] Update garden_Types controller spec for rails 5 --- spec/controllers/garden_types_controller_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/controllers/garden_types_controller_spec.rb b/spec/controllers/garden_types_controller_spec.rb index 31ae830b1..9afb4587f 100644 --- a/spec/controllers/garden_types_controller_spec.rb +++ b/spec/controllers/garden_types_controller_spec.rb @@ -10,7 +10,7 @@ RSpec.describe GardenTypesController, type: :controller do context "when not signed in" do describe 'GET new' do - before { get :new, id: garden_type.to_param } + before { get :new, params: { id: garden_type.to_param } } it { expect(response).to redirect_to(root_path) } end @@ -32,19 +32,19 @@ RSpec.describe GardenTypesController, type: :controller do end describe 'GET edit' do - before { get :edit, id: garden_type.to_param } + before { get :edit, params: { id: garden_type.to_param } } it { expect(response).to redirect_to(root_path) } end describe 'POST update' do - before { post :update, id: garden_type.to_param, garden_type: valid_params } + before { post :update, params: { id: garden_type.to_param, garden_type: valid_params } } it { expect(response).to redirect_to(root_path) } end describe 'DELETE' do - before { delete :destroy, id: garden_type.to_param, params: { garden_type: valid_params } } + before { delete :destroy, params: { id: garden_type.to_param, params: { garden_type: valid_params } } } it { expect(response).to redirect_to(root_path) } end @@ -69,19 +69,19 @@ RSpec.describe GardenTypesController, type: :controller do end describe 'GET edit' do - before { get :edit, id: any_garden_type.to_param } + before { get :edit, params: { id: any_garden_type.to_param } } it { expect(response).to redirect_to(root_path) } end describe 'POST update' do - before { post :update, id: any_garden_type.to_param, garden_type: valid_params } + before { post :update, params: { id: any_garden_type.to_param, garden_type: valid_params } } it { expect(response).to redirect_to(root_path) } end describe 'DELETE' do - before { delete :destroy, id: any_garden_type.to_param, params: { garden_type: valid_params } } + before { delete :destroy, params: { id: any_garden_type.to_param, params: { garden_type: valid_params } } } it { expect(response).to redirect_to(root_path) } end From 55f6636da54314e0a000dd661d2a664f6b1d506b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 22:06:41 +1300 Subject: [PATCH 047/124] change "required" to "optional" --- app/models/garden.rb | 2 +- app/models/planting.rb | 2 +- app/models/seed.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/garden.rb b/app/models/garden.rb index c25cc69b4..cd0834852 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -8,7 +8,7 @@ class Garden < ApplicationRecord has_many :plantings, dependent: :destroy has_many :crops, through: :plantings - belongs_to :garden_type, required: false + belongs_to :garden_type, optional: true # set up geocoding geocoded_by :location diff --git a/app/models/planting.rb b/app/models/planting.rb index 95908723b..08a78fdd8 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -23,7 +23,7 @@ class Planting < ApplicationRecord # Ancestry of food belongs_to :parent_seed, class_name: 'Seed', # parent foreign_key: 'parent_seed_id', - required: false, + optional: true, inverse_of: :child_plantings has_many :child_seeds, class_name: 'Seed', # children foreign_key: 'parent_planting_id', diff --git a/app/models/seed.rb b/app/models/seed.rb index 2075afba2..253718039 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -14,7 +14,7 @@ class Seed < ApplicationRecord # Relationships belongs_to :crop belongs_to :parent_planting, class_name: 'Planting', foreign_key: 'parent_planting_id', - required: false, inverse_of: :child_seeds # parent + optional: true, inverse_of: :child_seeds # parent has_many :child_plantings, class_name: 'Planting', foreign_key: 'parent_seed_id', dependent: :nullify, inverse_of: :parent_seed # children From 95d2aa221fecf2454c99fa4290298a084b5574bc Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 22:06:53 +1300 Subject: [PATCH 048/124] Removed plot spec --- spec/models/garden_spec.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 1ed9deabb..7d1f83d0b 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -104,16 +104,6 @@ describe Garden do expect(Planting.count).to eq(all - 2) end - it "destroys plots when deleted" do - garden = FactoryBot.create(:garden, owner: owner) - @plot1 = FactoryBot.create(:plot, garden: garden, garden_type: garden_type) - @plot2 = FactoryBot.create(:plot, garden: garden, garden_type: garden_type) - garden.plots.size.should eq(2) - all = Plot.count - garden.destroy - Plot.count.should eq(all - 2) - end - context 'area' do it 'allows numeric area' do garden = FactoryBot.build(:garden, area: 33) From 09dc928250a7c296419b892924d0c2d0eaf327a3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 22:07:07 +1300 Subject: [PATCH 049/124] Update model specs to not use `should` --- spec/models/garden_type.rb | 41 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/spec/models/garden_type.rb b/spec/models/garden_type.rb index e3d4f4ddf..8eb38fc4d 100644 --- a/spec/models/garden_type.rb +++ b/spec/models/garden_type.rb @@ -1,37 +1,32 @@ require 'rails_helper' describe GardenType do - let(:owner) { FactoryBot.create(:member) } - let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Free Carrots') } - let(:garden_type) { FactoryBot.create(:garden_type, name: "fake hole in the ground") } + let(:garden) { FactoryBot.create(:garden, 'Free Carrots') } - it "should have a name" do - garden_type = FactoryBot.build(:garden_type, name: "organic") - garden_type.should be_valid + describe "should have a name" do + let(:garden_type) { FactoryBot.build(:garden_type, name: "organic") } + it { expect(garden_type).to be_valid } end - it "doesn't allow a nil name" do - garden_type = FactoryBot.build(:garden_type, name: nil) - garden_type.should_not be_valid + describe "doesn't allow a nil name" do + let(:garden_type) { FactoryBot.build(:garden_type, name: nil) } + it { expect(garden_type).not_to be_valid } end - it "doesn't allow a blank name" do - garden_type = FactoryBot.build(:garden_type, name: "") - garden_type.should_not be_valid + describe "doesn't allow a blank name" do + let(:garden_type) { FactoryBot.build(:garden_type, name: "") } + it { expect(garden_type).not_to be_valid } end - it "doesn't allow a name with only spaces" do - garden_type = FactoryBot.build(:garden_type, name: " ") - garden_type.should_not be_valid + describe "doesn't allow a name with only spaces" do + let(:garden_type) { FactoryBot.build(:garden_type, name: " ") } + it { expect(garden_type).not_to be_valid } end - it "destroys plots when deleted" do - garden_type = FactoryBot.create(:garden_type, name: "Massive Flower Pot") - @plot1 = FactoryBot.create(:plot, garden: garden, garden_type: garden_type) - @plot2 = FactoryBot.create(:plot, garden: garden, garden_type: garden_type) - garden_type.plots.size.should eq(2) - all = Plot.count - garden_type.destroy - Plot.count.should eq(all - 2) + describe "does not delete gardens when deleted" do + before { FactoryBot.create :garden, garden_type: garden_type } + let(:garden_type) { FactoryBot.create(:garden_type, name: "Massive Flower Pot") } + it { expect(garden_type.gardens.size).to eq(1) } + it { expect { garden_type.destroy }.not_to change { Garden.count } } end end From e369b933848213c65394069a7f451f66aabebd5d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 22:07:35 +1300 Subject: [PATCH 050/124] Pass params to garden spec - for rails 5 --- spec/controllers/garden_types_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/garden_types_controller_spec.rb b/spec/controllers/garden_types_controller_spec.rb index 9afb4587f..9617de63d 100644 --- a/spec/controllers/garden_types_controller_spec.rb +++ b/spec/controllers/garden_types_controller_spec.rb @@ -16,7 +16,7 @@ RSpec.describe GardenTypesController, type: :controller do end describe 'PUT create' do - before { put :create, garden_type: valid_params } + before { put :create, params: { garden_type: valid_params } } it { expect(response).to redirect_to(root_path) } end From 5d32bc8010df60a43e75f6d9afaad8e2873036a3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 22:07:47 +1300 Subject: [PATCH 051/124] don't allow spaces in slug --- app/models/garden_type.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/garden_type.rb b/app/models/garden_type.rb index c31bbf128..b81789b69 100644 --- a/app/models/garden_type.rb +++ b/app/models/garden_type.rb @@ -8,7 +8,7 @@ class GardenType < ApplicationRecord validates :slug, presence: true, uniqueness: true def garden_type_slug - name.gsub!(/[^A-Za-z ]/, '') + name.gsub!(/[^A-Za-z]/, '') end def subtitler(garden_type) From 2d2304d8c05916eb2305d3aec0512c8ad6655d51 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 22:07:54 +1300 Subject: [PATCH 052/124] Rubocop lint --- app/helpers/application_helper.rb | 1 - db/migrate/20190326063855_create_garden_types.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d93850629..86a9ac2ef 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -27,7 +27,6 @@ module ApplicationHelper end def required_field_help_text - # rubocop:disable Rails/OutputSafety asterisk = content_tag :span, '*', class: ['red'] text = content_tag :em, 'denotes a required field' content_tag :div, asterisk + ' '.html_safe + text, class: ['margin-bottom'] diff --git a/db/migrate/20190326063855_create_garden_types.rb b/db/migrate/20190326063855_create_garden_types.rb index 7e3af2322..0d7ca230e 100644 --- a/db/migrate/20190326063855_create_garden_types.rb +++ b/db/migrate/20190326063855_create_garden_types.rb @@ -8,8 +8,8 @@ class CreateGardenTypes < ActiveRecord::Migration[5.2] add_column :gardens, :garden_type_id, :integer add_index :gardens, :garden_type_id ['organic', 'conventional', 'container', 'vertical', 'greenhouse', 'rooftop', 'no-dig', 'raised bed', - 'wicking bed', 'permaculture', 'hydroponic', 'aquaponic', 'orchard', 'food forest', - 'biodynamic'].each do |name| + 'wicking bed', 'permaculture', 'hydroponic', 'aquaponic', 'orchard', 'food forest', + 'biodynamic'].each do |name| say "Creating #{name}" GardenType.create! name: name end From 1e240cf4b859e5533111cad471d9d526fb3ac299 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 22:12:09 +1300 Subject: [PATCH 053/124] replace a rubocop ignore --- app/helpers/application_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 86a9ac2ef..70503cfb9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -29,6 +29,7 @@ module ApplicationHelper def required_field_help_text asterisk = content_tag :span, '*', class: ['red'] text = content_tag :em, 'denotes a required field' + # rubocop:disable Rails/OutputSafety content_tag :div, asterisk + ' '.html_safe + text, class: ['margin-bottom'] # rubocop:enable Rails/OutputSafety end From 8d579a4616b56f32073bb89aa668045f2a0e0ea7 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 26 Mar 2019 22:27:10 +1300 Subject: [PATCH 054/124] Gardens have descriptions --- spec/models/garden_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index 7d1f83d0b..f4aa7d51f 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -9,8 +9,8 @@ describe Garden do garden.slug.should match(/hatupatu-springfield-community-garden/) end - it "has a name" do - garden.name.should == "This is a **totally** cool garden" + it "has a description" do + garden.description.should == "This is a **totally** cool garden" end it "doesn't allow a nil name" do From 922278280837b00b83e31597b6e7f26be2227b05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 26 Mar 2019 09:39:24 +0000 Subject: [PATCH 055/124] Bump jsonapi-resources from 0.9.5 to 0.9.6 Bumps [jsonapi-resources](https://github.com/cerebris/jsonapi-resources) from 0.9.5 to 0.9.6. - [Release notes](https://github.com/cerebris/jsonapi-resources/releases) - [Commits](https://github.com/cerebris/jsonapi-resources/compare/v0.9.5...v0.9.6) Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3043c46d2..aeef895f0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -244,7 +244,7 @@ GEM railties (>= 3.2) sprockets-rails json (2.1.0) - jsonapi-resources (0.9.5) + jsonapi-resources (0.9.6) activerecord (>= 4.1) concurrent-ruby railties (>= 4.1) @@ -296,7 +296,7 @@ GEM multipart-post (2.0.0) newrelic_rpm (6.2.0.354) nio4r (2.3.1) - nokogiri (1.10.1) + nokogiri (1.10.2) mini_portile2 (~> 2.4.0) oauth (0.5.4) oauth2 (1.4.1) From 2126863632f0712976ef69d4f2c509307b917a69 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Wed, 27 Mar 2019 07:46:45 +0000 Subject: [PATCH 056/124] Bump devise from 4.6.1 to 4.6.2 Bumps [devise](https://github.com/plataformatec/devise) from 4.6.1 to 4.6.2. - [Release notes](https://github.com/plataformatec/devise/releases) - [Changelog](https://github.com/plataformatec/devise/blob/master/CHANGELOG.md) - [Commits](https://github.com/plataformatec/devise/compare/v4.6.1...v4.6.2) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index aeef895f0..eb6602ffc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -134,7 +134,7 @@ GEM activesupport (>= 3.0.0) dalli (2.7.10) database_cleaner (1.7.0) - devise (4.6.1) + devise (4.6.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0, < 6.0) From 30b5c0ce9dbacb50ef88eac32751334a449f33aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Fri, 29 Mar 2019 07:27:41 +0000 Subject: [PATCH 057/124] Bump capybara from 3.15.0 to 3.16.0 Bumps [capybara](https://github.com/teamcapybara/capybara) from 3.15.0 to 3.16.0. - [Release notes](https://github.com/teamcapybara/capybara/releases) - [Changelog](https://github.com/teamcapybara/capybara/blob/master/History.md) - [Commits](https://github.com/teamcapybara/capybara/compare/3.15.0...3.16.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index eb6602ffc..6c138a2fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,7 +80,7 @@ GEM uniform_notifier (~> 1.11) byebug (11.0.1) cancancan (2.3.0) - capybara (3.15.0) + capybara (3.16.0) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) From f48e131e147fae753811db995d9063d3106b0090 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sat, 30 Mar 2019 05:06:59 +0000 Subject: [PATCH 058/124] Auto corrected by following Lint Ruby RSpecEmptyLine --- spec/models/garden_type.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/models/garden_type.rb b/spec/models/garden_type.rb index 8eb38fc4d..149ff02ab 100644 --- a/spec/models/garden_type.rb +++ b/spec/models/garden_type.rb @@ -5,27 +5,33 @@ describe GardenType do describe "should have a name" do let(:garden_type) { FactoryBot.build(:garden_type, name: "organic") } + it { expect(garden_type).to be_valid } end describe "doesn't allow a nil name" do let(:garden_type) { FactoryBot.build(:garden_type, name: nil) } + it { expect(garden_type).not_to be_valid } end describe "doesn't allow a blank name" do let(:garden_type) { FactoryBot.build(:garden_type, name: "") } + it { expect(garden_type).not_to be_valid } end describe "doesn't allow a name with only spaces" do let(:garden_type) { FactoryBot.build(:garden_type, name: " ") } + it { expect(garden_type).not_to be_valid } end describe "does not delete gardens when deleted" do before { FactoryBot.create :garden, garden_type: garden_type } + let(:garden_type) { FactoryBot.create(:garden_type, name: "Massive Flower Pot") } + it { expect(garden_type.gardens.size).to eq(1) } it { expect { garden_type.destroy }.not_to change { Garden.count } } end From 837ae8cb8e7603d23f8e72f8396b4ca4facd69f4 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sat, 30 Mar 2019 05:08:00 +0000 Subject: [PATCH 059/124] Auto corrected by following Lint Ruby RSpec/AlignLeftLetBrace --- spec/controllers/garden_types_controller_spec.rb | 2 +- spec/models/garden_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/controllers/garden_types_controller_spec.rb b/spec/controllers/garden_types_controller_spec.rb index 9617de63d..1baf03b87 100644 --- a/spec/controllers/garden_types_controller_spec.rb +++ b/spec/controllers/garden_types_controller_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe GardenTypesController, type: :controller do include Devise::Test::ControllerHelpers let(:valid_params) { { name: 'My second GardenType' } } - let(:garden_type) { FactoryBot.create :garden_type } + let(:garden_type) { FactoryBot.create :garden_type } let(:member) { FactoryBot.create(:member) } let(:admin_member) { FactoryBot.create(:admin) } diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index f4aa7d51f..e27efce89 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' describe Garden do - let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } - let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } + let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } + let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } let(:garden_type) { FactoryBot.create(:garden_type, name: "aquaponic") } it "has a slug" do From fb243c1f8dc79ba61abd7510a4ae8f4d1042554f Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sat, 30 Mar 2019 05:10:13 +0000 Subject: [PATCH 060/124] Auto corrected by following Lint Ruby RSpec/ExpectChange --- spec/models/garden_type.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/garden_type.rb b/spec/models/garden_type.rb index 149ff02ab..cd5862c98 100644 --- a/spec/models/garden_type.rb +++ b/spec/models/garden_type.rb @@ -33,6 +33,6 @@ describe GardenType do let(:garden_type) { FactoryBot.create(:garden_type, name: "Massive Flower Pot") } it { expect(garden_type.gardens.size).to eq(1) } - it { expect { garden_type.destroy }.not_to change { Garden.count } } + it { expect { garden_type.destroy }.not_to change(Garden, :count) } end end From 4dcb4205345aac5b09baa1be1e9240f6b53942a8 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sat, 30 Mar 2019 20:26:34 +0000 Subject: [PATCH 061/124] Auto corrected by following Lint Ruby RSpec/HookArgument --- spec/controllers/garden_types_controller_spec.rb | 2 +- spec/views/garden_types/edit.html.haml_spec.rb | 2 +- spec/views/garden_types/new.html.haml_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/controllers/garden_types_controller_spec.rb b/spec/controllers/garden_types_controller_spec.rb index 1baf03b87..0777184b3 100644 --- a/spec/controllers/garden_types_controller_spec.rb +++ b/spec/controllers/garden_types_controller_spec.rb @@ -52,7 +52,7 @@ RSpec.describe GardenTypesController, type: :controller do end context "when signed in as a member" do - before(:each) { sign_in member } + before { sign_in member } let!(:member) { FactoryBot.create(:member) } diff --git a/spec/views/garden_types/edit.html.haml_spec.rb b/spec/views/garden_types/edit.html.haml_spec.rb index 3ee8f4a2d..b5c69b95f 100644 --- a/spec/views/garden_types/edit.html.haml_spec.rb +++ b/spec/views/garden_types/edit.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "garden_types/edit" do - before(:each) do + before do @owner = FactoryBot.create(:admin_member) sign_in @owner controller.stub(:current_user) { @owner } diff --git a/spec/views/garden_types/new.html.haml_spec.rb b/spec/views/garden_types/new.html.haml_spec.rb index bf888a61e..3241666af 100644 --- a/spec/views/garden_types/new.html.haml_spec.rb +++ b/spec/views/garden_types/new.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe "garden_types/new" do - before(:each) do + before do @owner = FactoryBot.create(:admin_member) sign_in @owner controller.stub(:current_user) { @owner } From 6e10dc2a2b743dfc3c1b22601758fc9855cb3ac3 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sat, 30 Mar 2019 20:26:15 +0000 Subject: [PATCH 062/124] Auto corrected by following Lint Ruby RSpec/AlignRightLetBrace --- spec/controllers/garden_types_controller_spec.rb | 2 +- spec/models/garden_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/controllers/garden_types_controller_spec.rb b/spec/controllers/garden_types_controller_spec.rb index 0777184b3..73e59d176 100644 --- a/spec/controllers/garden_types_controller_spec.rb +++ b/spec/controllers/garden_types_controller_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' RSpec.describe GardenTypesController, type: :controller do include Devise::Test::ControllerHelpers let(:valid_params) { { name: 'My second GardenType' } } - let(:garden_type) { FactoryBot.create :garden_type } + let(:garden_type) { FactoryBot.create :garden_type } let(:member) { FactoryBot.create(:member) } let(:admin_member) { FactoryBot.create(:admin) } diff --git a/spec/models/garden_spec.rb b/spec/models/garden_spec.rb index e27efce89..c709794a3 100644 --- a/spec/models/garden_spec.rb +++ b/spec/models/garden_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Garden do let(:owner) { FactoryBot.create(:member, login_name: 'hatupatu') } let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Springfield Community Garden') } - let(:garden_type) { FactoryBot.create(:garden_type, name: "aquaponic") } + let(:garden_type) { FactoryBot.create(:garden_type, name: "aquaponic") } it "has a slug" do garden.slug.should match(/hatupatu-springfield-community-garden/) From 71ab33d20cc2bb150e01d2baed80c8d009ba09e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 1 Apr 2019 07:55:43 +0000 Subject: [PATCH 063/124] Bump i18n-tasks from 0.9.28 to 0.9.29 Bumps [i18n-tasks](https://github.com/glebm/i18n-tasks) from 0.9.28 to 0.9.29. - [Release notes](https://github.com/glebm/i18n-tasks/releases) - [Changelog](https://github.com/glebm/i18n-tasks/blob/master/CHANGES.md) - [Commits](https://github.com/glebm/i18n-tasks/compare/v0.9.28...v0.9.29) Signed-off-by: dependabot[bot] --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6c138a2fe..4ca106605 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -212,7 +212,7 @@ GEM excon moneta multi_json (>= 1.9.2) - highline (2.0.0) + highline (2.0.1) html2haml (2.2.0) erubis (~> 2.7.0) haml (>= 4.0, < 6) @@ -223,7 +223,7 @@ GEM multi_xml (>= 0.5.2) i18n (1.6.0) concurrent-ruby (~> 1.0) - i18n-tasks (0.9.28) + i18n-tasks (0.9.29) activesupport (>= 4.0.2) ast (>= 2.1.0) erubi @@ -326,7 +326,7 @@ GEM parallel (1.14.0) paranoia (2.4.1) activerecord (>= 4.0, < 5.3) - parser (2.6.0.0) + parser (2.6.2.0) ast (~> 2.4.0) pg (0.21.0) platform-api (2.2.0) From 4ba5319ba89f137137ec0375df9e8adb91aa42d4 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sat, 30 Mar 2019 20:25:15 +0000 Subject: [PATCH 064/124] Auto corrected by following Lint Ruby Capybara/FeatureMethods --- spec/features/admin/forums_spec.rb | 14 +++--- spec/features/cms_spec.rb | 8 +-- .../comments/commenting_a_comment_spec.rb | 10 ++-- spec/features/crops/alternate_name_spec.rb | 18 +++---- spec/features/crops/browse_crops_spec.rb | 10 ++-- spec/features/crops/creating_a_crop_spec.rb | 6 +-- spec/features/crops/crop_detail_page_spec.rb | 42 ++++++++-------- spec/features/crops/crop_photos_spec.rb | 6 +-- spec/features/crops/crop_search_spec.rb | 8 +-- spec/features/crops/crop_wranglers_spec.rb | 20 ++++---- .../crops/crop_wrangling_button_spec.rb | 10 ++-- spec/features/crops/delete_crop_spec.rb | 8 +-- spec/features/crops/inflections_spec.rb | 14 +++--- spec/features/crops/request_new_crop_spec.rb | 12 ++--- spec/features/crops/requested_crops_spec.rb | 6 +-- spec/features/crops/show_spec.rb | 8 +-- spec/features/following_spec.rb | 24 ++++----- spec/features/footer_spec.rb | 4 +- spec/features/gardens/actions_spec.rb | 4 +- spec/features/gardens/adding_gardens_spec.rb | 8 +-- spec/features/gardens/gardens_index_spec.rb | 4 +- spec/features/gardens_spec.rb | 24 ++++----- .../features/harvests/browse_harvests_spec.rb | 12 ++--- .../harvests/harvesting_a_crop_spec.rb | 26 +++++----- spec/features/home/home_spec.rb | 6 +-- spec/features/likeable_spec.rb | 8 +-- spec/features/locale_spec.rb | 4 +- spec/features/member_profile_spec.rb | 50 +++++++++---------- spec/features/members/deletion_spec.rb | 34 ++++++------- spec/features/members_list_spec.rb | 6 +-- spec/features/notifications_spec.rb | 6 +-- spec/features/photos/new_photo_spec.rb | 12 ++--- spec/features/photos/show_photo_spec.rb | 4 +- .../features/places/searching_a_place_spec.rb | 6 +-- spec/features/planting_reminder_spec.rb | 16 +++--- .../plantings/planting_a_crop_spec.rb | 16 +++--- spec/features/posts/posting_a_post_spec.rb | 10 ++-- spec/features/rss/comments_spec.rb | 6 +-- spec/features/rss/crops_spec.rb | 6 +-- spec/features/rss/members_spec.rb | 6 +-- spec/features/rss/plantings_spec.rb | 6 +-- spec/features/rss/posts_spec.rb | 6 +-- spec/features/rss/seeds_spec.rb | 6 +-- spec/features/scientific_name_spec.rb | 18 +++---- spec/features/seeds/adding_seeds_spec.rb | 4 +- spec/features/seeds/misc_seeds_spec.rb | 6 +-- spec/features/seeds/seed_photos.rb | 2 +- spec/features/signin_spec.rb | 18 +++---- spec/features/signout_spec.rb | 8 +-- spec/features/signup_spec.rb | 10 ++-- spec/features/unsubscribing_spec.rb | 10 ++-- spec/requests/api/v1/gardens_request_spec.rb | 4 +- .../requests/api/v1/plantings_request_spec.rb | 4 +- 53 files changed, 302 insertions(+), 302 deletions(-) diff --git a/spec/features/admin/forums_spec.rb b/spec/features/admin/forums_spec.rb index 8cfce4915..75acbbbd3 100644 --- a/spec/features/admin/forums_spec.rb +++ b/spec/features/admin/forums_spec.rb @@ -1,15 +1,15 @@ require 'rails_helper' -feature "forums", js: true do +describe "forums", js: true do context "as an admin user" do let(:member) { create :admin_member } let(:forum) { create :forum } - background do + before do login_as member end - scenario "navigating to forum admin without js", js: false do + it "navigating to forum admin without js", js: false do visit root_path click_link "Admin" expect(current_path).to eq admin_path @@ -20,7 +20,7 @@ feature "forums", js: true do expect(page).to have_content "New forum" end - scenario "navigating to forum admin with js" do + it "navigating to forum admin with js" do visit root_path click_link member.login_name click_link "Admin" @@ -32,7 +32,7 @@ feature "forums", js: true do expect(page).to have_content "New forum" end - scenario "adding a forum" do + it "adding a forum" do visit forums_path click_link "New forum" expect(current_path).to eq new_forum_path @@ -43,7 +43,7 @@ feature "forums", js: true do expect(page).to have_content 'Forum was successfully created' end - scenario 'editing forum' do + it 'editing forum' do visit forum_path forum click_link 'Edit' fill_in 'Name', with: 'Something else' @@ -54,7 +54,7 @@ feature "forums", js: true do expect(page).to have_content 'Something else' end - scenario 'deleting forum' do + it 'deleting forum' do visit forum_path forum click_link 'Delete' expect(current_path).to eq forums_path diff --git a/spec/features/cms_spec.rb b/spec/features/cms_spec.rb index 405f77f18..4abe7d6d4 100644 --- a/spec/features/cms_spec.rb +++ b/spec/features/cms_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' -feature "cms admin" do +describe "cms admin" do let(:member) { create :member } let(:admin_member) { create :admin_member } - scenario "can't view CMS admin if not signed in" do + it "can't view CMS admin if not signed in" do visit comfy_admin_cms_path expect(current_path).to eq root_path expect(page).to have_content "Please sign in as an admin user" end - scenario "can't view CMS admin if not an admin member" do + it "can't view CMS admin if not an admin member" do # sign in as an ordinary member login_as member visit comfy_admin_cms_path @@ -18,7 +18,7 @@ feature "cms admin" do expect(page).to have_content "Please sign in as an admin user" end - scenario "admin members can view CMS admin area" do + it "admin members can view CMS admin area" do login_as admin_member visit comfy_admin_cms_path expect(current_path).to match(/#{comfy_admin_cms_path}/) # match any CMS admin page diff --git a/spec/features/comments/commenting_a_comment_spec.rb b/spec/features/comments/commenting_a_comment_spec.rb index 6c195e518..2ab3fa615 100644 --- a/spec/features/comments/commenting_a_comment_spec.rb +++ b/spec/features/comments/commenting_a_comment_spec.rb @@ -1,15 +1,15 @@ require 'rails_helper' -feature 'Commenting on a post' do +describe 'Commenting on a post' do let(:member) { create :member } let(:post) { create :post, author: member } - background do + before do login_as member visit new_comment_path post_id: post.id end - scenario "creating a comment" do + it "creating a comment" do fill_in "comment_body", with: "This is a sample test for comment" click_button "Post comment" expect(page).to have_content "comment was successfully created." @@ -19,11 +19,11 @@ feature 'Commenting on a post' do context "editing a comment" do let(:existing_comment) { create :comment, post: post, author: member } - background do + before do visit edit_comment_path existing_comment end - scenario "saving edit" do + it "saving edit" do fill_in "comment_body", with: "Testing edit for comment" click_button "Post comment" expect(page).to have_content "comment was successfully updated." diff --git a/spec/features/crops/alternate_name_spec.rb b/spec/features/crops/alternate_name_spec.rb index 716a26bc2..522ee8e30 100644 --- a/spec/features/crops/alternate_name_spec.rb +++ b/spec/features/crops/alternate_name_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' -feature "Alternate names", js: true do +describe "Alternate names", js: true do let!(:alternate_eggplant) { create :alternate_eggplant } let(:crop) { alternate_eggplant.crop } - scenario "Display alternate names on crop page" do + it "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 - scenario "Index page for alternate names" do + it "Index page for alternate names" do visit alternate_names_path expect(page).to have_content alternate_eggplant.name end @@ -19,11 +19,11 @@ feature "Alternate names", js: true do let!(:crop_wranglers) { create_list :crop_wrangling_member, 3 } let(:member) { crop_wranglers.first } - background do + before do login_as member end - scenario "Crop wranglers can edit alternate names" do + it "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" @@ -39,7 +39,7 @@ feature "Alternate names", js: true do expect(page).to have_content 'Alternate name was successfully updated' end - scenario "Crop wranglers can delete alternate names" do + it "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) @@ -49,7 +49,7 @@ feature "Alternate names", js: true do expect(page).to have_content 'Alternate name was successfully deleted' end - scenario "Crop wranglers can add alternate names" do + it "Crop wranglers can add alternate names" do visit crop_path(crop) expect(page).to have_link "Add", href: new_alternate_name_path(crop_id: crop.id) @@ -63,7 +63,7 @@ feature "Alternate names", js: true do expect(page).to have_content 'Alternate name was successfully created' end - scenario "The show-alternate-name page works" do + it "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 @@ -73,7 +73,7 @@ feature "Alternate names", js: true do let(:rejected_crop) { create :rejected_crop } let(:pending_alt_name) { create :alternate_name, crop: rejected_crop } - scenario "Displays crop rejection message" do + it "Displays crop rejection message" do visit alternate_name_path(pending_alt_name) expect(page).to have_content "This crop was rejected for the following reason: Totally fake" end diff --git a/spec/features/crops/browse_crops_spec.rb b/spec/features/crops/browse_crops_spec.rb index c9a6335ec..9a4c23ac3 100644 --- a/spec/features/crops/browse_crops_spec.rb +++ b/spec/features/crops/browse_crops_spec.rb @@ -1,28 +1,28 @@ require 'rails_helper' -feature "browse crops" do +describe "browse crops" do let(:tomato) { create :tomato } let(:maize) { create :maize } let(:pending_crop) { create :crop_request } let(:rejected_crop) { create :rejected_crop } - scenario "has a form for sorting by" do + it "has a form for sorting by" do visit crops_path expect(page).to have_css "select#sort" end - scenario "shows a list of crops" do + it "shows a list of crops" do crop1 = tomato visit crops_path expect(page).to have_content crop1.name end - scenario "pending crops are not listed" do + it "pending crops are not listed" do visit crops_path expect(page).not_to have_content pending_crop.name end - scenario "rejected crops are not listed" do + it "rejected crops are not listed" do visit crops_path expect(page).not_to have_content rejected_crop.name end diff --git a/spec/features/crops/creating_a_crop_spec.rb b/spec/features/crops/creating_a_crop_spec.rb index 64eff3628..14dd983d2 100644 --- a/spec/features/crops/creating_a_crop_spec.rb +++ b/spec/features/crops/creating_a_crop_spec.rb @@ -1,15 +1,15 @@ require 'rails_helper' -feature "Crop - " do +describe "Crop - " do let!(:crop_wrangler) { FactoryBot.create :crop_wrangling_member } let!(:member) { FactoryBot.create :member } - background do + before do login_as member visit new_crop_path end - scenario "creating a crop with multiple scientific and alternate name", :js do + it "creating a crop with multiple scientific and alternate name", :js do within "form#new_crop" do fill_in "crop_name", with: "Philippine flower" fill_in "en_wikipedia_url", with: "https://en.wikipedia.org/wiki/Jasminum_sambac" diff --git a/spec/features/crops/crop_detail_page_spec.rb b/spec/features/crops/crop_detail_page_spec.rb index 6386c7044..fb0297854 100644 --- a/spec/features/crops/crop_detail_page_spec.rb +++ b/spec/features/crops/crop_detail_page_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "crop detail page", js: true do +describe "crop detail page", js: true do subject do # Update the medians after all the # data has been loaded @@ -14,7 +14,7 @@ feature "crop detail page", js: true do let(:crop) { create :crop } context "varieties" do - scenario "The crop DOES NOT have varieties" do + it "The crop DOES NOT have varieties" do visit crop_path(crop) within ".varieties" do @@ -23,7 +23,7 @@ feature "crop detail page", js: true do end end - scenario "The crop has one variety" do + it "The crop has one variety" do create :crop, name: 'Roma tomato 1', parent: crop subject @@ -42,7 +42,7 @@ feature "crop detail page", js: true do let!(:roma3) { create :crop, name: 'Roma tomato 3', parent: crop } let!(:roma4) { create :crop, name: 'Roma tomato 4', parent: crop } - scenario "The crop has 4 varieties" do + it "The crop has 4 varieties" do subject within ".varieties" do @@ -53,7 +53,7 @@ feature "crop detail page", js: true do end end - scenario "The crop has 5 varieties, including grandchild", js: true do + it "The crop has 5 varieties, including grandchild", js: true do create :crop, name: 'Roma tomato child 1', parent: roma4 subject @@ -97,54 +97,54 @@ feature "crop detail page", js: true do context "signed in member" do let(:member) { create :member } - background do + before do login_as(member) end context "action buttons" do - background { subject } + before { subject } - scenario "has a link to plant the crop" do + it "has a link to plant the crop" do expect(page).to have_link "Plant #{crop.name}", href: new_planting_path(crop_id: crop.id) end - scenario "has a link to harvest the crop" do + it "has a link to harvest the crop" do expect(page).to have_link "Harvest #{crop.name}", href: new_harvest_path(crop_id: crop.id) end - scenario "has a link to add seeds" do + it "has a link to add seeds" do expect(page).to have_link "Add #{crop.name} seeds to stash", href: new_seed_path(crop_id: crop.id) end end context "SEO" do - background { subject } + before { subject } - scenario "has seed heading with SEO" do + it "has seed heading with SEO" do expect(page).to have_content "Find #{crop.name} seeds" end - scenario "has harvest heading with SEO" do + it "has harvest heading with SEO" do expect(page).to have_content "#{crop.name.capitalize} harvests" end - scenario "has planting heading with SEO" do + it "has planting heading with SEO" do expect(page).to have_content "See who's planted #{crop.name.pluralize}" end - scenario "has planting advice with SEO" do + it "has planting advice with SEO" do expect(page).to have_content "How to grow #{crop.name}" end - scenario "has a link to Wikipedia with SEO" do + it "has a link to Wikipedia with SEO" do expect(page).to have_content "Learn more about #{crop.name}" expect(page).to have_link "Wikipedia (English)", href: crop.en_wikipedia_url end - scenario "has a link to OpenFarm" do + it "has a link to OpenFarm" do expect(page).to have_link "OpenFarm - Growing guide", href: "https://openfarm.cc/en/crops/#{CGI.escape crop.name}" end - scenario "has a link to gardenate" do + it "has a link to gardenate" do expect(page).to have_link "Gardenate - Planting reminders", href: "http://www.gardenate.com/plant/#{CGI.escape crop.name}" end @@ -155,18 +155,18 @@ feature "crop detail page", js: true do let(:member) { create :member } let(:seed) { create :seed, crop: crop, quantity: 20, owner: member } - scenario "User not signed in" do + it "User not signed in" do visit crop_path(seed.crop) expect(page).not_to have_content "You have 20 seeds" end - scenario "User signed in" do + it "User signed in" do login_as(member) visit crop_path(seed.crop) expect(page).to have_link "You have 20 seeds of this crop." end - scenario "click link to your owned seeds" do + it "click link to your owned seeds" do login_as(member) visit crop_path(seed.crop) click_link "You have 20 seeds of this crop." diff --git a/spec/features/crops/crop_photos_spec.rb b/spec/features/crops/crop_photos_spec.rb index 0d7d1fbee..a7bfed6b3 100644 --- a/spec/features/crops/crop_photos_spec.rb +++ b/spec/features/crops/crop_photos_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "crop detail page", js: true do +describe "crop detail page", js: true do subject { page } let!(:member) { FactoryBot.create :member } @@ -50,12 +50,12 @@ feature "crop detail page", js: true do end context "when signed in" do - background { login_as(FactoryBot.create(:member)) } + before { login_as(FactoryBot.create(:member)) } include_examples "shows photos" end context "when signed in as photos owner" do - background { login_as(member) } + before { login_as(member) } include_examples "shows photos" end diff --git a/spec/features/crops/crop_search_spec.rb b/spec/features/crops/crop_search_spec.rb index 0cea2e168..b87655a01 100644 --- a/spec/features/crops/crop_search_spec.rb +++ b/spec/features/crops/crop_search_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -feature "crop search" do - scenario "search results show the search term in title" do +describe "crop search" do + it "search results show the search term in title" do visit root_path within "form#navbar-search" do fill_in "term", with: "tomato" @@ -10,12 +10,12 @@ feature "crop search" do expect(page).to have_css "h1", text: "Crops matching \"tomato\"" end - scenario "search page with no search term shows suitable title" do + it "search page with no search term shows suitable title" do visit search_crops_path expect(page).to have_css "h1", text: "Crop search" end - scenario "search page has a search form on it" do + it "search page has a search form on it" do visit search_crops_path expect(page).to have_css "form#crop-search" end diff --git a/spec/features/crops/crop_wranglers_spec.rb b/spec/features/crops/crop_wranglers_spec.rb index f9db489b2..c623d16b6 100644 --- a/spec/features/crops/crop_wranglers_spec.rb +++ b/spec/features/crops/crop_wranglers_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "crop wranglers", js: true do +describe "crop wranglers", js: true do context "signed in wrangler" do let!(:crop_wranglers) { create_list :crop_wrangling_member, 3 } let(:wrangler) { crop_wranglers.first } @@ -8,9 +8,9 @@ feature "crop wranglers", js: true do let!(:requested_crop) { create :crop_request } let!(:rejected_crop) { create :rejected_crop } - background { login_as wrangler } + before { login_as wrangler } - scenario "sees crop wranglers listed on the crop wrangler page" do + it "sees crop wranglers listed on the crop wrangler page" do visit root_path click_link wrangler.login_name click_link 'Crop Wrangling' @@ -23,7 +23,7 @@ feature "crop wranglers", js: true do end end - scenario "can see list of crops with extra detail of who created a crop" do + it "can see list of crops with extra detail of who created a crop" do visit root_path click_link wrangler.login_name click_link 'Crop Wrangling' @@ -40,7 +40,7 @@ feature "crop wranglers", js: true do it { expect(page).to have_link 'Delete' } end - scenario "can create a new crop" do + it "can create a new crop" do visit root_path click_link wrangler.login_name click_link 'Crop Wrangling' @@ -53,13 +53,13 @@ feature "crop wranglers", js: true do expect(page).to have_content 'planticus maximus' end - scenario "View pending crops" do + it "View pending crops" do visit crop_path(requested_crop) expect(page).to have_content "This crop is currently pending approval." expect(page).to have_content "Please approve this even though it's fake." end - scenario "View rejected crops" do + it "View rejected crops" do visit crop_path(rejected_crop) expect(page).to have_content "This crop was rejected for the following reason: Totally fake" end @@ -69,14 +69,14 @@ feature "crop wranglers", js: true do let!(:crop_wranglers) { create_list :crop_wrangling_member, 3 } let(:member) { create :member } - background { login_as member } + before { login_as member } - scenario "can't see wrangling page without js", js: false do + it "can't see wrangling page without js", js: false do visit root_path expect(page).not_to have_link "Crop Wrangling" end - scenario "can't see wrangling page with js" do + it "can't see wrangling page with js" do visit root_path click_link member.login_name expect(page).not_to have_link "Crop Wrangling" diff --git a/spec/features/crops/crop_wrangling_button_spec.rb b/spec/features/crops/crop_wrangling_button_spec.rb index bf285ba66..7e9c3d8d1 100644 --- a/spec/features/crops/crop_wrangling_button_spec.rb +++ b/spec/features/crops/crop_wrangling_button_spec.rb @@ -1,27 +1,27 @@ require 'rails_helper' -feature "crop wrangling button" do +describe "crop wrangling button" do let(:crop_wrangler) { create :crop_wrangling_member } let(:member) { create :member } context "crop wrangling button" do - background do + before do login_as crop_wrangler visit crops_path end - scenario "has a link to crop wrangling page" do + it "has a link to crop wrangling page" do expect(page).to have_link "Wrangle Crops", href: wrangle_crops_path end end context "crop wrangling button" do - background do + before do login_as member visit crops_path end - scenario "has no link to crop wrangling page" do + it "has no link to crop wrangling page" do expect(page).to have_no_link "Wrangle Crops", href: wrangle_crops_path end end diff --git a/spec/features/crops/delete_crop_spec.rb b/spec/features/crops/delete_crop_spec.rb index f1302c784..8a25b629a 100644 --- a/spec/features/crops/delete_crop_spec.rb +++ b/spec/features/crops/delete_crop_spec.rb @@ -1,20 +1,20 @@ require 'rails_helper' -feature "Delete crop spec" do +describe "Delete crop spec" do context "As a crop wrangler" do let(:wrangler) { FactoryBot.create :crop_wrangling_member } let!(:pending_crop) { FactoryBot.create :crop_request } let!(:approved_crop) { FactoryBot.create :crop } - background { login_as wrangler } + before { login_as wrangler } - scenario "Delete approved crop" do + it "Delete approved crop" do visit crop_path(approved_crop) click_link 'Delete' expect(page).to have_content "crop was successfully destroyed" end - scenario "Delete pending crop" do + it "Delete pending crop" do visit crop_path(pending_crop) click_link 'Delete' expect(page).to have_content "crop was successfully destroyed" diff --git a/spec/features/crops/inflections_spec.rb b/spec/features/crops/inflections_spec.rb index 615c4c9e9..c7ca5ce37 100644 --- a/spec/features/crops/inflections_spec.rb +++ b/spec/features/crops/inflections_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' -feature "irregular crop inflections" do +describe "irregular crop inflections" do # We're just testing a couple of representative crops to # check that inflection works: you don't need to add # every crop here. - scenario "crops which are mass nouns" do + it "crops which are mass nouns" do expect("kale".pluralize).to eq "kale" expect("broccoli".pluralize).to eq "broccoli" expect("square foot".pluralize).to eq "square feet" @@ -26,29 +26,29 @@ feature "irregular crop inflections" do expect("star anise".pluralize).to eq "star anise" end - scenario "crops which are particularly irregular" do + it "crops which are particularly irregular" do expect("curry leaf".pluralize).to eq "curry leaves" end - scenario "crops which require -es" do + it "crops which require -es" do expect("mango".pluralize).to eq "mangoes" expect("potato".pluralize).to eq "potatoes" end - scenario "crops where the first crop would normally be pluralized" do + it "crops where the first crop would normally be pluralized" do expect("Potato Onion".pluralize).to eq "Potato Onions" expect("pear tomato".pluralize).to eq "pear tomatoes" expect("chilli pepper".pluralize).to eq "chilli peppers" end - scenario "crops where the proper name succeeds the crop that would normally be pluralized" do + it "crops where the proper name succeeds the crop that would normally be pluralized" do expect("potato Taranaki".pluralize).to eq "potato Taranaki" expect("potato Gladstone".pluralize).to eq "potato Gladstone" expect("potato matariki".pluralize).to eq "potato matariki" expect("spinach Santana".pluralize).to eq "spinach Santana" end - scenario "crops of Māori origin" do + it "crops of Māori origin" do expect("kūmara".pluralize).to eq "kūmara" expect("pūhā".pluralize).to eq "pūhā" end diff --git a/spec/features/crops/request_new_crop_spec.rb b/spec/features/crops/request_new_crop_spec.rb index 1374d1176..cd5cfb984 100644 --- a/spec/features/crops/request_new_crop_spec.rb +++ b/spec/features/crops/request_new_crop_spec.rb @@ -1,15 +1,15 @@ require 'rails_helper' -feature "Requesting a new crop" do +describe "Requesting a new crop" do context "As a regular member" do let(:member) { create :member } let!(:wrangler) { create :crop_wrangling_member } - background do + before do login_as member end - scenario "Submit request" do + it "Submit request" do visit new_crop_path fill_in "Name", with: "Couch potato" fill_in "request_notes", with: "Couch potatoes are real for real." @@ -24,9 +24,9 @@ feature "Requesting a new crop" do let!(:crop) { create :crop_request } let!(:already_approved) { create :crop } - background { login_as wrangler } + before { login_as wrangler } - scenario "Approve a request" do + it "Approve a request" do visit edit_crop_path(crop) select "approved", from: "Approval status" click_button "Save" @@ -36,7 +36,7 @@ feature "Requesting a new crop" do expect(page).to have_content "crop was successfully updated." end - scenario "Rejecting a crop" do + it "Rejecting a crop" do visit edit_crop_path(crop) select "rejected", from: "Approval status" select "not edible", from: "Reason for rejection" diff --git a/spec/features/crops/requested_crops_spec.rb b/spec/features/crops/requested_crops_spec.rb index 2ab750fe7..a4e406b63 100644 --- a/spec/features/crops/requested_crops_spec.rb +++ b/spec/features/crops/requested_crops_spec.rb @@ -1,15 +1,15 @@ require 'rails_helper' -feature "Crop - " do +describe "Crop - " do let(:member) { create :member } let!(:requested_crop) { create :crop, requester: member, approval_status: 'pending', name: 'puha for dinner' } - background do + before do login_as member visit requested_crops_path end - scenario "creating a crop with multiple scientific and alternate name", :js do + it "creating a crop with multiple scientific and alternate name", :js do expect(page).to have_content "puha for dinner" end end diff --git a/spec/features/crops/show_spec.rb b/spec/features/crops/show_spec.rb index cc5ff75db..bfab353a4 100644 --- a/spec/features/crops/show_spec.rb +++ b/spec/features/crops/show_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature "browse crops" do +describe "browse crops" do let(:tomato) { create :tomato } let(:maize) { create :maize } let(:pending_crop) { create :crop_request } let(:rejected_crop) { create :rejected_crop } - scenario "Show crop info" do + it "Show crop info" do visit crop_path(tomato) expect(page).to have_text 'tomato' end @@ -18,7 +18,7 @@ feature "browse crops" do FactoryBot.create :harvest, crop: tomato, harvested_at: 60.minutes.ago, created_at: 10.minutes.ago end - scenario "Shows most recently harvested harvest" do + it "Shows most recently harvested harvest" do visit crop_path(tomato) expect(page).to have_link(href: harvest_path(most_recent_harvest)) end @@ -31,7 +31,7 @@ feature "browse crops" do FactoryBot.create :planting, crop: tomato, planted_at: 60.minutes.ago, created_at: 10.minutes.ago end - scenario "Shows most recently planted planting" do + it "Shows most recently planted planting" do visit crop_path(tomato) expect(page).to have_link(href: planting_path(most_recent_planting)) end diff --git a/spec/features/following_spec.rb b/spec/features/following_spec.rb index 0be64a4f0..762320671 100644 --- a/spec/features/following_spec.rb +++ b/spec/features/following_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' -feature "follows", :js do +describe "follows", :js do context "when signed out" do let(:member) { create :member } - scenario "follow buttons on member profile page" do + it "follow buttons on member profile page" do visit member_path(member) expect(page).not_to have_link "Follow" expect(page).not_to have_link "Unfollow" @@ -15,36 +15,36 @@ feature "follows", :js do let(:member) { create :member } let(:other_member) { create :member } - background do + before do login_as(member) end - scenario "your profile doesn't have a follow button" do + it "your profile doesn't have a follow button" do visit member_path(member) expect(page).not_to have_link "Follow" expect(page).not_to have_link "Unfollow" end context "following another member" do - background { visit member_path(other_member) } + before { visit member_path(other_member) } - scenario "has a follow button" do + it "has a follow button" do expect(page).to have_link "Follow", href: follows_path(followed: other_member.slug) end - scenario "has correct message and unfollow button" do + it "has correct message and unfollow button" do click_link 'Follow' expect(page).to have_content "Followed #{other_member.login_name}" expect(page).to have_link "Unfollow", href: follow_path(member.get_follow(other_member)) end - scenario "has a followed member listed in the following page" do + it "has a followed member listed in the following page" do click_link 'Follow' visit member_follows_path(member) expect(page).to have_content other_member.login_name end - scenario "has correct message and follow button after unfollow" do + it "has correct message and follow button after unfollow" do click_link 'Follow' click_link 'Unfollow' expect(page).to have_content "Unfollowed #{other_member.login_name}" @@ -52,19 +52,19 @@ feature "follows", :js do expect(page).to have_link "Follow", href: follows_path(followed: other_member.slug) end - scenario "has member in following list" do + it "has member in following list" do click_link 'Follow' visit member_follows_path(member) expect(page).to have_content other_member.login_name end - scenario "appears in in followed member's followers list" do + it "appears in in followed member's followers list" do click_link 'Follow' visit member_followers_path(other_member) expect(page).to have_content member.login_name end - scenario "removes members from following and followers lists after unfollow" do + it "removes members from following and followers lists after unfollow" do click_link 'Follow' click_link 'Unfollow' visit member_follows_path(member) diff --git a/spec/features/footer_spec.rb b/spec/features/footer_spec.rb index b7d109773..59d65b4db 100644 --- a/spec/features/footer_spec.rb +++ b/spec/features/footer_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' -feature "footer", js: true do +describe "footer", js: true do before { visit root_path } - scenario "footer is on home page" do + it "footer is on home page" do expect(page).to have_css 'footer' end diff --git a/spec/features/gardens/actions_spec.rb b/spec/features/gardens/actions_spec.rb index 98337063d..80faaf68b 100644 --- a/spec/features/gardens/actions_spec.rb +++ b/spec/features/gardens/actions_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' require 'custom_matchers' -feature "Gardens" do +describe "Gardens" do context 'logged in' do subject { page } let(:member) { FactoryBot.create :member } - background { login_as member } + before { login_as member } let(:garden) { member.gardens.first } let(:other_member_garden) { FactoryBot.create :garden } diff --git a/spec/features/gardens/adding_gardens_spec.rb b/spec/features/gardens/adding_gardens_spec.rb index c3f78dd18..437d2812f 100644 --- a/spec/features/gardens/adding_gardens_spec.rb +++ b/spec/features/gardens/adding_gardens_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' require 'custom_matchers' -feature "Gardens", :js do +describe "Gardens", :js do let(:member) { FactoryBot.create :member } - background do + before do login_as member visit new_garden_path end @@ -20,14 +20,14 @@ feature "Gardens", :js do expect(page).to have_optional 'input#garden_area' end - scenario "Create new garden" do + it "Create new garden" do fill_in "Name", with: "New garden" click_button "Save" expect(page).to have_content "Garden was successfully created" expect(page).to have_content "New garden" end - scenario "Refuse to create new garden with negative area" do + it "Refuse to create new garden with negative area" do visit new_garden_path fill_in "Name", with: "Negative Garden" fill_in "Area", with: -5 diff --git a/spec/features/gardens/gardens_index_spec.rb b/spec/features/gardens/gardens_index_spec.rb index b5b929df1..e14bbbc5d 100644 --- a/spec/features/gardens/gardens_index_spec.rb +++ b/spec/features/gardens/gardens_index_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' require 'custom_matchers' -feature "Gardens#index", :js do +describe "Gardens#index", :js do context "Logged in as member" do let(:member) { FactoryBot.create :member, login_name: 'shadow' } - background { login_as member } + before { login_as member } context "with 10 gardens" do before do diff --git a/spec/features/gardens_spec.rb b/spec/features/gardens_spec.rb index 504ecda49..816995dad 100644 --- a/spec/features/gardens_spec.rb +++ b/spec/features/gardens_spec.rb @@ -1,17 +1,17 @@ require 'rails_helper' -feature "Planting a crop", js: true do +describe "Planting a crop", js: true do # name is aaa to ensure it is ordered first let!(:garden) { create :garden, name: 'aaa' } let!(:planting) { create :planting, garden: garden, owner: garden.owner, planted_at: Date.parse("2013-3-10") } let!(:tomato) { create :tomato } let!(:finished_planting) { create :finished_planting, owner: garden.owner, garden: garden, crop: tomato } - background do + before do login_as garden.owner end - scenario "View gardens" do + it "View gardens" do visit gardens_path expect(page).to have_content "Everyone's gardens" within '.layout-actions' do @@ -24,7 +24,7 @@ feature "Planting a crop", js: true do expect(page).to have_content "Everyone's gardens" end - scenario "Marking a garden as inactive" do + it "Marking a garden as inactive" do visit garden_path(garden) click_link "Mark as inactive" expect(page).to have_content "Garden was successfully updated" @@ -33,14 +33,14 @@ feature "Planting a crop", js: true do expect(page).not_to have_content "Mark as inactive" end - scenario "List only active gardens" do + it "List only active gardens" do visit garden_path(garden) click_link "Mark as inactive" visit gardens_path expect(page).not_to have_link garden_path(garden) end - scenario "Create new garden" do + it "Create new garden" do visit new_garden_path fill_in "Name", with: "New garden" click_button "Save" @@ -48,7 +48,7 @@ feature "Planting a crop", js: true do expect(page).to have_content "New garden" end - scenario "Refuse to create new garden with negative area" do + it "Refuse to create new garden with negative area" do visit new_garden_path fill_in "Name", with: "Negative Garden" fill_in "Area", with: -5 @@ -58,17 +58,17 @@ feature "Planting a crop", js: true do end context "Clicking edit from the index page" do - background do + before do visit gardens_path end - scenario "button on index to edit garden" do + it "button on index to edit garden" do click_link href: edit_garden_path(garden) expect(page).to have_content 'Edit garden' end end - scenario "Edit garden" do + it "Edit garden" do visit new_garden_path fill_in "Name", with: "New garden" click_button "Save" @@ -81,7 +81,7 @@ feature "Planting a crop", js: true do expect(page).to have_content "Different name" end - scenario "Delete garden" do + it "Delete garden" do visit new_garden_path fill_in "Name", with: "New garden" click_button "Save" @@ -98,7 +98,7 @@ feature "Planting a crop", js: true do it_behaves_like "append date" end - scenario "List only active plantings on a garden" do + it "List only active plantings on a garden" do visit gardens_path expect(page).not_to have_content finished_planting.crop_name end diff --git a/spec/features/harvests/browse_harvests_spec.rb b/spec/features/harvests/browse_harvests_spec.rb index b2409c122..a141547e4 100644 --- a/spec/features/harvests/browse_harvests_spec.rb +++ b/spec/features/harvests/browse_harvests_spec.rb @@ -1,31 +1,31 @@ require 'rails_helper' -feature "browse harvests" do +describe "browse harvests" do subject { page } let!(:member) { create :member } let!(:harvest) { create :harvest, owner: member } - background { login_as member } + before { login_as member } - feature 'blank optional fields' do + describe 'blank optional fields' do let!(:harvest) { create :harvest, :no_description } before { visit harvests_path } - scenario 'read more' do + it 'read more' do is_expected.not_to have_link "Read more" end end - feature "filled in optional fields" do + describe "filled in optional fields" do let!(:harvest) { create :harvest, :long_description } before do visit harvests_path end - scenario 'read more' do + it 'read more' do is_expected.to have_link "Read more" end diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index f30d12baa..6f69555fc 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -1,13 +1,13 @@ require 'rails_helper' require 'custom_matchers' -feature "Harvesting a crop", :js, :elasticsearch do +describe "Harvesting a crop", :js, :elasticsearch do let(:member) { create :member } let!(:maize) { create :maize } let!(:plant_part) { create :plant_part } let(:planting) { create :planting, crop: maize, owner: member } - background do + before do login_as member visit new_harvest_path sync_elasticsearch [maize] @@ -26,7 +26,7 @@ feature "Harvesting a crop", :js, :elasticsearch do expect(page).to have_optional 'textarea#harvest_description' end - scenario "Creating a new harvest", :js do + it "Creating a new harvest", :js do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" @@ -45,24 +45,24 @@ feature "Harvesting a crop", :js, :elasticsearch do context "Clicking edit from the index page" do let!(:harvest) { create :harvest, crop: maize, owner: member } - background do + before do visit harvests_path end - scenario "button on index to edit harvest" do + it "button on index to edit harvest" do click_link "edit_harvest_glyphicon" expect(current_path).to eq edit_harvest_path(harvest) expect(page).to have_content 'Editing harvest' end end - scenario "Clicking link to owner's profile" do + it "Clicking link to owner's profile" do visit member_harvests_path(member) click_link "View #{member}'s profile >>" expect(current_path).to eq member_path member end - scenario "Harvesting from crop page" do + it "Harvesting from crop page" do visit crop_path(maize) within '.crop-actions' do click_link "Harvest #{maize.name}" @@ -77,7 +77,7 @@ feature "Harvesting a crop", :js, :elasticsearch do expect(page).to have_content "maize" end - scenario "Harvesting from planting page" do + it "Harvesting from planting page" do planting = create :planting, crop: maize, owner: member, garden: member.gardens.first visit planting_path(planting) within ".planting-actions" do @@ -96,12 +96,12 @@ feature "Harvesting a crop", :js, :elasticsearch do let(:existing_harvest) { create :harvest, crop: maize, owner: member } let!(:other_plant_part) { create :plant_part, name: 'chocolate' } - background do + before do visit harvest_path(existing_harvest) click_link "Edit" end - scenario "Saving without edits" do + it "Saving without edits" do # Check that the autosuggest helper properly fills inputs with # existing resource's data click_button "Save" @@ -109,7 +109,7 @@ feature "Harvesting a crop", :js, :elasticsearch do expect(page).to have_content "maize" end - scenario "change plant part" do + it "change plant part" do select other_plant_part.name, from: 'harvest[plant_part_id]' click_button "Save" expect(page).to have_content "harvest was successfully updated." @@ -127,11 +127,11 @@ feature "Harvesting a crop", :js, :elasticsearch do planted_at: Time.zone.yesterday end - background do + before do visit harvest_path(existing_harvest) end - scenario "linking to a planting" do + it "linking to a planting" do expect(page).to have_content existing_planting.to_s choose("harvest_planting_id_#{existing_planting.id}") click_button "save" diff --git a/spec/features/home/home_spec.rb b/spec/features/home/home_spec.rb index 7376de882..219dba412 100644 --- a/spec/features/home/home_spec.rb +++ b/spec/features/home/home_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "home page" do +describe "home page" do subject { page } let(:member) { FactoryBot.create :member } @@ -16,7 +16,7 @@ feature "home page" do let!(:finished_seed) { FactoryBot.create :tradable_seed, finished: true } let!(:untradable_seed) { FactoryBot.create :untradable_seed } - background do + before do # Add photos, so they can appear on home page planting.photos << photo seed.photos << photo @@ -79,7 +79,7 @@ feature "home page" do end context "when signed in" do - background { login_as member } + before { login_as member } include_examples 'show crops' include_examples 'show plantings' include_examples 'show harvests' diff --git a/spec/features/likeable_spec.rb b/spec/features/likeable_spec.rb index d1b637e0d..0a39154b0 100644 --- a/spec/features/likeable_spec.rb +++ b/spec/features/likeable_spec.rb @@ -1,17 +1,17 @@ require 'rails_helper' -feature 'Likeable', js: true do +describe 'Likeable', js: true do let(:member) { FactoryBot.create(:member) } let(:another_member) { FactoryBot.create(:london_member) } let(:post) { FactoryBot.create(:post) } context 'logged in member' do - background do + before do login_as member visit post_path(post) end - scenario 'can be liked' do + it 'can be liked' do expect(page).to have_link 'Like' click_link 'Like' expect(page).to have_content '1 like' @@ -23,7 +23,7 @@ feature 'Likeable', js: true do expect(page).to have_content '0 likes' end - scenario 'displays correct number of likes' do + it 'displays correct number of likes' do expect(page).to have_link 'Like' click_link 'Like' expect(page).to have_content '1 like' diff --git a/spec/features/locale_spec.rb b/spec/features/locale_spec.rb index 01d164f3c..863fac079 100644 --- a/spec/features/locale_spec.rb +++ b/spec/features/locale_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' -feature "Changing locales", js: true do +describe "Changing locales", js: true do after { I18n.locale = :en } - scenario "Locale can be set with a query param" do + it "Locale can be set with a query param" do visit root_path expect(page).to have_content("a community of food gardeners.") visit root_path(locale: 'ja') diff --git a/spec/features/member_profile_spec.rb b/spec/features/member_profile_spec.rb index a548c7eb0..913115188 100644 --- a/spec/features/member_profile_spec.rb +++ b/spec/features/member_profile_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' -feature "member profile", js: true do +describe "member profile", js: true do context "signed out member" do let(:member) { create :member } - scenario "basic details on member profile page" do + it "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 @@ -12,20 +12,20 @@ feature "member profile", js: true do expect(page).to have_link "More about this garden...", href: garden_path(member.gardens.first) end - scenario "no bio" do + it "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 + it "gravatar" do visit member_path(member) expect(page).to have_css "img.avatar" end context "location" do - scenario "member has set location" do + it "member has set location" do london_member = create :london_member visit member_path(london_member) expect(page).to have_css("h1>small", text: london_member.location) @@ -33,7 +33,7 @@ feature "member profile", js: true do expect(page).to have_content "See other members, plantings, seeds and more near #{london_member.location}" end - scenario "member has not set location" do + it "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") @@ -42,31 +42,31 @@ feature "member profile", js: true do end context "email privacy" do - scenario "public email address" do + it "public email address" do public_member = create :public_member visit member_path(public_member) expect(page).to have_content public_member.email end - scenario "private email address" do + it "private email address" do visit member_path(member) expect(page).not_to have_content member.email end end context "email privacy" do - scenario "public email address" do + it "public email address" do public_member = create :public_member visit member_path(public_member) expect(page).to have_content public_member.email end - scenario "private email address" do + it "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 + it "with no activity" do visit member_path(member) expect(page).to have_content "Activity" expect(page).to have_content "0 plantings" @@ -75,7 +75,7 @@ feature "member profile", js: true do expect(page).to have_content "0 posts" end - scenario "with some activity" do + it "with some activity" do create_list :planting, 2, owner: member create_list :harvest, 3, owner: member create_list :seed, 4, owner: member @@ -88,13 +88,13 @@ feature "member profile", js: true do end end - scenario "twitter link" do + it "twitter link" do twitter_auth = 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 + it "flickr link" do flickr_auth = 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}" @@ -107,56 +107,56 @@ feature "member profile", js: true do let(:admin_member) { create :admin_member } let(:crop_wrangler) { create :crop_wrangling_member } - background do + before do login_as(member) end - scenario "admin user's page" do + it "admin user's page" do visit member_path(admin_member) expect(page).to have_text "Admin" end - scenario "crop wrangler's page" do + it "crop wrangler's page" do visit member_path(crop_wrangler) expect(page).to have_text "Crop Wrangler" end - scenario "ordinary user's page" do + it "ordinary user's page" do visit member_path(other_member) expect(page).not_to have_text "Crop Wrangler" expect(page).not_to have_text "Admin" end context "your own profile page" do - background do + before do visit member_path(member) end - scenario "has a link to create new garden" do + it "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 + it "has a button to edit profile" do expect(page).to have_link "Edit profile", href: edit_member_registration_path end end context "someone else's profile page" do - background do + before do visit member_path(other_member) end - scenario "has a private message button" do + it "has a private message button" do expect(page).to have_link "Send message", href: new_notification_path(recipient_id: other_member.id) end end context "home page" do - background do + before do visit root_path end - scenario "does not have a button to edit profile" do + it "does not have a button to edit profile" do expect(page).not_to have_link "Edit profile", href: edit_member_registration_path end end diff --git a/spec/features/members/deletion_spec.rb b/spec/features/members/deletion_spec.rb index 3c392cb4c..6cf074f1a 100644 --- a/spec/features/members/deletion_spec.rb +++ b/spec/features/members/deletion_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "member deletion" do +describe "member deletion" do context "with activity and followers" do let(:member) { FactoryBot.create(:member) } let(:other_member) { FactoryBot.create(:member) } @@ -12,7 +12,7 @@ feature "member deletion" do let!(:secondgarden) { FactoryBot.create(:garden, owner: member) } let(:admin) { FactoryBot.create(:admin_member) } - background do + before do login_as(member) visit member_path(other_member) click_link 'Follow' @@ -30,13 +30,13 @@ feature "member deletion" do FactoryBot.create(:member, login_name: "ex_member") end - scenario "has option to delete on member profile page" do + it "has option to delete on member profile page" do visit member_path(member) click_link 'Edit profile' expect(page).to have_link "Delete Account" end - scenario "asks for password before deletion" do + it "asks for password before deletion" do visit member_path(member) click_link 'Edit profile' click_link 'Delete Account' @@ -44,7 +44,7 @@ feature "member deletion" do expect(page).to have_content "Current password can't be blank" end - scenario "password must be correct" do + it "password must be correct" do visit member_path(member) click_link 'Edit profile' click_link 'Delete Account' @@ -53,7 +53,7 @@ feature "member deletion" do expect(page).to have_content "Current password is invalid" end - scenario "deletes and removes bio" do + it "deletes and removes bio" do visit member_path(member) click_link 'Edit profile' click_link 'Delete Account' @@ -64,7 +64,7 @@ feature "member deletion" do end context "deletes and" do - background do + before do logout login_as(member) visit member_path(member) @@ -79,39 +79,39 @@ feature "member deletion" do it { expect(Member.with_deleted.find(member.id)).to eq member } end - scenario "removes plantings" do + it "removes plantings" do visit planting_path(planting) expect(page.status_code).to eq(404) end - scenario "removes gardens" do + it "removes gardens" do visit garden_path(secondgarden) expect(page.status_code).to eq(404) end - scenario "removes harvests and seeds" do + it "removes harvests and seeds" do visit harvest_path(harvest) expect(page.status_code).to eq(404) end - scenario "removes seeds" do + it "removes seeds" do visit seed_path(seed) expect(page.status_code).to eq(404) end - scenario "removes members from following" do + it "removes members from following" do visit member_follows_path(other_member) expect(page).not_to have_content member.login_name.to_s visit member_followers_path(other_member) expect(page).not_to have_content member.login_name.to_s end - scenario "replaces posts with deletion note" do + it "replaces posts with deletion note" do visit post_path(memberpost) expect(page.status_code).to eq(404) end - scenario "replaces comments on others' posts with deletion note, leaving post intact" do + it "replaces comments on others' posts with deletion note, leaving post intact" do FactoryBot.create :comment, post: othermemberpost, author: member, body: 'i am deleting my account' visit post_path(othermemberpost) @@ -120,7 +120,7 @@ feature "member deletion" do expect(page).to have_content "Member Deleted" end - scenario "can't be interesting" do + it "can't be interesting" do expect(Member.interesting).not_to include(member) expect(Planting.interesting).not_to include(planting) expect(Seed.interesting).not_to include(seed) @@ -128,7 +128,7 @@ feature "member deletion" do pending "doesn't show in nearby" - scenario "can no longer sign in" do + it "can no longer sign in" do visit new_member_session_path fill_in 'Login', with: member.login_name fill_in 'Password', with: member.password @@ -145,7 +145,7 @@ feature "member deletion" do FactoryBot.create(:cropbot) let!(:ex_wrangler) { FactoryBot.create(:crop_wrangling_member, login_name: "ex_wrangler") } - scenario "leaves crops behind" do + it "leaves crops behind" do login_as(otherwrangler) visit edit_crop_path(crop) expect(page).to have_content member.login_name diff --git a/spec/features/members_list_spec.rb b/spec/features/members_list_spec.rb index 184efbfb6..9523b6238 100644 --- a/spec/features/members_list_spec.rb +++ b/spec/features/members_list_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature "members list" do +describe "members list" do context "list all members" do let!(:member1) { create :member, login_name: "Archaeopteryx", confirmed_at: Time.zone.parse('2013-02-10') } let!(:member2) { create :member, login_name: "Zephyrosaurus", confirmed_at: Time.zone.parse('2014-01-11') } let!(:member3) { create :member, login_name: "Testingname", confirmed_at: Time.zone.parse('2014-05-09') } - scenario "default alphabetical sort" do + it "default alphabetical sort" do visit members_path expect(page).to have_css "#sort" expect(page).to have_selector "form" @@ -16,7 +16,7 @@ feature "members list" do expect(all_links.last).to have_text member2.login_name end - scenario "recently joined sort" do + it "recently joined sort" do visit members_path expect(page).to have_css "#sort" expect(page).to have_selector "form" diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index a5c544552..347d27627 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "Notifications", :js do +describe "Notifications", :js do let(:sender) { create :member } let(:recipient) { create :member, login_name: 'beyonce' } @@ -13,12 +13,12 @@ feature "Notifications", :js do post_id: nil end - background do + before do login_as recipient visit notification_path(notification) end - scenario "Replying to the notification" do + it "Replying to the notification" do click_link "Reply" expect(page).to have_content "Notification body" diff --git a/spec/features/photos/new_photo_spec.rb b/spec/features/photos/new_photo_spec.rb index 3c486fa5b..71cdfc198 100644 --- a/spec/features/photos/new_photo_spec.rb +++ b/spec/features/photos/new_photo_spec.rb @@ -1,17 +1,17 @@ require 'rails_helper' -feature "new photo page" do +describe "new photo page" do let(:photo) { FactoryBot.create :photo } context "signed in member" do let(:member) { FactoryBot.create :member } - background { login_as member } + before { login_as member } context "viewing a planting" do let(:planting) { FactoryBot.create :planting, owner: member } - scenario "add photo" do + it "add photo" do visit planting_path(planting) within '.planting-actions' do click_link('Add photo') @@ -23,7 +23,7 @@ feature "new photo page" do context "viewing a harvest" do let(:harvest) { FactoryBot.create :harvest, owner: member } - scenario "add photo" do + it "add photo" do visit harvest_path(harvest) within '.harvest-actions' do click_link "Add photo" @@ -35,7 +35,7 @@ feature "new photo page" do context "viewing a garden" do let(:garden) { FactoryBot.create :garden, owner: member } - scenario "add photo" do + it "add photo" do visit garden_path(garden) within '.garden-actions' do click_link "Add photo" @@ -47,7 +47,7 @@ feature "new photo page" do describe "viewing a seed" do let(:seed) { FactoryBot.create :seed, owner: member } - scenario "add photo" do + it "add photo" do visit seed_path(seed) first('.seed-actions').click_link('Add photo') expect(page).to have_text seed.to_s diff --git a/spec/features/photos/show_photo_spec.rb b/spec/features/photos/show_photo_spec.rb index 973aa349a..a8d2ff802 100644 --- a/spec/features/photos/show_photo_spec.rb +++ b/spec/features/photos/show_photo_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' -feature "show photo page" do +describe "show photo page" do context "signed in member" do let(:member) { create :member } - background { login_as member } + before { login_as member } context "linked to planting" do let(:planting) { create :planting } diff --git a/spec/features/places/searching_a_place_spec.rb b/spec/features/places/searching_a_place_spec.rb index 7a2d12898..29e49ce21 100644 --- a/spec/features/places/searching_a_place_spec.rb +++ b/spec/features/places/searching_a_place_spec.rb @@ -1,13 +1,13 @@ require "rails_helper" -feature "User searches" do +describe "User searches" do let(:member) { create :member, location: "Philippines" } let!(:maize) { create :maize } let(:garden) { create :garden, owner: member } let!(:seed1) { create :seed, owner: member } let!(:planting) { create :planting, garden: garden, owner: member, planted_at: Date.parse("2013-3-10") } - scenario "with a valid place" do + it "with a valid place" do visit places_path search_with "Philippines" expect(page).to have_content "community near Philippines" @@ -16,7 +16,7 @@ feature "User searches" do expect(page).not_to have_content "No results found" end - scenario "with a blank search string" do + it "with a blank search string" do visit places_path search_with "" expect(page).to have_content "Please enter a valid location" diff --git a/spec/features/planting_reminder_spec.rb b/spec/features/planting_reminder_spec.rb index e13803182..1b8fe7a37 100644 --- a/spec/features/planting_reminder_spec.rb +++ b/spec/features/planting_reminder_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' require 'capybara/email/rspec' -feature "Planting reminder email", :js do +describe "Planting reminder email", :js do let(:member) { create :member } let(:mail) { Notifier.planting_reminder(member) } @@ -11,16 +11,16 @@ feature "Planting reminder email", :js do { host: 'localhost', port: 8080 } end - scenario "has a greeting" do + it "has a greeting" do expect(mail).to have_content "Hello" end context "when member has no plantings" do - scenario "tells you to track your plantings" do + it "tells you to track your plantings" do expect(mail).to have_content "planting your first crop" end - scenario "doesn't list plantings" do + it "doesn't list plantings" do expect(mail).not_to have_content "most recent plantings you've told us about" end end @@ -31,7 +31,7 @@ feature "Planting reminder email", :js do let!(:p1) { create :planting, garden: member.gardens.first, owner: member } let!(:p2) { create :planting, garden: member.gardens.first, owner: member } - scenario "lists plantings" do + it "lists plantings" do expect(mail).to have_content "most recent plantings you've told us about" expect(mail).to have_link p1.to_s, href: planting_url(p1) expect(mail).to have_link p2.to_s, href: planting_url(p2) @@ -40,11 +40,11 @@ feature "Planting reminder email", :js do end context "when member has no harvests" do - scenario "tells you to tracking plantings" do + it "tells you to tracking plantings" do expect(mail).to have_content "Get started now by tracking your first harvest" end - scenario "doesn't list plantings" do + it "doesn't list plantings" do expect(mail).not_to have_content "the last few things you harvested were" end end @@ -55,7 +55,7 @@ feature "Planting reminder email", :js do let!(:h1) { create :harvest, owner: member } let!(:h2) { create :harvest, owner: member } - scenario "lists harvests" do + it "lists harvests" do expect(mail).to have_content "the last few things you harvested were" expect(mail).to have_link h1.to_s, href: harvest_url(h1) expect(mail).to have_link h2.to_s, href: harvest_url(h2) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 8cb70fc5a..e62e9f6ba 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" require 'custom_matchers' -feature "Planting a crop", :js, :elasticsearch do +describe "Planting a crop", :js, :elasticsearch do let(:member) { FactoryBot.create :member } let!(:maize) { FactoryBot.create :maize } let(:garden) { FactoryBot.create :garden, owner: member } @@ -9,7 +9,7 @@ feature "Planting a crop", :js, :elasticsearch do FactoryBot.create :planting, garden: garden, owner: member, planted_at: Date.parse("2013-03-10") end - background do + before do login_as member visit new_planting_path sync_elasticsearch [maize] @@ -32,7 +32,7 @@ feature "Planting a crop", :js, :elasticsearch do it { expect(page).to have_optional 'input#planting_finished_at' } end - scenario "Creating a new planting" do + it "Creating a new planting" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do @@ -48,7 +48,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).to have_content "Not enough data" end - scenario "Clicking link to owner's profile" do + it "Clicking link to owner's profile" do visit member_plantings_path(member) click_link "View #{member}'s profile >>" expect(current_path).to eq member_path(member) @@ -151,7 +151,7 @@ feature "Planting a crop", :js, :elasticsearch do end end - scenario "Planting from crop page" do + it "Planting from crop page" do visit crop_path(maize) within '.crop-actions' do click_link "Plant maize" @@ -165,7 +165,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).to have_content "maize" end - scenario "Editing a planting to add details" do + it "Editing a planting to add details" do visit planting_path(planting) click_link "Edit" fill_in "Tell us more about it", with: "Some extra notes" @@ -173,7 +173,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).to have_content "planting was successfully updated" end - scenario "Editing a planting to fill in the finished date" do + it "Editing a planting to fill in the finished date" do visit planting_path(planting) expect(page).to have_content "Not enough data" click_link "Edit" @@ -184,7 +184,7 @@ feature "Planting a crop", :js, :elasticsearch do expect(page).not_to have_content "Not enough data" end - scenario "Marking a planting as finished" do + it "Marking a planting as finished" do fill_autocomplete "crop", with: "mai" select_from_autocomplete "maize" within "form#new_planting" do diff --git a/spec/features/posts/posting_a_post_spec.rb b/spec/features/posts/posting_a_post_spec.rb index ac31b6fec..7467517c5 100644 --- a/spec/features/posts/posting_a_post_spec.rb +++ b/spec/features/posts/posting_a_post_spec.rb @@ -1,14 +1,14 @@ require 'rails_helper' -feature 'Post a post' do +describe 'Post a post' do let(:member) { create :member } - background do + before do login_as member visit new_post_path end - scenario "creating a post" do + it "creating a post" do fill_in "post_subject", with: "Testing" fill_in "post_body", with: "This is a sample test" click_button "Post" @@ -19,11 +19,11 @@ feature 'Post a post' do context "editing a post" do let(:existing_post) { create :post, author: member } - background do + before do visit edit_post_path(existing_post) end - scenario "saving edit" do + it "saving edit" do fill_in "post_subject", with: "Testing Edit" click_button "Post" expect(page).to have_content "Post was successfully updated" diff --git a/spec/features/rss/comments_spec.rb b/spec/features/rss/comments_spec.rb index f053a7e26..fef92010a 100644 --- a/spec/features/rss/comments_spec.rb +++ b/spec/features/rss/comments_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature 'Comments RSS feed' do - scenario 'The index feed exists' do +describe 'Comments RSS feed' do + it 'The index feed exists' do visit comments_path(format: 'rss') expect(page.status_code).to equal 200 end - scenario 'The index title is what we expect' do + it 'The index title is what we expect' do visit comments_path(format: 'rss') expect(page).to have_content "Recent comments on all posts (#{ENV['GROWSTUFF_SITE_NAME']})" end diff --git a/spec/features/rss/crops_spec.rb b/spec/features/rss/crops_spec.rb index ef45af20b..80ca34b29 100644 --- a/spec/features/rss/crops_spec.rb +++ b/spec/features/rss/crops_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature 'Crops RSS feed' do - scenario 'The index feed exists' do +describe 'Crops RSS feed' do + it 'The index feed exists' do visit crops_path(format: 'rss') expect(page.status_code).to equal 200 end - scenario 'The index title is what we expect' do + it 'The index title is what we expect' do visit crops_path(format: 'rss') expect(page).to have_content "Recently added crops (#{ENV['GROWSTUFF_SITE_NAME']})" end diff --git a/spec/features/rss/members_spec.rb b/spec/features/rss/members_spec.rb index 3849f9d80..8bf13b3c5 100644 --- a/spec/features/rss/members_spec.rb +++ b/spec/features/rss/members_spec.rb @@ -1,14 +1,14 @@ require 'rails_helper' -feature 'Members RSS feed' do +describe 'Members RSS feed' do let(:member) { create :member } - scenario 'The show action exists' do + it 'The show action exists' do visit member_path(member, format: 'rss') expect(page.status_code).to equal 200 end - scenario 'The show action title is what we expect' do + it 'The show action title is what we expect' do visit member_path(member, format: 'rss') expect(page).to have_content "#{member.login_name}'s recent posts (#{ENV['GROWSTUFF_SITE_NAME']})" end diff --git a/spec/features/rss/plantings_spec.rb b/spec/features/rss/plantings_spec.rb index c3f68fea6..7624c22c0 100644 --- a/spec/features/rss/plantings_spec.rb +++ b/spec/features/rss/plantings_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature 'Plantings RSS feed' do - scenario 'The index feed exists' do +describe 'Plantings RSS feed' do + it 'The index feed exists' do visit plantings_path(format: 'rss') expect(page.status_code).to equal 200 end - scenario 'The index title is what we expect' do + it 'The index title is what we expect' do visit plantings_path(format: 'rss') expect(page).to have_content "Recent plantings from "\ "#{@owner || 'all members'} (#{ENV['GROWSTUFF_SITE_NAME']})" diff --git a/spec/features/rss/posts_spec.rb b/spec/features/rss/posts_spec.rb index 668276fbb..93797c7bc 100644 --- a/spec/features/rss/posts_spec.rb +++ b/spec/features/rss/posts_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature 'Posts RSS feed' do - scenario 'The index feed exists' do +describe 'Posts RSS feed' do + it 'The index feed exists' do visit posts_path(format: 'rss') expect(page.status_code).to equal 200 end - scenario 'The index title is what we expect' do + it 'The index title is what we expect' do visit posts_path(format: 'rss') expect(page).to have_content "Recent posts from "\ "#{@author || 'all members'} (#{ENV['GROWSTUFF_SITE_NAME']})" diff --git a/spec/features/rss/seeds_spec.rb b/spec/features/rss/seeds_spec.rb index abb66e7e3..5ae25949e 100644 --- a/spec/features/rss/seeds_spec.rb +++ b/spec/features/rss/seeds_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature 'Seeds RSS feed' do - scenario 'The index feed exists' do +describe 'Seeds RSS feed' do + it 'The index feed exists' do visit seeds_path(format: 'rss') expect(page.status_code).to equal 200 end - scenario 'The index title is what we expect' do + it 'The index title is what we expect' do visit seeds_path(format: 'rss') expect(page).to have_content "Recent seeds from "\ "#{@owner || 'all members'} (#{ENV['GROWSTUFF_SITE_NAME']})" diff --git a/spec/features/scientific_name_spec.rb b/spec/features/scientific_name_spec.rb index 3844a3a07..00563deb6 100644 --- a/spec/features/scientific_name_spec.rb +++ b/spec/features/scientific_name_spec.rb @@ -1,16 +1,16 @@ require 'rails_helper' -feature "Scientific names", js: true do +describe "Scientific names", js: true do let!(:zea_mays) { create :zea_mays } let(:crop) { zea_mays.crop } - scenario "Display scientific names on crop page" do + it "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.name end - scenario "Index page for scientific names" do + it "Index page for scientific names" do visit scientific_names_path expect(page.status_code).to equal 200 expect(page).to have_content zea_mays.name @@ -20,11 +20,11 @@ feature "Scientific names", js: true do let!(:crop_wranglers) { create_list :crop_wrangling_member, 3 } let(:member) { crop_wranglers.first } - background do + before do login_as(member) end - scenario "Crop wranglers can edit scientific names" do + it "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" @@ -39,7 +39,7 @@ feature "Scientific names", js: true do expect(page).to have_content 'crop was successfully updated' end - scenario "Crop wranglers can delete scientific names" do + it "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) @@ -49,7 +49,7 @@ feature "Scientific names", js: true do expect(page).to have_content 'Scientific name was successfully deleted.' end - scenario "Crop wranglers can add scientific names" do + it "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) @@ -63,7 +63,7 @@ feature "Scientific names", js: true do expect(page).to have_content 'crop was successfully created.' end - scenario "The show-scientific-name page works" do + it "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, @@ -74,7 +74,7 @@ feature "Scientific names", js: true do let(:pending_crop) { create :crop_request } let(:pending_sci_name) { create :scientific_name, crop: pending_crop } - scenario "Displays crop pending message" do + it "Displays crop pending message" do visit scientific_name_path(pending_sci_name) expect(page).to have_content "This crop is currently pending approval" end diff --git a/spec/features/seeds/adding_seeds_spec.rb b/spec/features/seeds/adding_seeds_spec.rb index 2964a5ab3..0f21633c3 100644 --- a/spec/features/seeds/adding_seeds_spec.rb +++ b/spec/features/seeds/adding_seeds_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' require 'custom_matchers' -feature "Seeds", :js, :elasticsearch do +describe "Seeds", :js, :elasticsearch do let(:member) { create :member } let!(:maize) { create :maize } - background do + before do login_as member visit new_seed_path sync_elasticsearch [maize] diff --git a/spec/features/seeds/misc_seeds_spec.rb b/spec/features/seeds/misc_seeds_spec.rb index e7c1e0291..0d75dc3c4 100644 --- a/spec/features/seeds/misc_seeds_spec.rb +++ b/spec/features/seeds/misc_seeds_spec.rb @@ -1,12 +1,12 @@ require 'rails_helper' -feature "seeds", js: true do +describe "seeds", js: true do let(:member) { create :member } context "signed in user" do let(:crop) { create :crop } - background { login_as member } + before { login_as member } describe "button on index to edit seed" do let!(:seed) { create :seed, owner: member } @@ -41,7 +41,7 @@ feature "seeds", js: true do # actually adding seeds is in spec/features/seeds_new_spec.rb - scenario "edit seeds" do + it "edit seeds" do seed = create :seed, owner: member visit seed_path(seed) click_link 'Edit' diff --git a/spec/features/seeds/seed_photos.rb b/spec/features/seeds/seed_photos.rb index 60746d98b..add3d0fa5 100644 --- a/spec/features/seeds/seed_photos.rb +++ b/spec/features/seeds/seed_photos.rb @@ -1,7 +1,7 @@ require 'rails_helper' require 'custom_matchers' -feature "Seeds", :js do +describe "Seeds", :js do subject do login_as member visit seed_path(seed) diff --git a/spec/features/signin_spec.rb b/spec/features/signin_spec.rb index 07fd6a130..4be647588 100644 --- a/spec/features/signin_spec.rb +++ b/spec/features/signin_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -feature "signin", js: true do +describe "signin", js: true do let(:member) { FactoryBot.create :member } let(:recipient) { FactoryBot.create :member } let(:wrangler) { FactoryBot.create :crop_wrangling_member } @@ -12,34 +12,34 @@ feature "signin", js: true do click_button 'Sign in' end - scenario "via email address" do + it "via email address" do visit crops_path # some random page click_link 'Sign in' login expect(page).to have_content("Sign out") end - scenario "redirect to previous page after signin" do + it "redirect to previous page after signin" do visit crops_path # some random page click_link 'Sign in' login expect(current_path).to eq crops_path end - scenario "don't redirect to devise pages after signin" do + it "don't redirect to devise pages after signin" do visit new_member_registration_path # devise signup page click_link 'Sign in' login expect(current_path).to eq root_path end - scenario "redirect to signin page for if not authenticated to view notification" do + it "redirect to signin page for if not authenticated to view notification" do visit notification_path(notification) expect(current_path).to eq new_member_session_path end shared_examples "redirects to what you were trying to do" do - scenario do + it do visit "/#{model_name}/new" expect(current_path).to eq new_member_session_path login @@ -55,14 +55,14 @@ feature "signin", js: true do end end - scenario "after signin, redirect to new notifications page" do + it "after signin, redirect to new notifications page" do visit new_notification_path(recipient_id: recipient.id) expect(current_path).to eq new_member_session_path login expect(current_path).to eq new_notification_path end - scenario "after crop wrangler signs in and crops await wrangling, show alert" do + it "after crop wrangler signs in and crops await wrangling, show alert" do create :crop_request visit crops_path # some random page click_link 'Sign in' @@ -73,7 +73,7 @@ feature "signin", js: true do end context "with facebook" do - scenario "sign in" do + it "sign in" do # Ordinarily done by database_cleaner Member.where(login_name: 'tdawg').delete_all diff --git a/spec/features/signout_spec.rb b/spec/features/signout_spec.rb index 2ccfd17dc..69f285ea7 100644 --- a/spec/features/signout_spec.rb +++ b/spec/features/signout_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' -feature "signout" do +describe "signout" do let(:member) { create :member } let(:path) {} - scenario "redirect to previous page after signout" do + it "redirect to previous page after signout" do visit crops_path # some random page click_link 'Sign in' fill_in 'Login', with: member.login_name @@ -16,7 +16,7 @@ feature "signout" do end shared_examples "sign-in redirects" do |path| - scenario "after signout, redirect to signin page if page needs authentication" do + it "after signout, redirect to signin page if page needs authentication" do visit path expect(current_path).to eq new_member_session_path expect(page).to have_http_status(200) @@ -39,7 +39,7 @@ feature "signout" do include_examples "sign-in redirects", "/seeds/new" end - scenario 'photos' do + it 'photos' do garden = FactoryBot.create :garden, owner: member visit "/photos/new?id=#{garden.id}&type=garden" expect(current_path).to eq new_member_session_path diff --git a/spec/features/signup_spec.rb b/spec/features/signup_spec.rb index 6afb28119..331dedaa7 100644 --- a/spec/features/signup_spec.rb +++ b/spec/features/signup_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' -feature "signup", js: true do - scenario "sign up for new account from top menubar" do +describe "signup", js: true do + it "sign up for new account from top menubar" do visit crops_path # something other than front page, which has multiple signup links click_link 'Sign up' fill_in 'Login name', with: 'person123' @@ -13,7 +13,7 @@ feature "signup", js: true do expect(current_path).to eq root_path end - scenario "sign up for new account with existing username" do + it "sign up for new account with existing username" do visit crops_path # something other than front page, which has multiple signup links click_link 'Sign up' fill_in 'Login name', with: 'person123' @@ -32,7 +32,7 @@ feature "signup", js: true do click_button 'Sign up' end - scenario "sign up for new account without accepting TOS" do + it "sign up for new account without accepting TOS" do visit root_path first('.signup a').click # click the 'Sign up' button in the middle of the page fill_in 'Login name', with: 'person123' @@ -45,7 +45,7 @@ feature "signup", js: true do end context "with facebook" do - scenario "sign up" do + it "sign up" do # Ordinarily done by database_cleaner Member.where(login_name: 'tdawg').delete_all Member.where(email: 'tdawg@hotmail.com').delete_all diff --git a/spec/features/unsubscribing_spec.rb b/spec/features/unsubscribing_spec.rb index 3f7843034..18af5296b 100644 --- a/spec/features/unsubscribing_spec.rb +++ b/spec/features/unsubscribing_spec.rb @@ -1,15 +1,15 @@ require 'rails_helper' require 'capybara/email/rspec' -feature "unsubscribe" do +describe "unsubscribe" do let(:member) { create :member } let(:notification) { create :notification } - background do + before do clear_emails end - scenario "from planting reminder mailing list" do + it "from planting reminder mailing list" do # verifying the initial subscription status of the member expect(member.send_planting_reminder).to eq(true) expect(member.send_notification_email).to eq(true) @@ -26,7 +26,7 @@ feature "unsubscribe" do expect(updated_member.send_notification_email).to eq(true) end - scenario "from inbox notification mailing list" do + it "from inbox notification mailing list" do # verifying the initial subscription status of the member expect(member.send_planting_reminder).to eq(true) expect(member.send_notification_email).to eq(true) @@ -44,7 +44,7 @@ feature "unsubscribe" do expect(updated_member.send_notification_email).to eq(false) end - scenario "visit unsubscribe page with a non-encrypted parameter" do + it "visit unsubscribe page with a non-encrypted parameter" do # verifying the initial subscription status of the member expect(member.send_planting_reminder).to eq(true) expect(member.send_notification_email).to eq(true) diff --git a/spec/requests/api/v1/gardens_request_spec.rb b/spec/requests/api/v1/gardens_request_spec.rb index 127513607..89bb2e8ee 100644 --- a/spec/requests/api/v1/gardens_request_spec.rb +++ b/spec/requests/api/v1/gardens_request_spec.rb @@ -38,12 +38,12 @@ RSpec.describe 'Gardens', type: :request do "related" => "#{resource_url}/photos" } } end - scenario '#index' do + it '#index' do get '/api/v1/gardens', params: {}, headers: headers expect(subject['data']).to include(garden_encoded_as_json_api) end - scenario '#show' do + it '#show' do get "/api/v1/gardens/#{garden.id}", params: {}, headers: headers expect(subject['data']).to include(garden_encoded_as_json_api) end diff --git a/spec/requests/api/v1/plantings_request_spec.rb b/spec/requests/api/v1/plantings_request_spec.rb index 9137f8b39..cfd60fcf7 100644 --- a/spec/requests/api/v1/plantings_request_spec.rb +++ b/spec/requests/api/v1/plantings_request_spec.rb @@ -71,12 +71,12 @@ RSpec.describe 'Plantings', type: :request do } end - scenario '#index' do + it '#index' do get '/api/v1/plantings', params: {}, headers: headers expect(subject['data']).to include(planting_encoded_as_json_api) end - scenario '#show' do + it '#show' do get "/api/v1/plantings/#{planting.id}", params: {}, headers: headers expect(subject['data']['relationships']).to include("garden" => garden_as_json_api) expect(subject['data']['relationships']).to include("crop" => crop_as_json_api) From 495002d8b9b44d8ce6f7145f114bbb092eab3591 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 1 Apr 2019 22:33:33 +1300 Subject: [PATCH 065/124] Change "background" to "before" --- spec/features/shared_examples/append_date.rb | 2 +- spec/features/shared_examples/crop_suggest.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/shared_examples/append_date.rb b/spec/features/shared_examples/append_date.rb index 843730ff7..85b576a75 100644 --- a/spec/features/shared_examples/append_date.rb +++ b/spec/features/shared_examples/append_date.rb @@ -2,7 +2,7 @@ shared_examples "append date" do let(:this_month) { Time.zone.today.strftime("%B") } let(:this_year) { Time.zone.today.strftime("%Y") } - background { visit path } + before { visit path } scenario "Selecting a date with datepicker" do click_link link_text diff --git a/spec/features/shared_examples/crop_suggest.rb b/spec/features/shared_examples/crop_suggest.rb index b646ba7df..dc1474d73 100644 --- a/spec/features/shared_examples/crop_suggest.rb +++ b/spec/features/shared_examples/crop_suggest.rb @@ -6,7 +6,7 @@ shared_examples "crop suggest" do |resource| let!(:tomato) { create :tomato } let!(:roma) { create :roma } - background { sync_elasticsearch [pea, pear, maize, tomato] } + before { sync_elasticsearch [pea, pear, maize, tomato] } scenario "placeholder text in crop auto suggest field" do expect(page).to have_selector("input[placeholder='e.g. lettuce']") From 6ef3b027643f3b684eb491360e19fe719eb210ce Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 1 Apr 2019 22:33:41 +1300 Subject: [PATCH 066/124] Remove commented out code --- spec/features/gardens/actions_spec.rb | 32 --------------------------- 1 file changed, 32 deletions(-) diff --git a/spec/features/gardens/actions_spec.rb b/spec/features/gardens/actions_spec.rb index 80faaf68b..1f7fe2a26 100644 --- a/spec/features/gardens/actions_spec.rb +++ b/spec/features/gardens/actions_spec.rb @@ -72,36 +72,4 @@ describe "Gardens" do end end end - - # background do - # login_as member - # visit new_garden_path - # end - - # it "has the required fields help text" do - # expect(page).to have_content "* denotes a required field" - # end - - # it "displays required and optional fields properly" do - # expect(page).to have_selector ".form-group.required", text: "Name" - # expect(page).to have_optional 'textarea#garden_description' - # expect(page).to have_optional 'input#garden_location' - # expect(page).to have_optional 'input#garden_area' - # end - - # scenario "Create new garden" do - # fill_in "Name", with: "New garden" - # click_button "Save" - # expect(page).to have_content "Garden was successfully created" - # expect(page).to have_content "New garden" - # end - - # scenario "Refuse to create new garden with negative area" do - # visit new_garden_path - # fill_in "Name", with: "Negative Garden" - # fill_in "Area", with: -5 - # click_button "Save" - # expect(page).not_to have_content "Garden was successfully created" - # expect(page).to have_content "Area must be greater than or equal to 0" - # end end From a2fd0f0ae21165b1d0d6ad4a9063eca671642c02 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Mon, 1 Apr 2019 10:15:18 +0000 Subject: [PATCH 067/124] Auto corrected by following Lint Ruby RSpecEmptyLine --- spec/features/crops/crop_photos_spec.rb | 2 ++ spec/features/home/home_spec.rb | 1 + 2 files changed, 3 insertions(+) diff --git a/spec/features/crops/crop_photos_spec.rb b/spec/features/crops/crop_photos_spec.rb index a7bfed6b3..1507a5a15 100644 --- a/spec/features/crops/crop_photos_spec.rb +++ b/spec/features/crops/crop_photos_spec.rb @@ -51,11 +51,13 @@ describe "crop detail page", js: true do context "when signed in" do before { login_as(FactoryBot.create(:member)) } + include_examples "shows photos" end context "when signed in as photos owner" do before { login_as(member) } + include_examples "shows photos" end diff --git a/spec/features/home/home_spec.rb b/spec/features/home/home_spec.rb index 219dba412..8a10c83fa 100644 --- a/spec/features/home/home_spec.rb +++ b/spec/features/home/home_spec.rb @@ -80,6 +80,7 @@ describe "home page" do context "when signed in" do before { login_as member } + include_examples 'show crops' include_examples 'show plantings' include_examples 'show harvests' From b43b8f586878f64ca7c0b9a264995e8d4e7e127a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 2 Apr 2019 07:19:42 +0000 Subject: [PATCH 068/124] Bump js-routes from 1.4.4 to 1.4.5 Bumps [js-routes](https://github.com/railsware/js-routes) from 1.4.4 to 1.4.5. - [Release notes](https://github.com/railsware/js-routes/releases) - [Changelog](https://github.com/railsware/js-routes/blob/master/CHANGELOG.md) - [Commits](https://github.com/railsware/js-routes/compare/v1.4.4...v1.4.5) Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4ca106605..d44521854 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -240,8 +240,8 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) - js-routes (1.4.4) - railties (>= 3.2) + js-routes (1.4.5) + railties (>= 4) sprockets-rails json (2.1.0) jsonapi-resources (0.9.6) From 7c6a76b41cef80eb7b8af2ee61e7b22db8f92449 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Thu, 4 Apr 2019 07:17:14 +0000 Subject: [PATCH 069/124] Bump cancancan from 2.3.0 to 3.0.0 Bumps [cancancan](https://github.com/CanCanCommunity/cancancan) from 2.3.0 to 3.0.0. - [Release notes](https://github.com/CanCanCommunity/cancancan/releases) - [Changelog](https://github.com/CanCanCommunity/cancancan/blob/develop/CHANGELOG.md) - [Commits](https://github.com/CanCanCommunity/cancancan/compare/2.3.0...3.0.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d44521854..0b875f687 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,7 +79,7 @@ GEM activesupport (>= 3.0.0) uniform_notifier (~> 1.11) byebug (11.0.1) - cancancan (2.3.0) + cancancan (3.0.0) capybara (3.16.0) addressable mini_mime (>= 0.1.3) From d8b70a927a0ab19c30b33e919f95edd9303cf9f9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Fri, 5 Apr 2019 07:19:56 +0000 Subject: [PATCH 070/124] Bump js-routes from 1.4.5 to 1.4.6 Bumps [js-routes](https://github.com/railsware/js-routes) from 1.4.5 to 1.4.6. - [Release notes](https://github.com/railsware/js-routes/releases) - [Changelog](https://github.com/railsware/js-routes/blob/master/CHANGELOG.md) - [Commits](https://github.com/railsware/js-routes/compare/v1.4.5...v1.4.6) Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0b875f687..3ec98125b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -240,7 +240,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) - js-routes (1.4.5) + js-routes (1.4.6) railties (>= 4) sprockets-rails json (2.1.0) @@ -339,7 +339,7 @@ GEM psych (3.1.0) public_suffix (3.0.3) puma (3.12.1) - rack (2.0.6) + rack (2.0.7) rack-protection (2.0.5) rack rack-test (1.1.0) From 7ca263aa643032d43c3bc738498bb4d8fc36d84b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Fri, 5 Apr 2019 09:42:52 +0000 Subject: [PATCH 071/124] Bump capybara from 3.16.0 to 3.16.1 Bumps [capybara](https://github.com/teamcapybara/capybara) from 3.16.0 to 3.16.1. - [Release notes](https://github.com/teamcapybara/capybara/releases) - [Changelog](https://github.com/teamcapybara/capybara/blob/master/History.md) - [Commits](https://github.com/teamcapybara/capybara/compare/3.16.0...3.16.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3ec98125b..886c084ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,7 +80,7 @@ GEM uniform_notifier (~> 1.11) byebug (11.0.1) cancancan (3.0.0) - capybara (3.16.0) + capybara (3.16.1) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) @@ -390,7 +390,7 @@ GEM rb-inotify (0.10.0) ffi (~> 1.0) redis (4.1.0) - regexp_parser (1.3.0) + regexp_parser (1.4.0) responders (2.4.1) actionpack (>= 4.2.0, < 6.0) railties (>= 4.2.0, < 6.0) From a48acc0253e5ece2cbb754e56456bd3a2861ec9e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Fri, 5 Apr 2019 20:19:38 +0000 Subject: [PATCH 072/124] Bump rubocop from 0.66.0 to 0.67.2 Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.66.0 to 0.67.2. - [Release notes](https://github.com/rubocop-hq/rubocop/releases) - [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.66.0...v0.67.2) Signed-off-by: dependabot[bot] --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 886c084ed..7730545f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -323,10 +323,10 @@ GEM omniauth-oauth (~> 1.1) rack orm_adapter (0.5.0) - parallel (1.14.0) + parallel (1.17.0) paranoia (2.4.1) activerecord (>= 4.0, < 5.3) - parser (2.6.2.0) + parser (2.6.2.1) ast (~> 2.4.0) pg (0.21.0) platform-api (2.2.0) @@ -415,7 +415,7 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) - rubocop (0.66.0) + rubocop (0.67.2) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.5, != 2.5.1.1) From ad90dd6dfaf402002da2a95135dc02d967d68a2e Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 14:21:04 +1200 Subject: [PATCH 073/124] Fixes wrong host name in emails --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 95f82b4c8..ad361ca47 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -80,7 +80,7 @@ Rails.application.configure do config.active_record.dump_schema_after_migration = false # Growstuff configuration - config.action_mailer.default_url_options = { host: ENV['MAIL_SENDER_HOST'] } + config.action_mailer.default_url_options = { host: ENV['HOST'] } config.action_mailer.smtp_settings = { user_name: ENV['SENDGRID_USERNAME'], From a998a8b0f6d1603ba843a0c088c86908bfada47f Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 14:50:29 +1200 Subject: [PATCH 074/124] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a0433b22b..ef1935e0e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ encourage participation from people of all backgrounds and skill levels. ## Important links -* [Issues](http://github.com/Growstuff/growstuff/issues) (features we're +* [Issues](https://github.com/orgs/Growstuff/projects/1) (features we're working on, known bugs, etc) * [IRC](https://webchat.freenode.net/) growstuff channel (general chat, brainstorming and troubleshooting) or [Gitter](https://gitter.im/Growstuff/growstuff) * [Wiki](https://github.com/Growstuff/growstuff/wiki) (general documentation, etc. Help by migrating from the [old wiki](https://web.archive.org/web/*/wiki.growstuff.org)) From ae4ad3a62a373c030749ee3e90bdfd1ef407327d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 1 Apr 2019 19:24:51 +1300 Subject: [PATCH 075/124] Change to use searchkick --- Gemfile | 15 +++++---------- Gemfile.lock | 27 ++++++++++----------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/Gemfile b/Gemfile index ea339ba7c..f9f9ba59d 100644 --- a/Gemfile +++ b/Gemfile @@ -78,17 +78,13 @@ gem 'omniauth-facebook' gem 'omniauth-flickr', '>= 0.0.15' gem 'omniauth-twitter' +# Pretty charts gem "chartkick" -# client for Elasticsearch. Elasticsearch is a flexible -# and powerful, distributed, real-time search and analytics engine. -# An example of the use in the project is fuzzy crop search. -# Project does not use semver, so we want to be in sync with the version of -# elasticsearch we use -# See https://github.com/elastic/elasticsearch-ruby#compatibility -gem "elasticsearch-api", "~> 6.0.0" -gem "elasticsearch-model", "~> 6.0.0" -gem "elasticsearch-rails", "~> 6.0.0" +# clever elastic searh +gem 'searchkick' + + gem "hashie", ">= 3.5.3" gem 'rake', '>= 10.0.0' @@ -104,7 +100,6 @@ gem 'xmlrpc' # fixes rake error - can be removed if not needed later gem 'puma' group :production, :staging do - gem 'bonsai-elasticsearch-rails' # Integration with Bonsa-Elasticsearch on heroku gem 'dalli' gem 'memcachier' gem 'newrelic_rpm' diff --git a/Gemfile.lock b/Gemfile.lock index 7730545f3..ae33aae4d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -63,9 +63,6 @@ GEM erubi (>= 1.0.0) rack (>= 0.9.0) bluecloth (2.2.0) - bonsai-elasticsearch-rails (7.0.1) - elasticsearch-model (< 8) - elasticsearch-rails (< 8) bootstrap-datepicker-rails (1.8.0.1) railties (>= 3.0) bootstrap-kaminari-views (0.0.5) @@ -142,17 +139,12 @@ GEM warden (~> 1.2.3) diff-lcs (1.3) docile (1.1.5) - elasticsearch (6.0.3) - elasticsearch-api (= 6.0.3) - elasticsearch-transport (= 6.0.3) - elasticsearch-api (6.0.3) + elasticsearch (6.2.0) + elasticsearch-api (= 6.2.0) + elasticsearch-transport (= 6.2.0) + elasticsearch-api (6.2.0) multi_json - elasticsearch-model (6.0.0) - activesupport (> 3) - elasticsearch (> 1) - hashie - elasticsearch-rails (6.0.0) - elasticsearch-transport (6.0.3) + elasticsearch-transport (6.2.0) faraday multi_json erubi (1.8.0) @@ -452,6 +444,10 @@ GEM sprockets-rails tilt scout_apm (2.4.24) + searchkick (3.1.2) + activemodel (>= 4.2) + elasticsearch (>= 5) + hashie selenium-webdriver (3.141.0) childprocess (~> 0.5) rubyzip (~> 1.2, >= 1.2.2) @@ -516,7 +512,6 @@ DEPENDENCIES active_utils better_errors bluecloth - bonsai-elasticsearch-rails bootstrap-datepicker-rails bootstrap-kaminari-views bootstrap-sass @@ -536,9 +531,6 @@ DEPENDENCIES dalli database_cleaner devise - elasticsearch-api (~> 6.0.0) - elasticsearch-model (~> 6.0.0) - elasticsearch-rails (~> 6.0.0) factory_bot_rails faker figaro @@ -588,6 +580,7 @@ DEPENDENCIES ruby-units sass-rails scout_apm + searchkick selenium-webdriver sidekiq timecop From 61e0c2eb1dd92a9a362532e8a3d8b33e2c87dad4 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 1 Apr 2019 21:17:26 +1300 Subject: [PATCH 076/124] Swap elasticssearch for searchkick --- app/controllers/crops_controller.rb | 5 +- app/models/alternate_name.rb | 5 +- app/models/crop.rb | 72 ++++++++--------------------- app/models/scientific_name.rb | 3 +- app/services/crop_search_service.rb | 30 ++++-------- app/views/crops/search.html.haml | 9 ++-- lib/tasks/search.rake | 11 ++--- 7 files changed, 45 insertions(+), 90 deletions(-) diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 5b9562077..6b567e0c9 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -42,9 +42,10 @@ class CropsController < ApplicationController def search @term = params[:term] - @matches = Crop.search(@term) - @paginated_matches = @matches.paginate(page: params[:page]) + page = params[:page] + per_page = 12 + @matches = CropSearchService.search(@term, page, per_page, current_member: current_member) respond_with @matches end diff --git a/app/models/alternate_name.rb b/app/models/alternate_name.rb index 94e404b49..43d0b9c39 100644 --- a/app/models/alternate_name.rb +++ b/app/models/alternate_name.rb @@ -1,7 +1,10 @@ class AlternateName < ApplicationRecord - after_commit { |an| an.crop.__elasticsearch__.index_document if an.crop && ENV['GROWSTUFF_ELASTICSEARCH'] == "true" } belongs_to :crop belongs_to :creator, class_name: 'Member', inverse_of: :created_alternate_names validates :name, presence: true validates :crop, presence: true + + after_commit :reindex if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + + delegate :reindex, to: :crop end diff --git a/app/models/crop.rb b/app/models/crop.rb index 9d0d4ef20..53c40f718 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -8,9 +8,9 @@ class Crop < ApplicationRecord ## ## Relationships - has_many :scientific_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy + has_many :scientific_names, dependent: :destroy accepts_nested_attributes_for :scientific_names, allow_destroy: true, reject_if: :all_blank - has_many :alternate_names, after_add: :update_index, after_remove: :update_index, dependent: :destroy + has_many :alternate_names, dependent: :destroy has_many :plantings, dependent: :destroy has_many :seeds, dependent: :destroy has_many :harvests, dependent: :destroy @@ -34,6 +34,9 @@ class Crop < ApplicationRecord scope :interesting, -> { approved.has_photos } scope :has_photos, -> { includes(:photos).where.not(photos: { id: nil }) } + # Special scope to control if it's in the search index + scope :search_import, -> { approved } + ## ## Validations # Reasons are only necessary when rejecting @@ -52,49 +55,7 @@ class Crop < ApplicationRecord #################################### # Elastic search configuration - if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - include Elasticsearch::Model - include Elasticsearch::Model::Callbacks - # In order to avoid clashing between different environments, - # use Rails.env as a part of index name (eg. development_growstuff) - index_name [Rails.env, "growstuff"].join('_') - settings index: { number_of_shards: 1 }, - analysis: { - tokenizer: { - gs_edgeNGram_tokenizer: { - type: "edgeNGram", # edgeNGram: NGram match from the start of a token - min_gram: 3, - max_gram: 10, - # token_chars: Elasticsearch will split on characters - # that don't belong to any of these classes - token_chars: %w(letter digit) - } - }, - analyzer: { - gs_edgeNGram_analyzer: { - tokenizer: "gs_edgeNGram_tokenizer", - filter: ["lowercase"] - } - } - } do - mappings dynamic: 'false' do - indexes :id, type: 'long' - indexes :name, type: 'text', analyzer: 'gs_edgeNGram_analyzer' - indexes :approval_status, type: 'text' - indexes :scientific_names do - indexes :name, - type: 'text', - analyzer: 'gs_edgeNGram_analyzer', - # Disabling field-length norm (norm). If the norm option is turned on(by default), - # higher weigh would be given for shorter fields, which in our case is irrelevant. - norms: { enabled: false } - end - indexes :alternate_names do - indexes :name, type: 'text', analyzer: 'gs_edgeNGram_analyzer' - end - end - end - end + searchkick word_start: [:name] if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" def planting_photos Photo.joins(:plantings).where("plantings.crop_id": id) @@ -108,13 +69,6 @@ class Crop < ApplicationRecord Photo.joins(:seeds).where("seeds.crop_id": id) end - # update the Elasticsearch index (only if we're using it in this - # environment) - def update_index(_name_obj) - __elasticsearch__.index_document if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - end - # End Elasticsearch section - def to_s name end @@ -218,6 +172,20 @@ class Crop < ApplicationRecord where(["lower(crops.name) = :value", { value: name.downcase }]) end + def should_index? + approved? + end + + def search_data + { + name: name, + alternate_names: alternate_names.pluck(:name), + scientific_names: scientific_names.pluck(:name), + plantings_count: plantings_count, # boost the crops that are planted the most + planters_ids: plantings.pluck(:owner_id) # boost this product for these members + } + end + private def count_uses_of_property(col_name) diff --git a/app/models/scientific_name.rb b/app/models/scientific_name.rb index 7b20d2e9e..f593d0eef 100644 --- a/app/models/scientific_name.rb +++ b/app/models/scientific_name.rb @@ -1,7 +1,8 @@ class ScientificName < ApplicationRecord - after_commit { |sn| sn.crop.__elasticsearch__.index_document if sn.crop && ENV['GROWSTUFF_ELASTICSEARCH'] == "true" } belongs_to :crop belongs_to :creator, class_name: 'Member', inverse_of: :created_scientific_names validates :name, presence: true validates :crop, presence: true + after_commit :reindex if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + delegate :reindex, to: :crop end diff --git a/app/services/crop_search_service.rb b/app/services/crop_search_service.rb index 8fce60b2d..589c22608 100644 --- a/app/services/crop_search_service.rb +++ b/app/services/crop_search_service.rb @@ -1,23 +1,13 @@ class CropSearchService # Crop.search(string) - def self.search(query) - if ENV['GROWSTUFF_ELASTICSEARCH'] == "true" - search_str = query.nil? ? "" : query.downcase - response = Crop.__elasticsearch__.search( - query: { - bool: { - filter: { - term: { "approval_status" => "approved" } - }, - must: { - query_string: { - query: "*#{search_str}*" - } - } - } - } - ) - response.records.to_a + def self.search(query, page, per_page, current_member: nil) + if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + search_params = { page: page, per_page: per_page } + search_params[:boost_by] = [:plantings_count] # boost crops that are planted more often + # prioritise crops the member has planted + search_params[:boost_where] = { planters_ids: current_member.id } if current_member + search_params[:includes] = [:scientific_names] + Crop.search(query, search_params) else # if we don't have elasticsearch, just do a basic SQL query. # also, make sure it's an actual array not an activerecord @@ -25,7 +15,6 @@ class CropSearchService # manipulate it in the same ways (eg. deleting elements without deleting # the whole record from the db) matches = Crop.approved.where("name ILIKE ?", "%#{query}%").to_a - # we want to make sure that exact matches come first, even if not # using elasticsearch (eg. in development) exact_match = Crop.approved.find_by(name: query) @@ -33,8 +22,7 @@ class CropSearchService matches.delete(exact_match) matches.unshift(exact_match) end - - matches + matches.paginate(page: page, per_page: per_page) end end end diff --git a/app/views/crops/search.html.haml b/app/views/crops/search.html.haml index 1d1879447..48698d1e6 100644 --- a/app/views/crops/search.html.haml +++ b/app/views/crops/search.html.haml @@ -26,13 +26,12 @@ - else .pagination - = will_paginate @paginated_matches + = will_paginate @matches #paginated_matches .row - - @paginated_matches.each do |c| - .col-md-2.six-across - = render partial: "thumbnail", locals: { crop: c } + - @matches.each do |c| + .col-md-2.six-across= render partial: "thumbnail", locals: { crop: c } .pagination - = will_paginate @paginated_matches + = will_paginate @matches diff --git a/lib/tasks/search.rake b/lib/tasks/search.rake index 7097e029c..0ac99404f 100644 --- a/lib/tasks/search.rake +++ b/lib/tasks/search.rake @@ -1,11 +1,6 @@ namespace :search do - desc "Create elastic search index" - task create: :environment do - puts Crop.__elasticsearch__.create_index! force: true - end - - desc 'Refresh elastic search index' - task refresh: :environment do - puts Crop.__elasticsearch__.refresh_index! + desc 'reindex' + task reindex: :environment do + puts Crop.reindex end end From 370747390a049adf42f4b0c77b7257dcbabf1f2d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 1 Apr 2019 21:41:33 +1300 Subject: [PATCH 077/124] Add default pagination to crop search service --- app/models/crop.rb | 9 ++++++--- app/services/crop_search_service.rb | 2 +- spec/models/crop_spec.rb | 25 +++++++++++++------------ spec/support/elasticsearch_helpers.rb | 16 ---------------- 4 files changed, 20 insertions(+), 32 deletions(-) delete mode 100644 spec/support/elasticsearch_helpers.rb diff --git a/app/models/crop.rb b/app/models/crop.rb index 53c40f718..f8d8e84d3 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -55,7 +55,7 @@ class Crop < ApplicationRecord #################################### # Elastic search configuration - searchkick word_start: [:name] if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + searchkick word_start: [:name], case_sensitive: false if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" def planting_photos Photo.joins(:plantings).where("plantings.crop_id": id) @@ -164,8 +164,11 @@ class Crop < ApplicationRecord update(median_days_to_last_harvest: Planting.where(crop: self).median(:days_to_last_harvest)) end - def self.search(query) - CropSearchService.search(query) + # Only add this method, if we aren't using elastic search + unless ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + def self.search(query) + CropSearchService.search(query) + end end def self.case_insensitive_name(name) diff --git a/app/services/crop_search_service.rb b/app/services/crop_search_service.rb index 589c22608..72402889d 100644 --- a/app/services/crop_search_service.rb +++ b/app/services/crop_search_service.rb @@ -1,6 +1,6 @@ class CropSearchService # Crop.search(string) - def self.search(query, page, per_page, current_member: nil) + def self.search(query, page: 1, per_page: 12, current_member: nil) if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" search_params = { page: page, per_page: per_page } search_params[:boost_by] = [:plantings_count] # boost crops that are planted more often diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 4cd9c3fc1..15010adc1 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -357,31 +357,32 @@ describe Crop do end context "search", :elasticsearch do - let(:mushroom) { FactoryBot.create(:crop, name: 'mushroom') } - - before { sync_elasticsearch([mushroom]) } - + let!(:mushroom) { FactoryBot.create(:crop, name: 'mushroom') } + before { Crop.reindex } it "finds exact matches" do - expect(Crop.search('mushroom')).to eq [mushroom] + expect(Crop.search('mushroom').map(&:name)).to eq ['mushroom'] end it "finds approximate matches" do - expect(Crop.search('mush')).to eq [mushroom] + expect(Crop.search('mush', match: :word_start).map(&:name)).to eq ['mushroom'] + end + if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + it "finds mispellings matches" do + expect(Crop.search('muhsroom').map(&:name)).to eq ['mushroom'] + end end it "doesn't find non-matches" do - Crop.search('mush').should_not include @crop + expect(Crop.search('coffee').map(&:name)).to eq [] end it "searches case insensitively" do - Crop.search('mUsH').should include mushroom + expect(Crop.search('mUsHroom').map(&:name)).to eq ['mushroom'] end it "doesn't find 'rejected' crop" do @rejected_crop = FactoryBot.create(:rejected_crop, name: 'tomato') - sync_elasticsearch([@rejected_crop]) - Crop.search('tomato').should_not include @rejected_crop + expect(Crop.search('tomato').map(&:name)).to eq [] end it "doesn't find 'pending' crop" do @crop_request = FactoryBot.create(:crop_request, name: 'tomato') - sync_elasticsearch([@crop_request]) - Crop.search('tomato').should_not include @crop_request + expect(Crop.search('tomato').map(&:name)).to eq [] end end diff --git a/spec/support/elasticsearch_helpers.rb b/spec/support/elasticsearch_helpers.rb deleted file mode 100644 index 7cd3fe5f2..000000000 --- a/spec/support/elasticsearch_helpers.rb +++ /dev/null @@ -1,16 +0,0 @@ -module ElasticsearchHelpers - def sync_elasticsearch(crops) - return unless ENV['GROWSTUFF_ELASTICSEARCH'] == "true" - - crops.each { |crop| crop.__elasticsearch__.index_document } - Crop.__elasticsearch__.refresh_index! - end -end - -RSpec.configure do |config| - config.include ElasticsearchHelpers - - config.before(:all, elasticsearch: true) do - Crop.__elasticsearch__.create_index! force: true if ENV['GROWSTUFF_ELASTICSEARCH'] == "true" - end -end From c8716b6a1a1c6ff29e4cc39afc6c7449937b1828 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 1 Apr 2019 22:31:03 +1300 Subject: [PATCH 078/124] Add oj gem, to speed up json use --- Gemfile | 3 ++- Gemfile.lock | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index f9f9ba59d..4d1cb36d2 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,8 @@ gem 'font-awesome-sass' gem 'uglifier' # JavaScript compressor +gem 'oj' # Speeds up json + # planting and harvest predictions # based on median values for the crop gem 'active_median', '0.1.4' # needs postgresql update https://github.com/Growstuff/growstuff/issues/1757 @@ -84,7 +86,6 @@ gem "chartkick" # clever elastic searh gem 'searchkick' - gem "hashie", ">= 3.5.3" gem 'rake', '>= 10.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index ae33aae4d..dbf269820 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -297,6 +297,7 @@ GEM multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) + oj (3.7.11) omniauth (1.9.0) hashie (>= 3.4.6, < 3.7.0) rack (>= 1.6.2, < 3) @@ -557,6 +558,7 @@ DEPENDENCIES loofah (>= 2.2.1) memcachier newrelic_rpm + oj omniauth (~> 1.3) omniauth-facebook omniauth-flickr (>= 0.0.15) From bd797a4d8e29b7ee4390b3128e666ff16117fc4d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 2 Apr 2019 20:50:46 +1300 Subject: [PATCH 079/124] Change call to reindex crops in specs --- spec/features/harvests/harvesting_a_crop_spec.rb | 2 +- spec/features/plantings/planting_a_crop_spec.rb | 2 +- spec/features/seeds/adding_seeds_spec.rb | 2 +- spec/features/shared_examples/crop_suggest.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index 6f69555fc..f532e9de5 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -10,7 +10,7 @@ describe "Harvesting a crop", :js, :elasticsearch do before do login_as member visit new_harvest_path - sync_elasticsearch [maize] + maize.reindex end it_behaves_like "crop suggest", "harvest", "crop" diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index e62e9f6ba..0ada46178 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -12,7 +12,7 @@ describe "Planting a crop", :js, :elasticsearch do before do login_as member visit new_planting_path - sync_elasticsearch [maize] + maize.reindex end it_behaves_like "crop suggest", "planting" diff --git a/spec/features/seeds/adding_seeds_spec.rb b/spec/features/seeds/adding_seeds_spec.rb index 0f21633c3..ea39852a8 100644 --- a/spec/features/seeds/adding_seeds_spec.rb +++ b/spec/features/seeds/adding_seeds_spec.rb @@ -8,7 +8,7 @@ describe "Seeds", :js, :elasticsearch do before do login_as member visit new_seed_path - sync_elasticsearch [maize] + maize.reindex end it_behaves_like "crop suggest", "seed", "crop" diff --git a/spec/features/shared_examples/crop_suggest.rb b/spec/features/shared_examples/crop_suggest.rb index dc1474d73..c4f253ec5 100644 --- a/spec/features/shared_examples/crop_suggest.rb +++ b/spec/features/shared_examples/crop_suggest.rb @@ -6,7 +6,7 @@ shared_examples "crop suggest" do |resource| let!(:tomato) { create :tomato } let!(:roma) { create :roma } - before { sync_elasticsearch [pea, pear, maize, tomato] } + before { [pea, pear, maize, tomato].each{|crop| crop.reindex } } scenario "placeholder text in crop auto suggest field" do expect(page).to have_selector("input[placeholder='e.g. lettuce']") From ab57451b17ecb5cdf657139b83803475917c47a3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Tue, 2 Apr 2019 20:58:33 +1300 Subject: [PATCH 080/124] only reindex our one crop --- spec/models/crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 15010adc1..9fa704202 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -358,7 +358,7 @@ describe Crop do context "search", :elasticsearch do let!(:mushroom) { FactoryBot.create(:crop, name: 'mushroom') } - before { Crop.reindex } + before { mushroom.reindex } it "finds exact matches" do expect(Crop.search('mushroom').map(&:name)).to eq ['mushroom'] end From 150d44ad6f777fc7e7e970eb94cd3097d7ddde82 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 3 Apr 2019 20:07:05 +1300 Subject: [PATCH 081/124] named arguments for search --- app/controllers/crops_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 6b567e0c9..387ae4508 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -45,7 +45,10 @@ class CropsController < ApplicationController page = params[:page] per_page = 12 - @matches = CropSearchService.search(@term, page, per_page, current_member: current_member) + @matches = CropSearchService.search( + @term, page: page, + per_page: per_page, + current_member: current_member) respond_with @matches end From e465b6f19c96b682198da5d36d262bdc160e176a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 4 Apr 2019 10:50:44 +1300 Subject: [PATCH 082/124] Elastic search spec helper --- spec/spec_helper.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9a0b542df..4f076097e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,6 +32,20 @@ RSpec.configure do |config| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end + config.before(:suite) do + # reindex models + Crop.reindex + + # and disable callbacks + Searchkick.disable_callbacks + end + + config.around(:each, search: true) do |example| + Searchkick.callbacks(true) do + example.run + end + end + # rspec-mocks config goes here. You can use an alternate test double # library (such as bogus or mocha) by changing the `mock_with` option here. config.mock_with :rspec do |mocks| From e5c0edb0d0966fedf69bf7baeba2add8bdd5f8ad Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 4 Apr 2019 10:50:56 +1300 Subject: [PATCH 083/124] Tidy up specs --- .../plantings/planting_a_crop_spec.rb | 36 ++++++++++--------- spec/features/shared_examples/crop_suggest.rb | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 0ada46178..75cdbffd1 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -32,26 +32,30 @@ describe "Planting a crop", :js, :elasticsearch do it { expect(page).to have_optional 'input#planting_finished_at' } end - it "Creating a new planting" do - fill_autocomplete "crop", with: "mai" - select_from_autocomplete "maize" - within "form#new_planting" do - fill_in "When", with: "2014-06-15" - fill_in "How many?", with: 42 - select "cutting", from: "Planted from:" - select "semi-shade", from: "Sun or shade?" - fill_in "Tell us more about it", with: "It's rad." - click_button "Save" + describe "Creating a new planting" do + before do + fill_autocomplete "crop", with: "mai" + select_from_autocomplete "maize" + within "form#new_planting" do + fill_in "When", with: "2014-06-15" + fill_in "How many?", with: 42 + select "cutting", from: "Planted from:" + select "semi-shade", from: "Sun or shade?" + fill_in "Tell us more about it", with: "It's rad." + click_button "Save" + end end - expect(page).to have_content "planting was successfully created" - expect(page).to have_content "Not enough data" + it { expect(page).to have_content "planting was successfully created" } + it { expect(page).to have_content "Not enough data" } end - it "Clicking link to owner's profile" do - visit member_plantings_path(member) - click_link "View #{member}'s profile >>" - expect(current_path).to eq member_path(member) + describe "Clicking link to owner's profile" do + before do + visit member_plantings_path(member) + click_link "View #{member}'s profile >>" + end + it { expect(current_path).to eq member_path(member) } end describe "Progress bar status on planting creation" do diff --git a/spec/features/shared_examples/crop_suggest.rb b/spec/features/shared_examples/crop_suggest.rb index c4f253ec5..3b90b3a0d 100644 --- a/spec/features/shared_examples/crop_suggest.rb +++ b/spec/features/shared_examples/crop_suggest.rb @@ -6,7 +6,7 @@ shared_examples "crop suggest" do |resource| let!(:tomato) { create :tomato } let!(:roma) { create :roma } - before { [pea, pear, maize, tomato].each{|crop| crop.reindex } } + before { [pea, pear, maize, tomato].each(&:reindex) } scenario "placeholder text in crop auto suggest field" do expect(page).to have_selector("input[placeholder='e.g. lettuce']") From 789cffeca168751f32ce255668089f698bfd1129 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 4 Apr 2019 10:51:08 +1300 Subject: [PATCH 084/124] Eager loading --- app/controllers/crops_controller.rb | 10 ++++++---- app/controllers/gardens_controller.rb | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 387ae4508..e861d6bbd 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -46,14 +46,16 @@ class CropsController < ApplicationController per_page = 12 @matches = CropSearchService.search( - @term, page: page, - per_page: per_page, - current_member: current_member) + @term, page: page, + per_page: per_page, + current_member: current_member + ) respond_with @matches end def show - @crop = Crop.includes(:scientific_names, plantings: :photos).find_by!(slug: params[:slug]) + @crop = Crop.includes(:scientific_names, plantings: :photos) + .find_by!(slug: params[:slug]) @posts = @crop.posts.order(created_at: :desc).paginate(page: params[:page]) @photos = Photo.by_crop(@crop) diff --git a/app/controllers/gardens_controller.rb b/app/controllers/gardens_controller.rb index 82ed8d2a4..5851ba722 100644 --- a/app/controllers/gardens_controller.rb +++ b/app/controllers/gardens_controller.rb @@ -13,6 +13,7 @@ class GardensController < ApplicationController @gardens = @gardens.active unless @show_all @gardens = @gardens.where(owner: @owner) if @owner.present? @gardens = @gardens.joins(:owner).order(:name).paginate(page: params[:page]) + @gardens = @gardens.includes(:owner, plantings: [:owner, crop: :parent]) respond_with(@gardens) end From f3ae1a8ec352c1edc9e67bb4593633f37081f538 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Thu, 4 Apr 2019 10:51:35 +1300 Subject: [PATCH 085/124] Fix dangerous sql warning --- app/models/garden.rb | 1 + app/views/plantings/_form.html.haml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/garden.rb b/app/models/garden.rb index cd0834852..7987c4dc2 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -19,6 +19,7 @@ class Garden < ApplicationRecord default_scope { joins(:owner) } # Ensures owner exists scope :active, -> { where(active: true) } scope :inactive, -> { where(active: false) } + scope :order_by_name, -> { order("lower(name) asc") } validates :location, length: { maximum: 255 } validates :slug, uniqueness: true diff --git a/app/views/plantings/_form.html.haml b/app/views/plantings/_form.html.haml index 874b5329b..87f7ba16a 100644 --- a/app/views/plantings/_form.html.haml +++ b/app/views/plantings/_form.html.haml @@ -25,7 +25,7 @@ = f.label :garden_id, 'Where did you plant it?', class: 'control-label col-md-2' .col-md-8 = collection_select(:planting, :garden_id, - current_member.gardens.active.order("lower(gardens.name)"), + current_member.gardens.active.order_by_name, :id, :name, selected: @planting.garden_id || @garden.id, class: 'form-control') From ca743e421df6075f9ea546c0f3bf1a534f4e709d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 7 Apr 2019 15:48:49 +1200 Subject: [PATCH 086/124] Add matching ES methods for when no elastic search configured --- app/models/crop.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index f8d8e84d3..6c330534a 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -166,8 +166,12 @@ class Crop < ApplicationRecord # Only add this method, if we aren't using elastic search unless ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - def self.search(query) - CropSearchService.search(query) + def self.search(query, *extra_params) + CropSearchService.search(query, *extra_params) + end + def self.reindex + end + def reindex end end From 77d1fc7347cf14d0734565f1b8a153052c222ce6 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 11:00:53 +1200 Subject: [PATCH 087/124] Move crop searching specs from the crop model to the crop search service --- app/controllers/crops_controller.rb | 6 +- app/models/crop.rb | 15 +---- app/services/crop_search_service.rb | 19 ++++-- spec/models/crop_spec.rb | 30 --------- spec/services/crop_search_service_spec.rb | 74 +++++++++++++++++++++++ spec/spec_helper.rb | 10 +-- 6 files changed, 100 insertions(+), 54 deletions(-) create mode 100644 spec/services/crop_search_service_spec.rb diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index e861d6bbd..324f07581 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -42,12 +42,10 @@ class CropsController < ApplicationController def search @term = params[:term] - page = params[:page] - per_page = 12 @matches = CropSearchService.search( - @term, page: page, - per_page: per_page, + @term, page: params[:page], + per_page: 12, current_member: current_member ) respond_with @matches diff --git a/app/models/crop.rb b/app/models/crop.rb index 6c330534a..c768ed700 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -55,7 +55,9 @@ class Crop < ApplicationRecord #################################### # Elastic search configuration - searchkick word_start: [:name], case_sensitive: false if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + searchkick word_start: [:name, :alternate_names, :scientific_names], case_sensitive: false + end def planting_photos Photo.joins(:plantings).where("plantings.crop_id": id) @@ -164,17 +166,6 @@ class Crop < ApplicationRecord update(median_days_to_last_harvest: Planting.where(crop: self).median(:days_to_last_harvest)) end - # Only add this method, if we aren't using elastic search - unless ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - def self.search(query, *extra_params) - CropSearchService.search(query, *extra_params) - end - def self.reindex - end - def reindex - end - end - def self.case_insensitive_name(name) where(["lower(crops.name) = :value", { value: name.downcase }]) end diff --git a/app/services/crop_search_service.rb b/app/services/crop_search_service.rb index 72402889d..28b8680d8 100644 --- a/app/services/crop_search_service.rb +++ b/app/services/crop_search_service.rb @@ -2,11 +2,17 @@ class CropSearchService # Crop.search(string) def self.search(query, page: 1, per_page: 12, current_member: nil) if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - search_params = { page: page, per_page: per_page } - search_params[:boost_by] = [:plantings_count] # boost crops that are planted more often + search_params = { + page: page, + per_page: per_page, + fields: %i(name alternate_names scientific_names), + match: :word_start + } + # search_params[:boost_by] = [:plantings_count] # boost crops that are planted more often # prioritise crops the member has planted search_params[:boost_where] = { planters_ids: current_member.id } if current_member - search_params[:includes] = [:scientific_names] + search_params[:includes] = %i(scientific_names alternate_names) + Crop.search(query, search_params) else # if we don't have elasticsearch, just do a basic SQL query. @@ -14,7 +20,12 @@ class CropSearchService # collection, so it matches what we get from elasticsearch and we can # manipulate it in the same ways (eg. deleting elements without deleting # the whole record from the db) - matches = Crop.approved.where("name ILIKE ?", "%#{query}%").to_a + matcher = "%#{query}%" + matches = Crop.approved + .left_outer_joins(:alternate_names, :scientific_names) + .where("crops.name ILIKE ? OR alternate_names.name ILIKE ? OR scientific_names.name ILIKE ?", matcher, matcher, matcher) + + matches = matches.to_a # we want to make sure that exact matches come first, even if not # using elasticsearch (eg. in development) exact_match = Crop.approved.find_by(name: query) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 9fa704202..290e02d76 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -356,36 +356,6 @@ describe Crop do expect(@maize.plant_parts).to eq [@pp1] end - context "search", :elasticsearch do - let!(:mushroom) { FactoryBot.create(:crop, name: 'mushroom') } - before { mushroom.reindex } - it "finds exact matches" do - expect(Crop.search('mushroom').map(&:name)).to eq ['mushroom'] - end - it "finds approximate matches" do - expect(Crop.search('mush', match: :word_start).map(&:name)).to eq ['mushroom'] - end - if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - it "finds mispellings matches" do - expect(Crop.search('muhsroom').map(&:name)).to eq ['mushroom'] - end - end - it "doesn't find non-matches" do - expect(Crop.search('coffee').map(&:name)).to eq [] - end - it "searches case insensitively" do - expect(Crop.search('mUsHroom').map(&:name)).to eq ['mushroom'] - end - it "doesn't find 'rejected' crop" do - @rejected_crop = FactoryBot.create(:rejected_crop, name: 'tomato') - expect(Crop.search('tomato').map(&:name)).to eq [] - end - it "doesn't find 'pending' crop" do - @crop_request = FactoryBot.create(:crop_request, name: 'tomato') - expect(Crop.search('tomato').map(&:name)).to eq [] - end - end - context "csv loading" do before do # don't use 'let' for this -- we need to actually create it, diff --git a/spec/services/crop_search_service_spec.rb b/spec/services/crop_search_service_spec.rb new file mode 100644 index 000000000..6d17152d6 --- /dev/null +++ b/spec/services/crop_search_service_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe CropSearchService, type: :service do + describe 'search', :elasticsearch do + def search(term) + CropSearchService.search(term).map(&:name) + end + + context 'with a mushroom' do + let!(:mushroom) { FactoryBot.create(:crop, name: 'mushroom') } + + before do + # Alternate name + FactoryBot.create :alternate_name, name: 'fungus', crop: mushroom + # scientific name + FactoryBot.create :scientific_name, name: 'Agaricus bisporus', crop: mushroom + + # Requested and rejected + FactoryBot.create(:rejected_crop, name: 'rejected mushroom') + FactoryBot.create(:crop_request, name: 'requested mushroom') + + # Child record + FactoryBot.create(:crop, name: 'portabello', parent: mushroom) + Crop.reindex + end + + describe 'finds exact match' do + it { expect(search('mushroom')).to eq ['mushroom'] } + end + + describe 'finds approximate match "mush"' do + it { expect(search('mush')).to eq ['mushroom'] } + end + + if ENV['GROWSTUFF_ELASTICSEARCH'] == 'true' + describe 'finds mispellings matches' do + it { expect(search('muhsroom')).to eq ['mushroom'] } + it { expect(search('mushrom')).to eq ['mushroom'] } + end + end + + describe 'doesn\'t find non-match "coffee"' do + it { expect(search('coffee')).to eq [] } + end + + describe 'searches case insensitively' do + it { expect(search('mUsHroom')).to eq ['mushroom'] } + it { expect(search('Mushroom')).to eq ['mushroom'] } + it { expect(search('MUSHROOM')).to eq ['mushroom'] } + end + + it 'searches for alternate names' do + expect(search('fungus')).to eq ['mushroom'] + end + + describe 'searches for scientific names' do + it { expect(search('Agaricus bisporus')).to eq ['mushroom'] } + it { expect(search('agaricus bisporus')).to eq ['mushroom'] } + it { expect(search('Agaricus')).to eq ['mushroom'] } + it { expect(search('bisporus')).to eq ['mushroom'] } + end + + describe 'doesn\'t find rejected crop' do + it { expect(search('rejected')).to eq [] } + end + + describe 'doesn\'t find pending crop' do + it { expect(search('requested')).to eq [] } + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4f076097e..e76b3e55e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,11 +33,13 @@ RSpec.configure do |config| end config.before(:suite) do - # reindex models - Crop.reindex + if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + # reindex models + Crop.reindex - # and disable callbacks - Searchkick.disable_callbacks + # and disable callbacks + Searchkick.disable_callbacks + end end config.around(:each, search: true) do |example| From 01a3654d4184cba444d7f7699850927686897ea3 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 11:24:18 +1200 Subject: [PATCH 088/124] Working without elastic search too --- app/services/crop_search_service.rb | 3 +- .../harvests/harvesting_a_crop_spec.rb | 61 ++++++++++--------- spec/features/shared_examples/crop_suggest.rb | 2 - spec/services/crop_search_service_spec.rb | 2 +- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/app/services/crop_search_service.rb b/app/services/crop_search_service.rb index 28b8680d8..bf4c8acf2 100644 --- a/app/services/crop_search_service.rb +++ b/app/services/crop_search_service.rb @@ -23,7 +23,8 @@ class CropSearchService matcher = "%#{query}%" matches = Crop.approved .left_outer_joins(:alternate_names, :scientific_names) - .where("crops.name ILIKE ? OR alternate_names.name ILIKE ? OR scientific_names.name ILIKE ?", matcher, matcher, matcher) + .where("crops.name ILIKE ? OR alternate_names.name ILIKE ? OR scientific_names.name ILIKE ?", + matcher, matcher, matcher) matches = matches.to_a # we want to make sure that exact matches come first, even if not diff --git a/spec/features/harvests/harvesting_a_crop_spec.rb b/spec/features/harvests/harvesting_a_crop_spec.rb index f532e9de5..171d54e0b 100644 --- a/spec/features/harvests/harvesting_a_crop_spec.rb +++ b/spec/features/harvests/harvesting_a_crop_spec.rb @@ -10,7 +10,6 @@ describe "Harvesting a crop", :js, :elasticsearch do before do login_as member visit new_harvest_path - maize.reindex end it_behaves_like "crop suggest", "harvest", "crop" @@ -19,11 +18,11 @@ describe "Harvesting a crop", :js, :elasticsearch do expect(page).to have_content "* denotes a required field" end - it "displays required and optional fields properly" do - expect(page).to have_selector ".form-group.required", text: "What did you harvest?" - expect(page).to have_optional 'input#harvest_quantity' - expect(page).to have_optional 'input#harvest_weight_quantity' - expect(page).to have_optional 'textarea#harvest_description' + describe "displays required and optional fields properly" do + it { expect(page).to have_selector ".form-group.required", text: "What did you harvest?" } + it { expect(page).to have_optional 'input#harvest_quantity' } + it { expect(page).to have_optional 'input#harvest_weight_quantity' } + it { expect(page).to have_optional 'textarea#harvest_description' } end it "Creating a new harvest", :js do @@ -62,34 +61,38 @@ describe "Harvesting a crop", :js, :elasticsearch do expect(current_path).to eq member_path member end - it "Harvesting from crop page" do - visit crop_path(maize) - within '.crop-actions' do - click_link "Harvest #{maize.name}" + describe "Harvesting from crop page" do + before do + visit crop_path(maize) + within '.crop-actions' do + click_link "Harvest #{maize.name}" + end + within "form#new_harvest" do + select plant_part.name, from: 'harvest[plant_part_id]' + expect(page).to have_selector "input[value='maize']" + click_button "Save" + end end - within "form#new_harvest" do + + it { expect(page).to have_content "harvest was successfully created." } + it { expect(page).to have_content "maize" } + end + + describe "Harvesting from planting page" do + let!(:planting) { create :planting, crop: maize, owner: member, garden: member.gardens.first } + before do + visit planting_path(planting) + within ".planting-actions" do + click_link "Harvest" + end + select plant_part.name, from: 'harvest[plant_part_id]' - expect(page).to have_selector "input[value='maize']" click_button "Save" end - expect(page).to have_content "harvest was successfully created." - expect(page).to have_content "maize" - end - - it "Harvesting from planting page" do - planting = create :planting, crop: maize, owner: member, garden: member.gardens.first - visit planting_path(planting) - within ".planting-actions" do - click_link "Harvest" - end - - select plant_part.name, from: 'harvest[plant_part_id]' - click_button "Save" - - expect(page).to have_content "harvest was successfully created." - expect(page).to have_content planting.garden.name - expect(page).to have_content "maize" + it { expect(page).to have_content "harvest was successfully created." } + it { expect(page).to have_content planting.garden.name } + it { expect(page).to have_content "maize" } end context "Editing a harvest" do diff --git a/spec/features/shared_examples/crop_suggest.rb b/spec/features/shared_examples/crop_suggest.rb index 3b90b3a0d..b7e49dbd8 100644 --- a/spec/features/shared_examples/crop_suggest.rb +++ b/spec/features/shared_examples/crop_suggest.rb @@ -6,8 +6,6 @@ shared_examples "crop suggest" do |resource| let!(:tomato) { create :tomato } let!(:roma) { create :roma } - before { [pea, pear, maize, tomato].each(&:reindex) } - scenario "placeholder text in crop auto suggest field" do expect(page).to have_selector("input[placeholder='e.g. lettuce']") end diff --git a/spec/services/crop_search_service_spec.rb b/spec/services/crop_search_service_spec.rb index 6d17152d6..0835b9e67 100644 --- a/spec/services/crop_search_service_spec.rb +++ b/spec/services/crop_search_service_spec.rb @@ -23,7 +23,7 @@ RSpec.describe CropSearchService, type: :service do # Child record FactoryBot.create(:crop, name: 'portabello', parent: mushroom) - Crop.reindex + Crop.reindex if ENV['GROWSTUFF_ELASTICSEARCH'] == 'true' end describe 'finds exact match' do From 302e19776f1e958d766c4bc7e4314af66837c9cb Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 11:25:22 +1200 Subject: [PATCH 089/124] code style fix up --- app/models/crop.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/crop.rb b/app/models/crop.rb index c768ed700..51ba8c149 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -56,7 +56,7 @@ class Crop < ApplicationRecord #################################### # Elastic search configuration if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - searchkick word_start: [:name, :alternate_names, :scientific_names], case_sensitive: false + searchkick word_start: %i(name alternate_names scientific_names), case_sensitive: false end def planting_photos From 55e89e95fee3ea9814f50e1fc4f54463a57ac32d Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 13:21:54 +1200 Subject: [PATCH 090/124] Fix a deprecation warning --- spec/factories/photos.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories/photos.rb b/spec/factories/photos.rb index 5d3ef467c..b0a64331e 100644 --- a/spec/factories/photos.rb +++ b/spec/factories/photos.rb @@ -4,7 +4,7 @@ FactoryBot.define do factory :photo do owner flickr_photo_id { 1 } - title { Faker::HarryPotter.quote } + title { Faker::Movies::HarryPotter.quote } license_name { "CC-BY" } license_url { "http://example.com/license.html" } thumbnail_url { "http://example.com/#{Faker::File.file_name}.jpg" } From 5b35e3fe95865c517516723876be50148b77b392 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 13:22:07 +1200 Subject: [PATCH 091/124] remove an unnecesary index --- spec/features/seeds/adding_seeds_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/seeds/adding_seeds_spec.rb b/spec/features/seeds/adding_seeds_spec.rb index ea39852a8..e407c3782 100644 --- a/spec/features/seeds/adding_seeds_spec.rb +++ b/spec/features/seeds/adding_seeds_spec.rb @@ -8,7 +8,6 @@ describe "Seeds", :js, :elasticsearch do before do login_as member visit new_seed_path - maize.reindex end it_behaves_like "crop suggest", "seed", "crop" From 74e6a7cf2fde8ff566a4b4991d5cb9addf0c3631 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 14:15:30 +1200 Subject: [PATCH 092/124] Rename @matches to @crops --- app/controllers/crops_controller.rb | 4 ++-- app/views/crops/search.html.haml | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 324f07581..c4e2fcdfb 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -43,12 +43,12 @@ class CropsController < ApplicationController def search @term = params[:term] - @matches = CropSearchService.search( + @crops = CropSearchService.search( @term, page: params[:page], per_page: 12, current_member: current_member ) - respond_with @matches + respond_with @crops end def show diff --git a/app/views/crops/search.html.haml b/app/views/crops/search.html.haml index 48698d1e6..468339bc8 100644 --- a/app/views/crops/search.html.haml +++ b/app/views/crops/search.html.haml @@ -1,7 +1,7 @@ - if @term - content_for :title, "Crops matching \"#{@term}\"" - - if @matches - - content_for :subtitle, "#{@matches.size} total" + - if @crops + - content_for :subtitle, "#{@crops.size} total" - else - content_for :title, "Crop search" @@ -15,7 +15,7 @@ value: @term = submit_tag "Search", class: 'btn btn-primary' -- if @matches.empty? +- if @crops.empty? %h2 No results found %p Sorry, we couldn't find any crops that matched your search for "#{@term}". @@ -26,12 +26,12 @@ - else .pagination - = will_paginate @matches + = will_paginate @crops #paginated_matches .row - - @matches.each do |c| + - @crops.each do |c| .col-md-2.six-across= render partial: "thumbnail", locals: { crop: c } .pagination - = will_paginate @matches + = will_paginate @crops From e165c77d64d88607155ddc4e5bdb503bf46d119c Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 21:38:26 +1200 Subject: [PATCH 093/124] Force autocomplete to json format --- app/helpers/auto_suggest_helper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/helpers/auto_suggest_helper.rb b/app/helpers/auto_suggest_helper.rb index 6d4637d4e..1f9030fd8 100644 --- a/app/helpers/auto_suggest_helper.rb +++ b/app/helpers/auto_suggest_helper.rb @@ -10,8 +10,7 @@ module AutoSuggestHelper end resource = resource.class.name.downcase - source_path = Rails.application.routes.url_helpers.send("search_#{source}s_path") - + source_path = Rails.application.routes.url_helpers.send("search_#{source}s_path", format: :json) %( Date: Mon, 8 Apr 2019 21:59:26 +1200 Subject: [PATCH 094/124] Style/lint tidy up models --- app/models/garden.rb | 1 - app/models/harvest.rb | 4 ++-- app/models/planting.rb | 4 ++-- app/models/seed.rb | 16 ++++++++-------- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/models/garden.rb b/app/models/garden.rb index 7987c4dc2..fcbb32ea6 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -46,7 +46,6 @@ class Garden < ApplicationRecord }.freeze validates :area_unit, inclusion: { in: AREA_UNITS_VALUES.values, message: "%s is not a valid area unit" }, - allow_nil: true, allow_blank: true after_validation :cleanup_area diff --git a/app/models/harvest.rb b/app/models/harvest.rb index 94b71d7b4..c3ea95b66 100644 --- a/app/models/harvest.rb +++ b/app/models/harvest.rb @@ -57,11 +57,11 @@ class Harvest < ApplicationRecord validates :quantity, allow_nil: true, numericality: { only_integer: false, greater_than_or_equal_to: 0 } - validates :unit, allow_nil: true, allow_blank: true, inclusion: { + validates :unit, allow_blank: true, inclusion: { in: UNITS_VALUES.values, message: "%s is not a valid unit" } validates :weight_quantity, allow_nil: true, numericality: { only_integer: false } - validates :weight_unit, allow_nil: true, allow_blank: true, inclusion: { + validates :weight_unit, allow_blank: true, inclusion: { in: WEIGHT_UNITS_VALUES.values, message: "%s is not a valid unit" } validate :crop_must_match_planting diff --git a/app/models/planting.rb b/app/models/planting.rb index 08a78fdd8..9c4a59be5 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -56,10 +56,10 @@ class Planting < ApplicationRecord validates :quantity, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } - validates :sunniness, allow_nil: true, allow_blank: true, inclusion: { + validates :sunniness, allow_blank: true, inclusion: { in: SUNNINESS_VALUES, message: "%s is not a valid sunniness value" } - validates :planted_from, allow_nil: true, allow_blank: true, inclusion: { + validates :planted_from, allow_blank: true, inclusion: { in: PLANTED_FROM_VALUES, message: "%s is not a valid planting method" } diff --git a/app/models/seed.rb b/app/models/seed.rb index 253718039..7c49c9201 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -29,17 +29,17 @@ class Seed < ApplicationRecord numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :days_until_maturity_max, allow_nil: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } - validates :tradable_to, allow_nil: false, allow_blank: false, - inclusion: { in: TRADABLE_TO_VALUES, message: "You may only trade seed nowhere, "\ + validates :tradable_to, allow_blank: false, + inclusion: { in: TRADABLE_TO_VALUES, message: "You may only trade seed nowhere, "\ "locally, nationally, or internationally" } - validates :organic, allow_nil: false, allow_blank: false, - inclusion: { in: ORGANIC_VALUES, message: "You must say whether the seeds "\ + validates :organic, allow_blank: false, + inclusion: { in: ORGANIC_VALUES, message: "You must say whether the seeds "\ "are organic or not, or that you don't know" } - validates :gmo, allow_nil: false, allow_blank: false, - inclusion: { in: GMO_VALUES, message: "You must say whether the seeds are "\ + validates :gmo, allow_blank: false, + inclusion: { in: GMO_VALUES, message: "You must say whether the seeds are "\ "genetically modified or not, or that you don't know" } - validates :heirloom, allow_nil: false, allow_blank: false, - inclusion: { in: HEIRLOOM_VALUES, message: "You must say whether the seeds"\ + validates :heirloom, allow_blank: false, + inclusion: { in: HEIRLOOM_VALUES, message: "You must say whether the seeds"\ "are heirloom, hybrid, or unknown" } # From bd1a1c53f4e4a93d23d4be39212961e3a690aa70 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Mon, 8 Apr 2019 21:59:44 +1200 Subject: [PATCH 095/124] Removed unneeded rubocop disable --- app/helpers/application_helper.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 70503cfb9..b86731d7e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -29,9 +29,7 @@ module ApplicationHelper def required_field_help_text asterisk = content_tag :span, '*', class: ['red'] text = content_tag :em, 'denotes a required field' - # rubocop:disable Rails/OutputSafety content_tag :div, asterisk + ' '.html_safe + text, class: ['margin-bottom'] - # rubocop:enable Rails/OutputSafety end # From 7ac410c4999b17d0893bfe94278c8192010a10b5 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 10 Apr 2019 20:02:05 +1200 Subject: [PATCH 096/124] varieties info on crops#show (#1848) * Tests for crop.photos * More info on a crop's varieties, and parent * Update spec for new crop varieties display * Add varieties div wrapper, so test can find the area of the page --- app/views/crops/_thumbnail.html.haml | 8 +- app/views/crops/_varieties.html.haml | 25 +---- app/views/crops/show.html.haml | 12 ++- spec/features/crops/crop_detail_page_spec.rb | 73 +-------------- spec/models/crop_spec.rb | 97 ++++++++++---------- spec/models/photo_spec.rb | 12 +-- 6 files changed, 76 insertions(+), 151 deletions(-) diff --git a/app/views/crops/_thumbnail.html.haml b/app/views/crops/_thumbnail.html.haml index 77793ef22..c9dfe207e 100644 --- a/app/views/crops/_thumbnail.html.haml +++ b/app/views/crops/_thumbnail.html.haml @@ -11,6 +11,8 @@ - unless crop.scientific_names.empty? .scientificname = crop.scientific_names.first.name - .plantingcount - Planted - = pluralize(crop.plantings.size, "time") + - if crop.annual? && crop.median_lifespan.present? + .planting-lifespan + lifespan + %strong= crop.median_lifespan + days diff --git a/app/views/crops/_varieties.html.haml b/app/views/crops/_varieties.html.haml index 5cdc453ed..2b3407388 100644 --- a/app/views/crops/_varieties.html.haml +++ b/app/views/crops/_varieties.html.haml @@ -1,20 +1,5 @@ -.varieties - - if crop.parent - %p - = crop.name - is a variety of - = succeed "." do - = link_to crop.parent, crop.parent - - - unless crop.varieties.empty? - %p - Varieties of #{crop.name}: - - - max = 5 - = render partial: 'hierarchy', locals: { display_crops: [crop], max: max } - - if max != 0 && @count > max - = button_tag "Show all #{@count - 1} varieties", class: 'btn btn-link toggle crop-hierarchy' - = button_tag "Show less varieties", class: 'btn btn-link toggle crop-hierarchy hide' - - - if !crop.parent && crop.varieties.empty? - %p None known. +- if crop.varieties.size.positive? + %h3 Varieties + .row + - crop.varieties.order(:name).each do |v| + .col-md-2.six-across= render 'crops/thumbnail', crop: v \ No newline at end of file diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index 2b58de0bf..42ba16869 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -36,7 +36,7 @@ %h2 Photos %p= render 'crops/photos', photos: @photos %p= link_to 'more photos', crop_photos_path(@crop) - + .row .col-md-3 %h3 Sunniness @@ -48,6 +48,7 @@ %h3 Harvested for = pie_chart crop_harvested_for_path(@crop, format: :json), legend: "bottom" + .varieties= render 'varieties', crop: @crop %h3 Crop Map %p @@ -90,8 +91,13 @@ = render 'scientific_names', crop: @crop = render 'alternate_names', crop: @crop - %h4 #{@crop.name.capitalize} varieties - = render 'varieties', crop: @crop + - if @crop.parent + .parent-crop + = @crop.name + is a variety of + = succeed "." do + = link_to @crop.parent, @crop.parent + = render 'crops/thumbnail', crop: @crop.parent = render 'plantings', crop: @crop = render 'harvests', crop: @crop diff --git a/spec/features/crops/crop_detail_page_spec.rb b/spec/features/crops/crop_detail_page_spec.rb index fb0297854..bbf53b0a0 100644 --- a/spec/features/crops/crop_detail_page_spec.rb +++ b/spec/features/crops/crop_detail_page_spec.rb @@ -18,78 +18,7 @@ describe "crop detail page", js: true do visit crop_path(crop) within ".varieties" do - expect(page).to have_no_selector('li', text: /tomato/i) - expect(page).to have_no_selector('button', text: /Show+/i) - end - end - - it "The crop has one variety" do - create :crop, name: 'Roma tomato 1', parent: crop - - subject - - within ".varieties" do - # It lists all 2 items (note: including the top level item.) - expect(page).to have_selector('li', text: /tomato/i, count: 2) - # It DOES NOT have "Show all/less" toggle link - expect(page).to have_no_selector('button', text: /Show+/i) - end - end - - context "many" do - let!(:roma1) { create :crop, name: 'Roma tomato 1', parent: crop } - let!(:roma2) { create :crop, name: 'Roma tomato 2', parent: crop } - let!(:roma3) { create :crop, name: 'Roma tomato 3', parent: crop } - let!(:roma4) { create :crop, name: 'Roma tomato 4', parent: crop } - - it "The crop has 4 varieties" do - subject - - within ".varieties" do - # It lists all 5 items (note: including the top level item.) - expect(page).to have_selector('li', text: /tomato/i, count: 5) - # It DOES NOT have "Show all/less" toggle link - expect(page).to have_no_selector('button', text: /Show+/i) - end - end - - it "The crop has 5 varieties, including grandchild", js: true do - create :crop, name: 'Roma tomato child 1', parent: roma4 - - subject - - within ".varieties" do - # It lists the first 5 items (note: including the top level item.) - # It HAS have "Show all" toggle link but not "Show less" link - expect(page).to have_selector('li', text: /tomato/i, count: 5) - expect(page).to have_selector('li', text: 'Roma tomato 4') - expect(page).to have_no_selector('li', text: 'Roma tomato child 1') - # It shows the total number (5) correctly - expect(page).to have_selector('button', text: /Show all 5 +/i) - expect(page).to have_no_selector('button', text: /Show less+/i) - - # Clik "Show all" link - page.find('button', text: /Show all+/).click - - # It lists all 6 items (note: including the top level item.) - # It HAS have "Show less" toggle link but not "Show all" link - expect(page).to have_selector('li', text: /tomato/i, count: 6) - expect(page).to have_selector('li', text: 'Roma tomato 4') - expect(page).to have_selector('li', text: 'Roma tomato child 1') - expect(page).to have_no_selector('button', text: /Show all+/i) - expect(page).to have_selector('button', text: /Show less+/i) - - # Clik "Show less" link - page.find('button', text: /Show less+/).click - - # It lists 5 items (note: including the top level item.) - # It HAS have "Show all" toggle link but not "Show less" link - expect(page).to have_selector('li', text: /tomato/i, count: 5) - expect(page).to have_selector('li', text: 'Roma tomato 4') - expect(page).to have_no_selector('li', text: 'Roma tomato child 1') - expect(page).to have_selector('button', text: /Show all 5 +/i) - expect(page).to have_no_selector('button', text: /Show less+/i) - end + expect(page).not_to have_text 'tomato' end end end diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 4cd9c3fc1..fa5f746ce 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -1,25 +1,21 @@ require 'rails_helper' describe Crop do - let(:pp2) { FactoryBot.create(:plant_part) } - let(:pp1) { FactoryBot.create(:plant_part) } - let(:maize) { FactoryBot.create(:maize) } - context 'all fields present' do let(:crop) { FactoryBot.create(:tomato) } - it 'saves a basic crop' do + it 'should save a basic crop' do crop.save.should be(true) end - it 'is fetchable from the database' do + it 'should be fetchable from the database' do crop.save @crop2 = Crop.find_by(name: 'tomato') @crop2.en_wikipedia_url.should eq("http://en.wikipedia.org/wiki/Tomato") @crop2.slug.should eq("tomato") end - it 'stringifies as the system name' do + it 'should stringify as the system name' do crop.save crop.to_s.should eq('tomato') end @@ -31,7 +27,7 @@ describe Crop do end context 'invalid data' do - it 'does not save a crop without a system name' do + it 'should not save a crop without a system name' do crop = FactoryBot.build(:crop, name: nil) expect { crop.save }.to raise_error ActiveRecord::StatementInvalid end @@ -143,57 +139,61 @@ describe Crop do end context 'photos' do - before do - @crop = FactoryBot.create(:tomato) + shared_examples 'has default photo' do + it { expect(Crop.has_photos).to include(crop) } end + let!(:crop) { FactoryBot.create :tomato } + let(:member) { FactoryBot.create :member } context 'with a planting photo' do - before do - @planting = FactoryBot.create(:planting, crop: @crop) - @photo = FactoryBot.create(:photo, owner: @planting.owner) - @planting.photos << @photo - end + let!(:photo) { FactoryBot.create(:photo, owner: planting.owner) } + let!(:planting) { FactoryBot.create(:planting, crop: crop) } - it 'has a default photo' do - @crop.default_photo.should be_an_instance_of Photo - expect(@crop.default_photo.id).to eq @photo.id - end - - it 'is found in has_photos scope' do - Crop.has_photos.should include(@crop) - end + before { planting.photos << photo } + it { expect(crop.default_photo).to eq photo } + include_examples 'has default photo' end context 'with a harvest photo' do - before do - @harvest = FactoryBot.create(:harvest, crop: @crop) - @photo = FactoryBot.create(:photo, owner: @harvest.owner) - @harvest.photos << @photo - end - - it 'has a default photo' do - @crop.default_photo.should be_an_instance_of Photo - expect(@crop.default_photo.id).to eq @photo.id - end + let!(:harvest) { FactoryBot.create(:harvest, crop: crop) } + let!(:photo) { FactoryBot.create(:photo, owner: harvest.owner) } + before { harvest.photos << photo } + it { expect(crop.default_photo).to eq photo } + include_examples 'has default photo' context 'and planting photo' do - before do - @planting = FactoryBot.create(:planting, crop: @crop) - @planting_photo = FactoryBot.create(:photo, owner: @planting.owner) - @planting.photos << @planting_photo - end + let(:planting) { FactoryBot.create(:planting, crop: crop) } + let!(:planting_photo) { FactoryBot.create(:photo, owner: planting.owner) } + before { planting.photos << planting_photo } - it 'prefers the planting photo' do - expect(@crop.default_photo.id).to eq @planting_photo.id + it 'should prefer the planting photo' do + expect(crop.default_photo.id).to eq planting_photo.id end end end context 'with no plantings or harvests' do it 'has no default photo' do - expect(@crop.default_photo).to eq nil + expect(crop.default_photo).to eq nil end end + + describe 'finding all photos' do + let(:planting) { FactoryBot.create :planting, crop: crop } + let(:harvest) { FactoryBot.create :harvest, crop: crop } + let(:seed) { FactoryBot.create :seed, crop: crop } + before do + # Add photos to all + planting.photos << FactoryBot.create(:photo, owner: planting.owner) + harvest.photos << FactoryBot.create(:photo, owner: harvest.owner) + seed.photos << FactoryBot.create(:photo, owner: seed.owner) + end + + it { expect(crop.photos.size).to eq 3 } + it { expect(crop.planting_photos.size).to eq 1 } + it { expect(crop.harvest_photos.size).to eq 1 } + it { expect(crop.seed_photos.size).to eq 1 } + end end context 'sunniness' do @@ -292,7 +292,6 @@ describe Crop do let(:crop2_planting) { crop2.plantings.first } let(:member) { FactoryBot.create :member, login_name: 'pikachu' } - describe 'lists interesting crops' do before do # they need 3+ plantings each to be interesting @@ -337,6 +336,10 @@ describe Crop do end end + let(:maize) { FactoryBot.create(:maize) } + let(:pp1) { FactoryBot.create(:plant_part) } + let(:pp2) { FactoryBot.create(:plant_part) } + context "harvests" do let(:h1) { FactoryBot.create(:harvest, crop: maize, plant_part: pp1) } let(:h2) { FactoryBot.create(:harvest, crop: maize, plant_part: pp2) } @@ -386,7 +389,7 @@ describe Crop do end context "csv loading" do - before do + before(:each) do # don't use 'let' for this -- we need to actually create it, # regardless of whether it's used. @cropbot = FactoryBot.create(:cropbot) @@ -553,11 +556,11 @@ describe Crop do tomato.destroy end - it "deletes the association between post and the crop(tomato)" do + it "should delete the association between post and the crop(tomato)" do expect(Post.find(post.id).crops).to eq [maize] end - it "does not delete the posts" do + it "should not delete the posts" do expect(Post.find(post.id)).not_to eq nil end end @@ -577,11 +580,11 @@ describe Crop do end describe "rejecting a crop" do - it "gives reason if a default option" do + it "should give reason if a default option" do expect(rejected_reason.rejection_explanation).to eq "not edible" end - it "shows rejection notes if reason was other" do + it "should show rejection notes if reason was other" do expect(rejected_other.rejection_explanation).to eq "blah blah blah" end end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index d71a6cd1c..b78718f5c 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -146,12 +146,12 @@ describe Photo do seed.photos << seed_photo end - it { expect(Photo.by_model(Harvest)).to eq([harvest_photo]) } - it { expect(Photo.by_model(Planting)).to eq([planting_photo]) } - it { expect(Photo.by_model(Seed)).to eq([seed_photo]) } + it { expect(Photo.by_model(Harvest)).to eq([ harvest_photo ]) } + it { expect(Photo.by_model(Planting)).to eq([ planting_photo ]) } + it { expect(Photo.by_model(Seed)).to eq([ seed_photo ]) } - it { expect(Photo.by_crop(harvest_crop)).to eq([harvest_photo]) } - it { expect(Photo.by_crop(planting_crop)).to eq([planting_photo]) } - it { expect(Photo.by_crop(seed_crop)).to eq([seed_photo]) } + it { expect(Photo.by_crop(harvest_crop)).to eq([ harvest_photo ]) } + it { expect(Photo.by_crop(planting_crop)).to eq([ planting_photo ]) } + it { expect(Photo.by_crop(seed_crop)).to eq([ seed_photo ]) } end end From 526450f0eb78213ebc4a71d379fe2650929434ae Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 09:35:41 +1200 Subject: [PATCH 097/124] Added search controller specs --- spec/controllers/crops_controller_spec.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index d9dce9b9e..e484e8a1a 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -40,10 +40,21 @@ describe CropsController do describe "GET crop search" do describe 'fetches the crop search page' do - before { get :search } + let!(:tomato) { FactoryBot.create :tomato } + let!(:maize) { FactoryBot.create :maize } + before { Crop.reindex if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" } + describe 'search form page' do + before { get :search } - it { is_expected.to be_success } - it { is_expected.to render_template("crops/search") } + it { is_expected.to be_success } + it { is_expected.to render_template("crops/search") } + end + + describe 'perform a search' do + before { get :search, params: { term: 'tom' } } + it { expect(assigns(:term)).to eq 'tom'} + it { expect(assigns(:crops).map(&:name)).to eq ['tomato']} + end end end From 3ecb81300ac980cf05f7e9b4702f65e19b7f0f21 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 09:36:07 +1200 Subject: [PATCH 098/124] Re-index before we use autocomplete so elastic search is in sync --- spec/support/feature_helpers.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index f11a3a957..c6b37007c 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -1,5 +1,7 @@ module FeatureHelpers def fill_autocomplete(field, options = {}) + Crop.reindex if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" + fill_in field, with: options[:with] page.execute_script " $('##{field}').trigger('focus'); " From fa1913c8b65f5f13b2b8f1bb8541439d6c14ae38 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 09:50:36 +1200 Subject: [PATCH 099/124] Split a method to reduce the complexity --- app/services/crop_search_service.rb | 72 ++++++++++++++++------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/app/services/crop_search_service.rb b/app/services/crop_search_service.rb index bf4c8acf2..543481909 100644 --- a/app/services/crop_search_service.rb +++ b/app/services/crop_search_service.rb @@ -2,39 +2,47 @@ class CropSearchService # Crop.search(string) def self.search(query, page: 1, per_page: 12, current_member: nil) if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - search_params = { - page: page, - per_page: per_page, - fields: %i(name alternate_names scientific_names), - match: :word_start - } - # search_params[:boost_by] = [:plantings_count] # boost crops that are planted more often - # prioritise crops the member has planted - search_params[:boost_where] = { planters_ids: current_member.id } if current_member - search_params[:includes] = %i(scientific_names alternate_names) - - Crop.search(query, search_params) + elasticsearch(query, page: page, per_page: per_page, current_member: current_member) else - # if we don't have elasticsearch, just do a basic SQL query. - # also, make sure it's an actual array not an activerecord - # collection, so it matches what we get from elasticsearch and we can - # manipulate it in the same ways (eg. deleting elements without deleting - # the whole record from the db) - matcher = "%#{query}%" - matches = Crop.approved - .left_outer_joins(:alternate_names, :scientific_names) - .where("crops.name ILIKE ? OR alternate_names.name ILIKE ? OR scientific_names.name ILIKE ?", - matcher, matcher, matcher) - - matches = matches.to_a - # we want to make sure that exact matches come first, even if not - # using elasticsearch (eg. in development) - exact_match = Crop.approved.find_by(name: query) - if exact_match - matches.delete(exact_match) - matches.unshift(exact_match) - end - matches.paginate(page: page, per_page: per_page) + dbsearch(query, page: page, per_page: per_page, current_member: current_member) end end + + def self.elasticsearch(query, page: 1, per_page: 12, current_member: nil) + search_params = { + page: page, + per_page: per_page, + fields: %i(name alternate_names scientific_names), + match: :word_start + } + # search_params[:boost_by] = [:plantings_count] # boost crops that are planted more often + # prioritise crops the member has planted + search_params[:boost_where] = { planters_ids: current_member.id } if current_member + search_params[:includes] = %i(scientific_names alternate_names) + + Crop.search(query, search_params) + end + + def self.dbsearch(query, page: 1, per_page: 12, current_member: nil) + # if we don't have elasticsearch, just do a basic SQL query. + # also, make sure it's an actual array not an activerecord + # collection, so it matches what we get from elasticsearch and we can + # manipulate it in the same ways (eg. deleting elements without deleting + # the whole record from the db) + matcher = "%#{query}%" + matches = Crop.approved + .left_outer_joins(:alternate_names, :scientific_names) + .where("crops.name ILIKE ? OR alternate_names.name ILIKE ? OR scientific_names.name ILIKE ?", + matcher, matcher, matcher) + + matches = matches.to_a + # we want to make sure that exact matches come first, even if not + # using elasticsearch (eg. in development) + exact_match = Crop.approved.find_by(name: query) + if exact_match + matches.delete(exact_match) + matches.unshift(exact_match) + end + matches.paginate(page: page, per_page: per_page) + end end From 026efe5d15d582072189fc5ef28b7f7877652e70 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 09:50:49 +1200 Subject: [PATCH 100/124] Rubocop lint --- spec/controllers/crops_controller_spec.rb | 4 ++-- spec/models/photo_spec.rb | 12 ++++++------ spec/support/feature_helpers.rb | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index e484e8a1a..d4271ed5b 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -52,8 +52,8 @@ describe CropsController do describe 'perform a search' do before { get :search, params: { term: 'tom' } } - it { expect(assigns(:term)).to eq 'tom'} - it { expect(assigns(:crops).map(&:name)).to eq ['tomato']} + it { expect(assigns(:term)).to eq 'tom' } + it { expect(assigns(:crops).map(&:name)).to eq ['tomato'] } end end end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index b78718f5c..d71a6cd1c 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -146,12 +146,12 @@ describe Photo do seed.photos << seed_photo end - it { expect(Photo.by_model(Harvest)).to eq([ harvest_photo ]) } - it { expect(Photo.by_model(Planting)).to eq([ planting_photo ]) } - it { expect(Photo.by_model(Seed)).to eq([ seed_photo ]) } + it { expect(Photo.by_model(Harvest)).to eq([harvest_photo]) } + it { expect(Photo.by_model(Planting)).to eq([planting_photo]) } + it { expect(Photo.by_model(Seed)).to eq([seed_photo]) } - it { expect(Photo.by_crop(harvest_crop)).to eq([ harvest_photo ]) } - it { expect(Photo.by_crop(planting_crop)).to eq([ planting_photo ]) } - it { expect(Photo.by_crop(seed_crop)).to eq([ seed_photo ]) } + it { expect(Photo.by_crop(harvest_crop)).to eq([harvest_photo]) } + it { expect(Photo.by_crop(planting_crop)).to eq([planting_photo]) } + it { expect(Photo.by_crop(seed_crop)).to eq([seed_photo]) } end end diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index c6b37007c..836ff35eb 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -1,7 +1,7 @@ module FeatureHelpers def fill_autocomplete(field, options = {}) Crop.reindex if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" - + fill_in field, with: options[:with] page.execute_script " $('##{field}').trigger('focus'); " From 347d7519353b05c71afaf107dc36bb272c0541b5 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 10:03:18 +1200 Subject: [PATCH 101/124] More plurals and misspellings in search specs --- app/services/crop_search_service.rb | 9 +++++---- spec/services/crop_search_service_spec.rb | 22 ++++++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/services/crop_search_service.rb b/app/services/crop_search_service.rb index 543481909..705c259f2 100644 --- a/app/services/crop_search_service.rb +++ b/app/services/crop_search_service.rb @@ -12,13 +12,14 @@ class CropSearchService search_params = { page: page, per_page: per_page, - fields: %i(name alternate_names scientific_names), - match: :word_start + fields: %i(name^5 alternate_names scientific_names), + match: :word_start, + boost_by: [:plantings_count], + includes: %i(scientific_names alternate_names), + misspellings: { edit_distance: 2 } } - # search_params[:boost_by] = [:plantings_count] # boost crops that are planted more often # prioritise crops the member has planted search_params[:boost_where] = { planters_ids: current_member.id } if current_member - search_params[:includes] = %i(scientific_names alternate_names) Crop.search(query, search_params) end diff --git a/spec/services/crop_search_service_spec.rb b/spec/services/crop_search_service_spec.rb index 0835b9e67..811e51603 100644 --- a/spec/services/crop_search_service_spec.rb +++ b/spec/services/crop_search_service_spec.rb @@ -8,9 +8,12 @@ RSpec.describe CropSearchService, type: :service do CropSearchService.search(term).map(&:name) end - context 'with a mushroom' do + context 'with some crops' do let!(:mushroom) { FactoryBot.create(:crop, name: 'mushroom') } - + let!(:tomato) { FactoryBot.create(:crop ,name: 'tomato') } + let!(:taewa) { FactoryBot.create(:crop, name: 'taewa') } + let!(:zucchini) { FactoryBot.create(:crop, name: 'zucchini') } + let!(:broccoli) { FactoryBot.create(:crop, name: 'broccoli') } before do # Alternate name FactoryBot.create :alternate_name, name: 'fungus', crop: mushroom @@ -38,6 +41,8 @@ RSpec.describe CropSearchService, type: :service do describe 'finds mispellings matches' do it { expect(search('muhsroom')).to eq ['mushroom'] } it { expect(search('mushrom')).to eq ['mushroom'] } + it { expect(search('zuchini')).to eq ['zucchini'] } + it { expect(search('brocoli')).to eq ['broccoli'] } end end @@ -45,28 +50,33 @@ RSpec.describe CropSearchService, type: :service do it { expect(search('coffee')).to eq [] } end + describe 'finds plurals' do + it { expect(search('mushrooms')).to eq ['mushroom'] } + it { expect(search('tomatoes')).to eq ['tomato'] } + end + describe 'searches case insensitively' do it { expect(search('mUsHroom')).to eq ['mushroom'] } it { expect(search('Mushroom')).to eq ['mushroom'] } it { expect(search('MUSHROOM')).to eq ['mushroom'] } end - it 'searches for alternate names' do + it 'finds by alternate names' do expect(search('fungus')).to eq ['mushroom'] end - describe 'searches for scientific names' do + describe 'finds by scientific names' do it { expect(search('Agaricus bisporus')).to eq ['mushroom'] } it { expect(search('agaricus bisporus')).to eq ['mushroom'] } it { expect(search('Agaricus')).to eq ['mushroom'] } it { expect(search('bisporus')).to eq ['mushroom'] } end - describe 'doesn\'t find rejected crop' do + describe "doesn't find rejected crop" do it { expect(search('rejected')).to eq [] } end - describe 'doesn\'t find pending crop' do + describe "doesn't find pending crop" do it { expect(search('requested')).to eq [] } end end From 0a0cd24e2ad0bd7b8bac00a05b7906d901e25200 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 10:06:44 +1200 Subject: [PATCH 102/124] Removed extra reindex --- spec/features/plantings/planting_a_crop_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 75cdbffd1..f5df9f4b7 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -12,7 +12,6 @@ describe "Planting a crop", :js, :elasticsearch do before do login_as member visit new_planting_path - maize.reindex end it_behaves_like "crop suggest", "planting" From 174f54cb75d5f2140db99c1f1239de89b8dc9e10 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 10:13:36 +1200 Subject: [PATCH 103/124] Linting --- app/services/crop_search_service.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/services/crop_search_service.rb b/app/services/crop_search_service.rb index 705c259f2..3a7560a6d 100644 --- a/app/services/crop_search_service.rb +++ b/app/services/crop_search_service.rb @@ -10,12 +10,12 @@ class CropSearchService def self.elasticsearch(query, page: 1, per_page: 12, current_member: nil) search_params = { - page: page, - per_page: per_page, - fields: %i(name^5 alternate_names scientific_names), - match: :word_start, - boost_by: [:plantings_count], - includes: %i(scientific_names alternate_names), + page: page, + per_page: per_page, + fields: %i(name^5 alternate_names scientific_names), + match: :word_start, + boost_by: [:plantings_count], + includes: %i(scientific_names alternate_names), misspellings: { edit_distance: 2 } } # prioritise crops the member has planted From e34a2d609bd2cbca664f437806d87449f09a6db7 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 10:17:21 +1200 Subject: [PATCH 104/124] Plurals spec only when we have elastic search --- spec/services/crop_search_service_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/services/crop_search_service_spec.rb b/spec/services/crop_search_service_spec.rb index 811e51603..249932e19 100644 --- a/spec/services/crop_search_service_spec.rb +++ b/spec/services/crop_search_service_spec.rb @@ -50,9 +50,11 @@ RSpec.describe CropSearchService, type: :service do it { expect(search('coffee')).to eq [] } end - describe 'finds plurals' do - it { expect(search('mushrooms')).to eq ['mushroom'] } - it { expect(search('tomatoes')).to eq ['tomato'] } + if ENV['GROWSTUFF_ELASTICSEARCH'] == 'true' + describe 'finds plurals' do + it { expect(search('mushrooms')).to eq ['mushroom'] } + it { expect(search('tomatoes')).to eq ['tomato'] } + end end describe 'searches case insensitively' do From e322c863b2190e5fbba5572075758131eee1da2a Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 10:20:33 +1200 Subject: [PATCH 105/124] Removed unused arg to dbsearch --- app/services/crop_search_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/crop_search_service.rb b/app/services/crop_search_service.rb index 3a7560a6d..c2df12ef5 100644 --- a/app/services/crop_search_service.rb +++ b/app/services/crop_search_service.rb @@ -4,7 +4,7 @@ class CropSearchService if ENV["GROWSTUFF_ELASTICSEARCH"] == "true" elasticsearch(query, page: page, per_page: per_page, current_member: current_member) else - dbsearch(query, page: page, per_page: per_page, current_member: current_member) + dbsearch(query, page: page, per_page: per_page) end end @@ -24,7 +24,7 @@ class CropSearchService Crop.search(query, search_params) end - def self.dbsearch(query, page: 1, per_page: 12, current_member: nil) + def self.dbsearch(query, page: 1, per_page: 12) # if we don't have elasticsearch, just do a basic SQL query. # also, make sure it's an actual array not an activerecord # collection, so it matches what we get from elasticsearch and we can From 3e01da00366091f1dd00a496af241262e4c0c400 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 12:05:58 +1200 Subject: [PATCH 106/124] Remove waffle link, replace with github projects (#1916) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ef1935e0e..c2d696fa2 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ You might like to check out: Here on Github, you might find these useful: -* [Waffle](http://waffle.io/Growstuff/growstuff) has stories in "ready" that can be worked on. +* [Github Project Board](https://github.com/orgs/Growstuff/projects/1) has stories in "ready" that can be worked on. * [needs: design](https://github.com/Growstuff/growstuff/labels/needs:%20design) - tasks requiring high-level design -* [needs: visual design](https://github.com/Growstuff/growstuff/labels/needs:%20visual design) - tasks requiring visual/graphical design +* [needs: visual design](https://github.com/Growstuff/growstuff/labels/needs:%20visual+design) - tasks requiring visual/graphical design * [needs: documentation](https://github.com/Growstuff/growstuff/labels/needs:%20documentation) * [needs: data](https://github.com/Growstuff/growstuff/labels/needs:%20data) - tasks requiring data entry, data design, data import, or similar * [curated:beginner](https://github.com/Growstuff/growstuff/labels/curated:%20beginner) - tasks that are ideal for beginner programmers or people new to the project From cb680a5a0eec958b38bbad1ea6be0806eb9f1795 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 13 Apr 2019 12:09:47 +1200 Subject: [PATCH 107/124] Auto corrected by following Lint Ruby Space (#1917) --- spec/models/photo_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index b78718f5c..d71a6cd1c 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -146,12 +146,12 @@ describe Photo do seed.photos << seed_photo end - it { expect(Photo.by_model(Harvest)).to eq([ harvest_photo ]) } - it { expect(Photo.by_model(Planting)).to eq([ planting_photo ]) } - it { expect(Photo.by_model(Seed)).to eq([ seed_photo ]) } + it { expect(Photo.by_model(Harvest)).to eq([harvest_photo]) } + it { expect(Photo.by_model(Planting)).to eq([planting_photo]) } + it { expect(Photo.by_model(Seed)).to eq([seed_photo]) } - it { expect(Photo.by_crop(harvest_crop)).to eq([ harvest_photo ]) } - it { expect(Photo.by_crop(planting_crop)).to eq([ planting_photo ]) } - it { expect(Photo.by_crop(seed_crop)).to eq([ seed_photo ]) } + it { expect(Photo.by_crop(harvest_crop)).to eq([harvest_photo]) } + it { expect(Photo.by_crop(planting_crop)).to eq([planting_photo]) } + it { expect(Photo.by_crop(seed_crop)).to eq([seed_photo]) } end end From fb133b97b0b3d730ea7137904e964d6927cb3298 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Sat, 13 Apr 2019 12:12:35 +1200 Subject: [PATCH 108/124] Bump capybara from 3.16.1 to 3.16.2 (#1915) Bumps [capybara](https://github.com/teamcapybara/capybara) from 3.16.1 to 3.16.2. - [Release notes](https://github.com/teamcapybara/capybara/releases) - [Changelog](https://github.com/teamcapybara/capybara/blob/master/History.md) - [Commits](https://github.com/teamcapybara/capybara/compare/3.16.1...3.16.2) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7730545f3..38eb9fa60 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,7 +80,7 @@ GEM uniform_notifier (~> 1.11) byebug (11.0.1) cancancan (3.0.0) - capybara (3.16.1) + capybara (3.16.2) addressable mini_mime (>= 0.1.3) nokogiri (~> 1.8) From 5a8404e356023ef0aa98cda8a6998f7c0d7d9839 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Sat, 13 Apr 2019 00:15:24 +0000 Subject: [PATCH 109/124] Bump leaflet-rails from 1.3.1 to 1.4.0 Bumps [leaflet-rails](https://github.com/axyjo/leaflet-rails) from 1.3.1 to 1.4.0. - [Release notes](https://github.com/axyjo/leaflet-rails/releases) - [Changelog](https://github.com/axyjo/leaflet-rails/blob/master/CHANGELOG.md) - [Commits](https://github.com/axyjo/leaflet-rails/compare/v1.3.1...v1.4.0) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 38eb9fa60..98c785cf1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -265,7 +265,7 @@ GEM kramdown (2.1.0) launchy (2.4.3) addressable (~> 2.3) - leaflet-rails (1.3.1) + leaflet-rails (1.4.0) rails (>= 4.2.0) letter_opener (1.7.0) launchy (~> 2.2) From 50a2de3709ff31840d2edff0c92374bb603b9dbc Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sun, 14 Apr 2019 10:01:46 +0000 Subject: [PATCH 110/124] Auto corrected by following Lint Ruby RSpecEmptyLine --- spec/models/crop_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index fa5f746ce..cab5a4a9f 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -150,6 +150,7 @@ describe Crop do let!(:planting) { FactoryBot.create(:planting, crop: crop) } before { planting.photos << photo } + it { expect(crop.default_photo).to eq photo } include_examples 'has default photo' end @@ -157,13 +158,16 @@ describe Crop do context 'with a harvest photo' do let!(:harvest) { FactoryBot.create(:harvest, crop: crop) } let!(:photo) { FactoryBot.create(:photo, owner: harvest.owner) } + before { harvest.photos << photo } + it { expect(crop.default_photo).to eq photo } include_examples 'has default photo' context 'and planting photo' do let(:planting) { FactoryBot.create(:planting, crop: crop) } let!(:planting_photo) { FactoryBot.create(:photo, owner: planting.owner) } + before { planting.photos << planting_photo } it 'should prefer the planting photo' do @@ -182,6 +186,7 @@ describe Crop do let(:planting) { FactoryBot.create :planting, crop: crop } let(:harvest) { FactoryBot.create :harvest, crop: crop } let(:seed) { FactoryBot.create :seed, crop: crop } + before do # Add photos to all planting.photos << FactoryBot.create(:photo, owner: planting.owner) @@ -292,6 +297,7 @@ describe Crop do let(:crop2_planting) { crop2.plantings.first } let(:member) { FactoryBot.create :member, login_name: 'pikachu' } + describe 'lists interesting crops' do before do # they need 3+ plantings each to be interesting From e54c13afe3c193011c5b7f5f855dade857044810 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sun, 14 Apr 2019 18:36:34 +0000 Subject: [PATCH 111/124] Auto corrected by following Lint Ruby RSpec/AlignLeftLetBrace --- spec/models/crop_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index cab5a4a9f..7217a6e78 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -142,7 +142,7 @@ describe Crop do shared_examples 'has default photo' do it { expect(Crop.has_photos).to include(crop) } end - let!(:crop) { FactoryBot.create :tomato } + let!(:crop) { FactoryBot.create :tomato } let(:member) { FactoryBot.create :member } context 'with a planting photo' do @@ -185,7 +185,7 @@ describe Crop do describe 'finding all photos' do let(:planting) { FactoryBot.create :planting, crop: crop } let(:harvest) { FactoryBot.create :harvest, crop: crop } - let(:seed) { FactoryBot.create :seed, crop: crop } + let(:seed) { FactoryBot.create :seed, crop: crop } before do # Add photos to all @@ -343,8 +343,8 @@ describe Crop do end let(:maize) { FactoryBot.create(:maize) } - let(:pp1) { FactoryBot.create(:plant_part) } - let(:pp2) { FactoryBot.create(:plant_part) } + let(:pp1) { FactoryBot.create(:plant_part) } + let(:pp2) { FactoryBot.create(:plant_part) } context "harvests" do let(:h1) { FactoryBot.create(:harvest, crop: maize, plant_part: pp1) } From b84b1e89c15a03399fc874afaac76722792e449b Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sun, 14 Apr 2019 18:37:51 +0000 Subject: [PATCH 112/124] Auto corrected by following Lint Ruby RSpec/ExampleWording --- spec/models/crop_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 7217a6e78..9d293b092 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -4,18 +4,18 @@ describe Crop do context 'all fields present' do let(:crop) { FactoryBot.create(:tomato) } - it 'should save a basic crop' do + it 'saves a basic crop' do crop.save.should be(true) end - it 'should be fetchable from the database' do + it 'is fetchable from the database' do crop.save @crop2 = Crop.find_by(name: 'tomato') @crop2.en_wikipedia_url.should eq("http://en.wikipedia.org/wiki/Tomato") @crop2.slug.should eq("tomato") end - it 'should stringify as the system name' do + it 'stringifies as the system name' do crop.save crop.to_s.should eq('tomato') end @@ -27,7 +27,7 @@ describe Crop do end context 'invalid data' do - it 'should not save a crop without a system name' do + it 'does not save a crop without a system name' do crop = FactoryBot.build(:crop, name: nil) expect { crop.save }.to raise_error ActiveRecord::StatementInvalid end @@ -170,7 +170,7 @@ describe Crop do before { planting.photos << planting_photo } - it 'should prefer the planting photo' do + it 'prefers the planting photo' do expect(crop.default_photo.id).to eq planting_photo.id end end @@ -562,11 +562,11 @@ describe Crop do tomato.destroy end - it "should delete the association between post and the crop(tomato)" do + it "deletes the association between post and the crop(tomato)" do expect(Post.find(post.id).crops).to eq [maize] end - it "should not delete the posts" do + it "does not delete the posts" do expect(Post.find(post.id)).not_to eq nil end end @@ -586,11 +586,11 @@ describe Crop do end describe "rejecting a crop" do - it "should give reason if a default option" do + it "gives reason if a default option" do expect(rejected_reason.rejection_explanation).to eq "not edible" end - it "should show rejection notes if reason was other" do + it "shows rejection notes if reason was other" do expect(rejected_other.rejection_explanation).to eq "blah blah blah" end end From ff3ea5c52f6a46c680aaba4e9afbc0eefb09576e Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sun, 14 Apr 2019 18:38:05 +0000 Subject: [PATCH 113/124] Auto corrected by following Lint Ruby RSpec/HookArgument --- spec/models/crop_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 9d293b092..39c6e197b 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -395,7 +395,7 @@ describe Crop do end context "csv loading" do - before(:each) do + before do # don't use 'let' for this -- we need to actually create it, # regardless of whether it's used. @cropbot = FactoryBot.create(:cropbot) From b9ca89b3365e81fbcfcdc080ef51650fe6f2a21d Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sun, 14 Apr 2019 19:38:16 +0000 Subject: [PATCH 114/124] Auto corrected by following Lint Ruby RSpec/LetBeforeExamples --- spec/models/crop_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 39c6e197b..831b786e5 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -1,6 +1,9 @@ require 'rails_helper' describe Crop do + let(:pp2) { FactoryBot.create(:plant_part) } + let(:pp1) { FactoryBot.create(:plant_part) } + let(:maize) { FactoryBot.create(:maize) } context 'all fields present' do let(:crop) { FactoryBot.create(:tomato) } @@ -342,9 +345,6 @@ describe Crop do end end - let(:maize) { FactoryBot.create(:maize) } - let(:pp1) { FactoryBot.create(:plant_part) } - let(:pp2) { FactoryBot.create(:plant_part) } context "harvests" do let(:h1) { FactoryBot.create(:harvest, crop: maize, plant_part: pp1) } From b9a7c24da6daa0cad289da6b64c5f87cd481c22c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 15 Apr 2019 07:49:43 +0000 Subject: [PATCH 115/124] Bump sidekiq from 5.2.5 to 5.2.6 Bumps [sidekiq](https://github.com/mperham/sidekiq) from 5.2.5 to 5.2.6. - [Release notes](https://github.com/mperham/sidekiq/releases) - [Changelog](https://github.com/mperham/sidekiq/blob/master/Changes.md) - [Commits](https://github.com/mperham/sidekiq/compare/v5.2.5...v5.2.6) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 98c785cf1..d7f666ea4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -456,7 +456,7 @@ GEM childprocess (~> 0.5) rubyzip (~> 1.2, >= 1.2.2) sexp_processor (4.12.0) - sidekiq (5.2.5) + sidekiq (5.2.6) connection_pool (~> 2.2, >= 2.2.2) rack (>= 1.5.0) rack-protection (>= 1.5.0) From deef508b9c18133c3ebc8febd5f0dc7402890b29 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 16 Apr 2019 07:22:06 +0000 Subject: [PATCH 116/124] Bump cancancan from 3.0.0 to 3.0.1 Bumps [cancancan](https://github.com/CanCanCommunity/cancancan) from 3.0.0 to 3.0.1. - [Release notes](https://github.com/CanCanCommunity/cancancan/releases) - [Changelog](https://github.com/CanCanCommunity/cancancan/blob/develop/CHANGELOG.md) - [Commits](https://github.com/CanCanCommunity/cancancan/compare/3.0.0...3.0.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d7f666ea4..8d34463a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,7 +79,7 @@ GEM activesupport (>= 3.0.0) uniform_notifier (~> 1.11) byebug (11.0.1) - cancancan (3.0.0) + cancancan (3.0.1) capybara (3.16.2) addressable mini_mime (>= 0.1.3) From a4e398bb6247e0c8a6ed7f42a66c3a984832c982 Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Tue, 16 Apr 2019 09:55:51 +0000 Subject: [PATCH 117/124] Auto corrected by following Lint Ruby RSpec/AlignRightLetBrace --- spec/models/crop_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 831b786e5..9ebd4faeb 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Crop do let(:pp2) { FactoryBot.create(:plant_part) } let(:pp1) { FactoryBot.create(:plant_part) } - let(:maize) { FactoryBot.create(:maize) } + let(:maize) { FactoryBot.create(:maize) } context 'all fields present' do let(:crop) { FactoryBot.create(:tomato) } @@ -188,7 +188,7 @@ describe Crop do describe 'finding all photos' do let(:planting) { FactoryBot.create :planting, crop: crop } let(:harvest) { FactoryBot.create :harvest, crop: crop } - let(:seed) { FactoryBot.create :seed, crop: crop } + let(:seed) { FactoryBot.create :seed, crop: crop } before do # Add photos to all From d0001691d55349fd49b7c0912fdb510c923cbbac Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sun, 14 Apr 2019 19:40:49 +0000 Subject: [PATCH 118/124] Auto corrected by following Lint Ruby EmptyLine --- spec/models/crop_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 9ebd4faeb..ad6732ba8 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -345,7 +345,6 @@ describe Crop do end end - context "harvests" do let(:h1) { FactoryBot.create(:harvest, crop: maize, plant_part: pp1) } let(:h2) { FactoryBot.create(:harvest, crop: maize, plant_part: pp2) } From 8b0ecd568ea70c10adcba0cec120f11b08c241ee Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Tue, 16 Apr 2019 09:56:19 +0000 Subject: [PATCH 119/124] Auto corrected by following Lint Ruby RSpec/ImplicitSubject --- spec/features/crops/crop_detail_page_spec.rb | 10 +++++----- spec/features/gardens/actions_spec.rb | 16 ++++++++-------- spec/features/harvests/browse_harvests_spec.rb | 6 +++--- spec/features/home/home_spec.rb | 18 +++++++++--------- spec/features/seeds/seed_photos.rb | 8 ++++---- spec/helpers/photos_helper_spec.rb | 6 +++--- .../crops/_planting_advice.html.haml_spec.rb | 4 ++-- spec/views/members/show.rss.haml_spec.rb | 8 ++++---- spec/views/posts/show.html.haml_spec.rb | 8 ++++---- 9 files changed, 42 insertions(+), 42 deletions(-) diff --git a/spec/features/crops/crop_detail_page_spec.rb b/spec/features/crops/crop_detail_page_spec.rb index bbf53b0a0..2c263999b 100644 --- a/spec/features/crops/crop_detail_page_spec.rb +++ b/spec/features/crops/crop_detail_page_spec.rb @@ -119,7 +119,7 @@ describe "crop detail page", js: true do end it "predicts harvest" do - is_expected.to have_text("First harvest expected 20 days after planting") + expect(subject).to have_text("First harvest expected 20 days after planting") end end end @@ -142,12 +142,12 @@ describe "crop detail page", js: true do end it "predicts lifespan" do - is_expected.to have_text "Median lifespan" - is_expected.to have_text "99 days" + expect(subject).to have_text "Median lifespan" + expect(subject).to have_text "99 days" end it "describes annual crops" do - is_expected.to have_text( + expect(subject).to have_text( "#{crop.name} is an annual crop (living and reproducing in a single year or less)" ) end @@ -164,7 +164,7 @@ describe "crop detail page", js: true do end it "describes perennial crops" do - is_expected.to have_text("#{crop.name} is a perennial crop (living more than two years)") + expect(subject).to have_text("#{crop.name} is a perennial crop (living more than two years)") end end diff --git a/spec/features/gardens/actions_spec.rb b/spec/features/gardens/actions_spec.rb index 1f7fe2a26..4da6b1e32 100644 --- a/spec/features/gardens/actions_spec.rb +++ b/spec/features/gardens/actions_spec.rb @@ -15,9 +15,9 @@ describe "Gardens" do shared_examples "has buttons bar at top" do it "has buttons bar at top" do within '.layout-actions' do - is_expected.to have_link 'Add a garden' - is_expected.to have_link 'My gardens' - is_expected.to have_link "Everyone's gardens" + expect(subject).to have_link 'Add a garden' + expect(subject).to have_link 'My gardens' + expect(subject).to have_link "Everyone's gardens" end end end @@ -27,11 +27,11 @@ describe "Gardens" do include_examples "has buttons bar at top" it "has actions on garden" do - is_expected.to have_link 'Plant something here' - is_expected.to have_link 'Mark as inactive' - is_expected.to have_link 'Edit' - is_expected.to have_link 'Add photo' - is_expected.to have_link 'Delete' + expect(subject).to have_link 'Plant something here' + expect(subject).to have_link 'Mark as inactive' + expect(subject).to have_link 'Edit' + expect(subject).to have_link 'Add photo' + expect(subject).to have_link 'Delete' end end diff --git a/spec/features/harvests/browse_harvests_spec.rb b/spec/features/harvests/browse_harvests_spec.rb index a141547e4..1f05c5a34 100644 --- a/spec/features/harvests/browse_harvests_spec.rb +++ b/spec/features/harvests/browse_harvests_spec.rb @@ -14,7 +14,7 @@ describe "browse harvests" do before { visit harvests_path } it 'read more' do - is_expected.not_to have_link "Read more" + expect(subject).not_to have_link "Read more" end end @@ -26,11 +26,11 @@ describe "browse harvests" do end it 'read more' do - is_expected.to have_link "Read more" + expect(subject).to have_link "Read more" end it 'links to #show' do - is_expected.to have_link harvest.crop.name, href: harvest_path(harvest) + expect(subject).to have_link harvest.crop.name, href: harvest_path(harvest) end end end diff --git a/spec/features/home/home_spec.rb b/spec/features/home/home_spec.rb index 8a10c83fa..6ef612af0 100644 --- a/spec/features/home/home_spec.rb +++ b/spec/features/home/home_spec.rb @@ -27,13 +27,13 @@ describe "home page" do shared_examples 'shows seeds' do it "show tradeable seed" do - is_expected.to have_link href: seed_path(tradable_seed) + expect(subject).to have_link href: seed_path(tradable_seed) end it "does not show finished seeds" do - is_expected.not_to have_link href: seed_path(finished_seed) + expect(subject).not_to have_link href: seed_path(finished_seed) end it "does not show untradable seeds" do - is_expected.not_to have_link href: seed_path(untradable_seed) + expect(subject).not_to have_link href: seed_path(untradable_seed) end it { is_expected.to have_text 'View all seeds' } @@ -41,14 +41,14 @@ describe "home page" do shared_examples 'show plantings' do it 'shows plantings section' do - is_expected.to have_text 'Recently Planted' - is_expected.to have_link href: planting_path(planting) + expect(subject).to have_text 'Recently Planted' + expect(subject).to have_link href: planting_path(planting) end end shared_examples 'show harvests' do it 'shows harvests section' do - is_expected.to have_text 'Recently Harvested' - is_expected.to have_link href: harvest_path(harvest) + expect(subject).to have_text 'Recently Harvested' + expect(subject).to have_link href: harvest_path(harvest) end end @@ -61,12 +61,12 @@ describe "home page" do describe 'shows recently added crops' do it { is_expected.to have_text 'Recently Added' } it 'link to newest crops' do - is_expected.to have_link crop.name, href: crop_path(crop) + expect(subject).to have_link crop.name, href: crop_path(crop) end end it 'includes a link to all crops' do - is_expected.to have_link 'View all crops' + expect(subject).to have_link 'View all crops' end end diff --git a/spec/features/seeds/seed_photos.rb b/spec/features/seeds/seed_photos.rb index add3d0fa5..d1eacdd7f 100644 --- a/spec/features/seeds/seed_photos.rb +++ b/spec/features/seeds/seed_photos.rb @@ -31,16 +31,16 @@ describe "Seeds", :js do let!(:photos) { FactoryBot.create_list :photo, 50 } it "shows newest photo" do - is_expected.to have_xpath("//img[contains(@src,'#{photos.last.thumbnail_url}')]") + expect(subject).to have_xpath("//img[contains(@src,'#{photos.last.thumbnail_url}')]") end it "links to newest photo" do - is_expected.to have_xpath("//a[contains(@href,'#{photo_path(photos.last)}')]") + expect(subject).to have_xpath("//a[contains(@href,'#{photo_path(photos.last)}')]") end it "does not show oldest photo" do - is_expected.not_to have_xpath("//img[contains(@src,'#{photos.first.thumbnail_url}')]") + expect(subject).not_to have_xpath("//img[contains(@src,'#{photos.first.thumbnail_url}')]") end it "does not link to oldest photo" do - is_expected.not_to have_xpath("//a[contains(@href,'#{photo_path(photos.first)}')]") + expect(subject).not_to have_xpath("//a[contains(@href,'#{photo_path(photos.first)}')]") end end end diff --git a/spec/helpers/photos_helper_spec.rb b/spec/helpers/photos_helper_spec.rb index 60a6cbc59..cace0e120 100644 --- a/spec/helpers/photos_helper_spec.rb +++ b/spec/helpers/photos_helper_spec.rb @@ -22,7 +22,7 @@ describe PhotosHelper do before { planting.photos << planting_photo } it "uses planting photos" do - is_expected.to eq planting_photo.thumbnail_url + expect(subject).to eq planting_photo.thumbnail_url end end @@ -30,7 +30,7 @@ describe PhotosHelper do before { harvest.photos << harvest_photo } it "uses harvest photos" do - is_expected.to eq harvest_photo.thumbnail_url + expect(subject).to eq harvest_photo.thumbnail_url end end @@ -38,7 +38,7 @@ describe PhotosHelper do before { seed.photos << seed_photo } it "uses seed photos" do - is_expected.to eq seed_photo.thumbnail_url + expect(subject).to eq seed_photo.thumbnail_url end end end diff --git a/spec/views/crops/_planting_advice.html.haml_spec.rb b/spec/views/crops/_planting_advice.html.haml_spec.rb index 7335fd127..59e635b45 100644 --- a/spec/views/crops/_planting_advice.html.haml_spec.rb +++ b/spec/views/crops/_planting_advice.html.haml_spec.rb @@ -13,7 +13,7 @@ describe "crops/_planting_advice" do context "with no sunniness set" do include_examples "render planting_advice" it "doesn't show sunniness" do - is_expected.to have_content "Plant in: not known." + expect(subject).to have_content "Plant in: not known." end end @@ -41,7 +41,7 @@ describe "crops/_planting_advice" do context "when none are set" do include_examples "render planting_advice" it "doesn't show planted_from " do - is_expected.to have_content "Plant from: not known." + expect(subject).to have_content "Plant from: not known." end end diff --git a/spec/views/members/show.rss.haml_spec.rb b/spec/views/members/show.rss.haml_spec.rb index a0a7414e0..8ad64ab95 100644 --- a/spec/views/members/show.rss.haml_spec.rb +++ b/spec/views/members/show.rss.haml_spec.rb @@ -12,20 +12,20 @@ describe 'members/show.rss.haml', type: "view" do end it 'shows RSS feed title' do - is_expected.to have_text("callum's recent posts") + expect(subject).to have_text("callum's recent posts") end it 'shows content of posts' do - is_expected.to have_content "This is some text." + expect(subject).to have_content "This is some text." end it 'renders post bodies to HTML and XML-escapes them' do # The variable "rendered" has been entity-replaced and tag-stripped # The literal string output contains "<strong>" etc. - is_expected.to have_content "strong" + expect(subject).to have_content "strong" end it 'gives the author in the item title' do - is_expected.to have_content "#{@post1.subject} by #{@post1.author}" + expect(subject).to have_content "#{@post1.subject} by #{@post1.author}" end end diff --git a/spec/views/posts/show.html.haml_spec.rb b/spec/views/posts/show.html.haml_spec.rb index 2754439d1..bb59f2b47 100644 --- a/spec/views/posts/show.html.haml_spec.rb +++ b/spec/views/posts/show.html.haml_spec.rb @@ -71,7 +71,7 @@ describe "posts/show" do end it "shows comments" do - is_expected.to have_content comment.body + expect(subject).to have_content comment.body end it 'has an anchor to the comments' do @@ -95,7 +95,7 @@ describe "posts/show" do end it "shows the oldest comments first" do - is_expected.to have_content(/#{@comment1.body}.*#{@comment2.body}.*#{@comment3.body}.*#{@comment4.body}/m) + expect(subject).to have_content(/#{@comment1.body}.*#{@comment2.body}.*#{@comment3.body}.*#{@comment4.body}/m) end end @@ -105,7 +105,7 @@ describe "posts/show" do before { render } it "shows forum name" do - is_expected.to have_content "in #{post.forum.name}" + expect(subject).to have_content "in #{post.forum.name}" end end @@ -119,7 +119,7 @@ describe "posts/show" do end it 'shows a comment button' do - is_expected.to have_link "Comment", href: new_comment_path(post_id: post.id) + expect(subject).to have_link "Comment", href: new_comment_path(post_id: post.id) end end end From fcd7ad8ed63e1a9f6cad60f3e7703d372c154af8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Thu, 18 Apr 2019 07:20:57 +0000 Subject: [PATCH 120/124] Bump selenium-webdriver from 3.141.0 to 3.141.5926 Bumps [selenium-webdriver](https://github.com/SeleniumHQ/selenium) from 3.141.0 to 3.141.5926. - [Release notes](https://github.com/SeleniumHQ/selenium/releases) - [Changelog](https://github.com/SeleniumHQ/selenium/blob/master/rb/CHANGES) - [Commits](https://github.com/SeleniumHQ/selenium/commits) Signed-off-by: dependabot[bot] --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8d34463a1..3539c2fb1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,8 +95,8 @@ GEM capybara (>= 1.0, < 4) launchy chartkick (3.0.2) - childprocess (0.9.0) - ffi (~> 1.0, >= 1.0.11) + childprocess (1.0.1) + rake (< 13.0) cliver (0.3.2) codeclimate-test-reporter (1.0.9) simplecov (<= 0.13) @@ -452,8 +452,8 @@ GEM sprockets-rails tilt scout_apm (2.4.24) - selenium-webdriver (3.141.0) - childprocess (~> 0.5) + selenium-webdriver (3.141.5926) + childprocess (>= 0.5, < 2.0) rubyzip (~> 1.2, >= 1.2.2) sexp_processor (4.12.0) sidekiq (5.2.6) From d7497e4342ea206725c6384a8d2412d7a19bc71b Mon Sep 17 00:00:00 2001 From: pozorvlak Date: Fri, 19 Apr 2019 08:32:38 +1200 Subject: [PATCH 121/124] Fixed comment Co-Authored-By: Br3nda --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 4d1cb36d2..cf7cdc001 100644 --- a/Gemfile +++ b/Gemfile @@ -83,7 +83,7 @@ gem 'omniauth-twitter' # Pretty charts gem "chartkick" -# clever elastic searh +# clever elastic search gem 'searchkick' gem "hashie", ">= 3.5.3" From b3385663e87761aeb74cf04f1c9f4352c4b41ac8 Mon Sep 17 00:00:00 2001 From: pozorvlak Date: Fri, 19 Apr 2019 08:47:08 +1200 Subject: [PATCH 122/124] Fix spelling of portobello Co-Authored-By: Br3nda --- spec/services/crop_search_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/crop_search_service_spec.rb b/spec/services/crop_search_service_spec.rb index 249932e19..340633d57 100644 --- a/spec/services/crop_search_service_spec.rb +++ b/spec/services/crop_search_service_spec.rb @@ -25,7 +25,7 @@ RSpec.describe CropSearchService, type: :service do FactoryBot.create(:crop_request, name: 'requested mushroom') # Child record - FactoryBot.create(:crop, name: 'portabello', parent: mushroom) + FactoryBot.create(:crop, name: 'portobello', parent: mushroom) Crop.reindex if ENV['GROWSTUFF_ELASTICSEARCH'] == 'true' end From 3829db6bc273f239301e13eaa005a2facdef27c1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 19 Apr 2019 09:05:53 +1200 Subject: [PATCH 123/124] Specs for biasing results from elastic search --- spec/services/crop_search_service_spec.rb | 36 ++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/spec/services/crop_search_service_spec.rb b/spec/services/crop_search_service_spec.rb index 249932e19..1a4515f4e 100644 --- a/spec/services/crop_search_service_spec.rb +++ b/spec/services/crop_search_service_spec.rb @@ -10,7 +10,7 @@ RSpec.describe CropSearchService, type: :service do context 'with some crops' do let!(:mushroom) { FactoryBot.create(:crop, name: 'mushroom') } - let!(:tomato) { FactoryBot.create(:crop ,name: 'tomato') } + let!(:tomato) { FactoryBot.create(:crop, name: 'tomato') } let!(:taewa) { FactoryBot.create(:crop, name: 'taewa') } let!(:zucchini) { FactoryBot.create(:crop, name: 'zucchini') } let!(:broccoli) { FactoryBot.create(:crop, name: 'broccoli') } @@ -44,6 +44,40 @@ RSpec.describe CropSearchService, type: :service do it { expect(search('zuchini')).to eq ['zucchini'] } it { expect(search('brocoli')).to eq ['broccoli'] } end + + describe 'biased' do + # Make some crops with planting counts + let!(:mushroom_parent) { FactoryBot.create :crop, name: 'mushroom' } + let!(:oyster) { FactoryBot.create :crop, name: 'oyster mushroom', parent: mushroom_parent } + let!(:shitake) { FactoryBot.create :crop, name: 'shitake mushroom', parent: mushroom_parent } + let!(:common) { FactoryBot.create :crop, name: 'common mushroom', parent: mushroom_parent } + let!(:brown) { FactoryBot.create :crop, name: 'brown mushroom', parent: mushroom_parent } + let!(:white) { FactoryBot.create :crop, name: 'white mushroom', parent: mushroom_parent } + + describe 'biased to higher planting counts' do + before do + # Having plantings should bring these crops to the top of the search results + FactoryBot.create_list :planting, 10, crop: white + FactoryBot.create_list :planting, 4, crop: shitake + Crop.reindex + end + subject { search('mushroom') } + it { expect(subject.first).to eq 'white mushroom' } + it { expect(subject.second).to eq 'shitake mushroom' } + end + describe "biased to crops you've planted" do + let(:owner) { FactoryBot.create :member } + before do + FactoryBot.create :planting, crop: oyster, owner: owner + FactoryBot.create :planting, crop: oyster, owner: owner + FactoryBot.create :planting, crop: shitake, owner: owner + Crop.reindex + end + subject { CropSearchService.search('mushroom', current_member: owner).map(&:name) } + it { expect(subject.first).to eq oyster.name } + it { expect(subject.second).to eq shitake.name } + end + end end describe 'doesn\'t find non-match "coffee"' do From 6af61d0e86e8a2f32c1e5e93c3fcd4a3f46a682f Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Fri, 19 Apr 2019 09:11:56 +1200 Subject: [PATCH 124/124] Add someone else's plantings, to ensure test is valid --- spec/services/crop_search_service_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/services/crop_search_service_spec.rb b/spec/services/crop_search_service_spec.rb index 11429e56c..a73fd70d9 100644 --- a/spec/services/crop_search_service_spec.rb +++ b/spec/services/crop_search_service_spec.rb @@ -68,6 +68,7 @@ RSpec.describe CropSearchService, type: :service do describe "biased to crops you've planted" do let(:owner) { FactoryBot.create :member } before do + FactoryBot.create_list :planting, 10, crop: brown FactoryBot.create :planting, crop: oyster, owner: owner FactoryBot.create :planting, crop: oyster, owner: owner FactoryBot.create :planting, crop: shitake, owner: owner