diff --git a/.byebug_history b/.byebug_history index 937a277..2106f09 100644 --- a/.byebug_history +++ b/.byebug_history @@ -1,4 +1,103 @@ exit +result +result.first +next +opts +self +user +next +env[ENV_SESSION_OPTIONS] +next +user +step +status +step +next +name +step +sql +name +step +name +step +Thread.current.status +next +name +step +attr_name +step +attributes[name] +step +value +step +attr +step +other +step +value +step +name +step +self +value +step +env["rack.errors"].inspect +env["rack.errors"].debug +env["rack.errors"].name +env["rack.errors"] +env +step +set_host(v) +v +@host +step +@user +step +value +step +k +step +value +step +str +step +value +step +params +step +@@schemes +step +path +parameters +step +@value +step +attributes +step +@value +@valu +step +@recipe +exit +step +ivar +step +@path_helper_modules +step +exception +step +exception +step +exception +step +app +step +@integration_session +step +@integration_session +step +@recipe +exit eixt step eval recipes diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 97269b3..238535b 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -5,6 +5,7 @@ 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? @@ -50,6 +51,8 @@ def update flash[:success] = "Your recipe was update success" redirect_to recipe_path(@recipe) else + puts "\n\n Recipe debug: #{YAML::dump(params)} \n\n" + render :edit end end @@ -66,7 +69,6 @@ def like end def destroy - @recipe.destroy! flash[:success] = "Recipe Deleted" redirect_to recipes_path @@ -93,19 +95,25 @@ def set_user @user = User.find(current_user.id) end - # name: , summary: , description: , prep_times: , servings_made: def recipe_params - # raise recipe_params.inspect + params.require(:recipe).permit( + :name, + :summary, + :description, + :prep_times, + :servings_made, + :feeds, + :user_id, - params.require(:recipe).permit(:id, :user_id, :name, :summary, :description, - :prep_times, :servings_made, - :picture, :chef_id, - style_ids: [], - ingredients_attributes: [:id, :name, :_destroy], - directions_attributes: [:id, :name, :step, :_destroy], - feed_ids: [], - calorie_ids: [], - preptime_ids: []) + # :picture, + # :chef_id, + # style_ids: [], + # ingredients_attributes: [:id, :name, :_destroy], + # directions_attributes: [:id, :name, :step, :_destroy], + # feed_ids: [], + # calorie_ids: [], + # preptime_ids: [] + ) end def set_recipe @@ -124,4 +132,42 @@ 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 7693734..4de0c98 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -12,7 +12,8 @@ class Recipe < ActiveRecord::Base has_many :recipe_preptimes has_many :preptimes, through: :recipe_preptimes has_many :recipe_feeds - has_many :feeds, through: :recipe_feeds + # Going to a integer & no relationship + # has_many :feeds, through: :recipe_feeds # searchkick accepts_nested_attributes_for :ingredients, reject_if: proc { |attributes| attributes['name'].blank? }, @@ -21,19 +22,18 @@ class Recipe < ActiveRecord::Base reject_if: proc { |attributes| attributes['step'].blank? }, allow_destroy: true - # This one was erroring the system out - # validates :user_id, presence: true - + validates :user_id, presence: true # validates :directions, presence: true # validates :ingredients, presence: true - # validates :feeds, presence: true - validates :servings_made, presence: true - validates :prep_times, 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} - mount_uploader :picture, PictureUploader - validate :picture_size + validates :servings_made, presence: true + validates :prep_times, presence: true + validates :feeds, presence: true + + # mount_uploader :picture, PictureUploader + # validate :picture_size def thumbs_up_total self.likes.where(like: true).size diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index 80e31a9..0aee9cb 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -32,9 +32,9 @@ <% if recipe.ingredients.any? %>

Ingredients: <%= render recipe.ingredients %>

<% end %> - <% if recipe.feeds.any? %> -

Feeds: <%= render recipe.feeds %>

- <% end %> + +

Feeds: <%= recipe.feeds %>

+ <% if recipe.preptimes.any? %>

Preptime: <%= render recipe.preptimes %>

<% end %> diff --git a/app/views/recipes/show.html.erb b/app/views/recipes/show.html.erb index 5548eda..2eb1621 100644 --- a/app/views/recipes/show.html.erb +++ b/app/views/recipes/show.html.erb @@ -33,9 +33,9 @@ <% if @recipe.styles.any? %>

Styles: <%= render @recipe.styles %>

<% end %> - <% if @recipe.feeds.any? %> -

Feeds: <%= render @recipe.feeds %>

- <% end %> + +

Feeds: <%= @recipe.feeds %>

+ <% if @recipe.preptimes.any? %>

Preptime: <%= render @recipe.preptimes %>

<% end %> diff --git a/error_result.rb b/error_result.rb new file mode 100644 index 0000000..c26692e --- /dev/null +++ b/error_result.rb @@ -0,0 +1,30 @@ +[200, {"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "Content-Type"=>"text/html; charset=utf-8"}, +# +, @stream=#, @buf=["\n\n \n +Edit a Recipe | FitnessLabs (A & K LABS)\n \n \n \n \n \n +\n \n \n +\n \n \n \n
\n \n
\n\n \n
\n
\n
\n
\n
\n \n
\n
\n
Please correct the following errors:
\n
    \n
  • Summary is too short (minimum is 10 characters)
  • \n
\n
\n
\n\n
\n
\n
\n \n \n \n
\n
\n \n
\n \n \n
\n
\n \n
\n \n
\n \n \n
\n Add Step\n
\n
\n
\n
\n \n \n \n
\n
\n Styles: \n
\n
\n Feeds: \n
\n
\n Preptime: \n
\n
\n Calories: \n\n
\n
\n \n Upload image: \n \n +\n \n
\n \n
\n
\n\n\n\n
\n \n \n\n\n \n \n"], @closed=false>, @header={"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "Content-Type"=>"text/html; charset=utf-8"}, @status=200, @sending_file=false, @blank=false, @cv=#, @cond=#>, @committed=false, @sending=false, @sent=false, @content_type="text/html", @charset="utf-8", @cache_control={}, @etag=nil, @request=#[1, 3], "rack.input"=>#, "rack.errors"=>#, "rack.multithread"=>false, "rack.multiprocess"=>true, "rack.run_once"=>false, "REQUEST_METHOD"=>"PATCH", "SERVER_NAME"=>"www.example.com", "SERVER_PORT"=>"80", "QUERY_STRING"=>"", "PATH_INFO"=>"/recipes/980190962", "rack.url_scheme"=>"http", "HTTPS"=>"off", "SCRIPT_NAME"=>"", "CONTENT_LENGTH"=>"163", "rack.test"=>true, "REMOTE_ADDR"=>"127.0.0.1", "REQUEST_URI"=>"/recipes/980190962", "HTTP_HOST"=>"www.example.com:80", "CONTENT_TYPE"=>"application/x-www-form-urlencoded", "HTTP_ACCEPT"=>"text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", "HTTP_COOKIE"=>"", "ORIGINAL_FULLPATH"=>"/recipes/980190962", "ORIGINAL_SCRIPT_NAME"=>"", "action_dispatch.routes"=>#, "action_dispatch.parameter_filter"=>[:password], "action_dispatch.redirect_filter"=>[], "action_dispatch.secret_token"=>nil, "action_dispatch.secret_key_base"=>"2963815850e6542bbdefa7981fe9ded6cbc4076ed3ff551c4806f23921c625f54a6484dcbe1c682716c41ae743f6de714c1574421daa53bc91f54e2bab72dd76", "action_dispatch.show_exceptions"=>false, "action_dispatch.show_detailed_exceptions"=>true, "action_dispatch.logger"=>#, @formatter=#, @logdev=#, @mon_owner=nil, @mon_count=0, @mon_mutex=#>>, "action_dispatch.backtrace_cleaner"=>#, #, #, #], @silencers=[#], @root="/home/ubuntu/workspace/">, "action_dispatch.key_generator"=>#, @cache_keys=#"\xC8f\xFD\xBA\x9BM5\xA08\xD0!\xBE\xA2\xE6\xCB\xA6\x84\xC9N$\xFE\xAA\xE5\ae\xCFShc\x7F\x1FA\xAF\x14h\x8B[#\xA4R)\x19\xEF\x13Yg\x8F\x18\x90\xBDg\e/\xEA\x86\xC4\xBE\x18\x11T\xB1\xDF\x92>", "encrypted cookie64"=>"<\xCC\xC8\xB4\x19\x0E\xF9\xEF\bx\xAF\x13\xD5\x9D\xDD#U\x95\xAB\xF4M>\"1m\xC4d\x81\xE9\xB73R2F\ad\xAC\xA5\xD9\xFB\x8FD5~h\x89\xBD^\x88\xDC\xB8\x00\x1A6\x97T\xA4\xFC3/\xA7f7\x9F", "signed encrypted cookie64"=>"u\xE9\x8Ea\xB6\xD93\xD93S\xB8\xEA\x0E\x9D~AqN\b\x18&\x81\x86\xB7\"!\xA1\xE1\x96\x82L?\xD9W\xFD\xCFX\xC4\xAB\x8C\x06\xB1F>bB\xB9\x8E\xBC/\xDEy]?|\xD1\r\x19\x04\x99\x91]\xA8\xFA"}, @default_proc=nil>>, "action_dispatch.http_auth_salt"=>"http authentication", "action_dispatch.signed_cookie_salt"=>"signed cookie", "action_dispatch.encrypted_cookie_salt"=>"encrypted cookie", "action_dispatch.encrypted_signed_cookie_salt"=>"signed encrypted cookie", "action_dispatch.cookies_serializer"=>:json, "action_dispatch.cookies_digest"=>nil, "ROUTES_46674040_SCRIPT_NAME"=>"", "action_dispatch.request_id"=>"77a8027b-dafa-4003-986a-1973d40a6059", "action_dispatch.remote_ip"=>#, #, #, #, #, #], @ip="127.0.0.1">, "rack.session"=>#:user, :scope_defaults=>{}, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#}, @app=#>, @cache_control="max-age=0, private, must-revalidate", @no_cache_control="no-cache">>>, @parsers={#=>:json}>>, @default_options={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false}, @key="_workspace_session", @cookie_only=true>, @env={...}, @delegate={"session_id"=>"12e25049f4b3168a0e27c63f60fbb217", "warden.user.user.key"=>[[980190963], ""]}, @loaded=true, @exists=nil>, "rack.session.options"=>#:user, :scope_defaults=>{}, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#}, @app=#>, @cache_control="max-age=0, private, must-revalidate", @no_cache_control="no-cache">>>, @parsers={#=>:json}>>, @default_options={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>false}, @key="_workspace_session", @cookie_only=true>, @env={...}, @delegate={:path=>"/", :domain=>nil, :expire_after=>nil, :secure=>false, :httponly=>true, :defer=>false, :renew=>true, :id=>"12e25049f4b3168a0e27c63f60fbb217"}>, "action_dispatch.request.content_type"=>#, "rack.request.cookie_hash"=>{}, "rack.request.cookie_string"=>"", "action_dispatch.cookies"=>#, @cache_keys=#"\xC8f\xFD\xBA\x9BM5\xA08\xD0!\xBE\xA2\xE6\xCB\xA6\x84\xC9N$\xFE\xAA\xE5\ae\xCFShc\x7F\x1FA\xAF\x14h\x8B[#\xA4R)\x19\xEF\x13Yg\x8F\x18\x90\xBDg\e/\xEA\x86\xC4\xBE\x18\x11T\xB1\xDF\x92>", "encrypted cookie64"=>"<\xCC\xC8\xB4\x19\x0E\xF9\xEF\bx\xAF\x13\xD5\x9D\xDD#U\x95\xAB\xF4M>\"1m\xC4d\x81\xE9\xB73R2F\ad\xAC\xA5\xD9\xFB\x8FD5~h\x89\xBD^\x88\xDC\xB8\x00\x1A6\x97T\xA4\xFC3/\xA7f7\x9F", "signed encrypted cookie64"=>"u\xE9\x8Ea\xB6\xD93\xD93S\xB8\xEA\x0E\x9D~AqN\b\x18&\x81\x86\xB7\"!\xA1\xE1\x96\x82L?\xD9W\xFD\xCFX\xC4\xAB\x8C\x06\xB1F>bB\xB9\x8E\xBC/\xDEy]?|\xD1\r\x19\x04\x99\x91]\xA8\xFA"}, @default_proc=nil>>, @set_cookies={}, @delete_cookies={}, @host="www.example.com", @secure=false, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>nil, :secret_key_base=>"2963815850e6542bbdefa7981fe9ded6cbc4076ed3ff551c4806f23921c625f54a6484dcbe1c682716c41ae743f6de714c1574421daa53bc91f54e2bab72dd76", :upgrade_legacy_signed_cookies=>false, :serializer=>:json, :digest=>nil}, @cookies={}, @committed=false, @encrypted=#, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>nil, :secret_key_base=>"2963815850e6542bbdefa7981fe9ded6cbc4076ed3ff551c4806f23921c625f54a6484dcbe1c682716c41ae743f6de714c1574421daa53bc91f54e2bab72dd76", :upgrade_legacy_signed_cookies=>false, :serializer=>:json, :digest=>nil}, @encryptor=#bB\xB9\x8E\xBC/\xDEy]?|\xD1\r\x19\x04\x99\x91]\xA8\xFA", @cipher="aes-256-cbc", @verifier=#bB\xB9\x8E\xBC/\xDEy]?|\xD1\r\x19\x04\x99\x91]\xA8\xFA", @digest="SHA1", @serializer=ActiveSupport::MessageEncryptor::NullSerializer>, @serializer=ActiveSupport::MessageEncryptor::NullSerializer>>, @signed_or_encrypted=#, @options={:signed_cookie_salt=>"signed cookie", :encrypted_cookie_salt=>"encrypted cookie", :encrypted_signed_cookie_salt=>"signed encrypted cookie", :secret_token=>nil, :secret_key_base=>"2963815850e6542bbdefa7981fe9ded6cbc4076ed3ff551c4806f23921c625f54a6484dcbe1c682716c41ae743f6de714c1574421daa53bc91f54e2bab72dd76", :upgrade_legacy_signed_cookies=>false, :serializer=>:json, :digest=>nil}, @encryptor=#bB\xB9\x8E\xBC/\xDEy]?|\xD1\r\x19\x04\x99\x91]\xA8\xFA", @cipher="aes-256-cbc", @verifier=#bB\xB9\x8E\xBC/\xDEy]?|\xD1\r\x19\x04\x99\x91]\xA8\xFA", @digest="SHA1", @serializer=ActiveSupport::MessageEncryptor::NullSerializer>, @serializer=ActiveSupport::MessageEncryptor::NullSerializer>>>, "action_dispatch.request.unsigned_session_cookie"=>{"session_id"=>"12e25049f4b3168a0e27c63f60fbb217"}, "warden"=>Warden::Proxy:43594380 @config={:default_scope=>:user, :scope_defaults=>{}, :default_strategies=>{:user=>[:rememberable, :database_authenticatable]}, :intercept_401=>false, :failure_app=>#}, "action_dispatch.request.path_parameters"=>{:controller=>"recipes", :action=>"update", :id=>"980190962"}, "action_controller.instance"=>#"text/html"}, @_status=200, @_request=#, @_response=#, @_env={...}, @_lookup_context=#, @details={:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}, @skip_default_locale=false, @cache=true, @prefixes=["recipes", "application"], @rendered_format=:html, @view_paths=#=>####[app/views/recipes/edit.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "recipes"=>###[]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "application"=>###[app/views/layouts/application.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "form"=>###[app/views/recipes/_form.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "errors"=>###[app/views/shared/_errors.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "ingredient_fields"=>###[app/views/recipes/_ingredient_fields.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "direction_fields"=>###[app/views/recipes/_direction_fields.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "navigation2"=>###[app/views/layouts/_navigation2.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "messages"=>###[app/views/layouts/_messages.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "footer"=>###[app/views/layouts/_footer.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>>, @path="/home/ubuntu/workspace/app/views">, #=>####[]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>>, @path="/usr/local/rvm/gems/ruby-2.3.0/gems/devise-4.2.1/app/views">, #=>####[]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>>, @path="/usr/local/rvm/gems/ruby-2.3.0/gems/mailboxer-0.14.0/app/views">]>>, @_action_name="update", @_response_body=["\n\n \n Edit a Recipe | FitnessLabs (A & K LABS)\n \n \n \n \n \n \n \n \n \n \n \n \n
\n \n
\n\n \n
\n
\n
\n
\n
\n \n
\n
\n
Please correct the following errors:
\n
    \n
  • Summary is too short (minimum is 10 characters)
  • \n
\n
\n
\n\n
\n
\n
\n \n \n \n
\n
\n \n
\n \n \n
\n
\n \n
\n \n
\n \n \n
\n Add Step\n
\n
\n
\n
\n \n \n \n
\n
\n Styles: \n
\n
\n Feeds: \n
\n
\n Preptime: \n
\n
\n Calories: \n\n
\n
\n \n Upload image: \n \n \n \n
\n \n
\n
\n\n\n\n
\n \n \n\n\n \n \n"], @marked_for_same_origin_verification=false, @_config={}, @current_user=#, @user=#, @_params={"recipe"=>{"servings_made"=>"10", "id"=>"980190962", "name"=>"This is a name", "summary"=>"MyText2", "description"=>"MyText", "prep_times"=>"0", "user_id"=>"1"}, "controller"=>"recipes", "action"=>"update", "id"=>"980190962"}, @recipe=#, @_db_runtime=10.62725, @_view_renderer=#, @details={:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}, @skip_default_locale=false, @cache=true, @prefixes=["recipes", "application"], @rendered_format=:html, @view_paths=#=>####[app/views/recipes/edit.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "recipes"=>###[]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "application"=>###[app/views/layouts/application.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "form"=>###[app/views/recipes/_form.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "errors"=>###[app/views/shared/_errors.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "ingredient_fields"=>###[app/views/recipes/_ingredient_fields.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "direction_fields"=>###[app/views/recipes/_direction_fields.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "navigation2"=>###[app/views/layouts/_navigation2.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "messages"=>###[app/views/layouts/_messages.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>, "footer"=>###[app/views/layouts/_footer.html.erb]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>>, @path="/home/ubuntu/workspace/app/views">, #=>####[]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>>, @path="/usr/local/rvm/gems/ruby-2.3.0/gems/devise-4.2.1/app/views">, #=>####[]}, @default_proc=nil>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>}, @default_proc=#>>, @path="/usr/local/rvm/gems/ruby-2.3.0/gems/mailboxer-0.14.0/app/views">]>>>, @_view_context_class=#, @_url_options={:host=>"www.example.com", :port=>nil, :protocol=>"http://", :_recall=>{:controller=>"recipes", :action=>"update", :id=>"980190962"}}, @mailbox=#>, @_searchkick_runtime=0, @_view_runtime=544.9214299610742>, "rack.request.form_hash"=>{"recipe"=>{"servings_made"=>"10", "id"=>"980190962", "name"=>"This is a name", "summary"=>"MyText2", "description"=>"MyText", "prep_times"=>"0", "user_id"=>"1"}}, "rack.request.form_vars"=>"recipe[servings_made]=10&recipe[id]=980190962&recipe[name]=This+is+a+name&recipe[summary]=MyText2&recipe[description]=MyText&recipe[prep_times]=0&recipe[user_id]=1", "rack.request.form_input"=>#, "action_dispatch.request.request_parameters"=>{"recipe"=>{"servings_made"=>"10", "id"=>"98019096 +2", "name"=>"This is a name", "summary"=>"MyText2", "description"=>"MyText", "prep_times"=>"0", "user_id"=>"1"}}, "rack.request.query_string"=>"", "rack.request.query_hash"=> + +{}, "action_dispatch.request.query_parameters"=>{}, "action_dispatch.request.parameters"=>{"recipe"=>{"servings_made"=>"10", "id"=>"980190962", "name"=>"This is a name", "s + +ummary"=>"MyText2", "description"=>"MyText", "prep_times"=>"0", "user_id"=>"1"}, "controller"=>"recipes", "action"=>"update", "id"=>"980190962"}, "action_dispatch.request.for +mats"=>[#], "action_dispatch.request.flash_hash"=>#, @flashes={}, @now=nil>}, @filtered_parameters={"recipe"=>{"servings_made"=>"10", "id"=>"980190962", "name"=>"This is a name", "su +mmary"=>"MyText2", "description"=>"MyText", "prep_times"=>"0", "user_id"=>"1"}, "controller"=>"recipes", "action"=>"update", "id"=>"980190962"}, @filtered_env=nil, @filtered_p +ath=nil, @protocol="http://", @port=80, @method=nil, @request_method="PATCH", @remote_ip="127.0.0.1", @original_fullpath=nil, @fullpath="/recipes/980190962", @ip=nil, @uuid=nil>>>] \ No newline at end of file diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb index 8aea01e..1bc4e52 100644 --- a/test/controllers/recipes_controller_test.rb +++ b/test/controllers/recipes_controller_test.rb @@ -30,22 +30,19 @@ class RecipesControllerTest < ActionDispatch::IntegrationTest end test "should update recipe" do - @recipe = recipes(:one) + sign_in @user + @recipe = recipes(:one) - patch recipe_url(@recipe), params: { recipe: {id: @recipe.id, - name: @recipe.name, summary: @recipe.summary, - description: @recipe.description, prep_times: @recipe.prep_times, - servings_made: @recipe.servings_made} } + patch recipe_url(@recipe), recipe: { + name: "This is a name", + summary: @recipe.summary, + description: @recipe.description, + prep_times: @recipe.prep_times, + servings_made: @recipe.servings_made, + feeds: 3, + user_id: 1 + } assert_redirected_to recipe_url(@recipe) - end - - test "should create recipe" do - assert_difference('Recipe.count') do -# puts "\n\n Body Response #{@body.response} \n\n" - post recipes_url, params: { recipe: { name: "SOMEONE", summary: "Something Else", - description: "Something Else", prep_times: "90", servings_made: "3", user_id: "1"} } - end - - assert_redirected_to recipe_path(Recipe.last) + end end \ No newline at end of file diff --git a/test/fixtures/recipes.yml b/test/fixtures/recipes.yml index 4d53b0e..fdefd0a 100644 --- a/test/fixtures/recipes.yml +++ b/test/fixtures/recipes.yml @@ -2,12 +2,13 @@ one: name: MyString1 - summary: MyText2 + summary: MyText2222222 description: MyText prep_times: MyTest servings_made: 10 + # feeds: 3 # picture: - user_id: one + user_id: 1 two: name: MyString2 diff --git a/test/models/recipe_test.rb b/test/models/recipe_test.rb index acf1ba2..f6fba0e 100644 --- a/test/models/recipe_test.rb +++ b/test/models/recipe_test.rb @@ -4,37 +4,48 @@ 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) + end - test "recipe is valid" do - recipe = Recipe.new(name: "SOMEONE", summary: "Something Else", - description: "Something Else", prep_times: "90", servings_made: "3") - assert recipe.valid?, 'recipe is not valid' + test "@recipe is valid" do + assert @recipe.valid?, '@recipe is not valid' end - - test "recipe should be invalid without description" do - recipe = Recipe.new(name: "Something", summary: "Something Else") - assert recipe.invalid?, 'recipe should be invalid, but passed validation' + + test "@recipe should be invalid without name" do + @recipe["name"] = "" + assert @recipe.invalid?, '@recipe should be invalid without name, but passed validation' end - test "recipe should be invalid without summary" do - recipe = Recipe.new(name: "Something", description: "Something Else") - assert recipe.invalid?, 'recipe should be invalid, but passed validation' + test "@recipe should be invalid without summary" do + @recipe["summary"] = "" + assert @recipe.invalid?, '@recipe should be invalid without summary, but passed validation' end - - test "recipe should be invalid without name" do - recipe = Recipe.new(summary: "Something Else", description: "Something Else") - assert recipe.invalid?, 'recipe should be invalid, but passed validation' + + test "@recipe should be invalid without description" do + @recipe["description"] = "" + assert @recipe.invalid?, '@recipe should be invalid without description, but passed validation' + end + + test "@recipe should be invalid without preptime" do + @recipe["prep_times"] = "" + assert @recipe.invalid?, '@recipe should be invalid - missing prep_times, but passed validation' end - test "recipe should be invalid without preptime" do - recipe = Recipe.new(name: "Something new", summary: "Something Else", - description: "Something Else", servings_made: "3") - assert recipe.invalid?, 'recipe should be invalid - missing prep_times, but passed validation' + test "@recipe should be invalid without servings_made" do + @recipe["servings_made"] = "" + refute @recipe.valid?, '@recipe should be invalid - missing servings_made, but passed validation' end - test "recipe should be invalid without servings_made" do - recipe = Recipe.new(name: "SOMEONE", summary: "Something Else", - description: "Something Else", prep_times: "Something") - refute recipe.valid?, 'recipe should be invalid - missing servings_made, but passed validation' + test "@recipe should be invalid without feeds" do + @recipe["feeds"] = "" + refute @recipe.valid?, '@recipe should be invalid - missing feeds, but passed validation' + end + + 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 end