繁体   English   中英

在Michael Hartl(出色的)Rails教程的第7章,练习2

[英]On Chapter 7, Excercise 2, of Michael Hartl's (excellent) Rails Tutorial

练习2:他建议的用于检查与表单注册相关的错误消息的模板是下面的最后两个assert_selects:

require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest

  test "invalid signup information" do
    get signup_path
    assert_no_difference 'User.count' do
      post users_path, user: { name:  "",
                               email: "user@invalid",
                               password:              "foo",
                               password_confirmation: "bar" }
    end
    assert_template 'users/new'
    assert_select 'div#<CSS id for error explanation>'
    assert_select 'div.<CSS class for field with error>'
  end

我无法弄清楚需要用什么来代替他在括号内的内容。 自定义CSS的表单部分如下所示:

#error_explanation {
  color: red;
  ul {
    color: red;
    margin: 0 0 30px 0;
  }
}

.field_with_errors {
  @extend .has-error;
  .form-control {
    color: $state-danger-text;
  }
}

按照他的指示添加它们

  assert_select 'div#<CSS id for error explanation>'
  assert_select 'div.<CSS class for field with error>'

将会

  assert_select 'div#error_explanation'
  assert_select 'div.field_with_errors'
assert_select 'div#error_explanation'
assert_select 'div.field_with_errors'

本教程希望我用上述代码替换示例。 我不明白,但终于找到了答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM