tests featured tags administration and adding featured tags to debates
This commit is contained in:
@@ -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