summaryrefslogtreecommitdiff
path: root/test/unit/sip_account_test.rb
blob: e85e4933bedd72d67c0f629243ea68baf38b6ebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'test_helper'

class SipAccountTest < ActiveSupport::TestCase
  
  def test_should_have_a_valid_factory
    assert FactoryGirl.build(:sip_account).valid?
  end
  
  test "that the value_of_to_s field is filled" do
    sip_account = FactoryGirl.create(:sip_account)
    assert_equal sip_account.value_of_to_s, sip_account.to_s
  end
  
  test "should have a unique auth_name per sip_domain" do
    provider_sip_domain = FactoryGirl.create(:sip_domain)
    tenants      = []
    sip_accounts = []
    2.times { |i|
      tenants[i] = provider_sip_domain.tenants.create(FactoryGirl.build(:tenant).attributes)
      sip_accounts[i] = FactoryGirl.build(
        :sip_account,
        :sip_accountable => tenants[i],
        :auth_name => "somerandomauthname",
        :tenant_id => tenants[i].id
        )
    }
    sip_accounts[0].save!
    
    assert   sip_accounts[0].valid?
    assert ! sip_accounts[1].valid?,
      "Shouldn't be possible to use the same phone number more than once per SIP realm."
  end
  
end