ruby app.rb
to start the server to port 3000ruby integration_tests.rb
to run tests.- I used Sinatra as it serves perfectly the purpose of this assignment: this way we can keep the application code to the minimum and avoid adding extra complexity to it.
- I decoupled code by having the
app.rb
file which only serves as the controller. It has no knowledge about Contentful and how to retrieve recipes. - Business logic is encapsulated inside the
Recipes
module which exposes the two aggregate methods to retrieve all recipes or a specific recipe (in a more sophisticated case, each of these methods would instantiate a service object class which would encapsulate its business logic, but of course it was not the case of this assignment.) Recipes
defines aRecipe < Contentful::Entry
class which offers public methods with names, etc, so that the view (or the presenter) do not have to make nested calls (ie:recipe.something.something
) This way, we adhere to Demeter's law. Also, I usedfields[:field_name]
instead of the direct method invokation so that it does not raise an error. In a real life scenario, I would probably define what fields are required (ie: title and description) and what are optional (ie: tags), and raise an error in case a required field is missing, so that we would be properly alerted (and with a failsafe mechanism to avoid displaying errors to the user).- I created a
Recipes::RecipePresenter
which is a decorator taking care of defining the right text to be shown and converting markdown (returned by Contentful) to HTML. This way, the view only defines the structure while contents are defined in the presenter. - Views are in HAML: normally I use ERB (because it is more of a standard) but for such small projects HAML helps with programming speed, therefore I used it.
- I created integration tests to make sure the pages are working. In a real life scenario, I would have written unit tests, too, but, given the time constraint, I have chosen to write ony the most essential tests (which are integration tests because they prove that the whole system work).
- In a real life scenario, error cases (like :id not found) would need to be handled.
-
Notifications
You must be signed in to change notification settings - Fork 0
steookk/contentful_recipes
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Sinatra app to demonstrate use of content stored in Contentful
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published