Sha256: f795ef78cbfaed83f86512b47b746781144adf6d02c865390bf61967291f5f25

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require "rails_helper"

RSpec.describe "<%= class_name.pluralize %> API" do
  let(:parsed_response) do
    JSON.parse(response.body)
  end

  RSpec.shared_examples "<%= plural_name %> invalid parameter format" do |parameter_name, incorrect_value|
    let(:request_params) { super().merge({ parameter_name => incorrect_value }) }
    it do
      subject
      expect(response).to have_http_status(400)
    end
    it { expect { subject }.to change { <%= class_name %>.count }.by(0) }
    it do
      subject
      expect(parsed_response).to include("errors")
    end
  end
<% for action in actions %>
  context "GET #<%= action %>" do
    let(:name) { "Breakfast" }
    let(:request_params) do
      {
        name: name
      }
    end
    subject { get "/api/v1/<%= plural_name %>", params: request_params }

    describe "param validation" do
      # TODO: fill in param validation, examples:
      # it_behaves_like "<%= plural_name %> invalid parameter format", :name, ""
      # it_behaves_like "<%= plural_name %> invalid parameter format", :name, nil
    end

    describe "response" do
      before { subject }
      it { expect(response).to have_http_status(200) }
      it { expect(parsed_response).to be_empty }
    end

    it do
      subject
      expect(response).to have_http_status(200)
    end
    it { expect { subject }.to change { <%= class_name %>.count }.by(1) }
  end
<% end %>
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-api-controller-generator-0.1.1 lib/generators/api_controller/templates/spec.rb
rails-api-controller-generator-0.1.0 lib/generators/api_controller/templates/spec.rb