tests featured tags administration and adding featured tags to debates
This commit is contained in:
@@ -6,9 +6,8 @@
|
||||
<li>
|
||||
<strong><%= tag.name %></strong>
|
||||
|
||||
<%= form_for(tag, url: admin_tag_path(tag), as: :tag) do |f| %>
|
||||
<!-- <%= f.check_box :featured %> -->
|
||||
<%= 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 %>
|
||||
|
||||
@@ -2,4 +2,8 @@ en:
|
||||
admin:
|
||||
dashboard:
|
||||
index:
|
||||
title: Administration
|
||||
title: Administration
|
||||
tags:
|
||||
index:
|
||||
title: 'Debate topics'
|
||||
mark_as_featured: 'Mark as featured'
|
||||
|
||||
@@ -2,4 +2,8 @@ es:
|
||||
admin:
|
||||
dashboard:
|
||||
index:
|
||||
title: Administración
|
||||
title: Administración
|
||||
tags:
|
||||
index:
|
||||
title: 'Temas de debate'
|
||||
mark_as_featured: 'Marcar como destacado'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, <script>alert("hey");</script>'
|
||||
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, <script>alert("hey");</script>'
|
||||
['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, <script>alert("hey");</script>'
|
||||
|
||||
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, <script>alert("hey");</script>'
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'Update should not be posible if logged user is not the author' do
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user