草庐IT

update_test

全部标签

关于Document mapping type name can‘t start with ‘_‘, found: [_update]

在修改elasticsearch时,用_update进行局部修改,修改失败,报错{    "error": {        "root_cause": [            {                "type": "invalid_type_name_exception",                "reason": "Document mapping type name can't start with '_', found: [_update]"            }        ],        "type": "invalid_type_name_exce

自动化update_post_meta

因此,我一直在研究此旧代码,并且正在尝试改进它。我有这个代码,从帖子中节省了许多自定义字段。if(isset($_REQUEST['unidade-dir1-cargo'])){update_post_meta($post_id,'unidade-dir1-cargo',sanitize_text_field($_POST['unidade-dir1-cargo']));update_post_meta($post_id,'unidade-dir1-nome',sanitize_text_field($_POST['unidade-dir1-nome']));update_post_meta(

ruby-on-rails - rails 中的 create_or_update 方法

ifClassName.exists?(["id=?",self.id])object=ClassName.find_by_name(self.name)object.update_attributes!(:street_address=>self.street_address,:city_name=>self.city_name,:name=>self.org_unit_name,:state_prov_id=>self.state_prov_id,:zip_code=>self.zip_code)elseClassName.create!:street_address=>self.

ruby - 有没有办法在 Test::Unit 中撤消 any_instance 的摩卡 stub

很像thisquestion,我也在使用RyanBates的nifty_scaffold。它具有使用Mocha的any_instance的理想方面。在Controller后面的模型对象中强制进入“无效”状态的方法。与我链接到的问题不同,我没有使用RSpec,而是使用Test::Unit。这意味着那里的两个以RSpec为中心的解决方案对我不起作用。是否有通用的(即:与Test::Unit一起使用)删除any_instancestub的方法?我认为它导致我的测试出现错误,我想验证这一点。 最佳答案 碰巧,Mocha0.10.0允许uns

ruby - 在 Ruby 的 Test::Unit::TestCase 中,如何覆盖初始化方法?

我正在为Test::Unit苦苦挣扎。当我想到单元测试时,我会想到每个文件一个简单的测试。但在Ruby的框架中,我必须改写:classMyTest但是每次调用test_*方法时都会运行设置和拆卸。这正是我不想要的。相反,我想要一个只为整个类(class)运行一次的设置方法。但是我似乎无法在不破坏TestCase的初始化的情况下编写自己的initialize()。这可能吗?还是我让这件事变得无可救药地复杂了? 最佳答案 如HalFulton的书“TheRubyWay”中所述。他覆盖了Test::Unit的self.suite方法,该方

ruby-on-rails - Rails 测试找不到 test_helper

我试图通过ruby​​test/unit/mytest.rb运行单独的测试,但我总是收到“没有这样的文件要加载-test_helper”的错误。Google提出了一些建议,但没有一个对我有用。我在Ubuntu10.10上运行Rails3.0、Ruby1.9.2(通过RVM)这是我到目前为止所做的尝试-非常感谢任何建议将“requiretest_helper”更改为“requireFile.dirname(FILE)+“/../test_helper””在test/unit/mytest_test.rb中。它带回“没有要加载的文件--test/unit/../test_helper”尝试

ruby-on-rails - minitest、test::unit 和 rails

我在某处读到“minitest”是“ruby1.9.2+的新测试::单元”。但ruby​​1.9.3似乎包含两者test::unit和minitest,是真的吗?在默认的rails测试中,如Railstestingguide中所述....诸如ActiveSupport::TestCase、ActionController::TestCase之类的东西,是使用Test::Unit还是Minitest?在Rails指南中,它显示了带有如下定义的测试的示例:test"shouldshowpost"doget:show,:id=>@post.idassert_response:successe

ruby-on-rails - 将 bool 值传递给 update_attributes 的问题

我有以下模型:classGuestCateringtruevalidates:order_number,:presence=>truevalidates:orderable,:presence=>trueend但是当我尝试使用以下代码更新现有的GuestCatering时:guest_catering.update_attributes(:orderable=>false)guestcatering变量是一个有效的GuestCatering对象。guest_catering对象更新后出现错误,像这样:nil}>但是当我传递一个orderable=>true时,一切都很好,没有错误。这里

ruby-on-rails - rails : Testing named scopes with RSpec

我是测试Rails网络应用程序和RSpec的新手。我使用遗留代码并需要添加测试。那么使用RSpec测试查找器和命名范围的最佳方法是什么?我在Google中找到了一些方法,但它们并不理想。例如:http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in-ruby-on-railsit"excludesusersthatarenotactive"do@user=Factory(:user,:active=>false)User.active.should_notinclude(@user)e

ruby - bundler 能告诉我 Gemfile 中的哪些 gems 有更新的版本吗(例如 bundle update 的试运行)

有没有办法运行bundleupdate在假装模式下,类似于Rails生成器的-p(假装)标志或cap的-n(试运行)标志?我在想像这样的事情:$>bundleupdate-pFetchingsourceindexforhttp://rubygems.org/Thefollowinggemshaveupdatedversions:...listofgems... 最佳答案 Bundler1.1引入了一个新的“过时”功能,这正是我一直在寻找的。PatShaughnessy很棒write-up关于新功能。用他的话说,bundleoutda