关于迈克尔哈特尔(优秀)Rails教程的第7章练习2

时间:2014-11-21 05:06:01

标签: css ruby-on-rails

练习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;
  }
}

2 个答案:

答案 0 :(得分:2)

在他发出指示时添加它们

  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'

答案 1 :(得分:0)

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

教程要我用上面的代码替换这个例子。我不明白,但终于找到了答案。