diff --git a/.github/workflows/ci-features-admin.yml b/.github/workflows/ci-features-admin.yml index 2a605ea5ea..c737035df7 100644 --- a/.github/workflows/ci-features-admin.yml +++ b/.github/workflows/ci-features-admin.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-comments.yml b/.github/workflows/ci-features-comments.yml index e587d13ecf..8d2d65a0d6 100644 --- a/.github/workflows/ci-features-comments.yml +++ b/.github/workflows/ci-features-comments.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-conversations.yml b/.github/workflows/ci-features-conversations.yml index b107b16451..857e4c2e98 100644 --- a/.github/workflows/ci-features-conversations.yml +++ b/.github/workflows/ci-features-conversations.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-crops.yml b/.github/workflows/ci-features-crops.yml index deb916360b..ea3b5f4e0d 100644 --- a/.github/workflows/ci-features-crops.yml +++ b/.github/workflows/ci-features-crops.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-gardens.yml b/.github/workflows/ci-features-gardens.yml index 244b3c6c08..0d6272932c 100644 --- a/.github/workflows/ci-features-gardens.yml +++ b/.github/workflows/ci-features-gardens.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-harvests.yml b/.github/workflows/ci-features-harvests.yml index a3be5b1125..5b1e6888e5 100644 --- a/.github/workflows/ci-features-harvests.yml +++ b/.github/workflows/ci-features-harvests.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-home.yml b/.github/workflows/ci-features-home.yml index 3e4f4a9c29..ff0b976c14 100644 --- a/.github/workflows/ci-features-home.yml +++ b/.github/workflows/ci-features-home.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-members.yml b/.github/workflows/ci-features-members.yml index 87e4717315..fead41eb87 100644 --- a/.github/workflows/ci-features-members.yml +++ b/.github/workflows/ci-features-members.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-places.yml b/.github/workflows/ci-features-places.yml index eaa33c3a7e..2b2e44eef0 100644 --- a/.github/workflows/ci-features-places.yml +++ b/.github/workflows/ci-features-places.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-plantings.yml b/.github/workflows/ci-features-plantings.yml index 0e01a2dfd0..39533e8d64 100644 --- a/.github/workflows/ci-features-plantings.yml +++ b/.github/workflows/ci-features-plantings.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-posts.yml b/.github/workflows/ci-features-posts.yml index 5342e77c2b..4a5f11581c 100644 --- a/.github/workflows/ci-features-posts.yml +++ b/.github/workflows/ci-features-posts.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-seeds.yml b/.github/workflows/ci-features-seeds.yml index a1158eae8c..fd1f93d699 100644 --- a/.github/workflows/ci-features-seeds.yml +++ b/.github/workflows/ci-features-seeds.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features-timeline.yml b/.github/workflows/ci-features-timeline.yml index 660481a000..63378d5e01 100644 --- a/.github/workflows/ci-features-timeline.yml +++ b/.github/workflows/ci-features-timeline.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci-features.yml b/.github/workflows/ci-features.yml index e8fdb8c236..2e1729acd3 100644 --- a/.github/workflows/ci-features.yml +++ b/.github/workflows/ci-features.yml @@ -61,7 +61,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a62ede169a..31a2e5c027 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -76,7 +76,7 @@ jobs: id: yarn-cache-dir-path run: echo "::set-output name=dir::$(yarn cache dir)" - name: Setup yarn cache - uses: actions/cache@v5 + uses: actions/cache@v6 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} diff --git a/Gemfile.lock b/Gemfile.lock index 252f12deb5..26e3e4b03d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -138,22 +138,12 @@ GEM aws-sigv4 (~> 1.5) aws-sigv4 (1.12.1) aws-eventstream (~> 1, >= 1.0.2) - axe-core-api (4.11.3) + axe-core-api (4.12.0) dumb_delegator - ostruct - virtus - axe-core-capybara (4.11.3) - axe-core-api (= 4.11.3) - dumb_delegator - axe-core-rspec (4.11.3) - axe-core-api (= 4.11.3) - dumb_delegator - ostruct - virtus - axiom-types (0.1.1) - descendants_tracker (~> 0.0.4) - ice_nine (~> 0.11.0) - thread_safe (~> 0.3, >= 0.3.1) + axe-core-capybara (4.12.0) + axe-core-api (= 4.12.0) + axe-core-rspec (4.12.0) + axe-core-api (= 4.12.0) base64 (0.3.0) bcrypt (3.1.22) benchmark (0.5.0) @@ -207,8 +197,6 @@ GEM childprocess (5.1.0) logger (~> 1.5) coderay (1.1.3) - coercible (1.0.0) - descendants_tracker (~> 0.0.1) coffee-rails (5.0.0) coffee-script (>= 2.2.0) railties (>= 5.2.0) @@ -242,8 +230,6 @@ GEM database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) date (3.5.1) - descendants_tracker (0.0.4) - thread_safe (~> 0.3, >= 0.3.1) devise (5.0.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -358,7 +344,6 @@ GEM logger ostruct ice_cube (0.17.0) - ice_nine (0.11.2) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) @@ -721,7 +706,6 @@ GEM terser (1.2.7) execjs (>= 0.3.0, < 3) thor (1.5.0) - thread_safe (0.3.6) tilt (2.7.0) timecop (0.9.11) timeout (0.6.1) @@ -741,10 +725,6 @@ GEM activemodel (>= 3.0.0) public_suffix vcr (6.4.0) - virtus (2.0.0) - axiom-types (~> 0.1) - coercible (~> 1.0) - descendants_tracker (~> 0.0, >= 0.0.3) warden (1.2.9) rack (>= 2.0.9) webrat (0.7.3) diff --git a/app/controllers/harvests_controller.rb b/app/controllers/harvests_controller.rb index 4a5f9bd15c..97a16d6433 100644 --- a/app/controllers/harvests_controller.rb +++ b/app/controllers/harvests_controller.rb @@ -4,27 +4,26 @@ class HarvestsController < DataController after_action :update_crop_medians, only: %i(create update destroy) def index - where = {} + @harvests = Harvest.all + if params[:member_slug].present? @owner = Member.find_by!(slug: params[:member_slug]) - where['owner_id'] = @owner.id + @harvests = @harvests.where(owner_id: @owner.id) end if params[:crop_slug] @crop = Crop.find_by(slug: params[:crop_slug]) - where['crop_id'] = @crop.id + @harvests = @harvests.where(crop_id: @crop.id) if @crop end if params[:planting_slug] @planting = Planting.find_by(slug: params[:planting_slug]) - where['planting_id'] = @planting.id + @harvests = @harvests.where(planting_id: @planting.id) if @planting end - @harvests = Harvest.search('*', where:, - limit: 100, - page: params[:page], - load: (request.format.csv? ? { include: %i(crop owner plant_part) } : false), - boost_by: [:created_at]) + @harvests = @harvests.includes(:crop, :owner, :plant_part) + + @harvests = @harvests.recent.paginate(page: params[:page], per_page: 100) @filename = csv_filename diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 6f6d8aa8be..a2d89f21b3 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -40,12 +40,9 @@ def show end end - @harvests = Harvest.search( - where: { owner_id: @member.id }, - boost_by: [:created_at], - limit: 16, - load: false - ) + @harvests = Harvest.where(owner_id: @member.id) + .recent + .limit(16) respond_to do |format| format.html # show.html.haml diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index 2d7a26d17b..c5fa9e9c9e 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -8,26 +8,10 @@ class PlantingsController < DataController def index @show_all = params[:all] == '1' - where = {} - where['active'] = true unless @show_all + @owner = Member.find_by!(slug: params[:member_slug]) if params[:member_slug].present? + @crop = Crop.find_by(slug: params[:crop_slug]) if params[:crop_slug] - if params[:member_slug].present? - @owner = Member.find_by!(slug: params[:member_slug]) - where['owner_id'] = @owner.id - end - - if params[:crop_slug] - @crop = Crop.find_by(slug: params[:crop_slug]) - where['crop_id'] = @crop.id unless @crop.nil? - end - - @plantings = Planting.search( - where:, - page: params[:page], - limit: 30, - boost_by: [:created_at], - load: false - ) + @plantings = plantings @filename = "Growstuff-#{specifics}Plantings-#{Time.zone.now.to_fs(:number)}.csv" respond_with(@plantings) @@ -35,7 +19,7 @@ def index def show @photos = @planting.photos.includes(:owner).order(date_taken: :desc) - @harvests = Harvest.search(where: { planting_id: @planting.id }) + @harvests = Harvest.where(planting_id: @planting.id).recent @current_activities = @planting.activities.current.includes(:owner).order(created_at: :desc) @finished_activities = @planting.activities.finished.includes(:owner).order(created_at: :desc) @matching_seeds = matching_seeds diff --git a/app/controllers/seeds_controller.rb b/app/controllers/seeds_controller.rb index 3b65a13d14..17531227c9 100644 --- a/app/controllers/seeds_controller.rb +++ b/app/controllers/seeds_controller.rb @@ -2,36 +2,32 @@ class SeedsController < DataController def index - where = {} + @seeds = Seed.all if params[:member_slug].present? @owner = Member.find_by!(slug: params[:member_slug]) - where['owner_id'] = @owner.id + @seeds = @seeds.where(owner_id: @owner.id) end if params[:crop_slug].present? @crop = Crop.find_by(slug: params[:crop_slug]) - where['crop_id'] = @crop.id + @seeds = @seeds.where(crop_id: @crop.id) if @crop end if params[:planting_id].present? @planting = Planting.find_by(slug: params[:planting_id]) - where['parent_planting'] = @planting.id + @seeds = @seeds.where(parent_planting_id: @planting.id) if @planting end - where['tradeable_to'] = params[:tradeable_to] if params[:tradeable_to].present? + @seeds = @seeds.where(tradable_to: params[:tradeable_to]) if params[:tradeable_to].present? @show_all = (params[:all] == '1') - where['finished'] = false unless @show_all + @seeds = @seeds.current unless @show_all @filename = csv_filename - @seeds = Seed.search( - where:, - page: params[:page], - limit: 30, - boost_by: [:created_at], - load: (request.format.csv? ? { include: %i(crop owner) } : false) - ) + @seeds = @seeds.includes(:crop, :owner) + .order(created_at: :desc) + .paginate(page: params[:page], per_page: 30) respond_with(@seeds) end diff --git a/app/models/concerns/search_harvests.rb b/app/models/concerns/search_harvests.rb deleted file mode 100644 index f1d18cbcf5..0000000000 --- a/app/models/concerns/search_harvests.rb +++ /dev/null @@ -1,74 +0,0 @@ -# frozen_string_literal: true - -module SearchHarvests - extend ActiveSupport::Concern - - included do - searchkick merge_mappings: true, - settings: { number_of_shards: 1, number_of_replicas: 0 }, - mappings: { - properties: { - harvests_count: { type: :integer }, - photos_count: { type: :integer }, - created_at: { type: :integer }, - harvested_at: { type: :date } - } - } - - def search_data - { - slug:, - quantity:, - - # crop - crop_id:, - crop_name:, - crop_slug: crop.slug, - - # owner - owner_id:, - owner_login_name:, - owner_slug:, - plant_part_name: plant_part&.name, - - # planting - planting_id:, - planting_slug: planting&.slug, - - # photo - has_photos: photos.size.positive?, - thumbnail_url: default_photo&.thumbnail_url || crop.default_photo&.thumbnail_url, - - # counts - photos_count: photos.count, - - # timestamps - harvested_at:, - created_at: created_at.to_i - } - end - - def self.homepage_records(limit) - records = [] - owners = [] - 1..limit.times do - where = { - # Disabled for now so that more relevant harvests are - # surfaced; even if we're falling back to crop photos. - # photos_count: { gt: 0 }, - owner_id: { not: owners } - } - one_record = search('*', - limit: 1, - where:, - boost_by: [:created_at], - load: false).first - return records if one_record.nil? - - owners << one_record.owner_id - records << one_record - end - records - end - end -end diff --git a/app/models/concerns/search_plantings.rb b/app/models/concerns/search_plantings.rb deleted file mode 100644 index b44bb6ee3f..0000000000 --- a/app/models/concerns/search_plantings.rb +++ /dev/null @@ -1,87 +0,0 @@ -# frozen_string_literal: true - -module SearchPlantings - extend ActiveSupport::Concern - - included do - searchkick merge_mappings: true, - settings: { number_of_shards: 1, number_of_replicas: 0 }, - mappings: { - properties: { - active: { type: :boolean }, - created_at: { type: :integer }, - harvests_count: { type: :integer }, - photos_count: { type: :integer }, - owner_location: { type: :text } - } - } - - def search_data - { - slug:, - active:, - finished: finished?, - has_photos: photos.size.positive?, - location:, - percentage_grown: percentage_grown.to_i, - planted_at:, - planted_from:, - planted_year: planted_at&.year, - quantity:, - sunniness:, - garden_id:, - garden_slug: garden&.garden_slug, - garden_name: garden&.name, - description:, - - first_harvest_predicted_at:, - finish_predicted_at:, - - # crops - crop_id:, - crop_name:, - crop_slug:, - crop_perennial:, - - # owner - owner_id:, - owner_location:, - owner_login_name:, - owner_slug:, - - # photos - thumbnail_url: default_photo&.thumbnail_url || crop.default_photo&.thumbnail_url, - # counts - photos_count: photos.size, - harvests_count:, - - # timestamps - created_at: created_at.to_i, - updated_at: updated_at.to_i - } - end - - def self.homepage_records(limit) - records = [] - owners = [] - 1..limit.times do - where = { - # Disabled for now so that more relevant plantings are - # surfaced; even if we're falling back to crop photos. - # photos_count: { gt: 0 }, - owner_id: { not: owners } - } - one_record = search('*', - limit: 1, - where:, - boost_by: [:created_at], - load: false).first - return records if one_record.nil? - - owners << one_record.owner_id - records << one_record - end - records - end - end -end diff --git a/app/models/concerns/search_seeds.rb b/app/models/concerns/search_seeds.rb deleted file mode 100644 index a6df842e3f..0000000000 --- a/app/models/concerns/search_seeds.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -module SearchSeeds - extend ActiveSupport::Concern - - included do - searchkick merge_mappings: true, - settings: { number_of_shards: 1, number_of_replicas: 0 }, - mappings: { - properties: { - id: { type: :integer }, - created_at: { type: :integer }, - plant_before: { type: :text }, - photos_count: { type: :integer }, - tradable_to: { type: :text } - } - } - - def search_data - { - slug:, - finished: finished?, - gmo:, - active:, - heirloom:, - location: owner.location, - organic:, - quantity:, - plant_before: plant_before&.to_fs(:ymd), - tradable_to:, - tradable:, - - # crop - crop_id:, - crop_name: crop.name, - crop_slug: crop.slug, - - # owner - owner_id:, - owner_location:, - owner_login_name:, - owner_slug:, - - # planting - parent_planting:, - - # counts - photos_count: photos.size, - - # photo - has_photos: photos.size.positive?, - thumbnail_url: default_photo&.thumbnail_url || crop.default_photo&.thumbnail_url, - - created_at: created_at.to_i - } - end - - def self.homepage_records(limit) - search('*', limit:, - where: { - finished: false, - tradable: true, - _or: [{ plant_before: nil }, { plant_before: { lt: Date.today } }] - }, - boost_by: [:created_at], - load: false) - end - end -end diff --git a/app/models/harvest.rb b/app/models/harvest.rb index b130fe097e..18900319c8 100644 --- a/app/models/harvest.rb +++ b/app/models/harvest.rb @@ -5,7 +5,6 @@ class Harvest < ApplicationRecord extend FriendlyId include PhotoCapable include Ownable - include SearchHarvests include Likeable attr_accessor :overall_rating @@ -156,6 +155,10 @@ def crop_name_to_human end end + def self.homepage_records(limit) + recent.one_per_owner.limit(limit) + end + private def crop_must_match_planting diff --git a/app/models/planting.rb b/app/models/planting.rb index 6b90bc3b8a..3df7167496 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -7,7 +7,6 @@ class Planting < ApplicationRecord include Ownable include PredictPlanting include PredictHarvest - include SearchPlantings include Likeable friendly_id :planting_slug, use: %i(slugged finders) @@ -133,6 +132,10 @@ def nearby_same_crop end end + def self.homepage_records(limit) + recent.one_per_owner.limit(limit) + end + private def cannot_be_finished_and_failed diff --git a/app/models/seed.rb b/app/models/seed.rb index d3d8fb47d8..483e4e9b69 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -5,7 +5,6 @@ class Seed < ApplicationRecord include PhotoCapable include Finishable include Ownable - include SearchSeeds friendly_id :seed_slug, use: %i(slugged finders) @@ -73,4 +72,11 @@ def seed_slug def to_s I18n.t('seeds.string', crop: crop.name, owner:) end + + def self.homepage_records(limit) + current.tradable + .where("plant_before IS NULL OR plant_before < ?", Time.zone.today) + .order(created_at: :desc) + .limit(limit) + end end diff --git a/app/views/home/_plantings.html.haml b/app/views/home/_plantings.html.haml index 2e15376905..d288856702 100644 --- a/app/views/home/_plantings.html.haml +++ b/app/views/home/_plantings.html.haml @@ -1,12 +1,12 @@ %h2= t('.recently_planted') - Planting.homepage_records(6).each do |planting| - - next unless planting['thumbnail_url'].present? - = link_to planting_path(slug: planting['slug']), class: 'list-group-item list-group-item-action flex-column align-items-start' do + - next unless planting.thumbnail_url.present? + = link_to planting_path(slug: planting.slug), class: 'list-group-item list-group-item-action flex-column align-items-start' do .d-flex.w-100.justify-content-between.homepage--list-item %p.mb-2 - = image_tag planting['thumbnail_url'], width: 75, class: 'rounded shadow', alt: "Image of #{planting['crop_name']} by #{planting['owner_login_name']}" + = image_tag planting.thumbnail_url, width: 75, class: 'rounded shadow', alt: "Image of #{planting.crop_name} by #{planting.owner_login_name}" .text-right - %h4= planting['crop_name'] - - if planting['planted_from'].present? - %span.badge.badge-success= planting['planted_from'].pluralize - %small.text-muted planted by #{planting['owner_login_name']} + %h4= planting.crop_name + - if planting.planted_from.present? + %span.badge.badge-success= planting.planted_from.pluralize + %small.text-muted planted by #{planting.owner_login_name} diff --git a/app/views/plantings/index.ics.erb b/app/views/plantings/index.ics.erb index f487d8e961..0c4ffdffcc 100644 --- a/app/views/plantings/index.ics.erb +++ b/app/views/plantings/index.ics.erb @@ -7,34 +7,34 @@ cal.description = "Plantings by #{@owner.login_name}" event = Icalendar::Event.new lines = [] - lines << "Quantity: #{planting['quantity'] ? planting['quantity'] : 'unknown' }" - lines << "Planted on: #{planting['planted_at'] ? planting['planted_at'] : 'unknown' }" - lines << "Sunniness: #{planting['sunniness'] ? planting['sunniness'] : 'unknown' }" - lines << "Planted from: #{planting['planted_from'] ? planting['planted_from'] : 'unknown' }" - lines << "First harvest from: #{planting['first_harvest_predicted_at'] ? planting['first_harvest_predicted_at'] : 'unknown' }" - lines << "Last harvest from: #{planting['last_harvest_predicted_at'] ? planting['last_harvest_predicted_at'] : 'unknown' }" - lines << "Finish predicted at: #{planting['finish_predicted_at'] ? planting['finish_predicted_at'] : 'unknown'}" - lines << "Finished at: #{planting['finished_at'] ? planting['finished_at'] : 'unknown' }" + lines << "Quantity: #{planting.quantity || 'unknown' }" + lines << "Planted on: #{planting.planted_at || 'unknown' }" + lines << "Sunniness: #{planting.sunniness || 'unknown' }" + lines << "Planted from: #{planting.planted_from || 'unknown' }" + lines << "First harvest from: #{planting.first_harvest_predicted_at || 'unknown' }" + lines << "Last harvest from: #{planting.last_harvest_predicted_at || 'unknown' }" + lines << "Finish predicted at: #{planting.finish_predicted_at || 'unknown'}" + lines << "Finished at: #{planting.finished_at || 'unknown' }" lines << planting.description - finish_date = Date.parse(planting['finished_at'] || planting['finish_predicted_at'] || planting['last_harvest_predicted_at']) rescue nil + finish_date = (planting.finished_at || planting.finish_predicted_at || planting.last_harvest_predicted_at)&.to_date - event.dtstart = Time.at(planting['created_at']) - event.dtend = finish_date || 1.day.from_now - event.summary = planting['crop_name'] + event.dtstart = planting.created_at + event.dtend = finish_date || 1.day.from_now.to_date + event.summary = planting.crop.name event.description = lines.join("\n") event.ip_class = "PUBLIC" - event.url = planting_url(slug: planting['slug']) + event.url = planting_url(slug: planting.slug) cal.add_event(event) if finish_date && finish_date > Date.today - predicted_date = Date.parse(planting['first_harvest_predicted_at']) if planting['first_harvest_predicted_at'] + predicted_date = planting.first_harvest_predicted_at&.to_date todo = Icalendar::Todo.new todo.dtstart = predicted_date || finish_date || Date.today todo.due = finish_date - todo.summary = "Harvest #{planting['crop_name']}" + todo.summary = "Harvest #{planting.crop.name}" cal.add_todo(todo) @@ -42,9 +42,9 @@ cal.description = "Plantings by #{@owner.login_name}" event = Icalendar::Event.new event.dtstart = predicted_date || finish_date || Date.today event.dtend = finish_date - event.summary = "Harvest #{planting['crop_name']}" + event.summary = "Harvest #{planting.crop.name}" event.ip_class = "PUBLIC" - event.url = planting_url(slug: planting['slug']) + event.url = planting_url(slug: planting.slug) cal.add_event(event) end diff --git a/app/views/plantings/index.rss.haml b/app/views/plantings/index.rss.haml index 6a7536755d..b49b0e9322 100644 --- a/app/views/plantings/index.rss.haml +++ b/app/views/plantings/index.rss.haml @@ -6,15 +6,15 @@ %link= plantings_url - @plantings.each do |planting| %item - %title #{planting['crop_name']} in #{planting['location']} - %pubdate= planting['created_at'].to_fs(:rfc822) + %title #{planting.crop_name} in #{planting.location} + %pubdate= planting.created_at.to_fs(:rfc822) %description :escaped -

Quantity: #{planting['quantity'] ? planting['quantity'] : 'unknown' }

-

Planted on: #{planting['planted_at'] ? planting['planted_at'] : 'unknown' }

-

Sunniness: #{planting['sunniness'] ? planting['sunniness'] : 'unknown' }

-

Planted from: #{planting['planted_from'] ? planting['planted_from'] : 'unknown' }

+

Quantity: #{planting.quantity ? planting.quantity : 'unknown' }

+

Planted on: #{planting.planted_at ? planting.planted_at : 'unknown' }

+

Sunniness: #{planting.sunniness ? planting.sunniness : 'unknown' }

+

Planted from: #{planting.planted_from ? planting.planted_from : 'unknown' }

:escaped_markdown - #{ strip_tags markdownify(planting['description']) } - %link= planting_url(slug: planting['slug']) - %guid= planting_url(slug: planting['slug']) + #{ strip_tags markdownify(planting.description) } + %link= planting_url(slug: planting.slug) + %guid= planting_url(slug: planting.slug) diff --git a/app/views/seeds/index.rss.haml b/app/views/seeds/index.rss.haml index 912e11293e..b07864ca33 100644 --- a/app/views/seeds/index.rss.haml +++ b/app/views/seeds/index.rss.haml @@ -17,6 +17,6 @@

Heirloom? #{seed.heirloom}

- if seed.tradable :escaped -

Will trade #{seed.tradable_to} from #{seed.location ||= 'unknown location'}

+

Will trade #{seed.tradable_to} from #{seed.location || 'unknown location'}

%link= seed_url(slug: seed.slug) %guid= seed_url(slug: seed.slug) diff --git a/config/initializers/rack_attack.rb b/config/initializers/rack_attack.rb index 2d1e40e223..1317f2583e 100644 --- a/config/initializers/rack_attack.rb +++ b/config/initializers/rack_attack.rb @@ -27,6 +27,11 @@ class Rack::Attack end end + # Abusive services + blocklist('block Semrush crawler') do |request| + request.user_agent.to_s.downcase.include?('semrush') + end + ### Custom Response Headers ### # Add Retry-After header to throttled responses diff --git a/db/migrate/20191226051019_elastic_indexing.rb b/db/migrate/20191226051019_elastic_indexing.rb index a1c37885a7..2ad42ddbea 100644 --- a/db/migrate/20191226051019_elastic_indexing.rb +++ b/db/migrate/20191226051019_elastic_indexing.rb @@ -4,12 +4,6 @@ class ElasticIndexing < ActiveRecord::Migration[5.2] def up say 'indexing crops' Crop.reindex - say 'indexing plantings' - Planting.reindex - say 'indexing seeds' - Seed.reindex - say 'indexing harvests' - Harvest.reindex say 'indexing photos' Photo.reindex end diff --git a/lib/tasks/search.rake b/lib/tasks/search.rake index 396a9f33bd..cd13590bc7 100644 --- a/lib/tasks/search.rake +++ b/lib/tasks/search.rake @@ -4,8 +4,5 @@ namespace :search do desc 'reindex' task reindex: :environment do Crop.reindex - Planting.reindex - Harvest.reindex - Seed.reindex end end diff --git a/spec/controllers/harvests_controller_spec.rb b/spec/controllers/harvests_controller_spec.rb index c6e61de4a8..b8768c1f91 100644 --- a/spec/controllers/harvests_controller_spec.rb +++ b/spec/controllers/harvests_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe HarvestsController, :search do +describe HarvestsController do login_member def valid_attributes @@ -22,14 +22,12 @@ def valid_attributes let!(:tomato_harvest) { create(:harvest, owner_id: first_member.id, crop_id: tomato.id) } let!(:maize_harvest) { create(:harvest, owner_id: second_member.id, crop_id: maize.id) } - before { Harvest.reindex } - describe "assigns all harvests as @harvests" do before { get :index, params: {} } it { expect(assigns(:harvests).size).to eq 2 } - it { expect(assigns(:harvests)[0].slug).to eq tomato_harvest.slug } - it { expect(assigns(:harvests)[1].slug).to eq maize_harvest.slug } + it { expect(assigns(:harvests)).to include(tomato_harvest) } + it { expect(assigns(:harvests)).to include(maize_harvest) } end describe "picks up owner from params and shows owner's harvests only" do diff --git a/spec/controllers/plantings_controller_spec.rb b/spec/controllers/plantings_controller_spec.rb index 7414835bd2..dbc385d141 100644 --- a/spec/controllers/plantings_controller_spec.rb +++ b/spec/controllers/plantings_controller_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe PlantingsController, :search do +describe PlantingsController do login_member def valid_attributes @@ -12,7 +12,7 @@ def valid_attributes } end - describe "GET index", :search do + describe "GET index" do let!(:first_member) { create(:member) } let!(:second_member) { create(:member) } let!(:tomato) { create(:tomato) } @@ -20,16 +20,12 @@ def valid_attributes let!(:tomato_planting) { create(:planting, crop: tomato, owner: first_member, created_at: 1.day.ago) } let!(:maize_planting) { create(:planting, crop: maize, owner: second_member, created_at: 5.days.ago) } - before do - Planting.reindex - end - describe "assigns all plantings as @plantings" do before { get :index } it { expect(assigns(:plantings).size).to eq 2 } - it { expect(assigns(:plantings)[0]['slug']).to eq tomato_planting.slug } - it { expect(assigns(:plantings)[1]['slug']).to eq maize_planting.slug } + it { expect(assigns(:plantings)[0].slug).to eq tomato_planting.slug } + it { expect(assigns(:plantings)[1].slug).to eq maize_planting.slug } end describe "picks up owner from params and shows owner's plantings only" do @@ -37,14 +33,14 @@ def valid_attributes it { expect(assigns(:owner)).to eq first_member } it { expect(assigns(:plantings).size).to eq 1 } - it { expect(assigns(:plantings).first['slug']).to eq tomato_planting.slug } + it { expect(assigns(:plantings).first.slug).to eq tomato_planting.slug } end describe "picks up crop from params and shows the plantings for the crop only" do before { get :index, params: { crop_slug: maize.slug } } it { expect(assigns(:crop)).to eq maize } - it { expect(assigns(:plantings).first['slug']).to eq maize_planting.slug } + it { expect(assigns(:plantings).first.slug).to eq maize_planting.slug } end end diff --git a/spec/controllers/seeds_controller_spec.rb b/spec/controllers/seeds_controller_spec.rb index 9ae4b58635..97a971d53d 100644 --- a/spec/controllers/seeds_controller_spec.rb +++ b/spec/controllers/seeds_controller_spec.rb @@ -2,13 +2,12 @@ require 'rails_helper' -describe SeedsController, :search do +describe SeedsController do let(:owner) { create(:member) } describe "GET index" do describe "picks up owner from params" do before do - Seed.reindex get :index, params: { member_slug: owner.slug } end @@ -25,7 +24,6 @@ let!(:planting) { create(:planting, owner:) } before do - Seed.reindex get :new, params: { planting_slug: planting.to_param } end diff --git a/spec/factories/harvests.rb b/spec/factories/harvests.rb index eab2192521..1772f066f3 100644 --- a/spec/factories/harvests.rb +++ b/spec/factories/harvests.rb @@ -29,8 +29,5 @@ end trait :reindex do - after(:create) do |harvest, _evaluator| - harvest.reindex(refresh: true) - end end end diff --git a/spec/factories/planting.rb b/spec/factories/planting.rb index 815d349c6c..a00c36bcc4 100644 --- a/spec/factories/planting.rb +++ b/spec/factories/planting.rb @@ -68,11 +68,5 @@ planting.save end end - - trait :reindex do - after(:create) do |planting, _evaluator| - planting.reindex(refresh: true) - end - end end end diff --git a/spec/factories/seeds.rb b/spec/factories/seeds.rb index b71aeaa4bb..deafb53020 100644 --- a/spec/factories/seeds.rb +++ b/spec/factories/seeds.rb @@ -31,11 +31,5 @@ factory :untradable_seed do tradable_to { "nowhere" } end - - trait :reindex do - after(:create) do |seed, _evaluator| - seed.reindex(refresh: true) - end - end end end diff --git a/spec/features/harvests/browse_harvests_spec.rb b/spec/features/harvests/browse_harvests_spec.rb index 7d748d870d..7fe8e3438b 100644 --- a/spec/features/harvests/browse_harvests_spec.rb +++ b/spec/features/harvests/browse_harvests_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe "browse harvests", :search do +describe "browse harvests" do subject { page } let!(:harvest) { create(:harvest, owner: member) } @@ -11,10 +11,9 @@ include_context 'signed in member' describe 'blank optional fields' do - let!(:harvest) { create(:harvest, :no_description, :reindex) } + let!(:harvest) { create(:harvest, :no_description) } before do - Harvest.reindex visit harvests_path end @@ -24,10 +23,9 @@ end describe "filled in optional fields" do - let!(:harvest) { create(:harvest, :long_description, :reindex) } + let!(:harvest) { create(:harvest, :long_description) } before do - Harvest.reindex visit harvests_path end diff --git a/spec/features/home/home_spec.rb b/spec/features/home/home_spec.rb index e068522f9b..0e53958a76 100644 --- a/spec/features/home/home_spec.rb +++ b/spec/features/home/home_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe "home page", :search do +describe "home page" do subject { page } let(:member) { create(:member) } @@ -14,9 +14,9 @@ let(:seed) { create(:tradable_seed, owner: member, crop:) } let(:harvest) { create(:harvest, owner: member, crop:) } - let!(:tradable_seed) { create(:tradable_seed, :reindex, finished: false) } - let!(:finished_seed) { create(:tradable_seed, :reindex, finished: true) } - let!(:untradable_seed) { create(:untradable_seed, :reindex) } + let!(:tradable_seed) { create(:tradable_seed, finished: false) } + let!(:finished_seed) { create(:tradable_seed, finished: true) } + let!(:untradable_seed) { create(:untradable_seed) } before do # Add photos, so they can appear on home page @@ -25,9 +25,6 @@ harvest.photos << photo Crop.reindex - Planting.reindex - Seed.reindex - Harvest.reindex visit root_path end diff --git a/spec/features/likeable_spec.rb b/spec/features/likeable_spec.rb index 530db5e28e..b6072a1eb2 100644 --- a/spec/features/likeable_spec.rb +++ b/spec/features/likeable_spec.rb @@ -8,7 +8,7 @@ let!(:activity) { create(:activity, :reindex, owner: member) } let!(:photo) { create(:photo, owner: member) } let!(:harvest) { create(:harvest, :reindex, owner: member) } - let!(:planting) { create(:planting, :reindex, owner: member) } + let!(:planting) { create(:planting, owner: member) } include_context 'signed in member' diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 1a17ba4055..bba98e436e 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -10,8 +10,6 @@ create(:planting, garden:, owner: member, planted_at: Date.parse("2013-03-10")) end - before { Planting.reindex } - context 'signed in' do include_context 'signed in member' before { visit new_planting_path } @@ -223,9 +221,6 @@ expect(page).to have_content "Aug 2014" expect(page).to have_content "4/5" - # ensure we've indexed in elastic search - planting.reindex(refresh: true) - # shouldn't be on the page visit plantings_path expect(page).to have_no_content "maize" diff --git a/spec/features/rss/plantings_spec.rb b/spec/features/rss/plantings_spec.rb index 06f19fb6d1..8664459330 100644 --- a/spec/features/rss/plantings_spec.rb +++ b/spec/features/rss/plantings_spec.rb @@ -9,7 +9,6 @@ end it 'The index title is what we expect' do - Planting.reindex visit plantings_path(format: 'rss') expect(page).to have_content "Recent plantings from " \ "#{@owner || 'all members'} (#{ENV.fetch('GROWSTUFF_SITE_NAME', nil)})" diff --git a/spec/models/harvest_spec.rb b/spec/models/harvest_spec.rb index 535dedd4c2..c55a9bf96d 100644 --- a/spec/models/harvest_spec.rb +++ b/spec/models/harvest_spec.rb @@ -148,6 +148,19 @@ end end + describe '.homepage_records' do + it 'returns unique harvests per owner' do + member1 = create(:member) + member2 = create(:member) + create(:harvest, owner: member1, created_at: 1.day.ago) + h2 = create(:harvest, owner: member1, created_at: 1.hour.ago) + h3 = create(:harvest, owner: member2, created_at: 2.hours.ago) + + records = described_class.homepage_records(5) + expect(records).to contain_exactly(h2, h3) + end + end + context "stringification" do let(:crop) { create(:crop, name: "apricot") } diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 021e78c81a..03ffe813fa 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -596,16 +596,14 @@ def one_hundred_day_old_planting it { expect(member.plantings.active).not_to include(failed_planting) } end - describe 'homepage', :search do + describe 'homepage' do subject { described_class.homepage_records(100) } - let!(:interesting_planting) { create(:planting, :reindex, :with_photo) } - let!(:finished_interesting_planting) { create(:finished_planting, :reindex, :with_photo) } - let!(:planting) { create(:planting, :reindex) } - - before { described_class.reindex } + let!(:interesting_planting) { create(:planting, :with_photo) } + let!(:finished_interesting_planting) { create(:finished_planting, :with_photo) } + let!(:planting) { create(:planting) } it { expect(subject.count).to eq 3 } - it { expect(subject.map(&:id)).to eq([interesting_planting.id.to_s, finished_interesting_planting.id.to_s, planting.id.to_s]) } + it { expect(subject.map(&:id)).to include(interesting_planting.id, finished_interesting_planting.id, planting.id) } end end diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index dcc6d3b0b1..bda11204b6 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -213,16 +213,14 @@ end end - describe 'homepage', :search do + describe 'homepage' do subject { described_class.homepage_records(100) } - let!(:tradable_seed) { create(:tradable_seed, :reindex, finished: false) } - let!(:finished_seed) { create(:tradable_seed, :reindex, finished: true) } - let!(:untradable_seed) { create(:untradable_seed, :reindex) } - - before { described_class.reindex } + let!(:tradable_seed) { create(:tradable_seed, finished: false) } + let!(:finished_seed) { create(:tradable_seed, finished: true) } + let!(:untradable_seed) { create(:untradable_seed) } it { expect(subject.count).to eq 1 } - it { expect(subject.first.id).to eq tradable_seed.id.to_s } + it { expect(subject.first.id).to eq tradable_seed.id } end end diff --git a/spec/requests/plantings_spec.rb b/spec/requests/plantings_spec.rb index 1a1126cb77..e47b7752e2 100644 --- a/spec/requests/plantings_spec.rb +++ b/spec/requests/plantings_spec.rb @@ -15,7 +15,7 @@ before do @member = create(:interesting_member) - @predictable_planting = create(:predictable_planting, owner: @member, planted_at: 1.days.ago, days_to_first_harvest: 10, + @predictable_planting = create(:predictable_planting, owner: @member, planted_at: 1.day.ago, days_to_first_harvest: 10, days_to_last_harvest: 20) @predictable_planting.crop.update(median_days_to_first_harvest: 10) @@ -24,7 +24,6 @@ @finished_planting = create(:finished_planting, owner: @member) @annual_planting = create(:annual_planting, owner: @member) @perennial_planting = create(:perennial_planting, owner: @member) - Planting.reindex end describe "GET /members/x/plantings.ics" do @@ -34,19 +33,17 @@ calendar = Icalendar::Parser.new(response.body, true).parse.first expect(calendar.description[0].to_s).to eq "Plantings by #{@member.login_name}" events = calendar.events - expect(events.length).to eq 7 # There are 8, but finished plantings aren't included + expect(events.length).to eq 7 - # TODO: Better date comparison - # Predicted finish should be used - expect(events[1].summary.to_s).to include @predictable_planting.crop.name - expect(events[1].dtstart.to_datetime.to_i).to be_within(1.second).of @predictable_planting.created_at.to_i - expect(events[1].dtend.to_date).to eq @predictable_planting.finish_predicted_at + predictable_event = events.find { |e| e.dtend.to_date == @predictable_planting.finish_predicted_at } + expect(predictable_event.summary.to_s).to include @predictable_planting.crop.name + expect(predictable_event.dtstart.to_datetime.to_i).to be_within(1.second).of @predictable_planting.created_at.to_i # Actual finish should be used - # expect(events[4].dtend.to_date).to be_within(1.second).of @finised_planting.finished_at + # expect(events[4].dtend.to_date).to be_within(1.second).of @finished_planting.finished_at # Otherwise, tomorrow should be used - expect(events[3].dtend.to_date).to eq 1.day.from_now.to_date + expect(events.map { |e| e.dtend.to_date }).to include 1.day.from_now.to_date # TBA: Perennial and annual crops predictions of 'next' harvest date don't really fit @@ -86,16 +83,18 @@ data = CSV.parse(response.body, headers: true) expect(data.headers).to eq expected_headers - expect(data[1]["Crop name"]).to eq @predictable_planting.crop.name - expect(data[1]["Owner name"]).to eq @member.to_s - expect(data[1]["Garden name"]).to eq @predictable_planting.garden.to_s - expect(data[1]["Description"]).to eq @predictable_planting.description - expect(data[1]["Date planted"]).to eq @predictable_planting.planted_at.to_fs(:db) - expect(data[1]["Quantity"].to_i).to eq @predictable_planting.quantity - expect(data[1]["Sunniness"]).to eq @predictable_planting.sunniness - expect(data[1]["Planted from"]).to eq @predictable_planting.planted_from - expect(data[1]["Date added"]).to eq @predictable_planting.created_at.to_fs(:db) - expect(data[1]["License"]).to eq "CC-BY-SA Growstuff http://growstuff.org/" + row = data.detect { |crop_name| @predictable_planting.id.to_s == crop_name['Id'] } + + expect(row["Crop name"]).to eq @predictable_planting.crop.name + expect(row["Owner name"]).to eq @member.to_s + expect(row["Garden name"]).to eq @predictable_planting.garden.to_s + expect(row["Description"]).to eq @predictable_planting.description + expect(row["Date planted"]).to eq @predictable_planting.planted_at.to_fs(:db) + expect(row["Quantity"].to_i).to eq @predictable_planting.quantity + expect(row["Sunniness"]).to eq @predictable_planting.sunniness + expect(row["Planted from"]).to eq @predictable_planting.planted_from + expect(row["Date added"]).to eq @predictable_planting.created_at.to_fs(:db) + expect(row["License"]).to eq "CC-BY-SA Growstuff http://growstuff.org/" expect(data.count).to eq 6 end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 11c62a0219..0c14ef865e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -46,9 +46,6 @@ def index_everything # reindex models Crop.reindex - Harvest.reindex - Planting.reindex - Seed.reindex end config.before(:suite) do diff --git a/spec/views/harvests/index.rss.haml_spec.rb b/spec/views/harvests/index.rss.haml_spec.rb index c63dd4348d..1283fe48aa 100644 --- a/spec/views/harvests/index.rss.haml_spec.rb +++ b/spec/views/harvests/index.rss.haml_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'harvests/index.rss.haml', :search do +describe 'harvests/index.rss.haml' do before do controller.stub(:current_user) { nil } @member = create(:member) @@ -12,8 +12,7 @@ @harvest2 = create(:harvest, crop: @tomato) @harvest3 = create(:harvest, crop: @tomato) - Harvest.searchkick_index.refresh - assign(:harvests, Harvest.search(load: false)) + assign(:harvests, Harvest.all) end context 'all harvests' do diff --git a/spec/views/home/_seeds.html.haml_spec.rb b/spec/views/home/_seeds.html.haml_spec.rb index 4ebb780e3e..b589c02606 100644 --- a/spec/views/home/_seeds.html.haml_spec.rb +++ b/spec/views/home/_seeds.html.haml_spec.rb @@ -2,12 +2,11 @@ require 'rails_helper' -describe 'home/_seeds.html.haml', :search, type: "view" do +describe 'home/_seeds.html.haml', type: "view" do let!(:seed) { create(:tradable_seed, owner:) } let(:owner) { create(:london_member) } before do - Seed.searchkick_index.refresh render end diff --git a/spec/views/plantings/index.rss.haml_spec.rb b/spec/views/plantings/index.rss.haml_spec.rb index daa1cc7cac..b604970b0c 100644 --- a/spec/views/plantings/index.rss.haml_spec.rb +++ b/spec/views/plantings/index.rss.haml_spec.rb @@ -2,9 +2,9 @@ require 'rails_helper' -describe 'plantings/index.rss.haml', :search do +describe 'plantings/index.rss.haml' do before do - controller.stub(:current_user) { nil } + allow(view).to receive(:current_user).and_return(nil) end context 'all plantings' do @@ -12,8 +12,7 @@ @planting = create(:planting) @sunny = create(:sunny_planting) @seedling = create(:seedling_planting) - Planting.searchkick_index.refresh - assign(:plantings, Planting.search(load: false)) + assign(:plantings, Planting.all) render end diff --git a/spec/views/seeds/index.rss.haml_spec.rb b/spec/views/seeds/index.rss.haml_spec.rb index af5c2fc43c..ddc081d047 100644 --- a/spec/views/seeds/index.rss.haml_spec.rb +++ b/spec/views/seeds/index.rss.haml_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -describe 'seeds/index.rss.haml', :search do +describe 'seeds/index.rss.haml' do before do controller.stub(:current_user) { nil } end @@ -26,8 +26,7 @@ let!(:tradable) { create(:tradable_seed) } before do - Seed.searchkick_index.refresh - assign(:seeds, Seed.search(load: false)) + assign(:seeds, Seed.all) render end @@ -51,8 +50,7 @@ before do assign(:owner, seed.owner) - Seed.searchkick_index.refresh - assign(:seeds, Seed.search(load: false)) + assign(:seeds, Seed.all) render end