Browse files

Use CallBehaviour state constants and removed related definition from…

… Call class
  • Loading branch information...
1 parent 9af637a commit c6c4fa7ba7a10819e25e070765e722d060bd0ee0 Zhao Lu committed Sep 20, 2011
View
2 Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/o2Labs/play.git
- revision: 6f16b10f05f0a1a6d31eae8ed2d4b34b8bfa75b0
+ revision: 21d421cf217dd86e0b04590be95d484e682db4d2
specs:
connfu (0.0.3)
blather (= 0.5.4)
View
22 app/models/call.rb
@@ -2,21 +2,6 @@ class Call < ActiveRecord::Base
belongs_to :account
belongs_to :endpoint
- STATES = [
- :rejected,
- :caller_ringing,
- :recipient_ringing,
- :caller_answered,
- :recipient_answered,
- :recipient_busy,
- :answered,
- :ended
- ]
-
- STATES.each do |state|
- const_set state.to_s.upcase, state
- end
-
def openvoice_address
endpoint.account.address
end
@@ -25,12 +10,11 @@ def update_state!(state)
update_attributes(:state => state)
end
- def state
- self['state'].to_sym
- end
-
def display_state
state.to_s.humanize
end
+ def state
+ self['state'].to_sym
+ end
end
View
2 lib/incoming_call.rb
@@ -19,7 +19,7 @@ class IncomingCall
call_id, endpoint = *establish_call
if call_id
- call_record.state = Call::ANSWERED
+ call_record.state = Connfu::Dsl::CallBehaviour::ANSWERED
call_record.endpoint = endpoint
call_record.save!
View
14 lib/jobs/outgoing_call.rb
@@ -19,7 +19,7 @@ def self.perform(call_record_id)
hangup "#{call_id}@#{Connfu.connection.jid.domain}"
end
c.on_reject do
- call.update_state!(Call::REJECTED)
+ call.update_state!(c.state)
if call_id != last_event_call_id
hangup "#{call_id}@#{Connfu.connection.jid.domain}"
@rejected = true
@@ -29,27 +29,27 @@ def self.perform(call_record_id)
c.on_ringing do
case last_event_call_id
when call_id
- call.update_state!(Call::CALLER_RINGING)
+ call.update_state!("caller " + c.state.to_s)
when @joined_call_id
- call.update_state!(Call::RECIPIENT_RINGING)
+ call.update_state!("recipient " + c.state.to_s)
end
end
c.on_answer do
case last_event_call_id
when call_id
- call.update_state!(Call::CALLER_ANSWERED)
+ call.update_state!("caller " + c.state.to_s)
@joined_call_id = dial_join({:dial_to => recipient, :dial_from => openvoice_address})
when @joined_call_id
- call.update_state!(Call::RECIPIENT_ANSWERED)
+ call.update_state!("recipient " + c.state.to_s)
end
end
c.on_busy do
- call.update_state!(Call::RECIPIENT_BUSY)
+ call.update_state!(c.state)
hangup "#{call_id}@#{Connfu.connection.jid.domain}"
end
c.on_hangup do
unless @rejected
- call.update_state!(Call::ENDED)
+ call.update_state!(c.state)
if call_id == last_event_call_id
hangup "#{@joined_call_id}@#{Connfu.connection.jid.domain}"
else
View
4 spec/models/call_spec.rb
@@ -7,9 +7,9 @@
end
it "persists state to given value" do
- subject.update_state!(Call::REJECTED)
+ subject.update_state!(:rejected)
subject.reload
- subject.state.should eql(Call::REJECTED)
+ subject.state.should eql(Connfu::Dsl::CallBehaviour::REJECTED)
end
end
end
View
4 spec/models/incoming_call_spec.rb
@@ -194,7 +194,7 @@
it 'should log the call as answered by the endpoint' do
logged_call = @account.calls.last
logged_call.endpoint.should eql(@endpoint_one)
- logged_call.state.should eql(Call::ANSWERED)
+ logged_call.state.should eql(Connfu::Dsl::CallBehaviour::ANSWERED)
end
it 'should hangup the caller when the openvoice endpoint hangs up' do
@@ -450,7 +450,7 @@
it 'should log the call as answered by the endpoint' do
logged_call = @account.calls.last
logged_call.endpoint.should eql(@endpoint_one)
- logged_call.state.should eql(Call::ANSWERED)
+ logged_call.state.should eql(Connfu::Dsl::CallBehaviour::ANSWERED)
end
it 'should not hang up the call' do
View
20 spec/models/outgoing_call_spec.rb
@@ -39,7 +39,7 @@
end
it 'should set the Call state to caller ringing' do
- @call.reload.state.should eq Call::CALLER_RINGING
+ @call.reload.state.should eq ('caller ' + Connfu::Dsl::CallBehaviour::RINGING.to_s).to_sym
end
describe "when the openvoice endpoint answers" do
@@ -61,7 +61,7 @@
end
it 'should set the Call state to caller answered' do
- @call.reload.state.should eq Call::CALLER_ANSWERED
+ @call.reload.state.should eq ('caller ' + Connfu::Dsl::CallBehaviour::ANSWERED.to_s).to_sym
end
describe "when recipient is ringing" do
@@ -73,7 +73,7 @@
end
it "should set the state to recipient ringing" do
- @call.reload.state.should eq Call::RECIPIENT_RINGING
+ @call.reload.state.should eq ('recipient ' + Connfu::Dsl::CallBehaviour::RINGING.to_s).to_sym
end
describe "when recipient answers" do
@@ -86,7 +86,7 @@
end
it "should set the state to recipient answered" do
- @call.reload.state.should eq Call::RECIPIENT_ANSWERED
+ @call.reload.state.should eq ('recipient ' + Connfu::Dsl::CallBehaviour::ANSWERED.to_s).to_sym
end
describe "and the recipient hangs up" do
@@ -102,7 +102,7 @@
end
it "should set the state to call ended" do
- @call.reload.state.should eq Call::ENDED
+ @call.reload.state.should eq Connfu::Dsl::CallBehaviour::HANGUP
end
end
@@ -119,7 +119,7 @@
end
it "should set the state to call ended" do
- @call.reload.state.should eq Call::ENDED
+ @call.reload.state.should eq Connfu::Dsl::CallBehaviour::HANGUP
end
end
end
@@ -130,7 +130,7 @@
end
it "should set the state to call rejected" do
- @call.reload.state.should eq Call::REJECTED
+ @call.reload.state.should eq Connfu::Dsl::CallBehaviour::REJECTED
end
it "should hang up the openvoice user's endpoint" do
@@ -181,8 +181,8 @@
incoming :busy_presence, @joined_call_jid
end
- it "shold set the state to call recipient busy" do
- @call.reload.state.should eq Call::RECIPIENT_BUSY
+ it "should set the state to call recipient busy" do
+ @call.reload.state.should eq Connfu::Dsl::CallBehaviour::BUSY
end
it "should hang up the openvoice user's endpoint" do
@@ -214,7 +214,7 @@
end
it "should set the call state to rejected" do
- @call.reload.state.should eq Call::REJECTED
+ @call.reload.state.should eq Connfu::Dsl::CallBehaviour::REJECTED
end
it "should mark the handler as finished" do

0 comments on commit c6c4fa7

Please sign in to comment.