main
 1require 'rails_helper'
 2
 3describe VideosController do
 4  let(:user) { create(:user) }
 5
 6  before { http_login(user) }
 7
 8  describe "#index" do
 9    render_views
10
11    let!(:video) { create(:video) }
12
13    it 'returns all the videos' do
14      xhr :get, :index
15      expect(assigns(:videos)).to include(video)
16    end
17  end
18
19
20  context "#create" do
21    render_views
22
23    it "creates a new video" do
24      xhr :post, :create, video: { title: 'hello', uri: 'http://youtu.be/jghvdDB-t30?list=PLYuXlc3r66uFJErV5rYpZRcD8oDGtQlQc' }
25      expect(response).to be_success
26      json = JSON.parse(response.body)
27      expect(json['video']['id']).to_not be_nil
28      expect(json['video']['title']).to eql('hello')
29      expect(json['video']['description']).to be_nil
30      expect(json['video']['uri']).to eql("http://youtu.be/jghvdDB-t30?list=PLYuXlc3r66uFJErV5rYpZRcD8oDGtQlQc")
31    end
32  end
33
34  context "#update" do
35    render_views
36    let(:video) { create(:video, user: user) }
37
38    it 'updates the video' do
39      xhr :put, :update, id: video.id, video: { title: 'hello', description: 'blah', uri: 'http://youtu.be/blah' }
40      video.reload
41      expect(video.title).to eql('hello')
42      expect(video.description).to eql('blah')
43      expect(video.uri).to eql('http://youtu.be/blah')
44    end
45
46    it 'responds with the proper json' do
47      xhr :put, :update, id: video.id, video: { title: 'hello', description: 'blah', uri: 'http://youtu.be/blah' }
48      json = JSON.parse(response.body)
49      expect(json['video']['id']).to eql(video.id)
50      expect(json['video']['title']).to eql('hello')
51      expect(json['video']['description']).to eql('blah')
52      expect(json['video']['uri']).to eql("http://youtu.be/blah")
53    end
54  end
55
56  context "#destroy" do
57    let(:video) { create(:video, user: user) }
58
59    it 'deletes the video' do
60      xhr :delete, :destroy, id: video.id
61      expect(response).to be_success
62      expect(Video.find_by(id: video.id)).to be_nil
63    end
64  end
65end