小编Dav*_*d C的帖子

在功能测试方法中运行循环是否可以?

在概念上可以在测试方法中运行循环吗?

我想在控制器中测试一系列参数值,以确定不同的输入是否返回正确的值.

  test "logged in user - add something - 0 qty" do
    @app = Factory.create(:app)

    (0..5).each do |t|
      @qty = t
      login(:user)
      get :add. :id => @app.id, :qty => @qty
      assert_nil(flash[:error])
      assert_response :redirect
      assert_redirect_to :controller => :apps, :action => :show, :id => @app.id
      if @qty = 0 
        assert_equal(Invite.all.count, @qty + 1)
      else 
        assert_something .........
    end
  end
Run Code Online (Sandbox Code Playgroud)

这样的事情.

ruby unit-testing ruby-on-rails functional-testing

3
推荐指数
1
解决办法
999
查看次数

heroku如何在其命令行应用程序中存储其身份验证?

我假设当您第一次安装heroku gem时,系统会提示您输入您的用户名/密码,它会将该用户名/密码发送到其服务器进行验证.

然后,heroku(或任何其他命令行应用程序)如何安全地在文件系统上存储该经过验证的令牌,然后在运行其他命令(如"heroku create")进行验证时将其一起传输?

我在这里使用heroku作为一个例子,因为它是我能想到的唯一一个我现在想做的事情.

ruby security authentication command-line design-patterns

3
推荐指数
1
解决办法
1645
查看次数

在rails中进行异常处理是否有任何良好的最佳实践?

我目前正在使用Rails 2.3.5,我在我的应用程序中尝试尽可能多地使用rescue_from exception.

我的ApplicationController救援现在看起来像这样:

  rescue_from Acl9::AccessDenied, :with => :access_denied
  rescue_from Exceptions::NotPartOfGroup, :with => :not_part_of_group
  rescue_from Exceptions::SomethingWentWrong, :with => :something_went_wrong
  rescue_from ActiveRecord::RecordNotFound, :with => :something_went_wrong
  rescue_from ActionController::UnknownAction, :with => :something_went_wrong
  rescue_from ActionController::UnknownController, :with => :something_went_wrong
  rescue_from ActionController::RoutingError, :with => :something_went_wrong
Run Code Online (Sandbox Code Playgroud)

我还希望能够捕获上面没有列出的任何例外情况.有没有推荐的方式我应该写我的救援?

谢谢

ruby exception-handling ruby-on-rails

2
推荐指数
1
解决办法
2448
查看次数

查找属于当月(或其他月份)的条目

我有一个模型(费用),其中包含"成本"等字段.

我想迭代我的所有费用,找到属于特定月份的所有条目的总和.

有没有办法直接在rails中做到这一点?

Expense.find(:all,:conditions => .....)

ruby activerecord ruby-on-rails

0
推荐指数
1
解决办法
1363
查看次数

还有另一个位置Rails正在寻找我的irbrc配置吗?

我的.irbrc位于我的〜/ .irbrc.

我注意到当我在Rails 3.x应用程序上运行'rails console'时,它说它正在寻找一个宝石.

Gems missing: no such file to load -- ap
Run Code Online (Sandbox Code Playgroud)

但如果我在rails 2.x应用程序上运行'irb'或'script/console',一切都会正常运行.

是否有另一个位置Rails 3寻找irbrc配置?

我不确定这些信息是否适用,但我在我的盒子上运行RVM(Ubuntu)

ruby ruby-on-rails irb ruby-on-rails-3

0
推荐指数
1
解决办法
924
查看次数