mirror of
https://github.com/Growstuff/growstuff.git
synced 2025-12-30 13:07:49 -05:00
* Fix todo * Rubcop * Rubocop * Rubocop * Rename harvests_routing_spec.rb to harvests_controller_routing_spec.rb Making codeclimate happier * Rename for CodeFactor: updates_routing_spec.rb to posts_controller_updates_routing_spec.rb For codefactor * Rename for CodeFactor: follows_routing_spec.rb to follows_controller_routing_spec.rb * Rename for CodeFactor: forums_routing_spec.rb to forums_controller_routing_spec.rb * Rename spec/routing/roles_routing_spec.rb to spec/routing/admin/roles_controller_routing_spec.rb * Rename authentications_routing_spec.rb to authentications_controller_routing_spec.rb * Rename for CodeFactor: plantings_routing_spec.rb to plantings_controller_routing_spec.rb * Rename for CodeFactor: scientific_names_routing_spec.rb to scientific_names_controller_routing_spec.rb * Rename for CodeFactor: seeds_routing_spec.rb to seeds_controller_routing_spec.rb * Rename for CodeFactor: comments_routing_spec.rb to comments_controller_routing_spec.rb * Rename for CodeFactor: garden_types_routing_spec.rb to garden_types_controller_routing_spec.rb * Rename for CodeFactor: admin_routing_spec.rb to admin_controller_routing_spec.rb * Rename for CodeFactor: gardens_routing_spec.rb to gardens_controller_routing_spec.rb * Rename for CodeFactor: photos_routing_spec.rb to photos_controller_routing_spec.rb * Rename for CodeFactor: plant_parts_routing_spec.rb to plant_parts_controller_routing_spec.rb * Rename for CodeFactor: crops_routing_spec.rb to crops_controller_routing_spec.rb * [CodeFactor] Apply fixes * Rename * Code factor bot --------- Co-authored-by: Cesy <cesy.avon@gmail.com> Co-authored-by: codefactor-io <support@codefactor.io>
114 lines
3.1 KiB
Ruby
114 lines
3.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe 'Likeable', :js, :search do
|
|
let(:another_member) { FactoryBot.create(:london_member) }
|
|
let!(:post) { FactoryBot.create(:post, :reindex, author: member) }
|
|
let!(:photo) { FactoryBot.create(:photo, :reindex, owner: member) }
|
|
|
|
before do
|
|
Photo.reindex
|
|
end
|
|
|
|
include_context 'signed in member'
|
|
|
|
describe 'photos' do
|
|
def like_count_class
|
|
"#photo-#{photo.id} .like-count"
|
|
end
|
|
|
|
shared_examples 'photo 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#index' do
|
|
let(:path) { photos_path }
|
|
|
|
include_examples 'photo can be liked'
|
|
end
|
|
|
|
describe 'photos#show' do
|
|
let(:path) { photo_path(photo) }
|
|
|
|
include_examples 'photo can be liked'
|
|
end
|
|
|
|
describe 'crops#show' do
|
|
let(:crop) { FactoryBot.create(:crop) }
|
|
let(:planting) { FactoryBot.create(:planting, owner: member, crop:) }
|
|
let(:path) { crop_path(crop) }
|
|
|
|
before { planting.photos << photo }
|
|
|
|
include_examples 'photo can be liked'
|
|
end
|
|
end
|
|
|
|
describe 'posts' do
|
|
let(:like_count_class) { "#post-#{post.id} .like-count" }
|
|
|
|
before { visit post_path(post) }
|
|
|
|
it 'can be liked' do
|
|
expect(page).to have_css(like_count_class, text: "0")
|
|
expect(page).to have_link 'Like'
|
|
click_link 'Like', class: 'like-btn'
|
|
expect(page).to have_css(like_count_class, text: "1")
|
|
|
|
# Reload page
|
|
visit post_path(post)
|
|
expect(page).to have_css(like_count_class, text: "1")
|
|
expect(page).to have_link 'Unlike'
|
|
|
|
click_link 'Unlike', class: 'like-btn'
|
|
expect(page).to have_css(like_count_class, text: "0")
|
|
end
|
|
|
|
it 'displays correct number of likes' do
|
|
expect(page).to have_link 'Like'
|
|
click_link 'Like', class: 'like-btn'
|
|
expect(page).to have_css(like_count_class, text: "1")
|
|
|
|
logout(member)
|
|
login_as(another_member)
|
|
visit post_path(post)
|
|
|
|
expect(page).to have_link 'Like'
|
|
click_link 'Like', class: 'like-btn'
|
|
expect(page).to have_css(like_count_class, text: "2")
|
|
logout(another_member)
|
|
end
|
|
end
|
|
end
|