[Nitro] [ANN] Nitro + Og 0.22.0
David Corbin
dcorbin at machturtle.com
Tue Aug 9 05:49:44 EDT 2005
This gets the same exception I had?
David
On Monday 08 August 2005 01:17 am, John Lloyd-Jones wrote:
> See the class Address. Comment out tthe two personal_customer_oid,
> personal_customer_oid= methods and the code fails. This is code was
> updated to use Og 0.22. Tell me if I am using it incorrectly.
>
> On 8/7/05, George Moschovitis <george.moschovitis at gmail.com> wrote:
> > Please. give me some source code that triggers this behaviour.
>
> ===== customer.rb =====
> require 'og'
>
> module Created
> prop_accessor :created, Date
> pre "@created ||= Date.today", :on => :og_insert
> end
>
> module Status
> property :status, String
> pre "@status ||= 'entered'", :on => :og_insert
> end
>
> module Customer
> include Created
> include Status
> property :customer_number, String, :unique => true
> property :creditLimit, String
> end
>
>
> module CRM
>
> # class Party; end
>
> class Phone
> property :type, String
> property :countryCode, String
> property :areaCode, String
> property :number, String
> property :extension, String
> property :comments, String
> end
>
> class ContactInfo
> property :email, String
> property :url, String
> property :phone, Phone
> property :fax, Phone
>
> end
>
> class DateRange
> property :from_dt, Date
> property :to_dt, Date
> end
>
> class ExternalId; end
> class ExtraInfo
> property :name, String
> property :type, String
> property :value, String
> property :externalId, ExternalId
>
> belongs_to :externalId, ExternalId
> end
>
> class ExternalId
> property :type, String
> property :value, String
> property :status, String
> property :validity, DateRange
> property :extraInfo, FixedNum
>
> # belongs_to Party, :field => :extid
> has_many :extraInfos, ExtraInfo
> end
>
> class Party; end
> class Address
> property :street1, String
> property :street2, String
> property :city, String
> property :state, String
> property :postcode, String
> property :name, String
> # property :party, Party
> belongs_to Party, :field => :party
>
> # Need to put this in by hand otherwise I get something like this:
> #(eval):23:in `add_address': undefined method
> `personal_customer_oid=' # for #<Address:0xb7c5c46c> (NoMethodError)
> # from og-test.rb:53:in `addAddress'
> # from og-test.rb:124
>
> def personal_customer_oid
> self.party_oid
> end
> def personal_customer_oid=(oid)
> self.party_oid = oid
> end
> end
>
> class Party
> # property :address, Fixnum
> property :contactInfo, ContactInfo
> property :externalIds, ExternalId
>
> has_many Address, :foreign_field => :party
> # has_many ExternalId, :foreign_field => extid
>
> def initialize
> puts "Party: initialize..."
> end
>
>
> def addAddress( a )
> puts "addAddress: @address = #{@address}"
> add_address( a )
> @address += 1
> end
> end
>
> class Person < Party
> property :firstName, String
> property :middleName, String
> property :lastName, String
> property :knownBy, String
> property :mobile, Phone
> end
>
> class Organization < Party
> property :name, String
> end
>
> class CorporateCustomer < Organization; end
> class Department < Organization
> belongs_to :corporateCustomer, CorporateCustomer
> end
>
> class PersonalCustomer < Person
> include Customer
>
> def initialize (number, first, middle, last)
> super()
> @customer_number = number
> @firstName = first
> @middleName = middle
> @lastName = last
> end
>
> end
>
> class CorporateCustomer < Organization
> include Customer
>
> property :departments, Department
> property :contact, Person
> property :parent, Organization
>
> has_many :departments, Department
> end
>
> class EnterpriseCustomer < Organization
> include Customer
>
> property :companies, CorporateCustomer
>
> has_many :companies, CorporateCustomer
> end
> end
>
> ==== tc_customer.rb =====
> $:.unshift File.join(File.dirname(__FILE__), 'lib')
>
> $DBG = true
>
> require 'test/unit'
> require 'og'
> require 'customer.rb'
>
>
> class TC_Customer < Test::Unit::TestCase # :nodoc: all
> include Og
>
> puts "Og Version #{Og::Version}"
>
> @og = Og.setup(
>
> :destroy => true,
> :store => :sqlite,
> :name => 'tc_customer'
>
> )
>
> def setup
>
> puts "create a (fictious) primary address"
> @a_primary = CRM::Address.new
> @a_primary.street1 = '1370 Dunlap Ave'
> @a_primary.street2 = 'Apt # 786'
> @a_primary.city = 'Phoenix'
> @a_primary.state = 'AZ'
> @a_primary.name = 'primary'
>
> puts "create a (fictious) mailing address"
> @a_mailing = CRM::Address.new
> @a_mailing.street1 = '1290 Ray Ave'
> @a_mailing.street2 = 'P.O Box 15'
> @a_mailing.city = 'Chandler'
> @a_mailing.state = 'AZ'
> @a_mailing.name = 'mailing'
>
> end
>
> def teardown
> end
>
> def test_store_and_retrieve
> puts "create personal customer"
> p1 = CRM::PersonalCustomer.new('1001', 'John', '', 'Lloyd-Jones')
> puts "save the personal customer"
> p1.save
>
> p2 = CRM::PersonalCustomer.one :condition => 'customer_number=1001'
> assert_equal p1.firstName, p2.firstName, "Expect first name to be same"
> assert_equal p1.lastName, p2.lastName, "Expect last name to be same"
> end
>
> def test_address
> puts "create personal customer"
> p1 = CRM::PersonalCustomer.new('1002', 'Kalpana', '', 'Lloyd-Jones')
> puts "save the personal customer"
> p1.save
>
> p2 = CRM::PersonalCustomer.one :condition => 'customer_number=1002'
> p2.addresses << @a_primary
> p2.save
>
> p3 = CRM::PersonalCustomer.one :condition => 'customer_number=1002'
> p3.addresses.each { |a|
> puts "#{a.street1} #{a.city}, #{a.state}"
> }
> # assert_equal( p2.address, 1, "p2.address should be 1 (first address)"
> ) assert_equal( @a_primary.party_oid, p1.oid, "@a_primary should belong to
> p1")
> end
>
> def test_multiple_addresses
> p2 = CRM::PersonalCustomer.one :condition => 'customer_number=1002'
>
> puts "add mailing address"
> p2.addresses << @a_mailing
> p2.save
>
> p3 = CRM::PersonalCustomer.one :condition => 'customer_number=1002'
> puts "p3 party id is #{p3.oid}"
> p3.addresses.each do |a|
> puts "id #{a.oid}: #{a.street1} #{a.city}, #{a.state}"
> a1 = case a.name
> when 'primary' then @a_primary
> when 'mailing' then @a_mailing
> end
> assert_equal(a1.street1, a.street1, "street1 should match")
> assert_equal(a1.city, a.city, "city should match")
> assert_equal(a1.state, a.state, "state should match")
> end
> end
>
> end
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
More information about the Nitro-general
mailing list