forked from AdaGold/media-ranker
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathwork_test.rb
66 lines (49 loc) · 1.38 KB
/
work_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require "test_helper"
# Add Relations Tests in Wave 2
# Add Fixtures Later
# New? Create?
describe Work do
it "can be instantiated and is valid when all required fields are present" do
# Arrange
@work = Work.new(title: "Long", category: "Movie")
# Act
created_work = @work.valid?
# Assert
expect(created_work).must_equal true
end
it "is invalid without title" do
# Arrange
@work = Work.new(category: "Movie")
#Act
created_work = @work.valid?
# Assert
expect(created_work).must_equal false
expect(@work.errors.messages).must_include :title
end
it "is invalid without category" do
# Arrange
@work = Work.new(title: "Long")
#Act
created_work = @work.valid?
# Assert
expect(created_work).must_equal false
expect(@work.errors.messages).must_include :category
end
it "returns a spotlight work" do
spotlit = Work.spotlight
expect(spotlit).must_be_instance_of Work
end
it "returns nil for spotlight when database is empty" do
Work.delete_all
expect(Work.count).must_equal 0
expect(Work.spotlight).must_be_nil
end
it "returns an array for top 10" do
top_books = Work.top_ten("book")
expect(top_books).must_be_instance_of Array
end
it "returns an array of 10 books for top 10 method" do
top_books = Work.top_ten("book")
expect(top_books.length).must_equal 10
end
end