diff --git a/lib/hotsheet/configuration.rb b/lib/hotsheet/configuration.rb index b8f7fcd..6c8c9fa 100644 --- a/lib/hotsheet/configuration.rb +++ b/lib/hotsheet/configuration.rb @@ -28,6 +28,8 @@ def initialize(model_name) end def validate! + return unless ActiveRecord::Base.connection.table_exists?(model_class.table_name) + ensure_only_one_attribute_set validate_attribute_existence end @@ -41,7 +43,6 @@ def ensure_only_one_attribute_set end def validate_attribute_existence - model_class = model_name.to_s.constantize all_attributes = model_class.column_names (included_attributes + excluded_attributes).each do |attr| @@ -50,6 +51,10 @@ def validate_attribute_existence end end end + + def model_class + model_name.to_s.constantize + end end end end diff --git a/spec/lib/configuration_spec.rb b/spec/lib/configuration_spec.rb index ee65579..3ed250b 100644 --- a/spec/lib/configuration_spec.rb +++ b/spec/lib/configuration_spec.rb @@ -44,6 +44,10 @@ def self.name "Author" end + def self.table_name + "authors" + end + def self.column_names %w[id name birthdate created_at updated_at] end