Я учу меня некоторым Rails!Но сейчас я не могу избежать ошибки, которую выдает RSpec.Ошибка выглядит следующим образом:
1) EntryMethodsController POST create with valid params creates a new EntryMethod
Failure/Error: post :create,
NoMethodError:
undefined method `reflect_on_association' for "4e94ca4f66472f02ff00000a":String
# ./app/controllers/entry_methods_controller.rb:43:in `create'
# ./spec/controllers/entry_methods_controller_spec.rb:48:in `block (4 levels) in '
Finished in 0.29409 seconds
13 examples, 1 failure
Failed examples:
rspec ./spec/controllers/entry_methods_controller_spec.rb:47 # EntryMethodsController POST create with valid params creates a new EntryMethod
Done.
Тест
describe "POST create" do
describe "with valid params" do
before :each do
@contest = FactoryGirl.create(:contest)
end
after :each do
@contest.destroy
end
it "creates a new EntryMethod" do
expect {
post :create,
:contest => @contest,
:entry_method => FactoryGirl.attributes_for(:url_entry_method, :contest => @contest)
}.to change(@contest.entry_methods, :count).by(1)
end
end
end
Контроллер
def create
@entry_method = Contest.find(params[:contest_id])
.entry_methods.new(params[:entry_method])
respond_to do |format|
if @entry_method.save
format.html { redirect_to @entry_method, notice: 'Entry method was successfully created.' }
format.json { render json: @entry_method, status: :created, location: @entry_method }
else
format.html { render action: "new" }
format.json { render json: @entry_method.errors, status: :unprocessable_entity }
end
end
end
Модели
class Contest
include Mongoid::Document
include Mongoid::Timestamps
field :name, :type => String
field :rules, :type => String
field :start_date, :type => Time
field :end_date, :type => Time
embeds_many :entry_methods
end
class EntryMethod
include Mongoid::Document
field :url, :type => String
field :string, :type => String
embedded_in :contest
end
Спасибо, ТАК классные люди,:)