From babdc87ee0558be740c08b13e125408a42691780 Mon Sep 17 00:00:00 2001 From: Miriam Date: Mon, 31 Oct 2016 15:36:07 -0700 Subject: [PATCH 01/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3666ab78e..afd643dd4 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,6 @@ Once you've explored the API docs, this project: - Provide checkboxes or other controls to limit the search to options such as: - Peanut Free - Soy Free - - High Protien + - High Protein - Etc From 54e22b7198efb9beb604c55dc3e6eef63b4b9a56 Mon Sep 17 00:00:00 2001 From: Natasha Ewing Date: Mon, 31 Oct 2016 15:40:15 -0700 Subject: [PATCH 02/14] created a rails app within my branch fork --- .gitignore | 17 ++ Gemfile | 47 +++++ Gemfile.lock | 162 ++++++++++++++++++ README.rdoc | 28 +++ Rakefile | 6 + app/assets/images/.keep | 0 app/assets/javascripts/application.js | 16 ++ app/assets/stylesheets/application.css | 15 ++ app/controllers/application_controller.rb | 5 + app/controllers/concerns/.keep | 0 app/helpers/application_helper.rb | 2 + app/mailers/.keep | 0 app/models/.keep | 0 app/models/concerns/.keep | 0 app/views/layouts/application.html.erb | 14 ++ bin/bundle | 3 + bin/rails | 9 + bin/rake | 9 + bin/setup | 29 ++++ bin/spring | 16 ++ config.ru | 4 + config/application.rb | 26 +++ config/boot.rb | 3 + config/database.yml | 25 +++ config/environment.rb | 5 + config/environments/development.rb | 41 +++++ config/environments/production.rb | 79 +++++++++ config/environments/test.rb | 42 +++++ config/initializers/assets.rb | 11 ++ config/initializers/backtrace_silencers.rb | 7 + config/initializers/cookies_serializer.rb | 3 + .../initializers/filter_parameter_logging.rb | 4 + config/initializers/inflections.rb | 16 ++ config/initializers/mime_types.rb | 4 + config/initializers/session_store.rb | 3 + config/initializers/wrap_parameters.rb | 14 ++ config/locales/en.yml | 23 +++ config/routes.rb | 56 ++++++ config/secrets.yml | 22 +++ db/seeds.rb | 7 + lib/assets/.keep | 0 lib/tasks/.keep | 0 log/.keep | 0 public/404.html | 67 ++++++++ public/422.html | 67 ++++++++ public/500.html | 66 +++++++ public/favicon.ico | 0 public/robots.txt | 5 + test/controllers/.keep | 0 test/fixtures/.keep | 0 test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/test_helper.rb | 10 ++ vendor/assets/javascripts/.keep | 0 vendor/assets/stylesheets/.keep | 0 57 files changed, 988 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 README.rdoc create mode 100644 Rakefile create mode 100644 app/assets/images/.keep create mode 100644 app/assets/javascripts/application.js create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/helpers/application_helper.rb create mode 100644 app/mailers/.keep create mode 100644 app/models/.keep create mode 100644 app/models/concerns/.keep create mode 100644 app/views/layouts/application.html.erb create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/setup create mode 100755 bin/spring create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/database.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/backtrace_silencers.rb create mode 100644 config/initializers/cookies_serializer.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/initializers/mime_types.rb create mode 100644 config/initializers/session_store.rb create mode 100644 config/initializers/wrap_parameters.rb create mode 100644 config/locales/en.yml create mode 100644 config/routes.rb create mode 100644 config/secrets.yml create mode 100644 db/seeds.rb create mode 100644 lib/assets/.keep create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 public/404.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/favicon.ico create mode 100644 public/robots.txt create mode 100644 test/controllers/.keep create mode 100644 test/fixtures/.keep create mode 100644 test/helpers/.keep create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/test_helper.rb create mode 100644 vendor/assets/javascripts/.keep create mode 100644 vendor/assets/stylesheets/.keep diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..050c9d95c --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# 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 the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-journal + +# Ignore all logfiles and tempfiles. +/log/* +!/log/.keep +/tmp diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..e87fad5fc --- /dev/null +++ b/Gemfile @@ -0,0 +1,47 @@ +source 'https://rubygems.org' + + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '4.2.7' +# Use sqlite3 as the database for Active Record +gem 'sqlite3' +# Use SCSS for stylesheets +gem 'sass-rails', '~> 5.0' +# Use Uglifier as compressor for JavaScript assets +gem 'uglifier', '>= 1.3.0' +# Use CoffeeScript for .coffee assets and views +gem 'coffee-rails', '~> 4.1.0' +# See https://github.com/rails/execjs#readme for more supported runtimes +# gem 'therubyracer', platforms: :ruby + +# Use jquery as the JavaScript library +gem 'jquery-rails' +# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks +gem 'turbolinks' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +gem 'jbuilder', '~> 2.0' +# bundle exec rake doc:rails generates the API under doc/api. +gem 'sdoc', '~> 0.4.0', group: :doc + +# Use ActiveModel has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Use Unicorn as the app server +# gem 'unicorn' + +# Use Capistrano for deployment +# gem 'capistrano-rails', group: :development + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug' +end + +group :development do + # Access an IRB console on exception pages or by using <%= console %> in views + gem 'web-console', '~> 2.0' + + # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring + gem 'spring' +end + diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..c1dccfc10 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,162 @@ +GEM + remote: https://rubygems.org/ + specs: + actionmailer (4.2.7) + actionpack (= 4.2.7) + actionview (= 4.2.7) + activejob (= 4.2.7) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.7) + actionview (= 4.2.7) + activesupport (= 4.2.7) + rack (~> 1.6) + rack-test (~> 0.6.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.7) + activesupport (= 4.2.7) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.7) + activesupport (= 4.2.7) + globalid (>= 0.3.0) + activemodel (4.2.7) + activesupport (= 4.2.7) + builder (~> 3.1) + activerecord (4.2.7) + activemodel (= 4.2.7) + activesupport (= 4.2.7) + arel (~> 6.0) + activesupport (4.2.7) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + arel (6.0.3) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + builder (3.2.2) + byebug (9.0.6) + coffee-rails (4.1.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.1.x) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.10.0) + concurrent-ruby (1.0.2) + debug_inspector (0.0.2) + erubis (2.7.0) + execjs (2.7.0) + globalid (0.3.7) + activesupport (>= 4.1.0) + i18n (0.7.0) + jbuilder (2.6.0) + activesupport (>= 3.0.0, < 5.1) + multi_json (~> 1.2) + jquery-rails (4.2.1) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + json (1.8.3) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.9.1) + multi_json (1.12.1) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + rack (1.6.4) + rack-test (0.6.3) + rack (>= 1.0) + rails (4.2.7) + actionmailer (= 4.2.7) + actionpack (= 4.2.7) + actionview (= 4.2.7) + activejob (= 4.2.7) + activemodel (= 4.2.7) + activerecord (= 4.2.7) + activesupport (= 4.2.7) + bundler (>= 1.3.0, < 2.0) + railties (= 4.2.7) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.7) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (4.2.7) + actionpack (= 4.2.7) + activesupport (= 4.2.7) + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (11.3.0) + rdoc (4.2.2) + json (~> 1.4) + sass (3.4.22) + sass-rails (5.0.6) + railties (>= 4.0.0, < 6) + sass (~> 3.1) + sprockets (>= 2.8, < 4.0) + sprockets-rails (>= 2.0, < 4.0) + tilt (>= 1.1, < 3) + sdoc (0.4.2) + json (~> 1.7, >= 1.7.7) + rdoc (~> 4.0) + spring (2.0.0) + activesupport (>= 4.2) + sprockets (3.7.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.2.0) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + sqlite3 (1.3.12) + thor (0.19.1) + thread_safe (0.3.5) + tilt (2.0.5) + turbolinks (5.0.1) + turbolinks-source (~> 5) + turbolinks-source (5.0.0) + tzinfo (1.2.2) + thread_safe (~> 0.1) + uglifier (3.0.3) + execjs (>= 0.3.0, < 3) + web-console (2.3.0) + activemodel (>= 4.0) + binding_of_caller (>= 0.7.2) + railties (>= 4.0) + sprockets-rails (>= 2.0, < 4.0) + +PLATFORMS + ruby + +DEPENDENCIES + byebug + coffee-rails (~> 4.1.0) + jbuilder (~> 2.0) + jquery-rails + rails (= 4.2.7) + sass-rails (~> 5.0) + sdoc (~> 0.4.0) + spring + sqlite3 + turbolinks + uglifier (>= 1.3.0) + web-console (~> 2.0) + +BUNDLED WITH + 1.13.6 diff --git a/README.rdoc b/README.rdoc new file mode 100644 index 000000000..dd4e97e22 --- /dev/null +++ b/README.rdoc @@ -0,0 +1,28 @@ +== README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... + + +Please feel free to use a different markup language if you do not plan to run +rake doc:app. diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..ba6b733dd --- /dev/null +++ b/Rakefile @@ -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 File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js new file mode 100644 index 000000000..e07c5a830 --- /dev/null +++ b/app/assets/javascripts/application.js @@ -0,0 +1,16 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require jquery +//= require jquery_ujs +//= require turbolinks +//= require_tree . diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 000000000..f9cd5b348 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 000000000..d83690e1b --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 000000000..de6be7945 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/mailers/.keep b/app/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/models/.keep b/app/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 000000000..237dbba45 --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + ApiMuncher + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 000000000..0138d79b7 --- /dev/null +++ b/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 000000000..d87d5f578 --- /dev/null +++ b/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 000000000..acdb2c138 --- /dev/null +++ b/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/bin/spring b/bin/spring new file mode 100755 index 000000000..9bc076b9e --- /dev/null +++ b/bin/spring @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + if spring = lockfile.specs.detect { |spec| spec.name == "spring" } + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/config.ru b/config.ru new file mode 100644 index 000000000..bd83b2541 --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 000000000..20568697a --- /dev/null +++ b/config/application.rb @@ -0,0 +1,26 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module ApiMuncher + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + + # Do not swallow errors in after_commit/after_rollback callbacks. + config.active_record.raise_in_transactional_callbacks = true + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 000000000..6b750f00b --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,3 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 000000000..1c1a37ca8 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: 5 + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 000000000..ee8d90dc6 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 000000000..b55e2144b --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,41 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 000000000..5c1b32e48 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,79 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 000000000..1c19f08b2 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,42 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static file server for tests with Cache-Control for performance. + config.serve_static_files = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Randomize the order test cases are executed. + config.active_support.test_order = :random + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 000000000..01ef3e663 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 000000000..59385cdf3 --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 000000000..7f70458de --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 000000000..ac033bf9d --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 000000000..dc1899682 --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 000000000..6cc0e03e4 --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_api-muncher_session' diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 000000000..33725e95f --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 000000000..065395716 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 000000000..3f66539d5 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,56 @@ +Rails.application.routes.draw do + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". + + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end +end diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 000000000..a108404b1 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: e59a61bddc16f8b9ab57dec201f471751b5092e7e67fa1d34966becd911bc8631a2d3571b8377f1942f6bc49c94f9a7f3f2882ba32ad23f1cfd5f77a0705f583 + +test: + secret_key_base: 8c5b73b38d17c66141d15930a76f2c81c2ee5745ef15c90918bb5f1425a33fbc362a5ed9d647906dc24913738a4e8ee4574ab783fbb69078176132595bf3954d + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 000000000..4edb1e857 --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +# +# Examples: +# +# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) +# Mayor.create(name: 'Emanuel', city: cities.first) diff --git a/lib/assets/.keep b/lib/assets/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/log/.keep b/log/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/public/404.html b/public/404.html new file mode 100644 index 000000000..b612547fc --- /dev/null +++ b/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/422.html b/public/422.html new file mode 100644 index 000000000..a21f82b3b --- /dev/null +++ b/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/500.html b/public/500.html new file mode 100644 index 000000000..061abc587 --- /dev/null +++ b/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 000000000..e69de29bb diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 000000000..3c9c7c01f --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,5 @@ +# See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file +# +# To ban all spiders from the entire site uncomment the next two lines: +# User-agent: * +# Disallow: / diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/.keep b/test/fixtures/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 000000000..92e39b2d7 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,10 @@ +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../../config/environment', __FILE__) +require 'rails/test_help' + +class ActiveSupport::TestCase + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... +end diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep new file mode 100644 index 000000000..e69de29bb diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep new file mode 100644 index 000000000..e69de29bb From 7965f33684287d0d38e6de86754ff940e09caaea Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Tue, 1 Nov 2016 12:15:30 -0700 Subject: [PATCH 03/14] setting up basic routes/controllers/view for #index --- .gitignore | 3 ++ Gemfile | 15 ++++++ Gemfile.lock | 54 ++++++++++++++++++++ app/assets/javascripts/recipes.coffee | 3 ++ app/assets/stylesheets/recipes.scss | 3 ++ app/controllers/recipes_controller.rb | 6 +++ app/helpers/application_helper.rb | 2 + app/helpers/recipes_helper.rb | 2 + app/views/recipes/index.html.erb | 3 ++ config/routes.rb | 5 ++ lib/assets/attibution_edamam.png | Bin 0 -> 5274 bytes test/controllers/recipes_controller_test.rb | 19 +++++++ test/test_helper.rb | 15 ++++++ 13 files changed, 130 insertions(+) create mode 100644 app/assets/javascripts/recipes.coffee create mode 100644 app/assets/stylesheets/recipes.scss create mode 100644 app/controllers/recipes_controller.rb create mode 100644 app/helpers/recipes_helper.rb create mode 100644 app/views/recipes/index.html.erb create mode 100644 lib/assets/attibution_edamam.png create mode 100644 test/controllers/recipes_controller_test.rb diff --git a/.gitignore b/.gitignore index e422e0120..110936ade 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,7 @@ !/log/.keep /tmp .DS_Store + +# SECRETS .env +/test/cassettes/ diff --git a/Gemfile b/Gemfile index 13d617ca2..a12cfa0e6 100644 --- a/Gemfile +++ b/Gemfile @@ -32,10 +32,21 @@ gem 'sdoc', '~> 0.4.0', group: :doc # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +# API GEMS +gem 'httparty' + +gem 'foundation-rails' + + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' gem 'better_errors' + gem 'dotenv-rails' + + gem 'minitest-vcr' + gem 'webmock' + end group :development do @@ -45,3 +56,7 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end + +group :test do + gem 'minitest-reporters' +end diff --git a/Gemfile.lock b/Gemfile.lock index c1dccfc10..30144d0e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,11 +36,22 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.4.0) + ansi (1.5.0) arel (6.0.3) + babel-source (5.8.35) + babel-transpiler (0.7.0) + babel-source (>= 4.0, < 6) + execjs (~> 2.0) + better_errors (2.1.1) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) builder (3.2.2) byebug (9.0.6) + coderay (1.1.1) coffee-rails (4.1.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.1.x) @@ -49,11 +60,24 @@ GEM execjs coffee-script-source (1.10.0) concurrent-ruby (1.0.2) + crack (0.4.3) + safe_yaml (~> 1.0.0) debug_inspector (0.0.2) + dotenv (2.1.1) + dotenv-rails (2.1.1) + dotenv (= 2.1.1) + railties (>= 4.0, < 5.1) erubis (2.7.0) execjs (2.7.0) + foundation-rails (6.2.4.0) + railties (>= 3.1.0) + sass (>= 3.3.0, < 3.5) + sprockets-es6 (>= 0.9.0) globalid (0.3.7) activesupport (>= 4.1.0) + hashdiff (0.3.0) + httparty (0.14.0) + multi_xml (>= 0.5.2) i18n (0.7.0) jbuilder (2.6.0) activesupport (>= 3.0.0, < 5.1) @@ -71,8 +95,20 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_portile2 (2.1.0) + minispec-metadata (2.0.0) + minitest minitest (5.9.1) + minitest-reporters (1.1.12) + ansi + builder + minitest (>= 5.0) + ruby-progressbar + minitest-vcr (1.4.0) + minispec-metadata (~> 2.0) + minitest (>= 4.7.5) + vcr (>= 2.9) multi_json (1.12.1) + multi_xml (0.5.5) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) rack (1.6.4) @@ -105,6 +141,8 @@ GEM rake (11.3.0) rdoc (4.2.2) json (~> 1.4) + ruby-progressbar (1.8.1) + safe_yaml (1.0.4) sass (3.4.22) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -120,6 +158,10 @@ GEM sprockets (3.7.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) + sprockets-es6 (0.9.2) + babel-source (>= 5.8.11) + babel-transpiler + sprockets (>= 3.0.0) sprockets-rails (3.2.0) actionpack (>= 4.0) activesupport (>= 4.0) @@ -135,20 +177,31 @@ GEM thread_safe (~> 0.1) uglifier (3.0.3) execjs (>= 0.3.0, < 3) + vcr (3.0.3) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) + webmock (2.1.0) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff PLATFORMS ruby DEPENDENCIES + better_errors byebug coffee-rails (~> 4.1.0) + dotenv-rails + foundation-rails + httparty jbuilder (~> 2.0) jquery-rails + minitest-reporters + minitest-vcr rails (= 4.2.7) sass-rails (~> 5.0) sdoc (~> 0.4.0) @@ -157,6 +210,7 @@ DEPENDENCIES turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) + webmock BUNDLED WITH 1.13.6 diff --git a/app/assets/javascripts/recipes.coffee b/app/assets/javascripts/recipes.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/app/assets/javascripts/recipes.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/recipes.scss b/app/assets/stylesheets/recipes.scss new file mode 100644 index 000000000..1e10ffa50 --- /dev/null +++ b/app/assets/stylesheets/recipes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the recipes controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb new file mode 100644 index 000000000..99044569d --- /dev/null +++ b/app/controllers/recipes_controller.rb @@ -0,0 +1,6 @@ +class RecipesController < ApplicationController + +def index + +end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..6e9385e59 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ module ApplicationHelper + + end diff --git a/app/helpers/recipes_helper.rb b/app/helpers/recipes_helper.rb new file mode 100644 index 000000000..f526316e2 --- /dev/null +++ b/app/helpers/recipes_helper.rb @@ -0,0 +1,2 @@ +module RecipesHelper +end diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb new file mode 100644 index 000000000..115f26cae --- /dev/null +++ b/app/views/recipes/index.html.erb @@ -0,0 +1,3 @@ +

+ This is the index page +

diff --git a/config/routes.rb b/config/routes.rb index 3f66539d5..af3291132 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,9 @@ Rails.application.routes.draw do + + get '/' => 'recipes#index' + + # get '/:id' => 'recipes#show' + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/lib/assets/attibution_edamam.png b/lib/assets/attibution_edamam.png new file mode 100644 index 0000000000000000000000000000000000000000..68a62660b1418e86d35572769f83b24ded754b6d GIT binary patch literal 5274 zcmaJ_by$=8-`+?C5f30Cf;bw9jY*9TfeAypq}jj?#$b#ZC@3CELZzey=?)PI0Tp2& zB`F=!9fxwni|2RF`MrO<=Y6j0dA@Po_x-8+uP0nzPm6)>8XW)tV1R3D7@n^Q=kLu6 zH0NLWZbOOlg@bU%oM41=BKX+jQ2($J#ri3{mz-KaX~l0suhCgElrNm?Lyy zjySBi{V$BTFV_8>4FD)8`?}jZx}XR=4k%}|n<8klz6r#GMk<2Lq!3_)yE^ItTAPSR z84>l29f>ZEa!8P}5|4r}>|6kgBG~izVqM)lVZMr>KXqZ}`(M`*Af7)V1Q$inf08ms z=<}%K@F*TBaj=*pSQ^YD4H1VxZ_CKYi1J8+Az%rxqy$7#3?c)AO2WWkp1&T@c{DuI z31+CF`B$v-lOpH=f#434knr*G5%+)&0}e}E(4 zJRjiPdDM-hc+AjlNSu%7pJ)UE26yu$*tplI`_`6?LVeHKm22Rl-s%2@#m(# zOQbIa0Dijy*HAU~9bHSMe{X7%)HXaymYF^nUTdfdorxd!#1^f*#v3 z_eh^CnfSc*2!C8N&?IOi$wZpTNwrXqXrr|VbJY8uJN4qzX^DI*M98_IDVEOs-tUL z;=;LqWW%*%1ziy!t{;ldm!xAM^t~V z1CWxH8LcNYwTyl?t{hiP&BA3s85CBD%$~9b%Q}^1m67webz zf>2aFjsd9&3RhNZhiK zMr_q1QPx|wa%9Py%Lx@Q=K7@&61g&h!RLvJSeM9Ts0O>vvB{8zOcNk~_{FJZsY7R= zk5)0tgrS43|MIumrbVb}OXY{63FLjPCnW>&dpn@$7A_LY_XQzjFgUDu9~qwjS$YR7 zEw<^W0opcV>;TOVq(N! zuLjr8DyTDf>%m{;h7eL7x>!G;*L}Kv4aA?x+CP5ON+3XHq4+KO+1` zmJhYLSoMNPIf8M`6!IlMO7dASw&B+EGyV;0D>LjATY@i}I zhO|ya zVW?u!D)6#_Qnl#5fsKq-9J%shFj&go{}P*OQ-X)I#X&hY+{OZ>=b3@{L7a8 zZm_p-h>-o5%VQ%{7A}VPO52T!28+EjM3|stGX?>J?sL4^s-3n+gKr>-Acl;DpszPj zJLbE)M|m2$oYUJ+PL65bMI|?nsy|uVO}q4Jw8XVd)}Q&pcZJ@=n1*#Dr!R{P>!x_tm>U<0hvqkVfUhktb5;!KSooN7>3#bm1p9wsAR16U%s<}kFxs5vY$oD4`%;TtPG*teWX{(Ui*_f4{* zhc#uHezP5x&^}|vb0G=U%f}R1GlKHZ-jlD|QM@eZcr8!wf3t6c_R0M(0l(uhdoa9e z$4iDk?yc;myr_}lxaGWhiFi$TgYs=mXK$>1_68QO0Y)SzO-_ojZ=;MvSywh9c;~Yz z{F=gHRzG6aJFYmVdl3C3CJ{lHuRv{!NrR5p@1b+4tXo1JO*K!%dL2B_@f6h z47xQZi!sfWfzt7eg9(p*~90Ql*tceFC9_h!@5K2iWc?m9DRh<^^M@&(9C!tynd-z4Dagm zWy>=2%3Iar3SYSkL^L#41E1%;IG}EOQ$UG~SP1MilXow3r(&oN?H2wfXH*hiGa?@j zFexyWzF${!jX5v3x(G`)*u&RJLa7^4FhjJ;~I7=thsoD8*Mx+nKlte?O&&owMjg z+#cia%4MgTvp9z4(vwuu?otY8TJ~tL~{sF$eDp%qgxsR?_k8G3>n{qy-NZx?__GNX>ExPTpcU zp`qT9q$b@VX}zcc;bdl9W9Mow`O)Kz!FXEzvhUYywW52yr(8c})-z%zG*xR_4xx+2 zHwJZ41H@QL|I!JQg22S$1)^IOb*7@ujQbP2oUT}7jK+&~)(qB`6<_A(oSJSh!lB3I2c zq+@rSw*&N&hp5V@+-KFlzT8WaXiL1Y&yD!0*O#tsX^h$j6uu26SEw|^9*)&YXv>q% zf=_qS;-#H@0m?9^(M!*Ysk??@Lr)%J&+sp-pouxF_QF_)`V`$)MBu*A0{+$(=(7UaGC0Ecz1nQgS(`I%`n*PM5v1K>oBhfa(vpx9VC}jOLwH6Q7*ap~0a^z9UgD(Kw}!Cuh4S2BOS; zZmjarlHycb7rm@?PWop_qC8!A8wKI%ZuYI)7xS|i+Ikx}F0FaADAQ;=Q@&OAO{X9+ zSs3dNVLBSjMn#(Wd)WH|UhIhHrYdc)IVUt$d7GY)b7Hc&s z>PcCWW&B;LbIRcjZ90v3+^njJYgF#`i6pn}t)(4&@TgK{;2rw~0=3m-6Z5K_LdoVA z);dl(laWTK4-an}MVsy-^6MULkb#ps!!k5F*(YkqfCpt#79 z@SF~bnk3f|z?i=h@{lf9VXY=tFsnT$e=_xCZTe~jgC?;+5K{7)-V01^TUVV2zAsNF zwvFeQ7E42^nCy#`=SW>{6m`kXGU(BaN@r#3WM<+=T`Z5=F8|T#PIJl{Xr*O-v+{7l?z^Bec{WT35_uLGMA@TTQ@T-D^mw?&t+}wHl-jm@Yc+TKsaTRYlREC~G z%&tOwW%Q4u2P&-^H*IfT)0_;SPS1sCISkdiB-_MphcP=`Ydp{ zFA&=~uV&qY!fTyS|oM@_46%|C(%axfz843i9nkA{}*Yzr~E z#={cNHw(K4^Du4=mEE${k2RME3vqn(nr|i4+1IXBr%0j-4d_~koSH>x1EnI{x$DJF zT18^-V>o;tlv+x(6`tjrqJpe{`06BzM+=0Qu%~qZTqle_YLYsa_TQxfanV41X_4>q z)pwmv59^hTR`w|8X)Syboj*FoE*)0A;!mNv@QLZ+{lcRWk1#Ov1M3vNbj5CAmNj*8 zx=6J{0Ofcq+2hg>%i@XUs{v_O!vkyywdvb^gfvvpj={@aS@}J8CyR}>E@z@PCvXsT z>__!{JZ)=YV2`y!KFhQ#mrNZCg#y34nPc|fZ)#B##ORu9854CNN}2$E$IgQ?iX}CX z(q0GU)VMye@(F`aaRYu4Z@H!!f+w87a+Z+R(*3I8-+@GTdH)Mv2ZVi+o;V`9CoOX{ zPe-jrVf80Aw0kS5SSd3zZ?CD|G`bGP2Mx!~)0@?ep?DFuObT2U`~$n7K;OBw`0Nky2lpZ@7pA24yg#$kGMx=O zxEK!0`_?LBmws@v?TW?*Qh1fKyMKchMXyF-gZ=4w;vdn$$JlB zmxCFBo`%kGF4se{(;^h59FI=@~?XCmKm&6ov8Ze?*jh8&{@x~r@2*1=)MDr$nGve5$l;r+;McD5`OiN>kQ z8Eg>svWe3q$td`f$Qy%dHo7XqZfxgPD1TZ*Ss_!R2m&AYLf3j}>0lf&)=U*>JgE~$O??v%$Z9JW$?9Wc|wWD;O`)5^A!)b$w@{H4> zIl;fzF3^8(Q3PI3M~I9(PV)SUnr{uV+>jX?IHn7E-%6e0;S(zOV9I#(Z6brWYh_VA z^|3e=X;wk(b&J3E9&N*rOs1J+(5=CRL!IyF8|KTgfF(M17fRmV_6r0+>1dJr-S0^g zjI;P%!siW;6i)qpqoo}A>b~Zu9}h)~0?l2q8$B|Q_voIm_dNQ-rqGRR1E1C2dX~v7 j6JXi3)%W>~9t? :new_episodes, # record new data when we don't have it yet + :match_requests_on => [:method, :uri, :body] # The http method, URI and body of a request all need to match + } +end + class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. From bb06c6dcefc134732b390a57f2b10ba5af361532 Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Tue, 1 Nov 2016 12:17:33 -0700 Subject: [PATCH 04/14] added .env to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 050c9d95c..cad61db0b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ /log/* !/log/.keep /tmp + +.env From b0d3253e787cedc4b2714536afa53d912288f2be Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Tue, 1 Nov 2016 14:10:01 -0700 Subject: [PATCH 05/14] WIP setting up API. Next pass first test. --- app/controllers/recipes_controller.rb | 5 +-- db/schema.rb | 16 +++++++++ lib/edamam_api_wrapper.rb | 52 +++++++++++++++++++++++++++ test/lib/edamam_api_wrapper_test.rb | 52 +++++++++++++++++++++++++++ test/test_helper.rb | 3 ++ 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 db/schema.rb create mode 100644 lib/edamam_api_wrapper.rb create mode 100644 test/lib/edamam_api_wrapper_test.rb diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 99044569d..af9e1badd 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -1,6 +1,7 @@ class RecipesController < ApplicationController -def index + def index -end + end + end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..4dfbb1680 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,16 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 0) do + +end diff --git a/lib/edamam_api_wrapper.rb b/lib/edamam_api_wrapper.rb new file mode 100644 index 000000000..1e2ee21cc --- /dev/null +++ b/lib/edamam_api_wrapper.rb @@ -0,0 +1,52 @@ +require 'httparty' + +class SlackApiWrapper + BASE_URL = "https://api.edamam.com/search" + THE_KEY = ENV["EDAMAM_KEY"] + THE_ID = ENV["EDAMAM_ID"] + + def self.list_recipes +# "https://api.edamam.com/search?q=chicken&app_id=${YOUR_APP_ID}&app_key=${YOUR_APP_KEY}" +# note that there are curly brackets above not in the variable below + url = BASE_URL + "search.list?" + "_id=$#{THE_ID}&app_key=$#{THE_KEY}" + data = HTTParty.get(url) + search_list = [] + if data["search_results"] + data["search_results"].each do |recipe| + wrapper = Recipe.new(recipe["name"], recipe["id"], ) + end + + end + + # BASE_URL = "https://slack.com/api/" + # TOKEN = ENV["SLACK_TOKEN"] + # + # def self.listchannels() + # url = BASE_URL + "channels.list?" + "token=#{TOKEN}" + "&pretty=1&exclude_archived=1" + # data = HTTParty.get(url) + # channel_list = [] + # if data["channels"] + # data["channels"].each do |channel| + # wrapper = Channel.new channel["name"], channel["id"] , purpose: channel["purpose"], is_archived: channel["is_archived"], members: channel["members"] + # channel_list << wrapper + # end + # end + # return channel_list + # end + # + # def self.sendmsg(channel, msg, token = nil) + # puts "Sending message to channel #{channel}: #{msg}" + # + # url = BASE_URL + "chat.postMessage?" + "token=#{TOKEN}" + # data = HTTParty.post(url, + # body: { + # "text" => "#{msg}", + # "channel" => "#{channel}", + # "username" => "Goldie", + # "icon_emoji" => ":star2:", + # "as_user" => "false" + # }, + # :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }) + # end + +end diff --git a/test/lib/edamam_api_wrapper_test.rb b/test/lib/edamam_api_wrapper_test.rb new file mode 100644 index 000000000..9e3eda30d --- /dev/null +++ b/test/lib/edamam_api_wrapper_test.rb @@ -0,0 +1,52 @@ +class EdamamApiWrapperTest < ActiveSupport::TestCase + +#slack listchannels + test "list_recipes returns array of recipes" do + VCR.use_cassette("recipes") do + recipes = EdamamApiWrapper.list_recipes + puts recipes.first + assert_kind_of Array, recipes + recipes.each do |recipe| + assert_kind_of Recipe, recipe + end + end + end + + # test "listchannels returns array of channels" do + # VCR.use_cassette("channels") do + # channels = SlackApiWrapper.listchannels + # assert_kind_of Array, channels + # channels.each do |channel| + # assert_kind_of Channel, channel + # end + # end + # end + + +# slackapi sendmsg + # test "Can send a search query and get a valid response" do + # VCR.use_cassette("recipes") do + # search = "cilantro" + # response = EdamamApiWrapper. + # end + # + # end + # test "Can send valid message to real channel" do + # VCR.use_cassette("channels") do + # message = "This is a test. One. Two. Three. End of testing." + # response = SlackApiWrapper.sendmsg("test-api-brackets", message) + # assert response["ok"] + # assert_equal response["message"]["text"], message + # end + # end + # + # test "Can't send message to fake channel" do + # VCR.use_cassette("channels") do + # response = SlackApiWrapper.sendmsg("this-channel-does-not-exist", "test message") + # assert_not response["ok"] + # assert_not_nil response["error"] + # end + # end + # + +end diff --git a/test/test_helper.rb b/test/test_helper.rb index de24b6c59..1754bd676 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,9 +3,12 @@ require 'rails/test_help' require "minitest/reporters" + +# For API set-up require 'vcr' require 'webmock/minitest' + VCR.configure do |config| config.cassette_library_dir = 'test/cassettes' # folder where casettes will be located config.hook_into :webmock # tie into this other tool called webmock From a6ccdd2b7751986c9cca0b8260f29cfa16a51f56 Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Wed, 2 Nov 2016 11:15:24 -0700 Subject: [PATCH 06/14] list_recipe method works if method has a manipulated search string inserted --- config/application.rb | 5 +++++ lib/edamam_api_wrapper.rb | 27 +++++++++++++++++---------- lib/recipe.rb | 5 +++++ test/lib/edamam_api_wrapper_test.rb | 16 +++------------- test/lib/recipe_test.rb | 0 5 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 lib/recipe.rb create mode 100644 test/lib/recipe_test.rb diff --git a/config/application.rb b/config/application.rb index 20568697a..37e26bf37 100644 --- a/config/application.rb +++ b/config/application.rb @@ -22,5 +22,10 @@ class Application < Rails::Application # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true + +# DONT FORGET to add the lib + # Automatically load all code from /lib + config.autoload_paths << Rails.root.join('lib') + end end diff --git a/lib/edamam_api_wrapper.rb b/lib/edamam_api_wrapper.rb index 1e2ee21cc..3fc7f52ae 100644 --- a/lib/edamam_api_wrapper.rb +++ b/lib/edamam_api_wrapper.rb @@ -1,21 +1,28 @@ require 'httparty' -class SlackApiWrapper +class EdamamApiWrapper BASE_URL = "https://api.edamam.com/search" THE_KEY = ENV["EDAMAM_KEY"] THE_ID = ENV["EDAMAM_ID"] + # attr_reader :data + def self.list_recipes -# "https://api.edamam.com/search?q=chicken&app_id=${YOUR_APP_ID}&app_key=${YOUR_APP_KEY}" -# note that there are curly brackets above not in the variable below - url = BASE_URL + "search.list?" + "_id=$#{THE_ID}&app_key=$#{THE_KEY}" - data = HTTParty.get(url) - search_list = [] - if data["search_results"] - data["search_results"].each do |recipe| - wrapper = Recipe.new(recipe["name"], recipe["id"], ) + url = BASE_URL + "?q=#{search_string}" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" + # url = BASE_URL + "?q=chicken" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" + puts "URL: #{url}" + data = HTTParty.get(url) #.parsed_response + search_results = [] # was called the search_list + if data["hits"] + data["hits"].each do |hit| + wrapper = Recipe.new(hit["recipe"]["label"], hit["recipe"]["image"], hit["recipe"]["url"]) + # label is recipe title + # url is url for original recipe + # image is image of recipe item + search_results << wrapper end - + end + return search_results end # BASE_URL = "https://slack.com/api/" diff --git a/lib/recipe.rb b/lib/recipe.rb new file mode 100644 index 000000000..bbc92d284 --- /dev/null +++ b/lib/recipe.rb @@ -0,0 +1,5 @@ +# tests first +class Recipe + def initialize(title, image, url) + end +end diff --git a/test/lib/edamam_api_wrapper_test.rb b/test/lib/edamam_api_wrapper_test.rb index 9e3eda30d..d234803ad 100644 --- a/test/lib/edamam_api_wrapper_test.rb +++ b/test/lib/edamam_api_wrapper_test.rb @@ -1,10 +1,10 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase -#slack listchannels - test "list_recipes returns array of recipes" do +#slack equivalent listchannels +# this test passes when search_string is inserted into list_recipes + test "list_recipes returns array of recipes when it has a search string" do VCR.use_cassette("recipes") do recipes = EdamamApiWrapper.list_recipes - puts recipes.first assert_kind_of Array, recipes recipes.each do |recipe| assert_kind_of Recipe, recipe @@ -12,16 +12,6 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase end end - # test "listchannels returns array of channels" do - # VCR.use_cassette("channels") do - # channels = SlackApiWrapper.listchannels - # assert_kind_of Array, channels - # channels.each do |channel| - # assert_kind_of Channel, channel - # end - # end - # end - # slackapi sendmsg # test "Can send a search query and get a valid response" do diff --git a/test/lib/recipe_test.rb b/test/lib/recipe_test.rb new file mode 100644 index 000000000..e69de29bb From 83bc95b47d238f4cf3ce77c87f485c992000275a Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Wed, 2 Nov 2016 16:38:13 -0700 Subject: [PATCH 07/14] Recipe class and APIwrapper implemented and searches can be preformed from console, some testing --- app/controllers/recipes_controller.rb | 9 +++- config/routes.rb | 2 + lib/edamam_api_wrapper.rb | 53 +++++++-------------- lib/recipe.rb | 12 +++++ test/controllers/recipes_controller_test.rb | 8 ---- test/lib/edamam_api_wrapper_test.rb | 48 +++++++++---------- test/lib/recipe_test.rb | 26 ++++++++++ 7 files changed, 87 insertions(+), 71 deletions(-) diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index af9e1badd..ba9e24977 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -1,7 +1,14 @@ +# require 'EdamamApiWrapper' +# require 'recipe' + class RecipesController < ApplicationController def index end - + + # def search + # + # end + end diff --git a/config/routes.rb b/config/routes.rb index 76e12b000..1b15d230f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,8 @@ get '/' => 'recipes#index' + get '/search' => 'recipes#search' + # get '/:id' => 'recipes#show' # The priority is based upon order of creation: first created -> highest priority. diff --git a/lib/edamam_api_wrapper.rb b/lib/edamam_api_wrapper.rb index 3fc7f52ae..570ebb889 100644 --- a/lib/edamam_api_wrapper.rb +++ b/lib/edamam_api_wrapper.rb @@ -5,16 +5,16 @@ class EdamamApiWrapper THE_KEY = ENV["EDAMAM_KEY"] THE_ID = ENV["EDAMAM_ID"] - # attr_reader :data + attr_reader :data - def self.list_recipes - url = BASE_URL + "?q=#{search_string}" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" + def self.list_recipes(clean_string) + url = BASE_URL + "?q=#{clean_string}" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" # url = BASE_URL + "?q=chicken" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" - puts "URL: #{url}" - data = HTTParty.get(url) #.parsed_response + puts "list_recipes URL: #{url}" + @data = HTTParty.get(url) #.parsed_response search_results = [] # was called the search_list - if data["hits"] - data["hits"].each do |hit| + if @data["hits"] + @data["hits"].each do |hit| wrapper = Recipe.new(hit["recipe"]["label"], hit["recipe"]["image"], hit["recipe"]["url"]) # label is recipe title # url is url for original recipe @@ -25,35 +25,14 @@ def self.list_recipes return search_results end - # BASE_URL = "https://slack.com/api/" - # TOKEN = ENV["SLACK_TOKEN"] - # - # def self.listchannels() - # url = BASE_URL + "channels.list?" + "token=#{TOKEN}" + "&pretty=1&exclude_archived=1" - # data = HTTParty.get(url) - # channel_list = [] - # if data["channels"] - # data["channels"].each do |channel| - # wrapper = Channel.new channel["name"], channel["id"] , purpose: channel["purpose"], is_archived: channel["is_archived"], members: channel["members"] - # channel_list << wrapper - # end - # end - # return channel_list - # end - # - # def self.sendmsg(channel, msg, token = nil) - # puts "Sending message to channel #{channel}: #{msg}" - # - # url = BASE_URL + "chat.postMessage?" + "token=#{TOKEN}" - # data = HTTParty.post(url, - # body: { - # "text" => "#{msg}", - # "channel" => "#{channel}", - # "username" => "Goldie", - # "icon_emoji" => ":star2:", - # "as_user" => "false" - # }, - # :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }) - # end +# restrictions on search queries @todo + def self.query_sanitation(search_string) + puts "Requesting #{search_string} from Edamam database" + # Need to clean the string up + clean_string = search_string + # Used by the recipe controller action + return clean_string + end + end diff --git a/lib/recipe.rb b/lib/recipe.rb index bbc92d284..eaa114e20 100644 --- a/lib/recipe.rb +++ b/lib/recipe.rb @@ -1,5 +1,17 @@ # tests first class Recipe + attr_reader :title, :image, :url + def initialize(title, image, url) + @title = title + @image = image + @url = url end + + def self.search_results(search_query) + # clean up the search string + clean_query = search_query.split.first.gsub(/[^a-zA-Z]/, '') + return EdamamApiWrapper.list_recipes(clean_query) + end + end diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb index ec62e78f4..806a1976e 100644 --- a/test/controllers/recipes_controller_test.rb +++ b/test/controllers/recipes_controller_test.rb @@ -7,13 +7,5 @@ class RecipesControllerTest < ActionController::TestCase assert_response :success end -# @todo once the API is set up - test "the index must have access to recipes (instance variable)" do - - - get :index - - - end end diff --git a/test/lib/edamam_api_wrapper_test.rb b/test/lib/edamam_api_wrapper_test.rb index d234803ad..7cf52191f 100644 --- a/test/lib/edamam_api_wrapper_test.rb +++ b/test/lib/edamam_api_wrapper_test.rb @@ -1,10 +1,12 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase #slack equivalent listchannels -# this test passes when search_string is inserted into list_recipes +# this is for the greyed out version of list_recipes +# this test passes when search_query is inserted into list_recipes test "list_recipes returns array of recipes when it has a search string" do VCR.use_cassette("recipes") do - recipes = EdamamApiWrapper.list_recipes + clean_string = "cilantro" + recipes = EdamamApiWrapper.list_recipes(clean_string) assert_kind_of Array, recipes recipes.each do |recipe| assert_kind_of Recipe, recipe @@ -12,31 +14,27 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase end end + # slackapi sendmsg equivalent + # query_sanitation should return the recipes matching the first word in the string typed in + test "Can send a search query and get a valid response" do + VCR.use_cassette("hits") do + search_string = "cilantro" + response = EdamamApiWrapper.query_sanitation(search_string) + assert_equal(response, "cilantro") # because cilantro is the sanitized version of itself + end + end -# slackapi sendmsg - # test "Can send a search query and get a valid response" do - # VCR.use_cassette("recipes") do - # search = "cilantro" - # response = EdamamApiWrapper. +# PUT THIS IN LATER + # test "Will only return the search query using the first word letters from the search_query" do + # VCR.use_cassette("hits") do + # search_string = "cilantro, edamame and caramel" + # response = EdamamApiWrapper.search_query(search_string) + # assert_equal response["q"], "cilantro" # end - # # end - # test "Can send valid message to real channel" do - # VCR.use_cassette("channels") do - # message = "This is a test. One. Two. Three. End of testing." - # response = SlackApiWrapper.sendmsg("test-api-brackets", message) - # assert response["ok"] - # assert_equal response["message"]["text"], message - # end - # end - # - # test "Can't send message to fake channel" do - # VCR.use_cassette("channels") do - # response = SlackApiWrapper.sendmsg("this-channel-does-not-exist", "test message") - # assert_not response["ok"] - # assert_not_nil response["error"] - # end - # end - # + # test "Will not send a query for searches not starting on a letter character" do + # assert false + # assert_nil true # ? + # end end diff --git a/test/lib/recipe_test.rb b/test/lib/recipe_test.rb index e69de29bb..07722f5f2 100644 --- a/test/lib/recipe_test.rb +++ b/test/lib/recipe_test.rb @@ -0,0 +1,26 @@ +require 'test_helper' + +class RecipeTest < ActiveSupport::TestCase + test "Recipe.search_results should return an array of recipes with a given search_query" do + VCR.use_cassette("hits") do + clean_string = "cilantro" + recipes = Recipe.search_results(clean_string) + assert_kind_of Array, recipes + assert_not recipes.empty? + recipes.each do |recipe| + assert_kind_of Recipe, recipe + end + end + end + +# #search_results returns the information needed for this application only, we can't test this because I am not asking for query information in my API request +# test "search_results should return the results for the first word in a query" do +# VCR.use_cassette("hits") do +# search_query = "cilantro, edamame and caramel" +# response = Recipe.search_results(search_query) +# +# assert false +# # assert_equal(response["q"], "cilantro") +# end +# end +end From 4958795ab0a3d739b947e2f9d67c651e359b09e5 Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Thu, 3 Nov 2016 15:06:13 -0700 Subject: [PATCH 08/14] Tests ensures only valid search queries get through to wrapper. List view at recipes#index set up with basic html and content. Working on pagation-search and list view. --- .../assets/images}/attibution_edamam.png | Bin app/assets/javascripts/home.coffee | 3 ++ app/assets/stylesheets/home.scss | 3 ++ app/controllers/home_controller.rb | 5 +++ app/controllers/recipes_controller.rb | 31 ++++++++++++++++-- app/helpers/home_helper.rb | 2 ++ app/helpers/recipes_helper.rb | 9 +++++ app/views/home/index.html.erb | 19 +++++++++++ app/views/layouts/application.html.erb | 10 +++++- app/views/recipes/index.html.erb | 18 +++++++++- config/routes.rb | 4 ++- lib/edamam_api_wrapper.rb | 21 +++++++----- lib/recipe.rb | 19 +++++++---- test/controllers/home_controller_test.rb | 8 +++++ test/controllers/recipes_controller_test.rb | 23 +++++++++++-- test/helpers/recipes_helper_test.rb | 11 +++++++ test/lib/recipe_test.rb | 12 +++++++ 17 files changed, 176 insertions(+), 22 deletions(-) rename {lib/assets => app/assets/images}/attibution_edamam.png (100%) create mode 100644 app/assets/javascripts/home.coffee create mode 100644 app/assets/stylesheets/home.scss create mode 100644 app/controllers/home_controller.rb create mode 100644 app/helpers/home_helper.rb create mode 100644 app/views/home/index.html.erb create mode 100644 test/controllers/home_controller_test.rb create mode 100644 test/helpers/recipes_helper_test.rb diff --git a/lib/assets/attibution_edamam.png b/app/assets/images/attibution_edamam.png similarity index 100% rename from lib/assets/attibution_edamam.png rename to app/assets/images/attibution_edamam.png diff --git a/app/assets/javascripts/home.coffee b/app/assets/javascripts/home.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/app/assets/javascripts/home.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss new file mode 100644 index 000000000..f0ddc6846 --- /dev/null +++ b/app/assets/stylesheets/home.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the home controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb new file mode 100644 index 000000000..6e81b3963 --- /dev/null +++ b/app/controllers/home_controller.rb @@ -0,0 +1,5 @@ +class HomeController < ApplicationController + + def index; end + +end diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index ba9e24977..3596ee059 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -4,11 +4,36 @@ class RecipesController < ApplicationController def index + search_string = recipe_params[:q] + if @page == nil + @page = 0 + elsif @page >=0 + @page +=10 + end + @recipes ||= Recipe.search_results(search_string, @page) + end + def search + if params["q"] != "" + # SUCCESS + search_string = recipe_params[:q] + @recipes = Recipe.search_results(search_string) + unless @recipes.empty? + render :index + return + end + # else + end + flash[:notice] = "Please enter a valid search term" + redirect_to root_path end - # def search - # - # end +private + +# undefined method `permit' for "cilantro":String +def recipe_params + params.permit(:q) +end + end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb new file mode 100644 index 000000000..23de56ac6 --- /dev/null +++ b/app/helpers/home_helper.rb @@ -0,0 +1,2 @@ +module HomeHelper +end diff --git a/app/helpers/recipes_helper.rb b/app/helpers/recipes_helper.rb index f526316e2..f32adbb37 100644 --- a/app/helpers/recipes_helper.rb +++ b/app/helpers/recipes_helper.rb @@ -1,2 +1,11 @@ module RecipesHelper + def link_selector(recipe) + if recipe.url + return recipe.url + elsif recipe.uri + return recipe.uri + else + return recipes_path + end + end end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb new file mode 100644 index 000000000..a76b4fec4 --- /dev/null +++ b/app/views/home/index.html.erb @@ -0,0 +1,19 @@ + <% if flash[:notice] %> +
+ <%= flash[:notice] %> + <% flash[:notice] = nil %> +
+ <% else %> +

Welcome to the Muncher!

+ <% end %> +
+ <%= form_tag(search_path, method: "get") do %> + <%= label_tag(:q, "Search for:") %> + <%= text_field_tag(:q) %> + <%= submit_tag("Go!") %> + <% end %> +
+ +

+ This is the home#index page +

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 237dbba45..55ccd8d13 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -7,8 +7,16 @@ <%= csrf_meta_tags %> +
-<%= yield %> +
+<%= yield %> +
+
+ <%= link_to "Search", root_path %> + <%= image_tag("attibution_edamam.png", alt: "Powered by Edamam") -%> +
+
diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index 115f26cae..874498174 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -1,3 +1,19 @@ + +
+ <% if @recipes != nil %> + <% listing = 1 %> + <% @recipes.each do |recipe| %> +
+
+ <%= "#{listing}" %> +

<%= link_to(image_tag(recipe.image), image_path(recipe_path(recipe)) ) %>

+ <%= link_to "#{recipe.title}", link_selector(recipe) %> +
+ <% listing +=1 %> +
+ <% end %> + <% end %> +

- This is the index page + This is the recipes#index page

diff --git a/config/routes.rb b/config/routes.rb index 1b15d230f..75339fa41 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,9 @@ Rails.application.routes.draw do + root 'home#index' - get '/' => 'recipes#index' + get '/recipes' => 'recipes#index' + get '/recipes/:id' => 'recipes#show', as: 'recipe' get '/search' => 'recipes#search' diff --git a/lib/edamam_api_wrapper.rb b/lib/edamam_api_wrapper.rb index 570ebb889..c405dee48 100644 --- a/lib/edamam_api_wrapper.rb +++ b/lib/edamam_api_wrapper.rb @@ -7,25 +7,31 @@ class EdamamApiWrapper attr_reader :data - def self.list_recipes(clean_string) - url = BASE_URL + "?q=#{clean_string}" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" + def self.list_recipes(clean_string, page=0) + #gives us the first ten + page_string = "&from=0" + if page !=0 + page_string = "&from=#{page}" + end + url = BASE_URL + "?q=#{clean_string}" + page_string + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" # url = BASE_URL + "?q=chicken" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" - puts "list_recipes URL: #{url}" + # puts "list_recipes URL: #{url}" @data = HTTParty.get(url) #.parsed_response - search_results = [] # was called the search_list + search_results = [] if @data["hits"] @data["hits"].each do |hit| - wrapper = Recipe.new(hit["recipe"]["label"], hit["recipe"]["image"], hit["recipe"]["url"]) + wrapper = Recipe.new(hit["recipe"]["label"], hit["recipe"]["image"], hit["recipe"]["uri"], hit["recipe"]["url"]) # label is recipe title - # url is url for original recipe # image is image of recipe item + # uri is uri for recipe on edamam + # url is url for original recipe search_results << wrapper end end return search_results end -# restrictions on search queries @todo +# restrictions on search queries imposed by Edamam @todo def self.query_sanitation(search_string) puts "Requesting #{search_string} from Edamam database" # Need to clean the string up @@ -34,5 +40,4 @@ def self.query_sanitation(search_string) return clean_string end - end diff --git a/lib/recipe.rb b/lib/recipe.rb index eaa114e20..b6ef7e308 100644 --- a/lib/recipe.rb +++ b/lib/recipe.rb @@ -1,17 +1,24 @@ # tests first class Recipe - attr_reader :title, :image, :url + attr_reader :title, :image, :uri, :url, :clean_query - def initialize(title, image, url) + def initialize(title, image, uri, url) @title = title @image = image + @uri = uri @url = url + # @clean_query = nil end - def self.search_results(search_query) - # clean up the search string - clean_query = search_query.split.first.gsub(/[^a-zA-Z]/, '') - return EdamamApiWrapper.list_recipes(clean_query) + def self.search_results(search_query, page=0) + # clean up the search string first + if search_query != nil + @clean_query = search_query.split.first + unless @clean_query == nil || @clean_query == "" || @clean_query.gsub!(/[^a-zA-Z]/, '') + return EdamamApiWrapper.list_recipes(@clean_query, page) + end + end + return nil end end diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 000000000..873c71e99 --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class HomeControllerTest < ActionController::TestCase + test "should get the index" do + get :index + assert_response :success + end +end diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb index 806a1976e..92072d914 100644 --- a/test/controllers/recipes_controller_test.rb +++ b/test/controllers/recipes_controller_test.rb @@ -3,9 +3,28 @@ class RecipesControllerTest < ActionController::TestCase test "should get the index" do - get :index - assert_response :success + VCR.use_cassette("recipes") do + get :index + assert_response :success + end end + test "search form should have a successful search if search_query is valid" do + VCR.use_cassette("recipes") do + params = {"q" => "cilantro"} + get :search, params + assert_response 200 + assert_template :index + end + end + + test "search form should not redirect to recipes#index if empty" do + VCR.use_cassette("recipes") do + params = {"q" => ""} + get :search, params + assert_redirected_to root_path + end + + end end diff --git a/test/helpers/recipes_helper_test.rb b/test/helpers/recipes_helper_test.rb new file mode 100644 index 000000000..294d2d0a5 --- /dev/null +++ b/test/helpers/recipes_helper_test.rb @@ -0,0 +1,11 @@ +require 'test_helper' + +# Not sure this is included in rake, it gives lots of errors + + # test "link_selector view helper method should not be nil" do + # VCR.use_cassette("recipes") do + # recipe = recipes.first + # recipe.url = nil + # assert_not_nil link_selector(recipe) + # end + # end diff --git a/test/lib/recipe_test.rb b/test/lib/recipe_test.rb index 07722f5f2..448c56d43 100644 --- a/test/lib/recipe_test.rb +++ b/test/lib/recipe_test.rb @@ -1,6 +1,7 @@ require 'test_helper' class RecipeTest < ActiveSupport::TestCase + test "Recipe.search_results should return an array of recipes with a given search_query" do VCR.use_cassette("hits") do clean_string = "cilantro" @@ -13,6 +14,17 @@ class RecipeTest < ActiveSupport::TestCase end end + test "search_results should return nil if the search_query is not valid" do + numbers_string = "1234" + empty_string = "" + nil_that_should_be_a_string = nil + + assert_nil(Recipe.search_results(numbers_string)) + assert_nil(Recipe.search_results(empty_string)) + assert_nil(Recipe.search_results(nil_that_should_be_a_string)) + end + + # #search_results returns the information needed for this application only, we can't test this because I am not asking for query information in my API request # test "search_results should return the results for the first word in a query" do # VCR.use_cassette("hits") do From 2159af66e5c212a3a533c0cec6cf8dbc3187cbed Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Thu, 3 Nov 2016 21:14:25 -0700 Subject: [PATCH 09/14] added get_recipe method and started on recipe#show --- app/controllers/recipes_controller.rb | 19 ++++++---- app/views/recipes/index.html.erb | 19 +++++----- app/views/recipes/show.html.erb | 14 ++++++++ lib/edamam_api_wrapper.rb | 19 +++++++--- lib/recipe.rb | 31 +++++++++++++--- test/controllers/recipes_controller_test.rb | 6 ++++ test/lib/edamam_api_wrapper_test.rb | 40 +++++++++++++-------- test/lib/recipe_test.rb | 12 +++++++ 8 files changed, 121 insertions(+), 39 deletions(-) create mode 100644 app/views/recipes/show.html.erb diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 3596ee059..ed3ab4517 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -5,12 +5,8 @@ class RecipesController < ApplicationController def index search_string = recipe_params[:q] - if @page == nil - @page = 0 - elsif @page >=0 - @page +=10 - end - @recipes ||= Recipe.search_results(search_string, @page) + + @recipes ||= Recipe.search_results(search_string, @listing) end def search @@ -19,6 +15,11 @@ def search search_string = recipe_params[:q] @recipes = Recipe.search_results(search_string) unless @recipes.empty? + if @listing == nil + @listing = 0 + elsif @listing >=0 + @listing +=10 + end render :index return end @@ -28,6 +29,12 @@ def search redirect_to root_path end + def show + show_params = params[:id] + @recipe = Recipe.find(show_params) + raise + end + private # undefined method `permit' for "cilantro":String diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index 874498174..dd1c42fda 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -1,17 +1,18 @@
<% if @recipes != nil %> - <% listing = 1 %> + <% listing_num = @listing + 1 %> <% @recipes.each do |recipe| %> -
-
- <%= "#{listing}" %> -

<%= link_to(image_tag(recipe.image), image_path(recipe_path(recipe)) ) %>

- <%= link_to "#{recipe.title}", link_selector(recipe) %> -
- <% listing +=1 %> -
+
+
+ <%= "#{listing_num}" %> +

<%= link_to(image_tag(recipe.image), image_path(recipe_path(recipe.id)) ) %>

+

<%= link_to "#{recipe.title}", link_selector(recipe) %>

+ <% listing_num +=1 %> +
+
<% end %> + <% end %>

diff --git a/app/views/recipes/show.html.erb b/app/views/recipes/show.html.erb new file mode 100644 index 000000000..2c00843d1 --- /dev/null +++ b/app/views/recipes/show.html.erb @@ -0,0 +1,14 @@ +

+

<%= @recipe.title %>

+
+
+

+ +

+
+
+
+ +

+ This is the recipe#show page +

diff --git a/lib/edamam_api_wrapper.rb b/lib/edamam_api_wrapper.rb index c405dee48..e34e24dd8 100644 --- a/lib/edamam_api_wrapper.rb +++ b/lib/edamam_api_wrapper.rb @@ -7,11 +7,12 @@ class EdamamApiWrapper attr_reader :data - def self.list_recipes(clean_string, page=0) + def self.list_recipes(clean_string, listing=0) + #gives us the first ten page_string = "&from=0" - if page !=0 - page_string = "&from=#{page}" + if listing !=0 + page_string = "&from=#{listing}" end url = BASE_URL + "?q=#{clean_string}" + page_string + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" # url = BASE_URL + "?q=chicken" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" @@ -20,11 +21,14 @@ def self.list_recipes(clean_string, page=0) search_results = [] if @data["hits"] @data["hits"].each do |hit| - wrapper = Recipe.new(hit["recipe"]["label"], hit["recipe"]["image"], hit["recipe"]["uri"], hit["recipe"]["url"]) + wrapper = Recipe.new(listing, hit["recipe"]["label"], hit["recipe"]["image"], hit["recipe"]["uri"], hit["recipe"]["url"], hit["recipe"]["ingredientLines"], hit["recipe"]["dietLabels"]) + listing += 1 # label is recipe title # image is image of recipe item # uri is uri for recipe on edamam # url is url for original recipe + # "ingredientLines" is the array of ingredients + # "dietLabels" is the array of dietary information search_results << wrapper end end @@ -40,4 +44,11 @@ def self.query_sanitation(search_string) return clean_string end + def self.get_recipe(recipe_uri) + url = BASE_URL + "?r=#{URI.encode(recipe_uri)}" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" + @data = HTTParty.get(url) + # check/test for valid return + return Recipe.new(0, @data[0]['label'], @data[0]['image'], @data[0]['uri'], @data[0]['url'], @data[0]['ingredientLines'], @data[0]['dietLabels'] ) + end + end diff --git a/lib/recipe.rb b/lib/recipe.rb index b6ef7e308..5a1162a07 100644 --- a/lib/recipe.rb +++ b/lib/recipe.rb @@ -1,24 +1,45 @@ # tests first class Recipe - attr_reader :title, :image, :uri, :url, :clean_query + attr_reader :title, :image, :uri, :url, :ingredients, :diet_info, :id #, :clean_query - def initialize(title, image, uri, url) + def initialize(listing, title, image, uri, url, ingredients, dietary_info) + @id = listing @title = title @image = image @uri = uri @url = url - # @clean_query = nil + @ingredients = ingredients + @diet_info = dietary_info + @clean_query = nil end - def self.search_results(search_query, page=0) + # The RecipesController will send the listing number, but to remember what it means we call it page here and elsewhere + def self.search_results(search_query, listing=0) # clean up the search string first if search_query != nil @clean_query = search_query.split.first unless @clean_query == nil || @clean_query == "" || @clean_query.gsub!(/[^a-zA-Z]/, '') - return EdamamApiWrapper.list_recipes(@clean_query, page) + return EdamamApiWrapper.list_recipes(@clean_query, listing) end end return nil end +# returns nil if no search query available or if the id is not in use + def self.find(id) + recipes = Recipe.search_results(@clean_query) + recipes.each do |recipe| + if recipe.id == id + #SUCCESS + return recipe + end + end + return nil + end + +# Method makes sure two recipe objects with the same content are the same + def ==(another_recipe) + return self.title == another_recipe.title && self.image == another_recipe.image && self.uri == another_recipe.uri && self.url == another_recipe.url && self.ingredients == another_recipe.ingredients && self.diet_info == another_recipe.diet_info + end + end diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb index 92072d914..dc2846f89 100644 --- a/test/controllers/recipes_controller_test.rb +++ b/test/controllers/recipes_controller_test.rb @@ -24,7 +24,13 @@ class RecipesControllerTest < ActionController::TestCase get :search, params assert_redirected_to root_path end + end + test "should get show" do + VCR.use_cassette("recipes") do + get :show, id: 0 + assert_response :success + end end end diff --git a/test/lib/edamam_api_wrapper_test.rb b/test/lib/edamam_api_wrapper_test.rb index 7cf52191f..0601670b0 100644 --- a/test/lib/edamam_api_wrapper_test.rb +++ b/test/lib/edamam_api_wrapper_test.rb @@ -14,27 +14,37 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase end end - # slackapi sendmsg equivalent - # query_sanitation should return the recipes matching the first word in the string typed in - test "Can send a search query and get a valid response" do - VCR.use_cassette("hits") do - search_string = "cilantro" - response = EdamamApiWrapper.query_sanitation(search_string) - assert_equal(response, "cilantro") # because cilantro is the sanitized version of itself + test "get_recipe should successfully return correct recipe" do + VCR.use_cassette("recipes") do + uri = 'http://www.edamam.com/ontologies/edamam.owl#recipe_c468dc28f8b64bb711125cc150b15c25' + actual_recipe = EdamamApiWrapper.get_recipe(uri) + + expected_recipe = Recipe.new(0, 'Grilled Deviled Chickens Under a Brick', 'https://www.edamam.com/web-img/5f5/5f51c89f832d50da84e3c05bef3f66f9.jpg', uri, 'http://www.marthastewart.com/recipe/grilled-deviled-chickens-under-a-brick', ['4 baby chickens (poussins) or cornish hens (about 1 1/4 pounds each), or 4 chicken breast halves', '3 lemons, plus wedges for garnish', '4 cloves garlic, peeled and smashed', '1 tablespoon crushed red-pepper flakes, or to taste', '1 tablespoon finely chopped fresh thyme', '1 tablespoon finely chopped fresh rosemary', '1/2 cup olive oil', 'Salt, to taste'], ['Low-Carb']) + + assert_equal(actual_recipe, expected_recipe) + end end -# PUT THIS IN LATER - # test "Will only return the search query using the first word letters from the search_query" do + # # not implemented + # # query_sanitation should return the recipes matching the first word in the string typed in + # test "Can send a search query and get a valid response" do # VCR.use_cassette("hits") do - # search_string = "cilantro, edamame and caramel" - # response = EdamamApiWrapper.search_query(search_string) - # assert_equal response["q"], "cilantro" + # search_string = "cilantro" + # response = EdamamApiWrapper.query_sanitation(search_string) + # assert_equal(response, "cilantro") # because cilantro is the sanitized version of itself # end # end - # test "Will not send a query for searches not starting on a letter character" do - # assert false - # assert_nil true # ? +# dont know what to assert here to ensure it works + # test "an argument value for listing will return a successful API request" do + # VCR.use_cassette("hits") do + # clean_string = "cilantro" + # listing = 30 + # response = EdamamApiWrapper.list_recipes(clean_string, listing) + # puts "#{response}" + # assert response[200] + # end # end + end diff --git a/test/lib/recipe_test.rb b/test/lib/recipe_test.rb index 448c56d43..637c1deb6 100644 --- a/test/lib/recipe_test.rb +++ b/test/lib/recipe_test.rb @@ -24,7 +24,18 @@ class RecipeTest < ActiveSupport::TestCase assert_nil(Recipe.search_results(nil_that_should_be_a_string)) end +#show + # test "find should be able to find the instance recipe with specified id" do + # # params_id = 0 + # # assert_instance_of Recipe, Recipe.find(params_id) + # end + test "two different recipe objects with the same data should be equal" do + recipe_a = Recipe.new(0, "Chocolate Ham", "ham.jpg", "http_string", "https_string", ["jam", "cheese"], ["Saturday night", "not for kids"]) + recipe_b = Recipe.new(0, "Chocolate Ham", "ham.jpg", "http_string", "https_string", ["jam", "cheese"], ["Saturday night", "not for kids"]) + + assert_equal(recipe_a, recipe_b) + end # #search_results returns the information needed for this application only, we can't test this because I am not asking for query information in my API request # test "search_results should return the results for the first word in a query" do # VCR.use_cassette("hits") do @@ -35,4 +46,5 @@ class RecipeTest < ActiveSupport::TestCase # # assert_equal(response["q"], "cilantro") # end # end + end From 2af5dd588bb5623042cdd3370a8c8687340d9790 Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Fri, 4 Nov 2016 10:54:05 -0700 Subject: [PATCH 10/14] validation tests and logic in the right places --- app/controllers/recipes_controller.rb | 21 ++++++++++--------- app/views/recipes/index.html.erb | 3 --- lib/edamam_api_wrapper.rb | 19 +++++++++++++---- lib/recipe.rb | 11 ++-------- test/controllers/recipes_controller_test.rb | 12 +++++------ test/lib/edamam_api_wrapper_test.rb | 23 +++++++++++++++++++++ test/lib/recipe_test.rb | 8 +++---- 7 files changed, 61 insertions(+), 36 deletions(-) diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index ed3ab4517..5dd9c96ff 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -14,15 +14,17 @@ def search # SUCCESS search_string = recipe_params[:q] @recipes = Recipe.search_results(search_string) - unless @recipes.empty? - if @listing == nil - @listing = 0 - elsif @listing >=0 - @listing +=10 - end - render :index - return - end + # We have control over Recipe search results (in /lib) + +# handle @recipes empty in view. + # if @listing == nil + # @listing = 0 + # elsif @listing >=0 + # @listing +=10 + # end + render :index + return + # else end flash[:notice] = "Please enter a valid search term" @@ -37,7 +39,6 @@ def show private -# undefined method `permit' for "cilantro":String def recipe_params params.permit(:q) end diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index dd1c42fda..29dcadaf1 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -1,14 +1,11 @@
<% if @recipes != nil %> - <% listing_num = @listing + 1 %> <% @recipes.each do |recipe| %>
- <%= "#{listing_num}" %>

<%= link_to(image_tag(recipe.image), image_path(recipe_path(recipe.id)) ) %>

<%= link_to "#{recipe.title}", link_selector(recipe) %>

- <% listing_num +=1 %>
<% end %> diff --git a/lib/edamam_api_wrapper.rb b/lib/edamam_api_wrapper.rb index e34e24dd8..d7b4435d6 100644 --- a/lib/edamam_api_wrapper.rb +++ b/lib/edamam_api_wrapper.rb @@ -7,8 +7,12 @@ class EdamamApiWrapper attr_reader :data - def self.list_recipes(clean_string, listing=0) + def self.list_recipes(search_string, listing=0) + clean_string = query_sanitation(search_string) + if clean_string.empty? + return [] + end #gives us the first ten page_string = "&from=0" if listing !=0 @@ -35,11 +39,15 @@ def self.list_recipes(clean_string, listing=0) return search_results end +# not implemented # restrictions on search queries imposed by Edamam @todo def self.query_sanitation(search_string) puts "Requesting #{search_string} from Edamam database" # Need to clean the string up - clean_string = search_string + if search_string.nil? + return '' + end + clean_string = search_string.gsub(/[^a-zA-Z ]/, '') # Used by the recipe controller action return clean_string end @@ -47,8 +55,11 @@ def self.query_sanitation(search_string) def self.get_recipe(recipe_uri) url = BASE_URL + "?r=#{URI.encode(recipe_uri)}" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" @data = HTTParty.get(url) - # check/test for valid return - return Recipe.new(0, @data[0]['label'], @data[0]['image'], @data[0]['uri'], @data[0]['url'], @data[0]['ingredientLines'], @data[0]['dietLabels'] ) + if @data.empty? + return nil + else + return Recipe.new(0, @data[0]['label'], @data[0]['image'], @data[0]['uri'], @data[0]['url'], @data[0]['ingredientLines'], @data[0]['dietLabels'] ) + end end end diff --git a/lib/recipe.rb b/lib/recipe.rb index 5a1162a07..9a71b8dd9 100644 --- a/lib/recipe.rb +++ b/lib/recipe.rb @@ -10,19 +10,12 @@ def initialize(listing, title, image, uri, url, ingredients, dietary_info) @url = url @ingredients = ingredients @diet_info = dietary_info - @clean_query = nil end # The RecipesController will send the listing number, but to remember what it means we call it page here and elsewhere def self.search_results(search_query, listing=0) - # clean up the search string first - if search_query != nil - @clean_query = search_query.split.first - unless @clean_query == nil || @clean_query == "" || @clean_query.gsub!(/[^a-zA-Z]/, '') - return EdamamApiWrapper.list_recipes(@clean_query, listing) - end - end - return nil + # cleaned up in wrapper + return EdamamApiWrapper.list_recipes(search_query, listing) end # returns nil if no search query available or if the id is not in use diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb index dc2846f89..3a27c1c7f 100644 --- a/test/controllers/recipes_controller_test.rb +++ b/test/controllers/recipes_controller_test.rb @@ -26,11 +26,11 @@ class RecipesControllerTest < ActionController::TestCase end end - test "should get show" do - VCR.use_cassette("recipes") do - get :show, id: 0 - assert_response :success - end - end + # test "should get show" do + # VCR.use_cassette("recipes") do + # get :show, id: 0 + # assert_response :success + # end + # end end diff --git a/test/lib/edamam_api_wrapper_test.rb b/test/lib/edamam_api_wrapper_test.rb index 0601670b0..f9c88a714 100644 --- a/test/lib/edamam_api_wrapper_test.rb +++ b/test/lib/edamam_api_wrapper_test.rb @@ -14,6 +14,14 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase end end + test "list_recipes returns an empty array if the query has no results back from the API" do + VCR.use_cassette("recipes") do + query = "automobile" + recipes = EdamamApiWrapper.list_recipes(query) + assert_equal([], recipes) + end + end + test "get_recipe should successfully return correct recipe" do VCR.use_cassette("recipes") do uri = 'http://www.edamam.com/ontologies/edamam.owl#recipe_c468dc28f8b64bb711125cc150b15c25' @@ -26,6 +34,21 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase end end + test "get_recipe should return nil for unexpected uri requests" do + VCR.use_cassette("recipes") do + uri = 'http://www.edamam.com/ontologies/edamam.owl#recipe_myownuri' + unexpected_uri_response = EdamamApiWrapper.get_recipe(uri) + + assert_nil unexpected_uri_response + + end + end + + test "get_recipe should return nil if the request to the API was unsuccessful" do + VCR.use_cassette("recipes") do + end + end + # # not implemented # # query_sanitation should return the recipes matching the first word in the string typed in # test "Can send a search query and get a valid response" do diff --git a/test/lib/recipe_test.rb b/test/lib/recipe_test.rb index 637c1deb6..32d0c0bd2 100644 --- a/test/lib/recipe_test.rb +++ b/test/lib/recipe_test.rb @@ -14,14 +14,14 @@ class RecipeTest < ActiveSupport::TestCase end end - test "search_results should return nil if the search_query is not valid" do + test "search_results should return an empty array if the search_query is not valid" do numbers_string = "1234" empty_string = "" nil_that_should_be_a_string = nil - assert_nil(Recipe.search_results(numbers_string)) - assert_nil(Recipe.search_results(empty_string)) - assert_nil(Recipe.search_results(nil_that_should_be_a_string)) + assert_equal([], Recipe.search_results(numbers_string)) + assert_equal([], Recipe.search_results(empty_string)) + assert_equal([], Recipe.search_results(nil_that_should_be_a_string)) end #show From 1f8d41097fa5ec2943510f68bfbe9f54b920e385 Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Fri, 4 Nov 2016 13:55:50 -0700 Subject: [PATCH 11/14] Added some pages logic. Removed recipe#index and instead recipes#search is using '/recipes' - and tests --- app/controllers/recipes_controller.rb | 20 ++++++-------------- config/routes.rb | 3 +-- lib/edamam_api_wrapper.rb | 15 +++++++-------- lib/recipe.rb | 4 ++-- test/controllers/recipes_controller_test.rb | 21 +++++++++++++-------- test/lib/edamam_api_wrapper_test.rb | 19 +++++++++++++++---- 6 files changed, 44 insertions(+), 38 deletions(-) diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 5dd9c96ff..5232d8cbc 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -3,25 +3,17 @@ class RecipesController < ApplicationController - def index - search_string = recipe_params[:q] - - @recipes ||= Recipe.search_results(search_string, @listing) - end - def search if params["q"] != "" # SUCCESS search_string = recipe_params[:q] - @recipes = Recipe.search_results(search_string) + page = (recipe_params[:page] || 1).to_i + @recipes = Recipe.search_results(search_string, page) # We have control over Recipe search results (in /lib) -# handle @recipes empty in view. - # if @listing == nil - # @listing = 0 - # elsif @listing >=0 - # @listing +=10 - # end + # raise + # This will return an empty list if there are no search results from the API methods. + # @todo Implement redirect to root for [] render :index return @@ -40,7 +32,7 @@ def show private def recipe_params - params.permit(:q) + params.permit(:q, :page) end diff --git a/config/routes.rb b/config/routes.rb index 75339fa41..fa8056112 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,10 +2,9 @@ root 'home#index' - get '/recipes' => 'recipes#index' get '/recipes/:id' => 'recipes#show', as: 'recipe' - get '/search' => 'recipes#search' + get '/recipes' => 'recipes#search', as: 'search' # get '/:id' => 'recipes#show' diff --git a/lib/edamam_api_wrapper.rb b/lib/edamam_api_wrapper.rb index d7b4435d6..2ab0f1078 100644 --- a/lib/edamam_api_wrapper.rb +++ b/lib/edamam_api_wrapper.rb @@ -7,17 +7,17 @@ class EdamamApiWrapper attr_reader :data - def self.list_recipes(search_string, listing=0) - + def self.list_recipes(search_string, page=1) + # clean up string clean_string = query_sanitation(search_string) if clean_string.empty? return [] end #gives us the first ten - page_string = "&from=0" - if listing !=0 - page_string = "&from=#{listing}" - end + + listing = (page*10) - 10 + + page_string = "&from=#{listing}" url = BASE_URL + "?q=#{clean_string}" + page_string + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" # url = BASE_URL + "?q=chicken" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" # puts "list_recipes URL: #{url}" @@ -26,7 +26,6 @@ def self.list_recipes(search_string, listing=0) if @data["hits"] @data["hits"].each do |hit| wrapper = Recipe.new(listing, hit["recipe"]["label"], hit["recipe"]["image"], hit["recipe"]["uri"], hit["recipe"]["url"], hit["recipe"]["ingredientLines"], hit["recipe"]["dietLabels"]) - listing += 1 # label is recipe title # image is image of recipe item # uri is uri for recipe on edamam @@ -42,7 +41,7 @@ def self.list_recipes(search_string, listing=0) # not implemented # restrictions on search queries imposed by Edamam @todo def self.query_sanitation(search_string) - puts "Requesting #{search_string} from Edamam database" + # puts "Requesting #{search_string} from Edamam database" # Need to clean the string up if search_string.nil? return '' diff --git a/lib/recipe.rb b/lib/recipe.rb index 9a71b8dd9..af574151f 100644 --- a/lib/recipe.rb +++ b/lib/recipe.rb @@ -13,9 +13,9 @@ def initialize(listing, title, image, uri, url, ingredients, dietary_info) end # The RecipesController will send the listing number, but to remember what it means we call it page here and elsewhere - def self.search_results(search_query, listing=0) + def self.search_results(search_query, page=1) # cleaned up in wrapper - return EdamamApiWrapper.list_recipes(search_query, listing) + return EdamamApiWrapper.list_recipes(search_query, page) end # returns nil if no search query available or if the id is not in use diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb index 3a27c1c7f..ff5115385 100644 --- a/test/controllers/recipes_controller_test.rb +++ b/test/controllers/recipes_controller_test.rb @@ -2,13 +2,6 @@ class RecipesControllerTest < ActionController::TestCase - test "should get the index" do - VCR.use_cassette("recipes") do - get :index - assert_response :success - end - end - test "search form should have a successful search if search_query is valid" do VCR.use_cassette("recipes") do params = {"q" => "cilantro"} @@ -18,7 +11,7 @@ class RecipesControllerTest < ActionController::TestCase end end - test "search form should not redirect to recipes#index if empty" do + test "search form should render root if empty" do VCR.use_cassette("recipes") do params = {"q" => ""} get :search, params @@ -26,6 +19,18 @@ class RecipesControllerTest < ActionController::TestCase end end + test "if search query is invalid or there are no results it will return an empty array, and redirect_to root" do + assert false + end + + test "search should render the correct page" do + VCR.use_cassette("recipes") do + params = {"q" => "tilapia", "page" => 2} + get :search, params + assert + end + end + # test "should get show" do # VCR.use_cassette("recipes") do # get :show, id: 0 diff --git a/test/lib/edamam_api_wrapper_test.rb b/test/lib/edamam_api_wrapper_test.rb index f9c88a714..2e18cd301 100644 --- a/test/lib/edamam_api_wrapper_test.rb +++ b/test/lib/edamam_api_wrapper_test.rb @@ -34,6 +34,15 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase end end + test "list_recipes page should return the listings from that page" do + VCR.use_cassette("recipes") do + search_string = "tilapia" + page = 2 + recipes = EdamamApiWrapper.list_recipes(search_string, page) + assert_equal('http://www.edamam.com/ontologies/edamam.owl#recipe_55a8fd184bca071fefbbdc01325f88ef', recipes.first.uri) + end + end + test "get_recipe should return nil for unexpected uri requests" do VCR.use_cassette("recipes") do uri = 'http://www.edamam.com/ontologies/edamam.owl#recipe_myownuri' @@ -44,10 +53,12 @@ class EdamamApiWrapperTest < ActiveSupport::TestCase end end - test "get_recipe should return nil if the request to the API was unsuccessful" do - VCR.use_cassette("recipes") do - end - end + # test "get_recipe should return nil if the request to the API was unsuccessful" do + # VCR.use_cassette("recipes") do + # assert false + # end + # end + # # not implemented # # query_sanitation should return the recipes matching the first word in the string typed in From 6234f047b34ab3e20d71e2ddcefffd83474cd2d1 Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Fri, 4 Nov 2016 14:55:49 -0700 Subject: [PATCH 12/14] Basic Foundation added --- Gemfile | 6 +- Gemfile.lock | 4 + app/assets/javascripts/application.js | 10 + app/assets/stylesheets/_settings.scss | 574 ++++++++++++++++++ .../{application.css => application.scss} | 2 + .../stylesheets/foundation_and_overrides.scss | 52 ++ app/assets/stylesheets/home.scss | 3 + app/views/home/index.html.erb | 4 +- app/views/layouts/application.html.erb | 38 +- app/views/recipes/index.html.erb | 10 +- 10 files changed, 678 insertions(+), 25 deletions(-) create mode 100644 app/assets/stylesheets/_settings.scss rename app/assets/stylesheets/{application.css => application.scss} (94%) create mode 100644 app/assets/stylesheets/foundation_and_overrides.scss diff --git a/Gemfile b/Gemfile index a12cfa0e6..61460c65e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,10 @@ source 'https://rubygems.org' +# Two gems, to use Foundation: +# Foundation Rails Gem +gem 'foundation-rails' +# Required due to an incompatibility between TurboLinks and Foundation. +gem 'jquery-turbolinks' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.7' @@ -35,7 +40,6 @@ gem 'sdoc', '~> 0.4.0', group: :doc # API GEMS gem 'httparty' -gem 'foundation-rails' group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 30144d0e6..99a0bc6f8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -86,6 +86,9 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + jquery-turbolinks (2.1.0) + railties (>= 3.1.0) + turbolinks json (1.8.3) loofah (2.0.3) nokogiri (>= 1.5.9) @@ -200,6 +203,7 @@ DEPENDENCIES httparty jbuilder (~> 2.0) jquery-rails + jquery-turbolinks minitest-reporters minitest-vcr rails (= 4.2.7) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a830..038d8d7ec 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,5 +12,15 @@ // //= require jquery //= require jquery_ujs +//= require foundation //= require turbolinks //= require_tree . + +$(function(){ $(document).foundation(); }); + +//= require foundation +$(document).foundation(); + +$(document).on('turbolinks:load', function() { + $(function(){ $(document).foundation(); }); +}); diff --git a/app/assets/stylesheets/_settings.scss b/app/assets/stylesheets/_settings.scss new file mode 100644 index 000000000..703053eb9 --- /dev/null +++ b/app/assets/stylesheets/_settings.scss @@ -0,0 +1,574 @@ +// Foundation for Sites Settings +// ----------------------------- +// +// Table of Contents: +// +// 1. Global +// 2. Breakpoints +// 3. The Grid +// 4. Base Typography +// 5. Typography Helpers +// 6. Abide +// 7. Accordion +// 8. Accordion Menu +// 9. Badge +// 10. Breadcrumbs +// 11. Button +// 12. Button Group +// 13. Callout +// 14. Close Button +// 15. Drilldown +// 16. Dropdown +// 17. Dropdown Menu +// 18. Flex Video +// 19. Forms +// 20. Label +// 21. Media Object +// 22. Menu +// 23. Meter +// 24. Off-canvas +// 25. Orbit +// 26. Pagination +// 27. Progress Bar +// 28. Reveal +// 29. Slider +// 30. Switch +// 31. Table +// 32. Tabs +// 33. Thumbnail +// 34. Title Bar +// 35. Tooltip +// 36. Top Bar + +@import 'util/util'; + +// 1. Global +// --------- + +$global-font-size: 100%; +$global-width: rem-calc(1200); +$global-lineheight: 1.5; +$foundation-palette: ( + primary: #2199e8, + secondary: #777, + success: #3adb76, + warning: #ffae00, + alert: #ec5840, +); +$light-gray: #e6e6e6; +$medium-gray: #cacaca; +$dark-gray: #8a8a8a; +$black: #0a0a0a; +$white: #fefefe; +$body-background: $white; +$body-font-color: $black; +$body-font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; +$body-antialiased: true; +$global-margin: 1rem; +$global-padding: 1rem; +$global-weight-normal: normal; +$global-weight-bold: bold; +$global-radius: 0; +$global-text-direction: ltr; +$global-flexbox: false; +$print-transparent-backgrounds: true; + +@include add-foundation-colors; + +// 2. Breakpoints +// -------------- + +$breakpoints: ( + small: 0, + medium: 640px, + large: 1024px, + xlarge: 1200px, + xxlarge: 1440px, +); +$breakpoint-classes: (small medium large); + +// 3. The Grid +// ----------- + +$grid-row-width: $global-width; +$grid-column-count: 12; +$grid-column-gutter: ( + small: 20px, + medium: 30px, +); +$grid-column-align-edge: true; +$block-grid-max: 8; + +// 4. Base Typography +// ------------------ + +$header-font-family: $body-font-family; +$header-font-weight: $global-weight-normal; +$header-font-style: normal; +$font-family-monospace: Consolas, 'Liberation Mono', Courier, monospace; +$header-sizes: ( + small: ( + 'h1': 24, + 'h2': 20, + 'h3': 19, + 'h4': 18, + 'h5': 17, + 'h6': 16, + ), + medium: ( + 'h1': 48, + 'h2': 40, + 'h3': 31, + 'h4': 25, + 'h5': 20, + 'h6': 16, + ), +); +$header-color: inherit; +$header-lineheight: 1.4; +$header-margin-bottom: 0.5rem; +$header-text-rendering: optimizeLegibility; +$small-font-size: 80%; +$header-small-font-color: $medium-gray; +$paragraph-lineheight: 1.6; +$paragraph-margin-bottom: 1rem; +$paragraph-text-rendering: optimizeLegibility; +$code-color: $black; +$code-font-family: $font-family-monospace; +$code-font-weight: $global-weight-normal; +$code-background: $light-gray; +$code-border: 1px solid $medium-gray; +$code-padding: rem-calc(2 5 1); +$anchor-color: $primary-color; +$anchor-color-hover: scale-color($anchor-color, $lightness: -14%); +$anchor-text-decoration: none; +$anchor-text-decoration-hover: none; +$hr-width: $global-width; +$hr-border: 1px solid $medium-gray; +$hr-margin: rem-calc(20) auto; +$list-lineheight: $paragraph-lineheight; +$list-margin-bottom: $paragraph-margin-bottom; +$list-style-type: disc; +$list-style-position: outside; +$list-side-margin: 1.25rem; +$list-nested-side-margin: 1.25rem; +$defnlist-margin-bottom: 1rem; +$defnlist-term-weight: $global-weight-bold; +$defnlist-term-margin-bottom: 0.3rem; +$blockquote-color: $dark-gray; +$blockquote-padding: rem-calc(9 20 0 19); +$blockquote-border: 1px solid $medium-gray; +$cite-font-size: rem-calc(13); +$cite-color: $dark-gray; +$keystroke-font: $font-family-monospace; +$keystroke-color: $black; +$keystroke-background: $light-gray; +$keystroke-padding: rem-calc(2 4 0); +$keystroke-radius: $global-radius; +$abbr-underline: 1px dotted $black; + +// 5. Typography Helpers +// --------------------- + +$lead-font-size: $global-font-size * 1.25; +$lead-lineheight: 1.6; +$subheader-lineheight: 1.4; +$subheader-color: $dark-gray; +$subheader-font-weight: $global-weight-normal; +$subheader-margin-top: 0.2rem; +$subheader-margin-bottom: 0.5rem; +$stat-font-size: 2.5rem; + +// 6. Abide +// -------- + +$abide-inputs: true; +$abide-labels: true; +$input-background-invalid: map-get($foundation-palette, alert); +$form-label-color-invalid: map-get($foundation-palette, alert); +$input-error-color: map-get($foundation-palette, alert); +$input-error-font-size: rem-calc(12); +$input-error-font-weight: $global-weight-bold; + +// 7. Accordion +// ------------ + +$accordion-background: $white; +$accordion-plusminus: true; +$accordion-item-color: foreground($accordion-background, $primary-color); +$accordion-item-background-hover: $light-gray; +$accordion-item-padding: 1.25rem 1rem; +$accordion-content-background: $white; +$accordion-content-border: 1px solid $light-gray; +$accordion-content-color: foreground($accordion-content-background, $body-font-color); +$accordion-content-padding: 1rem; + +// 8. Accordion Menu +// ----------------- + +$accordionmenu-arrows: true; +$accordionmenu-arrow-color: $primary-color; + +// 9. Badge +// -------- + +$badge-background: $primary-color; +$badge-color: foreground($badge-background); +$badge-padding: 0.3em; +$badge-minwidth: 2.1em; +$badge-font-size: 0.6rem; + +// 10. Breadcrumbs +// --------------- + +$breadcrumbs-margin: 0 0 $global-margin 0; +$breadcrumbs-item-font-size: rem-calc(11); +$breadcrumbs-item-color: $primary-color; +$breadcrumbs-item-color-current: $black; +$breadcrumbs-item-color-disabled: $medium-gray; +$breadcrumbs-item-margin: 0.75rem; +$breadcrumbs-item-uppercase: true; +$breadcrumbs-item-slash: true; + +// 11. Button +// ---------- + +$button-padding: 0.85em 1em; +$button-margin: 0 0 $global-margin 0; +$button-fill: solid; +$button-background: $primary-color; +$button-background-hover: scale-color($button-background, $lightness: -15%); +$button-color: $white; +$button-color-alt: $black; +$button-radius: $global-radius; +$button-sizes: ( + tiny: 0.6rem, + small: 0.75rem, + default: 0.9rem, + large: 1.25rem, +); +$button-opacity-disabled: 0.25; +$button-background-hover-lightness: -20%; +$button-hollow-hover-lightness: -50%; + +// 12. Button Group +// ---------------- + +$buttongroup-margin: 1rem; +$buttongroup-spacing: 1px; +$buttongroup-child-selector: '.button'; +$buttongroup-expand-max: 6; + +// 13. Callout +// ----------- + +$callout-background: $white; +$callout-background-fade: 85%; +$callout-border: 1px solid rgba($black, 0.25); +$callout-margin: 0 0 1rem 0; +$callout-padding: 1rem; +$callout-font-color: $body-font-color; +$callout-font-color-alt: $body-background; +$callout-radius: $global-radius; +$callout-link-tint: 30%; + +// 14. Close Button +// ---------------- + +$closebutton-position: right top; +$closebutton-offset-horizontal: 1rem; +$closebutton-offset-vertical: 0.5rem; +$closebutton-size: 2em; +$closebutton-lineheight: 1; +$closebutton-color: $dark-gray; +$closebutton-color-hover: $black; + +// 15. Drilldown +// ------------- + +$drilldown-transition: transform 0.15s linear; +$drilldown-arrows: true; +$drilldown-arrow-color: $primary-color; +$drilldown-background: $white; + +// 16. Dropdown +// ------------ + +$dropdown-padding: 1rem; +$dropdown-border: 1px solid $medium-gray; +$dropdown-font-size: 1rem; +$dropdown-width: 300px; +$dropdown-radius: $global-radius; +$dropdown-sizes: ( + tiny: 100px, + small: 200px, + large: 400px, +); + +// 17. Dropdown Menu +// ----------------- + +$dropdownmenu-arrows: true; +$dropdownmenu-arrow-color: $anchor-color; +$dropdownmenu-min-width: 200px; +$dropdownmenu-background: $white; +$dropdownmenu-border: 1px solid $medium-gray; + +// 18. Flex Video +// -------------- + +$flexvideo-margin-bottom: rem-calc(16); +$flexvideo-ratio: 4 by 3; +$flexvideo-ratio-widescreen: 16 by 9; + +// 19. Forms +// --------- + +$fieldset-border: 1px solid $medium-gray; +$fieldset-padding: rem-calc(20); +$fieldset-margin: rem-calc(18 0); +$legend-padding: rem-calc(0 3); +$form-spacing: rem-calc(16); +$helptext-color: $black; +$helptext-font-size: rem-calc(13); +$helptext-font-style: italic; +$input-prefix-color: $black; +$input-prefix-background: $light-gray; +$input-prefix-border: 1px solid $medium-gray; +$input-prefix-padding: 1rem; +$form-label-color: $black; +$form-label-font-size: rem-calc(14); +$form-label-font-weight: $global-weight-normal; +$form-label-line-height: 1.8; +$select-background: $white; +$select-triangle-color: $dark-gray; +$select-radius: $global-radius; +$input-color: $black; +$input-placeholder-color: $medium-gray; +$input-font-family: inherit; +$input-font-size: rem-calc(16); +$input-background: $white; +$input-background-focus: $white; +$input-background-disabled: $light-gray; +$input-border: 1px solid $medium-gray; +$input-border-focus: 1px solid $dark-gray; +$input-shadow: inset 0 1px 2px rgba($black, 0.1); +$input-shadow-focus: 0 0 5px $medium-gray; +$input-cursor-disabled: not-allowed; +$input-transition: box-shadow 0.5s, border-color 0.25s ease-in-out; +$input-number-spinners: true; +$input-radius: $global-radius; +$button-radius: $global-radius; + +// 20. Label +// --------- + +$label-background: $primary-color; +$label-color: foreground($label-background); +$label-font-size: 0.8rem; +$label-padding: 0.33333rem 0.5rem; +$label-radius: $global-radius; + +// 21. Media Object +// ---------------- + +$mediaobject-margin-bottom: $global-margin; +$mediaobject-section-padding: $global-padding; +$mediaobject-image-width-stacked: 100%; + +// 22. Menu +// -------- + +$menu-margin: 0; +$menu-margin-nested: 1rem; +$menu-item-padding: 0.7rem 1rem; +$menu-item-color-active: $white; +$menu-item-background-active: map-get($foundation-palette, primary); +$menu-icon-spacing: 0.25rem; + +// 23. Meter +// --------- + +$meter-height: 1rem; +$meter-radius: $global-radius; +$meter-background: $medium-gray; +$meter-fill-good: $success-color; +$meter-fill-medium: $warning-color; +$meter-fill-bad: $alert-color; + +// 24. Off-canvas +// -------------- + +$offcanvas-size: 250px; +$offcanvas-background: $light-gray; +$offcanvas-zindex: -1; +$offcanvas-transition-length: 0.5s; +$offcanvas-transition-timing: ease; +$offcanvas-fixed-reveal: true; +$offcanvas-exit-background: rgba($white, 0.25); +$maincontent-class: 'off-canvas-content'; +$maincontent-shadow: 0 0 10px rgba($black, 0.5); + +// 25. Orbit +// --------- + +$orbit-bullet-background: $medium-gray; +$orbit-bullet-background-active: $dark-gray; +$orbit-bullet-diameter: 1.2rem; +$orbit-bullet-margin: 0.1rem; +$orbit-bullet-margin-top: 0.8rem; +$orbit-bullet-margin-bottom: 0.8rem; +$orbit-caption-background: rgba($black, 0.5); +$orbit-caption-padding: 1rem; +$orbit-control-background-hover: rgba($black, 0.5); +$orbit-control-padding: 1rem; +$orbit-control-zindex: 10; + +// 26. Pagination +// -------------- + +$pagination-font-size: rem-calc(14); +$pagination-margin-bottom: $global-margin; +$pagination-item-color: $black; +$pagination-item-padding: rem-calc(3 10); +$pagination-item-spacing: rem-calc(1); +$pagination-radius: $global-radius; +$pagination-item-background-hover: $light-gray; +$pagination-item-background-current: $primary-color; +$pagination-item-color-current: foreground($pagination-item-background-current); +$pagination-item-color-disabled: $medium-gray; +$pagination-ellipsis-color: $black; +$pagination-mobile-items: false; +$pagination-mobile-current-item: false; +$pagination-arrows: true; + +// 27. Progress Bar +// ---------------- + +$progress-height: 1rem; +$progress-background: $medium-gray; +$progress-margin-bottom: $global-margin; +$progress-meter-background: $primary-color; +$progress-radius: $global-radius; + +// 28. Reveal +// ---------- + +$reveal-background: $white; +$reveal-width: 600px; +$reveal-max-width: $global-width; +$reveal-padding: $global-padding; +$reveal-border: 1px solid $medium-gray; +$reveal-radius: $global-radius; +$reveal-zindex: 1005; +$reveal-overlay-background: rgba($black, 0.45); + +// 29. Slider +// ---------- + +$slider-width-vertical: 0.5rem; +$slider-transition: all 0.2s ease-in-out; +$slider-height: 0.5rem; +$slider-background: $light-gray; +$slider-fill-background: $medium-gray; +$slider-handle-height: 1.4rem; +$slider-handle-width: 1.4rem; +$slider-handle-background: $primary-color; +$slider-opacity-disabled: 0.25; +$slider-radius: $global-radius; + +// 30. Switch +// ---------- + +$switch-background: $medium-gray; +$switch-background-active: $primary-color; +$switch-height: 2rem; +$switch-height-tiny: 1.5rem; +$switch-height-small: 1.75rem; +$switch-height-large: 2.5rem; +$switch-radius: $global-radius; +$switch-margin: $global-margin; +$switch-paddle-background: $white; +$switch-paddle-offset: 0.25rem; +$switch-paddle-radius: $global-radius; +$switch-paddle-transition: all 0.25s ease-out; + +// 31. Table +// --------- + +$table-background: $white; +$table-color-scale: 5%; +$table-border: 1px solid smart-scale($table-background, $table-color-scale); +$table-padding: rem-calc(8 10 10); +$table-hover-scale: 2%; +$table-row-hover: darken($table-background, $table-hover-scale); +$table-row-stripe-hover: darken($table-background, $table-color-scale + $table-hover-scale); +$table-striped-background: smart-scale($table-background, $table-color-scale); +$table-stripe: even; +$table-head-background: smart-scale($table-background, $table-color-scale / 2); +$table-head-row-hover: darken($table-head-background, $table-hover-scale); +$table-foot-background: smart-scale($table-background, $table-color-scale); +$table-foot-row-hover: darken($table-foot-background, $table-hover-scale); +$table-head-font-color: $body-font-color; +$table-foot-font-color: $body-font-color; +$show-header-for-stacked: false; + +// 32. Tabs +// -------- + +$tab-margin: 0; +$tab-background: $white; +$tab-background-active: $light-gray; +$tab-item-font-size: rem-calc(12); +$tab-item-background-hover: $white; +$tab-item-padding: 1.25rem 1.5rem; +$tab-expand-max: 6; +$tab-content-background: $white; +$tab-content-border: $light-gray; +$tab-content-color: foreground($tab-background, $primary-color); +$tab-content-padding: 1rem; + +// 33. Thumbnail +// ------------- + +$thumbnail-border: solid 4px $white; +$thumbnail-margin-bottom: $global-margin; +$thumbnail-shadow: 0 0 0 1px rgba($black, 0.2); +$thumbnail-shadow-hover: 0 0 6px 1px rgba($primary-color, 0.5); +$thumbnail-transition: box-shadow 200ms ease-out; +$thumbnail-radius: $global-radius; + +// 34. Title Bar +// ------------- + +$titlebar-background: $black; +$titlebar-color: $white; +$titlebar-padding: 0.5rem; +$titlebar-text-font-weight: bold; +$titlebar-icon-color: $white; +$titlebar-icon-color-hover: $medium-gray; +$titlebar-icon-spacing: 0.25rem; + +// 35. Tooltip +// ----------- + +$has-tip-font-weight: $global-weight-bold; +$has-tip-border-bottom: dotted 1px $dark-gray; +$tooltip-background-color: $black; +$tooltip-color: $white; +$tooltip-padding: 0.75rem; +$tooltip-font-size: $small-font-size; +$tooltip-pip-width: 0.75rem; +$tooltip-pip-height: $tooltip-pip-width * 0.866; +$tooltip-radius: $global-radius; + +// 36. Top Bar +// ----------- + +$topbar-padding: 0.5rem; +$topbar-background: $light-gray; +$topbar-submenu-background: $topbar-background; +$topbar-title-spacing: 1rem; +$topbar-input-width: 200px; +$topbar-unstack-breakpoint: medium; + diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 94% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index f9cd5b348..c8b8e576f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -12,4 +12,6 @@ * *= require_tree . *= require_self + *= require foundation_and_overrides + */ diff --git a/app/assets/stylesheets/foundation_and_overrides.scss b/app/assets/stylesheets/foundation_and_overrides.scss new file mode 100644 index 000000000..458eb4faf --- /dev/null +++ b/app/assets/stylesheets/foundation_and_overrides.scss @@ -0,0 +1,52 @@ +@charset 'utf-8'; + +@import 'settings'; +@import 'foundation'; + +// If you'd like to include motion-ui the foundation-rails gem comes prepackaged with it, uncomment the 3 @imports, if you are not using the gem you need to install the motion-ui sass package. +// +@import 'motion-ui/motion-ui'; + +// We include everything by default. To slim your CSS, remove components you don't use. + +@include foundation-global-styles; +@include foundation-grid; +@include foundation-typography; +@include foundation-button; +@include foundation-forms; +@include foundation-visibility-classes; +@include foundation-float-classes; +@include foundation-accordion; +@include foundation-accordion-menu; +@include foundation-badge; +@include foundation-breadcrumbs; +@include foundation-button-group; +@include foundation-callout; +@include foundation-close-button; +@include foundation-drilldown-menu; +@include foundation-dropdown; +@include foundation-dropdown-menu; +@include foundation-flex-video; +@include foundation-label; +@include foundation-media-object; +@include foundation-menu; +@include foundation-menu-icon; +@include foundation-off-canvas; +@include foundation-orbit; +@include foundation-pagination; +@include foundation-progress-bar; +@include foundation-slider; +@include foundation-sticky; +@include foundation-reveal; +@include foundation-switch; +@include foundation-table; +@include foundation-tabs; +@include foundation-thumbnail; +@include foundation-title-bar; +@include foundation-tooltip; +@include foundation-top-bar; + +// If you'd like to include motion-ui the foundation-rails gem comes prepackaged with it, uncomment the 3 @imports, if you are not using the gem you need to install the motion-ui sass package. +// +@include motion-ui-transitions; +@include motion-ui-animations; diff --git a/app/assets/stylesheets/home.scss b/app/assets/stylesheets/home.scss index f0ddc6846..8f3b702f4 100644 --- a/app/assets/stylesheets/home.scss +++ b/app/assets/stylesheets/home.scss @@ -1,3 +1,6 @@ // Place all the styles related to the home controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ +div.results { + height: 22em; +} diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index a76b4fec4..0092c411c 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -6,12 +6,14 @@ <% else %>

Welcome to the Muncher!

<% end %> -
+
+
<%= form_tag(search_path, method: "get") do %> <%= label_tag(:q, "Search for:") %> <%= text_field_tag(:q) %> <%= submit_tag("Go!") %> <% end %> +

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 55ccd8d13..45ae08f74 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,22 +1,24 @@ - - - ApiMuncher - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> - <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> - <%= csrf_meta_tags %> - - -

+ + + + -
+ <%= content_for?(:title) ? yield(:title) : "Untitled" %> -<%= yield %> -
-
- <%= link_to "Search", root_path %> - <%= image_tag("attibution_edamam.png", alt: "Powered by Edamam") -%> -
-
- + <%= stylesheet_link_tag "application" %> + <%= javascript_include_tag "application", 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + + + <%= yield %> +
+
+ <%= link_to "Search", root_path %> + <%= image_tag("attibution_edamam.png", alt: "Powered by Edamam") -%> +
+
+ diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index 874498174..b22c1e115 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -2,18 +2,18 @@
<% if @recipes != nil %> <% listing = 1 %> +
<% @recipes.each do |recipe| %> -
-
+
<%= "#{listing}" %>

<%= link_to(image_tag(recipe.image), image_path(recipe_path(recipe)) ) %>

- <%= link_to "#{recipe.title}", link_selector(recipe) %> +

<%= link_to "#{recipe.title}", link_selector(recipe) %>

<% listing +=1 %> -
<% end %> +
<% end %>

- This is the recipes#index page + This is the recipes#search page

From 809e8ed61d19c34e6f40e0be50e2ff7494793c8b Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Sat, 5 Nov 2016 18:42:37 -0700 Subject: [PATCH 13/14] show controller tested and has a basic view --- app/controllers/recipes_controller.rb | 6 ++-- app/views/recipes/index.html.erb | 16 +++++++--- app/views/recipes/show.html.erb | 20 ++++++++++--- config/routes.rb | 3 +- lib/edamam_api_wrapper.rb | 2 +- lib/recipe.rb | 23 ++++++-------- test/controllers/recipes_controller_test.rb | 33 +++++++++++++-------- test/lib/recipe_test.rb | 29 ++++++++++++++---- 8 files changed, 88 insertions(+), 44 deletions(-) diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 5232d8cbc..12e60cbce 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -24,9 +24,9 @@ def search end def show - show_params = params[:id] - @recipe = Recipe.find(show_params) - raise + show_params = params[:uri] + # Will stop some invalid recipes rather than showing an empty list + @recipe = EdamamApiWrapper.get_recipe(show_params) end private diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index b22c1e115..b9c2f2154 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -3,17 +3,25 @@ <% if @recipes != nil %> <% listing = 1 %>
+
+
<% @recipes.each do |recipe| %>
<%= "#{listing}" %> -

<%= link_to(image_tag(recipe.image), image_path(recipe_path(recipe)) ) %>

-

<%= link_to "#{recipe.title}", link_selector(recipe) %>

+

<%= link_to(image_tag(recipe.image), image_path(recipe_path(recipe.uri)) ) %>

+

<%= link_to "#{recipe.title}", recipe_path(recipe.uri) %>

<% listing +=1 %> <% end %>
<% end %>
-

+

+

+ Not quite where I want this to go yet: + <%= link_to "Next", search_path(@recipes) %> +

+
+ diff --git a/app/views/recipes/show.html.erb b/app/views/recipes/show.html.erb index 2c00843d1..97d004c5c 100644 --- a/app/views/recipes/show.html.erb +++ b/app/views/recipes/show.html.erb @@ -1,12 +1,24 @@
-

<%= @recipe.title %>

+
+

<%= link_to "#{@recipe.title}", @recipe.url %>

+
+

<%= link_to(image_tag(@recipe.image), image_path(recipe_path(@recipe.uri)) ) %>

-

- -

+

Ingredients Needed:

+ <% @recipe.ingredients.each do |ingred| %> +

<%= ingred %>

+ <% end %>
+
+

Dietary Information:

+

+ <% @recipe.diet_info.each do |info| %> + <%= info %> + <% end %> +

+

diff --git a/config/routes.rb b/config/routes.rb index fa8056112..b2943c950 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,8 @@ root 'home#index' - get '/recipes/:id' => 'recipes#show', as: 'recipe' +# Make note that all new /recipes/something routes must go above + get '/recipes/*uri' => 'recipes#show', as: 'recipe', constraints: {uri: /.+/} get '/recipes' => 'recipes#search', as: 'search' diff --git a/lib/edamam_api_wrapper.rb b/lib/edamam_api_wrapper.rb index 2ab0f1078..8d34b0d24 100644 --- a/lib/edamam_api_wrapper.rb +++ b/lib/edamam_api_wrapper.rb @@ -53,7 +53,7 @@ def self.query_sanitation(search_string) def self.get_recipe(recipe_uri) url = BASE_URL + "?r=#{URI.encode(recipe_uri)}" + "&app_id=#{THE_ID}&app_key=#{THE_KEY}" - @data = HTTParty.get(url) + @data = HTTParty.get(url).parsed_response if @data.empty? return nil else diff --git a/lib/recipe.rb b/lib/recipe.rb index af574151f..60d14032b 100644 --- a/lib/recipe.rb +++ b/lib/recipe.rb @@ -1,9 +1,9 @@ # tests first class Recipe - attr_reader :title, :image, :uri, :url, :ingredients, :diet_info, :id #, :clean_query + attr_reader :title, :image, :uri, :url, :ingredients, :diet_info, :listing_set def initialize(listing, title, image, uri, url, ingredients, dietary_info) - @id = listing + @listing_set = listing @title = title @image = image @uri = uri @@ -12,24 +12,19 @@ def initialize(listing, title, image, uri, url, ingredients, dietary_info) @diet_info = dietary_info end - # The RecipesController will send the listing number, but to remember what it means we call it page here and elsewhere def self.search_results(search_query, page=1) # cleaned up in wrapper - return EdamamApiWrapper.list_recipes(search_query, page) + @search_query = search_query + @page = page + return @recipes = EdamamApiWrapper.list_recipes(search_query, page) end -# returns nil if no search query available or if the id is not in use - def self.find(id) - recipes = Recipe.search_results(@clean_query) - recipes.each do |recipe| - if recipe.id == id - #SUCCESS - return recipe - end - end - return nil + def different_page(page_direction) + # @page += page_direction + # return @recipes = EdamamApiWrapper.list_recipes(@search_query, @page) end + # Method makes sure two recipe objects with the same content are the same def ==(another_recipe) return self.title == another_recipe.title && self.image == another_recipe.image && self.uri == another_recipe.uri && self.url == another_recipe.url && self.ingredients == another_recipe.ingredients && self.diet_info == another_recipe.diet_info diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb index ff5115385..e3036b1a1 100644 --- a/test/controllers/recipes_controller_test.rb +++ b/test/controllers/recipes_controller_test.rb @@ -7,7 +7,7 @@ class RecipesControllerTest < ActionController::TestCase params = {"q" => "cilantro"} get :search, params assert_response 200 - assert_template :index + assert :index end end @@ -19,23 +19,32 @@ class RecipesControllerTest < ActionController::TestCase end end - test "if search query is invalid or there are no results it will return an empty array, and redirect_to root" do - assert false - end - test "search should render the correct page" do VCR.use_cassette("recipes") do params = {"q" => "tilapia", "page" => 2} get :search, params - assert + assert_response 200 + assert :index + end + end + + test "should get show" do + VCR.use_cassette("recipes") do + params = {"uri" => "http://www.edamam.com/ontologies/edamam.owl#recipe_55a8fd184bca071fefbbdc01325f88ef"} + get :show, params + assert_response :success + assert_response 200 # also works + assert :show end end - # test "should get show" do - # VCR.use_cassette("recipes") do - # get :show, id: 0 - # assert_response :success - # end - # end +# # parsing error in get_recipe that I dont know how to solve +# test "should not get show for invalid uri params" do +# VCR.use_cassette("recipe") do +# params = {"uri" => 'myrecipes.com'} +# get :show, params +# assert :show +# end +# end end diff --git a/test/lib/recipe_test.rb b/test/lib/recipe_test.rb index 32d0c0bd2..32fa2698a 100644 --- a/test/lib/recipe_test.rb +++ b/test/lib/recipe_test.rb @@ -2,7 +2,7 @@ class RecipeTest < ActiveSupport::TestCase - test "Recipe.search_results should return an array of recipes with a given search_query" do + test "Recipe.search_results should return an array of recipes" do VCR.use_cassette("hits") do clean_string = "cilantro" recipes = Recipe.search_results(clean_string) @@ -24,10 +24,29 @@ class RecipeTest < ActiveSupport::TestCase assert_equal([], Recipe.search_results(nil_that_should_be_a_string)) end -#show - # test "find should be able to find the instance recipe with specified id" do - # # params_id = 0 - # # assert_instance_of Recipe, Recipe.find(params_id) + # test "different_page can be called after self.search_results and should return an array of recipes" do + # VCR.use_cassette("hits") do + # # we already asserted this works + # clean_string = "cilantro" + # working_recipes = Recipe.search_results(clean_string) + # + # # test that this works to request the next set of recipes + # next_set_recipes = working_recipes.different_page(1) + # assert_kind_of Array, next_set_recipes + # assert_not next_set_recipes.empty? + # next_set_recipes.each do |recipe| + # assert_kind_of Recipe, recipe + # end + # + # # test that this works to request the previous set of recipes + # previous_set_recipes = working_recipes.different_page((-1)) + # + # assert_kind_of Array, previous_set_recipes + # assert_not previous_set_recipes.empty? + # previous_set_recipes.each do |recipe| + # assert_kind_of Recipe, recipe + # end + # end # end test "two different recipe objects with the same data should be equal" do From b514aba07cfe5666dc92beee4c6f1fe9602bb5a7 Mon Sep 17 00:00:00 2001 From: Alma Maizels Date: Sat, 5 Nov 2016 22:42:53 -0700 Subject: [PATCH 14/14] Through TDD added feature to change recipe listings back and forward, and to first page --- app/controllers/recipes_controller.rb | 21 ++++-- app/views/recipes/index.html.erb | 15 +++-- config/routes.rb | 2 + lib/recipe.rb | 10 ++- test/controllers/recipes_controller_test.rb | 41 +++++++++++ test/lib/recipe_test.rb | 75 ++++++++++++--------- 6 files changed, 119 insertions(+), 45 deletions(-) diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 12e60cbce..b18983d1c 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -7,8 +7,8 @@ def search if params["q"] != "" # SUCCESS search_string = recipe_params[:q] - page = (recipe_params[:page] || 1).to_i - @recipes = Recipe.search_results(search_string, page) + @page = (recipe_params[:page] || 1).to_i + @recipes = Recipe.search_results(search_string, @page) # We have control over Recipe search results (in /lib) # raise @@ -24,15 +24,28 @@ def search end def show - show_params = params[:uri] + show_params = recipe_params[:uri] # Will stop some invalid recipes rather than showing an empty list @recipe = EdamamApiWrapper.get_recipe(show_params) end + def more + @page = (recipe_params[:page] || 1).to_i + more_direction = recipe_params[:page_direction].to_i + # the Recipe class stops invalid page changes + @recipes = Recipe.change_page(more_direction) + if (@page + more_direction)>1 + @page += more_direction + params[:page] = @page + end + + render :index + end + private def recipe_params - params.permit(:q, :page) + params.permit(:q, :page, :uri, :page_direction) end diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index b9c2f2154..6599f89cf 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -1,25 +1,30 @@

<% if @recipes != nil %> - <% listing = 1 %>
<% @recipes.each do |recipe| %>
- <%= "#{listing}" %>

<%= link_to(image_tag(recipe.image), image_path(recipe_path(recipe.uri)) ) %>

<%= link_to "#{recipe.title}", recipe_path(recipe.uri) %>

- <% listing +=1 %> <% end %>
<% end %>

- Not quite where I want this to go yet: - <%= link_to "Next", search_path(@recipes) %> + <% page_number = params[:page].to_i %> + <% if page_number > 1 %> + <%= link_to "First Page", search_path(q: "cilantro") %> + <% if page_number > 2 %> + <%= link_to "<<", recipes_more_path({page_direction: "-2"}) %> + <% end %> + <%= link_to "<", recipes_more_path({page_direction: "-1"}) %> + <% end %> + <%= link_to ">", recipes_more_path({page_direction: "1"}) %> + <%= link_to ">>", recipes_more_path({page_direction: "2"}) %>