<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Deployment Zone &#187; Computers</title>
	<atom:link href="http://www.deploymentzone.com/category/computers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.deploymentzone.com</link>
	<description>&#34;I write C#&#34;.gsub(/C#/, &#039;Ruby&#039;)</description>
	<lastBuildDate>Tue, 24 Jan 2012 06:30:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Project level .pryrc</title>
		<link>http://www.deploymentzone.com/2012/01/22/project-level-pryrc/</link>
		<comments>http://www.deploymentzone.com/2012/01/22/project-level-pryrc/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 18:56:12 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[pry]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=327</guid>
		<description><![CDATA[Building off my previous ~/.pryrc I wanted to automatically load up my core project Ruby file, spec_helper.rb, and fire off some initialization routines whenever I start a new Pry session in my project's directory.
Because the contents of the local directory's .pryrc is evaluated before the :before_session hook from ~/.pryrc timing is a bit more delicate. [...]]]></description>
			<content:encoded><![CDATA[<p>Building off my previous <tt>~/.pryrc</tt> I wanted to automatically load up my core project Ruby file, <tt>spec_helper.rb</tt>, and fire off some initialization routines whenever I start a new Pry session in my project's directory.</p>
<p>Because the contents of the local directory's <tt>.pryrc</tt> is evaluated before the <tt>:before_session</tt> hook from <tt>~/.pryrc</tt> timing is a bit more delicate.  I get around this by creating a custom function named <tt>_pry_before_session</tt> (but you could name it anything you want really) and have the <tt>~/.pryrc</tt>'s <tt>before_session</tt> hook execute it if it exists.</p>
<p>So my project's <tt>.pryrc</tt>:</p>
<pre class="brush:ruby;">#~/Projects/ActiveAvro/.pryrc
def _pry_before_session
  require 'active_avro'
  require 'spec_helper'
  ActiveAvroHelper.initialize
end
</pre>
<p>And my updated <tt>~/.pryrc</tt> looks like this:</p>
<pre class="brush:ruby;">#~/.pryrc
require 'interactive_editor'

Pry.config.editor = "mate"
# add the current directories /lib and /spec directories to the path if they exist
before_session = Proc.new do |out, target, _pry_|
  dir = `pwd`.chomp
  %w(lib spec test).map{ |d| "#{dir}/#{d}" }.each { |p| $: << p unless !Dir.exists?(p) || $:.include?(p) }
  # if a local .pryrc defines a _pry_before_session function, execute it now
  send(:_pry_before_session) rescue nil
end
Pry.hooks[:before_session] = before_session
</pre>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2012/01/22/project-level-pryrc/&via=cfeduke&text=Project level .pryrc&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2012/01/22/project-level-pryrc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pry and .pryrc &#8211; add ./lib and ./spec to $LOAD_PATH</title>
		<link>http://www.deploymentzone.com/2012/01/22/pry-and-pryrc-add-lib-and-spec-to-load_path/</link>
		<comments>http://www.deploymentzone.com/2012/01/22/pry-and-pryrc-add-lib-and-spec-to-load_path/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 15:50:29 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[pry]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=324</guid>
		<description><![CDATA[Add the current directory's ./lib and ./spec paths to your $LOAD_PATH variable when you start up a new pry shell.]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://pry.github.com/">Pry</a> a lot.  If I had to develop without it I'd spend a hell of a lot more time not writing Ruby code.  Often I use Pry in a Rails project as part of <tt>rails console</tt> but I also use it with my non-Rails Ruby projects.  I wanted to get around having to append commonly used directories to the <tt>$LOAD_PATH</tt> each time I fire up a Pry session.</p>
<p>Ruby code you place in your <tt>~/.pryrc</tt> is executed when your Pry session begins.</p>
<p>Here's the relevant lines from my <tt>~/.pryrc</tt> that add the appropriate paths to <tt>$LOAD_PATH</tt> during start up.</p>
<pre class="brush:ruby;">#~/.pryrc
&#8942;
# add the current directories /lib and /spec directories to the path if they exist
before_session = Proc.new do |out, target, _pry_|
  dir = `pwd`.chomp
  %w(lib spec test).map{ |d| "#{dir}/#{d}" }.each { |p| $: << p unless !Dir.exists?(p) || $:.include?(p) }
end
Pry.hooks = { :before_session => before_session }
</pre>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2012/01/22/pry-and-pryrc-add-lib-and-spec-to-load_path/&via=cfeduke&text=Pry and .pryrc - add ./lib and ./spec to $LOAD_PATH&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2012/01/22/pry-and-pryrc-add-lib-and-spec-to-load_path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vim [TAB] function definition file not found (in zsh)</title>
		<link>http://www.deploymentzone.com/2012/01/20/vim-tab-function-definition-file-not-found-in-zsh/</link>
		<comments>http://www.deploymentzone.com/2012/01/20/vim-tab-function-definition-file-not-found-in-zsh/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 04:16:02 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[aggravations]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=321</guid>
		<description><![CDATA[Recently I ran into
_arguments:448: _vim_files: function definition file not found
when attempting to tab complete a file name while invoking vim.  Easy fix - at least for me: rm ~/.zcompdump.  Found the answer here.  How it got that way in the first place is another mystery. 
Tweet]]></description>
			<content:encoded><![CDATA[<p>Recently I ran into</p>
<pre>_arguments:448: _vim_files: function definition file not found</pre>
<p>when attempting to tab complete a file name while invoking vim.  Easy fix - at least for me: <tt>rm ~/.zcompdump</tt>.  Found the answer <a href="https://bbs.archlinux.org/viewtopic.php?id=37245">here</a>.  How it got that way in the first place is another mystery. </p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2012/01/20/vim-tab-function-definition-file-not-found-in-zsh/&via=cfeduke&text=vim [TAB] function definition file not found (in zsh)&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2012/01/20/vim-tab-function-definition-file-not-found-in-zsh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby 1.9.3 and Thrift (0.5.0-0.8.0+?)</title>
		<link>http://www.deploymentzone.com/2012/01/19/ruby-1-9-3-and-thrift-0-5-0-0-8-0/</link>
		<comments>http://www.deploymentzone.com/2012/01/19/ruby-1-9-3-and-thrift-0-5-0-0-8-0/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 01:52:47 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[thrift]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=318</guid>
		<description><![CDATA[Thrift for Ruby with Ruby 1.9.x = Incompatible character encodings: ASCII-8BIT and UTF-8.]]></description>
			<content:encoded><![CDATA[<p><a href="http://breakthebit.org/post/7136099549/fixing-thrift-incompatible-encoding-exception-on-ruby">This post</a> basically sums the bug with the Ruby Thrift bindings where the exception message is "Incompatible character encodings: ASCII-8BIT and UTF-8".  This problem is a bit of a bitch to hunt down but once you find it its relatively easy to fix.</p>
<p>While I've <a href="https://github.com/cfeduke/thrift">got a fork</a> with a <a href="https://github.com/apache/thrift/pull/10">pull request</a> I'm fairly certain that the Apache software foundation has other... means of accepting patches so this pull request will be largely irrelevant.</p>
<p>Until the problem is fixed and propagated to the thrift gem you can monkey patch this issue yourself:</p>
<pre class="brush:ruby;"># encoding: utf-8
module Thrift
  UTF8_ENCODING = "utf-8"
  class BinaryProtocol
    def write_string(str)
      write_i32(str.bytesize)
      trans.write(str)
    end
  end

  class HTTPClientTransport < BaseTransport
    def write(buf)
      puts "write"
      @outbuf << buf.force_encoding(UTF8_ENCODING)
    end
  end
  class FramedTransport < BaseTransport
    def write(buf,sz=nil)
      buf.force_encoding(UTF8_ENCODING)
      return @transport.write(buf) unless @write

      @wbuf << (sz ? buf[0...sz] : buf)
    end
    def flush
      return @transport.flush unless @write
      out = [@wbuf.length].pack('N')
      out.force_encoding(UTF8_ENCODING)
      out << @wbuf
      @transport.write(out)
      @transport.flush
      @wbuf = ''
    end
  end
  class BufferedTransport < BaseTransport
    def write(buf)
      @wbuf << buf.force_encoding(UTF8_ENCODING)
    end

    def flush
      if @wbuf != ''
        @wbuf.force_encoding(UTF8_ENCODING)
        @transport.write(@wbuf)
        @wbuf = ''
      end

      @transport.flush
    end
  end
end
</pre>
<p>While I can't vouch for the production worthiness of the above code I can say it at least gets me past an aggravating hurdle.</p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2012/01/19/ruby-1-9-3-and-thrift-0-5-0-0-8-0/&via=cfeduke&text=Ruby 1.9.3 and Thrift (0.5.0-0.8.0+?)&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2012/01/19/ruby-1-9-3-and-thrift-0-5-0-0-8-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manning Hadoop in Action Chapter 1 Example</title>
		<link>http://www.deploymentzone.com/2012/01/11/manning-hadoop-in-action-chapter-1-example/</link>
		<comments>http://www.deploymentzone.com/2012/01/11/manning-hadoop-in-action-chapter-1-example/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 03:30:15 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hadoop]]></category>
		<category><![CDATA[manning]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=312</guid>
		<description><![CDATA[Manning's Hadoop in Action chapter 1 baseline example source code.]]></description>
			<content:encoded><![CDATA[<p>It took me a little while of digging to get to the baseline source code for the <a href="http://www.amazon.com/gp/product/1935182196/ref=as_li_ss_tl?ie=UTF8&tag=deplozone-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=1935182196">Manning Hadoop in Action</a> (2010) chapter 1 source code.</p>
<p>You can find the <tt>WordCount.java</tt> <a href="http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-mapreduce-examples/src/main/java/org/apache/hadoop/examples/WordCount.java">here</a>.  Here's the 1.0.0 version I used:</p>
<pre class="brush:java;">/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.examples;

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

public class WordCount {

  public static class TokenizerMapper
       extends Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(Object key, Text value, Context context
                    ) throws IOException, InterruptedException {
      StringTokenizer itr = new StringTokenizer(value.toString(), " \t\n\r\f,.:;?![]'*");
      while (itr.hasMoreTokens()) {
        word.set(itr.nextToken().toLowerCase());
        context.write(word, one);
      }
    }
  }

  public static class IntSumReducer
       extends Reducer<Text,IntWritable,Text,IntWritable> {
    private IntWritable result = new IntWritable();

    public void reduce(Text key, Iterable<IntWritable> values,
                       Context context
                       ) throws IOException, InterruptedException {
      int sum = 0;
      for (IntWritable val : values) {
        sum += val.get();
      }
      if (sum > 4) {
		  context.write(key, result);
	      result.set(sum);
	  }
    }
  }

  public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length != 2) {
      System.err.println("Usage: wordcount <in> <out>");
      System.exit(2);
    }
    Job job = new Job(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }
}
</pre>
<p>Compilation with Java 6 (1.6) is a bit more involved.  I wrote a simple shell script, the important thing here is to get the classpath flag correct.  Java veterans will of course have no problem with this, but it took me a few minutes to sort out.</p>
<pre class="brush:bash;">#!/bin/bash
rm -rf output/
javac -classpath "../share/hadoop/lib/commons-cli-1.2.jar:../share/hadoop/hadoop-core-1.0.0.jar" -d classes src/WordCount.java
jar -cvf wordcount.jar -C classes/ .
../bin/hadoop jar wordcount.jar org.apache.hadoop.examples.WordCount input output</pre>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2012/01/11/manning-hadoop-in-action-chapter-1-example/&via=cfeduke&text=Manning Hadoop in Action Chapter 1 Example&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2012/01/11/manning-hadoop-in-action-chapter-1-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Non-obvious &#8220;Share configuration&#8221; paths in RubyMine</title>
		<link>http://www.deploymentzone.com/2011/12/13/non-obvious-share-configuration-paths-in-rubymine/</link>
		<comments>http://www.deploymentzone.com/2011/12/13/non-obvious-share-configuration-paths-in-rubymine/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 02:21:36 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[guard]]></category>
		<category><![CDATA[rubymine]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=304</guid>
		<description><![CDATA[RubyMine share configuration and Guard.]]></description>
			<content:encoded><![CDATA[<p>(This was written regarding the RubyMine 4.0 EAP but it probably applies to many of the earlier versions as well.)</p>
<p>When you <tt>Run > Edit Configurations</tt> in RubyMine you can create a number of different configurations.  One of these is a regular Ruby script which can be useful for running such tasks as <tt>guard</tt>.  You select the <strong>full path</strong> to the <tt>*.rb</tt> file and then you click the Share configuration check box.  You might wonder how you express those paths as relative to the project path; after all you want to share the configuration with your teammates and their paths won't likely match your own.</p>
<p>Well it turns out there's no secret sauce to make this work; RubyMine will substitute the macro value <tt>$PROJECT_DIR$</tt> if the script's path is relative to the project you currently have open.  In the UI you'll see the fully expanded path, but when you commit your shared project settings the macro value is what is actually recorded in the <tt>*.xml</tt> file.  When your teammates pull down your shared configurations it will be relative to their project's path.</p>
<p>So to get Guard (with Spork) running in RubyMine I did the following:</p>
<ol>
<li>Created a <tt>run_guard.rb</tt> file in my project's root</li>
<pre class="brush:ruby;">#./run_guard.rb
exec 'guard'</pre>
<li>RubyMine: Run > Edit Configurations</li>
<li>Hit the + and add a new Ruby script</li>
<li>Name it Guard, select the full path to the <tt>run_guard.rb</tt>, select the Bundler tab, check run in the context of Bundler (for good measure)</li>
<li><tt>.idea</tt> is correctly in my <tt>.gitignore</tt> file... but the shared configs live under <tt>.idea/sharedConfigurations/</tt></li>
<li><tt>git add -f .idea/sharedConfigurations/Guard.xml</tt> and commit, push
</ol>
<p>Run the new Guard configuration and you'll see it display in one of the output panes at the bottom of the screen by default.  When you save your specs it will automatically run as normal (but beware that &#x2318;S saves all files).</p>
<p>We also found out that <tt>pry</tt> statements in your RubyMine hosted Guard process won't allow you to interact with the running test session; instead the process will just hang.</p>
<p><em>Update: some more useful RSpec information with RubyMine:</em></p>
<p><strong>Built in <tt>spec</tt> task:</strong> If your spec task is dying because you've configured a DRb server via Guard (using Spork) and you don't plan on running the built-in Spork task within RubyMine <a href="http://avdi.org/devblog/2011/04/17/rubymine-spork-rspec-cucumber/">you'll need to make some changes to your <tt>Spork.prefork</tt> block</a> <strong>and</strong> add an environment variable for the Guard script itself (Run > Edit Configurations) named "RUBYMINE_HOME" and point it to your RubyMine's application path (i.e. for me its <tt>/Applications/RubyMine EAP.app/</tt>).  Now when Guard is running your built-in <tt>rspec</tt> task can execute without dying.</p>
<p><strong>growlnotify:</strong> if you still want Growl notifications for your RubyMine hosted Guard you may need to <tt>sudo ln -s /usr/local/bin/growlnotify /usr/bin/growlnotify</tt>.</p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2011/12/13/non-obvious-share-configuration-paths-in-rubymine/&via=cfeduke&text=Non-obvious "Share configuration" paths in RubyMine&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2011/12/13/non-obvious-share-configuration-paths-in-rubymine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpeccing POST and raw data (using RAW_POST_DATA)</title>
		<link>http://www.deploymentzone.com/2011/12/12/rspeccing-post-and-raw-data-using-raw_post_data/</link>
		<comments>http://www.deploymentzone.com/2011/12/12/rspeccing-post-and-raw-data-using-raw_post_data/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 06:14:19 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=299</guid>
		<description><![CDATA[RSpeccing POST with RAW_POST_DATA.]]></description>
			<content:encoded><![CDATA[<p>I got a request over the weekend to support a client library on the Android platform that cannot submit multipart form data easily.  The request was to allow the client to send the raw bytes as the HTTP request body.  In order to implement this functionality I of course wanted to spec it out first to make sure I was writing this correctly - it isn't every day that I deal with the raw request body after all.</p>
<p>My spec ended up looking like this...</p>
<pre class="brush:ruby;">#./spec/controllers/file_test_api_controller_spec.rb
&#8942;
  describe "#raw_upload" do
    before do
      # file_path points to a file I used dd to generate that is 11,776 bytes
      bytes = File.open(file_path, 'rb').read
      @request.env['RAW_POST_DATA'] = bytes
      post :raw_upload, { }, 'CONTENT_TYPE' => 'application/octet-stream'
      @request.env.delete('RAW_POST_DATA')
    end
    subject { response }
    its "status" do
      should == 200
    end
    its "body" do
      should =~ /size.*11776/m
    end
  end
&#8942;
</pre>
<p>To access this data directly in your controller, you just use <tt>request.raw_post</tt>.</p>
<p>Its worth noting that my controller replies with a receipt in JSON that includes the size of the received data which is why the spec regexes the body for it - there's no automagic occurring with my controller's response.</p>
<p>This approach does <strong>not</strong> work with HTTP PUT as the RAW_POST_DATA request environment variable is cleared when a PUT is performed.</p>
<p>Reference: <a href="http://stackoverflow.com/questions/2103977/how-to-send-raw-post-data-in-a-rails-functional-test">How to send raw post data in a Rails functional test?</a></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2011/12/12/rspeccing-post-and-raw-data-using-raw_post_data/&via=cfeduke&text=RSpeccing POST and raw data (using RAW_POST_DATA)&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2011/12/12/rspeccing-post-and-raw-data-using-raw_post_data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>button_to UrlHelpers all in a row</title>
		<link>http://www.deploymentzone.com/2011/12/07/button_to-urlhelpers-all-in-a-row/</link>
		<comments>http://www.deploymentzone.com/2011/12/07/button_to-urlhelpers-all-in-a-row/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 00:41:27 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=296</guid>
		<description><![CDATA[button_to UrlHelpers displayed horizontally instead of vertically.]]></description>
			<content:encoded><![CDATA[<p>If you are using a series of <tt>button_to</tt> UrlHelpers in Rails and want the buttons to line up horizontally on a row you can use this CSS to accomplish it:</p>
<pre class="brush:css;">/* ./app/assets/stylesheets/button_to.css.scss */
form.button_to {
	margin:0;
	padding:0;
	display:inline;
}

form.button_to div, form.button_to div input {
	display:inline;
}
</pre>
<p>If you are using Rails 3.x's asset pipeline, remember to add a line to your <tt>application.css</tt> to include the <tt>button_to</tt> asset - assuming you're breaking out your styles into separate files.</p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2011/12/07/button_to-urlhelpers-all-in-a-row/&via=cfeduke&text=button_to UrlHelpers all in a row&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2011/12/07/button_to-urlhelpers-all-in-a-row/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec/unit testing permanent signed cookies</title>
		<link>http://www.deploymentzone.com/2011/12/06/rspecunit-testing-permanent-signed-cookies/</link>
		<comments>http://www.deploymentzone.com/2011/12/06/rspecunit-testing-permanent-signed-cookies/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 00:03:41 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[unit-test]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=292</guid>
		<description><![CDATA[Writing RSpec specifications with controllers which require signed cookies.]]></description>
			<content:encoded><![CDATA[<p>Ran into a simple problem today while I was speccing a new controller in our project.  We generate some signed cookies for devices which check into our system and then we use those cookies to identify these devices when they return.  Unfortunately the <tt>ActionController.TestRequest @request</tt> instance variable you get when using rspec-rails has the <tt>cookies</tt> collection as a basic hash and no <tt>cookies=</tt> method defined.  This means that attempting to invoke <tt>permanent</tt> or <tt>signed</tt> on a hash results in a runtime error and you can't just assign the cookies collection to a valid <tt>ActionDispatch::Cookies::CookieJar</tt> instance.</p>
<p>You can get around this by going around the missing attribute setter and changing the instance variable directly.</p>
<pre class="brush:ruby;">#./specs/controllers/some_controller_spec.rb
   # a new device is created here...
   &#8942;
   @request.instance_variable_set(:@cookies, ActionDispatch::Cookies::CookieJar.build(@request))
   # the token is what we use to identify the device on subsequent requests
   # so our specs need to be able to create it when necessary
   @request.cookies.permanent.signed[:token] = [device.device_id, device.secret]
   &#8942;
   # remainder of spec omitted
</pre>
<p>If you're doing stuff with the regular <tt>cookies</tt> hash you will need to <tt>merge!</tt> your <tt>cookies</tt> hash with the <tt>@request.cookies</tt> hash before building and assigning the full blown <tt>ActionDispatch::Cookies::CookieJar</tt> instance.</p>
<p>Reference: <a href="http://stackoverflow.com/questions/4979866/how-to-test-cookies-permanent-signed-in-rails-3">How to test cookies.permanent.signed in Rails 3</a></p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2011/12/06/rspecunit-testing-permanent-signed-cookies/&via=cfeduke&text=RSpec/unit testing permanent signed cookies&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2011/12/06/rspecunit-testing-permanent-signed-cookies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BootstrapFormBuilder, or how ActionView::Helpers::FormBuilder ruined my day</title>
		<link>http://www.deploymentzone.com/2011/12/02/bootstrapformbuilder-or-how-actionviewhelpersformbuilder-ruined-my-day/</link>
		<comments>http://www.deploymentzone.com/2011/12/02/bootstrapformbuilder-or-how-actionviewhelpersformbuilder-ruined-my-day/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 21:39:41 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.deploymentzone.com/?p=285</guid>
		<description><![CDATA[ActionView::Helpers::FormBuilder article written in 2011!  Gasp!]]></description>
			<content:encoded><![CDATA[<p>There is surprisingly little up to date information about <tt>ActionView::Helpers::FormBuilder</tt>.  That's because mostly it hasn't changed.  I'm always afraid of documentation going back to 2008 when we're talking about Rails because 99% of the time its just not quite going to work.</p>
<p>A little bit of background: we're using <a href="http://twitter.github.com/bootstrap/">Twitter's Bootstrap</a> in our project.  There's a bit of ceremony around each field such that you need to do a <tt>.clearfix</tt> div, then a label, then a <tt>.input</tt> div and finally the input.  I want to eliminate all those keystrokes so I can just do:</p>
<pre class="brush:ruby">#./app/views/c2dm/new.html.haml
form_for @message, :url => {:action => 'create'} do |f|
  %fieldset
    = f.text_field :registration_id
    = f.text_field :collapse_key
    = f.text_area :message
    .actions
      %input.btn.primary{:type=>"submit"}
</pre>
<p>Here's the no-nonsense way of achieving this by adding a new class to your <tt>app/helpers/application_helper.rb</tt> (don't forget to restart your Rails server when you do this):</p>
<pre class="brush:ruby;">#./app/helpers/application_helper
&#8942;
# add these lines after the ApplicationHelper module
class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
  helpers = field_helpers +
              %w{date_select datetime_select time_select} +
              %w{collection_select select country_select time_zone_select} -
              %w{hidden_field label fields_for} # Don't decorate these
  helpers.each do |name|
    define_method(name) do |field, *args|
      options_index = ActionView::Helpers::FormBuilder.instance_method(name.to_sym).parameters.index([:opt,:options])
      if options_index.nil?
        options = args.last.is_a?(Hash) ? args.pop : {} # pretty sure this shouldn't happen
      else
        options = args[options_index - 1] # -1 to account for the method name argument
      end
      label = label(field, options[:label], :class => options[:label_class])
      @template.content_tag(:div, :class => 'clearfix') do
        @template.concat(label)
        @template.concat(@template.content_tag(:div, :class => 'input') { @template.concat(super(field, *args)) })
      end
    end
  end
end

ActionView::Base.default_form_builder = BootstrapFormBuilder
# you can also register this in ./config/application in the config block
# but I was not having a lot of success going that way
# which is why I moved it to the ./app/helpers/application_helper.rb file
</pre>
<p>Ideally you'd add this somewhere outside of <tt>application_helper.rb</tt> and load it properly.</p>
<p>What I referenced:</p>
<p><a href="http://onrails.org/2008/06/13/advanced-rails-studio-custom-form-builder">advanced rails studio: custom form builder</a><br />
<a href="http://code.alexreisner.com/articles/form-builders-in-rails.html">Form Builders in Rails</a><br />
<a href="http://adamhooper.com/eng/articles/2">Working With and Around FormBuilder</a></p>
<p>Updated: 12/21/2011 for handling methods where <tt>options</tt> isn't the last param.</p>
<div style="float: right; margin-left: 10px;"><a href="http://twitter.com/share?url=http://www.deploymentzone.com/2011/12/02/bootstrapformbuilder-or-how-actionviewhelpersformbuilder-ruined-my-day/&via=cfeduke&text=BootstrapFormBuilder, or how ActionView::Helpers::FormBuilder ruined my day&related=:&lang=en&count=horizontal" class="twitter-share-button">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div>]]></content:encoded>
			<wfw:commentRss>http://www.deploymentzone.com/2011/12/02/bootstrapformbuilder-or-how-actionviewhelpersformbuilder-ruined-my-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

