From a910a607c30e31dacac8252b0265bee14d114952 Mon Sep 17 00:00:00 2001 From: amyesh Date: Wed, 15 May 2019 11:37:46 -0700 Subject: [PATCH] removed show and create methods from customers controller --- app/controllers/customers_controller.rb | 30 --------- test/controllers/customers_controller_test.rb | 62 ------------------- 2 files changed, 92 deletions(-) diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 2d6c2b802..9168cc00f 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -4,34 +4,4 @@ def index render json: customers.as_json(only: [:id, :name, :registered_at, :postal_code, :phone, :movies_checked_out_count]), status: :ok end - - def show - customer = Customer.find_by(id: params[:id]) - - if !customer.nil? - render json: customer.as_json(only: [:id, :name, :registered_at, :postal_code, :phone, :movies_checked_out_count]), - status: :ok - else - render json: {ok: false, errors: {customer: ["customer not found"]}}, - status: :not_found - end - end - - def create - customer = Customer.new(customer_params) - - if customer.save - render json: customer.as_json(only: [:name, :registered_at, :address, :city, :state, :postal_code, :phone, :movies_checked_out_count, :id]), - status: :ok - else - render json: {ok: false, errors: customer.errors.messages}, - status: :bad_request - end - end - - private - - def customer_params - params.require(:customer).permit(:name, :registered_at, :address, :city, :state, :postal_code, :phone, :movies_checked_out_count) - end end diff --git a/test/controllers/customers_controller_test.rb b/test/controllers/customers_controller_test.rb index 865676ddf..b37ba551c 100644 --- a/test/controllers/customers_controller_test.rb +++ b/test/controllers/customers_controller_test.rb @@ -35,66 +35,4 @@ end end end - - describe "show" do - it "can get a customer with valid info" do - get customer_path(customers(:two).id) - must_respond_with :success - expect(response.header["Content-Type"]).must_include "json" - end - it "raises an error and return not found if given invalid params" do - get customer_path(100) - must_respond_with :not_found - body = JSON.parse(response.body) - expect(body).must_be_kind_of Hash - expect(body).must_include "errors" - expect(body["errors"]).must_include "customer" - end - end - - describe "create" do - let(:customer_data) { - { - name: "Chris Tucker", - address: "555 Scammer Drive", - city: "Seattle", - state: "WA", - postal_code: "11111", - phone: "123-867-5309", - movies_checked_out_count: 2, - registered_at: DateTime.now, - } - } - - it "creates a new customer given valid data" do - expect { - post customers_path, params: {customer: customer_data} - }.must_change "Customer.count", 1 - - body = JSON.parse(response.body) - expect(response.header["Content-Type"]).must_include "json" - expect(body).must_be_kind_of Hash - expect(body).must_include "id" - - customer = Customer.find(body["id"].to_i) - - expect(customer.name).must_equal customer_data[:name] - must_respond_with :success - end - - it "returns an error for invalid customer data" do - customer_data["name"] = nil - - expect { - post customers_path, params: {customer: customer_data} - }.wont_change "Customer.count" - - body = JSON.parse(response.body) - expect(response.header["Content-Type"]).must_include "json" - expect(body).must_be_kind_of Hash - expect(body).must_include "errors" - expect(body["errors"]).must_include "name" - must_respond_with :bad_request - end - end end