VRFS-3316 : Review summary uniqueness validation and spec.
This commit is contained in:
parent
0beb386bea
commit
4b52d97a64
|
|
@ -2,11 +2,11 @@ module JamRuby
|
|||
class ReviewSummary < ActiveRecord::Base
|
||||
attr_accessible :target, :target_type, :avg_rating, :wilson_score, :review_count
|
||||
belongs_to :target, polymorphic: true
|
||||
belongs_to :user, foreign_key: 'user_id', class_name: "JamRuby::User"
|
||||
|
||||
|
||||
validates :avg_rating, presence:true, numericality: true
|
||||
validates :review_count, presence:true, numericality: {only_integer: true}
|
||||
validates :wilson_score, presence:true, numericality: {greater_than:0, less_than:1}
|
||||
validates :target, presence:true
|
||||
validates :target_id, uniqueness:true
|
||||
end
|
||||
end
|
||||
|
|
@ -83,6 +83,14 @@ describe Review do
|
|||
puts "complete:: #{review_summary.errors.inspect}"
|
||||
review_summary.valid?.should be_true
|
||||
end
|
||||
|
||||
it "unique" do
|
||||
review = ReviewSummary.create(target:target, avg_rating:3, wilson_score:0.82, review_count:14)
|
||||
review.valid?.should be_true
|
||||
|
||||
review2 = ReviewSummary.create(target:target, avg_rating:3.22, wilson_score:0.91, review_count:12)
|
||||
review2.valid?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue