test/test_associations.rb in sugarcrm-0.9.10 vs test/test_associations.rb in sugarcrm-0.9.11
- old
+ new
@@ -1,14 +1,31 @@
require 'helper'
-class TestAssociations < Test::Unit::TestCase
+class TestAssociations < ActiveSupport::TestCase
context "A SugarCRM::Associations class" do
should "Return an array of Association objects when self#register(SugarCRM::User.new)" do
associations = SugarCRM::Associations.register(SugarCRM::User.new)
assert associations.include? "email_addresses"
assert associations.proxy_methods.include? "email_addresses"
end
end
+
+ context "A SugarCRM::Association class" do
+ should "compute relationship cardinality correctly" do
+ c = SugarCRM::Case.first
+ link_fields_hash = c.associations.classify{|i| i.link_field}
+ # TODO: test one_to_one cardinality by creating custom module with custom relationship
+ # (no "official" one-to-one relationship exists in Sugar out of the box)
+ assert_equal :one_to_many, link_fields_hash['calls'].first.cardinality
+ assert_equal :many_to_one, link_fields_hash['accounts'].first.cardinality
+ assert_equal :many_to_many, link_fields_hash['contacts'].first.cardinality
+ end
+ should "respond to #pretty_print" do
+ a = SugarCRM::Case.first.associations.first
+ assert_respond_to a, :pretty_print
+ end
+ end
+
context "A SugarCRM::Base instance" do
should "return an email address when sent #email_addresses" do
u = SugarCRM::User.find("seed_sarah_id")
assert_instance_of SugarCRM::AssociationCollection, u.email_addresses
assert_instance_of SugarCRM::EmailAddress, u.email_addresses.first
\ No newline at end of file