Skip to content

Commit

Permalink
recording variety of changes to get controller tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirv committed Jun 9, 2017
1 parent 1bcc1ab commit 18b344b
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 71 deletions.
22 changes: 22 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
exit
step
exps
e.call
e
before
step
exps
step
exps
e
step
expression
step
@user
Recipe.count
exit
response.body
response
exit
@recipe
recipe
q!
eval raise(exception)
eval e
Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ gem 'raphael-rails'

group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
# gem 'spring'
end

group :development, :test do
gem 'sqlite3'
gem 'pry'
gem 'byebug'
gem 'guard'
gem 'guard-minitest'

end

group :production do
Expand Down
35 changes: 31 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ GEM
execjs (2.7.0)
faraday (0.11.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
figaro (1.1.1)
thor (~> 0.14)
fission (0.5.0)
Expand Down Expand Up @@ -228,6 +229,19 @@ GEM
formatador (0.2.5)
globalid (0.3.7)
activesupport (>= 4.1.0)
guard (2.14.1)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-minitest (2.4.6)
guard-compat (~> 1.2)
minitest (>= 3.0)
hashie (3.5.5)
i18n (0.8.1)
inflecto (0.0.2)
Expand All @@ -243,8 +257,13 @@ GEM
railties (>= 3.2.16)
json (1.8.6)
jwt (1.5.6)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lumberjack (1.0.12)
mail (2.6.4)
mime-types (>= 1.16, < 4)
mailboxer (0.14.0)
Expand All @@ -262,9 +281,13 @@ GEM
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nenv (0.3.0)
net-ssh (3.2.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
oauth (0.5.1)
oauth2 (1.3.1)
faraday (>= 0.8, < 0.12)
Expand Down Expand Up @@ -330,6 +353,9 @@ GEM
ranked-model (0.4.0)
activerecord (>= 3.1.12)
raphael-rails (2.1.2)
rb-fsevent (0.9.8)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
rbvmomi (1.11.0)
builder (~> 3.0)
json (>= 1.8)
Expand All @@ -338,6 +364,7 @@ GEM
rdoc (4.3.0)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
ruby_dep (1.5.0)
sass (3.4.23)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
Expand All @@ -352,15 +379,14 @@ GEM
activemodel (>= 4.1)
elasticsearch (>= 1)
hashie
shellany (0.0.1)
simple_form (3.4.0)
actionpack (> 4, < 5.1)
activemodel (> 4, < 5.1)
slop (3.6.0)
social-share-button (0.1.10)
coffee-rails
sass-rails
spring (2.0.1)
activesupport (>= 4.2)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand Down Expand Up @@ -413,6 +439,8 @@ DEPENDENCIES
figaro
fog (~> 1.38.0)
font-awesome-sass (~> 4.6.2)
guard
guard-minitest
jbuilder (~> 2.0)
jquery-rails
jquery-ui-rails (~> 5.0, >= 5.0.5)
Expand All @@ -435,7 +463,6 @@ DEPENDENCIES
searchkick
simple_form
social-share-button
spring
sqlite3
turbolinks
uglifier (>= 1.3.0)
Expand All @@ -447,4 +474,4 @@ RUBY VERSION
ruby 2.3.0p0

BUNDLED WITH
1.13.6
1.14.4
44 changes: 44 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"


guard :minitest do
# with Minitest::Unit
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' }

# with Minitest::Spec
# watch(%r{^spec/(.*)_spec\.rb$})
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }

# Rails 4
watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
watch(%r{^test/.+_test\.rb$})
watch(%r{^test/test_helper\.rb$}) { 'test' }
watch(%r{^test/controllers/*.rb})

# Rails < 4
# watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
# watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
# watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
end
8 changes: 4 additions & 4 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +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



def search
if params[:search].present?
@recipes = Recipe.search(params[:search])
Expand Down Expand Up @@ -93,9 +92,10 @@ def set_user
@user = User.find(current_user.id)
end


# name: , summary: , description: , prep_times: , servings_made:
def recipe_params
params.require(:recipe).permit(:user_id, :chef_id, :name, :summary, :description, :picture, style_ids: [], ingredients_attributes: [:id, :name, :_destroy], directions_attributes: [:id, :step, :_destroy], feed_ids: [], calorie_ids: [], preptime_ids: [])
params.require(:recipe).permit(:id, :user_id, :name, :summary, :description,
:prep_times, :servings_made )
end

def set_recipe
Expand Down
3 changes: 3 additions & 0 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Recipe < ActiveRecord::Base

# 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}
Expand Down
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

config.log_level = :debug

end
5 changes: 5 additions & 0 deletions db/migrate/20170603191543_add_prep_to_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPrepToRecipes < ActiveRecord::Migration
def change
add_column :recipes, :prep_time, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170605004344_add_feeds_to_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFeedsToRecipes < ActiveRecord::Migration
def change
add_column :recipes, :feeds, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170605014412_add_preptimes_to_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPreptimesToRecipes < ActiveRecord::Migration
def change
add_column :recipes, :prep_times, :integer
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170605014604_remove_preptime_from_recipes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemovePreptimeFromRecipes < ActiveRecord::Migration
def change
remove_column :recipes, :prep_time
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170606044516_add_servings_made_to_recipe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddServingsMadeToRecipe < ActiveRecord::Migration
def change
add_column :recipes, :servings_made, :integer
end
end
7 changes: 5 additions & 2 deletions 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: 20170413232840) do
ActiveRecord::Schema.define(version: 20170606044516) do

create_table "directions", force: :cascade do |t|
t.text "step"
Expand Down Expand Up @@ -180,6 +180,9 @@
t.datetime "updated_at"
t.string "picture"
t.integer "user_id"
t.integer "feeds"
t.integer "prep_times"
t.integer "servings_made"
end

add_index "recipes", ["user_id"], name: "index_recipes_on_user_id"
Expand Down Expand Up @@ -275,4 +278,4 @@
add_index "zets", ["exercise_id"], name: "index_zets_on_exercise_id"
add_index "zets", ["workout_id"], name: "index_zets_on_workout_id"

end
end
4 changes: 2 additions & 2 deletions test/controllers/ingredient_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'test_helper'

class IngredientControllerTest < ActionController::TestCase
test "should get name:string" do
test "should get name" do
get :name
assert_response :success
end

test "should get recipe_id:integer" do
test "should get recipe_id" do
get :recipe_id
assert_response :success
end
Expand Down
6 changes: 0 additions & 6 deletions test/controllers/recipe_controller_test.rb

This file was deleted.

Loading

0 comments on commit 18b344b

Please sign in to comment.