Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring ringer spec.

  • Loading branch information...
commit 8f29129f6b09672f1f1694beda97d63c23036a27 1 parent 68392c9
Willa authored
View
1  .gitignore
@@ -4,3 +4,4 @@ logfile
dump.rdb
UTF-8
log_file.log
+lib/public/javascript/jquery-cookie
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--require spec_helper
View
4 Gemfile
@@ -27,11 +27,13 @@ group :development do
end
group :test do
-
+ gem 'dm-rspec'
+ gem 'factory_girl'
gem 'rspec'
gem 'fakeweb'
gem 'pusher-fake'
gem 'capybara'
+ gem 'shoulda-matchers'
end
gem 'resque'
View
16 Gemfile.lock
@@ -40,6 +40,8 @@ GEM
addressable (2.2.8)
backports (2.6.7)
bcrypt-ruby (3.0.1)
+ bourne (1.1.2)
+ mocha (= 0.10.5)
builder (3.0.4)
capybara (2.0.2)
mime-types (>= 1.16)
@@ -80,6 +82,9 @@ GEM
dm-postgres-adapter (1.2.0)
dm-do-adapter (~> 1.2.0)
do_postgres (~> 0.10.6)
+ dm-rspec (0.2.3)
+ dm-core
+ dm-validations
dm-serializer (1.2.2)
dm-core (~> 1.2.0)
fastercsv (~> 1.5)
@@ -108,6 +113,8 @@ GEM
erubis (2.7.0)
eventmachine (1.0.0)
facets (2.9.3)
+ factory_girl (4.2.0)
+ activesupport (>= 3.0.0)
fakeweb (1.3.0)
fastercsv (1.5.5)
ffi (1.3.1)
@@ -126,7 +133,10 @@ GEM
libwebsocket (0.1.7.1)
addressable
websocket
+ metaclass (0.0.1)
mime-types (1.19)
+ mocha (0.10.5)
+ metaclass (~> 0.0.1)
multi_json (1.3.7)
nexmo (1.0.0)
nokogiri (1.5.6)
@@ -184,6 +194,9 @@ GEM
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
+ shoulda-matchers (1.4.2)
+ activesupport (>= 3.0.0)
+ bourne (~> 1.1.2)
signature (0.1.6)
sinatra (1.3.3)
rack (~> 1.3, >= 1.3.6)
@@ -251,7 +264,9 @@ DEPENDENCIES
datamapper
dm-observer
dm-postgres-adapter
+ dm-rspec
facets
+ factory_girl
fakeweb
foreman
googlecharts!
@@ -268,6 +283,7 @@ DEPENDENCIES
rake
resque
rspec
+ shoulda-matchers
sinatra
sinatra-authentication
sinatra-contrib
View
2  lib/crowdring.rb
@@ -21,6 +21,7 @@
require "sinatra/json"
require "sinatra/jsonp"
require 'googlecharts'
+
require 'crowdring/telephony_services/telephony_service'
require 'crowdring/telephony_services/twilio_service'
require 'crowdring/telephony_services/kookoo_service'
@@ -35,7 +36,6 @@
require 'crowdring/telephony_services/composite_service'
require 'crowdring/batch_send_sms'
-require 'crowdring/filter'
require 'crowdring/ivr'
require 'crowdring/phone_number_fields'
require 'crowdring/campaign'
View
48 lib/crowdring/filter.rb
@@ -1,48 +0,0 @@
-module Crowdring
- class Filter
- @@filters = {}
- def self.create(name)
- className, *modifier = name.split(':')
- @@filters[className].new(modifier.join(':'))
- end
-
- def initialize(*args)
- end
-
- def self.register name
- @@filters[name] = self
- end
- end
-
- class AllFilter < Filter
- def filter(input)
- input
- end
-
- register 'all'
- end
-
- class AfterFilter < Filter
- def initialize(cutoff)
- @cutoff = DateTime.parse cutoff
- end
-
- def filter(input)
- input.select {|item| item.created_at > @cutoff }
- end
-
- register 'after'
- end
-
- class CountryFilter < Filter
- def initialize(countries)
- @countries = countries.split('|')
- end
-
- def filter(input)
- input.select {|item| @countries.include? item.country.char_3_code }
- end
-
- register 'country'
- end
-end
View
1  lib/crowdring/ringer.rb
@@ -22,6 +22,7 @@ class Ringer
has n, :rings, constraint: :destroy
+ validates_presence_of :phone_number
validates_with_method :phone_number, :valid_phone_number?
after :create, :add_tags
View
28 spec/factories.rb
@@ -0,0 +1,28 @@
+FactoryGirl.define do
+ factory :campaign, :class => "Crowdring::Campaign" do
+
+ sequence(:title) {|n| "Campaign #{n}"}
+ # t.voice_numbers ['+18001111111']
+ # t.sms_number '+18002222222'
+ end
+
+ factory :ringer, :class => "Crowdring::Ringer" do
+ sequence(:phone_number){|n| "+1212111111#{n}"}
+
+ end
+
+ factory :invalid_ringer, class: "Crowdring::Ringer" do
+ phone_number 'invalid'
+ end
+
+ factory :area_code, class: "Crowdring::Tag" do
+ group "area code"
+ value "212"
+ end
+
+ factory :country, class: "Crowdring::Tag" do
+ group "country"
+ value "united states"
+ end
+end
+
View
29 spec/filter_spec.rb
@@ -1,29 +0,0 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
-describe 'filters' do
- it 'should return all of the given elements' do
- filter = Crowdring::Filter.create('all')
- filter.filter([1,2,3]).should eq([1,2,3])
- end
-
- it 'should return the elements created after a given date' do
- oldOne = double('old', created_at: DateTime.now - 2)
- newOne = double('new', created_at: DateTime.now)
- filter = Crowdring::Filter.create("after:#{DateTime.now - 1}")
- filter.filter([oldOne, newOne]).should eq([newOne])
- end
-
- it 'should return the elements matching the given country code' do
- numOne = double('US', country: Phonie::Country.find_by_country_code('US'))
- numTwo = double('IN', country: Phonie::Country.find_by_country_code('IN'))
- filter = Crowdring::Filter.create("country:US")
- filter.filter([numOne, numTwo]).should eq([numOne])
- end
-
- it 'should accept multiple country codes separated by bars' do
- numOne = double('US', country: Phonie::Country.find_by_country_code('US'))
- numTwo = double('IN', country: Phonie::Country.find_by_country_code('IN'))
- filter = Crowdring::Filter.create("country:US|IN")
- filter.filter([numOne, numTwo]).should eq([numOne, numTwo])
- end
-end
View
69 spec/ringer_spec.rb
@@ -1,65 +1,28 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
describe Crowdring::Ringer do
+ let(:ringer){ create(:ringer) }
+
before(:each) do
DataMapper.auto_migrate!
- @number1 = '+18001111111'
- @number2 = '+18002222222'
- @number3 = '+18003333333'
- end
-
- it 'should not create two ringers with the same phone number' do
- Crowdring::Ringer.create(phone_number: @number1).saved?.should be_true
- Crowdring::Ringer.create(phone_number: @number1).saved?.should be_false
- end
-
- it 'should not create a ringer with an invalid phone number' do
- Crowdring::Ringer.create(phone_number: 'invalid!').saved?.should be_false
- end
-
- it 'should destroy all relevant memberships when destroying a ringer' do
- campaign = Crowdring::Campaign.create(title: 'campaign')
- campaign.voice_numbers = [{phone_number: @number1, description: 'num1'}]
- campaign.sms_number = @number2
- campaign.save
-
- ringer = Crowdring::Ringer.create(phone_number: @number1)
-
- campaign.voice_numbers.first.ring(ringer)
- ringer.destroy
-
- Crowdring::Ringer.all.count.should eq(0)
- Crowdring::Ring.all.count.should eq(0)
- Crowdring::Campaign.all.count.should eq(1)
end
- it 'should be tagged with the ringers area code upon creation' do
- ringer = Crowdring::Ringer.create(phone_number: @number1)
+ it { should validate_presence_of :phone_number}
+ it { should have_many(:tags)}
+ it { should have_many(:ringer_taggings)}
+ it { should have_many(:rings)}
+ it { should validate_uniqueness_of :phone_number}
- ringer.tags.should include(Crowdring::Tag.from_str('area code:800'))
+ context "Invalid ringer phone_number" do
+ let(:invalid){ build(:invalid_ringer) }
+ it { invalid.should_not be_valid}
end
- it 'should be tagged with the ringers country name upon creation' do
- ringer = Crowdring::Ringer.create(phone_number: @number1)
+ context "New ringer has tag of area code" do
+ let(:area_code){ build(:area_code)}
+ let(:country){ build(:country)}
- ringer.tags.should include(Crowdring::Tag.from_str('country:united states'))
- end
+ subject{ Crowdring::Ringer.create(phone_number: '+12121111111')}
- it 'should interpret numbers with and without a + sign as being the same' do
- r1 = Crowdring::Ringer.from('+18001111111')
- r2 = Crowdring::Ringer.from('18001111111')
-
- Crowdring::Ringer.count.should eq(1)
- r2.should eq(r1)
+ its(:tags){should include area_code}
+ its(:tags){should include country}
end
-
- it 'should assume a number without a country code is a US number' do
- r1 = Crowdring::Ringer.from('+18001111111')
- r2 = Crowdring::Ringer.from('8001111111')
-
- Crowdring::Ringer.count.should eq(1)
- r2.should eq(r1)
- end
-
-
end
View
8 spec/spec_helper.rb
@@ -3,6 +3,14 @@
require 'pusher-fake'
require 'fakeweb'
+require 'factory_girl'
+require 'dm-rspec'
+require 'factories'
+
+RSpec.configure do |config|
+ config.include FactoryGirl::Syntax::Methods
+ config.include(DataMapper::Matchers)
+end
ENV['RACK_ENV'] ||= 'test'
ENV['PUSHER_APP_ID'] = 'app_id'
Please sign in to comment.
Something went wrong with that request. Please try again.