diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb
index cc0375749..12003c0a5 100644
--- a/app/views/admin/tags/index.html.erb
+++ b/app/views/admin/tags/index.html.erb
@@ -6,9 +6,8 @@
<%= tag.name %>
- <%= form_for(tag, url: admin_tag_path(tag), as: :tag) do |f| %>
-
- <%= f.check_box :featured, label: false %>
+ <%= form_for(tag, url: admin_tag_path(tag), as: :tag, html: { id: "edit_tag_#{tag.id}"}) do |f| %>
+ <%= f.check_box :featured, label: false, id: "tag_featured_#{tag.id}" %>
<%= t("admin.tags.index.mark_as_featured") %>
<%= f.submit(class: "button radius tiny") %>
<% end %>
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index dd8cc2b94..2cd19f755 100644
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -2,4 +2,8 @@ en:
admin:
dashboard:
index:
- title: Administration
\ No newline at end of file
+ title: Administration
+ tags:
+ index:
+ title: 'Debate topics'
+ mark_as_featured: 'Mark as featured'
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 7ebe05bc6..bfafea00d 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -2,4 +2,8 @@ es:
admin:
dashboard:
index:
- title: Administración
\ No newline at end of file
+ title: Administración
+ tags:
+ index:
+ title: 'Temas de debate'
+ mark_as_featured: 'Marcar como destacado'
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 19480db63..c5e911994 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -81,8 +81,6 @@ en:
comment_button: Publish comment
reply_link: Reply
reply_button: Publish reply
- tags:
- featured: Featured
votes:
agree: I agree
disagree: I disagree
@@ -122,8 +120,3 @@ en:
default: "You are not authorized to access this page."
manage:
all: "You are not authorized to %{action} %{subject}."
- admin:
- tags:
- index:
- title: 'Debate topics'
- mark_as_featured: 'Mark as featured'
diff --git a/config/locales/es.yml b/config/locales/es.yml
index b43dba2f3..3e4e353d6 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -81,8 +81,6 @@ es:
comment_button: Publicar comentario
reply_link: Responder
reply_button: Publicar respuesta
- tags:
- featured: Destacado
votes:
agree: Estoy de acuerdo
disagree: No estoy de acuerdo
@@ -134,8 +132,3 @@ es:
all: "No tienes permiso para borrar %{subject}"
manage:
all: "No tienes permiso para realizar la acción '%{action}' sobre %{subject}."
- admin:
- tags:
- index:
- title: 'Temas de debate'
- mark_as_featured: 'Marcar como destacado'
diff --git a/config/locales/responders.en.yml b/config/locales/responders.en.yml
index 41c13a326..68bf8581b 100644
--- a/config/locales/responders.en.yml
+++ b/config/locales/responders.en.yml
@@ -4,12 +4,11 @@ en:
create:
notice: '%{resource_name} was successfully created.'
# alert: '%{resource_name} could not be created.'
- # update:
- # notice: '%{resource_name} was successfully updated.'
+ update:
+ notice: '%{resource_name} was successfully updated.'
# alert: '%{resource_name} could not be updated.'
# destroy:
# notice: '%{resource_name} was successfully destroyed.'
# alert: '%{resource_name} could not be destroyed.'
save_changes:
notice: "Saved"
-
diff --git a/config/locales/responders.es.yml b/config/locales/responders.es.yml
index e11fbccbc..6b64f5728 100644
--- a/config/locales/responders.es.yml
+++ b/config/locales/responders.es.yml
@@ -3,8 +3,8 @@ es:
actions:
create:
notice: "%{resource_name} creado correctamente."
- # update:
- # notice: "%{resource_name} actualizado correctamente."
+ update:
+ notice: "%{resource_name} actualizado correctamente."
# destroy:
# notice: "%{resource_name} borrado correctamente."
# alert: "%{resource_name} no ha podido ser borrado."
diff --git a/spec/factories.rb b/spec/factories.rb
index 6bbe3b68b..547b1fe24 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -35,4 +35,16 @@ FactoryGirl.define do
user
end
+ factory :tag, class: 'ActsAsTaggableOn::Tag' do
+ name 'Medio Ambiente'
+
+ trait :featured do
+ featured true
+ end
+
+ trait :unfeatured do
+ featured false
+ end
+ end
+
end
diff --git a/spec/features/admin_spec.rb b/spec/features/admin_spec.rb
index 1c9e845a0..ca5074772 100644
--- a/spec/features/admin_spec.rb
+++ b/spec/features/admin_spec.rb
@@ -2,6 +2,14 @@ require 'rails_helper'
feature 'Admin' do
let(:user) { create(:user) }
+ let(:administrator) do
+ create(:administrator, user: user)
+ user
+ end
+ let(:moderator) do
+ create(:moderator, user: user)
+ user
+ end
scenario 'Access as regular user is not authorized' do
login_as(user)
@@ -12,9 +20,7 @@ feature 'Admin' do
end
scenario 'Access as a moderator is not authorized' do
- create(:moderator, user: user)
-
- login_as(user)
+ login_as(moderator)
visit admin_root_path
expect(current_path).to eq(root_path)
@@ -22,9 +28,7 @@ feature 'Admin' do
end
scenario 'Access as an administrator is authorized' do
- create(:administrator, user: user)
-
- login_as(user)
+ login_as(administrator)
visit admin_root_path
expect(current_path).to eq(admin_root_path)
@@ -32,9 +36,7 @@ feature 'Admin' do
end
scenario "Admin access links" do
- create(:administrator, user: user)
-
- login_as(user)
+ login_as(administrator)
visit root_path
expect(page).to have_link('Administration')
@@ -42,9 +44,7 @@ feature 'Admin' do
end
scenario "Moderation access links" do
- create(:moderator, user: user)
-
- login_as(user)
+ login_as(moderator)
visit root_path
expect(page).to have_link('Moderation')
@@ -52,9 +52,7 @@ feature 'Admin' do
end
scenario 'Admin dashboard' do
- create(:administrator, user: user)
-
- login_as(user)
+ login_as(administrator)
visit root_path
click_link 'Administration'
@@ -65,9 +63,7 @@ feature 'Admin' do
end
scenario 'Moderation dashboard' do
- create(:moderator, user: user)
-
- login_as(user)
+ login_as(moderator)
visit root_path
click_link 'Moderation'
@@ -77,4 +73,21 @@ feature 'Admin' do
expect(page).to_not have_css('#admin_menu')
end
+ context 'Tags' do
+ scenario 'marking tags as featured / unfeatured' do
+ unfeatured_tag = create :tag, :unfeatured, name: 'Mi barrio'
+
+ login_as(administrator)
+ visit admin_tags_path
+
+ expect(page).to have_content 'Mi barrio'
+ save_and_open_page
+
+ check "tag_featured_#{unfeatured_tag.id}"
+ click_button 'Update Tag'
+
+ expect(page).to have_checked_field("tag_featured_#{unfeatured_tag.id}")
+ end
+ end
+
end
diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb
index 87856c457..984f3ea2e 100644
--- a/spec/features/debates_spec.rb
+++ b/spec/features/debates_spec.rb
@@ -70,26 +70,55 @@ feature 'Debates' do
expect(page.html).to_not include '<p>This is'
end
- scenario 'tagging using dangerous strings' do
+ context 'Tagging debates' do
+ let(:author) { create(:user) }
- author = create(:user)
- login_as(author)
+ background do
+ login_as(author)
+ end
- visit new_debate_path
+ scenario 'using featured tags', :js do
+ ['Medio Ambiente', 'Ciencia'].each do |tag_name|
+ create(:tag, :featured, name: tag_name)
+ end
- fill_in 'debate_title', with: 'A test'
- fill_in 'debate_description', with: 'A test'
- fill_in 'debate_tag_list', with: 'user_id=1, &a=3, '
- fill_in 'debate_captcha', with: SimpleCaptcha::SimpleCaptchaData.first.value
- check 'debate_terms_of_service'
+ visit new_debate_path
- click_button 'Create Debate'
+ fill_in 'debate_title', with: 'A test'
+ fill_in_ckeditor 'debate_description', with: 'A test'
+ fill_in 'debate_captcha', with: correct_captcha_text
+ check 'debate_terms_of_service'
- expect(page).to have_content 'Debate was successfully created.'
- expect(page).to have_content 'user_id1'
- expect(page).to have_content 'a3'
- expect(page).to have_content 'scriptalert("hey");script'
- expect(page.html).to_not include 'user_id=1, &a=3, '
+ ['Medio Ambiente', 'Ciencia'].each do |tag_name|
+ find('.js-add-tag-link', text: tag_name).click
+ end
+
+ click_button 'Create Debate'
+
+ expect(page).to have_content 'Debate was successfully created.'
+ ['Medio Ambiente', 'Ciencia'].each do |tag_name|
+ expect(page).to have_content tag_name
+ end
+ end
+
+ scenario 'using dangerous strings' do
+ visit new_debate_path
+
+ fill_in 'debate_title', with: 'A test'
+ fill_in 'debate_description', with: 'A test'
+ fill_in 'debate_captcha', with: correct_captcha_text
+ check 'debate_terms_of_service'
+
+ fill_in 'debate_tag_list', with: 'user_id=1, &a=3, '
+
+ click_button 'Create Debate'
+
+ expect(page).to have_content 'Debate was successfully created.'
+ expect(page).to have_content 'user_id1'
+ expect(page).to have_content 'a3'
+ expect(page).to have_content 'scriptalert("hey");script'
+ expect(page.html).to_not include 'user_id=1, &a=3, '
+ end
end
scenario 'Update should not be posible if logged user is not the author' do
diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb
index 066e32b87..c1ad724bb 100644
--- a/spec/support/common_actions.rb
+++ b/spec/support/common_actions.rb
@@ -60,4 +60,18 @@ module CommonActions
"img.initialjs-avatar[data-name='#{name}']"
end
+ # Used to fill ckeditor fields
+ # @param [String] locator label text for the textarea or textarea id
+ def fill_in_ckeditor(locator, params = {})
+ # Find out ckeditor id at runtime using its label
+ locator = find('label', text: locator)[:for] if page.has_css?('label', text: locator)
+ # Fill the editor content
+ page.execute_script <<-SCRIPT
+ var ckeditor = CKEDITOR.instances.#{locator}
+ ckeditor.setData('#{params[:with]}')
+ ckeditor.focus()
+ ckeditor.updateElement()
+ SCRIPT
+ end
+
end