-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MysqlAdapter transactions support (#58)
- Loading branch information
1 parent
f68a534
commit 364d42f
Showing
20 changed files
with
159 additions
and
33 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
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 |
---|---|---|
|
@@ -15,3 +15,5 @@ | |
/gemfiles/*.gemfile.lock | ||
out | ||
*.sqlite3 | ||
|
||
.idea |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Changelog | ||
|
||
## v0.9.0 | ||
- Add MySql support | ||
|
||
## v0.8.0 | ||
- Drop support for Ruby 2.7. | ||
- Drop support for Rails 6.0. | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module SaferRailsConsole | ||
VERSION = '0.8.0' | ||
VERSION = '0.9.0' | ||
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
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,37 @@ | ||
# frozen_string_literal: true | ||
|
||
shared_context "db sandbox context" do | ||
let(:adapter) {} | ||
|
||
shared_examples_for "auto_rollback" do | ||
it "automatically executes rollback and begins a new transaction after executing a invalid SQL statement" do | ||
run_console_commands('Model.create!', 'Model.where(invalid: :statement)', 'Model.create!') | ||
|
||
# Run a new console session to ensure the database changes were not saved | ||
result = run_console_commands("puts \"Model Count = \#{Model.count}\"") | ||
expect(result.stdout).to include('Model Count = 0') | ||
end | ||
end | ||
|
||
shared_examples_for "read_only" do | ||
it "enforces a read_only transaction" do | ||
# Run a console session that makes some database changes | ||
run_console_commands('Model.create!', 'Model.create!') | ||
|
||
# Run a new console session to ensure the database changes were not saved | ||
result = run_console_commands("puts \"Model Count = \#{Model.count}\"") | ||
expect(result.stdout).to include('Model Count = 0') | ||
end | ||
|
||
it "lets the user know that an operation could not be completed" do | ||
result = run_console_commands('Model.create!') | ||
expect(result.stdout).to include('An operation could not be completed due to read-only mode.') | ||
end | ||
end | ||
|
||
def run_console_commands(*commands) | ||
commands += ['exit'] | ||
environment = "development#{adapter.nil? ? '' : "-#{adapter}"}" | ||
run_console('--sandbox', input: commands.join("\n"), rails_env: environment) | ||
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 |
---|---|---|
@@ -1,34 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../../contexts/db_sandbox' | ||
|
||
describe "Integration: patches/sandbox" do | ||
context "auto_rollback" do | ||
it "automatically executes rollback and begins a new transaction after executing a invalid SQL statement" do | ||
run_console_commands('Model.create!', 'Model.where(invalid: :statement)', 'Model.create!') | ||
include_context "db sandbox context" | ||
|
||
# Run a new console session to ensure the database changes were not saved | ||
result = run_console_commands('puts "Model Count = #{Model.count}"') # rubocop:disable Lint/InterpolationCheck | ||
expect(result.stdout).to include('Model Count = 0') | ||
end | ||
context "for PostgreSQL" do | ||
it_behaves_like "auto_rollback" | ||
it_behaves_like "read_only" | ||
end | ||
|
||
context "read_only" do | ||
it "enforces a read_only transaction" do | ||
# Run a console session that makes some database changes | ||
run_console_commands('Model.create!', 'Model.create!') | ||
|
||
# Run a new console session to ensure the database changes were not saved | ||
result = run_console_commands('puts "Model Count = #{Model.count}"') # rubocop:disable Lint/InterpolationCheck | ||
expect(result.stdout).to include('Model Count = 0') | ||
end | ||
|
||
it "lets the user know that an operation could not be completed" do | ||
result = run_console_commands('Model.create!') | ||
expect(result.stdout).to include('An operation could not be completed due to read-only mode.') | ||
end | ||
end | ||
context "for Mysql" do | ||
let(:adapter) { :mysql2 } | ||
|
||
def run_console_commands(*commands) | ||
commands += ['exit'] | ||
run_console('--sandbox', input: commands.join("\n")) | ||
it_behaves_like "auto_rollback" | ||
it_behaves_like "read_only" | ||
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
source 'https://rubygems.org' | ||
|
||
gem 'mysql2' | ||
gem 'pg' | ||
gem 'rails', '~> 6.1.7' | ||
|
||
|
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
source 'https://rubygems.org' | ||
|
||
gem 'mysql2' | ||
gem 'pg' | ||
gem 'rails', '~> 7.0.8' | ||
|
||
|
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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
source 'https://rubygems.org' | ||
|
||
gem 'mysql2' | ||
gem 'pg' | ||
gem 'rails', '~> 7.1.2' | ||
|
||
|
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
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