Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9043443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:44:01+00:00 2026-06-16T10:44:01+00:00

Consider the following stored procedure : CREATE OR REPLACE FUNCTION get_supported_locales() RETURNS TABLE( code

  • 0

Consider the following stored procedure:

CREATE OR REPLACE FUNCTION get_supported_locales()
RETURNS TABLE(
  code character varying(10)
) AS
...

And the following method that call’s it:

def self.supported_locales
  query = "SELECT code FROM get_supported_locales();"
  res = ActiveRecord::Base.connection.execute(query)
  res.values.flatten
end

I’m trying to write a test for this method but I’m getting some problems while mocking:

it "should list an intersection of locales available on the app and on last fm" do
  res = mock(PG::Result)
  res.should_receive(:values).and_return(['en', 'pt'])
  ActiveRecord::Base.connection.stub(:execute).and_return(res)

  Language.supported_locales.should =~ ['pt', 'en']
end

This test succeds but any test that runs after this one gives the following message:

WARNING:  there is already a transaction in progress

Why does this happen? Am I doing the mocking

The database is postgres 9.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:44:02+00:00Added an answer on June 16, 2026 at 10:44 am

    Your test is running using database level transactions. When the test completes, the transaction is rolled back so that none of the changes made in the test are actually saved to the database. In your case, this rollback can’t happen because you have stubbed out the execute method on the ActiveRecord connection.

    You can disable transactions globally and switch to using DatabaseCleaner to enable/disable transactions for various tests. You could then set up to use transactions through DatabaseCleaner by default so your existing tests don’t change, and then in this one test choose to disable transactions in favor of some other strategy (such as the null strategy since there is no cleaning to be done for this test).

    This other SO post indicates you may be able to avoid disabling transactions globally and turn them off on a per test basis as well, I have not tried that myself though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following psuedo T-SQL code (performed by a stored procedure): CREATE TABLE #localTable
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Consider the following code. <!DOCTYPE html> <script> console.log(a); function a() {} </script> Notice that
Consider the following stored procedure.. CREATE PROCEDURE SlowCleanUp (@MaxDate DATETIME) AS BEGIN PRINT 'Deleting
Using MSSQL 2008 and XQUERY Consider the following XML stored in a table: <ROOT>
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following table: create table temp ( name int, a int, b int
Consider the following: CREATE TABLE Members ( MemberID CHAR(10) , GroupID CHAR(10) , JoinDate
I have a parent child relationship stored in a table consider the following example
Consider following code: My problem is: 1) I can't seem to cast the errors

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.