English 中文(简体)
简单表格协会的光谱测试
原标题:Rspec test on Simple Form Associations

I am trying to run a request spec on a form (built with Simple Form). The form includes some select boxes that are generated using the association method and therefore database values for the model.

When running save_and_open_page it doesn t look like the select the values in the drop downs.

我已经看过Mocking和Stubbing,但这对我来说是新的,我仍然对这一概念略感困惑。

是否有办法为挑选的盒子收集资料,以便Capybara能够收回吗?

I m使用铁路3.1、简单表格、Kroybara和KadoGirl。

我的法典是......

<>strong>challenge_spec

describe "New 挑战s" do

  before(:all) do
    %w["Under 13", "13 - 16"].each do |item|
      FactoryGirl.create(:age, :name => item)
     end
  end

  it "should redirect to resources after submission" do

    login_valid_user

    visit new_challenge_path

    @challenge = Factory.build(:challenge)

    fill_in "challenge_name", :with => @challenge.name
    fill_in "challenge_description", :with => @challenge.description
    fill_in "challenge_description", :with => @challenge.description
    select "30 mins", :from => "challenge_timescale"
    save_and_open_page
    select 1, :from => "challenge_age_id"
    select @challenge.category, :from => "challenge_category_id"

    click_button "save_button"

  end
end

<><><><><>><>>>><>>>>>>

def new
  @challenge = 挑战.new

  respond_to do |format|
    format.html # new.html.haml
    format.json { render json: @challenge }
  end
end

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

<%= f.association :age, :prompt => "Please select..." %>

Models

挑战

class 挑战 < ActiveRecord::Base
  belongs_to :age
end

年龄

class 年龄 < ActiveRecord::Base
  has_many :challenges
end
问题回答

我强烈建议为你的测试设置固定装置。

这样,你就可以人工制作和操纵测试所需的记录。 它不像使用cks、 st和双倍,而是提高了对申请和测试的了解。





相关问题
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: ...

热门标签