Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6320377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:57:41+00:00 2026-05-24T15:57:41+00:00

I am testing a form. It looks like: <form accept-charset=UTF-8 action=/the_action method=post> <select id=id

  • 0

I am testing a form. It looks like:

<form accept-charset="UTF-8" action="/the_action" method="post">
  <select id="id" name="z[z_id]">
    <option value="7">Foo</option> 
    <option value="11">Bar</option> 
  </select>
</form>

How do you get all of the option values into an array(7,11) for testing? These values are id’s for a model, so I want to test certain attributes for each object.

I read api docs (http://api.rubyonrails.org/) for HTML::Selector but it didn’t help.

Also used assert_select from Rails Guides (http://guides.rubyonrails.org/testing.html#testing-views) but didn’t figure out how to use value in a way other than testing for equality.

Do you have any recommended introductory resources?

Thanks.

Edit: Here’s the code in the view:

<%= form_tag( :action => :the_action) do %>
<%= select :model_name, :model_id, Model.where(:user_id => 1).collect{|m| [m.full_name, m.id]}, :selected => selected_value, :include_blank => false %>
<%= submit_tag "view model" %>
<% end %>

There is no controller code for this functionality.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:57:42+00:00Added an answer on May 24, 2026 at 3:57 pm

    Sounds to me as if you are testing the model through the view. Is there any reason not to just check for the presence of the selector in the view, and test the attributes of the model in the model tests?

    Edit:

    So the way I would deal with this would be to create a method on the model

    def options_for_user(user_id)
       self.where(user_id => 1).collect{|m| [m.full_name, m.id]}
    end
    

    and then I would just call this method from the view, and test the option creation in the unit tests. Maybe that’s just me – but it makes testing this sort of thing very easy …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here's the query: SELECT [Lab Occurrence Form].[1 0 Preanalytical (Before Testing)],Count([Lab Occurrence Form].[1 0
I have a form that looks like this: $guests = 2; // Just for
I have installed VS2010 and MVC2 and testing a simple form using tinyMCE. When
The test form generated by ASMX is pretty handy for testing operations. However, there
I have a form that has multiple fields, and for testing purposes is there
i am new to access sql and i built a select statement that looks
i have a query in access that is this: SELECT iif([Cup Type] like '*Cylinder*',count([Cup
My application I have an application design that looks like this: web application layer
I'm using an checkbox on an ASP.NET MVC form like so: <%=Html.CheckBox(AgreeToRules, Model.AgreeToRules)%> The
I would like to implement the Post/Redirect/Get pattern in a page that will post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.