diff --git a/lib/netsuite/records/customer.rb b/lib/netsuite/records/customer.rb index 1b6ab4f7a..5acadb1fc 100644 --- a/lib/netsuite/records/customer.rb +++ b/lib/netsuite/records/customer.rb @@ -23,7 +23,7 @@ class Customer :password, :password2, :phone, :phonetic_name, :pref_cc_processor, :print_on_check_as, :print_transactions, :referrer, :reminder_days, :representing_subsidiary, :require_pwd_change, :resale_number, :sales_group, :sales_readiness, :sales_team_list, :salutation, :send_email, :ship_complete, :shipping_item, - :stage, :start_date, :subscriptions_list, :sync_partner_teams, :tax_exempt, :tax_item, :taxable, + :stage, :start_date, :subscriptions_list, :sync_partner_teams, :tax_exempt, :tax_item, :taxable, :territory, :third_party_acct, :third_party_country, :third_party_zipcode, :title, :url, :vat_reg_number, :visits, :web_lead diff --git a/lib/netsuite/records/record_ref.rb b/lib/netsuite/records/record_ref.rb index f83bac8cd..beeae1d3c 100644 --- a/lib/netsuite/records/record_ref.rb +++ b/lib/netsuite/records/record_ref.rb @@ -18,13 +18,25 @@ def initialize(attributes_or_record = {}) @type = attributes.delete(:type) || attributes.delete(:@type) || attributes.delete(:"@xsi:type") @attributes = attributes else - record = attributes_or_record + record = attributes_or_record @internal_id = record.internal_id if record.respond_to?(:internal_id) @external_id = record.external_id if record.respond_to?(:external_id) @type = record.class.to_s.split('::').last.lower_camelcase end end + def ==(other) + other.class == self.class && + other.internal_id != nil && self.internal_id != nil && + other.internal_id.to_s == self.internal_id.to_s + end + + alias_method :eql?, :== + + def hash + internal_id.to_s.hash + end + def method_missing(m, *args, &block) if attributes.keys.map(&:to_sym).include?(m.to_sym) attributes[m.to_sym] @@ -33,6 +45,9 @@ def method_missing(m, *args, &block) end end + def respond_to_missing?(m, include_all=false) + attributes.keys.map(&:to_sym).include?(m.to_sym) || super + end end end end diff --git a/spec/netsuite/records/customer_spec.rb b/spec/netsuite/records/customer_spec.rb index bb0491e77..5cbdef92e 100644 --- a/spec/netsuite/records/customer_spec.rb +++ b/spec/netsuite/records/customer_spec.rb @@ -18,7 +18,7 @@ :password, :password2, :phone, :phonetic_name, :pref_cc_processor,:print_on_check_as, :print_transactions, :referrer, :reminder_days, :representing_subsidiary, :require_pwd_change, :resale_number, :sales_group, :sales_readiness, :sales_team_list, :salutation, :send_email, :ship_complete, :shipping_item, - :stage, :start_date, :subscriptions_list, :sync_partner_teams, :tax_exempt, :tax_item, :taxable, + :stage, :start_date, :subscriptions_list, :sync_partner_teams, :tax_exempt, :tax_item, :taxable, :territory, :third_party_acct, :third_party_country, :third_party_zipcode, :title, :unbilled_orders, :url, :vat_reg_number, :visits, :web_lead ].each do |field| diff --git a/spec/netsuite/records/record_ref_spec.rb b/spec/netsuite/records/record_ref_spec.rb index 162f33ee9..148793626 100644 --- a/spec/netsuite/records/record_ref_spec.rb +++ b/spec/netsuite/records/record_ref_spec.rb @@ -44,6 +44,51 @@ expect(record_ref.banana).to eql('for monkeys') end end + + context 'responding to' do + it 'responds to the arbitrary attributes' do + expect(record_ref).to respond_to(:name) + expect(record_ref).to respond_to(:banana) + end + it 'continues to respond to other methods' do + expect(record_ref).to respond_to(:internal_id) + expect(record_ref).to respond_to(:to_s) + end + end + end + + describe 'equality' do + context 'when internal id is nil' do + subject { NetSuite::Records::RecordRef.new(:name => 'name!') } + it { should_not eq(record_ref) } + it { should_not eq(NetSuite::Records::RecordRef.new(:name => 'name!')) } + it { should_not eq(NetSuite::Records::RecordRef.new(:name => 'other!')) } + end + context 'when internal id is not nil' do + subject { NetSuite::Records::RecordRef.new(:internal_id => '5', :name => 'name!') } + it { should_not eq(NetSuite::Records::RecordRef.new(:internal_id => '9', :name => 'name!')) } + it { should eq(NetSuite::Records::RecordRef.new(:internal_id => '5')) } + it { should eq(NetSuite::Records::RecordRef.new(:internal_id => 5)) } + it { should_not eq(NetSuite::Records::RecordRef.new(:name => 'name!')) } + it { should eq(NetSuite::Records::RecordRef.new(:internal_id => '5', :name => 'name!')) } + it { should eq(NetSuite::Records::RecordRef.new(:internal_id => '5', :name => 'other')) } + it { should_not eq(Struct.new(:internal_id).new('5')) } + end + end + + describe '#hash' do + context 'when the internal id is a string' do + subject { NetSuite::Records::RecordRef.new(:internal_id => '5') } + it 'hashes the internal id' do + expect(subject.hash).to eq('5'.hash) + end + end + context 'when the internal id is an integer' do + subject { NetSuite::Records::RecordRef.new(:internal_id => 5) } + it 'hashes the internal id as a string' do + expect(subject.hash).to eq('5'.hash) + end + end end describe 'untouchables' do @@ -60,7 +105,7 @@ describe 'initialize from record' do it 'initializes a new ref with the proper attributes from the record' do - record = NetSuite::Records::Classification.new(:is_inactive => false, :name => 'Retail', :internal_id => '9') + record = NetSuite::Records::Classification.new(:is_inactive => false, :name => 'Retail', :internal_id => '9') record_ref = NetSuite::Records::RecordRef.new(record) expect(record_ref).to be_kind_of(NetSuite::Records::RecordRef) expect(record_ref.internal_id).to eql('9') @@ -71,7 +116,7 @@ describe '#to_record' do it 'can represent itself as a SOAP record' do record_ref = NetSuite::Records::RecordRef.new(:something => 'blah') - record = { + record = { 'platformCore:something' => 'blah' } expect(record_ref.to_record).to eql(record) @@ -83,5 +128,4 @@ expect(record_ref.record_type).to eql('platformCore:RecordRef') end end - end