JackHQ

Posts tagged rails

2 notes

Code School - Rails Best Practices Review

The Code School ‘Rails Best Practices’ Super Deluxe Championship edition had me hooked from the beginning with the references to 1980’s arcade games. The videos were so entertaining to watch that I could not stop until the course was done. Taking the time to review concepts that are already familiar never hurts any one. The First 3 levels were exactly this. After progressing past the 3rd level (The challenges could have been a little more difficult.), I started to pick up a few new tricks that I have begun to use in my day to day coding. Learning about delegators and presenters was helpful. The try method has helped me clean up some ugly nil checks in views. No matter what level the rails developer, this course is worth going through.

Gregg Pollack does such a great job of keeping it entertaining, you can not help but pay attention and learn something new or just brush up on your existing skills. I would definitely be interested in taking more courses from Code School.

Kris Windham

Jack Russell Software

Filed under ruby rails codeshool

13 notes

html2haml.heroku.com up 670.01%

What a difference a year makes, html2haml.heroku.com was launched on 05-31-2009, and really picked up steam in October 2009. Almost 200 developers daily are using the simple tool to help convert html to haml.

Is haml picking up traction?

Recently, there was a solid debate between erb vs haml, on the new podcast Ruby Rogues.

On the show, the preference from Haml or Erb was split down the middle and both sides made compelling arguments.

More than just Ruby Users

So many other languages and frameworks have adopted the usage of haml.

What is the best? (Haml or Erb)

I think the debate will continue on for sometime.

It is clear that there are more developers converting html to haml, than a year ago on html2haml.heroku.com. I think HAML is here to stay, whether you love it or hate it. Below are some more stats that are interesting as well.

Thanks again to Hampton Catlin, Nathan Weizenbaum, Chris Eppstein, and numerous contributors to haml and to Heroku for hosting the site.

Filed under ruby rails haml html2haml

2 notes

Code School - Rails Best Practices Review

If you are anything like me visual and hands-on experience are two of the most effect methods of learning. Code School has taken these teaching methods a step further to offers a new intuitive and interactive learning experience through the use of video, slides, and chapter quizes that utilize the in-browser editor. I have taken both of the courses that are currently being offered: Rails for Zombies and Rails Best Practices. Both courses have proven to be quite useful for me seeing as though I am still quite new to Ruby on Rails and coding in general. Rails for Zombies is an awesome low-level ROR overview great for newbs or as a refresher, whereas Rails Best Practices focuses more on refactoring of code, and you guessed it, ‘Best Practices’.

My most recent Code School experience was taking the ‘Rails Best Practice’ course, which I must say is a very useful and well put together course. Throughout the course, I was constantly having ‘A-ha’ moments learning cool new tricks, which I guess is the point. The content layout of the course was well laid out and each lesson was well organized with common themed material. As is the flow of the other Code School lessons, each lesson is followed by some useful hands-on quizes that review that lessons’ material.

In general, the lesson quizes are awesome in that you are able to get in some hand-on experience and utilize new tricks you may have just learned. The convenience of being able to go from the lesson to the lesson quizes and the editor and begin writing code all in your browser window is awesome!! My only aversion being that many of the error logs in the editor we not very helpful in debugging at all. A few times I found myself spending way too much time trying to figure out what was wrong with my code only to find out I had any extra space somewhere.

In all, I found ‘Rails Best Practice to be a great learning tool filled with great information that is delivered through captivating multimedia videos and slides.

  • Russell Niller

Jack Russell Software

Filed under ruby rails CodeSchool

0 notes

Code School - Rails Best Practices Review

I am a big proponent of the learn by doing paradigm and the Rails Best Practices course from the guys at Code School is a really neat way to get familiar with rails development. I really enjoyed the light-hearted yet content packed screencasts that have the usual awesome production values from Envy Labs. I was even more impressed with the exercises at the end of the sections. The slick interface was a joy to use but there were several times where the answer I provided, while “correct”, was not quite what the exercise was looking for and it was hard to tell why. Even though I was familiar with most of the topics covered there were several things I learned that have become a part of my everyday toolkit. I was unaware of the .try and .present? methods and they have helped in making my code more readable. I also learned a lot about the rails counter cache and the subtleties in the methods for getting the size of a collection. Overall I enjoyed working through the sections and I am very excited to see what Code School is able to do with their interactive platform!!

  • Colin Alstad Jack Russell Software

Filed under ruby rails codeschool

13 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

1 note

Using Rack/test for Rails and RESTful api’s

Needing a way to test a RESTful API quickly using RSpec and Rack/test.

We brainstormed the pros and cons of the following integration frameworks, cucumber, unencumbered, rack::test. Cucumber is heavy and would require time to setup. Unencumbered is completely new to us and therefore could be a potential time-sink. Rack::Test is new to us also, but integrates with our rspec test suite out of the box and appeared to be extremely lightweight.

Based on the examples we found on integrating Rack::Test with Sinatra, we loved the simplicity and decided to give it a go.

We initially only had one piece of functionality to test. We need to post data to a server protected by basic authorization using JSON successfully. The following test achieved our goal in a very short amount of time:

require 'spec_helper'

describe 'restful add xxxxx' do
  include Rack::Test::Methods

  def app
    ActionController::Dispatcher.new
  end

  before(:each) do
    User.delete_all
    User.create!(
      :login => 'admin',
      :email => 'admin@example.com',
      :password => 'Xxxxx',
      :password_confirmation => 'xxxxx'
    )
  end

  it 'should post JSON successfully' do
    post '/xxxxxx.json', { :xxxxx => {
      :first_name => 'Test',
      :last_name => 'Admin',
      :dob => 20.years.ago,
      :gender => 'M'
    } }, { 'HTTP_AUTHORIZATION' => encode_credentials('user', 'password') }
    assert last_response.ok?
  end

  private

  def encode_credentials(username, password)
    "Basic " + Base64.encode64("#{username}:#{password}")
  end
end

The main point to note is injecting the HTTP_AUTHORIZATION attributes into the POST method. That allowed us to connect to the web service and RESTfully test our application!

Now that we are validated against the server, the next test we needed to write was to verify that the response returned from the JSON POST did not include any errors in the rails validation hash:

it 'should post with valid zip codes' do
  post '/xxxxxx.json', { :xxxxxx => {
    :first_name => 'Test',
    :last_name => 'Admin',
    :dob => 20.years.ago,
    :gender => 'M',
    :zip => '9103'
  } }, { 'HTTP_AUTHORIZATION' => encode_credentials('xxx', 'Xxx') }
  assert !last_response.body.include?('Zip must be in 00000 or 0000 or 00000-0000 format')
end

Based on the test above, we know that a validation error message in our rails app is not being returned in the response body returned by our web service. The test passed.

That is all there is to it.

pblittle

Filed under rails rack rspec