Sha256: d8bf3da8b7e40c6fc6b5a3aab30a8039b8db4504e8b306c573e42d94758268e2

Contents?: true

Size: 1.68 KB

Versions: 6

Compression:

Stored size: 1.68 KB

Contents

require "spec_helper"

describe "Recipes" do
  let(:env) do
    { "ACCEPT" => "application/json", "CONTENT_TYPE" => "application/json" }
  end

  let(:params) do
    {}
  end

  describe "GET /recipes/:id" do
    let(:recipe) do
      Recipe.create(name: "test", type: 2)
    end

    context "with valid condition (using Rack::Test)", :autodoc do
      before do
        env["Content-Type"] = "application/json"
      end

      include Rack::Test::Methods

      it "returns the recipe" do
        get "/recipes/#{recipe.id}", params, env
        last_response.status.should == 200
      end
    end
  end

  describe "POST /recipes" do
    before do
      params[:name] = "name"
      params[:type] = 1
    end

    context "without required param" do
      before do
        params.delete(:name)
      end

      it "returns 400" do
        post "/recipes", params.to_json, env
        response.status.should == 400
      end
    end

    context "with other typed param" do
      before do
        params[:type] = "x"
      end

      it "returns 400" do
        post "/recipes", params.to_json, env
        response.status.should == 400
      end
    end

    context "without non-required param" do
      before do
        params.delete(:type)
      end

      it "creates a new recipe" do
        post "/recipes", params.to_json, env
        response.status.should == 201
      end
    end

    context "with valid condition", :autodoc do
      let(:description) do
        <<-EOS
          Creates
          a
          new
          recipe!
        EOS
      end

      it "creates a new recipe" do
        post "/recipes", params.to_json, env
        response.status.should == 201
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
autodoc-0.3.6 spec/requests/recipes_spec.rb
autodoc-0.3.5 spec/requests/recipes_spec.rb
autodoc-0.3.4 spec/requests/recipes_spec.rb
autodoc-0.3.3 spec/requests/recipes_spec.rb
autodoc-0.3.2 spec/requests/recipes_spec.rb
autodoc-0.3.1 spec/requests/recipes_spec.rb