VRFS-3316 : Reviews/Ratings
* schemas for reviews and review_summaries * migrations * models * validations * initial specs to verify creation of reviews and review_summaries with a jamtrack and subsequently, various validations.
This commit is contained in:
parent
f13d14b62d
commit
91a8b4ab9c
|
|
@ -296,4 +296,5 @@ add_description_to_perf_samples.sql
|
|||
alter_genre_player_unique_constraint.sql
|
||||
musician_search.sql
|
||||
enhance_band_profile.sql
|
||||
alter_band_profile_rate_defaults.sql
|
||||
alter_band_profile_rate_defaults.sql
|
||||
reviews.sql
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
CREATE TABLE reviews (
|
||||
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
|
||||
user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
target_id VARCHAR(64) NOT NULL,
|
||||
target_type VARCHAR(32) NOT NULL,
|
||||
description VARCHAR(8000),
|
||||
rating INT NOT NULL,
|
||||
deleted_by_user_id VARCHAR(64) REFERENCES users(id) ON DELETE SET NULL,
|
||||
deleted_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NULL,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE review_summaries (
|
||||
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
|
||||
target_id VARCHAR(64) NOT NULL,
|
||||
target_type VARCHAR(32) NOT NULL,
|
||||
avg_rating FLOAT NOT NULL,
|
||||
wilson_score FLOAT NOT NULL,
|
||||
review_count INT NOT NULL,
|
||||
created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL,
|
||||
updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL
|
||||
);
|
||||
|
|
@ -111,6 +111,8 @@ require "jam_ruby/models/machine_fingerprint"
|
|||
require "jam_ruby/models/machine_extra"
|
||||
require "jam_ruby/models/fraud_alert"
|
||||
require "jam_ruby/models/fingerprint_whitelist"
|
||||
require "jam_ruby/models/review"
|
||||
require "jam_ruby/models/review_summary"
|
||||
require "jam_ruby/models/rsvp_request"
|
||||
require "jam_ruby/models/rsvp_slot"
|
||||
require "jam_ruby/models/rsvp_request_rsvp_slot"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
module JamRuby
|
||||
class Review < ActiveRecord::Base
|
||||
attr_accessible :target, :rating, :description, :user
|
||||
belongs_to :target, polymorphic: true
|
||||
belongs_to :user, foreign_key: 'user_id', class_name: "JamRuby::User"
|
||||
belongs_to :deleted_by_user, foreign_key: 'deleted_by_user_id', class_name: "JamRuby::User"
|
||||
|
||||
validates :rating, presence:true, numericality: {only_integer: true, minimum:1, maximum:5}
|
||||
validates :target, presence:true
|
||||
validates :user, presence:true
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
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
|
||||
end
|
||||
end
|
||||
|
|
@ -45,6 +45,9 @@ module JamRuby
|
|||
# authorizations (for facebook, etc -- omniauth)
|
||||
has_many :user_authorizations, :class_name => "JamRuby::UserAuthorization"
|
||||
|
||||
has_many :reviews, :class_name => "JamRuby::Review"
|
||||
has_many :review_summaries, :class_name => "JamRuby::ReviewSummary"
|
||||
|
||||
# calendars (for scheduling NOT in music_session)
|
||||
has_many :calendars, :class_name => "JamRuby::Calendar"
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Review do
|
||||
|
||||
shared_examples_for :review do |target, target_type|
|
||||
before(:each) do
|
||||
Review.delete_all
|
||||
User.delete_all
|
||||
@user = FactoryGirl.create(:user)
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
Review.delete_all
|
||||
User.delete_all
|
||||
end
|
||||
|
||||
context "validates review" do
|
||||
it "blank target" do
|
||||
review = Review.create()
|
||||
review.valid?.should be_false
|
||||
review.errors[:target].should == ["can't be blank"]
|
||||
end
|
||||
|
||||
it "no rating" do
|
||||
review = Review.create(target:target)
|
||||
review.valid?.should be_false
|
||||
review.errors[:rating].should include("can't be blank")
|
||||
review.errors[:rating].should include("is not a number")
|
||||
end
|
||||
|
||||
it "no user" do
|
||||
review = Review.create(target:target, rating:3)
|
||||
review.valid?.should be_false
|
||||
review.errors[:user].should include("can't be blank")
|
||||
end
|
||||
|
||||
it "complete" do
|
||||
review = Review.create(target:target, rating:3, user:@user)
|
||||
review.valid?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "validates review summary" do
|
||||
it "blank target" do
|
||||
review_summary = ReviewSummary.create()
|
||||
review_summary.valid?.should be_false
|
||||
review_summary.errors[:target].should == ["can't be blank"]
|
||||
end
|
||||
|
||||
it "no rating" do
|
||||
review_summary = ReviewSummary.create(target:target)
|
||||
review_summary.valid?.should be_false
|
||||
review_summary.errors[:target].should be_empty
|
||||
review_summary.errors[:avg_rating].should include("can't be blank")
|
||||
review_summary.errors[:avg_rating].should include("is not a number")
|
||||
end
|
||||
|
||||
it "no score" do
|
||||
review_summary = ReviewSummary.create(target:target, avg_rating:3.2)
|
||||
review_summary.valid?.should be_false
|
||||
review_summary.errors[:target].should be_empty
|
||||
review_summary.errors[:avg_rating].should be_empty
|
||||
review_summary.errors[:wilson_score].should include("can't be blank")
|
||||
review_summary.errors[:wilson_score].should include("is not a number")
|
||||
end
|
||||
|
||||
it "no count" do
|
||||
review_summary = ReviewSummary.create(target:target, avg_rating:3.2, wilson_score:0.95)
|
||||
review_summary.valid?.should be_false
|
||||
review_summary.errors[:review_count].should include("can't be blank")
|
||||
end
|
||||
|
||||
it "complete" do
|
||||
review_summary = ReviewSummary.create(target:target, avg_rating:3.2, wilson_score:0.95, review_count: 15)
|
||||
puts "complete:: #{review_summary.errors.inspect}"
|
||||
review_summary.valid?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "with a jamtrack" do
|
||||
@jam_track = FactoryGirl.create(:jam_track)
|
||||
it_behaves_like :review, @jam_track, "jam_track"
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Reference in New Issue