def test_presence_of_free_text
profile = Profile.find :first
post :edit, {:id => profile.id}
assert_select “textarea”, :name => “record[free_text_ec]”
end
The test results in a failure, because the element cannot be found.
I’m pretty sure the element should be there, and I’ve tried the
following
combinations as well:
assert_select “textarea”, :name => “record[free_text_ec]”
assert_select “textarea.record_free_text_ec”, :name =>
“record[free_text_ec]”
assert_select “input[type=textarea][id=record_free_text_ec]”
assert_select “[type=textarea][id=record_free_text_ec]”
assert_select “input[type=TEXTAREA][id=record_free_text_ec]”
assert_select “LI textarea”, :name => “record[free_text_ec]”
assert_select
“html:root>body>div>div>div>div>form>ol>li>ol>li>textarea”, :id =>
“record_free_text_ec”
They all fail.
One does not fail, and that’s
assert_select “", :name => “record[free_text_ec]”
But, to be sure, I’ve checked this option with a dummy name
(e.g. assert_select "”, :name => “Hjdueubduagagaxxxxx”)
and it strangely enough it succeeds as well.
Does anyone know how to make the assert_select find my textarea tag
correctly?
In my case the assert_select works for pages that are NOT using
active scaffold, I just do, as you proposed…
assert_select “textarea#record_free_text_ec”
and this works.
I think the problem lies in the fact my (GET) request in the
test, is probably not returning what I expected, and that’s why the
assert_select doesn’t find the textarea.
From the browser the GET returns the right html, from the
test the GET is giving me values 0 or 302 for an assert_response.
I’ve checked the response with puts @response.inspect, and it
doesn’t look like what I should get.
Just for the records, for whoever might end up on this thread.
I found out what the problem was, it has nothing to do with active
scaffold.
The cause of this problem was a missing fixture in my tests.
More specifically. I use the plug in act_as_authenticated, and
the first line in my tests is usually login_as(:someone), that
sets the user as logged in.
The method login_as worked fine, and the @current_user instance
variable was set in my controllers, but the instances of an
association
(i.e. has_and_belongs_to_many :roles) where not made and not set
in the specific user instance, this caused some conditions to fail and
resulted in a redirect.
Moral of the story: I needed to add an extra fixture to my functional
test.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.