safer_rails_console 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e22a55eb2977ecd729a7839b196333e48099183b
4
- data.tar.gz: 7521fecaac6acc88c8707325cd65ba441f20b4e7
3
+ metadata.gz: cdf260deb3867b5bed0d92646aa88de6f64afd03
4
+ data.tar.gz: 3cbaac5740f226b7a0364168f4ab137d080fe1ec
5
5
  SHA512:
6
- metadata.gz: ee7b35dda3fa5ca743625ffba0649e99996fef4f1b30d57c81071830799ee1ee3572a387e598b70d3c8cc2c3e908bfdd147ed7d6e4da7b01d170cf9c71cb034c
7
- data.tar.gz: a3e5e78324986964cb026a7b3e25406bad453431befd662692f1f17af923c085c30d07d3039324adfaf79619089b3c65edf4991394aae2549be34ba30714e628
6
+ metadata.gz: 470e4da18f0fe1ad4e10df31ae6189f66c7ee58f66389bc8bc3c6d0224f6f8c816dec8d7b94001b22911778bc595a6da7e0de0e3a360c348e29b56de64f7638f
7
+ data.tar.gz: a3afb5cc08b8a001879271c7f86b4c78dc5b6cb13d97f2a7602f4ab3ebe96437cc9fb0d22c33ef872fbf9d9daa85e5bd7cc44c43b2e679d2baab112be7c8ef5d
@@ -1,10 +1,19 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
 
4
+ services:
5
+ - postgresql
6
+
4
7
  bundler_args: --without test --jobs 3 --retry 3
5
8
  before_install:
6
9
  - gem install bundler
7
10
 
11
+ before_script:
12
+ - cp spec/internal/database.yml.travis spec/internal/rails_4_1/config/database.yml
13
+ - cp spec/internal/database.yml.travis spec/internal/rails_4_2/config/database.yml
14
+ - cp spec/internal/database.yml.travis spec/internal/rails_5_0/config/database.yml
15
+ - cp spec/internal/database.yml.travis spec/internal/rails_5_1/config/database.yml
16
+
8
17
  script:
9
18
  - bundle exec rubocop
10
19
  - bundle exec rspec
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.1.4](https://github.com/salsify/safer_rails_console/tree/v0.1.4) (2017-08-15)
4
+ [Full Changelog](https://github.com/salsify/safer_rails_console/compare/v0.1.3...v0.1.4)
5
+
6
+ **Fixed bugs:**
7
+
8
+ - Invalid cached and prepared statements do not trigger a automatic rollback with PostgreSQL [\#16](https://github.com/salsify/safer_rails_console/issues/16)
9
+ - safer\_rails\_console doesn't work in alerts service rails console mode in sandbox mode [\#13](https://github.com/salsify/safer_rails_console/issues/13)
10
+
11
+ **Merged pull requests:**
12
+
13
+ - Patch PostgreSQLAdapter\#execute\_and\_clear instead of AbstractAdapter\#log for auto-rollback [\#15](https://github.com/salsify/safer_rails_console/pull/15) ([timothysu](https://github.com/timothysu))
14
+
3
15
  ## [v0.1.3](https://github.com/salsify/safer_rails_console/tree/v0.1.3) (2017-08-02)
4
16
  [Full Changelog](https://github.com/salsify/safer_rails_console/compare/v0.1.2...v0.1.3)
5
17
 
@@ -2,15 +2,44 @@ module SaferRailsConsole
2
2
  module Patches
3
3
  module Sandbox
4
4
  module AutoRollback
5
+ def self.rollback_and_begin_new_transaction
6
+ connection = ::ActiveRecord::Base.connection
7
+ connection.rollback_db_transaction
8
+ connection.begin_db_transaction
9
+ end
10
+
5
11
  module ActiveRecord
6
12
  module ConnectionAdapters
7
- module AbstractAdapter
8
- def log(sql, name = 'SQL', binds = [], statement_name = nil)
9
- super(sql, name, binds, statement_name) { yield }
13
+ module PostgreSQLAdapter41
14
+ def exec_no_cache(sql, name, binds)
15
+ super
16
+ rescue => e
17
+ SaferRailsConsole::Patches::Sandbox::AutoRollback.rollback_and_begin_new_transaction
18
+ raise e
19
+ end
20
+
21
+ def exec_cache(sql, name, binds)
22
+ super
23
+ rescue => e
24
+ SaferRailsConsole::Patches::Sandbox::AutoRollback.rollback_and_begin_new_transaction
25
+ raise e
26
+ end
27
+ end
28
+
29
+ module PostgreSQLAdapter42
30
+ def execute_and_clear(sql, name, binds)
31
+ super
10
32
  rescue => e
11
- connection = ::ActiveRecord::Base.connection
12
- connection.rollback_db_transaction
13
- connection.begin_db_transaction
33
+ SaferRailsConsole::Patches::Sandbox::AutoRollback.rollback_and_begin_new_transaction
34
+ raise e
35
+ end
36
+ end
37
+
38
+ module PostgreSQLAdapter5
39
+ def execute_and_clear(sql, name, binds, prepare: false)
40
+ super
41
+ rescue => e
42
+ SaferRailsConsole::Patches::Sandbox::AutoRollback.rollback_and_begin_new_transaction
14
43
  raise e
15
44
  end
16
45
  end
@@ -21,4 +50,12 @@ module SaferRailsConsole
21
50
  end
22
51
  end
23
52
 
24
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(SaferRailsConsole::Patches::Sandbox::AutoRollback::ActiveRecord::ConnectionAdapters::AbstractAdapter)
53
+ if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
54
+ if SaferRailsConsole::RailsVersion.four_one?
55
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SaferRailsConsole::Patches::Sandbox::AutoRollback::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter41)
56
+ elsif SaferRailsConsole::RailsVersion.four_two?
57
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SaferRailsConsole::Patches::Sandbox::AutoRollback::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter42)
58
+ else
59
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(SaferRailsConsole::Patches::Sandbox::AutoRollback::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter5)
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module SaferRailsConsole
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'bundler', '~> 1.15'
35
35
  spec.add_development_dependency 'mixlib-shellout', '~> 2.2'
36
36
  spec.add_development_dependency 'overcommit', '~> 0.39.0'
37
+ spec.add_development_dependency 'pg', '~> 0.21'
37
38
  spec.add_development_dependency 'rake', '~> 12.0'
38
39
  spec.add_development_dependency 'rspec', '~> 3.6'
39
40
  spec.add_development_dependency 'salsify_rubocop', '~> 0.48.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safer_rails_console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify, Inc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-02 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.39.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.21'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.21'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rake
71
85
  requirement: !ruby/object:Gem::Requirement