Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker
Joe Moore

Standup 06/23/2009: Multi-table Inheritance?

Joe Moore
Tuesday, June 23, 2009

Ask for Help

“Has anyone implemented mutli-table (class table) inheritance in Rails, as apposed to single table inheritance (STI)?”

  • There are some plugins that nobody has tried, such as inherits_from
  • What about a view to represent the super set of tables and rows?

“We’re looking for a dead-simple, drop-in JS rating or ‘starting’ plugin.”

Check out the start-rating jQuery plugin. Any other suggestions?

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 3/27/2009: Gem repo forked?

Pivotal Labs
Friday, March 27, 2009

Interesting Things

  • IE doesn’t allow you to change the type of an input. If you create an input with createElement, IE will not allow you to change that element to a button. This was discovered when a project’s javascript dom builder code was modified to generate inputs of type=button rather than type=submit. The cross-browser solution was to create some other temporary dom element such as a div and then set the innerHtml of that element to a type=button input, then extract that child element and return it in the builder call. Yeah!

Ask for Help

“What’s the best way to get gems for forked repos?”

There was quite a discussion on this. The specific issue is that the team is trying to use Compass (Chris Eppstein gave a talk on Compass at Pivotal on 3/18-look for the future video on our Talks Page.) For the moment, since compass depends on the edge version of sass you must first manually install sass before installing the compass gem.

  • One suggestion was to submit a fix for the gem. This is not a good solution in this case since the new version of sass/haml is expected to be released soon, fixing compass and simplifying its installation.
  • Pivotal will likely host its own internal gem server at some point to deal with issues like this.
  • The Has My Gem Built Yet? service might be useful in some situations, but not for this specific problem.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 3/25/2009: Branches + JSUnit + CI + IE = :-(

Pivotal Labs
Wednesday, March 25, 2009

Interesting Things

  • Branches + JsUnit + CI + IE = :-( : Apparently it is difficult to manage IE’s cache in CI. One project apparently has a bat file on CI that clears the cache every 30 minutes. Another team solved this by making the cache directory read only. Often browser/OS combinations have some technique for disabling caching.
  • Test Swarm Alpha: this is a crowd sourced javascript testing solution (think seti@home for javascript testing) being developed by John Resig.

Ask for Help

“AR attribute appears to be skipped by text field helper?!” Apparently the model method is bypassed by the text field helper if a column of the same name is present in the underlying table. This was experienced in Rails 2.2.

Others have apparently experienced this in the past but a clear answer did not surface.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 3/24/2009: Browser History with Javascript and Page Based Json

Pivotal Labs
Tuesday, March 24, 2009

Interesting Things

  • Browser History with Javascript and Page Based Json: One of our projects solved the vexing problem of browser history for a page that has initial page provided json with subsequent ajax updates. A simple page back operation will display the originally downloaded data, not the updated data. The solution is to add a unique id for each page, and store these ids in a cookie. When an ajax request updates the page it removes its page id from the cookie. When you use the back button, each page checks to see if its unique id is in the cookie, and if it is not, it forces a reload.
    Really Simple History was mentioned as another way to manage javascript/ajax history.
  • Rubymine Build 784 has the Weirdest. Bug. Ever.: This may only be a problem if you work on a mac and you need to enter capital letters in rubymine dialogs like find and replace ;-). Many of us are fans of intellij/rubymine, but we wish they had a better test process. To be fair, rubymine is in public preview, so expect the occasional bug or two.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Run JavaScript in Selenium tests. Easily.

Pivotal Labs
Thursday, March 5, 2009

Here’s the gist of this post: gist.github.com/58876

Ever since I’ve started using Webrat, a lot of the pain of Selenium has gone away
for me. There’s still a little bit of pain though. Part of it is caused by the fact
that it’s harder than it should be to just execute arbitrary bits of JavaScript in
in your current window under test. Well no more. Here’s a helper:

module SeleniumHelpers
  # Execute JavaScript in the context of your Selenium window
  def run_javascript(javascript)
    driver.get_eval <<-JS
      (function() {
        with(this) {
          #{javascript}
        }
      }).call(selenium.browserbot.getCurrentWindow());
    JS
  end

  private

  # If running in regular Selenium context, get_eval is defined on self.
  def driver
    respond_to?(:selenium) ? send(:selenium) : self
  end
end

To use it with Cucumber, do like so:

World do |world|
  world.extend(SeleniumHelpers)
  world
end

To use it with POS, do like so:

class JavaScriptHelperTest < SeleniumTestCase
  include SeleniumHelpers

  # your tests go here...
end

Now what?

Now to run JavaScript in your Selenium window, just call run_javascript. Note
that it’s always going to return a String, so you may have to massage the output
a tad:

checked_boxes_count = run_javascript <<-JS
  jQuery('input[type=checkbox]:checked').size();
JS

checked_boxes_count         # => "3"
checked_boxes_count.to_i   # => 3

Cooler stuff

While Webrat’s DSL for traversing web apps is awesome, I’ve always found the
alternatives (Polonium for example) to not jive well with how I think. They’re
way better than talking directly to Selenium, you’re still locked in to a certain
style. The run_javascript helper makes it easier to write your own helpers that
fit your own style.

module ElementHelpers
  class Element
    def initialize(context, selector)
      @context, @selector = context, selector
    end

    def hide!
      call(:hide)
    end

    def show!
      call(:show)
    end

    def visible?
      call(:is, ':visible') == 'true'
    end

    private

    def call(fn, *args)
      @context.run_javascript <<-JS
        return jQuery(#{@selector.inspect})[#{fn.to_s.inspect}](#{args.map(&:inspect).join(', ')});
      JS
    end
  end

  def locate(selector)
    Element.new(self, selector)
  end
end

Now you can write your tests like so:

class JavaScriptHelperTest < ActiveSupport::TestCase
  include SeleniumHelpers
  include ElementHelpers

  def setup
    @element = locate('#all')
  end

  def test_visible_by_default
    assert @element.visible?
  end

  def test_hide_element
    @element.hide!
    assert ! @element.visible?
  end

  def test_show_element
    @element.hide! # setup
    @element.show!
    assert @element.visible?
  end
end

Credit should go to Brian Takita, since he did most of the hard work and I just wrote a method. Let me
know if you have any issues or ideas with the helper, and may all your tests be green.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Standup 11/12/2008: JSON2.js borked?

Pivotal Labs
Thursday, November 13, 2008

Interesting Things

  • JSON version 2 has problems with its JavaScript implementation json2.js, specifically when calling JSON.stringify() on arrays:

    // JSON version 1
    [1] => "[1]"
    
    
    // JSON version 2
    [1] => ""[1]""
    

    We’re not sure if this is a bug or a feature. We’re sticking with JSON version 1 until further notice.

  • Pivot Adam has a very interesting blog post about functors called Give up the func. Check it out!

Ask for Help

“We were having problems when mocking an ActiveRecord association under Mocha when we called expects on a method that calls a method.”

The solution was basically to not mock associations.

“Mod_rewrite + SSL was causing problems when redirecting to a subdomain behind SSL.”

A wild-card SSL certificate solves the problem.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Effective Markdown Editing with the WMD editor and the Save Text Area Firefox plugin

Pivotal Labs
Saturday, October 18, 2008

Anytime I need to edit Markdown, I reach for the WMD editor. Their splitscreen demo is the most effective way to edit Markdown that I have seen.

The left screen is the editor and the right screen is the “real-time” preview of the Markdown. It is nice because I don’t have to press a preview button to see rendered Markdown. The Markdown is also rendered as I type so I get instantaneous feedback of my changes.

There is also a Save Text Area Firefox addon, which enables me to save/load the contents of a text area to/from a file on the filesystem. Also the Ctrl+s shortcut saves the file.

So when editing Markdown, I:

  1. Open Firefox and go to http://wmd-editor.com/examples/splitscreen?blank=1
  2. Load or Save a markdown file by right-clicking the editor screen
    1. Going to the Text submenu
    2. Clicking Load or Save As
  3. Edit the file and see the generated output

Of course, its not a text editor replacement, since the possible text manipulation in Firefox is limited, but the feedback that is provided by WMD is very effective to rapid Markdown editing. I hope this sort of UI becomes more common.

Now if only there were a similar Textile editor…

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Sean Beckett

Standup 08/04/2008

Sean Beckett
Monday, August 4, 2008

Ask for Help

“Does anyone know why a Selenium click event might not trigger the same activity as directly triggering the DOM id through javascript? We have a form submit button that works fine when directly activated but doesn’t work in Selenium.”

It was suggested that perhaps this is a timing issue. Maybe some required JS for the form hasn’t loaded before Selenium is trying the event.

One workaround would be to test only the form submission called by on-click instead of the click itself.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

IE Javascript memory leak dector

Pivotal Labs
Sunday, January 27, 2008

http://blogs.msdn.com/gpde/pages/javascript-memory-leak-detector.aspx

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

javascript_include_tag in Rails

Pivotal Labs
Thursday, December 13, 2007

Want to avoid feeling like a chump and spending countless hours troubleshooting a crazily-stupid-simple problem?

When you enter a .js in your javascripts directory and include it using a javascript_include_tag, take the <script> tags off the front and back.

You probably knew that already. Why didn’t you tell me sooner?

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (780)
  • rails (113)
  • testing (88)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (55)
  • techtalk (44)
  • rspec (38)
  • ironblogger (32)
  • productivity (30)
  • activerecord (29)
  • gogaruco (29)
  • git (28)
  • nyc (27)
  • rubymine (26)
  • bloggerdome (23)
  • mobile (22)
  • process (21)
  • pivotal tracker (20)
  • cucumber (20)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • css (13)
  • tdd (13)
  • selenium (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to javascript Feed
  1. ←
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5
  7. 6
  8. →
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >