Skip to content

Commit

Permalink
null database strategy to disable @javascript handling
Browse files Browse the repository at this point in the history
  • Loading branch information
akostadinov committed Oct 21, 2021
1 parent 2abac38 commit 1c3a4e0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
34 changes: 33 additions & 1 deletion features/choose_javascript_database_strategy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ Feature: Choose javascript database strategy
Right now, the default behavior is to use truncation, but you can override this by telling
cucumber-rails which strategy to use for javascript scenarios.

The deletion strategy can be quicker for situations where truncation causes locks which
The `:deletion` strategy can be quicker for situations where truncation causes locks which
has been reported by some Oracle users.

The `:none` strategy can be used when user doesn't want special handling of scenario
database clean-up regardless of tags set for said scenario.

Background:
Given I have created a new Rails app and installed cucumber-rails
And I have a "Widget" ActiveRecord model object
Expand Down Expand Up @@ -101,6 +104,35 @@ Feature: Choose javascript database strategy
5 steps (5 passed)
"""

Scenario: Set the strategy to none and run a javascript scenario.
When I append to "features/env.rb" with:
"""
DatabaseCleaner.strategy = :transaction
Cucumber::Rails::Database.javascript_strategy = :none
"""
And I write to "features/widgets.feature" with:
"""
Feature:
Background:
When I create 2 widgets
@javascript
Scenario:
When I create 3 widgets
Then I should have 5 widgets
And the DatabaseCleaner strategy should be transaction
Scenario:
Then I should have 2 widgets
And the DatabaseCleaner strategy should be transaction
"""
And I run the cukes
Then the feature run should pass with:
"""
2 scenarios (2 passed)
7 steps (7 passed)
"""

Scenario: Set the strategy to truncation with an except option and run a javascript scenario.
When I append to "features/env.rb" with:
"""
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require 'cucumber/rails/capybara'
require 'cucumber/rails/database/strategy'
require 'cucumber/rails/database/deletion_strategy'
require 'cucumber/rails/database/null_strategy'
require 'cucumber/rails/database/shared_connection_strategy'
require 'cucumber/rails/database/truncation_strategy'
require 'cucumber/rails/database'
Expand Down
3 changes: 2 additions & 1 deletion lib/cucumber/rails/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def map
truncation: TruncationStrategy,
shared_connection: SharedConnectionStrategy,
transaction: SharedConnectionStrategy,
deletion: DeletionStrategy
deletion: DeletionStrategy,
none: NullStrategy
}
end

Expand Down
15 changes: 15 additions & 0 deletions lib/cucumber/rails/database/null_strategy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Cucumber
module Rails
module Database
class NullStrategy
def before_js; end

def before_non_js; end

def after; end
end
end
end
end
1 change: 1 addition & 0 deletions spec/cucumber/rails/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'database_cleaner'
require 'cucumber/rails/database/strategy'
require 'cucumber/rails/database/deletion_strategy'
require 'cucumber/rails/database/null_strategy'
require 'cucumber/rails/database/shared_connection_strategy'
require 'cucumber/rails/database/truncation_strategy'
require 'cucumber/rails/database'
Expand Down

0 comments on commit 1c3a4e0

Please sign in to comment.