FormTestHelper should change hidden fields

Railsoids:

FormTestHelper rules. It tests your response.body form at the same
time as it triggers your action, with all the parameters in that form.
This obviously improves quality.

But it took issue with this:

submit_form 'validate_stuff' do |form|
  form['IBhidden'] = 'validate'
end

The field IBhidden is a hidden field. To be fair, FTH erred on the
side of matching what a user can do. Users can’t change hidden fields,
so FTH threw “TypeError: Can’t modify hidden field’s value”.

But that impairs FTH’s ability to match my JavaScript, which scribbles
freely on that field. So instead of making a federal case out of this,
I monkey-patched FTH:

module FormTestHelper
class Hidden < Field
def value=(value)
super(value)
end
end
end

For FTH’s next version, who’s right? FTH, me, or both?


Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!

Hi

Sorry for the late answer but I faced the same problem and found the
solution so I guess I should share… You should call set_value() method
instead of =() like this

submit_form 'validate_stuff' do |form|
  form['IBhidden'].set_value 'validate'
end

Simon

Simon P. wrote:

submit_form 'validate_stuff' do |form|
  form['IBhidden'].set_value 'validate'
end

Righteous - I shall remove the monkey patch immediately.

(Dang that’s a hard habit to break!! Track the source to the point
where you don’t like it, then rewrite that one spot! What could go
wrong??:wink:


Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!

I am looking for some advice about how to best take a string of RJS and
convert it into a string of Javascript within a controller. I am
presenting the user with a textbox and allowing them to type in RJS
which will then be converted into Javascript and stored in the database.

Thank you,
Matthew M.

Matthew M. wrote:

The above code works just fine but I want a way to pass in arbitrary content between the do and end. Something like

@the_rjs = render_to_string :update do |page|
“#{params[:rjs_stuff]}”
end

page << params[…]

Where params[:rjs_stuff] holds some RJS that was entered by a user. Yes I know this is a huge security risk but I am
prototyping something and this is what the project calls for at the moment. Regardless of what I put in for params[:rjs_stuff] I get

try {

} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘’); throw e }

Install this as a plugin, or just raid it for source:

http://phlip.svnrepository.com/svn/yar_wiki

The test file shows another way to extract RJS as a string, and shows
how to turn off debug_rjs:

def get_rjs
ActionView::Base.debug_rjs = false

ActionView::Helpers::PrototypeHelper::
    JavaScriptGenerator.new(@controller) do |rjs|
  return rjs
end

end

Call rjs.to_s before debug_rjs becomes true again.

Here’s another system, from a private project that shamelessly stashes
JS in the database:

def temporarily(obj, member, new_value)

old_value = obj.send(member)
equator = member.to_s+'='

begin
  obj.send(equator, new_value)
  yield
ensure
  obj.send(equator, old_value)
end

end

def get_js(rjs)
temporarily ActionView::Base, :debug_rjs, false do
return rjs.to_s
end
end

def javascript_generator
jsg = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator
jsg.new(self){|rjs| return rjs }
end


Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!

Matthew M. wrote:

I am looking for some advice about how to best take a string of RJS and
convert it into a string of Javascript within a controller. I am
presenting the user with a textbox and allowing them to type in RJS
which will then be converted into Javascript and stored in the database.

Thank you,
Matthew M.

I have sort of figured out my question but need a little bit of advice
to get past a roadblock.

@the_rjs = render_to_string :update do |page|
page.replace_html ‘message_top’, “Turtles are green”
end

The above code works just fine but I want a way to pass in arbitrary
content between the do and end. Something like

@the_rjs = render_to_string :update do |page|
“#{params[:rjs_stuff]}”
end

Where params[:rjs_stuff] holds some RJS that was entered by a user. Yes
I know this is a huge security risk but I am
prototyping something and this is what the project calls for at the
moment. Regardless of what I put in for params[:rjs_stuff] I get

try {

} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(’’); throw e
}

Any ideas?

Thank you,
Matthew M.