Conversation
… Recipe class. still working on associated tests.
…n controller from command line.
…links to recipe details, view incomplete.
…mbol is not permitted
API MuncherWhat We're Looking For
|
| def index | ||
| @query = params[:search] | ||
|
|
||
| if params[:search] |
There was a problem hiding this comment.
Because the empty string is truthy in Ruby, even if you search for nothing you won't end up in the error handling here. Instead, you might have something like if params[:search] && params[:search] != "".
|
|
||
| def new | ||
|
|
||
| end |
There was a problem hiding this comment.
I don't think the new action is used in your app.
|
|
||
| unless @recipe | ||
| head :not_found | ||
| end |
There was a problem hiding this comment.
I like this idea, but I do not believe the code will ever get here. Your API wrapper throws an error if the recipe is not found, but here you check for a nil response. You have two options to make the connection:
- Use a
begin/rescueblock here to catch the exception - Instead of throwing an error, return
nilfromApiWrapper.find_recipeif the recipe can't be found.
|
|
||
|
|
||
| # parse the JSON data in order to get recipe details for the show page | ||
| if data.empty? |
There was a problem hiding this comment.
It looks like you're missing a call to check_status here. If the API returns an error like not_authed (as opposed to no results), as is this method won't be able to detect it.
| # # | ||
| # | ||
| # get recipe_path params: { search: "chicken", url: "http://www.edamam.com/ontologies/edamam.owl%23recipe_637913ec61d9da69eb451818c3293df2" + "fake-url"} | ||
| # must_respond_with :not_found |
There was a problem hiding this comment.
I think this test is failing because the controller action is handling the error incorrectly. See comments above.
| begin # something which might raise an exception | ||
| origin_token = ApiWrapper::TOKEN | ||
| ApiWrapper::TOKEN = "bogus_token" | ||
| VCR.use_cassette("recipes") do |
There was a problem hiding this comment.
I like this way of testing an invalid token - much simpler than what we did in class.
API Muncher
Congratulations! You're submitting your assignment!
Comprehension Questions