Merge pull request #855 from consul/districts-and-categories

Categories and Geozones
This commit is contained in:
Juanjo Bazán
2016-01-26 13:55:06 +01:00
35 changed files with 522 additions and 220 deletions

View File

@@ -106,27 +106,6 @@ feature 'Debates' do
expect(page).to have_content "Debate created successfully."
end
scenario 'Failed creation goes back to new showing featured tags' do
featured_tag = create(:tag, :featured)
tag = create(:tag)
login_as(create(:user))
visit new_debate_path
fill_in 'debate_title', with: ""
fill_in 'debate_description', with: 'Very important issue...'
fill_in 'debate_captcha', with: correct_captcha_text
check 'debate_terms_of_service'
click_button "Start a debate"
expect(page).to_not have_content "Debate created successfully."
expect(page).to have_content "error"
within(".tags") do
expect(page).to have_content featured_tag.name
expect(page).to_not have_content tag.name
end
end
scenario 'Errors on create' do
author = create(:user)
login_as(author)
@@ -204,27 +183,43 @@ feature 'Debates' do
login_as(author)
end
scenario 'using featured tags', :js do
['Medio Ambiente', 'Ciencia'].each do |tag_name|
create(:tag, :featured, name: tag_name)
end
pending 'Category tags', :js do
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
visit new_debate_path
fill_in 'debate_title', with: 'A test'
fill_in_ckeditor 'debate_description', with: 'A test'
fill_in 'debate_title', with: 'Testing auto link'
fill_in 'debate_description', with: "<script>alert('hey')</script> <a href=\"javascript:alert('surprise!')\">click me<a/> http://example.org"
fill_in 'debate_captcha', with: correct_captcha_text
check 'debate_terms_of_service'
['Medio Ambiente', 'Ciencia'].each do |tag_name|
find('.js-add-tag-link', text: tag_name).click
end
find('.js-add-tag-link', text: 'Education').click
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
['Medio Ambiente', 'Ciencia'].each do |tag_name|
expect(page).to have_content tag_name
within "#tags" do
expect(page).to have_content 'Education'
expect(page).to_not have_content 'Health'
end
end
scenario 'Custom tags' do
visit new_debate_path
fill_in 'debate_title', with: "Great title"
fill_in 'debate_description', with: 'Very important issue...'
fill_in 'debate_captcha', with: correct_captcha_text
check 'debate_terms_of_service'
fill_in 'debate_tag_list', with: 'Refugees, Solidarity'
click_button 'Start a debate'
expect(page).to have_content 'Debate created successfully.'
within "#tags" do
expect(page).to have_content 'Refugees'
expect(page).to have_content 'Solidarity'
end
end
@@ -323,27 +318,6 @@ feature 'Debates' do
expect(page).to have_content "Debate updated successfully."
end
scenario 'Failed update goes back to edit showing featured tags' do
debate = create(:debate)
featured_tag = create(:tag, :featured)
tag = create(:tag)
login_as(debate.author)
visit edit_debate_path(debate)
expect(current_path).to eq(edit_debate_path(debate))
fill_in 'debate_title', with: ""
fill_in 'debate_captcha', with: correct_captcha_text
click_button "Save changes"
expect(page).to_not have_content "Debate updated successfully."
expect(page).to have_content "error"
within(".tags") do
expect(page).to have_content featured_tag.name
expect(page).to_not have_content tag.name
end
end
describe 'Limiting tags shown' do
scenario 'Index page shows up to 5 tags per debate' do
tag_list = ["Hacienda", "Economía", "Medio Ambiente", "Corrupción", "Fiestas populares", "Prensa"]
@@ -890,4 +864,67 @@ feature 'Debates' do
visit debate_path(debate)
expect(page).to have_content('User deleted')
end
context "Filter" do
pending "By category" do
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
debate1 = create(:debate, tag_list: education.name)
debate2 = create(:debate, tag_list: health.name)
visit debates_path
within "#categories" do
click_link "Education"
end
within("#debates") do
expect(page).to have_css('.debate', count: 1)
expect(page).to have_content(debate1.title)
end
end
context "By geozone" do
background do
geozone1 = Geozone.create(name: "California")
geozone2 = Geozone.create(name: "New York")
@debate1 = create(:debate, geozone: geozone1)
@debate2 = create(:debate, geozone: geozone2)
end
pending "From map" do
visit debates_path
click_link "map"
within("#html_map") do
url = find("area[title='California']")[:href]
visit url
end
within("#debates") do
expect(page).to have_css('.debate', count: 1)
expect(page).to have_content(@debate1.title)
end
end
pending "From geozone list" do
visit debates_path
click_link "map"
within("#geozones") do
click_link "California"
end
within("#debates") do
expect(page).to have_css('.debate', count: 1)
expect(page).to have_content(@debate1.title)
end
end
end
end
end

View File

@@ -166,31 +166,6 @@ feature 'Proposals' do
expect(page).to have_content "Proposal created successfully."
end
scenario 'Failed creation goes back to new showing featured tags' do
featured_tag = create(:tag, :featured)
tag = create(:tag)
login_as(create(:user))
visit new_proposal_path
fill_in 'proposal_title', with: ""
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in 'proposal_description', with: 'Very important issue...'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_captcha', with: correct_captcha_text
check 'proposal_terms_of_service'
click_button "Create proposal"
expect(page).to_not have_content "Proposal created successfully."
expect(page).to have_content "error"
within(".tags") do
expect(page).to have_content featured_tag.name
expect(page).to_not have_content tag.name
end
end
scenario 'Errors on create' do
author = create(:user)
login_as(author)
@@ -271,42 +246,67 @@ feature 'Proposals' do
expect(page.html).to_not include "<script>alert('hey')</script>"
end
context 'Tagging proposals' do
context 'Tagging' do
let(:author) { create(:user) }
background do
login_as(author)
end
scenario 'using featured tags', :js do
['Medio Ambiente', 'Ciencia'].each do |tag_name|
create(:tag, :featured, name: tag_name)
end
scenario 'Category tags', :js do
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
visit new_proposal_path
fill_in 'proposal_title', with: 'A test with enough characters'
fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in_ckeditor 'proposal_description', with: 'A description with enough characters'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_captcha', with: correct_captcha_text
check 'proposal_terms_of_service'
['Medio Ambiente', 'Ciencia'].each do |tag_name|
find('.js-add-tag-link', text: tag_name).click
end
find('.js-add-tag-link', text: 'Education').click
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
['Medio Ambiente', 'Ciencia'].each do |tag_name|
expect(page).to have_content tag_name
within "#tags" do
expect(page).to have_content 'Education'
expect(page).to_not have_content 'Health'
end
end
scenario 'Custom tags' do
visit new_proposal_path
fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in 'proposal_description', with: 'This is very important because...'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_captcha', with: correct_captcha_text
check 'proposal_terms_of_service'
fill_in 'proposal_tag_list', with: 'Refugees, Solidarity'
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
within "#tags" do
expect(page).to have_content 'Refugees'
expect(page).to have_content 'Solidarity'
end
end
scenario 'using dangerous strings' do
author = create(:user)
login_as(author)
visit new_proposal_path
fill_in 'proposal_title', with: 'A test of dangerous strings'
@@ -330,6 +330,61 @@ feature 'Proposals' do
end
end
context "Geozones" do
scenario "Default whole city" do
author = create(:user)
login_as(author)
visit new_proposal_path
fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in 'proposal_description', with: 'This is very important because...'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_captcha', with: correct_captcha_text
check 'proposal_terms_of_service'
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
within "#geozone" do
expect(page).to have_content 'All city'
end
end
scenario "Specific geozone" do
geozone = create(:geozone, name: 'California')
geozone = create(:geozone, name: 'New York')
author = create(:user)
login_as(author)
visit new_proposal_path
fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
fill_in 'proposal_summary', with: 'In summary, what we want is...'
fill_in 'proposal_description', with: 'This is very important because...'
fill_in 'proposal_external_url', with: 'http://rescue.org/refugees'
fill_in 'proposal_video_url', with: 'http://youtube.com'
fill_in 'proposal_responsible_name', with: 'Isabel Garcia'
fill_in 'proposal_captcha', with: correct_captcha_text
check 'proposal_terms_of_service'
select('California', from: 'proposal_geozone_id')
click_button 'Create proposal'
expect(page).to have_content 'Proposal created successfully.'
within "#geozone" do
expect(page).to have_content 'California'
end
end
end
scenario 'Update should not be posible if logged user is not the author' do
proposal = create(:proposal)
expect(proposal).to be_editable
@@ -410,27 +465,6 @@ feature 'Proposals' do
expect(page).to have_content "Proposal updated successfully."
end
scenario 'Failed update goes back to edit showing featured tags' do
proposal = create(:proposal)
featured_tag = create(:tag, :featured)
tag = create(:tag)
login_as(proposal.author)
visit edit_proposal_path(proposal)
expect(current_path).to eq(edit_proposal_path(proposal))
fill_in 'proposal_title', with: ""
fill_in 'proposal_captcha', with: correct_captcha_text
click_button "Save changes"
expect(page).to_not have_content "Proposal updated successfully."
expect(page).to have_content "error"
within(".tags") do
expect(page).to have_content featured_tag.name
expect(page).to_not have_content tag.name
end
end
describe 'Limiting tags shown' do
scenario 'Index page shows up to 5 tags per proposal' do
create_featured_proposals
@@ -988,4 +1022,67 @@ feature 'Proposals' do
visit proposals_path
expect(page).to have_content('User deleted')
end
context "Filter" do
scenario "By category" do
education = create(:tag, name: 'Education', kind: 'category')
health = create(:tag, name: 'Health', kind: 'category')
proposal1 = create(:proposal, tag_list: education.name)
proposal2 = create(:proposal, tag_list: health.name)
visit proposals_path
within "#categories" do
click_link "Education"
end
within("#proposals") do
expect(page).to have_css('.proposal', count: 1)
expect(page).to have_content(proposal1.title)
end
end
context "By geozone" do
background do
geozone1 = Geozone.create(name: "California")
geozone2 = Geozone.create(name: "New York")
@proposal1 = create(:proposal, geozone: geozone1)
@proposal2 = create(:proposal, geozone: geozone2)
end
scenario "From map" do
visit proposals_path
click_link "map"
within("#html_map") do
url = find("area[title='California']")[:href]
visit url
end
within("#proposals") do
expect(page).to have_css('.proposal', count: 1)
expect(page).to have_content(@proposal1.title)
end
end
scenario "From geozone list" do
visit proposals_path
click_link "map"
within("#geozones") do
click_link "California"
end
within("#proposals") do
expect(page).to have_css('.proposal', count: 1)
expect(page).to have_content(@proposal1.title)
end
end
end
end
end