antonmi / espec_phoenix

ESpec for Phoenix web framework.
MIT License
138 stars 33 forks source link

RuntimeError with Ecto 2.0 #16

Closed SergeyKorochansky closed 8 years ago

SergeyKorochansky commented 8 years ago

@antonmi I updated ecto to the last version and my espec tests are red now :fearful: As said in Ecto changelog, I replaced begin_test_transaction with Ecto.Adapters.SQL.Sandbox.mode(FishDuel.Repo, :manual) and restart_test_transaction with :ok = Ecto.Adapters.SQL.Sandbox.checkout(FishDuel.Repo), but still recieve this error:

** (exit) an exception was raised:
    ** (RuntimeError) cannot find ownership process for #PID<0.560.0>. This may happen if you have not explicitly checked out or the checked out process crashed
        (db_connection) lib/db_connection.ex:817: DBConnection.checkout/2
        (db_connection) lib/db_connection.ex:717: DBConnection.run/3
        (db_connection) lib/db_connection.ex:535: DBConnection.prepare_execute/4
        (ecto) lib/ecto/adapters/sql.ex:362: Ecto.Adapters.SQL.execute_and_cache/7
        (ecto) lib/ecto/repo/queryable.ex:122: Ecto.Repo.Queryable.execute/5
        (ecto) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/4
        (ecto) lib/ecto/repo/queryable.ex:67: Ecto.Repo.Queryable.one!/4
        (fishduel) web/controllers/payment_method/withdraws_controller.ex:10: FishDuel.PaymentMethod.WithdrawsController.create/2
pragmaticivan commented 8 years ago

Having the same issue ;/

sriedel commented 8 years ago

Using ecto-2.0.0-rc.3 and phoenix-ecto-3.0.0-rc.0 it seems to be working.

I added to the bottom of spec/phoenix_helper.exs:

Ecto.Adapters.SQL.Sandbox.mode( App.Repo, :manual )

And in spec/spec_helper.exs:

  config.before fn ->
    :ok = Ecto.Adapters.SQL.Sandbox.checkout( App.Repo )
     {:shared, hello: :world}
   end

   config.finally fn(_shared) ->
      :ok = Ecto.Adapters.SQL.Sandbox.checkin( App.Repo )
      :ok
    end

Seems to be working for me.

pragmaticivan commented 8 years ago

@sriedel worked for me too, thanks.

antonmi commented 8 years ago

@sriedel thanks for the solution!

walter commented 8 years ago

@sriedel your fix did the trick for me as well. Thanks!