Corey Innis's blog



Corey InnisCorey Innis
Standup 02/11/2008
edit Posted by Corey Innis on Monday February 11, 2008 at 11:57PM

Interesting Things

  • Got Example?

    Don't forget to make use of the reserved (top- and second-level) domain names set aside by RFC 2606... especially if you find yourself writing something like:

    result = @model.do_request('http://www.somebogusdomain.com')
    result.code.should == 1001
    
    
    # NOTE: www.somebogusdomain.com actually exists!
    

Corey InnisCorey Innis
Standup 02/07/2008
edit Posted by Corey Innis on Thursday February 07, 2008 at 05:58PM

Interesting Things

  • There's an IE PNG transparency bug fix as a plugin for jQuery. It looks fairly complete, with more coverage than many others out there and the usage is trivial (once installed):

    <script type="text/javascript">
      $(document).ready(function(){ 
        $(document).pngFix(); 
      }); 
    </script>
    

    The major downside so far: it scales background images.

  • Rails Bug:

    In a failing/rolled back transaction, those ActiveRecord objects that were created prior to the exception still have IDs and respond false to object_name.new_record? (which would seem to indicate that a record for the object has been saved).

    For more info, here are a couple bug tickets.

Corey InnisCorey Innis
Standup 02/05/2008
edit Posted by Corey Innis on Tuesday February 05, 2008 at 10:42PM

Interesting Things

  • In exploring options for RSpec testing of XML responses, one project decided a custom XPath matcher would do the trick nicely:

    items = Item.find(:all)
    get :index
    
    
    response.body.should     have_nodes("//items/item", items.size)
    response.body.should     have_xpath("//items/item[ position() = 1 and @id = '0001' ]")
    response.body.should_not have_xpath("//bogus")
    

    Some other possibilities:

    • Hashes...

      items = Item.find(:all)
      get :index
      
      
      hash = Hash.from_xml(response.body)
      hash['ancestor']['parent']['items']['item'].size.should == items.size
      hash['ancestor']['parent']['items']['item'][0]['id'].should == '0001'
      hash['ancestor']['parent']['bogus'].should be_nil
      
    • Hpricot...

      items = Item.find(:all)
      get :index
      
      
      doc = Hpricot(response.body)
      doc.search("//items/item").size.should == items.size
      doc.at("//items/item[ @id = '0001' ]").position.should == 1
      doc.at("//bogus").should be_nil
      
    • assert_select from Rail's Test::Unit (using CSS-style selectors)...

      items = Item.find(:all)
      get :index
      
      
      assert_select("items > item", :count => 5)
      assert_select("items > item:nth-child(1)[id=?]", '0001')
      assert_select("bogus", false)
      

    What are your favorite techniques for asserting XML/XPath?

  • Something to consider when test-driving controller code:

    You're working with ActionController::TestResponse. So, response.success?, response.redirect?, etc. are available for you there (since they are defined on TestResponse), but not in your actual controllers. That is, things blow up if you try to use @response.success? in your application,

    e.g. to determine whether or not to store the current URL and redirect there after a login.