seed_dump 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +0,0 @@
1
- FactoryBot.define do
2
- factory :sample do
3
- # Use block syntax for attribute definitions
4
- string { 'string' }
5
- text { 'text' }
6
- integer { 42 }
7
- float { 3.14 }
8
- # BigDecimal needs to be initialized within the block
9
- decimal { BigDecimal('2.72') }
10
- # Use standard Ruby DateTime/Time parse methods directly
11
- datetime { DateTime.parse('July 4, 1776 7:14pm UTC') }
12
- time { Time.parse('3:15am UTC') }
13
- date { Date.parse('November 19, 1863') }
14
- binary { 'binary' }
15
- boolean { false }
16
- # Define created_at and updated_at explicitly as they are used in specs
17
- created_at { DateTime.parse('July 20, 1969 20:18 UTC') }
18
- updated_at { DateTime.parse('November 10, 1989 4:20 UTC') }
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- FactoryBot.define do
2
- factory :yet_another_sample do
3
- # Use block syntax for attribute definitions
4
- string { 'string' }
5
- text { 'text' }
6
- integer { 42 }
7
- float { 3.14 }
8
- # BigDecimal needs to be initialized within the block
9
- decimal { BigDecimal('2.72') }
10
- # Use standard Ruby DateTime/Time parse methods directly
11
- datetime { DateTime.parse('July 4, 1776 7:14pm UTC') }
12
- time { Time.parse('3:15am UTC') }
13
- date { Date.parse('November 19, 1863') }
14
- binary { 'binary' }
15
- boolean { false }
16
- # created_at and updated_at are typically handled by ActiveRecord timestamps
17
- # but can be defined explicitly if needed for specific tests.
18
- # created_at { Time.now }
19
- # updated_at { Time.now }
20
- end
21
- end
data/spec/helpers.rb DELETED
@@ -1,252 +0,0 @@
1
- # Mock Rails.application.eager_load! and define some
2
- # Rails models for use in specs.
3
- class Rails
4
- def self.application
5
- self
6
- end
7
-
8
- def self.eager_load!
9
- @already_called ||= false
10
-
11
- # Define models only if they aren't already defined
12
- # This prevents errors if eager_load! is called multiple times
13
- unless @already_called
14
- Object.const_set('Sample', Class.new(ActiveRecord::Base)) unless defined?(Sample)
15
- Object.const_set('AnotherSample', Class.new(ActiveRecord::Base)) unless defined?(AnotherSample)
16
- Object.const_set('YetAnotherSample', Class.new(ActiveRecord::Base)) unless defined?(YetAnotherSample)
17
- Object.const_set('NoTableModel', Class.new(ActiveRecord::Base)) unless defined?(NoTableModel)
18
- Object.const_set('EmptyModel', Class.new(ActiveRecord::Base)) unless defined?(EmptyModel)
19
- Object.const_set('CampaignsManager', Class.new(ActiveRecord::Base)) unless defined?(CampaignsManager)
20
- Object.const_set('Boss', Class.new(ActiveRecord::Base)) unless defined?(Boss)
21
-
22
- # STI models for testing issue #120
23
- unless defined?(BaseUser)
24
- base_user_class = Class.new(ActiveRecord::Base) do
25
- self.table_name = 'base_users'
26
- end
27
- Object.const_set('BaseUser', base_user_class)
28
- end
29
-
30
- unless defined?(AdminUser)
31
- admin_user_class = Class.new(BaseUser)
32
- Object.const_set('AdminUser', admin_user_class)
33
- end
34
-
35
- unless defined?(GuestUser)
36
- guest_user_class = Class.new(BaseUser)
37
- Object.const_set('GuestUser', guest_user_class)
38
- end
39
-
40
- # Model with serialized Hash field (issue #105) - JSON serialization
41
- unless defined?(SerializedSample)
42
- serialized_class = Class.new(ActiveRecord::Base) do
43
- self.table_name = 'serialized_samples'
44
- serialize :metadata, coder: JSON
45
- end
46
- Object.const_set('SerializedSample', serialized_class)
47
- end
48
-
49
- # Model with default_scope selecting specific columns (issue #165)
50
- unless defined?(ScopedSelectSample)
51
- scoped_class = Class.new(ActiveRecord::Base) do
52
- self.table_name = 'scoped_select_samples'
53
- default_scope { select(:id, :name) }
54
- end
55
- Object.const_set('ScopedSelectSample', scoped_class)
56
- end
57
-
58
- # Model with created_on/updated_on columns (issue #128)
59
- unless defined?(TimestampOnSample)
60
- timestamp_on_class = Class.new(ActiveRecord::Base) do
61
- self.table_name = 'timestamp_on_samples'
62
- end
63
- Object.const_set('TimestampOnSample', timestamp_on_class)
64
- end
65
-
66
- # Models with foreign key relationships for testing dependency ordering (issues #78, #83)
67
- # Author -> Book -> Review (Review depends on Book, Book depends on Author)
68
- unless defined?(Author)
69
- author_class = Class.new(ActiveRecord::Base) do
70
- self.table_name = 'authors'
71
- has_many :books
72
- end
73
- Object.const_set('Author', author_class)
74
- end
75
-
76
- unless defined?(Book)
77
- book_class = Class.new(ActiveRecord::Base) do
78
- self.table_name = 'books'
79
- belongs_to :author
80
- has_many :reviews
81
- end
82
- Object.const_set('Book', book_class)
83
- end
84
-
85
- unless defined?(Review)
86
- review_class = Class.new(ActiveRecord::Base) do
87
- self.table_name = 'reviews'
88
- belongs_to :book
89
- end
90
- Object.const_set('Review', review_class)
91
- end
92
-
93
- @already_called = true
94
- end
95
- end
96
-
97
- def self.env
98
- 'test'
99
- end
100
- end
101
-
102
- module Helpers
103
- # Define create_db as a module method (self.create_db)
104
- def self.create_db
105
- # Ensure ActiveRecord connection is established before migrations
106
- unless ActiveRecord::Base.connected?
107
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
108
- end
109
-
110
- ActiveRecord::Migration.verbose = false
111
-
112
- ActiveRecord::Schema.define(:version => 1) do
113
- # Use drop_table with if_exists for idempotency
114
- drop_table :samples, if_exists: true
115
- create_table 'samples', :force => true do |t|
116
- t.string 'string'
117
- t.text 'text'
118
- t.integer 'integer'
119
- t.float 'float'
120
- t.decimal 'decimal'
121
- t.datetime 'datetime'
122
- t.time 'time'
123
- t.date 'date'
124
- t.binary 'binary'
125
- t.boolean 'boolean'
126
- t.datetime 'created_at', :null => false
127
- t.datetime 'updated_at', :null => false
128
- end
129
-
130
- drop_table :another_samples, if_exists: true
131
- create_table 'another_samples', :force => true do |t|
132
- t.string 'string'
133
- t.text 'text'
134
- t.integer 'integer'
135
- t.float 'float'
136
- t.decimal 'decimal'
137
- t.datetime 'datetime'
138
- t.time 'time'
139
- t.date 'date'
140
- t.binary 'binary'
141
- t.boolean 'boolean'
142
- t.datetime 'created_at', :null => false
143
- t.datetime 'updated_at', :null => false
144
- end
145
-
146
- drop_table :yet_another_samples, if_exists: true
147
- create_table 'yet_another_samples', :force => true do |t|
148
- t.string 'string'
149
- t.text 'text'
150
- t.integer 'integer'
151
- t.float 'float'
152
- t.decimal 'decimal'
153
- t.datetime 'datetime'
154
- t.time 'time'
155
- t.date 'date'
156
- t.binary 'binary'
157
- t.boolean 'boolean'
158
- t.datetime 'created_at', :null => false
159
- t.datetime 'updated_at', :null => false
160
- end
161
-
162
- drop_table :empty_models, if_exists: true
163
- create_table 'empty_models', force: true
164
-
165
- # Join table without primary key (for issue #167 - HABTM tables)
166
- drop_table :campaigns_managers, if_exists: true
167
- create_table 'campaigns_managers', id: false, force: true do |t|
168
- t.integer :campaign_id
169
- t.integer :manager_id
170
- end
171
-
172
- # Table for testing default_scope with select (issue #165)
173
- drop_table :scoped_select_samples, if_exists: true
174
- create_table 'scoped_select_samples', force: true do |t|
175
- t.string :name
176
- t.string :description
177
- t.datetime 'created_at', null: false
178
- t.datetime 'updated_at', null: false
179
- end
180
-
181
- # Table for testing serialized Hash fields (issue #105) - JSON
182
- drop_table :serialized_samples, if_exists: true
183
- create_table 'serialized_samples', force: true do |t|
184
- t.string :name
185
- t.text :metadata
186
- t.datetime 'created_at', null: false
187
- t.datetime 'updated_at', null: false
188
- end
189
-
190
- # Table for testing created_on/updated_on exclusion (issue #128)
191
- drop_table :timestamp_on_samples, if_exists: true
192
- create_table 'timestamp_on_samples', force: true do |t|
193
- t.string :name
194
- t.datetime 'created_on', null: false
195
- t.datetime 'updated_on', null: false
196
- end
197
-
198
- # Table for testing model names ending in 's' (issue #121)
199
- drop_table :bosses, if_exists: true
200
- create_table 'bosses', force: true do |t|
201
- t.string :name
202
- t.datetime 'created_at', null: false
203
- t.datetime 'updated_at', null: false
204
- end
205
-
206
- # Table for testing STI deduplication (issue #120)
207
- drop_table :base_users, if_exists: true
208
- create_table 'base_users', force: true do |t|
209
- t.string :type # STI type column
210
- t.string :name
211
- t.string :email
212
- t.datetime 'created_at', null: false
213
- t.datetime 'updated_at', null: false
214
- end
215
-
216
- # Tables for testing foreign key dependency ordering (issues #78, #83)
217
- # Author -> Book -> Review dependency chain
218
- drop_table :reviews, if_exists: true
219
- drop_table :books, if_exists: true
220
- drop_table :authors, if_exists: true
221
-
222
- create_table 'authors', force: true do |t|
223
- t.string :name
224
- t.datetime 'created_at', null: false
225
- t.datetime 'updated_at', null: false
226
- end
227
-
228
- create_table 'books', force: true do |t|
229
- t.string :title
230
- t.references :author, foreign_key: true
231
- t.datetime 'created_at', null: false
232
- t.datetime 'updated_at', null: false
233
- end
234
-
235
- create_table 'reviews', force: true do |t|
236
- t.text :content
237
- t.integer :rating
238
- t.references :book, foreign_key: true
239
- t.datetime 'created_at', null: false
240
- t.datetime 'updated_at', null: false
241
- end
242
-
243
- end
244
- end
245
-
246
- # Keep load_sample_data as an instance method if needed by examples
247
- def load_sample_data
248
- Rails.application.eager_load!
249
-
250
- Sample.create!
251
- end
252
- end
data/spec/spec_helper.rb DELETED
@@ -1,59 +0,0 @@
1
- # Explicitly require logger before active_support to potentially resolve
2
- # constant lookup issues in newer Ruby versions with older ActiveSupport.
3
- require 'logger'
4
-
5
- require 'active_support'
6
- require 'active_record'
7
-
8
- require 'tempfile'
9
-
10
- require 'byebug'
11
-
12
- require 'database_cleaner/active_record' # Use the specific cleaner
13
- require 'factory_bot'
14
-
15
- # Require the main gem file to define SeedDump constant
16
- require_relative '../lib/seed_dump'
17
-
18
- require_relative './helpers' # Use require_relative for local files
19
-
20
- # Load FactoryBot definitions
21
- FactoryBot.find_definitions
22
-
23
- RSpec.configure do |config|
24
- config.order = 'random'
25
-
26
- # Include helper methods for use within examples (it blocks)
27
- config.include Helpers
28
-
29
- # Configure DatabaseCleaner and Schema Setup
30
- config.before(:suite) do
31
- # Ensure mock Rails models are defined once for the suite
32
- Rails.application.eager_load! if defined?(Rails) && Rails.respond_to?(:application)
33
-
34
- # Create the database schema once before the suite runs
35
- begin
36
- Helpers.create_db
37
- rescue => e
38
- puts "== RSpec: ERROR creating database schema: #{e.message} =="
39
- puts e.backtrace
40
- raise e # Re-raise the error to fail the suite setup
41
- end
42
-
43
-
44
- # Set up DatabaseCleaner strategy and clean once initially
45
- # Use truncation strategy for initial clean
46
- DatabaseCleaner.strategy = :truncation
47
- DatabaseCleaner.clean_with(:truncation)
48
- end
49
-
50
- # Use :truncation strategy before and after each example for thorough cleaning
51
- config.before(:each) do
52
- DatabaseCleaner.strategy = :truncation # Set strategy before starting
53
- DatabaseCleaner.start
54
- end
55
-
56
- config.after(:each) do
57
- DatabaseCleaner.clean
58
- end
59
- end