Mike Mazur's blog



Mike MazurMike Mazur
[Standup][SG] 2011-12-01 - Events events events!
edit Posted by Mike Mazur on Wednesday November 30, 2011 at 05:29PM

Events

Mike MazurMike Mazur
[Standup][SG] 2011-11-30 - Deprecations in jQuery 1.7
edit Posted by Mike Mazur on Tuesday November 29, 2011 at 05:59PM

Helps

"We have some DOM that looks like this: <div><span /><a /></div>. We can style the a which follows a span with the CSS rule span + a, but it appears there's no rule to style the span if it's followed by an a."

  • This is more of a sad face than a help.

Interestings

  • As part of jQuery's slimming down effort, in the 1.7 release non-standard event properties are no longer copied from the native event object to the jQuery event object. Certain plugins may not be aware of this change yet.

  • Along the lines of jQuery 1.7, .live() is also being deprecated. Please use .on() and .off() in its place.

Mike MazurMike Mazur
[Standup][SG] 2011-11-25 - Wonkiness with accepting an alert dialog in cucumber
edit Posted by Mike Mazur on Thursday November 24, 2011 at 05:30PM

Helps

"We are using page.driver.browser.switch_to.alert.accept in our cucumber steps in order to accept a JavaScript alert box. This appears to have an effect on the browser's behavior afterward, causing future scenarios to fail when they pass on their own. We're seeing timing issues, specifically around when the blur event is called when an input field loses focus. We didn't manage to find the root cause. Any ideas?"

  • Sounds intense! No answers, though.

Interestings

  • It's not possible to stub a delegated method; stub it on the object delegated to instead.

  • In order to get an accurate number of days since the epoch, do this: (Time.now.to_f / 60 / 60 / 24).round. The key here is the to_f instead of to_i to prevent losing precision early on.

Mike MazurMike Mazur
[Standup][SG] 2011-11-21 - Don't use GitHub to host your JavaScript!
edit Posted by Mike Mazur on Sunday November 20, 2011 at 05:28PM

Interestings

  • We included a JavaScript file and set its src attribute to a file's RAW URL on github. After about 400 requests within an hour, github started returning 403.

  • Public Service Announcement: local_assigns is a hash of local variables in a view. Useful when passing those variables on when rendering a partial; instead of enumerating the variables: render :partial 'foo', locals: { bar: bar, baz: baz}, pass the hash of locals: render :partial 'foo', locals: local_assigns

Mike MazurMike Mazur
[Standup][SG] 2011-11-17 - Chock-full of JavaScript
edit Posted by Mike Mazur on Thursday November 17, 2011 at 06:00PM

Helps

"Adding a JS alert box (with remote:true, confirm: 'Are you sure?' on a link_to) causes the cucumber feature to fail. It looks like, after we accept the alert with page.page.driver.browser.switch_to.alert.accept, the browser runs much slower than the cucumber feature, so while everything technically works, the feature fails. We worked around this by delaying cucumber with page.should have_no_content('content inside removed li') but it feels like a hack. Does anyone know what could be wrong with our setup, or is this to be expected?"

  • There were no comments other than the work-around we're already using.

"The pattern we use when testing ajax calls in Jasmine feels unsatisfactory because expect($.ajax).toHaveBeenCalledWith({ /* all params here */}); requires all the parameters passed to the ajax call to be specified in the expectation. This includes parameters we don't care about, such as beforeSend (which is passed by Rails' remote: true). There must be a better way?"

Interestings

  • To get the html of an element (ie: a 'ul') including itself, append the element to a new element (ie: an empty div), then get the html of the new element. For example: $('<div>').append($('ul')).html(). The element's parent could also be used if the element is an only child.

  • When appending an element which already exists in the DOM to another element, it will be moved from its present location in the DOM. This can be problematic when using the trick above to generate an element's html, and is fixed by cloning the element.

  • If you see 'Timezone Displacement out of range' when doing a heroku db:push, it's probably because you're using Ruby 1.9.3 in development while Heroku runs 1.9.2. Don't do that.

Events

  • GOV Camp at Suntec City TODAY, November 18, 2-10pm