JackHQ

Posts tagged rubyonrails

2 notes

Convert JavaScript to CoffeeScript

Rico Sta. Cruz created an awesome converter js2coffee. If you are planning to get into CoffeeScript, you have to check this page out.

http://ricostacruz.com/js2coffee

It will not craft CoffeeScript as well as if you did it by hand, but it is great to take some existing javascript and paste it in and see how it renders the CoffeeScript.

I just went over the https://github.com/visionmedia and grabbed the javascript from “node-growl” js file and pasted it in the javascript editor at js2coffee. It converted it to CoffeeScript and the generated CoffeeScript code was functional and compiled back into JavaScript!

Fun Stuff!

Filed under JavaScript coffeescript rubyonrails

0 notes

De-Identify your data or Fakerize your data

Ever need to pull a copy of your production data?

Ever need to create a demo sandbox for your sales team?

We did.

So we created a gem called Fakerize, it is currently going though some internal testing, but we will launch as open source as soon as we have all the issues worked out.

This Command Line Interface, makes it very easy to de-identify your database.

You simply create a config yaml file with a map of all your models and a list of fields that you want to fakerize.

---
:models:
-
   :name: :patients
   :options:
     -  
       :field: :last_name
       :fakerize: Name.last_name

Save as config.yml

Then install the fakerize gem

gem install fakerize

Then if you have a mysql database run:

fakerize database:convert mysql://user@localhost/mydb config.yml

And it will proceed to de-identify your database.

COOL!

Now you can push your database to a demo app or just hack on your database locally, but feel better that you are not carrying around your clients liability in your computer.

TODO!

Just the beginning!

We plan add a feature to allow you to use it for any data store.

Right now, it uses the Sequel Toolkit and can connect to any adapter that the Sequel toolkit uses, but we are planning to allow you to create adapters for any datastore.

Also we plan to add a “database:clean”, that will allow you to specify models that you want completely emptied!

Filed under ruby rubyonrails

12 notes

Testing jQuery Autocomplete using Capybara

Using Selenium + Capybara + jQuery to select an option from an AutoComplete

Have you ever found yourself pulling your hair out at 3:00am, frustrated and challenged beyond all that is humanly possible, because your tests are unable to select any of the options from an AutoComplete?

No?

Lucky you.

But if you have, this quick jQuery snippet, once placed correctly, will hopefully make your late nights of frustration a little bit shorter.

We first find the text field label, “Name”, and fill it in with text that will cause the AutoComplete to show us a list of the result(s) so that we may select one.

 fill_in 'Name', :with => 'Jack'

Moving to the next line, the sleep() is necessary so that the AutoComplete has time to load and have what we want selected. The time count may vary.

sleep 3

Lastly, we tell Capybara to run some script:

  • look inside the ui-menu-item list item class,
  • find the link (denoted by the anchor (a) tag) that has “Jack Russell Software” in it,
  • use the .trigger() function to simulate your mouse entering the AutoComplete field (different version of .mouseenter() http://api.jquery.com/mouseenter/), and
  • click on the selected field.

    page.execute_script ” $(‘#{selector}’).trigger("mouseenter").click();”

May your days (and nights) of testing AutoCompletes be fruitful.

Robert Pearce

Jack Russell Software Company

Filed under ruby rails rubyonrails