English 中文(简体)
铁路轨道——部分形式t出现在一体化测试中(不会使田地成为目的)
原标题:Rails Rspec - part of form doesn t appear in integration test (not rendering fields_for)

页: 1 因此,我可以拯救和洗衣。 学生有1个Phone<>/strong>(电话属于学生),并通过nes属向学生提供电话。 所有东西在浏览器中都是出色的,但在尝试测试更新时,“Pupil模式一会遇到一些麻烦。

www.un.org/Depts/DGACM/index_spanish.htm

class PupilsController < ApplicationController
  ...

  def edit
    @pupil = Pupil.find( params[:id] )
  end

  def update    
    pupil = Pupil.find( params[:id] )

    if pupil.update_attributes( params[:pupil] )
      redirect_to pupils_path
      ...
    else
      redirect_to edit_pupil_path
      ...
    end
  end
end

<关于编辑的网页:

<%= form_for @pupil, :html => {:class => "form-horizontal"} do |f| %>
  <%= field_set_tag do %>
    ...
    <div class="control-group">
      <%= f.label :pupil_address_of_living, "Address of living", :class => "control-label" %>

      <div class="controls">
        <%= f.text_area :pupil_address_of_living, :rows => 3, 
                        :placeholder => @everpresent_field_placeholder %>
      </div>
    </div>

    <hr/>

    <%= f.fields_for :pupil_phone do |pp| %>                                              
      <div class="control-group">
        <%= pp.label :pupil_home_number, "Home phone", :class => "control-label" %> 

        <div class="controls">
          <%= pp.text_field :pupil_home_number, :placeholder => @everpresent_field_placeholder %>
        </div>
      </div>
      ...
    <% end %>


    <%= f.submit "Change", :class => "btn btn-large btn-warning" %>
  <% end %>  
<% end %>

我的<>融合试验实际上失败了:

# encoding: UTF-8
require  spec_helper 

describe "SchoolHeads" do
  before(:each) do
    @attr = {
              :user_login => "iSchool_head",
              :password => "foobar"
            }

    user = User.new( @attr )
    user.user_role = "school_head"
    user.save!
  end

  ...
    describe "Updating" do
      describe "View" do
        before(:each) do
          @ipupil = Factory( :pupil, :pupil_phone => Factory( :pupil_phone ))            
          visit edit_pupil_path( :id => @ipupil.id )
        end 

        it "should have values in forms" do     
          response.should have_selector("form") do |form|
          ... 
          form.should have_selector("input", :name => "pupil[pupil_phone_attributes][pupil_home_number]")
        end
      end
    end

www.un.org/Depts/DGACM/index_french.htm

Failure/Error: form.should have_selector( "input",
expected following output to contain a <input name= pupil[pupil_phone_attributes][pupil_home_number] /> tag:

<form accept-charset="UTF-8" action="/pupils/220" class="form-horizontal" id="edit_pupil_220" method="post">
  <div style="margin:0;padding:0;display:inline">
    <input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="put">
  </div>
  <fieldset>
    ...      
    <div class="control-group">
      <label class="control-label" for="pupil_pupil_address_of_living">Address of living</label>
      <div class="controls">
        <textarea cols="40" id="pupil_pupil_address_of_living" name="pupil[pupil_address_of_living]" rows="3">Moscow</textarea>
       </div>
     </div>

     <hr>

     # Here i should have part of form with phones which is not rendering. 

     <input class="btn btn-large btn-warning" name="commit" type="submit" value="Change">
   </fieldset>
 </form>

我从未遇到过这种奇怪的问题。 它是 b还是什么? 这是我的错误吗?

最佳回答

我解决了这一问题。 非常感谢注意到这一问题的<斯特隆>普杰卑。 问题是,工厂的定型关系正确。 因此,一改成法典:

before(:each) do 
  @ipupil = FactoryGirl.create( :pupil ) 
  @attr_pupil_phones = { :pupil_home_number => "8903111111", 
                         :pupil_mobile_number => "777-33-22" } 
  @ipupil.create_pupil_phone( @attr_pupil_phones ) 
  ... 
end

如今,它运作良好。

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签