Skip to content
This repository has been archived by the owner on Aug 3, 2020. It is now read-only.

Remove namespace when inferring default SObject.table_name #24

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/active_force/sobject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/active_force/sobject/table_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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