tasafo/bizusafo

View on GitHub
app/models/rating.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
class Rating < ActiveRecord::Base
  belongs_to :user
  belongs_to :rateable, :polymorphic => true

  scope :positive, -> { where(:positive => true) }
  scope :positives_for, -> (user, type) { where("user_id = ? and rateable_type = ? and positive = true", user.id, type)}
  scope :negative, -> { where(:positive => false) }
  scope :negatives_for, -> (user, type) { where("user_id = ? and rateable_type = ? and positive = false", user.id, type)}
  scope :has_votes_for, -> (user, type) { where("user_id = ? and rateable_type = ?", user.id, type)}
end