summaryrefslogtreecommitdiff
path: root/spec/controllers/api/v2/tutorials_controller_spec.rb
blob: 65954243ba0c77092f0f2bdfee02abb96d67d80a (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
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)
          json_tutorial = json["tutorials"][0]
          expect(json_tutorial["id"]).to eql(tutorial.id)
          expect(json_tutorial["heading"]).to eql(tutorial.heading)
          expect(json_tutorial["description"]).to eql(tutorial.description)
          expect(json_tutorial["url"]).to eql(tutorial.url)
          expect(json_tutorial["submitter"]).to eql(tutorial.user.id)
          expect(json_tutorial["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