Skip to content

Instantly share code, notes, and snippets.

@josescasanova
Created March 18, 2014 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josescasanova/9619628 to your computer and use it in GitHub Desktop.
Save josescasanova/9619628 to your computer and use it in GitHub Desktop.
Queue_item tests
.............F...F........................................
Failures:
1) QueueItem#category_name returns the category's name of the video
Failure/Error: expect(queue_item.category_name).to eq("comedies")
expected: "comedies"
got: "Category"
(compared using ==)
# ./spec/models/queue_item_spec.rb:38:in `block (3 levels) in <top (required)>'
2) QueueItem#category returns the category of the video
Failure/Error: expect(queue_item.category).to eq(category)
expected: #<Category id: 1, name: "comedies", created_at: "2014-03-18 13:03:24", updated_at: "2014-03-18 13:03:24">
got: #<ActiveRecord::Associations::CollectionProxy [#<Category id: 1, name: "comedies", created_at: "2014-03-18 13:03:24", updated_at: "2014-03-18 13:03:24">]>
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-#<Category id: 1, name: "comedies", created_at: "2014-03-18 13:03:24", updated_at: "2014-03-18 13:03:24">
+[#<Category id: 1, name: "comedies", created_at: "2014-03-18 13:03:24", updated_at: "2014-03-18 13:03:24">]
# ./spec/models/queue_item_spec.rb:48:in `block (3 levels) in <top (required)>'
Finished in 3.06 seconds
58 examples, 2 failures
Failed examples:
rspec ./spec/models/queue_item_spec.rb:33 # QueueItem#category_name returns the category's name of the video
rspec ./spec/models/queue_item_spec.rb:43 # QueueItem#category returns the category of the video
class QueueItem < ActiveRecord::Base
belongs_to :user
belongs_to :video
def video_title
video.title
end
def rating
review = Review.where(user_id: user.id, video_id: video.id).first
review.rating if review
end
def category_name
video.categories.name
end
def category
video.categories
end
end
require 'spec_helper'
describe QueueItem do
it { should belong_to(:user) }
it { should belong_to(:video) }
describe "#video_title" do
it "returns the title of the associated video" do
video = Fabricate(:video, title: 'Monk')
queue_item = Fabricate(:queue_item, video: video)
expect(queue_item.video_title).to eq('Monk')
end
end
describe "#rating" do
it "returns the rating from the review when the review is present" do
video = Fabricate(:video)
user = Fabricate(:user)
review = Fabricate(:review, user: user, video: video, rating: 4)
queue_item = Fabricate(:queue_item, user: user, video: video)
expect(queue_item.rating).to eq(4)
end
it "returns nil when the review is not present" do
video = Fabricate(:video)
user = Fabricate(:user)
queue_item = Fabricate(:queue_item, user: user, video: video)
expect(queue_item.rating).to eq(nil)
end
end
describe "#category_name" do
it "returns the category's name of the video" do
category = Fabricate(:category, name: "comedies")
video = Fabricate(:video)
video.categories << category
queue_item = Fabricate(:queue_item, video: video)
expect(queue_item.category_name).to eq("comedies")
end
end
describe "#category" do
it "returns the category of the video" do
category = Fabricate(:category, name: "comedies")
video = Fabricate(:video)
video.categories << category
queue_item = Fabricate(:queue_item, video: video)
expect(queue_item.category).to eq(category)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment