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

Monthly Archives: August 2012

Mark Gangl

08/31/12: Labour Day!

Mark Gangl
Friday, August 31, 2012

Interestings

  • :last-child vs :first-child

Just a friendly reminder that :last-child is less cross-browser-friendly than :first-child (IE8 and earlier do not support it).

  • rails 3.2.8 + increment!

increment! doesn’t call before_update callback

https://github.com/rails/rails/issues/7306

  • devise with no database

Looking for tips on using devise without a database

Events

  • Monday: Labor Day!!
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Jesse Smith

[Standup][SF] 8/31/12: Mountain Lion comes Monday

Jesse Smith
Friday, August 31, 2012
  • 14px margin bullies jasmine_content

In Chrome, the #banner child element in #HTMLReporter has a 14px top margin. For some reason this margin overflows the parent and pushes the body element off the top of the window. jQuery offset will tell you that the body is offset by zero, but any child elements of body are pushed down by 14px. Try overflow-hidden to remedy.

  • Bundler 1.2 official release

Specify your ruby version without the –pre tag.

  • Pivotal Labs in SF is hosting a preview GoGaRuCo talk at lunch today. Thanks to all who attend.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Charlie Springer

Tracker Screencast: Project Tabs

Charlie Springer
Thursday, August 30, 2012

I seem to discover new things in Tracker all the time. After looking over the shoulder of someone on the dev team and seeing all their projects in “tabs” on top of their current project, I scratched my head thinking, “When do I get that!?” Is this a new feature or secret “developer only” mode? Upon closer inspection, it’s just another one of those hidden gems in Tracker preferences. Check out this short screencast to see how to enable project tabs or follow the instructions below.

  • Go to your profile
  • Scroll down to Project Page Preferences
  • Select Show project tabs
  • Press save

Thats it!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
JT Archie

merging scopes with STI models

JT Archie
Thursday, August 30, 2012

Introduction

On a client project recently, we ran into a domain problem that didn’t fit into the ActiveRecord standard conventions. The following is the thought process taken to get to our solution, so it gets detailed in some areas.

ActiveRecord has a great feature called Single Table Inheritance. It allows a model to have multiple types while using a single database table for the storage. Those type abstractions can each have their own validations, override base functionality, and specific abstraction functionality.

If your model has ever been littered with case statements checking if a User is a guest, admin, etc., you should take a look at STI.

Models

The project had a based model that had many types and each abstraction had a scope of .active that defined what it meant to be active for that type.

class Person < ActiveRecord::Base; end

class FireFighter < Person
  def self.active
    where(has_helmet: true)
  end
end

class PoliceOfficer < Person
  def self.active
    where(has_squad_car: true)
  end
end

Problem

We needed to create an API endpoint that returned all active Person instances. This would require us to iterate through each child of Person and get all its current active members. Since we have Person model let’s give it a concept of .active that incorporates every active member of society in our domain.

Solution

We can extend Person to return an array of each active FireFighter and PoliceOfficer.

class Person < ActiveRecord::Base
  def self.active
    FireFighter.active.all + PoliceOfficer.active.all
  end
end

One problem we have with this implementation is every time we add a new abstraction of Person we have to add to .active. Luckily, ActiveRecord STI comes with support for looking up a parent’s .descendants.

class Person < ActiveRecord::Base
  def self.active
    active_people = descendants.map do |descendant|
      d.active.all
    end.flatten
  end
end

This is pretty powerful. We can add Astronaut and any active astronauts will automatically be in Person.active array. This implementation will help satisfy our API endpoint requirements, but it does break useful ActiveRecord patterns.

Advance Solution

WARNING: Continue at your own risk. If you are content with the solution above stop, but if you want to see what can be done with Arel continue.

What if we want to chain scopes or extend the .active with pagination for our API? We cannot do this because easily because we are currently returning a Ruby array instead of an ActiveRecord::Relation. How can we modify .active to be an actual scope?

You might be thinking, ActiveRecord comes with the ability to merge scopes between models. Unfortunately, it does not work very well when merging scopes with STI models.

We ended using Arel (known for not being well documented) within our model. Each ActiveRecord::Relation is actually just an object with holding on to Arel values for different parts of an SQL statement — joins, froms, selects, etc. We are able to get the conditions for WHERE clause by looking at the ActiveRecord::Relation where_values.

class Person < ActiveRecord::Base
  def self.active
    conditions = descendants.map do |d|
      d.active.where_values.reduce(:and)
    end.reduce(:or)

    where(conditions)
  end
end

Our implementation takes the where_values from the .active scope from each descendant and does an SQL OR on them. ActiveRecord::Relation can take

# somewhere in a Rails console
> Person.active.to_sql
=> SELECT "people".* FROM "people"  WHERE (
      ("people"."has_helmet" = 't' AND "people"."type" = "FireFighter")
        OR
      ("people"."has_squad_car" = 't' AND "people"."type" = "PoliceOfficer")
    )

What does give us? We can now use Person.active as a normal scope, which allows us to append any conditions on to it.

> Person.active.where(created_at: 2.days.ago..1.day.ago).order(:created_at)
=> []
> Person.active.limit(10)
=> []
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Evan Goodberry

Hardware Hacking Meeting

Evan Goodberry
Thursday, August 30, 2012

Events

  • Thursday: Hardware Hacking Meeting today in this room @ 12:30
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
JT Archie

What I’ve learned about RubyMotion

JT Archie
Wednesday, August 29, 2012

I’ve been trying to learn RubyMotion recently, using Ruby to develop iOS appeals to me.

I have no prior Objective-C or Cocoa API knowledge besides the basic HelloWorld. I’ve been using this tutorial and have learned more about Cocoa API faster using Ruby than with Objective-C. There is less boilerplate code that needs to be written for defining interfaces and implementations.

The main takeaway of RubyMotion is that it is not your standard Ruby implementation. It is a Ruby runtime wrapped around the Objective-C runtime. All Ruby objects map directly to there corresponding Objective-C object — Array to NSMutableArray, Hash to NSMutableDictionary, etc. RubyMotion does not come with the standard library as other flavors, you are relying on Cocoa API as the standard library.

There is even a difference in Ruby syntax to map directly to Objective-C. The Objective-C language does message passing for “method invocation”. This means that a method call on an object is determined by parameters rather than just method name. RubyMotion had to include this language feature, so you will actually see Ruby that is invalid all other Ruby flavors.

class MyObject
    def doSomething(doSomething, argument: argument)
    end

    #This does not override the method defined above
    def doSomething(doSomething, anotherArgument: argument)
    end
end

Luckily there are extensions for your favorite editors. Rubymine even supports MacRuby syntax, but does not support autocomplete, yet.

Two weeks ago, I saw a talk about RubyMotion from its creator in Berlin. He gave the basic HelloWorld demonstration, but also gave an introduction in the community. It is small, but great things are coming out of it.

The community has started taking the power of Ruby and making the libraries and DSL-y things we love in Ruby.

  • BubbleWrap is a resource API. It gives you easy access to JSON parsing, HTTP requests, alerts, etc. It is kind of catch all of lower-level Cocoa API tasks that you don’t want to have to write your own helpers for.
  • Formotion is a DSL to create Forms. Usually you use Interface Builder to build forms and load the appropriate NIB. This gem will allows you to define a form in code.
  • MotionData is ActiveRecord like access to CoreData. It supports migrations, scopes, basic validations, etc.
  • SimpleView provides a DSL for formatting views.

With all this, there is one question that always gets asked. Is RubyMotion worth it? Yes! Laurent, the creator, is in it to win it! This is why he charging for the RubyMotion; funding ensures that he can continue to work on it.

From a Pivot role, I’ve had to discover RubyMotion’s position in testing. Pivotal Labs is a pure TDD shop, everything from Java, Objective-C, Javascript, and Ruby is tested.

RubyMotion comes with a prebuilt RSpec (actually a port of bacon) like testing framework. The testing framework supports the testing of views and controller using the UIAutomation framework. I think that we can agree that it could be better, but I believe there is enough to get started and allow us to expand on it.

The RubyMotion community is still growing. I look forward to see what comes out of it, so that I can use Ruby in other devices.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Jesse Smith

[Standup][SF] 08/29/12: Reconciliation

Jesse Smith
Wednesday, August 29, 2012

Helps

  • Font Awesome + CSS Transforms for tab throbber

Some pivots have experience with this working pretty well!

Interestings

  • False Alarm or DWF Lies

Draper/CI Reporter wasn’t our problem. Not entirely sure what was – but signs point to a Spork/ResqueSpec loader order problem on Linux only.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Evan Goodberry

Learning to Count with PostgreSQL

Evan Goodberry
Wednesday, August 29, 2012

Interestings

  • PostgreSQL COUNT(*) OVER()

Sometimes when you’re paginating you have to run 2 queries, one for the first n records, and another for the total count.

It’s possible to get both in one query using OVER().

SELECT , COUNT() OVER() as total_count FROM blog_posts ORDER BY created_at DESC LIMIT 25;

Each record will come back with a total_count attribute, so you will have to look at one of the records to figure out the count.

http://www.postgresql.org/docs/9.1/static/tutorial-window.html

  • Good article on quick Twitter Bootstrap style customizations

Some good links and resources in this article, including a sweet color scheme generator, FontAwesome, Kickstrap, and more.

Events

  • Wednesday: Enyo Bootcamp

Come to the Enyo Bootcamp workshop to learn everything you need to know to begin creating cross-platform cross-browser Web applications with this exciting framework. There will be a brief presentation followed by Q&A with some of the Developer Relations Engineers. Attendees should be somewhat familiar with HTML, JavaScript, and CSS to get the biggest benefit. Visit http://enyojs.com/ to get a leg up or come prepared to have your mind blown.

To get into the spirit of working with the framework, read about Xtuple’s recent experience at http://www.xtuple.org/node/5000 and be inspired by the ease of Enyo!

Eventbrite Invite: http://enyobootcampnewyorkcity.eventbrite.com/

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Joseph Palermo

[Standup][SF] 08/28/12: They at least strongly dislike each other

Joseph Palermo
Tuesday, August 28, 2012

Helps

  • Recommendations for static site generators for Heroku?

It looks like there’s a lot of them – does anyone have any personal recommendations?

Interestings

  • Draper and CI Reporter hate each other

This goes back to the Help a couple of weeks ago re: JSON being undefined. We blame Draper & its RSpec integration, but don’t yet have a solution.

  • eager_load and rake tasks

Eager loading doesn’t happen from rake tasks. This causes a problem if you are running in thread safe mode and dependency loading is disabled.

This has been fixed in master.

But until that is released, you can possibly branch your thread safe declaration on the existence of the $rails_rake_task global.

Events

  • eXtreme Tuesday

Come and talk about programming, and other aspects of XP. 6:30pm

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Austin Vance

[Standup][Boulder] 8/21/12: Keep your brews fresh.

Austin Vance
Tuesday, August 28, 2012

Helps

  • Installing postgres modules… We would like to use pg_trgrm and are looking for pointers and pain points installing pg_modules on dev and production systems. Anything will help.

Interestings

  • Remember to update your homebrew brew update to get new packages
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (778)
  • rails (113)
  • testing (87)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (54)
  • techtalk (44)
  • rspec (38)
  • activerecord (29)
  • productivity (29)
  • gogaruco (29)
  • ironblogger (29)
  • git (28)
  • nyc (27)
  • rubymine (25)
  • bloggerdome (22)
  • mobile (22)
  • cucumber (20)
  • process (19)
  • pivotal tracker (19)
  • 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)
  • tdd (13)
  • selenium (12)
  • css (12)
  • goruco (12)
  • bundler (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • api (10)
Subscribe to Community Feed
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. →
  • 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 >