blob: a227c175529e883b546fa7e3e6f0778cbd77bf09 (
plain)
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
|
require 'rails_helper'
describe SearchController do
describe "GET 'index'" do
context "when no search query is given" do
before { get :index }
it "should redirect you to the home page" do
expect(response).to redirect_to(root_url)
end
end
context "when a valid search query is given" do
let!(:user) { create(:user, :name => 'cake') }
let!(:bob) { create(:user, :name => 'bob') }
let!(:cake) { create(:creation, :name => 'cake') }
let!(:donut) { create(:creation, :name => 'donut') }
let!(:tutorial) { create(:tutorial, :description => 'cake') }
let!(:other_tutorial) { create(:tutorial, :description => 'donut') }
before { get :index, params: { q: 'cake' } }
it "returns a successful response" do
expect(response).to be_success
end
it "returns all creations that have a matching name" do
expect(assigns(:creations)).to include(cake)
end
it "does not include cakes that do not match" do
expect(assigns(:creations)).to_not include(donut)
end
it "returns all makers that match" do
expect(assigns(:members)).to include(user)
end
it "does not include makers with names that do not match" do
expect(assigns(:members)).to_not include(bob)
end
it "returns all tutorials that match" do
expect(assigns(:tutorials)).to include(tutorial)
end
it "does not return tutorials that do not match" do
expect(assigns(:tutorials)).to_not include(other_tutorial)
end
end
end
end
|