【问题标题】:NameError: undefined local variable or method `current_protocol_version' for #<App:0x007fcc0cb32010>NameError: #<App:0x007fcc0cb32010> 的未定义局部变量或方法`current_protocol_version'
【发布时间】:2014-03-21 03:47:41
【问题描述】:

我的单元测试有一些问题。

当我运行我的单元测试时,我遇到了一些问题:

  1. timestamp

  2. undefined loacal variable or method

========== 1 =============

当我运行单元测试时,timpestampdate field 出现错误。它说:

  -      "date"=>"2011-11-05T22:03:54+09:00",
  ?                           ^        ^
  +      "date"=>"2011-11-05T20:03:54+07:00",
  ?                           ^        ^
         "finished"=>1,
         "position"=>"",
         "timestamp"=>"2014-03-21T09:43:05+07:00",
         "type"=>"new type"},
       "content_id2"=>
        {"bookmark_suffix_max"=>3,
         "bookmarks"=>
          [{"date"=>"", "label"=>"", "name"=>"", "position"=>""},
           {"date"=>"", "label"=>"", "name"=>"", "position"=>""}],
  -      "date"=>"2011-11-04T22:03:54+09:00",
  ?                           ^        ^
  +      "date"=>"2011-11-04T20:03:54+07:00",
  ?                           ^        ^
         "finished"=>1,
         "position"=>"",
  -      "timestamp"=>"2011-11-04T22:03:54+09:00",
  ?                                ^        ^
  +      "timestamp"=>"2011-11-04T20:03:54+07:00",
  ?                                ^        ^
         "type"=>""}},
     "timestamp"=>"2014-03-21T09:43:05+07:00"}
test_merge1_with_conflict_1:_should_update_bookmark_info_with_client's_'date'_field(AccountBookmarkInfoTest)

是因为time_zone吗?或者是其他东西。我已经用+ 修复了-,但我仍然有同样的错误。

============ 2 ===============

Error: test_ContentsJsonCache.key_for_params_should_depend_all_query_parameters(ContentsJsonCacheTest)
  NameError: undefined local variable or method `current_protocol_version' for #<App:0x007fcc0a3f8800>
app/models/app.rb:166:in `implements_purchase_bonus_feature?'
app/models/app.rb:174:in `include_purchase_bonuses_in_contents_json?'
app/models/contents_json_cache.rb:21:in `key_for_params'
test/unit/contents_json_cache_test.rb:22:in `block in <class:ContentsJsonCacheTest>'

current_local_version 在:

**Controller. define : app.current_protocol_version

**Models. define :

    attr_accessible :current_protocol_version,
                    :name,
                    ....
**test->functional->app.controller_test.rb

    app = apps :one
    app.current_protocol_version = '1.1.9'
    assert_false app.implements_account_feature?

【问题讨论】:

  • 请出示您的测试代码。
  • 如果您发布您的代码
  • 对不起,我不敢这样做..
  • 问题已经解决了,把attr_accessible改成attr_accessor

标签: ruby-on-rails ruby unit-testing timestamp nameerror


【解决方案1】:

要修复时间戳错误,请在您的代码中执行此操作。

如果你有如下代码:

之前。

time.parse var

之后

time.zone.parse var

【讨论】:

    猜你喜欢
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多