Sha256: e5044539eda3d3aea9b386585b71060a56d065e98632a8e000e3e30a461eb5d1

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require 'spec_helper'

RSpec.describe JsonSchemaRails::SchemasController, type: :request do
  describe "GET #get" do
    context "with existing schema" do
      before { get "/schemas/posts/create#{format}" }
      let(:expected_schema) { YAML.load_file(Rails.root.join('app', 'schemas', 'posts', 'create.yml').to_s) }

      context "as json" do
        let(:format) { ".json" }
        it "returns the schema as json" do
          expect(response).to be_success
          expect(response.content_type).to eq :json
          expect(response.body).to eq expected_schema.to_json
        end
      end

      context "without format" do
        let(:format) { "" }
        it "returns the schema as json" do
          expect(response).to be_success
          expect(response.content_type).to eq :json
          expect(response.body).to eq expected_schema.to_json
        end
      end

      context "as yaml" do
        let(:format) { ".yaml" }
        it "returns the schema as yaml" do
          expect(response).to be_success
          expect(response.content_type).to eq :yaml
          expect(response.body).to eq expected_schema.to_yaml
        end
      end
    end

    context "with nonexisting schema" do
      subject { -> { get "/schemas/posts/nonexist.json" } }

      it "raises ActionController::RoutingError" do
        expect(subject).to raise_error ActionController::RoutingError
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
json_schema_rails-0.2.1 spec/integration/schemas_controller_spec.rb
json_schema_rails-0.2.0 spec/integration/schemas_controller_spec.rb