Skip to content

Commit

Permalink
Do not validate if table doesnt exist yet
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-isler committed Nov 14, 2024
1 parent ae819b8 commit 670f80c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/hotsheet/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -50,6 +51,10 @@ def validate_attribute_existence
end
end
end

def model_class
model_name.to_s.constantize
end
end
end
end
4 changes: 4 additions & 0 deletions spec/lib/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 670f80c

Please sign in to comment.