Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored campaign spec.

  • Loading branch information...
commit 874d900b3b14d2eee111ef0d564a3c650a214f98 1 parent 9fb8954
Willa authored
Showing with 153 additions and 171 deletions.
  1. +2 −1  .rspec
  2. +56 −58 Gemfile.lock
  3. +93 −111 spec/campaign_spec.rb
  4. +2 −1  spec/spec_helper.rb
View
3  .rspec
@@ -1,2 +1,3 @@
--color
---require spec_helper
+--require spec_helper
+--order rand:3455
View
114 Gemfile.lock
@@ -1,44 +1,44 @@
GIT
remote: git://github.com/mattetti/googlecharts.git
- revision: 8a0afd24a489fcb6195e395634a89b6657a4b2b1
+ revision: b0f9d44cf8c8dcfc521661e02036b73306041e75
specs:
googlecharts (1.6.8)
GIT
remote: git://github.com/michelson/lazy_high_charts.git
- revision: e43d60bff31874e54c490c60312b50d09914e9bf
+ revision: c2b17d09f5abb1f5aa29206eaf42ebe59c9503da
specs:
- lazy_high_charts (1.3.3.beta)
+ lazy_high_charts (1.3.3)
bundler (~> 1.0)
hash-deep-merge
GIT
remote: git://github.com/wmoxam/phonie.git
- revision: 685aa4edcb644c433c4b2d40ea1bcc0803ae4976
+ revision: f56672121cfd237d03691120eacf5725a722deba
specs:
- phonie (1.0.1)
+ phonie (1.0.3)
GEM
remote: https://rubygems.org/
specs:
- actionpack (3.2.11)
- activemodel (= 3.2.11)
- activesupport (= 3.2.11)
+ actionpack (3.2.12)
+ activemodel (= 3.2.12)
+ activesupport (= 3.2.12)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
- rack (~> 1.4.0)
+ rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
- activemodel (3.2.11)
- activesupport (= 3.2.11)
+ activemodel (3.2.12)
+ activesupport (= 3.2.12)
builder (~> 3.0.0)
- activesupport (3.2.11)
+ activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.2.8)
- backports (2.6.7)
+ backports (3.1.1)
bcrypt-ruby (3.0.1)
bourne (1.1.2)
mocha (= 0.10.5)
@@ -50,10 +50,10 @@ GEM
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 1.0.0)
- childprocess (0.3.6)
- ffi (~> 1.0, >= 1.0.6)
+ childprocess (0.3.9)
+ ffi (~> 1.0, >= 1.0.11)
daemons (1.1.9)
- data_objects (0.10.11)
+ data_objects (0.10.12)
addressable (~> 2.1)
datamapper (1.2.0)
dm-aggregates (~> 1.2.0)
@@ -65,7 +65,7 @@ GEM
dm-transactions (~> 1.2.0)
dm-types (~> 1.2.0)
dm-validations (~> 1.2.0)
- diff-lcs (1.1.3)
+ diff-lcs (1.2.1)
dm-aggregates (1.2.0)
dm-core (~> 1.2.0)
dm-constraints (1.2.0)
@@ -82,7 +82,7 @@ GEM
dm-postgres-adapter (1.2.0)
dm-do-adapter (~> 1.2.0)
do_postgres (~> 0.10.6)
- dm-rspec (0.2.3)
+ dm-rspec (0.2.4)
dm-core
dm-validations
dm-serializer (1.2.2)
@@ -105,53 +105,51 @@ GEM
uuidtools (~> 2.1)
dm-validations (1.2.0)
dm-core (~> 1.2.0)
- do_postgres (0.10.11)
- data_objects (= 0.10.11)
+ do_postgres (0.10.12)
+ data_objects (= 0.10.12)
em-websocket (0.3.8)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
erubis (2.7.0)
- eventmachine (1.0.0)
+ eventmachine (1.0.3)
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)
- foreman (0.61.0)
+ ffi (1.4.0)
+ foreman (0.62.0)
thor (>= 0.13.6)
- haml (3.1.7)
+ haml (4.0.0)
+ tilt
hash-deep-merge (0.1.1)
- hashie (1.2.0)
+ hashie (2.0.2)
hike (1.2.1)
- i18n (0.6.1)
+ i18n (0.6.4)
journey (1.0.4)
- json (1.7.6)
- json_pure (1.7.6)
- jwt (0.1.5)
+ json (1.7.7)
+ json_pure (1.7.7)
+ jwt (0.1.6)
multi_json (>= 1.0)
- libwebsocket (0.1.7.1)
- addressable
- websocket
metaclass (0.0.1)
- mime-types (1.19)
+ mime-types (1.21)
mocha (0.10.5)
metaclass (~> 0.0.1)
multi_json (1.3.7)
- nexmo (1.0.0)
+ nexmo (1.1.0)
nokogiri (1.5.6)
plivo (0.2.15)
builder (>= 2.1.2)
json (>= 1.6.6)
rest-client (>= 1.6.7)
- pusher (0.11.2)
+ pusher (0.11.3)
multi_json (~> 1.0)
signature (~> 0.1.6)
pusher-fake (0.2.0)
em-websocket (= 0.3.8)
- multi_json (~> 1.3.7)
+ multi_json (= 1.3.7)
thin (= 1.5.0)
- rack (1.4.4)
+ rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-flash (0.1.2)
@@ -159,9 +157,9 @@ GEM
rack-flash3 (1.0.3)
rack
rack
- rack-protection (1.3.2)
+ rack-protection (1.4.0)
rack
- rack-ssl (1.3.2)
+ rack-ssl (1.3.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
@@ -169,38 +167,38 @@ GEM
rack (>= 1.0)
rack-test (>= 0.5)
rake (10.0.3)
- redis (3.0.2)
+ redis (3.0.3)
redis-namespace (1.2.1)
redis (~> 3.0.0)
- resque (1.23.0)
+ resque (1.23.1)
multi_json (~> 1.0)
redis-namespace (~> 1.0)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
rest-client (1.6.7)
mime-types (>= 1.16)
- rspec (2.12.0)
- rspec-core (~> 2.12.0)
- rspec-expectations (~> 2.12.0)
- rspec-mocks (~> 2.12.0)
- rspec-core (2.12.2)
- rspec-expectations (2.12.1)
- diff-lcs (~> 1.1.3)
- rspec-mocks (2.12.1)
+ rspec (2.13.0)
+ rspec-core (~> 2.13.0)
+ rspec-expectations (~> 2.13.0)
+ rspec-mocks (~> 2.13.0)
+ rspec-core (2.13.1)
+ rspec-expectations (2.13.0)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.13.0)
rubyzip (0.9.9)
rufus-tokyo (1.0.7)
- selenium-webdriver (2.27.2)
+ selenium-webdriver (2.31.0)
childprocess (>= 0.2.5)
- libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
+ websocket (~> 1.0.4)
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)
- rack-protection (~> 1.2)
+ sinatra (1.3.5)
+ rack (~> 1.4)
+ rack-protection (~> 1.3)
tilt (~> 1.3, >= 1.3.3)
sinatra-authentication (0.4.1)
dm-core
@@ -234,9 +232,9 @@ GEM
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
- thor (0.16.0)
- tilt (1.3.3)
- tropo-provisioning (0.0.24)
+ thor (0.17.0)
+ tilt (1.3.5)
+ tropo-provisioning (0.0.27)
activesupport
hashie (>= 0.2.1)
i18n
@@ -250,7 +248,7 @@ GEM
uuidtools (2.1.3)
vegas (0.1.11)
rack (>= 1.0.0)
- websocket (1.0.6)
+ websocket (1.0.7)
xpath (1.0.0)
nokogiri (~> 1.3)
yajl-ruby (1.1.0)
View
204 spec/campaign_spec.rb
@@ -1,134 +1,116 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
describe Crowdring::Campaign do
- let(:campaign) { create(:campaign) }
it { should validate_presence_of :goal }
it { should have_many :rings }
it { should have_many :asks }
it { should have_many :ivrs }
it { should have_many :aggregate_campaigns }
it { should have_many :voice_numbers }
- it { should have_one :sms_number }
- def app
- Crowdring::Server
- end
-
-
- describe 'campaign creation' do
- before(:each) do
- DataMapper.auto_migrate!
- @number1 = {phone_number: '+18001111111', description: 'num1'}
- @number2 = '+18002222222'
- @number3 = '+18003333333'
- @c = Crowdring::Campaign.create(title: 'test')
+ it { should have_one :sms_number}
+
+ let(:voice_number) { [{phone_number: '+18001111111', description: 'numer1'}]}
+ let(:sms_number){ '+18002222222'}
+ let(:goal) { 100 }
+ let(:campaign) { Crowdring::Campaign.create(title: 'test', voice_numbers: voice_number, sms_number: sms_number, goal: goal)}
+ before { DataMapper.auto_migrate! }
+ context 'campaign creation' do
+
+ context 'Create with valid parameters' do
+ subject { campaign }
+ its(:title) { should == 'test'}
+ its(:voice_numbers){ should == Crowdring::AssignedVoiceNumber.all }
+ its(:sms_number) { should == Crowdring::AssignedSMSNumber.first }
end
- it 'should create a campaign with a voice number and a sms number' do
- @campaign = Crowdring::Campaign.create(title: 'test2', voice_numbers: [@number1], sms_number: @number2)
-
- @campaign.save.should be_true
- @campaign.voice_numbers.first.should eq(Crowdring::AssignedVoiceNumber.first)
- @campaign.sms_number.should eq(Crowdring::AssignedSMSNumber.first)
- end
-
- it 'should remove the assigned numbers on campaign destruction' do
- @c.voice_numbers.new(@number1)
- @c.sms_number = @number2
- @c.save
-
- @c.destroy.should be_true
- Crowdring::AssignedCampaignVoiceNumber.all.should be_empty
- Crowdring::AssignedSMSNumber.all.should be_empty
+ context 'Create with invalid parameters' do
+ subject { Crowdring::Campaign.create()}
+ its(:title) { should be_nil }
+ its(:valid?) { should be_false }
end
- it 'should not allow assignment of an invalid phone number' do
- @c.voice_numbers.new({phone_number:'badger, badger', description: 'nonsense'})
- @c.save.should be_false
- end
+ context 'Destroy a campaign' do
+ subject { campaign.destroy }
+ it { should be_true }
- it 'should not allow assigning the same number to multiple campaigns' do
- c1 = Crowdring::Campaign.create(title: 'test1')
- c1.voice_numbers.new(@number1)
- c1.save
+ subject { Crowdring::AssignedCampaignVoiceNumber.all }
+ it { should be_empty }
- c2 = Crowdring::Campaign.create(title: 'test2')
- c2.voice_numbers.new(@number1)
-
- c2.save.should be_false
+ subject { Crowdring::AssignedSMSNumber.all }
+ it { should be_empty }
end
- it 'should create a default offline ask upon campaign creation' do
- c1 = Crowdring::Campaign.create(title: 'test1', voice_numbers: [{phone_number: '18001111111', description: 'foo'}])
-
- c1.saved?.should be_true
- c1.asks.first.is_a?(Crowdring::OfflineAsk).should be_true
- end
-
- it 'should not allow creation of 2 campaigns with the same name and provide a useful error' do
- c1 = Crowdring::Campaign.create(title: 'test', voice_numbers: [{phone_number: '18001111111', description: 'foo'}])
- c2 = Crowdring::Campaign.new(title: 'test', voice_numbers: [{phone_number: '18001111112', description: 'bar'}])
-
- c1.save.should be_true
- c2.save.should be_false
- c2.all_errors.map(&:full_messages).join('|').should match(/title/i)
+ context 'Offline Ask creation' do
+ subject { campaign.asks.first }
+ its(:title) { should include('Offline Ask') }
+ its(:class) { should == Crowdring::OfflineAsk }
end
end
+ context 'Campaign and Ringer' do
+ let(:ana) { build(:ringer) }
+ let(:jack) { build(:ringer)}
- describe 'campaign and ringer' do
- before(:each) do
- DataMapper.auto_migrate!
- @number1 = '+18001111111'
- @number2 = '+18002222222'
- @number3 = '+18003333333'
- @number4 = '+18004444444'
- @number5 = '+18005555555'
- @c = Crowdring::Campaign.create(title: 'test', voice_numbers: [{phone_number: @number2, description: 'num1'}], sms_number: @number3)
+ before do
+ subject { campaign }
+ campaign.rings.stub_chain(:create, :saved?).and_return(true)
end
- it 'should have many ringers' do
- r1 = Crowdring::Ringer.create(phone_number: @number1)
- r2 = Crowdring::Ringer.create(phone_number: @number2)
- @c.rings.create(ringer: r1)
- @c.rings.create(ringer: r2)
-
- @c.ringers.should include(Crowdring::Ringer.first(phone_number: @number1))
- @c.ringers.should include(Crowdring::Ringer.first(phone_number: @number2))
- end
-
- it 'should track the original date a ringer supported a campaign' do
- r = Crowdring::Ringer.create(phone_number: @number2)
- @c.voice_numbers.first.ring(r)
-
- @c.rings.first.created_at.to_date.should eq(Date.today)
- end
-
- it 'should track all of the times a ringer rings a campaign' do
- r = Crowdring::Ringer.create(phone_number: @number2)
- @c.voice_numbers.first.ring(r)
-
- @c.rings.count.should eq(1)
- end
-
- it 'should remove rings when a campaign is destroyed' do
- r = Crowdring::Ringer.create(phone_number: @number2)
- @c.voice_numbers.first.ring(r)
- @c.destroy
-
- Crowdring::Ring.all.should be_empty
- Crowdring::Ringer.all.count.should eq(1)
- end
-
- it 'should be able to provide the ringers of a certain assigned number' do
- @c.voice_numbers << {phone_number: @number3, description: 'num3'}
- @c.save
- r = Crowdring::Ringer.create(phone_number: @number4)
- r2 = Crowdring::Ringer.create(phone_number: @number5)
- @c.voice_numbers.first.ring(r)
- @c.voice_numbers.last.ring(r2)
-
- @c.ringers_from(@c.voice_numbers.first).should eq([r])
- @c.ringers_from(@c.voice_numbers.last).should eq([r2])
- end
+ subject { campaign.ring(ana) }
+ it { should be_true }
end
+ # describe 'campaign and ringer' do
+ # before(:each) do
+ # DataMapper.auto_migrate!
+ # @number1 = '+18001111111'
+ # @number2 = '+18002222222'
+ # @number3 = '+18003333333'
+ # @number4 = '+18004444444'
+ # @number5 = '+18005555555'
+ # @c = Crowdring::Campaign.create(title: 'test', voice_numbers: [{phone_number: @number2, description: 'num1'}], sms_number: @number3)
+ # end
+
+ # it 'should have many ringers' do
+ # r1 = Crowdring::Ringer.create(phone_number: @number1)
+ # r2 = Crowdring::Ringer.create(phone_number: @number2)
+ # @c.rings.create(ringer: r1)
+ # @c.rings.create(ringer: r2)
+
+ # @c.ringers.should include(Crowdring::Ringer.first(phone_number: @number1))
+ # @c.ringers.should include(Crowdring::Ringer.first(phone_number: @number2))
+ # end
+
+ # it 'should track the original date a ringer supported a campaign' do
+ # r = Crowdring::Ringer.create(phone_number: @number2)
+ # @c.voice_numbers.first.ring(r)
+
+ # @c.rings.first.created_at.to_date.should eq(Date.today)
+ # end
+
+ # it 'should track all of the times a ringer rings a campaign' do
+ # r = Crowdring::Ringer.create(phone_number: @number2)
+ # @c.voice_numbers.first.ring(r)
+
+ # @c.rings.count.should eq(1)
+ # end
+
+ # it 'should remove rings when a campaign is destroyed' do
+ # r = Crowdring::Ringer.create(phone_number: @number2)
+ # @c.voice_numbers.first.ring(r)
+ # @c.destroy
+
+ # Crowdring::Ring.all.should be_empty
+ # Crowdring::Ringer.all.count.should eq(1)
+ # end
+
+ # it 'should be able to provide the ringers of a certain assigned number' do
+ # @c.voice_numbers << {phone_number: @number3, description: 'num3'}
+ # @c.save
+ # r = Crowdring::Ringer.create(phone_number: @number4)
+ # r2 = Crowdring::Ringer.create(phone_number: @number5)
+ # @c.voice_numbers.first.ring(r)
+ # @c.voice_numbers.last.ring(r2)
+
+ # @c.ringers_from(@c.voice_numbers.first).should eq([r])
+ # @c.ringers_from(@c.voice_numbers.last).should eq([r2])
+ # end
+ # end
end
View
3  spec/spec_helper.rb
@@ -9,7 +9,8 @@
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
- config.include(DataMapper::Matchers)
+ config.include DataMapper::Matchers
+ config.order = 'random'
end
ENV['RACK_ENV'] ||= 'test'

0 comments on commit 874d900

Please sign in to comment.
Something went wrong with that request. Please try again.