"Type" 在 RSpec 中用作引发异常的关键字,但在生产或开发环境中不使用
"Type" used as keyword raising an exception in RSpec but not in production or development environments
我正在开发一个大型网络应用程序,它使用 "type" 作为数据库中许多表的列。我知道单词 "type" 是 Ruby 中的关键字,不应用作列。但是,为什么我在本地服务器上仍然可以运行 web 应用程序正常运行,并且在生产环境中没有任何明显的问题?使用 "type" 作为列是否会在将来造成任何麻烦?
这种行为更加令人困惑,因为它确实导致我的 RSpec 功能测试在创建视频(资源之一)然后重定向到显示视图时失败。 (请注意,视频作为属性与几个以 "type" 作为列的表格相关联)。
这是引发的错误消息:
"The single-table inheritance mechanism failed to locate the subclass:
'reference'. This error is raised because the column
'type' is reserved for storing the class in case of
inheritance. Please rename this column if you didn't intend it to
be used for storing the inheritance class or overwrite
Tag.inheritance_column to use another column for that information."
(从 print page.body
生成并显示的 HTML 中提取)
为什么在我的测试规范中会引发此异常,而在开发或生产环境中却不会? (我负责整理测试规范,因此您的设备中有解决此错误的方法,这也会有所帮助!)
我的配置说明:
- 我正在使用 Ruby 2.1.2 和 rails 4.1.1
- 使用 capybara、factory girl 和 capybara-WebKit 作为网络驱动程序
事实证明,模式中有一个显式类型列,但它是从资源的子类中提取的。 RSpec 出现问题的原因是我试图定义类型列而不使其成为子类。解决方案是在将数据输入类型时使用子类表示法。在我的例子中,这意味着类型列中的字符串需要输入为:"Tags::Reference"
而不是 "reference"
.
我正在开发一个大型网络应用程序,它使用 "type" 作为数据库中许多表的列。我知道单词 "type" 是 Ruby 中的关键字,不应用作列。但是,为什么我在本地服务器上仍然可以运行 web 应用程序正常运行,并且在生产环境中没有任何明显的问题?使用 "type" 作为列是否会在将来造成任何麻烦?
这种行为更加令人困惑,因为它确实导致我的 RSpec 功能测试在创建视频(资源之一)然后重定向到显示视图时失败。 (请注意,视频作为属性与几个以 "type" 作为列的表格相关联)。
这是引发的错误消息:
"The single-table inheritance mechanism failed to locate the subclass:
'reference'. This error is raised because the column
'type' is reserved for storing the class in case of
inheritance. Please rename this column if you didn't intend it to
be used for storing the inheritance class or overwrite
Tag.inheritance_column to use another column for that information."
(从 print page.body
生成并显示的 HTML 中提取)
为什么在我的测试规范中会引发此异常,而在开发或生产环境中却不会? (我负责整理测试规范,因此您的设备中有解决此错误的方法,这也会有所帮助!)
我的配置说明:
- 我正在使用 Ruby 2.1.2 和 rails 4.1.1
- 使用 capybara、factory girl 和 capybara-WebKit 作为网络驱动程序
事实证明,模式中有一个显式类型列,但它是从资源的子类中提取的。 RSpec 出现问题的原因是我试图定义类型列而不使其成为子类。解决方案是在将数据输入类型时使用子类表示法。在我的例子中,这意味着类型列中的字符串需要输入为:"Tags::Reference"
而不是 "reference"
.