|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +RSpec.describe "/esdas", type: :request do |
| 4 | + let!(:esda) { create :esda } |
| 5 | + let(:valid_attributes) do |
| 6 | + { metadata: esda.metadata.to_json } |
| 7 | + end |
| 8 | + let(:invalid_attributes) do |
| 9 | + { metadata: "" } |
| 10 | + end |
| 11 | + |
| 12 | + let(:valid_headers) do |
| 13 | + {} |
| 14 | + end |
| 15 | + |
| 16 | + describe "GET /index" do |
| 17 | + it "renders a successful response" do |
| 18 | + get esdas_url, headers: valid_headers, as: :json |
| 19 | + expect(response).to be_successful |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + describe "GET /show" do |
| 24 | + it "renders a successful response" do |
| 25 | + get esda_url(esda), as: :json |
| 26 | + expect(response).to be_successful |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + describe "POST /create" do |
| 31 | + context "with valid parameters" do |
| 32 | + it "creates a new Esda" do |
| 33 | + expect { |
| 34 | + post esdas_url, |
| 35 | + params: { esda: valid_attributes }, headers: valid_headers, as: :json |
| 36 | + }.to change(Esda, :count).by(1) |
| 37 | + end |
| 38 | + |
| 39 | + it "renders a JSON response with the new esda" do |
| 40 | + post esdas_url, |
| 41 | + params: { esda: valid_attributes }, headers: valid_headers, as: :json |
| 42 | + expect(response).to have_http_status(:created) |
| 43 | + expect(response.content_type).to match(a_string_including("application/json")) |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context "with invalid parameters" do |
| 48 | + it "does not create a new Esda" do |
| 49 | + expect { |
| 50 | + post esdas_url, |
| 51 | + params: { esda: invalid_attributes }, as: :json |
| 52 | + }.to change(Esda, :count).by(0) |
| 53 | + end |
| 54 | + |
| 55 | + it "renders a JSON response with errors for the new esda" do |
| 56 | + post esdas_url, |
| 57 | + params: { esda: invalid_attributes }, headers: valid_headers, as: :json |
| 58 | + expect(response).to have_http_status(:unprocessable_entity) |
| 59 | + expect(response.content_type).to match(a_string_including("application/json")) |
| 60 | + end |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + describe "PATCH /update" do |
| 65 | + context "with valid parameters" do |
| 66 | + let(:metadata) do |
| 67 | + { this: :that }.as_json |
| 68 | + end |
| 69 | + let(:new_attributes) do |
| 70 | + { metadata: metadata.to_json } |
| 71 | + end |
| 72 | + it "updates the requested esda" do |
| 73 | + patch esda_url(esda), |
| 74 | + params: { esda: new_attributes }, headers: valid_headers, as: :json |
| 75 | + esda.reload |
| 76 | + expect(esda.metadata).to eq(metadata) |
| 77 | + end |
| 78 | + |
| 79 | + it "renders a JSON response with the esda" do |
| 80 | + patch esda_url(esda), |
| 81 | + params: { esda: new_attributes }, headers: valid_headers, as: :json |
| 82 | + expect(response).to have_http_status(:ok) |
| 83 | + expect(response.content_type).to match(a_string_including("application/json")) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + context "with invalid parameters" do |
| 88 | + it "renders a JSON response with errors for the esda" do |
| 89 | + patch esda_url(esda), |
| 90 | + params: { esda: invalid_attributes }, headers: valid_headers, as: :json |
| 91 | + expect(response).to have_http_status(:unprocessable_entity) |
| 92 | + expect(response.content_type).to match(a_string_including("application/json")) |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | + |
| 97 | + describe "DELETE /destroy" do |
| 98 | + it "destroys the requested esda" do |
| 99 | + expect { |
| 100 | + delete esda_url(esda), headers: valid_headers, as: :json |
| 101 | + }.to change(Esda, :count).by(-1) |
| 102 | + end |
| 103 | + end |
| 104 | +end |
0 commit comments