From b733c10babfc656a7d6e5a1680152f7c62e6d904 Mon Sep 17 00:00:00 2001 From: Dan Olson Date: Mon, 25 Aug 2014 13:42:57 -0500 Subject: [PATCH] Remove namespace when inferring default SObject.table_name --- lib/active_force/sobject.rb | 11 +++++------ spec/active_force/sobject/table_name_spec.rb | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/active_force/sobject.rb b/lib/active_force/sobject.rb index 821133e..18e0031 100644 --- a/lib/active_force/sobject.rb +++ b/lib/active_force/sobject.rb @@ -33,13 +33,16 @@ class << self def default_api_name(attribute) String(attribute).split('_').map(&:capitalize).join('_') << '__c' end + + def custom_table_name + self.name if STANDARD_TYPES.include? self.name + end end # The table name to used to make queries. # It is derived from the class name adding the "__c" when needed. - def self.table_name - @table_name ||= custom_table_name || "#{ self.name }__c" + @table_name ||= custom_table_name || "#{ self.name.split('::').last }__c" end def self.fields @@ -161,10 +164,6 @@ def changed_mappings mappings.select { |attr, sf_field| changed.include? attr.to_s} end - def self.custom_table_name - self.name if STANDARD_TYPES.include? self.name - end - def read_value field case sf_field_type field when :multi_picklist diff --git a/spec/active_force/sobject/table_name_spec.rb b/spec/active_force/sobject/table_name_spec.rb index ceab4ea..9a7c01d 100644 --- a/spec/active_force/sobject/table_name_spec.rb +++ b/spec/active_force/sobject/table_name_spec.rb @@ -25,5 +25,13 @@ class EnforcedTableName < ActiveForce::SObject expect(EnforcedTableName.table_name).to eq('Forced__c') end + it "doesn't include a namespace" do + module Foo + class Bar < ActiveForce::SObject + end + end + + expect(Foo::Bar.table_name).to eq('Bar__c') + end end end