cypress-rails 0.8.0.rc1 → 0.8.0

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
  SHA256:
3
- metadata.gz: 340bff5215842cc3afb419ff29bef8b977e573fdf5311711b4d0badaa05104d1
4
- data.tar.gz: c720c43244302da09c9f63f416cba150926c0a6ef4cbf53bc2c418727dd3b87a
3
+ metadata.gz: b714799f9b2c7cb3d97c1ae15730844d98d530eaaf2ae127aeff8604b4a1e53d
4
+ data.tar.gz: '094933f5801cc70665318327dfc1b91a4982d4372aee7920a8ad4ab6af9c1b38'
5
5
  SHA512:
6
- metadata.gz: bfb0b42e92ad4e5b576264b18ba035964823cc32b3717979edd127ca14b17f14639cf14083390c27daa1740b0302c0ba9c8b1ba53bb531ca72a03bdd9e9e0798
7
- data.tar.gz: 78f57627a4eec8c0ccde58b24b1e6104fe8164e11375a46561a5cf8fbcce12a9536041e60c7be431a7c389a00b3132db679a13b93f49810069e8a6271f255864
6
+ metadata.gz: 3b92614020eb57eba1968e60f1aa6f938d9c3fffd7c19eb254dfaa9e4f1bc352535362e54a4823820376ff22d3a59eb204ca399729275aeb5ad2138d7a745d8c
7
+ data.tar.gz: a0efc7383d3f055d07717ff2dabc46c212abdee68e7f38890fb3a1968c1277bbc5c0c0387a6353d20f99b8a4a2721f56a39226feb10a02d0e1703e75c889cc11
@@ -3,17 +3,43 @@ name: CI
3
3
  on: [push, pull_request, workflow_dispatch]
4
4
 
5
5
  jobs:
6
- build:
6
+ unit-tests:
7
7
  runs-on: ubuntu-latest
8
8
 
9
9
  strategy:
10
10
  matrix:
11
- ruby-version: ['3.0', '3.3']
12
- gemfile: ['Gemfile', 'Gemfile_rails71']
11
+ ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4']
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby-version }}
18
+ bundler-cache: true
19
+
20
+ - name: Run root unit tests and lint
21
+ run: |
22
+ bundle
23
+ bundle exec rake
24
+
25
+ example-app-tests:
26
+ runs-on: ubuntu-latest
27
+
28
+ strategy:
29
+ fail-fast: false
30
+ matrix:
31
+ ruby-version: ['3.0', '3.1', '3.2', '3.3', '3.4']
32
+ rails-version: ['7.1', '7.2', '8.0']
13
33
  exclude:
14
- # Rails 7.2 requires Ruby 3.1+
15
34
  - ruby-version: '3.0'
16
- gemfile: 'Gemfile'
35
+ rails-version: '7.2'
36
+ - ruby-version: '3.0'
37
+ rails-version: '8.0'
38
+ - ruby-version: '3.1'
39
+ rails-version: '8.0'
40
+
41
+ env:
42
+ BUNDLE_GEMFILE: ${{ github.workspace }}/example/gemfiles/rails_${{ matrix.rails-version }}.gemfile
17
43
 
18
44
  steps:
19
45
  - uses: actions/checkout@v4
@@ -21,6 +47,7 @@ jobs:
21
47
  with:
22
48
  ruby-version: ${{ matrix.ruby-version }}
23
49
  bundler-cache: true
50
+ cache-version: rails-${{ matrix.rails-version }}
24
51
 
25
- - name: Run tests
26
- run: ./script/test ${{matrix.gemfile}}
52
+ - name: Run example app Cypress tests
53
+ run: ./script/test_example_app
data/.gitignore CHANGED
@@ -6,3 +6,9 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+
10
+ # Gemfile.lock files are Ruby-version-sensitive (transitive deps can pin
11
+ # versions requiring a newer Ruby than some cells of the CI matrix), so each
12
+ # job resolves and caches its own instead of sharing a committed lock.
13
+ /Gemfile.lock
14
+ /example/gemfiles/*.gemfile.lock
data/CHANGELOG.md CHANGED
@@ -1,13 +1,27 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.8.0.rc1
4
- * Add compatibility with Rails 7.2
3
+ ## 0.8.0
4
+
5
+ * **[Breaking]** Remove `CYPRESS_RAILS_TRANSACTIONAL_SERVER`. cypress-rails no
6
+ longer wraps the server in a transaction or resets it between tests -
7
+ automatic Rails-version-specific transaction management proved unsustainable
8
+ to maintain (see [#164](https://github.com/testdouble/cypress-rails/issues/164),
9
+ [#161](https://github.com/testdouble/cypress-rails/issues/161)). Apps must
10
+ now reset their own state (e.g. with `database_cleaner`) using the
11
+ `after_reset_requested` hook; see the example app for a working setup
12
+ * **[Breaking]** Remove the `after_transaction_start` hook, since cypress-rails
13
+ no longer manages transactions
14
+ * **[Breaking]** Rename the `after_state_reset` hook to `after_reset_requested`.
15
+ It now fires whenever a reset was requested (via hitting
16
+ `/cypress_rails_reset_state`), rather than after cypress-rails had already
17
+ performed one - the app is expected to perform the reset itself in this hook
18
+ * **[Breaking]** Remove `CypressRails::Config#transactional_server`
19
+ * Add Rails 7.2 / 8.0 support
5
20
 
6
21
  ## 0.7.1
7
22
  * Add Rack 3.1 support [#163](https://github.com/testdouble/cypress-rails/pull/163)
8
23
 
9
24
  ## 0.7.0
10
- git
11
25
  * Add a `CYPRESS_RAILS_CYPRESS_DIR` option for cases where
12
26
  the cypress tests live outside the CYPRESS_RAILS_DIR [#159](https://github.com/testdouble/cypress-rails/pull/159)
13
27
 
data/README.md CHANGED
@@ -93,26 +93,39 @@ is a JavaScript-based tool and can't easily manipulate your Rails app directly,
93
93
  cypress-rails provides a number of hooks that you can use to manage your test
94
94
  data.
95
95
 
96
+ cypress-rails itself has no opinion on *how* you reset your database between
97
+ tests. Instead, cypress-rails gives you a hook (`after_reset_requested`) to run
98
+ whatever database-cleaning approach fits your app, such as the
99
+ [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner) gem.
100
+
96
101
  Here's what a `config/initializers/cypress_rails.rb` initializer might look
97
- like:
102
+ like, using `database_cleaner-active_record`'s transaction strategy:
98
103
 
99
104
  ```ruby
100
105
  return unless Rails.env.test?
101
106
 
107
+ require "database_cleaner/active_record"
108
+ DatabaseCleaner.strategy = :transaction
109
+
102
110
  CypressRails.hooks.before_server_start do
103
- # Called once, before either the transaction or the server is started
111
+ # Called once, before the server is started
112
+ DatabaseCleaner.start
104
113
  end
105
114
 
106
- CypressRails.hooks.after_transaction_start do
107
- # Called after the transaction is started (at launch and after each reset)
115
+ CypressRails.hooks.after_server_start do
116
+ # Called once, after the server has booted
108
117
  end
109
118
 
110
- CypressRails.hooks.after_state_reset do
111
- # Triggered after `/cypress_rails_reset_state` is called
119
+ CypressRails.hooks.after_reset_requested do
120
+ # Triggered after `/cypress_rails_reset_state` is called - this is your
121
+ # chance to actually reset the database
122
+ DatabaseCleaner.clean
123
+ DatabaseCleaner.start
112
124
  end
113
125
 
114
126
  CypressRails.hooks.before_server_stop do
115
127
  # Called once, at_exit
128
+ DatabaseCleaner.clean
116
129
  end
117
130
  ```
118
131
 
@@ -122,15 +135,9 @@ initializer](/example/config/initializers/cypress_rails_initializer.rb)
122
135
  in this repo.)
123
136
 
124
137
  The gem also provides a special route on the test server:
125
- `/cypress_rails_reset_state`. Each time it's called, cypress-rails will do
126
- two things at the beginning of the next request received by the Rails app:
127
-
128
- * If `CYPRESS_RAILS_TRANSACTIONAL_SERVER` is enabled, roll back the transaction,
129
- effectively resetting the application state to whatever it was at the start of
130
- the test run
131
-
132
- * Trigger any `after_state_reset` hooks you've configured (regardless of the
133
- transactional server setting)
138
+ `/cypress_rails_reset_state`. Each time it's called, cypress-rails will
139
+ trigger any `after_reset_requested` hooks you've configured at the beginning
140
+ of the next request received by the Rails app.
134
141
 
135
142
  This way, you can easily instruct the server to reset its test state from your
136
143
  Cypress tests like so:
@@ -164,10 +171,6 @@ preferred environment variables project-wide using a tool like
164
171
  requests to the app (e.g. via `cy.visit()`). If you've customized your
165
172
  `baseUrl` setting (e.g. in `cypress.config.js`), you'll need to duplicate it with
166
173
  this environment variable
167
- * **CYPRESS_RAILS_TRANSACTIONAL_SERVER** (default: `true`) when true, will start
168
- a transaction on all database connections before launching the server. In
169
- general this means anything done during `cypress open` or `cypress run` will
170
- be rolled back on exit (similar to running a Rails System test)
171
174
  * **CYPRESS_RAILS_CYPRESS_OPTS** (default: _none_) any options you want to
172
175
  forward to the Cypress CLI when running its `open` or `run` commands.
173
176
 
@@ -193,28 +196,24 @@ $ CYPRESS_RAILS_CYPRESS_OPTS="--browser chromium" bin/rake cypress:run
193
196
  ### before_server_start
194
197
 
195
198
  Pass a block to `CypressRails.hooks.before_server_start` to register a hook that
196
- will execute before the server or any transaction has been started. If you use
197
- Rails fixtures, it may make sense to load them here, so they don't need to be
198
- re-inserted for each request
199
+ will execute before the server has been started. If you use Rails fixtures, it
200
+ may make sense to load them here, so they don't need to be re-inserted for each
201
+ request. This is also a good place to start whatever database-cleaning strategy
202
+ you're using (e.g. `DatabaseCleaner.start`).
199
203
 
200
204
  ### after_server_start
201
205
 
202
206
  Pass a block to `CypressRails.hooks.after_server_start` to register a hook that
203
207
  will execute after the server has booted.
204
208
 
205
- ### after_transaction_start
206
-
207
- If there's any custom behavior or state management you want to do inside the
208
- transaction (so that it's also rolled back each time a reset is triggered),
209
- pass a block to `CypressRails.hooks.after_transaction_start`.
210
-
211
- ### after_state_reset
209
+ ### after_reset_requested
212
210
 
213
211
  Every time the test server receives an HTTP request at
214
- `/cypress_rails_reset_state`, the transaction will be rolled back (if
215
- `CYPRESS_RAILS_TRANSACTIONAL_SERVER` is enabled) and the `after_state_reset`
216
- hook will be triggered. To set up the hook, pass a block to
217
- `CypressRails.hooks.after_state_reset`.
212
+ `/cypress_rails_reset_state`, the `after_reset_requested` hook will be
213
+ triggered at the start of the next request. This is where you should actually
214
+ reset your database (e.g. `DatabaseCleaner.clean` followed by
215
+ `DatabaseCleaner.start`) - cypress-rails does not reset any state on its own.
216
+ To set up the hook, pass a block to `CypressRails.hooks.after_reset_requested`.
218
217
 
219
218
  ### before_server_stop
220
219
 
@@ -2,7 +2,7 @@ require_relative "env"
2
2
 
3
3
  module CypressRails
4
4
  class Config
5
- attr_accessor :rails_dir, :cypress_dir, :host, :port, :base_path, :transactional_server, :cypress_cli_opts
5
+ attr_accessor :rails_dir, :cypress_dir, :host, :port, :base_path, :cypress_cli_opts
6
6
 
7
7
  def initialize(
8
8
  rails_dir: Env.fetch("CYPRESS_RAILS_DIR", default: Dir.pwd),
@@ -10,7 +10,6 @@ module CypressRails
10
10
  host: Env.fetch("CYPRESS_RAILS_HOST", default: "127.0.0.1"),
11
11
  port: Env.fetch("CYPRESS_RAILS_PORT"),
12
12
  base_path: Env.fetch("CYPRESS_RAILS_BASE_PATH", default: "/"),
13
- transactional_server: Env.fetch("CYPRESS_RAILS_TRANSACTIONAL_SERVER", type: :boolean, default: true),
14
13
  cypress_cli_opts: Env.fetch("CYPRESS_RAILS_CYPRESS_OPTS", default: "")
15
14
  )
16
15
  @rails_dir = rails_dir
@@ -18,7 +17,6 @@ module CypressRails
18
17
  @host = host
19
18
  @port = port
20
19
  @base_path = base_path
21
- @transactional_server = transactional_server
22
20
  @cypress_cli_opts = cypress_cli_opts
23
21
  end
24
22
 
@@ -32,7 +30,6 @@ module CypressRails
32
30
  CYPRESS_RAILS_HOST....................#{host.inspect}
33
31
  CYPRESS_RAILS_PORT....................#{port.inspect}
34
32
  CYPRESS_RAILS_BASE_PATH...............#{base_path.inspect}
35
- CYPRESS_RAILS_TRANSACTIONAL_SERVER....#{transactional_server.inspect}
36
33
  CYPRESS_RAILS_CYPRESS_OPTS............#{cypress_cli_opts.inspect}
37
34
 
38
35
  DESC
@@ -16,12 +16,8 @@ module CypressRails
16
16
  register(:after_server_start, blk)
17
17
  end
18
18
 
19
- def after_transaction_start(&blk)
20
- register(:after_transaction_start, blk)
21
- end
22
-
23
- def after_state_reset(&blk)
24
- register(:after_state_reset, blk)
19
+ def after_reset_requested(&blk)
20
+ register(:after_reset_requested, blk)
25
21
  end
26
22
 
27
23
  def before_server_stop(&blk)
@@ -1,14 +1,12 @@
1
1
  require_relative "finds_bin"
2
2
  require_relative "config"
3
3
  require_relative "initializer_hooks"
4
- require_relative "manages_transactions"
5
4
  require_relative "starts_rails_server"
6
5
 
7
6
  module CypressRails
8
7
  class LaunchesCypress
9
8
  def initialize
10
9
  @initializer_hooks = InitializerHooks.instance
11
- @manages_transactions = ManagesTransactions.instance
12
10
  @starts_rails_server = StartsRailsServer.new
13
11
  @finds_bin = FindsBin.new
14
12
  end
@@ -16,13 +14,9 @@ module CypressRails
16
14
  def call(command, config)
17
15
  puts config
18
16
  @initializer_hooks.run(:before_server_start)
19
- if config.transactional_server
20
- @manages_transactions.begin_transaction
21
- end
22
17
  server = @starts_rails_server.call(
23
18
  host: config.host,
24
- port: config.port,
25
- transactional_server: config.transactional_server
19
+ port: config.port
26
20
  )
27
21
  bin = @finds_bin.call(config.cypress_dir)
28
22
 
@@ -52,9 +46,6 @@ module CypressRails
52
46
  @at_exit_hooks_have_fired ||= false # avoid warning
53
47
  return if @at_exit_hooks_have_fired
54
48
 
55
- if config.transactional_server
56
- @manages_transactions.rollback_transaction
57
- end
58
49
  @initializer_hooks.run(:before_server_stop)
59
50
 
60
51
  @at_exit_hooks_have_fired = true
@@ -1,20 +1,14 @@
1
1
  require_relative "config"
2
- require_relative "manages_transactions"
3
2
  require_relative "initializer_hooks"
4
3
 
5
4
  module CypressRails
6
5
  class ResetsState
7
6
  def initialize
8
- @manages_transactions = ManagesTransactions.instance
9
7
  @initializer_hooks = InitializerHooks.instance
10
8
  end
11
9
 
12
- def call(transactional_server:)
13
- if transactional_server
14
- @manages_transactions.rollback_transaction
15
- @manages_transactions.begin_transaction
16
- end
17
- @initializer_hooks.run(:after_state_reset)
10
+ def call
11
+ @initializer_hooks.run(:after_reset_requested)
18
12
  end
19
13
  end
20
14
  end
@@ -3,17 +3,17 @@ require_relative "server"
3
3
 
4
4
  module CypressRails
5
5
  class StartsRailsServer
6
- def call(host:, port:, transactional_server:)
7
- configure_rails_to_run_our_state_reset_on_every_request!(transactional_server)
6
+ def call(host:, port:)
7
+ configure_rails_to_run_our_state_reset_on_every_request!
8
8
  app = create_rack_app
9
9
  Server.new(app, host: host, port: port).tap do |server|
10
10
  server.boot
11
11
  end
12
12
  end
13
13
 
14
- def configure_rails_to_run_our_state_reset_on_every_request!(transactional_server)
14
+ def configure_rails_to_run_our_state_reset_on_every_request!
15
15
  Rails.application.executor.to_run do
16
- TracksResets.instance.reset_state_if_needed(transactional_server)
16
+ TracksResets.instance.reset_state_if_needed
17
17
  end
18
18
  end
19
19
 
@@ -10,9 +10,9 @@ module CypressRails
10
10
  @reset_needed = true
11
11
  end
12
12
 
13
- def reset_state_if_needed(transactional_server)
13
+ def reset_state_if_needed
14
14
  if @reset_needed
15
- ResetsState.new.call(transactional_server: transactional_server)
15
+ ResetsState.new.call
16
16
  @reset_needed = false
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module CypressRails
2
- VERSION = "0.8.0.rc1"
2
+ VERSION = "0.8.0"
3
3
  end
data/script/test CHANGED
@@ -6,12 +6,20 @@ set -x
6
6
 
7
7
  echo "---> Installing dependencies"
8
8
  bundle
9
+ cd example
10
+ bundle
11
+ yarn
12
+ cd ..
9
13
 
10
- echo "---> Running tests"
14
+ echo "---> Running root tests"
11
15
  bundle exec rake
12
- BUNDLE_GEMFILE="${1-Gemfile}" ./script/test_example_app
13
16
 
14
- bundle exec rake test
17
+ for gemfile in example/gemfiles/*.gemfile; do
18
+ echo "---> Running example app tests against $gemfile"
19
+ export BUNDLE_GEMFILE="$PWD/$gemfile"
20
+ (cd example && bundle) # ensure that gemfile's lockfile is installed
21
+ ./script/test_example_app
22
+ unset BUNDLE_GEMFILE
23
+ done
15
24
 
16
25
  echo "---> Job's done!"
17
-
@@ -2,6 +2,8 @@
2
2
 
3
3
  set -e
4
4
 
5
+ directory=$1
6
+
5
7
  cd example
6
8
  bundle
7
9
  yarn install
@@ -16,3 +18,4 @@ if ! bundle exec rake cypress:run CYPRESS_RAILS_CYPRESS_OPTS="-h" | grep -q "Usa
16
18
  echo "Failed to pass options to cypress run"
17
19
  exit 1
18
20
  fi
21
+
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cypress-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.rc1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-09-25 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: railties
@@ -94,7 +93,6 @@ dependencies:
94
93
  - - ">="
95
94
  - !ruby/object:Gem::Version
96
95
  version: 0.2.0
97
- description:
98
96
  email:
99
97
  - searls@gmail.com
100
98
  executables:
@@ -108,7 +106,6 @@ files:
108
106
  - ".travis.yml"
109
107
  - CHANGELOG.md
110
108
  - Gemfile
111
- - Gemfile.lock
112
109
  - LICENSE.txt
113
110
  - README.md
114
111
  - Rakefile
@@ -123,7 +120,6 @@ files:
123
120
  - lib/cypress-rails/init.rb
124
121
  - lib/cypress-rails/initializer_hooks.rb
125
122
  - lib/cypress-rails/launches_cypress.rb
126
- - lib/cypress-rails/manages_transactions.rb
127
123
  - lib/cypress-rails/open.rb
128
124
  - lib/cypress-rails/railtie.rb
129
125
  - lib/cypress-rails/rake.rb
@@ -144,7 +140,6 @@ licenses:
144
140
  - MIT
145
141
  metadata:
146
142
  rubygems_mfa_required: 'true'
147
- post_install_message:
148
143
  rdoc_options: []
149
144
  require_paths:
150
145
  - lib
@@ -159,8 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
154
  - !ruby/object:Gem::Version
160
155
  version: '0'
161
156
  requirements: []
162
- rubygems_version: 3.5.11
163
- signing_key:
157
+ rubygems_version: 4.0.21
164
158
  specification_version: 4
165
159
  summary: Helps you write Cypress tests of your Rails app
166
160
  test_files: []
data/Gemfile.lock DELETED
@@ -1,153 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- cypress-rails (0.8.0.rc1)
5
- puma (>= 3.8.0)
6
- railties (>= 5.2.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- actionpack (7.1.3)
12
- actionview (= 7.1.3)
13
- activesupport (= 7.1.3)
14
- nokogiri (>= 1.8.5)
15
- racc
16
- rack (>= 2.2.4)
17
- rack-session (>= 1.0.1)
18
- rack-test (>= 0.6.3)
19
- rails-dom-testing (~> 2.2)
20
- rails-html-sanitizer (~> 1.6)
21
- actionview (7.1.3)
22
- activesupport (= 7.1.3)
23
- builder (~> 3.1)
24
- erubi (~> 1.11)
25
- rails-dom-testing (~> 2.2)
26
- rails-html-sanitizer (~> 1.6)
27
- activesupport (7.1.3)
28
- base64
29
- bigdecimal
30
- concurrent-ruby (~> 1.0, >= 1.0.2)
31
- connection_pool (>= 2.2.5)
32
- drb
33
- i18n (>= 1.6, < 2)
34
- minitest (>= 5.1)
35
- mutex_m
36
- tzinfo (~> 2.0)
37
- ast (2.4.2)
38
- base64 (0.2.0)
39
- bigdecimal (3.1.6)
40
- builder (3.2.4)
41
- concurrent-ruby (1.2.3)
42
- connection_pool (2.4.1)
43
- crass (1.0.6)
44
- drb (2.2.0)
45
- ruby2_keywords
46
- erubi (1.12.0)
47
- i18n (1.14.1)
48
- concurrent-ruby (~> 1.0)
49
- io-console (0.7.2)
50
- irb (1.13.1)
51
- rdoc (>= 4.0.0)
52
- reline (>= 0.4.2)
53
- json (2.7.1)
54
- language_server-protocol (3.17.0.3)
55
- lint_roller (1.1.0)
56
- loofah (2.22.0)
57
- crass (~> 1.0.2)
58
- nokogiri (>= 1.12.0)
59
- minitest (5.22.2)
60
- mutex_m (0.2.0)
61
- nio4r (2.7.0)
62
- nokogiri (1.16.2)
63
- racc (~> 1.4)
64
- parallel (1.24.0)
65
- parser (3.3.0.5)
66
- ast (~> 2.4.1)
67
- racc
68
- psych (5.1.2)
69
- stringio
70
- puma (6.4.2)
71
- nio4r (~> 2.0)
72
- racc (1.7.3)
73
- rack (3.1.7)
74
- rack-session (2.0.0)
75
- rack (>= 3.0.0)
76
- rack-test (2.1.0)
77
- rack (>= 1.3)
78
- rackup (2.1.0)
79
- rack (>= 3)
80
- webrick (~> 1.8)
81
- rails-dom-testing (2.2.0)
82
- activesupport (>= 5.0.0)
83
- minitest
84
- nokogiri (>= 1.6)
85
- rails-html-sanitizer (1.6.0)
86
- loofah (~> 2.21)
87
- nokogiri (~> 1.14)
88
- railties (7.1.3)
89
- actionpack (= 7.1.3)
90
- activesupport (= 7.1.3)
91
- irb
92
- rackup (>= 1.0.0)
93
- rake (>= 12.2)
94
- thor (~> 1.0, >= 1.2.2)
95
- zeitwerk (~> 2.6)
96
- rainbow (3.1.1)
97
- rake (13.1.0)
98
- rdoc (6.6.3.1)
99
- psych (>= 4.0.0)
100
- regexp_parser (2.9.0)
101
- reline (0.5.7)
102
- io-console (~> 0.5)
103
- rexml (3.2.6)
104
- rubocop (1.59.0)
105
- json (~> 2.3)
106
- language_server-protocol (>= 3.17.0)
107
- parallel (~> 1.10)
108
- parser (>= 3.2.2.4)
109
- rainbow (>= 2.2.2, < 4.0)
110
- regexp_parser (>= 1.8, < 3.0)
111
- rexml (>= 3.2.5, < 4.0)
112
- rubocop-ast (>= 1.30.0, < 2.0)
113
- ruby-progressbar (~> 1.7)
114
- unicode-display_width (>= 2.4.0, < 3.0)
115
- rubocop-ast (1.30.0)
116
- parser (>= 3.2.1.0)
117
- rubocop-performance (1.20.2)
118
- rubocop (>= 1.48.1, < 2.0)
119
- rubocop-ast (>= 1.30.0, < 2.0)
120
- ruby-progressbar (1.13.0)
121
- ruby2_keywords (0.0.5)
122
- standard (1.33.0)
123
- language_server-protocol (~> 3.17.0.2)
124
- lint_roller (~> 1.0)
125
- rubocop (~> 1.59.0)
126
- standard-custom (~> 1.0.0)
127
- standard-performance (~> 1.3)
128
- standard-custom (1.0.2)
129
- lint_roller (~> 1.0)
130
- rubocop (~> 1.50)
131
- standard-performance (1.3.1)
132
- lint_roller (~> 1.1)
133
- rubocop-performance (~> 1.20.2)
134
- stringio (3.1.1)
135
- thor (1.3.0)
136
- tzinfo (2.0.6)
137
- concurrent-ruby (~> 1.0)
138
- unicode-display_width (2.5.0)
139
- webrick (1.8.1)
140
- zeitwerk (2.6.13)
141
-
142
- PLATFORMS
143
- ruby
144
-
145
- DEPENDENCIES
146
- bundler
147
- cypress-rails!
148
- minitest (~> 5.0)
149
- rake (~> 13.0)
150
- standard (>= 0.2.0)
151
-
152
- BUNDLED WITH
153
- 2.3.13
@@ -1,82 +0,0 @@
1
- require_relative "initializer_hooks"
2
-
3
- module CypressRails
4
- class ManagesTransactions
5
- def self.instance
6
- @instance ||= new
7
- end
8
-
9
- def begin_transaction
10
- @connections = gather_connections
11
- @connections.each do |connection|
12
- connection.begin_transaction joinable: false, _lazy: false
13
- end
14
-
15
- # When connections are established in the future, begin a transaction too
16
- @connection_subscriber = ActiveSupport::Notifications.subscribe("!connection.active_record") { |_, _, _, _, payload|
17
- if payload.key?(:spec_name) && (spec_name = payload[:spec_name])
18
- setup_shared_connection_pool
19
-
20
- begin
21
- connection = ActiveRecord::Base.connection_handler.retrieve_connection(spec_name)
22
- rescue ActiveRecord::ConnectionNotEstablished
23
- connection = nil
24
- end
25
-
26
- if connection && !@connections.include?(connection)
27
- connection.begin_transaction joinable: false, _lazy: false
28
- @connections << connection
29
- end
30
- end
31
- }
32
-
33
- @initializer_hooks.run(:after_transaction_start)
34
- end
35
-
36
- def rollback_transaction
37
- return unless @connections.present?
38
-
39
- ActiveSupport::Notifications.unsubscribe(@connection_subscriber) if @connection_subscriber
40
-
41
- @connections.each do |connection|
42
- connection.rollback_transaction if connection.transaction_open?
43
- end
44
- @connections.clear
45
-
46
- ActiveRecord::Base.connection_handler.clear_active_connections!
47
- end
48
-
49
- private
50
-
51
- def initialize
52
- @initializer_hooks = InitializerHooks.instance
53
- end
54
-
55
- def gather_connections
56
- setup_shared_connection_pool
57
-
58
- ActiveRecord::Base.connection_handler.connection_pool_list.map do |pool|
59
- # Rails 7.2+
60
- if pool.respond_to?(:lease_connection)
61
- pool.lease_connection
62
- else
63
- pool.connection
64
- end
65
- end
66
- end
67
-
68
- # Shares the writing connection pool with connections on
69
- # other handlers.
70
- #
71
- # In an application with a primary and replica the test fixtures
72
- # need to share a connection pool so that the reading connection
73
- # can see data in the open transaction on the writing connection.
74
- def setup_shared_connection_pool
75
- return unless ActiveRecord::TestFixtures.respond_to?(:setup_shared_connection_pool)
76
- @legacy_saved_pool_configs ||= Hash.new { |hash, key| hash[key] = {} }
77
- @saved_pool_configs ||= Hash.new { |hash, key| hash[key] = {} }
78
-
79
- ActiveRecord::TestFixtures.instance_method(:setup_shared_connection_pool).bind(self).call
80
- end
81
- end
82
- end