こんにちは私はスペックファイルの実行にこの問題があります。これは修復モデルです。
class Reparator < User
include Mongoid::Document
include Mongoid::Timestamps
field :private_reparator, :type => Boolean, :default => true
field :brand_name, :type => String
field :year_of_experience, :type => Integer, :default => 1
has_many :reparations
has_many :skills
validates_presence_of :skills, :year_of_experience
validates :year_of_experience, :numericality => {:greater_than_or_equal_to => 0}
end
これはスキルモデルです:
class Skill
include Mongoid::Document
field :name, :type => String
belongs_to :reparator
validates_presence_of :name
validates_uniqueness_of :name
end
これはコントローラーです:
class ReparatorsController < ApplicationController
respond_to :json
def index
@reparators = Reparator.all
respond_with @reparators
end
def show
@reparator = Reparator.find(params[:id])
respond_with @reparator
end
def create
@reparator = Reparator.new(params[:reparator])
@reparator.skills = params[:skills]
if @reparator.save
respond_with @reparator
else
respond_with @reparator.errors
end
end
def update
@reparator = Reparator.find(params[:id])
if @reparator.update_attributes(params[:reparator])
respond_with @reparator
else
respond_with @reparator.errors
end
end
def destroy
@reparator = Reparator.find(params[:id])
@reparator.destroy
respond_with "Correctly destroyed"
end
end
そして、これはこのコントローラーのスペックファイルです(合格しなかったテストを配置します):
it "Should create an reparator" do
valid_skills = [FactoryGirl.create(:skill).id, FactoryGirl.create(:skill).id]
valid_attributes = {:name => "Vianello",
:email => "maremma@gmail.com",
:address => "viale ciccio",
:private_reparator => true
}
post :create, :reparator => valid_attributes, :skills => valid_skills
assigns(:reparator).should be_a Reparator
assigns(:reparator).should be_persisted
end
そしてこれはスキルファクトリーガールです:
FactoryGirl.define do
factory :skill do
sequence(:name) {|n| "skill#{n}"}
end
end