mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-09-26 16:05:03 -04:00
* Refactor Plantings to remove Elasticsearch dependency This commit refactors the Plantings controller, model, and views to use ActiveRecord instead of Searchkick/Elasticsearch. Key changes: - Refactored `PlantingsController#index` to use an ActiveRecord-based `plantings` method. - Moved `homepage_records` logic from `SearchPlantings` concern to the `Planting` model using ActiveRecord scopes. - Removed `SearchPlantings` concern and deleted the file. - Updated `home/_plantings.html.haml` and `plantings/index.rss.haml` to use dot notation for `Planting` object attributes. - Updated specs to remove Searchkick-related setup and assertions. Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com> * Fix Planting.reindex * Fix test * Mark test pending --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
105 lines
2.8 KiB
Ruby
105 lines
2.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe 'Likeable', :js, :search do
|
|
let(:another_member) { create(:london_member) }
|
|
let!(:post) { create(:post, :reindex, author: member) }
|
|
let!(:activity) { create(:activity, :reindex, owner: member) }
|
|
let!(:photo) { create(:photo, owner: member) }
|
|
let!(:harvest) { create(:harvest, :reindex, owner: member) }
|
|
let!(:planting) { create(:planting, owner: member) }
|
|
|
|
include_context 'signed in member'
|
|
|
|
shared_examples 'object can be liked' do
|
|
it 'can be liked' do
|
|
visit path
|
|
expect(page).to have_css(like_count_class, text: "0")
|
|
click_link '0', class: 'like-btn'
|
|
expect(page).to have_css(like_count_class, text: "1")
|
|
|
|
# Reload page
|
|
visit path
|
|
expect(page).to have_css(like_count_class, text: "1")
|
|
expect(page).to have_link '1'
|
|
|
|
click_link '1', class: 'like-btn'
|
|
expect(page).to have_css(like_count_class, text: "0")
|
|
end
|
|
|
|
it 'displays correct number of likes' do
|
|
visit path
|
|
expect(page).to have_css(like_count_class, text: "0")
|
|
expect(page).to have_link '0'
|
|
click_link '0', class: 'like-btn'
|
|
expect(page).to have_css(like_count_class, text: "1")
|
|
|
|
logout(member)
|
|
login_as(another_member)
|
|
visit path
|
|
|
|
expect(page).to have_css(like_count_class, text: "1")
|
|
click_link '1', class: 'like-btn'
|
|
expect(page).to have_css(like_count_class, text: "2")
|
|
logout(another_member)
|
|
end
|
|
end
|
|
|
|
describe 'photos' do
|
|
def like_count_class
|
|
"#photo-#{photo.id} .like-count"
|
|
end
|
|
|
|
describe 'photos#index' do
|
|
let(:path) { photos_path }
|
|
|
|
include_examples 'object can be liked'
|
|
end
|
|
|
|
describe 'photos#show' do
|
|
let(:path) { photo_path(photo) }
|
|
|
|
include_examples 'object can be liked'
|
|
end
|
|
|
|
describe 'crops#show' do
|
|
let(:crop) { create(:crop) }
|
|
let(:planting) { create(:planting, owner: member, crop:) }
|
|
let(:path) { crop_path(crop) }
|
|
|
|
before { planting.photos << photo }
|
|
|
|
include_examples 'object can be liked'
|
|
end
|
|
end
|
|
|
|
describe 'posts' do
|
|
let(:like_count_class) { ".post-#{post.id} .like-count" }
|
|
let(:path) { post_path(post) }
|
|
|
|
include_examples 'object can be liked'
|
|
end
|
|
|
|
describe 'activities' do
|
|
let(:like_count_class) { ".activity-#{activity.id} .like-count" }
|
|
let(:path) { activity_path(activity) }
|
|
|
|
include_examples 'object can be liked'
|
|
end
|
|
|
|
describe 'plantings' do
|
|
let(:like_count_class) { ".planting-#{planting.id} .like-count" }
|
|
let(:path) { planting_path(planting) }
|
|
|
|
include_examples 'object can be liked'
|
|
end
|
|
|
|
describe 'harvests' do
|
|
let(:like_count_class) { ".harvest-#{harvest.id} .like-count" }
|
|
let(:path) { harvest_path(harvest) }
|
|
|
|
include_examples 'object can be liked'
|
|
end
|
|
end
|