私は、ブラウザでうまく機能するcarrierwaveを実装しています。ただし、私のテストはこれを返し続けます:
エラー
1) Item
Failure/Error: it { should be_valid }
expected valid? to return true, got false
# ./spec/models/item_spec.rb:36:in `block (2 levels) in <top (required)>'
factory.rb
include ActionDispatch::TestProcess
FactoryGirl.define do
sequence(:email) { |n| "User#{n}@example.com"}
factory :user do
name "John doe"
email
password "foobar"
password_confirmation "foobar"
end
factory :list do
name "Lorem ipsum"
user
end
factory :item do
image { fixture_file_upload(Rails.root.join('spec', 'support', 'test_images', 'google.png'), 'image/png') }
title "Shirt"
link "www.example.com"
list
end
end
item_spec.rb
require 'spec_helper'
describe Item do
let(:user) { FactoryGirl.create(:user) }
let(:list) { FactoryGirl.create(:list) }
before do
@item = list.items.build(title: "Lorem ipsum")
@item.valid?
puts @item.errors.full_messages.join("\n")
end
subject { @item }
it { should respond_to(:title) }
it { should respond_to(:list_id) }
it { should respond_to(:list) }
it { should respond_to(:image) }
it { should respond_to(:remote_image_url) }
its(:list) { should == list }
it { should be_valid }
describe "when list_id not present" do
before { @item.list_id = nil }
it { should_not be_valid }
end
describe "when image not present" do
before { @item.image = "" }
it { should_not be_valid }
end
describe "with blank title" do
before { @item.title = " " }
it { should_not be_valid }
end
describe "with title that is too long" do
before { @item.title = "a" * 141 }
it { should_not be_valid }
end
end
item.rb
class Item < ActiveRecord::Base
attr_accessible :link, :list_id, :title, :image, :remote_image_url
belongs_to :list
mount_uploader :image, ImageUploader
validates :title, presence: true, length: { maximum: 140 }
validates :list_id, presence: true
validates_presence_of :image
end
spec/support/test_images フォルダーに google.png という画像があります。
私はレールに非常に慣れていないので、どんな助けも大歓迎です!