考虑以下内容stored procedure
:
CREATE OR REPLACE FUNCTION get_supported_locales()
RETURNS TABLE(
code character varying(10)
) AS
...
以及以下调用它的方法:
def self.supported_locales
query = "SELECT code FROM get_supported_locales();"
res = ActiveRecord::Base.connection.execute(query)
res.values.flatten
end
我正在尝试为此方法编写测试,但在模拟时遇到了一些问题:
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
此测试成功,但在此之后运行的任何测试都会给出以下消息:
WARNING: there is already a transaction in progress
为什么会这样?我在嘲讽吗
数据库是postgres 9.1。