summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:01:45 +0100
commitb80bd744ad873f6fc43018bc4bfb90677de167bd (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /test/unit
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
Start of GS5.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/.gitkeep0
-rw-r--r--test/unit/access_authorization_test.rb7
-rw-r--r--test/unit/acd_agent_test.rb7
-rw-r--r--test/unit/acd_caller_test.rb7
-rw-r--r--test/unit/address_test.rb7
-rw-r--r--test/unit/api/row_test.rb7
-rw-r--r--test/unit/area_code_test.rb7
-rw-r--r--test/unit/automatic_call_distributor_test.rb7
-rw-r--r--test/unit/call_forward_case_test.rb7
-rw-r--r--test/unit/call_forward_test.rb9
-rw-r--r--test/unit/callthrough_test.rb134
-rw-r--r--test/unit/conference_invitee_test.rb17
-rw-r--r--test/unit/conference_test.rb48
-rw-r--r--test/unit/country_test.rb7
-rw-r--r--test/unit/dial_in_number_store_test.rb7
-rw-r--r--test/unit/fax_account_test.rb7
-rw-r--r--test/unit/fax_document_test.rb7
-rw-r--r--test/unit/fax_page_test.rb7
-rw-r--r--test/unit/fax_resolution_test.rb7
-rw-r--r--test/unit/fax_thumbnail_test.rb7
-rw-r--r--test/unit/gemeinschaft_setup_test.rb7
-rw-r--r--test/unit/gs_cluster_sync_log_entry_test.rb7
-rw-r--r--test/unit/gs_node_test.rb7
-rw-r--r--test/unit/gui_function_membership_test.rb7
-rw-r--r--test/unit/gui_function_test.rb7
-rw-r--r--test/unit/helpers/api/rows_helper_test.rb4
-rw-r--r--test/unit/helpers/config_siemens_helper_test.rb4
-rw-r--r--test/unit/helpers/page_helper_test.rb4
-rw-r--r--test/unit/helpers/sessions_helper_test.rb4
-rw-r--r--test/unit/hunt_group_member_test.rb7
-rw-r--r--test/unit/hunt_group_test.rb7
-rw-r--r--test/unit/language_test.rb7
-rw-r--r--test/unit/manufacturer_test.rb27
-rw-r--r--test/unit/oui_test.rb14
-rw-r--r--test/unit/phone_book_entry_test.rb51
-rw-r--r--test/unit/phone_book_test.rb119
-rw-r--r--test/unit/phone_model_test.rb9
-rw-r--r--test/unit/phone_number_range_test.rb9
-rw-r--r--test/unit/phone_number_test.rb260
-rw-r--r--test/unit/phone_sip_account_test.rb7
-rw-r--r--test/unit/phone_test.rb49
-rw-r--r--test/unit/ringtone_test.rb7
-rw-r--r--test/unit/sip_account_test.rb34
-rw-r--r--test/unit/sip_domain_test.rb9
-rw-r--r--test/unit/softkey_function_test.rb7
-rw-r--r--test/unit/softkey_test.rb7
-rw-r--r--test/unit/system_message_test.rb7
-rw-r--r--test/unit/tenant_membership_test.rb14
-rw-r--r--test/unit/tenant_test.rb33
-rw-r--r--test/unit/user_group_membership_test.rb39
-rw-r--r--test/unit/user_group_test.rb38
-rw-r--r--test/unit/user_test.rb82
-rw-r--r--test/unit/whitelist_test.rb7
53 files changed, 1214 insertions, 0 deletions
diff --git a/test/unit/.gitkeep b/test/unit/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/unit/.gitkeep
diff --git a/test/unit/access_authorization_test.rb b/test/unit/access_authorization_test.rb
new file mode 100644
index 0000000..ebd9f0b
--- /dev/null
+++ b/test/unit/access_authorization_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AccessAuthorizationTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert AccessAuthorization.new.valid?
+ # end
+end
diff --git a/test/unit/acd_agent_test.rb b/test/unit/acd_agent_test.rb
new file mode 100644
index 0000000..9e1a116
--- /dev/null
+++ b/test/unit/acd_agent_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AcdAgentTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert AcdAgent.new.valid?
+ end
+end
diff --git a/test/unit/acd_caller_test.rb b/test/unit/acd_caller_test.rb
new file mode 100644
index 0000000..68d5801
--- /dev/null
+++ b/test/unit/acd_caller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AcdCallerTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert AcdCaller.new.valid?
+ end
+end
diff --git a/test/unit/address_test.rb b/test/unit/address_test.rb
new file mode 100644
index 0000000..6d676ba
--- /dev/null
+++ b/test/unit/address_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AddressTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert Address.new.valid?
+ end
+end
diff --git a/test/unit/api/row_test.rb b/test/unit/api/row_test.rb
new file mode 100644
index 0000000..dc21050
--- /dev/null
+++ b/test/unit/api/row_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class Api::RowTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/area_code_test.rb b/test/unit/area_code_test.rb
new file mode 100644
index 0000000..10c7c08
--- /dev/null
+++ b/test/unit/area_code_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AreaCodeTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:area_code).valid?
+ end
+end
diff --git a/test/unit/automatic_call_distributor_test.rb b/test/unit/automatic_call_distributor_test.rb
new file mode 100644
index 0000000..b025df8
--- /dev/null
+++ b/test/unit/automatic_call_distributor_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class AutomaticCallDistributorTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert AutomaticCallDistributor.new.valid?
+ end
+end
diff --git a/test/unit/call_forward_case_test.rb b/test/unit/call_forward_case_test.rb
new file mode 100644
index 0000000..0d1d238
--- /dev/null
+++ b/test/unit/call_forward_case_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CallForwardCaseTest < ActiveSupport::TestCase
+
+ # Cannot be factory'd. CallForwardCases are seeded.
+
+end
diff --git a/test/unit/call_forward_test.rb b/test/unit/call_forward_test.rb
new file mode 100644
index 0000000..95716c5
--- /dev/null
+++ b/test/unit/call_forward_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class CallForwardTest < ActiveSupport::TestCase
+
+ test "should have a valid factory" do
+ assert Factory.build(:call_forward).valid?
+ end
+
+end
diff --git a/test/unit/callthrough_test.rb b/test/unit/callthrough_test.rb
new file mode 100644
index 0000000..c1c6ab3
--- /dev/null
+++ b/test/unit/callthrough_test.rb
@@ -0,0 +1,134 @@
+require 'test_helper'
+
+class CallthroughTest < ActiveSupport::TestCase
+ def setup
+ # Basic setup of a new system
+ #
+ germany = Country.create(:name => "Germany", :country_code => "49", :international_call_prefix => "00", :trunk_prefix => "0" )
+ Language.create(:name => 'Deutsch', :code => 'de')
+ AreaCode.create(:country => germany, :name => "Bendorf", :area_code => "2622")
+
+ @gemeinschaft_setup = GemeinschaftSetup.new
+ @gemeinschaft_setup.country = Country.first
+ @gemeinschaft_setup.language = Language.first
+
+ @current_user = @gemeinschaft_setup.build_user(
+ :user_name => I18n.t('gemeinschaft_setups.initial_setup.admin_name'),
+ :male => true,
+ :email => 'admin@localhost',
+ :first_name => 'Max',
+ :last_name => 'Mustermann',
+ :password => 'xxxxxxxxxx',
+ :password_confirmation => 'xxxxxxxxxx',
+ :language_id => Language.first.id,
+ )
+ @sip_domain = @gemeinschaft_setup.build_sip_domain(
+ :host => '10.0.0.1',
+ :realm => '10.0.0.1',
+ )
+
+ @gemeinschaft_setup.save
+
+ super_tenant = Tenant.create(
+ :name => SUPER_TENANT_NAME,
+ :country_id => @gemeinschaft_setup.country.id,
+ :language_id => @gemeinschaft_setup.language_id,
+ :description => I18n.t('gemeinschaft_setups.initial_setup.super_tenant_description'),
+ )
+
+ # Admin
+ super_tenant.tenant_memberships.create(:user_id => @gemeinschaft_setup.user.id)
+
+ # Create the Super-Tenant's group:
+ super_tenant_super_admin_group = super_tenant.user_groups.create(:name => I18n.t('gemeinschaft_setups.initial_setup.super_admin_group_name'))
+ super_tenant_super_admin_group.user_group_memberships.create(:user_id => @gemeinschaft_setup.user.id)
+
+ # Create the tenant.
+ #
+ @tenant = @sip_domain.tenants.build(:name => 'AMOOMA GmbH')
+ @tenant.country = Country.first
+ @tenant.language = Language.first
+ @tenant.internal_extension_ranges = '10-20'
+ @tenant.did_list = '02622-70648-x, 02622-706480'
+ @tenant.save
+
+ @tenant.tenant_memberships.create(:user_id => @current_user.id)
+ @current_user.update_attributes!(:current_tenant_id => @tenant.id)
+
+ # The first user becomes a member of the 'admin' UserGroup
+ #
+ admin_group = @tenant.user_groups.create(:name => I18n.t('gemeinschaft_setups.initial_setup.admin_group_name'))
+ admin_group.users << @current_user
+
+ # User group
+ #
+ user_group = @tenant.user_groups.create(:name => I18n.t('gemeinschaft_setups.initial_setup.user_group_name'))
+ user_group.users << @current_user
+
+ # Generate the internal_extensions
+ #
+ @tenant.generate_internal_extensions
+
+ # Generate the external numbers (DIDs)
+ #
+ @tenant.generate_dids
+ end
+
+ test 'the setup should create a valid system' do
+ # Basics
+ #
+ assert_equal 1, Country.count
+ assert_equal 1, Language.count
+
+ # Testing the installation
+ #
+ assert @gemeinschaft_setup.valid?
+ assert @sip_domain.valid?
+ assert @current_user.valid?
+
+ assert @tenant.valid?
+
+ assert_equal 0, SipAccount.count
+ assert_equal 2, Tenant.count
+ assert_equal 1, User.count
+
+ # Check the amount of phone_numbers
+ #
+ assert_equal 11, @tenant.phone_number_ranges.find_by_name(INTERNAL_EXTENSIONS).phone_numbers.count
+ assert_equal 12, @tenant.phone_number_ranges.find_by_name(DIRECT_INWARD_DIALING_NUMBERS).phone_numbers.count
+ end
+
+ test 'that a callthrough can only be created with at least one DID' do
+ assert_equal 0, Callthrough.count
+
+ did = @tenant.phone_number_ranges.find_by_name(DIRECT_INWARD_DIALING_NUMBERS).phone_numbers.first
+
+ callthrough = @tenant.callthroughs.build
+
+ assert !callthrough.valid?
+
+ callthrough.phone_numbers.build(:number => did.number)
+
+ assert callthrough.save
+ assert_equal 1, Callthrough.count
+ end
+
+ # TODO Activate this after fixing unique phone_number
+ #
+ # test 'that one DID can not be used by two different callthroughs' do
+ # assert_equal 0, Callthrough.count
+
+ # did = @tenant.phone_number_ranges.find_by_name(DIRECT_INWARD_DIALING_NUMBERS).phone_numbers.first
+
+ # callthroughs = Array.new
+ # (1..2).each do |i|
+ # callthroughs[i] = @tenant.callthroughs.build
+ # callthroughs[i].phone_numbers.build(:number => did.number)
+ # callthroughs[i].save
+ # end
+
+ # assert callthroughs[1].valid?, '1st Callthrough is not valid'
+ # assert !callthroughs[2].valid?, '2nd Callthrough is not valid'
+ # end
+
+end
diff --git a/test/unit/conference_invitee_test.rb b/test/unit/conference_invitee_test.rb
new file mode 100644
index 0000000..bcc4c9b
--- /dev/null
+++ b/test/unit/conference_invitee_test.rb
@@ -0,0 +1,17 @@
+require 'test_helper'
+
+class ConferenceInviteeTest < ActiveSupport::TestCase
+
+ def test_should_have_a_valid_factory
+ assert Factory.build(:conference_invitee).valid?
+ end
+
+ test "parent conference should not have a phone number twice" do
+ invitee = Factory.create(:conference_invitee)
+ conference = invitee.conference
+ phone_number = PhoneNumber.new(:number => invitee.phone_number.number)
+ invitee_bad = conference.conference_invitees.build(:phone_number => phone_number)
+ assert !invitee_bad.valid?
+ end
+
+end
diff --git a/test/unit/conference_test.rb b/test/unit/conference_test.rb
new file mode 100644
index 0000000..b7cce28
--- /dev/null
+++ b/test/unit/conference_test.rb
@@ -0,0 +1,48 @@
+require 'test_helper'
+
+class ConferenceTest < ActiveSupport::TestCase
+
+ def test_should_have_a_valid_factory
+ assert Factory.build(:conference).valid?
+ end
+
+ def test_dates_must_make_sense
+ # We can't create a conference in the past.
+ assert !Factory.build(:conference, :start => Time.now - 1.day, :end => Time.now + 1.day).valid?
+
+ # But we can create a conference which started 2 minutes ago.
+ assert Factory.build(:conference, :start => Time.now - 2.minutes, :end => Time.now + 1.hour).valid?
+
+ # The end must be before the start.
+ assert !Factory.build(:conference, :start => Time.now + 2.day, :end => Time.now + 1.day).valid?
+
+ # No date at all is fine.
+ assert Factory.build(:conference, :start => nil, :end => nil).valid?
+
+ # Just start or just end is not ok.
+ assert !Factory.build(:conference, :start => nil, :end => Time.now + 1.day).valid?
+ assert !Factory.build(:conference, :start => Time.now + 1.day, :end => nil).valid?
+ end
+
+ def test_pin_must_be_nil_or_more_than_6_digits
+ conference = Factory.build(:conference, :pin => nil)
+
+ assert conference.valid?
+
+ (MINIMUM_PIN_LENGTH - 1).times do |i|
+ pin = "#{10**i}"
+ conference.pin = pin
+ assert !conference.valid?
+ end
+
+ conference.pin = "#{10**(MINIMUM_PIN_LENGTH - 1)}"
+ assert conference.valid?
+
+ conference.pin = "-#{10**(MINIMUM_PIN_LENGTH - 1)}"
+ assert !conference.valid?
+
+ conference.pin = 'Teststring'
+ assert !conference.valid?
+ end
+
+end
diff --git a/test/unit/country_test.rb b/test/unit/country_test.rb
new file mode 100644
index 0000000..4933843
--- /dev/null
+++ b/test/unit/country_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CountryTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:country).valid?
+ end
+end
diff --git a/test/unit/dial_in_number_store_test.rb b/test/unit/dial_in_number_store_test.rb
new file mode 100644
index 0000000..d1341f9
--- /dev/null
+++ b/test/unit/dial_in_number_store_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class DialInNumberStoreTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/fax_account_test.rb b/test/unit/fax_account_test.rb
new file mode 100644
index 0000000..f4048cb
--- /dev/null
+++ b/test/unit/fax_account_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FaxAccountTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert FaxAccount.new.valid?
+ # end
+end
diff --git a/test/unit/fax_document_test.rb b/test/unit/fax_document_test.rb
new file mode 100644
index 0000000..190a953
--- /dev/null
+++ b/test/unit/fax_document_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FaxDocumentTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert FaxDocument.new.valid?
+ # end
+end
diff --git a/test/unit/fax_page_test.rb b/test/unit/fax_page_test.rb
new file mode 100644
index 0000000..522ffd5
--- /dev/null
+++ b/test/unit/fax_page_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FaxPageTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert FaxPage.new.valid?
+ # end
+end
diff --git a/test/unit/fax_resolution_test.rb b/test/unit/fax_resolution_test.rb
new file mode 100644
index 0000000..93676af
--- /dev/null
+++ b/test/unit/fax_resolution_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FaxResolutionTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/fax_thumbnail_test.rb b/test/unit/fax_thumbnail_test.rb
new file mode 100644
index 0000000..4fc5bc8
--- /dev/null
+++ b/test/unit/fax_thumbnail_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FaxThumbnailTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/gemeinschaft_setup_test.rb b/test/unit/gemeinschaft_setup_test.rb
new file mode 100644
index 0000000..5ea6523
--- /dev/null
+++ b/test/unit/gemeinschaft_setup_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class GemeinschaftSetupTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:gemeinschaft_setup).valid?
+ end
+end
diff --git a/test/unit/gs_cluster_sync_log_entry_test.rb b/test/unit/gs_cluster_sync_log_entry_test.rb
new file mode 100644
index 0000000..bff49e9
--- /dev/null
+++ b/test/unit/gs_cluster_sync_log_entry_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class GsClusterSyncLogEntryTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert GsClusterSyncLogEntry.new.valid?
+ end
+end
diff --git a/test/unit/gs_node_test.rb b/test/unit/gs_node_test.rb
new file mode 100644
index 0000000..1155cab
--- /dev/null
+++ b/test/unit/gs_node_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class GsNodeTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert GsNode.new.valid?
+ end
+end
diff --git a/test/unit/gui_function_membership_test.rb b/test/unit/gui_function_membership_test.rb
new file mode 100644
index 0000000..c85ec68
--- /dev/null
+++ b/test/unit/gui_function_membership_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class GuiFunctionMembershipTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/gui_function_test.rb b/test/unit/gui_function_test.rb
new file mode 100644
index 0000000..60bce1d
--- /dev/null
+++ b/test/unit/gui_function_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class GuiFunctionTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert GuiFunction.new.valid?
+ end
+end
diff --git a/test/unit/helpers/api/rows_helper_test.rb b/test/unit/helpers/api/rows_helper_test.rb
new file mode 100644
index 0000000..16c8fe7
--- /dev/null
+++ b/test/unit/helpers/api/rows_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class Api::RowsHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/helpers/config_siemens_helper_test.rb b/test/unit/helpers/config_siemens_helper_test.rb
new file mode 100644
index 0000000..1afae0d
--- /dev/null
+++ b/test/unit/helpers/config_siemens_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ConfigSiemensHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/helpers/page_helper_test.rb b/test/unit/helpers/page_helper_test.rb
new file mode 100644
index 0000000..6009662
--- /dev/null
+++ b/test/unit/helpers/page_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class PageHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/helpers/sessions_helper_test.rb b/test/unit/helpers/sessions_helper_test.rb
new file mode 100644
index 0000000..7d44e09
--- /dev/null
+++ b/test/unit/helpers/sessions_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class SessionsHelperTest < ActionView::TestCase
+end
diff --git a/test/unit/hunt_group_member_test.rb b/test/unit/hunt_group_member_test.rb
new file mode 100644
index 0000000..4472cc2
--- /dev/null
+++ b/test/unit/hunt_group_member_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class HuntGroupMemberTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert HuntGroupMember.new.valid?
+ # end
+end
diff --git a/test/unit/hunt_group_test.rb b/test/unit/hunt_group_test.rb
new file mode 100644
index 0000000..5ef843b
--- /dev/null
+++ b/test/unit/hunt_group_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class HuntGroupTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert HuntGroup.new.valid?
+ # end
+end
diff --git a/test/unit/language_test.rb b/test/unit/language_test.rb
new file mode 100644
index 0000000..3308735
--- /dev/null
+++ b/test/unit/language_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class LanguageTest < ActiveSupport::TestCase
+ test "has a valid factory" do
+ assert Factory.build(:language).valid?
+ end
+end
diff --git a/test/unit/manufacturer_test.rb b/test/unit/manufacturer_test.rb
new file mode 100644
index 0000000..635a977
--- /dev/null
+++ b/test/unit/manufacturer_test.rb
@@ -0,0 +1,27 @@
+require 'test_helper'
+
+class ManufacturerTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:manufacturer).valid?
+ end
+
+ # StateMachine Tests:
+ def test_that_the_initial_state_should_be_active
+ @manufacturer = Factory.create(:manufacturer)
+ assert_equal 'active', @manufacturer.state
+ assert @manufacturer.active?
+ end
+
+ def test_not_active_state_will_not_be_displayed
+ @manufacturer = Factory.create(:manufacturer)
+ assert_equal 1, Manufacturer.count
+
+ @manufacturer.deactivate!
+ assert_equal 0, Manufacturer.count
+ assert_equal 1, Manufacturer.unscoped.count
+
+ @manufacturer.activate!
+ assert_equal 1, Manufacturer.count
+ assert_equal Manufacturer.count, Manufacturer.unscoped.count
+ end
+end
diff --git a/test/unit/oui_test.rb b/test/unit/oui_test.rb
new file mode 100644
index 0000000..de48a97
--- /dev/null
+++ b/test/unit/oui_test.rb
@@ -0,0 +1,14 @@
+require 'test_helper'
+
+class OuiTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:oui).valid?
+ end
+
+ def test_that_the_initial_state_should_be_active
+ @oui = Factory.create(:oui)
+ assert_equal 'active', @oui.state
+ assert @oui.active?
+ end
+
+end
diff --git a/test/unit/phone_book_entry_test.rb b/test/unit/phone_book_entry_test.rb
new file mode 100644
index 0000000..c8d639b
--- /dev/null
+++ b/test/unit/phone_book_entry_test.rb
@@ -0,0 +1,51 @@
+require 'test_helper'
+
+class PhoneBookEntryTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert Factory.build(:phone_book_entry).valid?
+ end
+
+ # TODO Fix this test.
+
+ # test "only user can read entries in private phone books" do
+ # user = Factory.create(:user)
+ # phone_book = Factory.create(:phone_book, :phone_bookable_type => 'User', :phone_bookable_id => user.id)
+ # phone_book_entry = Factory.create(:phone_book_entry, :phone_book_id => phone_book.id)
+
+ # evil_user = Factory.create(:user)
+
+ # user_ability = Ability.new( user )
+ # evil_user_ability = Ability.new( evil_user )
+
+ # [ :show, :index ].each { |action|
+ # assert user_ability.can? action, phone_book_entry
+ # assert evil_user_ability.cannot? action, phone_book_entry
+ # }
+ # end
+
+ def test_that_the_initial_state_should_be_active
+ @phone_book_entry = Factory.create(:phone_book_entry)
+ assert_equal 'active', @phone_book_entry.state
+ assert @phone_book_entry.active?
+ end
+
+ test "a destroyed phone_book will destroy all phone_book_entries" do
+ phone_book = Factory.create(:phone_book)
+ 10.times { Factory.create(:phone_book_entry, :phone_book_id => phone_book.id) }
+
+ phone_book2 = Factory.create(:phone_book)
+ 5.times { Factory.create(:phone_book_entry, :phone_book_id => phone_book2.id) }
+
+ assert_equal 15, PhoneBookEntry.all.count
+
+ phone_book.destroy
+
+ assert_equal 5, PhoneBookEntry.all.count
+ end
+
+ test "that the value_of_to_s field is filled" do
+ phone_book_entry = Factory.create(:phone_book_entry)
+ assert_equal phone_book_entry.value_of_to_s, phone_book_entry.to_s
+ end
+
+end
diff --git a/test/unit/phone_book_test.rb b/test/unit/phone_book_test.rb
new file mode 100644
index 0000000..7db48f8
--- /dev/null
+++ b/test/unit/phone_book_test.rb
@@ -0,0 +1,119 @@
+require 'test_helper'
+
+class PhoneBookTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:phone_book).valid?
+ end
+
+ def test_should_have_unique_name_depending_on_type
+ user1 = Factory.create(:user)
+ user2 = Factory.create(:user)
+ tenant = Factory.create(:tenant)
+
+ phonebook = Factory.create(:phone_book, :phone_bookable => user1)
+ assert !user1.phone_books.build(:name => phonebook.name).valid?
+ assert user2.phone_books.build(:name => phonebook.name).valid?
+ assert tenant.phone_books.build(:name => phonebook.name).valid?
+ end
+
+ # TODO Create a real system for the phone_book tests and than test again.
+
+
+ # test "User gets a private phone book with rw rights" do
+ # user = Factory.create(:user)
+ # assert_equal 1, user.phone_books.count
+
+ # phone_book = user.phone_books.first
+
+ # user_ability = Ability.new( user )
+
+ # [ :show, :destroy, :edit ].each { |action|
+ # assert user_ability.can?( action, phone_book ), "should be able to #{action}"
+ # }
+
+ # # Lets test some stuff about the phone_book_entries
+ # assert_equal 0, phone_book.phone_book_entries.count
+
+ # entry1 = Factory.create(:phone_book_entry, :phone_book_id => phone_book.id)
+ # entry2 = Factory.create(:phone_book_entry, :phone_book_id => phone_book.id)
+ # entry3 = Factory.create(:phone_book_entry, :phone_book_id => phone_book.id)
+ # assert_equal 3, phone_book.phone_book_entries.count
+
+ # assert_equal 1, PhoneBookEntry.where(:id => entry1.id).count
+ # assert_equal 1, PhoneBookEntry.where(:id => entry2.id).count
+ # assert_equal 1, PhoneBookEntry.where(:id => entry3.id).count
+ # user.phone_books.first.destroy
+ # assert_equal 0, user.phone_books.count
+ # assert_equal 0, PhoneBookEntry.where(:id => entry1.id).count
+ # assert_equal 0, PhoneBookEntry.where(:id => entry2.id).count
+ # assert_equal 0, PhoneBookEntry.where(:id => entry3.id).count
+ # end
+
+ test "Tenant gets automatically one phone book and can destroy it" do
+ tenant = Factory.create(:tenant)
+ assert_equal 1, tenant.phone_books.count
+ tenant.phone_books.first.destroy
+ assert_equal 0, tenant.phone_books.count
+ end
+
+ # test "only tenant members can read a tenant phone book" do
+ # tenant = Factory.create(:tenant)
+ # user = Factory.create(:user)
+ # tenant.users << user
+ # tenant.save
+ # user.current_tenant = tenant
+ # user.save
+ # phone_book = Factory.create(:phone_book, :phone_bookable_type => 'Tenant', :phone_bookable_id => tenant.id)
+
+ # evil_user = Factory.create(:user)
+
+ # user_ability = Ability.new( user )
+ # evil_user_ability = Ability.new( evil_user )
+
+ # [ :show ].each { |action|
+ # assert user_ability.can?( action, phone_book ), "should be able to #{action}"
+ # assert evil_user_ability.cannot?( action, phone_book ), "should not be able to #{action}"
+ # }
+ # end
+
+
+
+ # test "tenant's phone book can not be edited by tenant members" do
+ # tenant = Factory.create(:tenant)
+ # user = Factory.create(:user)
+ # tenant.users << user
+ # phone_book = Factory.create(:phone_book, :phone_bookable_type => 'Tenant', :phone_bookable_id => tenant.id)
+
+ # evil_user = Factory.create(:user)
+
+ # user_ability = Ability.new( user )
+ # evil_user_ability = Ability.new( evil_user )
+
+ # [ :edit, :destroy ].each { |action|
+ # assert user_ability.cannot?( action, phone_book ), "should not be able to #{action}"
+ # assert evil_user_ability.cannot?( action, phone_book ), "should not be able to #{action}"
+ # }
+ # end
+
+ # test "only user can manage his private phone book after creating it" do
+ # user = Factory.create(:user)
+ # phone_book = Factory.create(:phone_book, :phone_bookable_type => 'User', :phone_bookable_id => user.id)
+
+ # evil_user = Factory.create(:user)
+
+ # user_ability = Ability.new( user )
+ # evil_user_ability = Ability.new( evil_user )
+
+ # [ :show, :destroy, :edit ].each { |action|
+ # assert user_ability.can?( action, phone_book ), "should be able to #{action}"
+ # assert evil_user_ability.cannot?( action, phone_book ), "should not be able to #{action}"
+ # }
+ # end
+
+ def test_that_the_initial_state_should_be_active
+ @phone_book = Factory.create(:phone_book)
+ assert_equal 'active', @phone_book.state
+ assert @phone_book.active?
+ end
+
+end
diff --git a/test/unit/phone_model_test.rb b/test/unit/phone_model_test.rb
new file mode 100644
index 0000000..e358cf9
--- /dev/null
+++ b/test/unit/phone_model_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class PhoneModelTest < ActiveSupport::TestCase
+
+ def test_should_have_a_valid_factory
+ assert Factory.build(:phone_model).valid?
+ end
+
+end
diff --git a/test/unit/phone_number_range_test.rb b/test/unit/phone_number_range_test.rb
new file mode 100644
index 0000000..1770299
--- /dev/null
+++ b/test/unit/phone_number_range_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class PhoneNumberRangeTest < ActiveSupport::TestCase
+
+ def test_should_have_a_valid_factory
+ assert Factory.build(:phone_number_range).valid?
+ end
+
+end
diff --git a/test/unit/phone_number_test.rb b/test/unit/phone_number_test.rb
new file mode 100644
index 0000000..e10b20c
--- /dev/null
+++ b/test/unit/phone_number_test.rb
@@ -0,0 +1,260 @@
+# ruby coding: utf-8
+
+require 'test_helper'
+
+class PhoneNumberTest < ActiveSupport::TestCase
+
+ test "should have valid factory" do
+ assert Factory.build(:phone_number).valid?
+ end
+
+ def test_that_the_initial_state_should_be_active
+ @phone_number = Factory.create(:phone_number)
+ assert_equal 'active', @phone_number.state
+ assert @phone_number.active?
+ end
+
+ test "that the value_of_to_s field is filled" do
+ phone_number = Factory.create(:phone_number)
+ assert_equal phone_number.value_of_to_s, phone_number.to_s
+ end
+
+ {
+ '+492612000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '+49 261 2000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '+49-261-2000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '492612000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '49888888882000' => nil, # unknown area code
+ '552612000' => nil, # unknown country code
+ '15551234567' => {
+ :country_code => "1",
+ :area_code => "555",
+ :central_office_code => "123",
+ :subscriber_number => "4567",
+ :extension => nil,
+ },
+ '2612000' => nil, # not an international number
+ '02612000' => nil, # not an international number
+ '00492612000' => nil, # invalid format
+ '2000' => nil,
+ '' => nil,
+ nil => nil,
+ '++++' => nil,
+ '###' => nil,
+ 'äöü' => nil,
+ false => nil,
+ true => nil, # true.to_s == "true" # invalid number
+ }.each_pair do |number, expected|
+ test "should parse number #{number.inspect} correctly" do
+ # load some country codes:
+ usa = Country.create(:name => "United States of America", :country_code => "1", :international_call_prefix => "011", :trunk_prefix => "1" )
+ germany = Country.create(:name => "Germany", :country_code => "49", :international_call_prefix => "00", :trunk_prefix => "0" )
+ cuba = Country.create(:name => "Cuba", :country_code => "53", :international_call_prefix => "119", :trunk_prefix => "" )
+ # load some area codes:
+ AreaCode.create(:country => germany, :name => "Koblenz am Rhein", :area_code => "261")
+ AreaCode.create(:country => germany, :name => "Neuwied", :area_code => "2631")
+ AreaCode.create(:country => germany, :name => "Berlin", :area_code => "30")
+ AreaCode.create(:country => germany, :name => "Hamburg", :area_code => "40")
+ AreaCode.create(:country => germany, :name => "Hohenmocker", :area_code => "39993")
+
+ assert_equal expected, PhoneNumber.parse_international_number( number )
+ end
+ end
+
+ {
+ '+492612000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '+49 261 2000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '+49-261-2000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '110' => {
+ :country_code => nil,
+ :area_code => nil,
+ :central_office_code => nil,
+ :subscriber_number => "110",
+ :extension => nil,
+ },
+ '11833' => {
+ :country_code => nil,
+ :area_code => nil,
+ :central_office_code => nil,
+ :subscriber_number => "11833",
+ :extension => nil,
+ },
+ '15551234567' => {
+ :country_code => nil,
+ :area_code => nil,
+ :central_office_code => nil,
+ :subscriber_number => "15551234567",
+ :extension => nil,
+ },
+ '0015551234567' => {
+ :country_code => "1",
+ :area_code => "555",
+ :central_office_code => "123",
+ :subscriber_number => "4567",
+ :extension => nil,
+ },
+ '+15551234567' => {
+ :country_code => "1",
+ :area_code => "555",
+ :central_office_code => "123",
+ :subscriber_number => "4567",
+ :extension => nil,
+ },
+ '02612000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '00492612000' => {
+ :country_code => "49",
+ :area_code => "261",
+ :central_office_code => nil,
+ :subscriber_number => "2000",
+ :extension => nil,
+ },
+ '2000' => {
+ :country_code => nil,
+ :area_code => nil,
+ :central_office_code => nil,
+ :subscriber_number => nil,
+ :extension => "2000",
+ },
+ '99' => {
+ :country_code => nil,
+ :area_code => nil,
+ :central_office_code => nil,
+ :subscriber_number => nil,
+ :extension => "99",
+ },
+ '5' => {
+ :country_code => nil,
+ :area_code => nil,
+ :central_office_code => nil,
+ :subscriber_number => nil,
+ :extension => "5",
+ },
+ '' => nil,
+ nil => nil,
+ '++++' => nil,
+ '###' => nil,
+ 'äöü' => nil,
+ false => nil,
+ true => nil, # true.to_s == "true" # invalid number
+ }.each_pair do |number, expected|
+ test "should parse number #{number.inspect} correctly for a specific tenant" do
+ # load some country codes:
+ usa = Country.create(:name => "United States of America", :country_code => "1", :international_call_prefix => "011", :trunk_prefix => "1" )
+ germany = Country.create(:name => "Germany", :country_code => "49", :international_call_prefix => "00", :trunk_prefix => "0" )
+ cuba = Country.create(:name => "Cuba", :country_code => "53", :international_call_prefix => "119", :trunk_prefix => "" )
+ # load some area codes:
+ AreaCode.create(:country => germany, :name => "Koblenz am Rhein", :area_code => "261")
+ AreaCode.create(:country => germany, :name => "Neuwied", :area_code => "2631")
+ AreaCode.create(:country => germany, :name => "Berlin", :area_code => "30")
+ AreaCode.create(:country => germany, :name => "Hamburg", :area_code => "40")
+ AreaCode.create(:country => germany, :name => "Hohenmocker", :area_code => "39993")
+
+ # create a tenant
+ tenant = Factory.create(:tenant, :country_id => germany.id)
+ # create some extensions
+ internal_extension_range = tenant.phone_number_ranges.create(:name => INTERNAL_EXTENSIONS)
+ ['2000', '2001', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '5', '99'].each do |extension|
+ internal_extension_range.phone_numbers.create(:name => "Extension #{extension}", :number => extension)
+ end
+
+ assert_equal expected, PhoneNumber.parse( number, tenant )
+ end
+ end
+
+ # TODO: Test uniqueness of a phone_number when creating it.
+
+ # test "has to be unique per sip_account" do
+ # germany = Country.create(:name => "Germany", :country_code => "49", :international_call_prefix => "00", :trunk_prefix => "0" )
+ # Language.create(:name => 'Deutsch', :code => 'de')
+ # AreaCode.create(:country => germany, :name => "Bendorf", :area_code => "2622")
+
+ # @sip_domain = Factory.create(:sip_domain)
+
+ # @tenant = @sip_domain.tenants.build(:name => 'AMOOMA GmbH')
+ # @tenant.country = Country.first
+ # @tenant.language = Language.first
+ # @tenant.internal_extension_ranges = '10-20'
+ # @tenant.save
+
+ # @tenant.generate_internal_extensions
+
+ # sip_account = @tenant.sip_accounts.build(Factory.create(:sip_account).attributes)
+ # phone_number = sip_account.phone_numbers.create(Factory.build(:phone_number, :number => '10').attributes)
+ # phone_number_evil = sip_account.phone_numbers.build(phone_number.attributes)
+
+ # assert phone_number.valid?
+ # assert !phone_number_evil.valid?
+ # end
+
+ # test "has to be unique per SIP domain even for different tenants" do
+ # provider_sip_domain = Factory.create(:sip_domain)
+ # tenants = []
+ # sip_accounts = []
+ # 2.times { |i|
+ # tenants[i] = provider_sip_domain.tenants.create(Factory.build(:tenant, :internal_extension_ranges => '10-20').attributes)
+ # tenants[i].generate_internal_extensions
+
+ # sip_accounts[i] = tenants[i].sip_accounts.build(Factory.build(:sip_account, :tenant_id => tenants[i].id).attributes)
+ # sip_accounts[i].phone_numbers.build(:number => '10')
+ # }
+ # sip_accounts[0].save
+
+ # assert sip_accounts[0].valid?, 'Should be valid.'
+ # assert ! sip_accounts[1].valid?,
+ # "Shouldn't be possible to use the same phone number more than once per SIP domain."
+
+ # # Lets change the second phone_number for a positiv test:
+ # #
+ # sip_accounts[1].phone_numbers.first.number = '11'
+ # assert sip_accounts[1].valid?
+ # end
+
+end
diff --git a/test/unit/phone_sip_account_test.rb b/test/unit/phone_sip_account_test.rb
new file mode 100644
index 0000000..735799e
--- /dev/null
+++ b/test/unit/phone_sip_account_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PhoneSipAccountTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert PhoneSipAccount.new.valid?
+ # end
+end
diff --git a/test/unit/phone_test.rb b/test/unit/phone_test.rb
new file mode 100644
index 0000000..4ad21df
--- /dev/null
+++ b/test/unit/phone_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class PhoneTest < ActiveSupport::TestCase
+
+ def test_should_have_a_valid_factory
+ assert Factory.build(:phone).valid?
+ end
+
+ # test "should destroy_all phones_sip_accounts if the phoneable changed" do
+ # sip_domain = Factory.create(:sip_domain)
+ # tenant = sip_domain.tenants.create(Factory.build(:tenant).attributes)
+ #
+ # user1 = Factory.create(:user)
+ # user2 = Factory.create(:user)
+ # tenant.tenant_memberships.create(:user_id => user1.id)
+ # tenant.tenant_memberships.create(:user_id => user2.id)
+ #
+ # phone = Factory.create(:phone, :phoneable => tenant)
+ #
+ # # Nothing there
+ # #
+ # assert_equal 0, phone.sip_accounts.count
+ #
+ # # move the phone to user1
+ # #
+ # phone.phoneable = user1
+ # phone.save
+ #
+ # # create some sip_accounts associated to phone
+ # #
+ # 3.times { Factory.create(:sip_account, :sip_accountable => user1, :tenant_id => tenant.id) }
+ # SipAccount.all.each do |sip_account|
+ # phone.phones_sip_accounts.create(:sip_account_id => sip_account.id)
+ # end
+ #
+ # # Should have 3 sip_accounts
+ # #
+ # assert_equal 3, phone.sip_accounts.count
+ #
+ # # Move to user2
+ # phone.phoneable = user2
+ # phone.save
+ #
+ # # Should have 0 sip_accounts
+ # #
+ # assert_equal 0, phone.sip_accounts.count
+ # end
+
+end
diff --git a/test/unit/ringtone_test.rb b/test/unit/ringtone_test.rb
new file mode 100644
index 0000000..dee6002
--- /dev/null
+++ b/test/unit/ringtone_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class RingtoneTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert Ringtone.new.valid?
+ # end
+end
diff --git a/test/unit/sip_account_test.rb b/test/unit/sip_account_test.rb
new file mode 100644
index 0000000..6595ccc
--- /dev/null
+++ b/test/unit/sip_account_test.rb
@@ -0,0 +1,34 @@
+require 'test_helper'
+
+class SipAccountTest < ActiveSupport::TestCase
+
+ def test_should_have_a_valid_factory
+ assert Factory.build(:sip_account).valid?
+ end
+
+ test "that the value_of_to_s field is filled" do
+ sip_account = Factory.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 = Factory.create(:sip_domain)
+ tenants = []
+ sip_accounts = []
+ 2.times { |i|
+ tenants[i] = provider_sip_domain.tenants.create(Factory.build(:tenant).attributes)
+ sip_accounts[i] = Factory.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
diff --git a/test/unit/sip_domain_test.rb b/test/unit/sip_domain_test.rb
new file mode 100644
index 0000000..5d31f69
--- /dev/null
+++ b/test/unit/sip_domain_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class SipDomainTest < ActiveSupport::TestCase
+
+ def test_should_have_a_valid_factory
+ assert Factory.build(:sip_domain).valid?
+ end
+
+end
diff --git a/test/unit/softkey_function_test.rb b/test/unit/softkey_function_test.rb
new file mode 100644
index 0000000..ed63836
--- /dev/null
+++ b/test/unit/softkey_function_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class SoftkeyFunctionTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
diff --git a/test/unit/softkey_test.rb b/test/unit/softkey_test.rb
new file mode 100644
index 0000000..ca173f9
--- /dev/null
+++ b/test/unit/softkey_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class SoftkeyTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert Softkey.new.valid?
+ # end
+end
diff --git a/test/unit/system_message_test.rb b/test/unit/system_message_test.rb
new file mode 100644
index 0000000..0476ac8
--- /dev/null
+++ b/test/unit/system_message_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class SystemMessageTest < ActiveSupport::TestCase
+ # def test_should_be_valid
+ # assert SystemMessage.new.valid?
+ # end
+end
diff --git a/test/unit/tenant_membership_test.rb b/test/unit/tenant_membership_test.rb
new file mode 100644
index 0000000..8e7a191
--- /dev/null
+++ b/test/unit/tenant_membership_test.rb
@@ -0,0 +1,14 @@
+require 'test_helper'
+
+class TenantMembershipTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:tenant_membership).valid?
+ end
+
+ def test_that_the_initial_state_should_be_active
+ @tenant_membership = Factory.create(:tenant_membership)
+ assert_equal 'active', @tenant_membership.state
+ assert @tenant_membership.active?
+ end
+
+end
diff --git a/test/unit/tenant_test.rb b/test/unit/tenant_test.rb
new file mode 100644
index 0000000..4d4abce
--- /dev/null
+++ b/test/unit/tenant_test.rb
@@ -0,0 +1,33 @@
+require 'test_helper'
+
+class TenantTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:tenant).valid?
+ end
+
+ def test_should_have_unique_name
+ tenant = Factory.create(:tenant)
+ assert !Factory.build(:tenant, :name => tenant.name).valid?
+ assert Factory.build(:tenant, :name => "different_#{tenant.name}").valid?
+ end
+
+ def test_that_the_initial_state_should_be_active
+ @tenant = Factory.create(:tenant)
+ assert_equal 'active', @tenant.state
+ assert @tenant.active?
+ end
+
+ def test_not_active_state_will_not_be_displayed
+ @tenant = Factory.create(:tenant)
+ assert_equal 1, Tenant.count
+
+ @tenant.deactivate!
+ assert_equal 0, Tenant.count
+ assert_equal 1, Tenant.unscoped.count
+
+ @tenant.activate!
+ assert_equal 1, Tenant.count
+ assert_equal Tenant.count, Tenant.unscoped.count
+ end
+
+end
diff --git a/test/unit/user_group_membership_test.rb b/test/unit/user_group_membership_test.rb
new file mode 100644
index 0000000..251229f
--- /dev/null
+++ b/test/unit/user_group_membership_test.rb
@@ -0,0 +1,39 @@
+require 'test_helper'
+
+class UserGroupMembershipTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:user_group_membership).valid?
+ end
+ def test_should_have_unique_members_in_each_group
+ group1 = Factory.create(:user_group)
+ group2 = Factory.create(:user_group)
+ user1 = Factory.create(:user)
+ user2 = Factory.create(:user)
+ member = Factory.create(
+ :user_group_membership,
+ :user_id => user1.id,
+ :user_group_id => group1.id
+ )
+ assert !Factory.build(
+ :user_group_membership,
+ :user_id => user1.id,
+ :user_group_id => group1.id
+ ).valid?
+ assert Factory.build(
+ :user_group_membership,
+ :user_id => user1.id,
+ :user_group_id => group2.id
+ ).valid?
+ assert Factory.build(
+ :user_group_membership,
+ :user_id => user2.id,
+ :user_group_id => group1.id
+ ).valid?
+ end
+
+ def test_that_the_initial_state_should_be_active
+ @user_group_membership = Factory.create(:user_group_membership)
+ assert_equal 'active', @user_group_membership.state
+ assert @user_group_membership.active?
+ end
+end
diff --git a/test/unit/user_group_test.rb b/test/unit/user_group_test.rb
new file mode 100644
index 0000000..5e815a8
--- /dev/null
+++ b/test/unit/user_group_test.rb
@@ -0,0 +1,38 @@
+require 'test_helper'
+
+class UserGroupTest < ActiveSupport::TestCase
+ def test_should_have_a_valid_factory
+ assert Factory.build(:user_group).valid?
+ end
+
+ def test_should_have_unique_name_on_same_tenant
+ tenant1 = Factory.create(:tenant)
+ tenant2 = Factory.create(:tenant)
+ group = Factory.create(:user_group, :tenant_id => tenant1.id)
+ assert !Factory.build(:user_group, :name => group.name, :tenant_id => tenant1.id).valid?
+ assert Factory.build(:user_group, :name => group.name, :tenant_id => tenant2.id).valid?
+ assert Factory.build(:user_group, :name => "different_#{group.name}", :tenant_id => tenant1.id).valid?
+ end
+
+ test "user_group_membership only available for tenant_memberships" do
+ good_tenant = Factory.create(:tenant)
+ evil_tenant = Factory.create(:tenant)
+
+ user = Factory.create(:user)
+ good_tenant.tenant_memberships.create(:user_id => user.id)
+
+ good_user_group = good_tenant.user_groups.create(:name => 'Example')
+ evil_user_group = evil_tenant.user_groups.create(:name => 'Example')
+
+ # Check the basics
+ assert_equal 1, good_tenant.user_groups.count
+ assert_equal 1, evil_tenant.user_groups.count
+ assert_equal 1, good_tenant.users.count
+ assert_equal 0, evil_tenant.users.count
+
+ # Check if the user can become a member
+ assert good_user_group.user_group_memberships.build(:user_id => user.id).valid?
+ assert !evil_user_group.user_group_memberships.build(:user_id => user.id).valid?
+ end
+
+end
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
new file mode 100644
index 0000000..bb89e77
--- /dev/null
+++ b/test/unit/user_test.rb
@@ -0,0 +1,82 @@
+require 'test_helper'
+
+class UserTest < ActiveSupport::TestCase
+
+ def test_should_have_a_valid_factory
+ assert Factory.build(:user).valid?
+ end
+
+ def test_should_have_a_unique_email_address
+ user = Factory.create(:user)
+ assert !Factory.build(:user, :email => user.email).valid?
+ assert Factory.build(:user, :email => "different_#{user.email}").valid?
+ end
+
+ def test_can_not_move_to_a_current_tenant_without_a_membership_relation
+ super_tenant = Factory.create(:tenant)
+ good_tenant = Factory.create(:tenant)
+ evil_tenant = Factory.create(:tenant)
+
+ user = Factory.create(:user)
+ super_tenant.tenant_memberships.create(:user_id => user.id)
+ good_tenant.tenant_memberships.create(:user_id => user.id)
+
+ assert user.update_attributes(:current_tenant_id => super_tenant.id)
+ assert !user.update_attributes(:current_tenant_id => evil_tenant.id)
+ assert user.update_attributes(:current_tenant_id => good_tenant.id)
+ end
+
+ test "should be possible to modify the user without changing the PIN" do
+ user = Factory.create(:user)
+ pin_salt = user.pin_salt
+ pin_hash = user.pin_hash
+ user.middle_name = "#{user.middle_name} Foo"
+ assert user.save, "Should be possible to save the user."
+ user = User.where(:id => user.id).first
+ assert user
+ assert_equal pin_salt, user.pin_salt, "PIN salt should not change."
+ assert_equal pin_hash, user.pin_hash, "PIN hash should not change."
+ end
+
+ test "should be possible to change the PIN" do
+ user = Factory.create(:user)
+ pin_salt = user.pin_salt
+ pin_hash = user.pin_hash
+ new_pin = '453267'
+ user.new_pin = new_pin
+ user.new_pin_confirmation = new_pin
+ assert user.save, "Should be possible to save the user."
+ user = User.where(:id => user.id).first
+ assert_not_equal "#{pin_salt}#{pin_hash}", "#{user.pin_salt}#{user.pin_hash}",
+ "PIN salt/hash should have changed."
+ end
+
+ test "should not be possible to change the PIN if the confirmation does not match" do
+ user = Factory.create(:user)
+ pin_salt = user.pin_salt
+ pin_hash = user.pin_hash
+ user.new_pin = '123001'
+ user.new_pin_confirmation = '123002'
+ assert ! user.save, "Should not be possible to save the user."
+ assert ! user.valid?, "Should not be valid."
+ assert user.errors && user.errors.messages
+ assert (
+ (user.errors.messages[:new_pin] && user.errors.messages[:new_pin].length > 0) ||
+ (user.errors.messages[:new_pin_confirmation] && user.errors.messages[:new_pin_confirmation].length > 0)
+ ), "There should be an error message because new_pin != new_pin_confirmation."
+ end
+
+ test "PIN must be numeric" do
+ user = Factory.create(:user)
+ new_pin = 'xxxx'
+ user.new_pin = new_pin
+ user.new_pin_confirmation = new_pin
+ assert ! user.save, "Should not be possible to save the user."
+ assert ! user.valid?, "Should not be valid."
+ assert (
+ (user.errors.messages[:new_pin] && user.errors.messages[:new_pin].length > 0) ||
+ (user.errors.messages[:new_pin_confirmation] && user.errors.messages[:new_pin_confirmation].length > 0)
+ ), "There should be an error message because PIN isn't numeric."
+ end
+
+end
diff --git a/test/unit/whitelist_test.rb b/test/unit/whitelist_test.rb
new file mode 100644
index 0000000..5678bbb
--- /dev/null
+++ b/test/unit/whitelist_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class WhitelistTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert Whitelist.new.valid?
+ end
+end