mardi 22 septembre 2015

Rails controller test error

I'am making a controller test, but I have this error. My model tests passing, but about this I don't know what is going on:

/cook-book/test/controllers/recipes_controller_test.rb:23]:  "Recipe.count" didn't change by 1 Expected: 3 Actual: 2

my 'recipes_controller_test.rb':

require 'test_helper'

class RecipesControllerTest < ActionController::TestCase
  include Devise::TestHelpers
    setup do
       @recipe = recipes(:one)
       user = User.create!(email: "example2@test.com", password:      "password",password_confirmation: "password" )
       sign_in user
    end  
   ....
  test "should create recipe" do
    assert_difference('Recipe.count') do
      post :create, recipe: { title: @recipe.title, image_file_name: @recipe.image_file_name, ingredients: @recipe.ingredients, description: @recipe.description } 
      end

    assert_redirected_to recipe_path(assigns(:recipe))
   end 

'recipes.yml':

one:
 title: MyString
 image_file_name: Myimage
 ingredients: MyText
 description: MyText

two:
 title: MyString
 image_file_name: Myimage
 ingredients: MyText
 description: MyText

and recipe model:

class Recipe < ActiveRecord::Base
  belongs_to :category
  belongs_to :user
  has_many :comments
  has_attached_file :image, styles: { medium: "400x400#", small: "250x250#"}
  validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
  validates :title, presence: true, length: { maximum: 30 }
  validates :ingredients, presence: true
  validates :description, presence: true
  validates :image, presence: true
  searchkick
end

Thanks!

Aucun commentaire:

Enregistrer un commentaire