- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Cucumber 测试 Multi-Tenancy PostgreSQL 应用程序。似乎每一步都重置数据库连接,因此需要在每一步设置schema_search_path
。我知道钩子(Hook),并寻找 BeforeStep
,但是 there's none .该帖子提到使用 Before
和 AfterStep
的组合,但这也不起作用,因为 schema_search_path
在每一步之前都被重置。
如何在每一步之前自动和 DRYly 切换数据库,以便我的 Cuke 世界与应用程序 session 一致?
想看详情?这是我现在的设置(注意:我正在使用 Apartment gem 进行切换):
Before do
# ...
Apartment::Database.switch @current_site.subdomain if @current_site
# ...
end
AfterStep do
puts "start of AfterStep. current_database: #{Apartment::Database.current_database}"
# ...
Apartment::Database.switch @current_site.subdomain if @current_site
# ...
puts "end of AfterStep. current_database: #{Apartment::Database.current_database}"
end
然后我有一些步骤:
Given /^a site "([^"]*)" exists$/ do |site_name|
@current_site = Site.make! :name => site_name, :subdomain => site_name.downcase.underscore
Apartment::Database.switch @current_site.subdomain
end
When /^I upload an image to the image field$/ do
image_path = "#{Rails.root}/spec/fixtures/5x5.jpg"
puts "About to attach_file. that's controlled by selenium so the ApplicationController should switch for us."
attach_file "File", image_path
puts "current site: #{@current_site.subdomain}"
puts "In the schema #{Apartment::Database.current_database}"
sleep 2
puts "Here are all images in #{Apartment::Database.current_database}: #{Image.all.inspect}"
end
下面是该步骤的 cucumber 输出:
Given the site "Fancake" exists
# Other steps...
When I upload an image to the image field
About to attach_file. that's controlled by selenium so the ApplicationController should switch for us.
current site: fancake
In the schema "$user",public
Here are all images in "$user",public: []
start of AfterStep. current_database: "$user",public
end of AfterStep. current_database: fancake
最佳答案
您的应用程序如何切换模式?您的 Cucumber 步骤应该以相同的方式执行(可能通过应用程序 UI)。
为什么要为模式烦恼呢? Multi-Tenancy 应用程序通常应将所有数据存储在一个模式中:如果将数据存储在一起,则比将数据分开存储时将数据粘合在一起更容易。
关于ruby-on-rails - 在 Cucumber 中的每一步之前自动切换 PostgreSQL 架构 - "BeforeStep"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8283649/
我有自己的 ItemReader 实现,有两种方法。 public class Reader implements ItemReader { private final Logger logg
我正在写一个 Spring 批处理作业。但是在加载这个实现tasklet接口(interface)的Archive类时,注释@BeforeStep下的方法不会被调用。谁能帮我这个 ? 谢谢你 impo
我一直在使用同步的 ItemProcessor 和 Writer,但现在我将其移至异步,如下面的代码: @Bean public Job importFraudCodeJob(Step compute
我有一个带有 @BeforeStep 函数的自定义读取器,用于初始化一些数据。这些数据来自外部数据库。 @Component public class CustomReader implements
我们正在尝试使用 spring 批处理分区来实现批处理作业。在“步骤 2”中是一个分区步骤,我需要步骤 1 中的一些数据进行处理。我使用了 StepExecutionContext ,它将被提升为作业
有没有办法让MultiResourceItemReader处理的currentResource在beforeStep方法中可用。请给我一个>工作代码示例。 我尝试将 multiresourceread
Specflow 查询 - 我想使用 BeforeStep 将一行放入日志报告中,因此我需要一种方法来获取当前步骤的名称。 最佳答案 查看面向方面设计产品 - http://www.postsharp
在我的 Java 和 maven 项目中,我使用 Cucumber 进行 BDD 测试。 这是我使用的依赖项: io.cucumber cucumber-ja
我正在使用 Spring Batch 版本 2.2.4.RELEASE我尝试用有状态的 ItemReader、ItemProcessor 和 ItemWriter bean 编写一个简单的示例。 pu
我希望能够在达到时间阈值时停止作业。我正在考虑两种方法。首先是在 afterStep 中停止工作。但是,如果它在最后一步完成时,我不希望它具有已停止状态。因此,我将在 beforeStep 中停止它。
我正在尝试使用 Cucumber 测试 Multi-Tenancy PostgreSQL 应用程序。似乎每一步都重置数据库连接,因此需要在每一步设置schema_search_path。我知道钩子(H
我是一名优秀的程序员,十分优秀!