Skip to content

Instantly share code, notes, and snippets.

@shwoodard
Created August 9, 2012 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shwoodard/3308129 to your computer and use it in GitHub Desktop.
Save shwoodard/3308129 to your computer and use it in GitHub Desktop.
RSpec + Capybara support file to work with ckeditor instances
module Ckeditor
class Instance
attr_reader :capybara
private :capybara
def initialize(instance_id, capybara)
@instance_id, @capybara = instance_id, capybara
end
def val(value)
capybara.execute_script "jQuery('textarea##{@instance_id}').val('#{value}')"
end
def reload_all
capybara.execute_script "for(var instance in CKEDITOR.instances) { if(CKEDITOR.instances.hasOwnProperty(instance)) {CKEDITOR.instances[instance].destroy(true);} }"
capybara.execute_script "CKEDITOR.replaceAll();"
end
end
end
# usage
# rte = Ckeditor::Instance.new(:my_instance_id, page)
# rte.val 'foo'
# rte.reload_all
# NOTE: page is provided by Capybara
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment