Skip to content

Commit

Permalink
create test tables outside of models
Browse files Browse the repository at this point in the history
  • Loading branch information
bdurand committed Oct 28, 2022
1 parent 9c10a01 commit dee20e0
Showing 1 changed file with 28 additions and 36 deletions.
64 changes: 28 additions & 36 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit dee20e0

Please sign in to comment.