+
<% if topic.author == current_user %>
<%= link_to t("community.show.topic.edit_button"), edit_community_topic_path(@community.id, topic), class: 'button small hollow' %>
+ <%= link_to t("community.show.topic.destroy_button"), community_topic_path(@community.id, topic), method: :delete, class: 'button hollow alert small' %>
<% end %>
diff --git a/config/locales/en/community.yml b/config/locales/en/community.yml
index 37b7ea74f..068c98998 100644
--- a/config/locales/en/community.yml
+++ b/config/locales/en/community.yml
@@ -26,6 +26,7 @@ en:
disabled_info_title: You need to be logged to create a new topic
topic:
edit_button: Edit
+ destroy_button: Destroy
comments:
one: 1 comment
other: "%{count} comments"
diff --git a/config/locales/en/responders.yml b/config/locales/en/responders.yml
index 17de27b74..203d5700e 100644
--- a/config/locales/en/responders.yml
+++ b/config/locales/en/responders.yml
@@ -29,3 +29,4 @@ en:
spending_proposal: "Spending proposal deleted succesfully."
budget_investment: "Investment project deleted succesfully."
error: "Could not delete"
+ topic: "Topic deleted successfully."
diff --git a/config/locales/es/community.yml b/config/locales/es/community.yml
index 196cd4c50..8013c116c 100644
--- a/config/locales/es/community.yml
+++ b/config/locales/es/community.yml
@@ -26,6 +26,7 @@ es:
disabled_info_title: Necesitas estar logueado para crear un nuevo tema
topic:
edit_button: Editar
+ destroy_button: Eliminar
comments:
one: 1 Comentario
other: "%{count} Comentarios"
diff --git a/config/locales/es/responders.yml b/config/locales/es/responders.yml
index d3d4ff163..74e3ea20a 100644
--- a/config/locales/es/responders.yml
+++ b/config/locales/es/responders.yml
@@ -29,3 +29,4 @@ es:
spending_proposal: "Propuesta de inversión eliminada."
budget_investment: "Propuesta de inversión eliminada."
error: "No se pudo borrar"
+ topic: "Tema eliminado."
diff --git a/db/seeds.rb b/db/seeds.rb
index 90665fdb8..41b995f8a 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -79,7 +79,7 @@ Setting['feature.public_stats'] = true
Setting['feature.budgets'] = true
Setting['feature.signature_sheets'] = true
Setting['feature.legislation'] = true
-Setting['feature.community'] = nil
+Setting['feature.community'] = true
# Spending proposals feature flags
Setting['feature.spending_proposal_features.voting_allowed'] = nil
diff --git a/spec/features/topics_specs.rb b/spec/features/topics_specs.rb
index 0d668d44b..9970e2339 100644
--- a/spec/features/topics_specs.rb
+++ b/spec/features/topics_specs.rb
@@ -13,7 +13,7 @@ feature 'Topics' do
expect(page).to have_selector(".button.expanded.disabled")
end
- scenario 'Should can access to new topic page with user logged', :js do
+ scenario 'Can access to new topic page with user logged', :js do
proposal = create(:proposal)
community = proposal.community
user = create(:user)
@@ -47,10 +47,10 @@ feature 'Topics' do
context 'Create' do
- scenario 'Should can create a new topic', :js do
+ scenario 'Can create a new topic', :js do
proposal = create(:proposal)
community = proposal.community
- user = create(:user)
+ user = create(:user)
login_as(user)
visit new_community_topic_path(community)
@@ -62,11 +62,20 @@ feature 'Topics' do
expect(current_path).to eq(community_path(community))
end
+ scenario 'Can not create a new topic when user not logged', :js 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 'Should can edit a topic' do
+ scenario 'Can edit a topic' do
proposal = create(:proposal)
community = proposal.community
user = create(:user)
@@ -82,11 +91,23 @@ feature 'Topics' do
expect(current_path).to eq(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 'Should can show topic' do
+ scenario 'Can show topic' do
proposal = create(:proposal)
community = proposal.community
topic = create(:topic, community: community)
@@ -99,4 +120,35 @@ feature 'Topics' do
end
+ context 'Destroy' do
+
+ scenario 'Can destroy a topic' do
+ proposal = create(:proposal)
+ community = proposal.community
+ user = create(:user)
+ topic = create(:topic, community: community, author: user)
+ login_as(user)
+ visit community_path(community)
+
+ click_link "Destroy"
+
+ expect(page).to have_content "Topic deleted successfully."
+ expect(page).not_to have_content topic.title
+ expect(current_path).to eq(community_path(community))
+ end
+
+ scenario 'Can not destroy 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 community_path(community)
+
+ expect(page).not_to have_link "Destroy"
+ end
+
+ end
+
end