Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support readonly option in SQLite3Adapter #33242

Merged
merged 1 commit into from Jul 2, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+36 −1
Diff settings

Always

Just for now

@@ -29,9 +29,11 @@ def sqlite3_connection(config)
Dir.mkdir(dirname) unless File.directory?(dirname)
end

db_opts = config.symbolize_keys.merge(results_as_hash: true)

db = SQLite3::Database.new(
config[:database].to_s,
results_as_hash: true
db_opts
)

db.busy_timeout(ConnectionAdapters::SQLite3Adapter.type_cast_config_to_integer(config[:timeout])) if config[:timeout]
@@ -504,6 +504,39 @@ def test_deprecate_valid_alter_table_type
assert_deprecated { @conn.valid_alter_table_type?(:string) }
end

def test_db_is_not_readonly_when_readonly_option_is_false
@conn = Base.sqlite3_connection database: ":memory:",
adapter: "sqlite3",
readonly: false

assert_not_predicate(@conn.raw_connection, :readonly?)
end

def test_db_is_not_readonly_when_readonly_option_is_unspecified
@conn = Base.sqlite3_connection database: ":memory:",
adapter: "sqlite3"

assert_not_predicate(@conn.raw_connection, :readonly?)
end

def test_db_is_readonly_when_readonly_option_is_true
@conn = Base.sqlite3_connection database: ":memory:",
adapter: "sqlite3",
readonly: true

assert_predicate(@conn.raw_connection, :readonly?)
end

def test_writes_are_not_permitted_to_readonly_databases
@conn = Base.sqlite3_connection database: ":memory:",
adapter: "sqlite3",
readonly: true

assert_raises(ActiveRecord::StatementInvalid, /SQLite3::ReadOnlyException/) do
@conn.execute("CREATE TABLE test(id integer)")
end
end

private

def assert_logged(logs)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.