Skip to content

Commit

Permalink
Cleaned up comments from tests & readme - all recipe controller/model…
Browse files Browse the repository at this point in the history
… now working CRUD
  • Loading branch information
Mirv committed Jun 16, 2017
1 parent 66d10f2 commit 49bb5f5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 118 deletions.
36 changes: 0 additions & 36 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -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 <head> tag & that the head tag is properly closed with </head>
- 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
Expand Down
61 changes: 3 additions & 58 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand All @@ -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
23 changes: 9 additions & 14 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170616205910_add_calories_to_recipe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCaloriesToRecipe < ActiveRecord::Migration
def change
add_column :recipes, :calories, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/recipes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions test/fixtures/recipes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions test/models/recipe_test.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 49bb5f5

Please sign in to comment.