Reputation: 5167
I am trying to write a simple test wherein I am checking whether priority is matching perfectly or not
my fixture code: 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"
My test code:
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
My internal_promotions.rb ( model )
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
The error message for the test is
InternalPromotionTest#test_it_should_show_top_banners_in_desc_priority_for_non_logged-in_users:
ActiveRecord::Fixture::FormatError: ActiveRecord::Fixture::FormatError
I am not able to understand the issue in the fixture as I have included all the mandatory fields in the fixture.
Upvotes: 1
Views: 91
Reputation: 5802
YAML's syntax is based on indentation using spaces. Make sure the attributes of an entry are indented properly, in your case the yml file should be formatted like this:
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"
Upvotes: 1