tests featured tags administration and adding featured tags to debates

This commit is contained in:
David Gil
2015-08-15 19:38:42 +02:00
parent 8b89cc5117
commit 664f656fe3
11 changed files with 117 additions and 57 deletions

View File

@@ -6,9 +6,8 @@
<li> <li>
<strong><%= tag.name %></strong> <strong><%= tag.name %></strong>
<%= form_for(tag, url: admin_tag_path(tag), as: :tag) do |f| %> <%= form_for(tag, url: admin_tag_path(tag), as: :tag, html: { id: "edit_tag_#{tag.id}"}) do |f| %>
<!-- <%= f.check_box :featured %> --> <%= f.check_box :featured, label: false, id: "tag_featured_#{tag.id}" %>
<%= f.check_box :featured, label: false %>
<%= t("admin.tags.index.mark_as_featured") %> <%= t("admin.tags.index.mark_as_featured") %>
<%= f.submit(class: "button radius tiny") %> <%= f.submit(class: "button radius tiny") %>
<% end %> <% end %>

View File

@@ -3,3 +3,7 @@ en:
dashboard: dashboard:
index: index:
title: Administration title: Administration
tags:
index:
title: 'Debate topics'
mark_as_featured: 'Mark as featured'

View File

@@ -3,3 +3,7 @@ es:
dashboard: dashboard:
index: index:
title: Administración title: Administración
tags:
index:
title: 'Temas de debate'
mark_as_featured: 'Marcar como destacado'

View File

@@ -81,8 +81,6 @@ en:
comment_button: Publish comment comment_button: Publish comment
reply_link: Reply reply_link: Reply
reply_button: Publish reply reply_button: Publish reply
tags:
featured: Featured
votes: votes:
agree: I agree agree: I agree
disagree: I disagree disagree: I disagree
@@ -122,8 +120,3 @@ en:
default: "You are not authorized to access this page." default: "You are not authorized to access this page."
manage: manage:
all: "You are not authorized to %{action} %{subject}." all: "You are not authorized to %{action} %{subject}."
admin:
tags:
index:
title: 'Debate topics'
mark_as_featured: 'Mark as featured'

View File

@@ -81,8 +81,6 @@ es:
comment_button: Publicar comentario comment_button: Publicar comentario
reply_link: Responder reply_link: Responder
reply_button: Publicar respuesta reply_button: Publicar respuesta
tags:
featured: Destacado
votes: votes:
agree: Estoy de acuerdo agree: Estoy de acuerdo
disagree: No estoy de acuerdo disagree: No estoy de acuerdo
@@ -134,8 +132,3 @@ es:
all: "No tienes permiso para borrar %{subject}" all: "No tienes permiso para borrar %{subject}"
manage: manage:
all: "No tienes permiso para realizar la acción '%{action}' sobre %{subject}." 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'

View File

@@ -4,12 +4,11 @@ en:
create: create:
notice: '%{resource_name} was successfully created.' notice: '%{resource_name} was successfully created.'
# alert: '%{resource_name} could not be created.' # alert: '%{resource_name} could not be created.'
# update: update:
# notice: '%{resource_name} was successfully updated.' notice: '%{resource_name} was successfully updated.'
# alert: '%{resource_name} could not be updated.' # alert: '%{resource_name} could not be updated.'
# destroy: # destroy:
# notice: '%{resource_name} was successfully destroyed.' # notice: '%{resource_name} was successfully destroyed.'
# alert: '%{resource_name} could not be destroyed.' # alert: '%{resource_name} could not be destroyed.'
save_changes: save_changes:
notice: "Saved" notice: "Saved"

View File

@@ -3,8 +3,8 @@ es:
actions: actions:
create: create:
notice: "%{resource_name} creado correctamente." notice: "%{resource_name} creado correctamente."
# update: update:
# notice: "%{resource_name} actualizado correctamente." notice: "%{resource_name} actualizado correctamente."
# destroy: # destroy:
# notice: "%{resource_name} borrado correctamente." # notice: "%{resource_name} borrado correctamente."
# alert: "%{resource_name} no ha podido ser borrado." # alert: "%{resource_name} no ha podido ser borrado."

View File

@@ -35,4 +35,16 @@ FactoryGirl.define do
user user
end end
factory :tag, class: 'ActsAsTaggableOn::Tag' do
name 'Medio Ambiente'
trait :featured do
featured true
end
trait :unfeatured do
featured false
end
end
end end

View File

@@ -2,6 +2,14 @@ require 'rails_helper'
feature 'Admin' do feature 'Admin' do
let(:user) { create(:user) } 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 scenario 'Access as regular user is not authorized' do
login_as(user) login_as(user)
@@ -12,9 +20,7 @@ feature 'Admin' do
end end
scenario 'Access as a moderator is not authorized' do scenario 'Access as a moderator is not authorized' do
create(:moderator, user: user) login_as(moderator)
login_as(user)
visit admin_root_path visit admin_root_path
expect(current_path).to eq(root_path) expect(current_path).to eq(root_path)
@@ -22,9 +28,7 @@ feature 'Admin' do
end end
scenario 'Access as an administrator is authorized' do scenario 'Access as an administrator is authorized' do
create(:administrator, user: user) login_as(administrator)
login_as(user)
visit admin_root_path visit admin_root_path
expect(current_path).to eq(admin_root_path) expect(current_path).to eq(admin_root_path)
@@ -32,9 +36,7 @@ feature 'Admin' do
end end
scenario "Admin access links" do scenario "Admin access links" do
create(:administrator, user: user) login_as(administrator)
login_as(user)
visit root_path visit root_path
expect(page).to have_link('Administration') expect(page).to have_link('Administration')
@@ -42,9 +44,7 @@ feature 'Admin' do
end end
scenario "Moderation access links" do scenario "Moderation access links" do
create(:moderator, user: user) login_as(moderator)
login_as(user)
visit root_path visit root_path
expect(page).to have_link('Moderation') expect(page).to have_link('Moderation')
@@ -52,9 +52,7 @@ feature 'Admin' do
end end
scenario 'Admin dashboard' do scenario 'Admin dashboard' do
create(:administrator, user: user) login_as(administrator)
login_as(user)
visit root_path visit root_path
click_link 'Administration' click_link 'Administration'
@@ -65,9 +63,7 @@ feature 'Admin' do
end end
scenario 'Moderation dashboard' do scenario 'Moderation dashboard' do
create(:moderator, user: user) login_as(moderator)
login_as(user)
visit root_path visit root_path
click_link 'Moderation' click_link 'Moderation'
@@ -77,4 +73,21 @@ feature 'Admin' do
expect(page).to_not have_css('#admin_menu') expect(page).to_not have_css('#admin_menu')
end 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 end

View File

@@ -70,19 +70,47 @@ feature 'Debates' do
expect(page.html).to_not include '&lt;p&gt;This is' expect(page.html).to_not include '&lt;p&gt;This is'
end end
scenario 'tagging using dangerous strings' do context 'Tagging debates' do
let(:author) { create(:user) }
author = create(:user) background do
login_as(author) login_as(author)
end
scenario 'using featured tags', :js do
['Medio Ambiente', 'Ciencia'].each do |tag_name|
create(:tag, :featured, name: tag_name)
end
visit new_debate_path visit new_debate_path
fill_in 'debate_title', with: 'A test' fill_in 'debate_title', with: 'A test'
fill_in 'debate_description', with: 'A test' fill_in_ckeditor '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: correct_captcha_text
fill_in 'debate_captcha', with: SimpleCaptcha::SimpleCaptchaData.first.value
check 'debate_terms_of_service' check 'debate_terms_of_service'
['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' click_button 'Create Debate'
expect(page).to have_content 'Debate was successfully created.' expect(page).to have_content 'Debate was successfully created.'
@@ -91,6 +119,7 @@ feature 'Debates' do
expect(page).to have_content 'scriptalert("hey");script' expect(page).to have_content 'scriptalert("hey");script'
expect(page.html).to_not include 'user_id=1, &a=3, <script>alert("hey");</script>' expect(page.html).to_not include 'user_id=1, &a=3, <script>alert("hey");</script>'
end end
end
scenario 'Update should not be posible if logged user is not the author' do scenario 'Update should not be posible if logged user is not the author' do
debate = create(:debate) debate = create(:debate)

View File

@@ -60,4 +60,18 @@ module CommonActions
"img.initialjs-avatar[data-name='#{name}']" "img.initialjs-avatar[data-name='#{name}']"
end 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 end