Permalink
Browse files

remove the concept of new ringers from broadcast and export csv file

  • Loading branch information...
1 parent 6dcdd4c commit 5a40660c6a580770fc89a6ccbe8167b805bfc026 Willa committed Nov 8, 2012
View
@@ -21,7 +21,7 @@ def self.create_double_opt_in(message)
end
def handle?(type, ringer)
- ringer.tags.include? recipient_tag
+ ringer.tagged?(recipient_tag)
end
def recipient_tag
@@ -41,12 +41,16 @@ def respond(ringer, sms_number)
[{cmd: :reject}]
end
+ def potential_recipients(ringers)
+ ringers.reject {|r| r.tagged?(recipient_tag) }
+ end
+
def recipients(ringers=Ringer.all)
- ringers.select {|r| r.tags.include?(recipient_tag)}
+ ringers.select {|r| r.tagged?(recipient_tag)}
end
def respondents(ringers=Ringer.all)
- ringers.select {|r| r.tags.include?(respondent_tag)}
+ ringers.select {|r| r.tagged?(respondent_tag)}
end
def trigger_for(ringer, sms_number)
@@ -60,14 +60,6 @@ def all_errors
allerrors.flatten
end
- def new_rings
- if most_recent_broadcast.nil?
- rings
- else
- rings.select { |r| r.created_at > most_recent_broadcast }
- end
- end
-
def slug
title.gsub(/\s/, '_').gsub(/[^a-zA-Z_]/, '').downcase
end
@@ -134,7 +134,7 @@ def process_request(service_name, request, response_type)
redirect to('/unsubscribe_numbers/new')
end
end
-
+
post '/unsubscribe_numbers/:phone_number/destroy' do
unsubscribe_number = AssignedUnsubscribeVoiceNumber.get(params[:phone_number])
if unsubscribe_number.destroy
@@ -21,8 +21,7 @@ def self.statsd_increment(stat, slug=nil)
def self.push_notify(m)
data = { number: m.ringer.pretty_phone_number,
ringer_count: m.campaign.ringers.count,
- ring_count: m.campaign.rings.count,
- new_ringer_count: m.campaign.new_rings.count }
+ ring_count: m.campaign.rings.count }
begin
Pusher[m.campaign.id].trigger('new', data)
View
@@ -45,6 +45,10 @@ def add_tags
save
end
+ def tagged?(tag)
+ tags.include?(tag)
+ end
+
def unsubscribe
update(subscribed: false)
end
@@ -43,6 +43,5 @@ def broadcast(from, msg, to_numbers)
@last_broadcast = {from: from, msg: msg, to_numbers: to_numbers }
p "Broadcast: from: #{from}, msg: '#{msg}', to: #{to_numbers}" if @do_output
end
-
end
end
@@ -5,7 +5,6 @@ new_ringer = (data) ->
data.ringer_count + " Unique Ringer" + (if data.ringer_count != 1 then "s" else ""))
$("#campaign-ringers .counts").effect("highlight", {color: '#63DB00'}, 500)
$(".all-label .ui-button-text").text('All ' + data.ringer_count)
- $(".new-label .ui-button-text").text(data.new_ringer_count + ' New')
delete_last = ->
if $('#ringers-numbers li').length > 10
View
@@ -58,8 +58,6 @@
#broadcast-filter.filter-buttons
%input#all1{type: 'radio', name: 'filter', value: 'all', checked: 'checked'}
%label.all-label{for: 'all1'}= "All #{@ringer_count}"
- %input#new1{type: 'radio', name: 'filter', value: "after:#{@campaign.most_recent_broadcast || @campaign.created_at}"}
- %label.new-label{for: 'new1'}= "#{@campaign.new_rings.count} New"
%input#country1{type: 'radio', name: 'filter', value: 'country:'}
%label{for: 'country1'} Country
#filter-options{style: 'display:none'}
@@ -73,8 +71,6 @@
#export-filter.filter-buttons
%input#all2{type: 'radio', name: 'filter', value: 'all', checked: 'checked'}
%label.all-label{for: 'all2'}= "All #{@ringer_count}"
- %input#new2{type: 'radio', name: 'filter', value: "after:#{@campaign.most_recent_broadcast || @campaign.created_at}"}
- %label.new-label{for: 'new2'}= "#{@campaign.new_rings.count} New"
%input#country2{type: 'radio', name: 'filter', value: 'country:'}
%label{for: 'country2'} Country
#filter-options{style: 'display:none'}
@@ -1,43 +0,0 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
-describe 'Filtering ringers', type: :request, js: true do
-
- before(:all) do
- @number = '+18001111111'
- @logging_service = Crowdring::LoggingService.new([@number])
- Crowdring::Server.service_handler.add('logging', @logging_service)
- end
-
- before(:each) do
- Capybara.app_host = 'http://localhost:5000'
-
- DataMapper.auto_migrate!
- @number2 = '+18002222222'
- @number3 = '+18003333333'
- @campaign = Crowdring::Campaign.create(
- title: 'title',
- message: Crowdring::Message.new(default_message:'default'),
- voice_numbers: [{phone_number: @number, description: 'num1'}],
- sms_number: @number)
- end
-
- it 'Filtering ringers based on who has joined since the most recent broadcast' do
- origRinger = Crowdring::Ringer.create(phone_number: @number2)
- @campaign.rings.create(ringer: origRinger, created_at: DateTime.now-2)
- @campaign.most_recent_broadcast = DateTime.now - 1
- @campaign.save
- newRinger = Crowdring::Ringer.create(phone_number: @number3)
- @campaign.voice_numbers.first.ring(newRinger)
-
- visit "/campaign/#{@campaign.id}"
- page.find("label[for=new1]").text.should match('1')
-
- within('#broadcast') do
- choose('new1')
- click_button('broadcastbutton')
- end
-
- @logging_service.last_broadcast[:to_numbers].should eq([@number3])
- Crowdring::Campaign.get(@campaign.id).new_rings.count.should eq(0)
- end
-end
@@ -1,16 +0,0 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-
-require 'capybara'
-require 'capybara/dsl'
-
-Capybara.app = Crowdring::Server
-
-RSpec.configure do |config|
- config.include Capybara::DSL
-end
-
-include Rack::Test::Methods
-
-def app
- Crowdring::Server
-end
View
@@ -200,32 +200,6 @@ def app
last_response.should be_redirect
last_response.location.should match("campaigns##{Regexp.quote(@campaign.id.to_s)}$")
end
-
- it 'should broadcast only to the new ringers of a campaign' do
- ringer = Crowdring::Ringer.create(phone_number: @number2)
- Crowdring::Ring.create(ringer: ringer, created_at: DateTime.now-2)
-
- @campaign.most_recent_broadcast = DateTime.now - 1
- @campaign.save
- newringer = Crowdring::Ringer.create(phone_number: @number3)
- @campaign.voice_numbers.first.ring(newringer)
-
- post "/campaign/#{@campaign.id}/broadcast", {message: 'message', filter: "after:#{@campaign.most_recent_broadcast}"}
- @sent_to.should eq([@number3])
- end
-
- it 'should not have any new ringers after a broadcast' do
- ringer = Crowdring::Ringer.create(phone_number: @number2)
- Crowdring::Ring.create(ringer: ringer, created_at: DateTime.now-2)
-
- @campaign.most_recent_broadcast = DateTime.now - 1
- @campaign.save
- newringer = Crowdring::Ringer.create(phone_number: @number3)
- @campaign.voice_numbers.first.ring(newringer)
-
- post "/campaign/#{@campaign.id}/broadcast", {message: 'message', filter: "after:#{@campaign.most_recent_broadcast}"}
- Campaign.get(@campaign.id).new_rings.should be_empty
- end
end
describe 'campaign exporting' do
@@ -258,16 +232,7 @@ def verify_csv(csvString, memberships, fields=[])
get "/campaign/#{@campaign.id}/csv", {filter: 'all', fields: fields}
verify_csv(last_response.body, @campaign.unique_rings, fields.keys)
end
-
- it 'should export only the new ringers numbers and support dates' do
- @campaign.most_recent_broadcast = DateTime.now - 1
- @campaign.save
- @campaign.ringers.create(phone_number: @number3)
-
- get "/campaign/#{@campaign.id}/csv", {filter: "after:#{@campaign.most_recent_broadcast}"}
- verify_csv(last_response.body, @campaign.new_rings)
- end
-
+
it 'should export the ringers country codes' do
r1 = Crowdring::Ringer.create(phone_number: @number2)
r2 = Crowdring::Ringer.create(phone_number: @number3)
@@ -276,7 +241,7 @@ def verify_csv(csvString, memberships, fields=[])
fields = {country_code: 'yes'}
get "/campaign/#{@campaign.id}/csv", {filter: 'all', fields: fields}
- verify_csv(last_response.body, @campaign.new_rings, fields.keys)
+ verify_csv(last_response.body, @campaign.ringers, fields.keys)
end
it 'should export the ringers area codes' do
@@ -287,7 +252,7 @@ def verify_csv(csvString, memberships, fields=[])
fields = {area_code: 'yes'}
get "/campaign/#{@campaign.id}/csv", {filter: 'all', fields: fields}
- verify_csv(last_response.body, @campaign.new_rings, fields.keys)
+ verify_csv(last_response.body, @campaign.ringers, fields.keys)
end
end
end

0 comments on commit 5a40660

Please sign in to comment.