Files
grecia/spec/system/topics_spec.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

147 lines
4.6 KiB
Ruby

require "rails_helper"
describe "Topics" do
context "Concerns" do
it_behaves_like "notifiable in-app", :topic_with_community
end
context "New" do
scenario "Create new topic link should redirect to sign up for anonymous users" do
proposal = create(:proposal)
community = proposal.community
logout
visit community_path(community)
click_link "Create topic"
expect(page).to have_content "Sign in with:"
expect(page).to have_current_path(new_user_session_path)
end
scenario "Can access to new topic page with user logged" do
proposal = create(:proposal)
community = proposal.community
user = create(:user)
login_as(user)
visit community_path(community)
click_link "Create topic"
expect(page).to have_content "Create a topic"
end
scenario "Should have content on new topic page" do
proposal = create(:proposal)
community = proposal.community
user = create(:user)
login_as(user)
visit community_path(community)
click_link "Create topic"
expect(page).to have_content "Title"
expect(page).to have_content "Initial text"
expect(page).to have_content "Recommendations to create a topic"
expect(page).to have_content "Do not write the topic title or whole sentences in capital letters. On the internet that is considered shouting. And no one likes to be yelled at."
expect(page).to have_content "Any topic or comment that implies an illegal action will be eliminated, also those that intend to sabotage the spaces of the subject, everything else is allowed."
expect(page).to have_content "Enjoy this space, the voices that fill it, it's yours too."
expect(page).to have_button("Create topic")
end
end
context "Create" do
scenario "Can create a new topic" do
proposal = create(:proposal)
community = proposal.community
user = create(:user)
login_as(user)
visit new_community_topic_path(community)
fill_in "topic_title", with: "New topic title"
fill_in "topic_description", with: "Topic description"
click_button "Create topic"
expect(page).to have_content "New topic title"
expect(page).to have_current_path(community_path(community))
end
scenario "Can not create a new topic when user not logged" do
proposal = create(:proposal)
community = proposal.community
visit new_community_topic_path(community)
expect(page).to have_content "You do not have permission to carry out the action 'new' on topic."
end
end
context "Edit" do
scenario "Can edit a topic" do
proposal = create(:proposal)
community = proposal.community
user = create(:user)
topic = create(:topic, community: community, author: user)
login_as(user)
visit edit_community_topic_path(community, topic)
fill_in "topic_title", with: "Edit topic title"
fill_in "topic_description", with: "Edit topic description"
click_button "Edit topic"
expect(page).to have_content "Edit topic title"
expect(page).to have_current_path(community_path(community))
end
scenario "Can not edit a topic when user logged is not an author" do
proposal = create(:proposal)
community = proposal.community
topic = create(:topic, community: community)
user = create(:user)
login_as(user)
visit edit_community_topic_path(community, topic)
expect(page).to have_content "You do not have permission to carry out the action 'edit' on topic."
end
end
context "Show" do
scenario "Can show topic" do
proposal = create(:proposal)
community = proposal.community
topic = create(:topic, community: community)
visit community_topic_path(community, topic)
expect(page).to have_content community.proposal.title
expect(page).to have_content topic.title
end
end
context "Destroy" do
scenario "Can destroy a topic" do
user = create(:user)
topic = create(:topic, :with_community, author: user)
login_as(user)
visit community_topic_path(topic.community, topic)
click_link "Delete topic"
expect(page).to have_content "Topic deleted successfully."
expect(page).not_to have_content topic.title
expect(page).to have_current_path(community_path(topic.community))
end
scenario "Can not destroy a topic when user logged is not an author" do
user = create(:user)
topic = create(:topic, :with_community)
login_as(user)
visit community_path(topic.community)
expect(page).not_to have_link "Delete"
end
end
end