-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.html
156 lines (153 loc) · 11.9 KB
/
README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<h2 id="assignment-for-module-3-recipe-finder">Assignment for Module #3: Recipe Finder</h2>
<p>The overall goal of this assignment is to implement a Rails application using model, view, and controller classes.</p>
<ul>
<li>the model class will access information</li>
<li>the view class will display information and accept commands from the user</li>
<li>the controller class will implement actions through internal service logic and the delegation to model and view classes.</li>
</ul>
<p>The functional goal is to provide web page access to recipe information served by <code>http://food2fork.com/api</code> through JSON and images. Documentation for the API can be found at http://food2fork.com/about/api.</p>
<h3 id="functional-requirements">Functional Requirements</h3>
<p>You are tasked with creating a Rails app that will display a recipe index page based on a search keyword entered.</p>
<ul>
<li>the user will supply a keyword to search for</li>
<li>the Rails app will pass that query to <code>http://food2fork.com/api</code> and accept the results</li>
<li>the Rails app will build a web page display of the results and accept the next keyword search</li>
<li>the web page displayed will provide HTML links to more detailed recipe information from other web sites.</li>
</ul>
<p>You should already have the <code>Recipe</code> class from an earlier assignment. (Remember, that unlike in that assignment - you will not need to <code>require</code> HTTParty gem in your code, since loading HTTParty gem should be the Bundler's job.)</p>
<p>You are also tasked with deploying your solution to Heroku - to be accessed by friends, family, other students, co-workers, and prospective employers.</p>
<h3 id="getting-started">Getting Started</h3>
<ol style="list-style-type: decimal">
<li><p>Create a new Rails application using the <code>rails</code> command called <code>recipefinder</code>.</p></li>
<li><p>Download and extract the starter set of boostrap files into the recipefinder directory.</p>
<ul>
<li>replace the generated Gemfile with the Gemfile from the bootstrap fileset</li>
<li>run the <code>bundle</code> command to resolve new gems</li>
</ul>
<pre class="shell"><code>|-- Gemfile
|-- README.md
|-- .rspec (important hidden file)
`-- spec
|-- recipes_app_spec.rb
`-- spec_helper.rb</code></pre></li>
<li><p>Install the following gems used by the rspec unit tests. You may have some of these already installed. The last gem is used for headless web page testing.</p>
<pre class="shell"><code>$ gem install rspec
$ gem install rspec-its
$ gem install capybara
$ gem install poltergeist</code></pre></li>
<li><p>Make sure phantomJS is installed and in your bin PATH on your system ($ phantomjs --version). This binary is used by the <code>poltergeist</code> gem to implement a headless unit test for the Web interface. You can interact with your Rails app directly using a browser without this library. It is only needed by the rspec tests to provide you feedback for example criteria the grader will be looking for later when submitted. PhantomJS installation was covered in Module 1. In case you need more information, the download URLs are below. Linux users will need to use version 1.9.8 or build from source. All other platforms can easily use 2.0.0.</p>
<ul>
<li>phantomjs downloads: http://phantomjs.org/download.html</li>
<li>bitbucket: https://bitbucket.org/ariya/phantomjs/downloads</li>
</ul></li>
<li><p>Run the rspec test(s) to receive feedback. They must be run from their location at the root of your rails application. All tests will (obviously) fail until you complete the specified solution.</p>
<pre class="shell"><code>Finished in 1.69 seconds (files took 0.41211 seconds to load)
8 examples, 8 failures
Failed examples:
rspec ./spec/recipes_app_spec.rb:6 # Recipes App displays
'Kahlúa-Spiked' when request parameter 'search' is mocha
rspec ./spec/recipes_app_spec.rb:11 # Recipes App utilizes
the FOOD2FORK_SERVER_AND_PORT environment variable
rspec ./spec/recipes_app_spec.rb:16 # Recipes App utilizes
the FOOD2FORK_KEY environment variable
rspec ./spec/recipes_app_spec.rb:24 # Recipes App visit root
displays chocolate (default)
rspec ./spec/recipes_app_spec.rb:28 # Recipes App visit root
displays 'Powered By Food2Fork.com'
rspec ./spec/recipes_app_spec.rb:32 # Recipes App visit root
displays table element that has a row with 3 columns
rspec ./spec/recipes_app_spec.rb:36 # Recipes App visit root
column 1 should have the thumbnail inside img tag inside a link tag
rspec ./spec/recipes_app_spec.rb:40 # Recipes App visit root
title should be inside a second column inside a link tagink tag</code></pre></li>
<li><p>Implement your Rails app solution and use the rspec tests to help verify your completed Rails app solution.</p></li>
<li><p>(Optional) Post your Rails app solution to Heroku.</p></li>
<li><p>Submit your Rails app solution for grading.</p></li>
</ol>
<h3 id="technical-requirements">Technical Requirements</h3>
<ol style="list-style-type: decimal">
<li><p>Create a new Rails app called <code>recipefinder</code>. Use the Gemfile provided in the boostrap files. Do not change the Gemfile from what is provided or your submitted solution may not be able to be processed by the grader (i.e., do not add any additional gems or change gem versions).</p></li>
<li><p>Generate <code>RecipesController</code> (recipes_controller.rb) that will have an <code>index</code> action</p></li>
<li><p>The <code>RecipesController</code> index action should</p>
<ul>
<li>check if a request parameter <code>search</code> was passed in.</li>
<li>use the <code>search</code> term as the keyword if supplied, and use a default value of <code>chocolate</code> if not supplied</li>
</ul></li>
<li><p>Create a model, <code>Recipe</code> (recipe.rb) that will contain a <code>for</code> class method.</p></li>
<li><p>The <code>Recipe</code> <code>for</code> class method should</p>
<ul>
<li>take a keyword to query</li>
<li>query the Food2Fork API for a result.</li>
<li>add the HTTP query parameter <code>key</code> (your developer key) to each outgoing URL request to <code>http://food2fork.com/api</code> using HTTParty <code>default_params</code>.</li>
<li>obtain the key value from an environment variable FOOD2FORK_KEY</li>
<li>obtain the url (and/or port) value from an environment variable FOOD2FORK_SERVER_AND_PORT</li>
</ul>
<p>You will use the <code>http://food2fork.com/api</code> host and port# (default=:80) during development and Heroku deployment. However, your assignment will be graded off-line and should get its host and port# from the <code>FOOD2FORK_SERVER_AND_PORT</code> environment variable. Your assignment must use the defined value if present and default to the real value otherwise.</p>
<pre class="sourceCode ruby"><code class="sourceCode ruby"><span class="kw">class</span> <span class="dt">Recipe</span>
...
key_value = <span class="dt">ENV</span>[<span class="st">'FOOD2FORK_KEY'</span>]
hostport = <span class="dt">ENV</span>[<span class="st">'FOOD2FORK_SERVER_AND_PORT'</span>] || <span class="st">'www.food2fork.com'</span>
base_uri <span class="st">"http://</span><span class="ot">#{</span>hostport<span class="ot">}</span><span class="st">/api"</span>
...</code></pre></li>
<li><p>Foods2Fork requires attribution when using their API. Place the following somewhere in your application layout file (<code>application.html.erb</code>) to be displayed alongside the recipes.</p>
<code><p>Powered By Food2Fork.com</p></code></li>
<li><p>Create your view that should</p>
<ul>
<li>list each recipe as a row in an HTML table (<code><table></code>)</li>
<li>Each row (<code><tr></code>) should have 3 columns (<code><td></code>) where
<ul>
<li>column 1 should contain the thumbnail of the recipe,</li>
<li>column 2 should contain the title and</li>
<li>column 3 should contain the social rank of the recipe.</li>
</ul></li>
</ul>
<p>You are not required to create an HTML form for the search term. You may specify the search keyword using just the URL with the following syntax in the browser.</p>
<pre class="url"><code>http://localhost:3000/recipes/index?search=swiss</code></pre></li>
<li><p>Add <code>href</code> tags to your image and title. You should be able to click on either the title or the thumbnail and go straight to the actual recipe (out there on the web). Look at <code>image_tag</code> Rails helper for help with defining an <code>img</code> tag (http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag) and use this helper as the first argument to <code>link_to</code> helper.</p></li>
<li><p>Inside the <code>image_tag</code> specify <code>width</code> and <code>height</code> of 100 for your images.</p></li>
<li><p>Sanitize recipe titles displayed. Rails automatically escapes HTML in your strings (to avoid XSS attacks http://en.wikipedia.org/wiki/Cross-site_scripting). Because of this, some of your titles will look wrong. For example, try searching for <code>mocha</code> and look at your titles. To get around this issue, Rails has a <code>sanitize</code> (or <code>raw</code>) helper (http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html#method-i-sanitize) that will help you display HTML characters properly</p></li>
<li><p>Make the <code>RecipesController</code> <code>index</code> action the default (root) page for your application. Instead of having to go to <code>http://localhost:3000/recipes/index</code> to get to your recipes, you want this page to be the default (root). You should therefore be able to go to <code>http://localhost:3000/?search=apple%20pie</code> for example and see your results.</p></li>
<li><p>(optional -- ungraded) Deploy your app to Heroku at recipefinderX.herokuapp.com where <code>X</code> is any available number from 1 to 10000000. In order to do this you will have to define the FOOD2FORK_KEY with your key to use the food2fork api on Heroku. Instructions for doing that can be found at the following link:</p>
<p>https://devcenter.heroku.com/articles/config-vars#example.</p></li>
</ol>
<h3 id="self-gradingfeedback">Self Grading/Feedback</h3>
<p>Some unit tests have been provided in the bootstrap files and provide examples of some tests the grader will be evaluating for when you submit your solution. They can be run from any location but be sure to copy the hidden <code>.rspec</code> file if you move them.</p>
<pre class="shell"><code>$ rspec
...
Recipes App
displays 'Kahlúa-Spiked' when request parameter 'search' is mocha
utilizes the FOOD2FORK_SERVER_AND_PORT environment variable
utilizes the FOOD2FORK_KEY environment variable
visit root
displays chocolate (default)
displays 'Powered By Food2Fork.com'
displays table element that has a row with 3 columns
column 1 should have the thumbnail inside img tag inside a link tag
title should be inside a second column inside a link tag
Finished in 2.73 seconds (files took 0.54954 seconds to load)
8 examples, 0 failures</code></pre>
<p>The tests assume your server is running on localhost:3000. Please adjust the source code in <code>recipes_app_spec.rb</code> if that is not the case with your development environment.</p>
<p><code>ruby Capybara.app_host = "http://localhost:3000"</code></p>
<h3 id="submission">Submission</h3>
<p>Submit an .zip archive (other archive forms not currently supported) with your solution root directory as the top-level (e.g., your Gemfile and sibling files must be in the root of the archive and <em>not</em> in a sub-folder. The grader will replace the spec files with fresh copies and will perform a test with different query terms.</p>
<pre class="text"><code>|-- app
| |-- assets
| |-- controllers
| |-- helpers
| |-- mailers
| |-- models
| `-- views
|-- bin
|-- config
|-- config.ru
|-- db
|-- Gemfile
|-- Gemfile.lock
|-- lib
|-- log
|-- public
|-- Rakefile
|-- README.rdoc
|-- test
`-- vendor</code></pre>
<h4 id="last-updated-2015-09-22">Last Updated: 2015-09-22</h4>