From dee20e002ba2d16201fb69940e851583ecb7cd8c Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Thu, 27 Oct 2022 18:51:17 -0700 Subject: [PATCH] create test tables outside of models --- spec/spec_helper.rb | 64 ++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5882ef5..0fad077 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,17 +8,36 @@ SupportTableData.data_directory = File.join(__dir__, "data") -class Color < ActiveRecord::Base - unless table_exists? - connection.create_table(table_name) do |t| - t.string :name, index: {unique: true} - t.integer :value - t.string :comment - t.integer :group_id - t.integer :hue_id - end +ActiveRecord::Base.connection.tap do |connection| + connection.create_table(:colors) do |t| + t.string :name, index: {unique: true} + t.integer :value + t.string :comment + t.integer :group_id + t.integer :hue_id + end + + connection.create_table(:groups, primary_key: :group_id) do |t| + t.string :name, index: {unique: true} + t.timestamps + end + + connection.create_table(:hues) do |t| + t.string :name, index: {unique: true} + t.integer :parent_id end + connection.create_table(:things) do |t| + t.string :name + t.integer :color_id + end + + connection.create_table(:invalids) do |t| + t.string :name + end +end + +class Color < ActiveRecord::Base include SupportTableData self.support_table_data_directory = File.join(__dir__, "data", "colors") @@ -49,13 +68,6 @@ def hex=(value) end class Group < ActiveRecord::Base - unless table_exists? - connection.create_table(table_name, primary_key: :group_id) do |t| - t.string :name, index: {unique: true} - t.timestamps - end - end - include SupportTableData self.primary_key = :group_id @@ -66,13 +78,6 @@ class Group < ActiveRecord::Base end class Hue < ActiveRecord::Base - unless table_exists? - connection.create_table(table_name) do |t| - t.string :name, index: {unique: true} - t.integer :parent_id - end - end - include SupportTableData self.support_table_key_attribute = :name @@ -89,23 +94,10 @@ def parent_name=(value) end class Thing < ActiveRecord::Base - unless table_exists? - connection.create_table(table_name) do |t| - t.string :name - t.integer :color_id - end - end - belongs_to :color end class Invalid < ActiveRecord::Base - unless table_exists? - connection.create_table(table_name) do |t| - t.string :name - end - end - include SupportTableData self.support_table_key_attribute = :name