railsware / rack_session_access

Rack middleware that provides access to rack.session environment
MIT License
257 stars 29 forks source link

Weird HTML escape in generated update session page when using capybara with JS #2

Closed nicolasblanco closed 12 years ago

nicolasblanco commented 12 years ago

Hi,

when enabling js in my integration test (using js: true) and capybara-webkit like this :

background do
  page.set_rack_session(user_id: @user.id)
end

scenario "It renders", js: true do
  visit "/"
end

The test fails with :

Failure/Error: page.set_rack_session(user_id: @user.id)
   Capybara::ElementNotFound:
     no button with value or id or text 'Update' found
   # (eval):2:in `click_button'

I've taken a look at the generated update session page HTML and it contains some weird HTML escape but only some parts of the form seem escaped (very weird) :

<html><head></head><body>
    <h2>Update rack session</h2>
    <p>Put marshalized and encoded with base64 ruby hash into the form</p>
    <form action="/rack_session" method="post" enctype="application/x-www-form-urlencoded">
      <input type="hidden" name="_method" value="put">
      <textarea cols="40" rows="10" name="data">      &lt;p&gt;
        &lt;input type="submit" value="Update"/&gt;
      &lt;/p&gt;
    &lt;/form&gt;
  &lt;/body&gt;
&lt;/html&gt;
</textarea></form></body></html>

Have you got some ideas?

Thanks.

Using : rails 2.3.8 / capybara 1.1.2 / capybara-screenshot 0.2.2 / capybara-webkit 0.12.1

ayanko commented 12 years ago

I'll check & fix

ayanko commented 12 years ago

Questions:

$ cat test_builder.rb 
require 'rubygems'
require 'builder'
builder = Builder::XmlMarkup.new(:indent => 2)
builder.html do |xml|
  xml.body do |xml|
    xml.textarea("", :cols => 40, :rows => 10, :name => 'data')
    xml.p do |xml|
      xml.input(:type => 'submit', :value => "Update")
    end
  end
end
data = builder.target!
puts data
nicolasblanco commented 12 years ago

Hi and thanks for looking for this strange issue.

The generated output of the test file looks fine. As I said, the HTML output is only bad when using js: true in my test. My tests which don't use JS works great with rack_session_access.

[$]nicolas@MacBook-Air-de-Nicolas-Blanco:[git:master?] /Users/nicolas/projects/simplib-> bundle exec ruby test_builder.rb 
<html>
  <body>
    <textarea cols="40" rows="10" name="data"/>
    <p>
      <input type="submit" value="Update"/>
    </p>
  </body>
</html>

[$]nicolas@MacBook-Air-de-Nicolas-Blanco:[git:master?] /Users/nicolas/projects/simplib-> bundle show builder
/Users/nicolas/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/builder-3.0.3
nicolasblanco commented 12 years ago

4 fixes my problem :)

ayanko commented 12 years ago

released v0.0.3