Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Did some tests and scope black magic on the preferences.
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinmillan committed Jan 27, 2013
1 parent 0af7946 commit 2833434
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 45 deletions.
30 changes: 17 additions & 13 deletions app/models/preference.rb
Original file line number Diff line number Diff line change
@@ -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
69 changes: 37 additions & 32 deletions spec/models/preference_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2833434

Please sign in to comment.