rspec should render_template still behaving weirdly
Specing a partial being rendered with render_template blows up. What to do?
render_template has been brittle for a long time. It obviously still is:
response.should render_template("template") #works fine
response.should render_template(partial: "template") #works fine
response.should render_template(partial: "template", locals: {local_array: []}) #blows up within rspec
You know how to fix it? Solve it here
RubyMine 4 is out
RubyMine "compare two files" isn't broken
It is just really, really weird: if you have to scroll when comparing two files check the file that is above in the project drawer first. If you scroll up to do select the second file to compare, the compare window won't open.
Stubbing can? can be hard
In a system with a lot of cancan abilities - what is the best way to stub a particular ability for controller specs? In the hierarchy of controllers, a lot of abilities may be checked, all of which would need to stubbed in order to get to the code under test.
Instead of stubbing the abilities, create a new, anonymous, ability class specific for your spec that gets all the necessary abilities and then stub current_ability to return an instance of that class. Internally cancan calls current_ability when you call can?: cancan controller additions
IntelliJ has a feature called modules: "a functional unit which you can compile, run, test and debug independently."

A module in IntelliJ is a top-level view on a part of a codebase. IntelliJ is for Java, which is why I do not typically use it. I use Rubymine - no similar functionality exists here... but a way around that!
Ask for Help
"Does anyone know about random highlighting occurring in RubyMine / IntelliJ on all OSes?"
RubyMine 3.1 apparently had issues with random highlighting which were resolved simply by upgrading to at least 3.2 release.
Interesting Things
Compostable Utensils
The office got compostable utensils that meet San Francisco city requirements!
Ask for Help
"What do you recommend for Devise user invitations?"
Interesting Things
- Did you know that Rubymine can search files found with a previous search? Do cmd-shift-f and do a search. Do cmd-shift-f again. In the dialog, select 'custom'. In the drop down list is 'Files in Previous Search Result'
- Former Pivot Alex Chaffee is teaching a javascript class, and there are still a few openings.
Help
Testing for class methods in Ruby
How do you test for the existence of a class method? Test it using #respond_to?
class Foo
def self.bar
puts "Hello, World!"
end
end
Foo.respond_to?(:bar)
=> true
And to make sure we are really just talking about class methods and not instance methods:
foo = Foo.new
foo.respond_to?(:bar)
=> false
Interesting
RubyMine and Rspec2 Bug Fixed!
We use the latest and greatest RubyMine version available at Pivotal, but sometimes technology choices such as Rails 3 and Rspec 2 are still ahead of it. The formatter that analyzes test output breaks on Rspec 2's output before any tests run. The bug is further discussed http://youtrack.jetbrains.net/issue/RUBY-6485. Luckily this bug will be fixed in the next EAP release.
Excuting .rvmrc commands and cruisecontrol
We've had a difficult time getting .rvmrc files to work with cruisecontrol.rb builds. Specifically, ccrb seems to launch the rake task in the project working directory. This means that the .rvmrc file is ignored. A workaround is to have your CI script directly use RVM or to add "cd .. && cd work" before your project cruise script or rake task.
Ask for Help
- Double-entry/ledger based accounting in Rails (i.e. Quickbooks in Rails for free)
Ideally would be tied in with user/role system where each accounting entry would be tied to a user, but also reconciled against a master account. Recommendations? Latest and greatest?
One suggestion was to look at the code that Wesabe open sourced code when they closed their doors.
- Error message when opening Rubymine "Invalid Git Root"
This is likely because the project included a submodule that wasn't configured correctly, fix this in under Rubymine's version control preferences.

Interesting Things
Test 404 handling (e.g.
rescue_from ActiveRecord::RecordNotFound, :with => :render_record_not_found) with Cucumber by temporarily settingActionController::Base.allow_rescue = true. This is usually set tofalseinfeatures/support/env.rbJSON.pretty_generatehates Rails 3Hashes
- Use window.postMessage to communicate between IFrames in a standard way
This should work in most modern browsers. Follow the Mozilla docs, NOT the various blog posts about this.
Ask for Help
- I asked if there's a date library in Ruby as rich as Java's JODA
Suggestions included Chronic and RI_CAL though I'm hoping for something that can represent arbitrary periods (ranges?) of time JODA and handles interval calculation and other such date/time arithmetic.
- is(':visible') doesn't always work as expected in Jasmine
One project reported that using this to as part of a Jasmine spec to ensure that an element becomes visible doesn't appear to be reliable.
- Annotate and Git History failed for a team using Rubymine 2.0.2 and git 1.7.2.1 in combination with svn.
They solved the problem by downgrading to git 1.7.1.1:
I followed instructions here to create a local set of portfiles:
http://guide.macports.org/#development.local-repositories and grabbed the older portfile from here:
https://trac.macports.org/browser/trunk/dports/devel/git-core?rev=69357
After I could do a port search git-core and have 1.7.1.1 show up, I was able to
sudo port deactivate git-core @1.7.2_0+doc+svnandsudo port install git-core @1.7.1.1+doc+svn
One person was experienced compile errors when installing
memprofon Ubuntu, fortunately somebody else had gotten this working before and offered to help him through thee.A team noticed that Bundler ran multiple (4) times on CI taking nearly 11mins overall and wanted to know to make Bundler run only once
It was suggested that the problem may be due to the way they'd setup their preinitializer.rb and they should move the bundle install into a Rake task.
if ENV['IS_CI_BOX']
puts "IS_CI_BOX is set, running bundle install..."
system('bundle install') || raise("'bundle install' command failed. Install bundler with gem install bundler.")
end
It was pointed out that they should make sure their Gemfile.lock file is checked into version control, which it was. Additionally Bundler 1.0.0 RC1 will allow isolating gems to a local path using bundle install path --disable-shared-gems
Interesting Things
- The Facebook Graph API doesn't appear to implement OAuth 2.0 properly/completely so it doesn't work with the OAuth2 gem
- One Pivot noticed that the version of ImageMagick installed on the default EngineYard solo image is out of date and had to upgrade this manually.
Interesting Things
RubyMine 2.0.2, refactor => extract partial == FAIL. If you select multiple divs and perform extract partial, the selected region is removed, but only the first complete div is included in the new partial.
Rspec/Rubymine focused tests. Rubymine attempts to run focused tests using the
--example 'text'option. Rspec apparently finds the example group, and runs the examples that are directly a part of that example group, but does not include descendent example groups -- *which can lead you to think examples are passing that were not actually run*. Apparently this is fixed in rspec 2.
Ask for Help
"Display of time is off by an hour, presumably due to Daylight Saving Time"
The team is displaying time stored as utc in the database, using strftime, and the time is off by an hour.
"Binding Click to Checkbox with Jquery"
A team was trying to check the value of a checkbox during the click event, but getting the opposite value. They worked through it but was hoping to find a better solution.
"Why is there a new default for include_root_in_json for rails 3?"
Just curious.
"Fakeweb, Capybara w/Selenium Webdriver == end of file?"
Getting "end of file" failure on CI. There were a few suggestions:
- There is a fork of fakeweb that allows it to ignore localhost.
- Consider using Webmock instead of fakeweb.
Interesting Things
RubyMine Integration
RubyMine is integrating with Pivotal Tracker! Beta version 2.5 lets you follow stories through the IDE's task tool and tags your source control comments with the current tasks. It's nice to see the title of your current story as you work. I'm excited to see what deeper integrations lie ahead. This screenshot shows what it looks like selecting a story through the menu item Tools > Task > Open...
Ask for Help
"We keep getting webrat thread exceptions running our integration specs with the rails integration runner: Thread tried to join itself. The error message varies with different versions of ruby 1.8.6 vs 1.8.7."
Anyone had this problem or know why?
"How do I skin an iphone mobile site to be the correct width so it's not 980px wide?"
<meta name="viewport" content="width = device width" />
*"We're trying to deploy some nginx configuration changes to EngineYard Cloud, what's the right way to do that?"
We've tried building custom chef recipes to solve this problem, but they run after nginx has already restarted, so are a poor solution to this problem. The better solution might be to check in configuration files into the application and symlink them into the nginx configuration directory using a before_symlink.rb hook in the /deploy directory.
*"We've got a
has_manyassociation where some of the child records are originally saved in an invalid state. When we later load the parent and ask it if it's valid, it returns true even withvalidates_associated. How can we get the desired validation behavior?"
Turns out that unloaded associations are not validated. Solution: load the association before calling .valid? on the parent. In general, you should also not create invalid objects, instead using a state variable to put them into a "draft" or "incomplete" state where they are still valid but not complete. Then remove that state and you'll see the errors required to finish that object.
Interesting Things
- When RubyMine 2.0.1 won't run your focused specs, try attaching rspec 1.2.9 to it rather than 1.3.x. It fixed this issue for one of our teams.
- Rubymine 2.0.2 came out today: can finally run focused contexts?! Also including bundler support! What's new
- We tried our Unicorn on EngineYard cloud: so far so good. It's still "experimental" but seems to work.
