forked from DatabaseCleaner/database_cleaner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add truncate_tables method to SQLiteAdapter.
Without this, the PostgreSQLAdapter truncate_tables method would be called and go kerblooie cuz t'ain't no PostgreSQL database in play.
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ vendor/ | |
examples/db/*.db | ||
examples/config/database.yml | ||
db/config.yml | ||
db/test.sqlite3 | ||
.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
spec/database_cleaner/active_record/truncation/sqlite3_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
require 'active_record' | ||
require 'support/active_record/sqlite3_setup' | ||
require 'database_cleaner/active_record/truncation' | ||
|
||
module ActiveRecord | ||
module ConnectionAdapters | ||
describe do | ||
before(:all) { active_record_sqlite3_setup } | ||
|
||
let(:adapter) { SQLite3Adapter } | ||
|
||
let(:connection) do | ||
active_record_sqlite3_connection | ||
end | ||
|
||
before(:each) do | ||
connection.truncate_tables connection.tables | ||
end | ||
|
||
describe "#truncate_table" do | ||
it "truncates the table" do | ||
2.times { User.create } | ||
|
||
connection.truncate_table('users') | ||
User.count.should eq 0 | ||
end | ||
|
||
it "resets AUTO_INCREMENT index of table" do | ||
2.times { User.create } | ||
User.delete_all | ||
|
||
connection.truncate_table('users') | ||
|
||
User.create.id.should eq 1 | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'support/active_record/database_setup' | ||
require 'support/active_record/schema_setup' | ||
|
||
module SQLite3Helper | ||
puts "Active Record #{ActiveRecord::VERSION::STRING}, sqlite3" | ||
|
||
# ActiveRecord::Base.logger = Logger.new(STDERR) | ||
|
||
def config | ||
db_config['sqlite3'] | ||
end | ||
|
||
def create_db | ||
@encoding = config['encoding'] || ENV['CHARSET'] || 'utf8' | ||
begin | ||
establish_connection(config.merge('database' => 'sqlite3', 'schema_search_path' => 'public')) | ||
rescue Exception => e | ||
$stderr.puts e, *(e.backtrace) | ||
$stderr.puts "Couldn't create database for #{config.inspect}" | ||
end | ||
end | ||
|
||
def establish_connection config = config | ||
ActiveRecord::Base.establish_connection(config) | ||
end | ||
|
||
def active_record_sqlite3_setup | ||
create_db | ||
establish_connection | ||
load_schema | ||
end | ||
|
||
def active_record_sqlite3_connection | ||
ActiveRecord::Base.connection | ||
end | ||
end | ||
|
||
RSpec.configure do |c| | ||
c.include SQLite3Helper | ||
end |