Skip to content

Commit

Permalink
wrote show method to find movie by title
Browse files Browse the repository at this point in the history
  • Loading branch information
J-C-L committed May 10, 2017
1 parent 3d4832c commit 224eac7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ The smoke tests live in the file [`test/VideoStoreAPI_smoke_tests.postman_collec
1. Click `Import` in the top left
1. Drag-and-drop the file into the box
1. In the left sidebar, click on the `Collections` tab
1. There should now be an entry for the smoke tests. Hover over it and click the `>` icon for a detail view.
1. There should now be an entry for the smoke tests. Hover over it and click the `>` icon for a detail view. You will notice they are in the format `{{url}}/movies`. `{{url}}` is a key which you can give a value on your computer.
1. To do so go to the Gearbox in the top-right and select `Manage Environments`
![Manage Environments](images/manage-environment.png)
1. Then Select `Add`
![add button](images/add-btn.png)
1. Lastly add a key `url` and value `http://localhost:3000`
![Key & Value](images/key-value.png)
1. Click the blue `Run` button. This will launch the collection runner.
1. In the collection runner, scroll down in the center pane and click the blue `Start Test` button

Expand Down Expand Up @@ -273,8 +279,7 @@ Fields to return:
- `title`
- `checkout_date`
- `due_date`


# Reference
- [Postman on Environments](https://www.getpostman.com/docs/environments)

11 changes: 11 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,15 @@ def index
end
end

def show
movie = Movie.find_by(title: params[:title])
if movie
render json: movie.as_json(only: [:title, :overview, :release_date, :inventory]), status: :ok
# add available _inventory
else
#render :not_found = 404
render status: :not_found, json: { error: "Could not find a movie with the title #{params[:title]}"}
end
end

end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
get 'movies', to:'movies#index', as: 'movies'
# GET /movies, #index


get 'movies/:title', to:'movies#show', as: 'movie'
# GET /movies/:title #show
# params: title

Expand Down
8 changes: 5 additions & 3 deletions test/fixtures/movies.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

psycho:
title: Psycho
overview: When larcenous real estate clerk Marion Crane
overview: When larcenous real estate clerk Marion Crane goes on the lam with a wad of cash and hopes of starting a new life, she ends up at the notorious Bates Motel, where manager Norman Bates cares for his housebound mother. The place seems quirky, but fine… until Marion decides to take a shower.
release_date: 1960-06-16
inventory: 8

jaws:
title: Jaws
overview: An insatiable great white shark
overview: An insatiable great white shark terrorizes the townspeople of Amity Island, The police chief, an oceanographer and a grizzled shark hunter seek to destroy the bloodthirsty beast.
release_date: 1975-06-19
inventory: 6

exorcist:
title: The Exorcist
overview: 12-year-old
overview: 12-year-old Regan MacNeil begins to adapt an explicit new personality as strange events befall the local area of Georgetown. Her mother becomes torn between science and superstition in a desperate bid to save her daughter, and ultimately turns to her last hope: Father Damien Karras, a troubled priest who is struggling with his own faith.
release_date: 1973-12-26
inventory: 7

0 comments on commit 224eac7

Please sign in to comment.