community_rating_test.rb 671 Bytes
require 'test_helper'

class CommunityRatingTest < ActiveSupport::TestCase
  test "The value must be between 1 and 5" do
    cr1 = CommunityRating.new :value => -1
    cr2 = CommunityRating.new :value => 6

    assert_equal false, cr1.valid?
    assert_equal false, cr2.valid?

    assert_equal true, cr1.errors[:value].include?("must be between 1 and 5")
    assert_equal true, cr2.errors[:value].include?("must be between 1 and 5")

    cr1.value = 1
    cr1.valid?

    cr2.value = 5
    cr2.valid?

    assert_equal false, cr1.errors[:value].include?("must be between 1 and 5")
    assert_equal false, cr2.errors[:value].include?("must be between 1 and 5")
  end
end