Skip to content

Commit 3e4bbc8

Browse files
Use sqlite3 for tests
1 parent 1c77aa0 commit 3e4bbc8

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,17 @@ You'll need to have git, Ruby, and MySQL. Then get up and running with a few com
144144
$ git clone ...
145145
$ bundle install
146146
$ vim spec/support/database.yml # Update username and password
147-
$ bin/setup
147+
$ bin/setup # Uses SQLite3 for testing (no additional setup required)
148148
$ bundle exec rspec
149149
```
150150

151+
## Database Compatibility
152+
153+
This gem works with any database supported by ActiveRecord (SQLite3, MySQL, PostgreSQL, etc.).
154+
The gem extends ActiveRecord's polymorphic associations and doesn't use database-specific features.
155+
156+
Development and testing uses SQLite3 for simplicity.
157+
151158
## Contributing
152159

153160
1. Fork it

Rakefile

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bundler/gem_tasks'
24
require 'yaml'
35
require 'active_record'
@@ -20,18 +22,10 @@ namespace :db do
2022

2123
desc 'Create the database'
2224
task :create do
23-
if database_config[:adapter] == 'sqlite3'
24-
# For SQLite3, just ensure the directory exists
25-
db_file = database_config.fetch(:database)
26-
FileUtils.mkdir_p(File.dirname(db_file)) unless File.dirname(db_file) == '.'
27-
puts 'Database created (SQLite3 will create file on first connection).'
28-
else
29-
# For other databases (MySQL, PostgreSQL, etc.)
30-
admin_config = database_config.merge(database: "mysql")
31-
ActiveRecord::Base.establish_connection(admin_config)
32-
ActiveRecord::Base.connection.create_database(database_config.fetch(:database))
33-
puts 'Database created.'
34-
end
25+
# SQLite3 creates the database file automatically, just ensure directory exists
26+
db_file = database_config.fetch(:database)
27+
FileUtils.mkdir_p(File.dirname(db_file)) unless File.dirname(db_file) == '.'
28+
puts 'Database ready (SQLite3).'
3529
end
3630

3731
desc 'Migrate the database'
@@ -53,16 +47,9 @@ namespace :db do
5347

5448
desc 'Drop the database'
5549
task :drop do
56-
if database_config[:adapter] == 'sqlite3'
57-
# For SQLite3, just delete the file
58-
db_file = database_config.fetch(:database)
59-
File.delete(db_file) if File.exist?(db_file)
60-
else
61-
# For other databases (MySQL, PostgreSQL, etc.)
62-
admin_config = database_config.merge(database: "mysql")
63-
ActiveRecord::Base.establish_connection(admin_config)
64-
ActiveRecord::Base.connection.drop_database(database_config.fetch(:database))
65-
end
50+
# For SQLite3, just delete the file
51+
db_file = database_config.fetch(:database)
52+
File.delete(db_file) if File.exist?(db_file)
6653
puts 'Database deleted.'
6754
end
6855

0 commit comments

Comments
 (0)