草庐IT

check_raise

全部标签

ruby-on-rails - rails : check if the model was really saved in after_save

ActiveRecord用于在每次调用保存方法时调用after_save回调,即使模型没有更改并且没有生成插入/更新查询也是如此。这实际上是默认行为。在大多数情况下这没问题。但是一些after_save回调对模型是否实际保存的事情很敏感。有没有办法确定模型是否实际保存在after_save中?我正在运行以下测试代码:classStage 最佳答案 ActiveRecordusetocallafter_savecallbackeachtimesavemethodiscalledevenifthemodelwasnotchangedan

ruby - 为什么 Minitest 的 assert_raises 在这种情况下没有按预期工作?

我正在尝试使用ActionControllerbugreporttemplate解决Rails中的一个奇怪行为.为了记录,这是模板中的Controller:classTestController我已经为缺失的Action添加了一条路线:routes.drawdoget'/'=>'test#index'get'/missing'=>'test#missing'end并且我试图断言AbstractController::ActionNotFound在遵循该路线时被引发:classBugTest预期行为:绿色测试。实际行为:#Runningtests:D,[2014-04-24T09:17:

ruby-on-rails - 安装 active admin 时 activeadmin.git (at master) is not yet checked out 错误

Activeadmingem已添加到我的rails项目中,但每次我尝试安装railsgactive_admin:install时,我都会收到类似的错误git://github.com/activeadmin/activeadmin.git(atmaster)isnotyetcheckedout.Runbundleinstallfirst.我肯定在运行“railsgactive_admin:install”之前运行了bundle。运行“bundleshow”后,我看到我已将“*activeadmin(1.0.0.pre3f916d6)”添加到我的项目中,但不断收到此错误消息。我的gem文

ruby - rspec: raise_error 用法来匹配错误信息

我使用raise(ConfigurationError.new(msg))引发错误我试着用rspec测试一下:expect{Base.configuration.username}.toraise_error(ConfigurationError,message)但这行不通。我该如何测试呢?目标是匹配message。 最佳答案 您可以使用正则表达式匹配错误消息:it{expect{Foo.bar}.toraise_error(NoMethodError,/private/)}这将检查NoMethodError是否由privateme

c - ruby的rb_raise如何停止调用它的c函数的执行?

如果你在C中将一个ruby​​方法写成一个使用rb_raise的函数,调用后的函数部分将不会被执行,程序将停止,你会认为rb_raise使用了exit()。但是如果你在ruby​​中拯救异常,比如:beginmethod_that_raises_an_exceptionrescueendputs'Youwilstillgethere.'ruby代码将继续,但您的函数将停止执行。rb_raise如何实现这一目标? 最佳答案 推测它使用了setjmp(在调用方法之前)和longjmp(在rb_raise中)。

ruby-on-rails - Rspec raise_error 测试失败,即使该方法引发错误

我的测试是这样的:它“在通过非订阅或试用成员(member)资格时确实返回错误”期望(helper.description_for_subscription(recurring_plan)).toraise_error(RuntimeError)结束我的方法返回这个:失败“未知订阅模型类型!”然而Rspec返回此失败消息:失败/错误:expect(helper.description_for_subscription(recurring_plan)).toraise_error(RuntimeError)运行时错误:未知的订阅模型类型!这是怎么回事?? 最佳

ruby-on-rails - "554 Please activate your Mailgun account. Check your inbox or log in to your control panel to resend the activation email."错误 Ruby on Rails

我正在使用RubyonRails构建网络应用程序。我正在使用Mailgun作为这个应用程序的邮件程序。当我使用Facebook注册时它工作正常但是当我尝试使用电子邮件和密码注册时,我不断收到此错误“554请激活您的Mailgun帐户。检查您的收件箱或登录到您的控制面板以重新发送激活电子邮件。“我已经在mailgun仪表板中将eamil授权给授权收件人。这是我的代码:Registrations_controller.rbclassRegistrationsControllerconfig/environments/development.rbRails.application.confi

ruby-on-rails - Rails action Mailer raise_delivery_errors,它是如何工作的?如何检测反弹?

我有一个发送大量邮件的Rails4.2.0应用程序,它是一个在线学习平台。目前我遇到退回问题,很多邮件因为邮件地址无效而退回。一种方法是手动解决问题,开始从数据库中删除它们。但这不合适,因为大约有10000个用户注册。现在我的问题是什么config.action_mailer.raise_delivery_errors=true是吗?它有什么作用?我如何从中得到回应?mail()方法是否有一个返回值,我可以在其中查看邮件是否已发送?是否有方法或最佳实践来检测邮件是否已送达? 最佳答案 如果设置为false,邮件将静默捕获并忽略通过尝

ruby - Rails 'raise StandardError.new' 和 'raise StandardError' 之间的区别

为了处理Rails异常,我看到人们使用“raiseSomeException.new”或“raiseSomeException”,有什么区别?说如果我有课classUnableToCreateShipments我可以两者都做吗?raiseUnableToCreateShipmentsraiseUnableToCreateShipments.new或者用消息raiseUnableToCreateShipments,'myerrormessage'raiseUnableToCreateShipments.new('myerrormessage') 最佳答案

ruby-on-rails - Mongoid::Errors::DocumentNotFound raise_not_found_error

*在底部更新*当寻找不存在的用户时,我得到:Mongoid::Errors::DocumentNotFoundinUsersController#showProblem:Document(s)notfoundforclassUserwithid(s)22.Summary:WhencallingUser.findwithanidorarrayofids,eachparametermustmatchadocumentinthedatabaseorthiserrorwillberaised.Thesearchwasfortheid(s):22...(1total)andthefollowin