PG::ConnectionBad: connection is closed after upgrading rails from 4.2 to 5.2












6














I have upgraded my rails version of a project from 4.2 to 5.2.1 some of my tests are failed because of pg connection closed error on the full trace is is as following.



    Failure/Error: DatabaseCleaner[:active_record].clean_with(:truncation)

ActiveRecord::StatementInvalid:
PG::ConnectionBad: connection is closed: TRUNCATE TABLE "public"."alerts", "public"."article_attachments", "public"."article_check_specification_tolerances", "public"."article_machine_part_settings", "public"."articles", "public"."attachments", "public"."check_batches", "public"."check_groups", "public"."check_specification_machine_types", "public"."check_specification_priorities", "public"."check_specification_responsibility_areas", "public"."check_specifications", "public"."checks", "public"."comments", "public"."counters", "public"."customers", "public"."defect_groups", "public"."defect_translations", "public"."defects", "public"."delayed_jobs", "public"."furnaces", "public"."gv_area_equipments", "public"."gv_areas", "public"."gv_components", "public"."gv_entries", "public"."gv_equipment_families", "public"."gv_equipments", "public"."gv_squads", "public"."gv_stop_reasons", "public"."gv_sub_equipment_components", "public"."gv_sub_equipments", "public"."job_specifications", "public"."jobs", "public"."lab_recipe_versions", "public"."lab_recipes", "public"."lines", "public"."machine_downtimes", "public"."machine_groups", "public"."machine_part_change_reasons", "public"."machine_part_changes", "public"."machine_part_translations", "public"."machine_parts", "public"."machine_type_group_machine_types", "public"."machine_type_groups", "public"."machine_types", "public"."messages", "public"."mold_sets", "public"."packing_schemes", "public"."rails_admin_settings", "public"."reasons", "public"."rejects", "public"."responsibility_areas", "public"."roles", "public"."settings", "public"."shift_definitions", "public"."shifts", "public"."system_log_entries", "public"."task_status_changes", "public"."tasks", "public"."tresholds", "public"."user_responsibility_areas", "public"."users", "public"."users_roles", "public"."workstations", "public"."machines", "public"."systematic_rejects", "public"."systematic_reject_machines" RESTART IDENTITY CASCADE;


and my rspec configurations are



RSpec.configure do |config|
config.around(:each) do |example|
DatabaseCleaner[:active_record].clean_with(:truncation)
# DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.cleaning do
example.run
end
end
end


strange thing is I can run tests one by one directory like



rspec spec/controllers/
rspec spec/contexts/
rspec spec/models


but it does not work when I try to run all in one with just



rspec spec/featues/


my feature_helper.rb is



require 'spec_helper'
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'capybara/rails'
require 'rack/handler/puma'
require 'support/shared_activerecord_connection'
require 'support/feature_macros'

Capybara.register_server :puma do |app, port, host|
require 'rack/handler/puma'
Capybara.asset_host = "http://#{host}:#{port}"
Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: '0:4', Silent: true, config_files: ['-'])
end
Capybara.configure do |config|
config.server = :puma
end

RSpec.configure do |config|
config.before(:suite) do
Rails.application.load_tasks
Rake::Task['assets:precompile'].invoke
end
end

require 'spec_helper'
require 'counter_column_fix'

RedisStore.class_eval do
def self.new_instance
$redis = Redis.new(Rails.configuration.redis_config)
end
end


what should I do to remove this error?










share|improve this question





























    6














    I have upgraded my rails version of a project from 4.2 to 5.2.1 some of my tests are failed because of pg connection closed error on the full trace is is as following.



        Failure/Error: DatabaseCleaner[:active_record].clean_with(:truncation)

    ActiveRecord::StatementInvalid:
    PG::ConnectionBad: connection is closed: TRUNCATE TABLE "public"."alerts", "public"."article_attachments", "public"."article_check_specification_tolerances", "public"."article_machine_part_settings", "public"."articles", "public"."attachments", "public"."check_batches", "public"."check_groups", "public"."check_specification_machine_types", "public"."check_specification_priorities", "public"."check_specification_responsibility_areas", "public"."check_specifications", "public"."checks", "public"."comments", "public"."counters", "public"."customers", "public"."defect_groups", "public"."defect_translations", "public"."defects", "public"."delayed_jobs", "public"."furnaces", "public"."gv_area_equipments", "public"."gv_areas", "public"."gv_components", "public"."gv_entries", "public"."gv_equipment_families", "public"."gv_equipments", "public"."gv_squads", "public"."gv_stop_reasons", "public"."gv_sub_equipment_components", "public"."gv_sub_equipments", "public"."job_specifications", "public"."jobs", "public"."lab_recipe_versions", "public"."lab_recipes", "public"."lines", "public"."machine_downtimes", "public"."machine_groups", "public"."machine_part_change_reasons", "public"."machine_part_changes", "public"."machine_part_translations", "public"."machine_parts", "public"."machine_type_group_machine_types", "public"."machine_type_groups", "public"."machine_types", "public"."messages", "public"."mold_sets", "public"."packing_schemes", "public"."rails_admin_settings", "public"."reasons", "public"."rejects", "public"."responsibility_areas", "public"."roles", "public"."settings", "public"."shift_definitions", "public"."shifts", "public"."system_log_entries", "public"."task_status_changes", "public"."tasks", "public"."tresholds", "public"."user_responsibility_areas", "public"."users", "public"."users_roles", "public"."workstations", "public"."machines", "public"."systematic_rejects", "public"."systematic_reject_machines" RESTART IDENTITY CASCADE;


    and my rspec configurations are



    RSpec.configure do |config|
    config.around(:each) do |example|
    DatabaseCleaner[:active_record].clean_with(:truncation)
    # DatabaseCleaner.clean_with(:truncation)
    DatabaseCleaner.cleaning do
    example.run
    end
    end
    end


    strange thing is I can run tests one by one directory like



    rspec spec/controllers/
    rspec spec/contexts/
    rspec spec/models


    but it does not work when I try to run all in one with just



    rspec spec/featues/


    my feature_helper.rb is



    require 'spec_helper'
    # This file is copied to spec/ when you run 'rails generate rspec:install'
    ENV['RAILS_ENV'] ||= 'test'
    require File.expand_path('../../config/environment', __FILE__)
    # Prevent database truncation if the environment is production
    abort("The Rails environment is running in production mode!") if Rails.env.production?
    require 'rspec/rails'
    require 'capybara/rails'
    require 'rack/handler/puma'
    require 'support/shared_activerecord_connection'
    require 'support/feature_macros'

    Capybara.register_server :puma do |app, port, host|
    require 'rack/handler/puma'
    Capybara.asset_host = "http://#{host}:#{port}"
    Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: '0:4', Silent: true, config_files: ['-'])
    end
    Capybara.configure do |config|
    config.server = :puma
    end

    RSpec.configure do |config|
    config.before(:suite) do
    Rails.application.load_tasks
    Rake::Task['assets:precompile'].invoke
    end
    end

    require 'spec_helper'
    require 'counter_column_fix'

    RedisStore.class_eval do
    def self.new_instance
    $redis = Redis.new(Rails.configuration.redis_config)
    end
    end


    what should I do to remove this error?










    share|improve this question



























      6












      6








      6


      2





      I have upgraded my rails version of a project from 4.2 to 5.2.1 some of my tests are failed because of pg connection closed error on the full trace is is as following.



          Failure/Error: DatabaseCleaner[:active_record].clean_with(:truncation)

      ActiveRecord::StatementInvalid:
      PG::ConnectionBad: connection is closed: TRUNCATE TABLE "public"."alerts", "public"."article_attachments", "public"."article_check_specification_tolerances", "public"."article_machine_part_settings", "public"."articles", "public"."attachments", "public"."check_batches", "public"."check_groups", "public"."check_specification_machine_types", "public"."check_specification_priorities", "public"."check_specification_responsibility_areas", "public"."check_specifications", "public"."checks", "public"."comments", "public"."counters", "public"."customers", "public"."defect_groups", "public"."defect_translations", "public"."defects", "public"."delayed_jobs", "public"."furnaces", "public"."gv_area_equipments", "public"."gv_areas", "public"."gv_components", "public"."gv_entries", "public"."gv_equipment_families", "public"."gv_equipments", "public"."gv_squads", "public"."gv_stop_reasons", "public"."gv_sub_equipment_components", "public"."gv_sub_equipments", "public"."job_specifications", "public"."jobs", "public"."lab_recipe_versions", "public"."lab_recipes", "public"."lines", "public"."machine_downtimes", "public"."machine_groups", "public"."machine_part_change_reasons", "public"."machine_part_changes", "public"."machine_part_translations", "public"."machine_parts", "public"."machine_type_group_machine_types", "public"."machine_type_groups", "public"."machine_types", "public"."messages", "public"."mold_sets", "public"."packing_schemes", "public"."rails_admin_settings", "public"."reasons", "public"."rejects", "public"."responsibility_areas", "public"."roles", "public"."settings", "public"."shift_definitions", "public"."shifts", "public"."system_log_entries", "public"."task_status_changes", "public"."tasks", "public"."tresholds", "public"."user_responsibility_areas", "public"."users", "public"."users_roles", "public"."workstations", "public"."machines", "public"."systematic_rejects", "public"."systematic_reject_machines" RESTART IDENTITY CASCADE;


      and my rspec configurations are



      RSpec.configure do |config|
      config.around(:each) do |example|
      DatabaseCleaner[:active_record].clean_with(:truncation)
      # DatabaseCleaner.clean_with(:truncation)
      DatabaseCleaner.cleaning do
      example.run
      end
      end
      end


      strange thing is I can run tests one by one directory like



      rspec spec/controllers/
      rspec spec/contexts/
      rspec spec/models


      but it does not work when I try to run all in one with just



      rspec spec/featues/


      my feature_helper.rb is



      require 'spec_helper'
      # This file is copied to spec/ when you run 'rails generate rspec:install'
      ENV['RAILS_ENV'] ||= 'test'
      require File.expand_path('../../config/environment', __FILE__)
      # Prevent database truncation if the environment is production
      abort("The Rails environment is running in production mode!") if Rails.env.production?
      require 'rspec/rails'
      require 'capybara/rails'
      require 'rack/handler/puma'
      require 'support/shared_activerecord_connection'
      require 'support/feature_macros'

      Capybara.register_server :puma do |app, port, host|
      require 'rack/handler/puma'
      Capybara.asset_host = "http://#{host}:#{port}"
      Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: '0:4', Silent: true, config_files: ['-'])
      end
      Capybara.configure do |config|
      config.server = :puma
      end

      RSpec.configure do |config|
      config.before(:suite) do
      Rails.application.load_tasks
      Rake::Task['assets:precompile'].invoke
      end
      end

      require 'spec_helper'
      require 'counter_column_fix'

      RedisStore.class_eval do
      def self.new_instance
      $redis = Redis.new(Rails.configuration.redis_config)
      end
      end


      what should I do to remove this error?










      share|improve this question















      I have upgraded my rails version of a project from 4.2 to 5.2.1 some of my tests are failed because of pg connection closed error on the full trace is is as following.



          Failure/Error: DatabaseCleaner[:active_record].clean_with(:truncation)

      ActiveRecord::StatementInvalid:
      PG::ConnectionBad: connection is closed: TRUNCATE TABLE "public"."alerts", "public"."article_attachments", "public"."article_check_specification_tolerances", "public"."article_machine_part_settings", "public"."articles", "public"."attachments", "public"."check_batches", "public"."check_groups", "public"."check_specification_machine_types", "public"."check_specification_priorities", "public"."check_specification_responsibility_areas", "public"."check_specifications", "public"."checks", "public"."comments", "public"."counters", "public"."customers", "public"."defect_groups", "public"."defect_translations", "public"."defects", "public"."delayed_jobs", "public"."furnaces", "public"."gv_area_equipments", "public"."gv_areas", "public"."gv_components", "public"."gv_entries", "public"."gv_equipment_families", "public"."gv_equipments", "public"."gv_squads", "public"."gv_stop_reasons", "public"."gv_sub_equipment_components", "public"."gv_sub_equipments", "public"."job_specifications", "public"."jobs", "public"."lab_recipe_versions", "public"."lab_recipes", "public"."lines", "public"."machine_downtimes", "public"."machine_groups", "public"."machine_part_change_reasons", "public"."machine_part_changes", "public"."machine_part_translations", "public"."machine_parts", "public"."machine_type_group_machine_types", "public"."machine_type_groups", "public"."machine_types", "public"."messages", "public"."mold_sets", "public"."packing_schemes", "public"."rails_admin_settings", "public"."reasons", "public"."rejects", "public"."responsibility_areas", "public"."roles", "public"."settings", "public"."shift_definitions", "public"."shifts", "public"."system_log_entries", "public"."task_status_changes", "public"."tasks", "public"."tresholds", "public"."user_responsibility_areas", "public"."users", "public"."users_roles", "public"."workstations", "public"."machines", "public"."systematic_rejects", "public"."systematic_reject_machines" RESTART IDENTITY CASCADE;


      and my rspec configurations are



      RSpec.configure do |config|
      config.around(:each) do |example|
      DatabaseCleaner[:active_record].clean_with(:truncation)
      # DatabaseCleaner.clean_with(:truncation)
      DatabaseCleaner.cleaning do
      example.run
      end
      end
      end


      strange thing is I can run tests one by one directory like



      rspec spec/controllers/
      rspec spec/contexts/
      rspec spec/models


      but it does not work when I try to run all in one with just



      rspec spec/featues/


      my feature_helper.rb is



      require 'spec_helper'
      # This file is copied to spec/ when you run 'rails generate rspec:install'
      ENV['RAILS_ENV'] ||= 'test'
      require File.expand_path('../../config/environment', __FILE__)
      # Prevent database truncation if the environment is production
      abort("The Rails environment is running in production mode!") if Rails.env.production?
      require 'rspec/rails'
      require 'capybara/rails'
      require 'rack/handler/puma'
      require 'support/shared_activerecord_connection'
      require 'support/feature_macros'

      Capybara.register_server :puma do |app, port, host|
      require 'rack/handler/puma'
      Capybara.asset_host = "http://#{host}:#{port}"
      Rack::Handler::Puma.run(app, Host: host, Port: port, Threads: '0:4', Silent: true, config_files: ['-'])
      end
      Capybara.configure do |config|
      config.server = :puma
      end

      RSpec.configure do |config|
      config.before(:suite) do
      Rails.application.load_tasks
      Rake::Task['assets:precompile'].invoke
      end
      end

      require 'spec_helper'
      require 'counter_column_fix'

      RedisStore.class_eval do
      def self.new_instance
      $redis = Redis.new(Rails.configuration.redis_config)
      end
      end


      what should I do to remove this error?







      ruby-on-rails-4 rspec ruby-on-rails-5 rake database-cleaner






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 15:21

























      asked Nov 14 '18 at 8:54









      Asnad Atta

      2,1391928




      2,1391928
























          1 Answer
          1






          active

          oldest

          votes


















          2














          DatabaseCleaner isn’t generally needed with Rails 5.1+ . Remove all references to it from your project and enable transactional testing in your RSpec config






          share|improve this answer





















          • same issue by removing database cleaner and I also enabled transactional testing
            – Asnad Atta
            Nov 23 '18 at 16:14










          • @AsnadAtta Then you're not requiring rspec-rails before trying to set use_transactional_fixtures
            – Thomas Walpole
            Nov 23 '18 at 16:16










          • @AsnadAtta There is no way you can still be having the same issue if you've removed database_cleaner - In the issue you state the error is from DatabaseCleaner[:active_record].clean_with(:truncation) - That can't be the error anymore if you've actually removed database_cleaner.
            – Thomas Walpole
            Nov 23 '18 at 16:38











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296233%2fpgconnectionbad-connection-is-closed-after-upgrading-rails-from-4-2-to-5-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          DatabaseCleaner isn’t generally needed with Rails 5.1+ . Remove all references to it from your project and enable transactional testing in your RSpec config






          share|improve this answer





















          • same issue by removing database cleaner and I also enabled transactional testing
            – Asnad Atta
            Nov 23 '18 at 16:14










          • @AsnadAtta Then you're not requiring rspec-rails before trying to set use_transactional_fixtures
            – Thomas Walpole
            Nov 23 '18 at 16:16










          • @AsnadAtta There is no way you can still be having the same issue if you've removed database_cleaner - In the issue you state the error is from DatabaseCleaner[:active_record].clean_with(:truncation) - That can't be the error anymore if you've actually removed database_cleaner.
            – Thomas Walpole
            Nov 23 '18 at 16:38
















          2














          DatabaseCleaner isn’t generally needed with Rails 5.1+ . Remove all references to it from your project and enable transactional testing in your RSpec config






          share|improve this answer





















          • same issue by removing database cleaner and I also enabled transactional testing
            – Asnad Atta
            Nov 23 '18 at 16:14










          • @AsnadAtta Then you're not requiring rspec-rails before trying to set use_transactional_fixtures
            – Thomas Walpole
            Nov 23 '18 at 16:16










          • @AsnadAtta There is no way you can still be having the same issue if you've removed database_cleaner - In the issue you state the error is from DatabaseCleaner[:active_record].clean_with(:truncation) - That can't be the error anymore if you've actually removed database_cleaner.
            – Thomas Walpole
            Nov 23 '18 at 16:38














          2












          2








          2






          DatabaseCleaner isn’t generally needed with Rails 5.1+ . Remove all references to it from your project and enable transactional testing in your RSpec config






          share|improve this answer












          DatabaseCleaner isn’t generally needed with Rails 5.1+ . Remove all references to it from your project and enable transactional testing in your RSpec config







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 15:42









          Thomas Walpole

          30.1k32647




          30.1k32647












          • same issue by removing database cleaner and I also enabled transactional testing
            – Asnad Atta
            Nov 23 '18 at 16:14










          • @AsnadAtta Then you're not requiring rspec-rails before trying to set use_transactional_fixtures
            – Thomas Walpole
            Nov 23 '18 at 16:16










          • @AsnadAtta There is no way you can still be having the same issue if you've removed database_cleaner - In the issue you state the error is from DatabaseCleaner[:active_record].clean_with(:truncation) - That can't be the error anymore if you've actually removed database_cleaner.
            – Thomas Walpole
            Nov 23 '18 at 16:38


















          • same issue by removing database cleaner and I also enabled transactional testing
            – Asnad Atta
            Nov 23 '18 at 16:14










          • @AsnadAtta Then you're not requiring rspec-rails before trying to set use_transactional_fixtures
            – Thomas Walpole
            Nov 23 '18 at 16:16










          • @AsnadAtta There is no way you can still be having the same issue if you've removed database_cleaner - In the issue you state the error is from DatabaseCleaner[:active_record].clean_with(:truncation) - That can't be the error anymore if you've actually removed database_cleaner.
            – Thomas Walpole
            Nov 23 '18 at 16:38
















          same issue by removing database cleaner and I also enabled transactional testing
          – Asnad Atta
          Nov 23 '18 at 16:14




          same issue by removing database cleaner and I also enabled transactional testing
          – Asnad Atta
          Nov 23 '18 at 16:14












          @AsnadAtta Then you're not requiring rspec-rails before trying to set use_transactional_fixtures
          – Thomas Walpole
          Nov 23 '18 at 16:16




          @AsnadAtta Then you're not requiring rspec-rails before trying to set use_transactional_fixtures
          – Thomas Walpole
          Nov 23 '18 at 16:16












          @AsnadAtta There is no way you can still be having the same issue if you've removed database_cleaner - In the issue you state the error is from DatabaseCleaner[:active_record].clean_with(:truncation) - That can't be the error anymore if you've actually removed database_cleaner.
          – Thomas Walpole
          Nov 23 '18 at 16:38




          @AsnadAtta There is no way you can still be having the same issue if you've removed database_cleaner - In the issue you state the error is from DatabaseCleaner[:active_record].clean_with(:truncation) - That can't be the error anymore if you've actually removed database_cleaner.
          – Thomas Walpole
          Nov 23 '18 at 16:38


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53296233%2fpgconnectionbad-connection-is-closed-after-upgrading-rails-from-4-2-to-5-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks