【发布时间】:2012-12-10 23:30:43
【问题描述】:
考虑以下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。
【问题讨论】:
标签: ruby postgresql rspec mocking