diff --git a/app/models/preference.rb b/app/models/preference.rb index fe78342..fd2ea90 100644 --- a/app/models/preference.rb +++ b/app/models/preference.rb @@ -1,13 +1,17 @@ -class Preference < ActiveRecord::Base - attr_accessible :like, :user_id, :restaurant_id - belongs_to :user - belongs_to :restaurant - - def self.likes - #self.all.map { |pref| pref.likes } - end - - def self.evaluate - # stuff - end -end +class Preference < ActiveRecord::Base + attr_accessible :like, :dislikes, :user_id, :restaurant_id + belongs_to :user + belongs_to :restaurant + + scope :likes, where(like: true) + scope :dislikes, where(like: false) + + #def self.likes + #self.find_all_by_like(true).map { |pref| pref.like } + # where(:like => true) + #end + + def self.evaluate + # stuff + end +end diff --git a/spec/models/preference_spec.rb b/spec/models/preference_spec.rb index 31011d2..4631d96 100644 --- a/spec/models/preference_spec.rb +++ b/spec/models/preference_spec.rb @@ -1,32 +1,37 @@ -require "spec_helper" - -describe Preference do - before(:each) do - @pref = Preference.new - end - - describe "Associations" do - it "belongs_to a Restaurant" do - @pref.restaurant = Restaurant.new - @pref.should have(:no).errors_on(:restaraunt) - end - - it "belongs_to a User" do - @pref.user = User.new - @pref.should have(:no).errors_on(:user) - end - end - - describe "Like Method" do - it "Likes should default to false" do - @pref.like.should be_false - end - - it "Likes should" do - Preference.likes.all? { |p| p.like == true }.should be_true - end - - - - end -end +require "spec_helper" + +describe Preference do + before(:each) do + @pref = Preference.new + end + + describe "Associations" do + it "belongs_to a Restaurant" do + @pref.restaurant = Restaurant.new + @pref.should have(:no).errors_on(:restaraunt) + end + + it "belongs_to a User" do + @pref.user = User.new + @pref.should have(:no).errors_on(:user) + end + end + + describe "Like/Dislike Method" do + it "Like should default to false" do + @pref.like.should be_false + end + + it "Likes method should all return like as true" do + Preference.likes.all? { |p| p.like == true }.should be_true + end + + it "Dislikes method should all return like as false" do + Preference.dislikes.all? { |p| p.like == true }.should be_false + end + + it "The count should equal the likes + dislikes" do + Preference.count.should == Preference.likes.count + Preference.dislikes.count + end + end +end