Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queues - Andrea Valliere & Kaitlin Ramirez - VideoStoreAPI #9

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
first model validation test for customer
Kaitlin Ramirez committed May 10, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 06d38e7bda3c35d3cc3154e658c4c82ccbf3d762
16 changes: 8 additions & 8 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@ def index
render json: customers.as_json(only: [:id, :name, :registered_at, :address, :city, :state, :postal_code, :phone, :account_credit]), status: :ok
end

def show
customer = Customer.find_by(id: params[:id])
if customer
render json: customer, status: :ok
else
render json: customer, status: :not_found
end
end
# def show

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete any code you're not using

# customer = Customer.find_by(id: params[:id])
# if customer
# render json: customer, status: :ok
# else
# render json: customer, status: :not_found
# end
# end
end
1 change: 1 addition & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Customer < ApplicationRecord
has_many :rentals
has_many :movies, :through => :rentals
validates :name, presence: true
end
6 changes: 2 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Rails.application.routes.draw do
get "customers", to: "customers#index", as: "customers"
get "movies", to: "movies#index", as: "movies"

get "movie/:id", to: "movies#show", as: "movie"

get "customers", to: "customers#index", as: "customers"

get "customer/:id", to: "customers#show", as: "customer"
# get "customer/:id", to: "customers#show", as: "customer"

# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
22 changes: 11 additions & 11 deletions test/controllers/customers_controller_test.rb
Original file line number Diff line number Diff line change
@@ -28,16 +28,16 @@
end
end

describe "show" do
it "can get a customer" do
get customer_path(customers(:two).id)
must_respond_with :success
end

it "does not get a customer that does not exist" do
get customer_path(Customer.last.id+1)
must_respond_with :not_found
end
end
# describe "show" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't need this just delete

# it "can get a customer" do
# get customer_path(customers(:two).id)
# must_respond_with :success
# end
#
# it "does not get a customer that does not exist" do
# get customer_path(Customer.last.id+1)
# must_respond_with :not_found
# end
# end
end
end
23 changes: 21 additions & 2 deletions test/models/customer_test.rb
Original file line number Diff line number Diff line change
@@ -2,8 +2,27 @@

describe Customer do
let(:customer) { Customer.new }
#
# it "must be valid" do
# value(customer).must_be :valid?
# end
describe "validations" do
it "must create a new customer with good info" do
customer.account_credit = 12.00
customer.address = "123 Bob Lives Here"
customer.city = "Seattle"
# id
customer.name = "Bob Smart"
customer.phone = "(123) 456-7890"
customer.postal_code = "12345"
customer.registered_at = "Wed, 20 Apr 2016 07:54:14 -0700"
customer.state = "KS"
customer.save!
customer.valid?.must_equal true
end

it "must be valid" do
value(customer).must_be :valid?
it "is invalid without a name" do

end
end
end