我正在尝试编写一个简单的测试,其中我正在检查优先级是否完美匹配
我的灯具代码:internal_promotions.yml
one:
title: "Testing"
subtitle: "is and is *bold*"
link_text: "Google"
link_url: "www.google.com"
status: "ACTIVE"
logo_file_name: "tiger-1511153910.jpg"
logo_content_type: "image/jpeg"
logo_file_size: 88983
logo_updated_at: "2017-11-20 04:58:30"
created_at: "2017-11-20 04:57:14"
updated_at: "2017-11-20 05:24:44"
banner_type: "both"
priority: 3
border_color: "FFFFFF"
background_color: "FFFFFF"
doctor_ids: "11722"
is_home: true
is_news: false
is_journal: false
is_quiz: false
is_survey: false
is_logged_in: true
is_not_logged_in: true
is_middle: true
is_bottom: true
valid_till: "2017-11-21 18:30:00"
我的测试代码:
class InternalPromotionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "it should show top banners in desc priority for non_logged-in users" do
assert_equal 3, internal_promotions(:one).priority
end
我的internal_promotions.rb(模特)
class InternalPromotion < ActiveRecord::Base
STATUS_LIST = ["ACTIVE", "INACTIVE"]
BANNER_TYPE = ["top", "inline", "both"]
validates_inclusion_of :status, in: STATUS_LIST, message: ' is not valid'
validates_inclusion_of :banner_type, in: BANNER_TYPE, message: 'is not valid'
has_and_belongs_to_many :specialties
validates_presence_of :title, :subtitle, :link_text, :link_url, :status, :banner_type
has_attached_file :logo,
styles: {small: "x80>"},
storage: :s3,
path: 'content/:style/:filename',
s3_credentials: 'config/s3.yml'
validates_attachment_content_type :logo, content_type: /\Aimage\/.*\z/
validates_length_of :title, maximum: 30
validates_length_of :subtitle, maximum: 20
validates_length_of :border_color, is: 6
validates_length_of :background_color, is: 6
before_post_process :rename_logo
测试的错误消息是
InternalPromotionTest#test_it_should_show_top_banners_in_desc_priority_for_non_logged-in_users:
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
我无法理解灯具中的问题,因为我已经在灯具中包含了所有必填字段。
答案 0 :(得分:1)
YAML的语法基于使用空格的缩进。确保条目的属性正确缩进,在您的情况下,yml文件的格式应如下所示:
one:
title: "Testing"
subtitle: "is and is *bold*"
link_text: "Google"
link_url: "www.google.com"
status: "ACTIVE"
logo_file_name: "tiger-1511153910.jpg"
logo_content_type: "image/jpeg"
logo_file_size: 88983
logo_updated_at: "2017-11-20 04:58:30"
created_at: "2017-11-20 04:57:14"
updated_at: "2017-11-20 05:24:44"
banner_type: "both"
priority: 3
border_color: "FFFFFF"
background_color: "FFFFFF"
doctor_ids: "11722"
is_home: true
is_news: false
is_journal: false
is_quiz: false
is_survey: false
is_logged_in: true
is_not_logged_in: true
is_middle: true
is_bottom: true
valid_till: "2017-11-21 18:30:00"