Created
April 10, 2015 14:05
-
-
Save tjmcewan/186155801af93ac9a666 to your computer and use it in GitHub Desktop.
nation builder tag cleaner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "spec_helper" | |
NATION = "my-nation" | |
EMAIL = "[email protected]" | |
PASSWORD = "Password1" | |
TAG_PATTERNS_TO_DELETE = [ | |
/^mass_tag_/, | |
/^valuable_member_/, | |
] | |
describe "delete tags", js: true, driver: :selenium do | |
specify do | |
visit "https://#{NATION}.nationbuilder.com/admin" | |
fill_in 'Email Address', with: EMAIL, match: :first | |
fill_in 'Password', with: PASSWORD | |
click_button 'Sign in with email' | |
sleep 2 # or wait_for_ajax | |
visit "https://#{NATION}.nationbuilder.com/admin/signup_tags/new" | |
total_tags = find('.total-found').text.match(/(\d+)$/)[1] rescue 1 | |
pages = (total_tags.to_i / 50.0).ceil # they show 50 tags per page | |
(1..pages).to_a.reverse.each do |page_number| | |
visit "https://#{NATION}.nationbuilder.com/admin/signup_tags/new?page=#{page_number}" | |
tags = all('.last a').select{|el| el.text =~ Regexp.union(TAG_PATTERNS_TO_DELETE) } | |
tag_ids = tags.map{|tag| tag.native.attribute(:href).match(/=(\d+)/)[1] } | |
tag_ids.each do |tag_id| | |
visit "https://#{NATION}.nationbuilder.com/admin/signup_tags/#{tag_id}/edit" | |
click_link "Delete Tag" | |
page.driver.browser.switch_to.alert.accept | |
sleep 1 | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment