diff --git a/README.rdoc b/README.rdoc index ac65a31..bcc199c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,46 +1,10 @@ # Readme -- Mirv's trouble shooting steps - To Do Listing - Beta Listing --- -Javascript trouble shooting stuff ... - - - First we need to decide if it's a loading issue - Open the web browser console & check `elements` for your js file names - ... saw the cocoon was loaded under the "elements" section - - Opened the /layouts/application.html.erb file & ensured there was only one javascript_include_tag. - - Also that the javascript_include_tag was in the tag & that the head tag is properly closed with - - Look for other non-essential or extra service loading files - ... Sumo was generating 4 errors in the chrome console, so I commented that out - - Checked the /app/assets/javascript folder for the application.js file, also that there's no .coffee files (rails autos them) - ... for some reason, you have `app/assets/javascript/exercise.coffee` showing up in the directory - - Check inside the application.js file ... - - Check order of your /app/assets/javascript/application.js files being loaded - ... yours is wrong ... the `//= require_tree .` - ... absolutely must be at the bottom or you're going to have issues including all the files. - - Additionally, you had two files which did not have the required, `//= ` in front of them. It's required to load them - - Ensure no extra scripts being loaded in the views, I use `grep -r 'script' /app` & check any spot that shows up - ... I'm finding scripts in your view files instead of the assets files for javascript ... - If the asset asset is loading, we know it's either a conflict or poorly written code - - Insert a piece of test code in the console so when the $.document or the turbolinks finished loading to see if it's poor code - ... they will report to console a string ("Page -- Loaded") in my case, - - If it doesn't load, it's a conflict with other java files, if it loads, it's just your code needs to be fixed - - I pull all the entries from the application.js except a test.js file (look up how to capture to log js to console) - - At this point it should work if everything before it passed ... if not you might have corrupt files - ... you should go into application.html.erb & use javascript_include_tag to include a CDN version of Jquery (google it) - - Assuming the test.js works ... - ... first, in your `app/assets/javascript/application.js`, at the bottom of the file up the `//= .` & save it ... - ... now, you should re-add your js files to the app/assets/javascript one at a time, testing each time by refreshing the ... - ... webpage, possibly restarting the server after copying the file in & doing a rake or rails assets like shown below - ... `rails assets:clean` & the `rails assets:precompile` - - - ---- - - to do first: - add images parralax image to aws diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index b0557a5..0bea0f8 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -5,7 +5,6 @@ class RecipesController < ApplicationController before_action :authenticate_user!, except: [:show, :index, :like, :search] before_action :require_same_user, only: [:edit, :update] before_action :admin_user, only: :destroy - # before_action :check_params def search if params[:search].present? @@ -97,26 +96,12 @@ def set_user def recipe_params params.require(:recipe).permit( - :name, - :summary, - :description, - :prep_times, # fails assert always valid - :servings_made, - :feeds, - :user_id, - - + :name, :summary, :description, :prep_times, + :servings_made, :feeds, :user_id, :calories, :picture, style_ids: [], ingredients_attributes: [:id, :name, :_destroy], - directions_attributes: [:id, :name, :step, :_destroy], - - # calorie_ids: [], # Need to replace - - # preptime_ids: [] # Don't use anymore - # feed_ids: [], # Don't use anymore - # :chef_id, # Don't use anymore - ) + directions_attributes: [:id, :name, :step, :_destroy]) end def set_recipe @@ -129,48 +114,8 @@ def require_same_user redirect_to recipes_path end end - def admin_user redirect_to recipes_path unless current_user.admin? end - - # def check_params - # required = [ - # :id, - # :user_id, - # :name, - # :summary, - # :description, - # :prep_times, - # :servings_made - # ] - # if required.all? {|k, m| params.has_key? k} - # # here you know params has all the keys defined in required array - # puts "\n\n\All params set\n\n" - # else - # puts "\n\n\One of params not set\n\n" - # puts YAML::dump(params) - # end - # end - # def check_params - # required = [ - # :id, - # :user_id, - # :name, - # :summary, - # :description, - # :prep_times, - # :servings_made - # ] - # visible_required = [] - # # puts "----Doing required.each----" - # required.each { |k| if (params.has_key? k) then visible_required << k else puts "was wrong ... #{k}" end } - # # puts "----Doing Passed----" - # visible_required.each { |k| puts "This is .... #{k}" } - # puts "----Doing params.each----" - # params.each { |k, m| puts "Key: #{k} -- value: #{m}" } - # # puts "\n\n Recipe debug: #{YAML::dump(params)} \n\n" - # # puts params.inspect - # end end \ No newline at end of file diff --git a/app/models/recipe.rb b/app/models/recipe.rb index a2d6a5f..85dce5d 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -8,18 +8,8 @@ class Recipe < ActiveRecord::Base has_many :reviews has_many :comments, as: :commentable - has_many :recipe_feeds - ### Going to a integer & no relationship #### - ### Going to a integer & no relationship #### - - # has_many :feeds, through: :recipe_feeds - # has_many :recipe_preptimes - # has_many :preptimes, through: :recipe_preptimes - has_many :recipe_calories - has_many :calories, through: :recipe_calories - - ### Going to a integer & no relationship #### - ### Going to a integer & no relationship #### + # has_many :recipe_feeds + # searchkick accepts_nested_attributes_for :ingredients, @@ -30,18 +20,23 @@ class Recipe < ActiveRecord::Base allow_destroy: true validates :user_id, presence: true - # validates :directions, presence: true - # validates :ingredients, presence: true + validates :name, presence: true, length: { minimum: 5, maximum: 100} validates :summary, presence: true, length: { minimum: 10, maximum: 150} validates :description, presence: true, length: { minimum: 5, maximum: 1000} validates :servings_made, presence: true validates :prep_times, presence: true validates :feeds, presence: true + validates :calories, presence: true # mount_uploader :picture, PictureUploader # validate :picture_size + #### These two really don't belong - should be tested in their model #### + # validates :directions, presence: true + # validates :ingredients, presence: true + #### + def thumbs_up_total self.likes.where(like: true).size end diff --git a/db/migrate/20170616205910_add_calories_to_recipe.rb b/db/migrate/20170616205910_add_calories_to_recipe.rb new file mode 100644 index 0000000..c5ec4f1 --- /dev/null +++ b/db/migrate/20170616205910_add_calories_to_recipe.rb @@ -0,0 +1,5 @@ +class AddCaloriesToRecipe < ActiveRecord::Migration + def change + add_column :recipes, :calories, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 1c84deb..99ce1b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170606044516) do +ActiveRecord::Schema.define(version: 20170616205910) do create_table "directions", force: :cascade do |t| t.text "step" @@ -183,6 +183,7 @@ t.integer "feeds" t.integer "prep_times" t.integer "servings_made" + t.integer "calories" end add_index "recipes", ["user_id"], name: "index_recipes_on_user_id" diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb index 1bc4e52..03aa3db 100644 --- a/test/controllers/recipes_controller_test.rb +++ b/test/controllers/recipes_controller_test.rb @@ -40,9 +40,9 @@ class RecipesControllerTest < ActionDispatch::IntegrationTest prep_times: @recipe.prep_times, servings_made: @recipe.servings_made, feeds: 3, - user_id: 1 + user_id: 1, + calories: 15 } assert_redirected_to recipe_url(@recipe) - end end \ No newline at end of file diff --git a/test/fixtures/recipes.yml b/test/fixtures/recipes.yml index fdefd0a..32e2f63 100644 --- a/test/fixtures/recipes.yml +++ b/test/fixtures/recipes.yml @@ -6,9 +6,10 @@ one: description: MyText prep_times: MyTest servings_made: 10 - # feeds: 3 - # picture: + feeds: 3 user_id: 1 + calories: 15 + # picture: two: name: MyString2 diff --git a/test/models/recipe_test.rb b/test/models/recipe_test.rb index f6fba0e..e84f938 100644 --- a/test/models/recipe_test.rb +++ b/test/models/recipe_test.rb @@ -1,13 +1,11 @@ require 'test_helper' class RecipeTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end + setup do @recipe = Recipe.new(name: "SOMEONE", summary: "Something Else", description: "Something Else", prep_times: "90", servings_made: "3", - feeds: "3", user_id: 1) + feeds: "3", user_id: 1, calories: 5) end test "@recipe is valid" do @@ -44,8 +42,13 @@ class RecipeTest < ActiveSupport::TestCase refute @recipe.valid?, '@recipe should be invalid - missing feeds, but passed validation' end - test "@recipe should be invalid without user_id" do + test "@recipe should be invalid without user_id" do @recipe["user_id"] = "" refute @recipe.valid?, '@recipe should be invalid - missing user_id, but passed validation' end + + test "@recipe should be invalid without calories" do + @recipe["calories"] = "" + refute @recipe.valid?, '@recipe should be invalid - missing calories, but passed validation' + end end