mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-30 10:49:03 -04:00
- Renamed all instances of 'Activity' to 'Job' in views, controllers, and models. - Updated routes to reflect the change from activities to jobs. - Modified database schema to rename the activities table to jobs and adjusted related columns. - Updated locale files to change activity-related translations to jobs. - Adjusted tests to ensure they reference jobs instead of activities. - Removed the category field from jobs as they are now a plain list. - Updated seed data and sample data generation to create jobs instead of activities.
97 lines
2.5 KiB
Ruby
97 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe 'Likeable', :js do
|
|
let(:another_member) { create(:london_member) }
|
|
let!(:post) { create(:post, author: member) }
|
|
let!(:photo) { create(:photo, owner: member) }
|
|
let!(:harvest) { create(:harvest, 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 '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
|