<commit_before>#Feature: Multiple Databases
#  In order to use Database Cleaner with multiple database repositories
#  As an engineer
#  I want to specify explicit strategies for each
#
#  Background: A Rails 3 app utilizing multiple database repositories exists
#    Given I have created a new Rails 3 app and installed cucumber-rails
#    And I append to "config/database.yml" with:
#      """
#
#      ursidae:
#        adapter: sqlite3
#        database: db/ursidae.sqlite3
#      """
#    And I write to "app/models/bear.rb" with:
#      """
#      class Bear < ActiveRecord::Base
#        establish_connection "ursidae"
#
#        attr_accessible :name
#      end
#      """
#    And a directory named "db/migrate"
#    And I write to "db/migrate/001_create_bears.rb" with:
#      """
#      class CreateBears < ActiveRecord::Migration
#        def self.up
#          if Rails.env == 'ursidae'
#            create_table :bears do |t|
#              t.string :name, :null => false
#            end
#            add_index :bears, :name,  :unique => true
#          end
#        end
#      end
#      """
#    And I successfully run `bundle exec rake db:migrate`
#    And I successfully run `bundle exec rake db:migrate RAILS_ENV=ursidae`
#    And I write to "features/support/env.rb" with:
#      """
#      require 'cucumber/rails'
#      DatabaseCleaner.strategy = :transaction
#      DatabaseCleaner[:active_record, {:connection => "ursidae"}].strategy = :truncation
#      """
#    And I write to "features/create_bear.feature" with:
#      """
#      Feature: Screws up in transactional test and must use truncation
#        Scenario: I create a bear
#          When I create a bear
#          And something transactional happens
#      """
#    And I write to "features/step_definitions/create_bear_steps.rb" with:
#      """
#      When /^I create a bear$/ do
#        Bear.create!(:name => "yogi")
#      end
#      When /^something transactional happens$/ do
#        Bear.transaction { Bear.find_by_name("yogi").lock! }
#      end
#      """
#
#  Scenario: Default transactional strategy is not attempted on second database
#    When I run `bundle exec rake cucumber FEATURE=features/create_bear.feature`
#    Then it should pass with:
#      """
#      1 scenario (1 passed)
#      2 steps (2 passed)
#      """
#    And the output should not contain "cannot rollback - no transaction is active"
#
#  Scenario: Truncation strategy is used on the second database
#    Given I successfully run `bundle exec rails runner 'Bear.create(:name => "boo boo")'`
#    And I successfully run `bundle exec rake cucumber FEATURE=features/create_bear.feature`
#    When I run `bundle exec rails runner 'raise "ahh! bears!" if Bear.count > 0'`
#    Then the exit status should be 0<commit_msg>put back multiple_databases test and changed Rails 3 app to Rails app<commit_after>Feature: Multiple Databases
  In order to use Database Cleaner with multiple database repositories
  As an engineer
  I want to specify explicit strategies for each

  Background: A Rails app utilizing multiple database repositories exists
    Given I have created a new Rails app and installed cucumber-rails
    And I append to "config/database.yml" with:
      """

      ursidae:
        adapter: sqlite3
        database: db/ursidae.sqlite3
      """
    And I write to "app/models/bear.rb" with:
      """
      class Bear < ActiveRecord::Base
        establish_connection "ursidae"

        attr_accessible :name
      end
      """
    And a directory named "db/migrate"
    And I write to "db/migrate/001_create_bears.rb" with:
      """
      class CreateBears < ActiveRecord::Migration
        def self.up
          if Rails.env == 'ursidae'
            create_table :bears do |t|
              t.string :name, :null => false
            end
            add_index :bears, :name,  :unique => true
          end
        end
      end
      """
    And I successfully run `bundle exec rake db:migrate`
    And I successfully run `bundle exec rake db:migrate RAILS_ENV=ursidae`
    And I write to "features/support/env.rb" with:
      """
      require 'cucumber/rails'
      DatabaseCleaner.strategy = :transaction
      DatabaseCleaner[:active_record, {:connection => :ursidae}].strategy = :truncation
      """
    And I write to "features/create_bear.feature" with:
      """
      Feature: Screws up in transactional test and must use truncation
        Scenario: I create a bear
          When I create a bear
          And something transactional happens
      """
    And I write to "features/step_definitions/create_bear_steps.rb" with:
      """
      When /^I create a bear$/ do
        Bear.create!(:name => "yogi")
      end
      When /^something transactional happens$/ do
        Bear.transaction { Bear.find_by_name("yogi").lock! }
      end
      """

  Scenario: Default transactional strategy is not attempted on second database
    When I run `bundle exec rake cucumber FEATURE=features/create_bear.feature`
    Then it should pass with:
      """
      1 scenario (1 passed)
      2 steps (2 passed)
      """
    And the output should not contain "cannot rollback - no transaction is active"

  Scenario: Truncation strategy is used on the second database
    Given I successfully run `bundle exec rails runner 'Bear.create(:name => "boo boo")'`
    And I successfully run `bundle exec rake cucumber FEATURE=features/create_bear.feature`
    When I run `bundle exec rails runner 'raise "ahh! bears!" if Bear.count > 0'`
    Then the exit status should be 0
{'fraction_non_alphanumeric': 0.0920532182668105, 'fraction_numerical': 0.004494786048184107, 'mean_word_length': 2.5751928020565553, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7301876', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1574, 'n_words': 576}