Add followable specific notices to follows controller actions and render notice on AJAX JS response.

This commit is contained in:
Senén Rodero Rodríguez
2017-07-19 19:43:05 +02:00
parent 3b1335062f
commit dec7d2d2b5
6 changed files with 63 additions and 5 deletions

View File

@@ -49,10 +49,23 @@ shared_examples "followable" do |followable_class_name, followable_path, followa
within "##{dom_id(followable)}" do
click_link "Follow"
expect(page).not_to have_link "Follow"
expect(page).to have_link "Unfollow"
end
end
scenario "Should display new follower notice after user clicks on follow button", :js do
user = create(:user)
login_as(user)
visit send(followable_path, arguments)
within "##{dom_id(followable)}" do
click_link "Follow"
end
expect(page).to have_content strip_tags(t("shared.followable.#{followable_class_name}.create.notice_html"))
end
scenario "Display unfollow button when user already following" do
user = create(:user)
follow = create(:follow, user: user, followable: followable)
@@ -63,7 +76,7 @@ shared_examples "followable" do |followable_class_name, followable_path, followa
expect(page).to have_link("Unfollow")
end
scenario "Should display follow button after user clicks on unfollow button", :js do
scenario "Should update follow button and show destroy notice after user clicks on unfollow button", :js do
user = create(:user)
follow = create(:follow, user: user, followable: followable)
login_as(user)
@@ -72,10 +85,24 @@ shared_examples "followable" do |followable_class_name, followable_path, followa
within "##{dom_id(followable)}" do
click_link "Unfollow"
expect(page).not_to have_link "Unfollow"
expect(page).to have_link "Follow"
end
end
scenario "Should display destroy follower notice after user clicks on unfollow button", :js do
user = create(:user)
follow = create(:follow, user: user, followable: followable)
login_as(user)
visit send(followable_path, arguments)
within "##{dom_id(followable)}" do
click_link "Unfollow"
end
expect(page).to have_content strip_tags(t("shared.followable.#{followable_class_name}.destroy.notice_html"))
end
end
end