Files
grecia/spec/shared/system/followable.rb
Javi Martín 92ddcb7aef Use JavaScript in system tests by default
JavaScript is used by about 98% of web users, so by testing without it
enabled, we're only testing that the application works for a very
reduced number of users.

We proceeded this way in the past because CONSUL started using Rails 4.2
and truncating the database between JavaScript tests with database
cleaner, which made these tests terribly slow.

When we upgraded to Rails 5.1 and introduced system tests, we started
using database transactions in JavaScript tests, making these tests much
faster. So now we can use JavaScript tests everywhere without critically
slowing down our test suite.
2021-04-07 14:41:06 +02:00

103 lines
3.1 KiB
Ruby

shared_examples "followable" do |followable_class_name, followable_path, followable_path_arguments|
let!(:arguments) { {} }
let!(:followable) { create(followable_class_name) }
def dom_id(record)
ActionView::RecordIdentifier.dom_id(record)
end
before do
followable_path_arguments.each do |argument_name, path_to_value|
arguments.merge!("#{argument_name}": followable.send(path_to_value))
end
end
context "Show" do
scenario "Should not display follow button when there is no logged user" do
visit send(followable_path, arguments)
within "##{dom_id(followable)}" do
expect(page).not_to have_link("Follow")
end
end
scenario "Should display follow button when user is logged in" do
user = create(:user)
login_as(user)
visit send(followable_path, arguments)
within "##{dom_id(followable)}" do
expect(page).to have_link("Follow #{followable.model_name.human.downcase}")
end
end
scenario "Should display follow button when user is logged and is not following" do
user = create(:user)
login_as(user)
visit send(followable_path, arguments)
expect(page).to have_link("Follow #{followable.model_name.human.downcase}")
end
scenario "Should display unfollow after user clicks on follow button" do
user = create(:user)
login_as(user)
visit send(followable_path, arguments)
within "##{dom_id(followable)}" do
click_link("Follow #{followable.model_name.human.downcase}")
expect(page).not_to have_link("Follow")
expect(page).to have_link("Following")
end
end
scenario "Should display new follower notice after user clicks on follow button" do
user = create(:user)
login_as(user)
visit send(followable_path, arguments)
within "##{dom_id(followable)}" do
click_link("Follow #{followable.model_name.human.downcase}")
end
expect(page).to have_content "We will notify you of changes as they occur"
end
scenario "Display unfollow button when user already following" do
user = create(:user, followables: [followable])
login_as(user)
visit send(followable_path, arguments)
expect(page).to have_link("Following")
end
scenario "Updates follow button & show destroy notice after unfollow button is clicked" do
user = create(:user, followables: [followable])
login_as(user)
visit send(followable_path, arguments)
within "##{dom_id(followable)}" do
click_link("Unfollow #{followable.model_name.human.downcase}")
expect(page).not_to have_link("Unfollow")
expect(page).to have_link("Follow #{followable.model_name.human.downcase}")
end
end
scenario "Should display destroy follower notice after user clicks on unfollow button" do
user = create(:user, followables: [followable])
login_as(user)
visit send(followable_path, arguments)
within "##{dom_id(followable)}" do
click_link("Unfollow #{followable.model_name.human.downcase}")
end
expect(page).to have_content "You will no longer receive notifications"
end
end
end