summaryrefslogtreecommitdiff
path: root/spec/controllers/api/v2/tutorials_controller_spec.rb
blob: c8d896ce5d182073540ec9fd5fe036a0d3c9cdff (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
require 'rails_helper'

module Api
  module V2
    describe TutorialsController do
      render_views
      describe "#index" do
        let!(:tutorial) { create(:tutorial) }

        before :each do
          xhr :get, :index
        end

        it 'loads all the tutorials' do
          expect(assigns(:tutorials)).to match_array([tutorial])
        end

        it 'responds with json' do
          json = JSON.parse(response.body)
          expect(json['tutorials'].count).to eql(1)
          expect(json['tutorials'][0]['id']).to eql(tutorial.id)
          expect(json['tutorials'][0]['heading']).to eql(tutorial.heading)
          expect(json['tutorials'][0]['description']).to eql(tutorial.description)
          expect(json['tutorials'][0]['url']).to eql(tutorial.url)
          expect(json['tutorials'][0]['submitter']).to eql(tutorial.user.id)
          expect(json['tutorials'][0]['imageUrl']).to eql(tutorial.image_url)
        end
      end

      describe "#show" do
        let!(:tutorial) { create(:tutorial) }

        it 'loads the single tutorial' do
          xhr :get, :show, id: tutorial.id
          expect(assigns(:tutorial)).to eql(tutorial)
        end
      end
    end
  end
end