This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Did some tests and scope black magic on the preferences.
- Loading branch information
1 parent
0af7946
commit 2833434
Showing
2 changed files
with
54 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |