Files
grecia/spec/system/topics_spec.rb
dependabot[bot] 0929eab188 Bump cancancan from 2.3.0 to 3.3.0
Bumps [cancancan](https://github.com/CanCanCommunity/cancancan) from 2.3.0 to 3.3.0.
- [Release notes](https://github.com/CanCanCommunity/cancancan/releases)
- [Changelog](https://github.com/CanCanCommunity/cancancan/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/CanCanCommunity/cancancan/compare/2.3.0...3.3.0)

---
updated-dependencies:
- dependency-name: cancancan
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-12 21:45:20 +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