Rails为测试环境加载不正确的数据库配置?(Rails loading incorrect database config for test env?)
有一个奇怪的问题...我的测试继续对我的开发数据库运行。 我在这里尝试了
test_helper.rb
中的test_helper.rb
:# this is the top of the file ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) binding.pry
并注意到3件事情:
ENV['RAILS_ENV']
/Rails.env
被正确设置为"test"
。Rails配置似乎加载了正确的值:
Rails.application.config.database_configuration[Rails.env] # => {"adapter"=>"postgis", # "encoding"=>"unicode", # "pool"=>5, # "username"=>"user", # "host"=>"localhost", # "database"=>"db_test"} <= CORRECT
...但ActiveRecord加载一个不正确的值:
ActiveRecord::Base.configurations[Rails.env] # => {"adapter"=>"postgis", # "encoding"=>"unicode", # "pool"=>5, # "username"=>"user", # "host"=>"localhost", # "port"=>5432, # "database"=>"db_development"} <= INCORRECT
另外,
ActiveRecord::Base.configurations[Rails.env]
返回一个port
密钥,而Rails.application.config.database_configuration[Rails.env]
不会。
为什么这些不同? 这是我的配置:
default: &default adapter: postgis encoding: unicode pool: 5 username: user host: localhost development: <<: *default database: db_development test: <<: *default database: db_test
我
grep
ed我的整个项目文件夹和config/database.yml
是我命名我的数据库的唯一地方,所以没有其他配置覆盖这个据我所知。我正在运行
rails 4.2.5
。帮帮我!
Have a weird issue... my tests keep running against my development database. I tried
binding.pry
intest_helper.rb
here:# this is the top of the file ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', __FILE__) binding.pry
And noticed 3 things:
ENV['RAILS_ENV']
/Rails.env
was set correctly to"test"
.Rails configuration seems to load the correct value:
Rails.application.config.database_configuration[Rails.env] # => {"adapter"=>"postgis", # "encoding"=>"unicode", # "pool"=>5, # "username"=>"user", # "host"=>"localhost", # "database"=>"db_test"} <= CORRECT
... but ActiveRecord loads an incorrect value:
ActiveRecord::Base.configurations[Rails.env] # => {"adapter"=>"postgis", # "encoding"=>"unicode", # "pool"=>5, # "username"=>"user", # "host"=>"localhost", # "port"=>5432, # "database"=>"db_development"} <= INCORRECT
Additionally,
ActiveRecord::Base.configurations[Rails.env]
returns aport
key whereasRails.application.config.database_configuration[Rails.env]
does not.
Why are these different? Here's my config:
default: &default adapter: postgis encoding: unicode pool: 5 username: user host: localhost development: <<: *default database: db_development test: <<: *default database: db_test
I
grep
ed my entire project folder andconfig/database.yml
is the only place I name my databases, so there's not another config overriding this one as far as I know.I'm running
rails 4.2.5
.Help!
原文:https://stackoverflow.com/questions/37469561
最满意答案
我设法让它工作,我90%确定可能是潜在的问题。 我原本以为设置主机视图,图形和绘图的顺序可能是问题,但结果却并非如此。
修订后的代码是:
protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); var view = NativeView; var graph = new CPTXYGraph { Title = "Pie Chart", }; var hostView = new CPTGraphHostingView(view.Bounds); view.AddSubview(hostView); var plot = new CPTPieChart { DataSource = new PiePlotDataSource(), PieRadius = hostView.Bounds.Size.Height / 4, }; graph.AddPlot(plot); hostView.HostedGraph = graph; }
我更改的是,在创建
CPTGraphHostingView()
,我将父View.Bounds
的View.Bounds
作为参数传递,然后将结果分配给变量hostView
,稍后将使用该变量。 我相信这是造成布局问题的原因。然后在设置饼图的
PieRadius
属性时使用PieRadius
。 如果未设置此属性,则不会显示饼图(仅显示一组X和Y轴)。就未调用的
PiePlotDataSource
方法而言,简单的清理和重建修复了该问题。 其NumberForPlot()
方法的更新代码如下:public override NSNumber NumberForPlot(CPTPlot plot, CPTPlotField forFieldEnum, uint index) { return forFieldEnum == CPTPlotField.BarLocation ? DummyData.Data[index] : index; }
请注意,我将
forFieldEnum
与CPTPlotField.BarLocation
进行比较,而不是CPTPlotField.PieChartWidth
。 这是因为我提出了一些断点并逐步完成了该方法,结果发现forFieldEnum
始终是CPTPlotField.BarLocation
。 我相信这是Xamarin CorePlot Compoenent的某种绑定错误。I have managed to get it working and I am 90% sure what may have been the underlying problem. I originally thought that the order of setting up the host view, graph and plot may have been the problem but it turns out it was not the case.
The revised code is:
protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); var view = NativeView; var graph = new CPTXYGraph { Title = "Pie Chart", }; var hostView = new CPTGraphHostingView(view.Bounds); view.AddSubview(hostView); var plot = new CPTPieChart { DataSource = new PiePlotDataSource(), PieRadius = hostView.Bounds.Size.Height / 4, }; graph.AddPlot(plot); hostView.HostedGraph = graph; }
What I have changed is that when creating a
CPTGraphHostingView()
, I pass in the parent'sView.Bounds
as a parameter and then assign the result to the variablehostView
, which will be used later. I believe this was what was causing the layout problems.The
hostView
is then used when setting thePieRadius
property of the pie chart. If this property isn't set, the pie chart does not show (only a set of X and Y axes are shown).In terms of the
PiePlotDataSource
methods not being called, a simple clean and rebuild fixed that problem. The updated code for itsNumberForPlot()
method is here:public override NSNumber NumberForPlot(CPTPlot plot, CPTPlotField forFieldEnum, uint index) { return forFieldEnum == CPTPlotField.BarLocation ? DummyData.Data[index] : index; }
Notice that I am comparing
forFieldEnum
toCPTPlotField.BarLocation
instead ofCPTPlotField.PieChartWidth
. This was because I put some break points in and stepped through the method, only to find thatforFieldEnum
was alwaysCPTPlotField.BarLocation
. I believe this is a binding error of some sort to the Xamarin CorePlot Compoenent.
相关问答
更多-
coreplot饼图数据标签会根据数据而中断(coreplot pie chart data labels get cut off depending on the data)[2024-01-03]
绘图数据标签由绘图区域剪切。 确保它足够大以包含饼图和任何标签。 Plot data labels are clipped by the plot area. Make sure it is big enough to contain the pie and any labels. -
确保使用有效的Android布局在MainActivity.OnCreate()设置默认的SetContentView() 。 Make sure to set a default SetContentView() in your MainActivity.OnCreate() with a valid Android layout.
-
在Xamarin中使用CorePlot的饼图显示白色空白屏幕(Pie Chart using CorePlot in Xamarin shows a white blank screen)[2022-02-23]
我设法让它工作,我90%确定可能是潜在的问题。 我原本以为设置主机视图,图形和绘图的顺序可能是问题,但结果却并非如此。 修订后的代码是: protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); var view = NativeView; var graph = new CPTXYGraph { Title = ... -
Core Plot现在对重叠标签没有任何作用。 您必须使用您对数据的了解并删除一些可能过于靠近的标签。 Core Plot doesn't do anything about overlapping labels right now. You have to use your knowledge of the data and remove some of the labels that might be too close together.
-
全白开放? 只是偶尔发生,那些东西就在那里,重新开放,Visual Studio总是让它回归我的生活。 但是,如果不是的话,你总是可以在你的用户文件夹中找到它下面的dtsx文件: C:\Users\
\Source\Workspaces\ 复制它,然后通过右键单击解决方案资源管理器中的SSIS Packages文件夹并将其添加到现有软件包中,然后将其拉回来,然后查看是否可以看到它。 All white on open? Just hap ... -
MPMoviePlayerController在启动之前显示空白屏幕?(MPMoviePlayerController shows blank white screen before launch?)[2023-07-21]
首先,你应该使用它来显示电影: [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController]; 其次,要更改moviePlayerViewController背景,您可以使用: moviePlayerViewController.view.backgroundColor = [UIColor blackColor]; 所以当视频启动时,背景颜色将变成黑色。 希望它的帮助... First, you should be ... -
由于x数据点相距一个单位,因此给xRange一个6的长度(加上一个绘图符号的位)就可以达到你想要的效果。 在您发布的代码中, xRange使用-scaleToFitPlots:设置-scaleToFitPlots:在扩展范围之前。 这使它适合所有绘图数据。 Since the x data points are one unit apart, giving the xRange a length of 6 (plus a bit for the plot symbols) will do what you ...
-
我假设你的意思是GUI在执行长时间运行时不会重绘。 (实际上不应该从Vista开始,但我离题了)。 如果您的长时间运行操作由多个步骤组成或紧密循环组成,那么您可以每隔一段时间向DoEvents撒一次呼叫,以使表单即使在工作时仍保持一定的响应。 另一个选择是将你的长期工作迁移到一个单独的线程中,但最后我在VB6中看起来并不是微不足道的,也不是简单的可能。 I assume you mean that the GUI won't redraw itself when executing a long-runni ...
-
似乎更新已阻止
相关文章
更多- solr config 部分注解
- Storm Config
- HTML5 Web SQL Database 数据库
- data-config
- springboot配置内存数据库测试环境
- Hadoop 0.21如何运行单个test case
- Solr安装异常:SolrException: Error loading class 'solr.VelocityResponseWriter'
- myEclipse8.5 New DataBase Connection Driver时出错
- 在main方法中开启线程与@Test中开启线程
- Rails设置环境变量
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。