Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
be82818
Initialize Rails API
hanalways May 14, 2019
6c65b70
generate models movie, rental, and customer
jessicacaley May 14, 2019
e3e0804
Generated Rentals, Customers, and Movies controllers
hanalways May 14, 2019
acd5972
Merge branch 'master' of https://github.com/jessicacaley/VideoStoreAPI
jessicacaley May 14, 2019
fb9ae97
Update routes for all endpoints
hanalways May 14, 2019
7025f6e
has_many and belongs_to relationships
jessicacaley May 14, 2019
4b76487
migrations to add foreign keys for movie and customer to rentals
jessicacaley May 14, 2019
6a72bd8
Merge branch 'master' of https://github.com/jessicacaley/VideoStoreAPI
jessicacaley May 14, 2019
1049e1d
Movies index, show, create, zomg and strong params
hanalways May 14, 2019
95c124b
Movies index, show, create, zomg and strong params
hanalways May 14, 2019
6bbb533
add validations to models for presence based on api requirements
jessicacaley May 14, 2019
4ce0ab0
Rename columns Check In/Out to checkout_date and checkin_date
hanalways May 14, 2019
6f5e938
Merge branch 'master' of https://github.com/jessicacaley/VideoStoreAPI
hanalways May 14, 2019
b5ef87b
fix validations
jessicacaley May 14, 2019
e275204
add default values for checkout and due date
jessicacaley May 14, 2019
48dccba
fix new line bug
jessicacaley May 14, 2019
17f96b3
fix rentals fixture bug after column rename
jessicacaley May 14, 2019
ad71d34
Customer validations and relationship passing all tests
hanalways May 14, 2019
3f1b382
movie model tests
jessicacaley May 14, 2019
4f239d5
must respond to in relationship tests
hanalways May 14, 2019
6b76fef
rental yml file
jessicacaley May 14, 2019
1dde9d3
Merge branch 'master' of https://github.com/jessicacaley/VideoStoreAPI
jessicacaley May 14, 2019
a50a321
Create and edit customer ymls
hanalways May 14, 2019
500f1f8
Merge branch 'master' of https://github.com/jessicacaley/VideoStoreAPI
hanalways May 14, 2019
ada8ff2
Tests include checking error messages
hanalways May 14, 2019
13032e1
Merge pull request #1 from jessicacaley/movie-model-tests
hanalways May 14, 2019
4b7693a
fix customer yml and add rental model relation tests
jessicacaley May 14, 2019
2467942
Refactor customer tests to pass with new yml info
hanalways May 14, 2019
e3f995b
validation tests for rental model
jessicacaley May 14, 2019
0ab4eb0
Merge branch 'master' of https://github.com/jessicacaley/VideoStoreAPI
jessicacaley May 14, 2019
4ea9175
make model test format uniform
jessicacaley May 14, 2019
87d88e2
create index action for customers
hanalways May 14, 2019
82d54b2
Merge branch 'master' of https://github.com/jessicacaley/VideoStoreAPI
hanalways May 14, 2019
5d093ba
add test for checkout date and due date default values
jessicacaley May 14, 2019
7809181
Merge branch 'master' of https://github.com/jessicacaley/VideoStoreAPI
jessicacaley May 14, 2019
922c6eb
add tests that rentals require movie and customer
jessicacaley May 14, 2019
ffb9ac0
start customers controller tests
jessicacaley May 14, 2019
44056df
Add SimpleCov and add returns json tests
hanalways May 14, 2019
6282255
customers returns an array
jessicacaley May 14, 2019
986893c
passing returns all the customers test
hanalways May 14, 2019
d84ab93
refactor required fields test for customer
hanalways May 14, 2019
1671f85
complete last customer index controller test
jessicacaley May 14, 2019
4daec78
movies index is a real working route
jessicacaley May 14, 2019
a217d00
Return json and Array tests passing
hanalways May 14, 2019
f3d61da
finish movies#index controller tests
jessicacaley May 14, 2019
d5e8881
add movies#show test outline
jessicacaley May 14, 2019
ed971ad
add comment
jessicacaley May 14, 2019
2a5686b
got movies#show tests working (partial)
jessicacaley May 15, 2019
cc67e25
finish movies#show tests
jessicacaley May 15, 2019
8d8d17b
edge case for movie show
hanalways May 15, 2019
e42bb5a
remove checkout_date and due_date defaults since rails is not dynamic :(
hanalways May 15, 2019
00d1983
first movie#create test
jessicacaley May 15, 2019
d8ba545
invalid movie data create test passing
hanalways May 15, 2019
29b7a28
add more movie#create tests
jessicacaley May 15, 2019
e0aa5f2
rentals#checkout start controller action and tests
jessicacaley May 15, 2019
3ef55b2
creates an instance of rental test passing
hanalways May 15, 2019
b38d304
added edge cases for rentals#create
jessicacaley May 15, 2019
dfbcb9e
rental for invalid rental id test passing
hanalways May 15, 2019
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
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore uploaded files in development
/storage/*
!/storage/.keep

.byebug_history

# Ignore master key for decrypting credentials and more.
/config/master.key

# Ignore generated files in coverage directory
coverage/*
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.5.1
58 changes: 58 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.3'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end


# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

group :development, :test do
gem 'pry-rails'
end

group :test do
gem 'minitest-rails'
gem 'minitest-reporters'
gem 'simplecov', require: false
end

gem 'rabl'
gem 'oj'
182 changes: 182 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.3)
actionpack (= 5.2.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.3)
actionview (= 5.2.3)
activesupport (= 5.2.3)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.3)
activesupport (= 5.2.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.3)
activesupport (= 5.2.3)
globalid (>= 0.3.6)
activemodel (5.2.3)
activesupport (= 5.2.3)
activerecord (5.2.3)
activemodel (= 5.2.3)
activesupport (= 5.2.3)
arel (>= 9.0)
activestorage (5.2.3)
actionpack (= 5.2.3)
activerecord (= 5.2.3)
marcel (~> 0.3.1)
activesupport (5.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
ansi (1.5.0)
arel (9.0.0)
bootsnap (1.4.4)
msgpack (~> 1.0)
builder (3.2.3)
byebug (11.0.1)
coderay (1.1.2)
concurrent-ruby (1.1.5)
crass (1.0.4)
docile (1.3.1)
erubi (1.8.0)
ffi (1.10.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
json (2.1.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
method_source (0.9.2)
mimemagic (0.3.3)
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
minitest-rails (3.0.0)
minitest (~> 5.8)
railties (~> 5.0)
minitest-reporters (1.3.6)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
msgpack (1.2.10)
nio4r (2.3.1)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
oj (3.7.12)
pg (1.1.4)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
puma (3.12.1)
rabl (0.14.1)
activesupport (>= 2.3.14)
rack (2.0.7)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.3)
actioncable (= 5.2.3)
actionmailer (= 5.2.3)
actionpack (= 5.2.3)
actionview (= 5.2.3)
activejob (= 5.2.3)
activemodel (= 5.2.3)
activerecord (= 5.2.3)
activestorage (= 5.2.3)
activesupport (= 5.2.3)
bundler (>= 1.3.0)
railties (= 5.2.3)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.3)
actionpack (= 5.2.3)
activesupport (= 5.2.3)
method_source
rake (>= 0.8.7)
thor (>= 0.19.0, < 2.0)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
ruby-progressbar (1.10.0)
ruby_dep (1.5.0)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
spring (2.0.2)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.3)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)

PLATFORMS
ruby

DEPENDENCIES
bootsnap (>= 1.1.0)
byebug
listen (>= 3.0.5, < 3.2)
minitest-rails
minitest-reporters
oj
pg (>= 0.18, < 2.0)
pry-rails
puma (~> 3.11)
rabl
rails (~> 5.2.3)
simplecov
spring
spring-watcher-listen (~> 2.0.0)
tzinfo-data

RUBY VERSION
ruby 2.5.1p57

BUNDLED WITH
1.16.6
9 changes: 9 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
guard :minitest, autorun: false, spring: true do
watch(%r{^app/(.+).rb$}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{^app/controllers/application_controller.rb$}) { 'test/controllers' }
watch(%r{^app/controllers/(.+)_controller.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
watch(%r{^lib/(.+).rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
watch(%r{^test/.+_test.rb$})
watch(%r{^test/test_helper.rb$}) { 'test' }
end
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require_relative 'config/application'

Rails.application.load_tasks
4 changes: 4 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
4 changes: 4 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
Empty file added app/controllers/concerns/.keep
Empty file.
6 changes: 6 additions & 0 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class CustomersController < ApplicationController
def index
customers = Customer.all
render status: :ok, json: customers.as_json(only: [:id, :name, :registered_at, :postal_code, :phone])
end
end
36 changes: 36 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class MoviesController < ApplicationController
def index
movies = Movie.all
render status: :ok, json: movies.as_json(only: [:id, :title, :release_date])
end

def show
movie = Movie.find_by(id: params[:id])

if movie
render status: :ok, json: movie.as_json(only: [:title, :overview, :release_date, :inventory])
else
render status: :not_found, json: {errors: ["Movie with ID #{params[:id]} not found"]}
end
end

def create
movie = Movie.new(movie_params)

if movie.save
render status: :ok, json: {id: movie.id}
else
render status: :bad_request, json: {errors: movie.errors.messages}
end
end

def zomg
render json: {works: "it works!"}

Choose a reason for hiding this comment

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

No status code?

end

private

def movie_params
params.permit(:title, :overview, :release_date, :inventory)
end
end
36 changes: 36 additions & 0 deletions app/controllers/rentals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class RentalsController < ApplicationController
def check_out
rental = Rental.new(rental_params)

rental.checkout_date = Date.current
rental.due_date = rental.checkout_date + 7

if rental.save
render status: :ok, json: {id: rental.id}
else
render status: :bad_request, json: {errors: rental.errors.messages}
end
end

def check_in
rental = Rental.find_by(id: params[:id])
unless rental
head :not_found
return
end

rental.checkin_date = Date.current

if rental.save
render status: :ok, json: {id: rental.id}
else
render status: :bad_request, json: {errors: rental.errors.messages}
end
end

private

def rental_params
params.permit(:customer_id, :movie_id)
end
end
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Empty file added app/models/concerns/.keep
Empty file.
Loading