<?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>Pivotal Labs &#187; Georg Apitz</title>
	<atom:link href="http://pivotallabs.com/author/georg/feed/" rel="self" type="application/rss+xml" />
	<link>http://pivotallabs.com</link>
	<description>Agility Developed</description>
	<lastBuildDate>Fri, 24 May 2013 05:20:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How to render jade templates on the server</title>
		<link>http://pivotallabs.com/how-to-render-jade-templates-on-the-server/</link>
		<comments>http://pivotallabs.com/how-to-render-jade-templates-on-the-server/#comments</comments>
		<pubDate>Fri, 11 Jan 2013 05:11:05 +0000</pubDate>
		<dc:creator>Georg Apitz</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[backbone]]></category>
		<category><![CDATA[jade]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[server-side]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/?p=11588</guid>
		<description><![CDATA[<p>The best way for Google and friends to crawl and index a page is by finding static content. With applications that make heavy use of libraries like Backbone, Sproutcore or ember.js a lot of the content can be rendered in the browser. This can constitute a serious problem since the support methods from Google et. al. for alternative crawling coem with no guarantees. We recently ran into this problem and came up with a neet solution where the client side templates can also be rendered server side. There are two parts to the implementation. First, a method that can take a jade partial and its local variables, compile and evaluate it. Second, a view that calls out to that method and provides the template and the necessary local variables. Part 1, the application_helper.rb require 'tilt-jade/jade_js' module ApplicationHelper def html_from_jade_template(partial, options={}) data = File.open(\ Rails.root.join("app", "assets", "templates", "#{partial}.js.jst.jade"\ )) compiled =&#8230;</p><p>The post <a href="http://pivotallabs.com/how-to-render-jade-templates-on-the-server/">How to render jade templates on the server</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>The best way for Google and friends to crawl and index a page is by finding static content. With applications that make heavy use of libraries like Backbone, Sproutcore or ember.js a lot of the content can be rendered in the browser. This can constitute a serious problem since the support methods from Google et. al. for alternative crawling coem with no guarantees.</p>
<p>We recently ran into this problem and came up with a neet solution where the client side templates can also be rendered server side.</p>
<p>There are two parts to the implementation. First, a method that can take a jade partial and its local variables, compile and evaluate it. Second, a view that calls out to that method and provides the template and the necessary local variables.</p>
<p><b>Part 1, the application_helper.rb</b></p>
<pre>
<code class="ruby">
require 'tilt-jade/jade_js'

module ApplicationHelper
  def html_from_jade_template(partial, options={})
    data = File.open(\
            Rails.root.join("app", "assets", "templates", "#{partial}.js.jst.jade"\
            ))
    compiled = JadeJs.compile(data, locals: {}, client: true, compileDebug: false)

    raw(JadeJs::Source.context.eval("(#{compiled})(#{options[:locals].to_json}, \
        jade.runtime.attrs, jade.runtime.escape, jade.runtime.rethrow, \
        jade.runtime.merge)" \
        ))
  end
end
</code>
</pre>
<p>The method is pretty straight forward, it loads the template from the assets/template directory, compiles it and then evals it with the provided locals. The output is raw html that can be included in your view.</p>
<p><b>Part 2, a view that requests the compiled and eval&#8217;d templates from the server</b></p>
<pre>
<code class="haml">
- body = "This content comes from the server. Remove the param from the url or toggle \
          with the link in the upper right."
#menu
  = html_from_jade_template("home/menu", locals: {items: [{title: "Server"}, \
    {title: "Side"}, {title: "Rendered"}]})
#content
  = html_from_jade_template("home/content", locals: {body: body })
</code>
</pre>
<p>Here the main thing is the call to the method in application helper that will produce the raw html given a template name and the necessary local variables.</p>
<p>That is pretty much it. It may take a little bit to figure out the requirements for the local variables in your template, especially since jade is very strict about them. If it can&#8217;t find one it will not compile.</p>
<p>I&#8217;ve put an <a title="server-side-jade" href="https://github.com/geapi/server-side-jade">example app</a> on github with the complete source code for this post.</p>
<p>The post <a href="http://pivotallabs.com/how-to-render-jade-templates-on-the-server/">How to render jade templates on the server</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/how-to-render-jade-templates-on-the-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jasmine Testing: Param(s) passed to a method.</title>
		<link>http://pivotallabs.com/jasmine-testing-object-construction/</link>
		<comments>http://pivotallabs.com/jasmine-testing-object-construction/#comments</comments>
		<pubDate>Thu, 19 Jul 2012 15:08:00 +0000</pubDate>
		<dc:creator>Georg Apitz</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[backbone]]></category>
		<category><![CDATA[jasmine]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/jasmine-testing-object-construction/</guid>
		<description><![CDATA[<p><p>Recently, I've been using a nice way to test if the correct arguments have been passed to a method. This uses a neat property of jasmine where you set up the method you want to test as a mock and have an expectation inside the mock.</p>

<p>The only caveat is you have to set an expectation that your mock get's called, otherwise if it never gets executed the test will also never fail. </p> <a href="http://pivotallabs.com/jasmine-testing-object-construction/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/jasmine-testing-object-construction/">Jasmine Testing: Param(s) passed to a method.</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Recently, I&#8217;ve been using a nice way to test if the correct arguments have been passed to a method. This uses a neat property of jasmine where you set up the method you want to test as a mock and have an expectation inside the mock.</p>
<p>The only caveat is you have to set an expectation that your mock get&#8217;s called, otherwise if it never gets executed the test will also never fail. </p>
<h3>Step by Step</h3>
<p>1&#41; Set up the spy on the method for which you want to test the params.<br />
2&#41; Set up the expectation to compare a param to an expected value.</p>
<pre>
spyOn&#40;App.Views.MasterView.prototype, 'initialize'&#41;.andCallFake&#40;function&#40;&#41; {
 expect&#40;arguments[0].template&#41;.toEqual&#40;JST['my_templates/simple_view']&#41;;
}&#41;;
</pre>
<p>3&#41; Call something that should call the method under test with the correct params.</p>
<pre>
var router = new App.Routers.ViewRouter;
router.simpleViewInit&#40;&#41;;
</pre>
<p>4&#41; Set up an expecatation that makes sure the method under test get&#8217;s actually called.</p>
<pre>
expect&#40;App.Views.MasterView.prototype.initialize&#41;.toHaveBeenCalled&#40;&#41;;
</pre>
<p>Here you go, now it is easy to test if a method is called with the expected param&#40;s&#41;.</p>
<h3>The complete test.</h3>
<pre>
describe&#40;'App.Routers.ViewRouter', function&#40;&#41; {
  beforeEach&#40;function&#40;&#41; {
    Backbone.history.start&#40;&#41;;
  }&#41;;

  afterEach&#40;function&#40;&#41; {
    Backbone.history.stop&#40;&#41;;
  }&#41;;

    describe&#40;'#simpleViewInit', function&#40;&#41; {
        it&#40;'call initialize on the MasterView with the simple_view template', function&#40;&#41; {
        spyOn&#40;App.Views.MasterView.prototype, 'initialize'&#41;.andCallFake&#40;function&#40;&#41; {
             expect&#40;arguments[0].template&#41;.toEqual&#40;JST['my_templates/simple_view']&#41;;
          }&#41;;
          var router = new App.Routers.ViewRouter;
          router.simpleViewInit&#40;&#41;;

         expect&#40;App.Views.MasterView.prototype.initialize&#41;.toHaveBeenCalled&#40;&#41;;
        }&#41;;
    }&#41;;
}&#41;;
</pre>
<h3>The code that is under test.</h3>
<pre>
App.Routers.ViewRouter = App.Routers.BaseRouter.extend&#40;
{
    routes: {
        'example1': 'example1'
    },

    initialize: function&#40;&#41; {
        ...
    },

    simpleViewInit: function&#40;&#41; {
        this.simpleViewRecord = new App.Models.SimpleViewRecord&#40;&#41;;
        this.simpleView = new App.Views.MasterView&#40;{
            el: '#view_element',
            model: this.simpleView,
            template: JST[''my_templates/simple_view''],
            state: 'expired'
        }&#41;;

        this.simpleViewInit.fetch&#40;{
            success: function&#40;model&#41; {
              model.trigger&#40;'change'&#41;;
            }, silent: true
        }&#41;;
    }
}&#41;;
</pre>
<p>The post <a href="http://pivotallabs.com/jasmine-testing-object-construction/">Jasmine Testing: Param(s) passed to a method.</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/jasmine-testing-object-construction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Standup] [Boulder]  heroku and the crickets</title>
		<link>http://pivotallabs.com/standup-boulder-heroku-and-the-crickets/</link>
		<comments>http://pivotallabs.com/standup-boulder-heroku-and-the-crickets/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 15:20:00 +0000</pubDate>
		<dc:creator>Georg Apitz</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[standup-notes]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/standup-boulder-heroku-and-the-crickets/</guid>
		<description><![CDATA[<p><h2>help</h2>

<ul>
<li>anybody seen old content showing up on heroku at various points in time &#40;especially at night&#41;?
<ul>
<li>crickets ...</li>
</ul></li>
</ul>

<h2>interesting</h2>

<ul>
<li>rake execute takes a hash, rake invoke takes an ordered list</li>
<li><a href="http://join.me">http://join.me</a> is a cool tool for interactive screen sharing</li>
<li>don't use anonymous iframes for ajax file upload, use a class or id,
<ul>
<li>we saw weird issues with a chat provider who uses an anonymous iframe which was getting all our file upload info</li>
</ul></li>
</ul> <a href="http://pivotallabs.com/standup-boulder-heroku-and-the-crickets/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/standup-boulder-heroku-and-the-crickets/">[Standup] [Boulder]  heroku and the crickets</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>help</h2>
<ul>
<li>anybody seen old content showing up on heroku at various points in time &#40;especially at night&#41;?
<ul>
<li>crickets &#8230;</li>
</ul>
</li>
</ul>
<h2>interesting</h2>
<ul>
<li>rake execute takes a hash, rake invoke takes an ordered list</li>
<li><a href="http://join.me">http://join.me</a> is a cool tool for interactive screen sharing</li>
<li>don&#8217;t use anonymous iframes for ajax file upload, use a class or id,
<ul>
<li>we saw weird issues with a chat provider who uses an anonymous iframe which was getting all our file upload info</li>
</ul>
</li>
</ul>
<p>The post <a href="http://pivotallabs.com/standup-boulder-heroku-and-the-crickets/">[Standup] [Boulder]  heroku and the crickets</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/standup-boulder-heroku-and-the-crickets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Standup] [Boulder] Make your own carousel</title>
		<link>http://pivotallabs.com/standup-boulder-make-your-own-carousel/</link>
		<comments>http://pivotallabs.com/standup-boulder-make-your-own-carousel/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 15:27:00 +0000</pubDate>
		<dc:creator>Georg Apitz</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[standup-notes]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/standup-boulder-make-your-own-carousel/</guid>
		<description><![CDATA[<p><h2>if you need to display complicated html in a javascript driven carousel, write your own,</h2>

<p>jquery plugins tend to mess with your markup and force it into a specific layout
which can break your behaviour</p>

<h2>acceptance vs. non acceptance rspec</h2>

<p>When running regular rspec tests and acceptance test combined slow build time were observed,
breaking them out into different builds resulted in a 25% speed up
&#40;combined 21 min, only rspec 5min, acceptance 10min&#41;</p>

<ul>
<li>possible help: leave transactional_fixtures as true for acceptance
supported by forcing one db connection as described here:
http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/</li>
<li>reopening the rspec config block in the acceptance helper can have unintended side effects, if you are running
units specs and acceptance specs together</li>
</ul> <a href="http://pivotallabs.com/standup-boulder-make-your-own-carousel/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/standup-boulder-make-your-own-carousel/">[Standup] [Boulder] Make your own carousel</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>if you need to display complicated html in a javascript driven carousel, write your own,</h2>
<p>jquery plugins tend to mess with your markup and force it into a specific layout<br />
which can break your behaviour</p>
<h2>acceptance vs. non acceptance rspec</h2>
<p>When running regular rspec tests and acceptance test combined slow build time were observed,<br />
breaking them out into different builds resulted in a 25% speed up<br />
&#40;combined 21 min, only rspec 5min, acceptance 10min&#41;</p>
<ul>
<li>possible help: leave transactional_fixtures as true for acceptance<br />
supported by forcing one db connection as described here:</p>
<p>http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/</li>
<li>reopening the rspec config block in the acceptance helper can have unintended side effects, if you are running<br />
units specs and acceptance specs together</li>
</ul>
<p>The post <a href="http://pivotallabs.com/standup-boulder-make-your-own-carousel/">[Standup] [Boulder] Make your own carousel</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/standup-boulder-make-your-own-carousel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>p3p headers to play with IE to keep cookies</title>
		<link>http://pivotallabs.com/p3p-headers-to-play-with-ie/</link>
		<comments>http://pivotallabs.com/p3p-headers-to-play-with-ie/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 03:55:00 +0000</pubDate>
		<dc:creator>Georg Apitz</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[ie cookie problem]]></category>
		<category><![CDATA[p3p]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/p3p-headers-to-play-with-ie/</guid>
		<description><![CDATA[<p><p>Another entry for memory's sake. In case you are running into problems with IE loosing cookies. You might have to set the psp response headers. See <a href="http://stackoverflow.com/questions/389456/cookie-blocked-not-saved-in-iframe-in-internet-explorer">here</a> for details.</p> <a href="http://pivotallabs.com/p3p-headers-to-play-with-ie/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/p3p-headers-to-play-with-ie/">p3p headers to play with IE to keep cookies</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Another entry for memory&#8217;s sake. In case you are running into problems with IE loosing cookies. You might have to set the psp response headers. See <a href="http://stackoverflow.com/questions/389456/cookie-blocked-not-saved-in-iframe-in-internet-explorer">here</a> for details.</p>
<p>The post <a href="http://pivotallabs.com/p3p-headers-to-play-with-ie/">p3p headers to play with IE to keep cookies</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/p3p-headers-to-play-with-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixture builder and rspec-acceptance</title>
		<link>http://pivotallabs.com/fixture-builder-and-rspec-acceptance/</link>
		<comments>http://pivotallabs.com/fixture-builder-and-rspec-acceptance/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 02:58:00 +0000</pubDate>
		<dc:creator>Georg Apitz</dc:creator>
				<category><![CDATA[Labs]]></category>
		<category><![CDATA[acceptance-testing]]></category>
		<category><![CDATA[database_cleaner]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://pivotallabs.com/fixture-builder-and-rspec-acceptance/</guid>
		<description><![CDATA[<p><p>Getting rspec-acceptance &#40;webdriver, no cucumber&#41; to work correctly with <a href="https://github.com/rdy/fixture_builder" title="fixture_builder on github">fixture_builder</a> and <a href="https://github.com/bmabey/database_cleaner" title="database_cleaner on github">database_cleaner</a> can be a bit of a drag. </p>

<p>It is actually not that hard and there are resources all over the inter tubes, you just have to find them.
For the sake of saving myself and some fellow programmers some time I will summarize the process we followed.</p>

<p>First, you need to make sure to have the <a href="https://github.com/rdy/fixture_builder" title="fixture_builder on github">fixture_builder</a>, <a href="https://github.com/bmabey/database_cleaner" title="database_cleaner on github">database_cleaner</a> and while we're at it <a href="https://github.com/leonid-shevtsov/headless">headless</a> gems installed.
Then the bulk of the work happens in <em>acceptance_helper.rb</em>, <em>spec_helper.rb</em> and <em>fixture_builder.rb</em>.</p>

<p>Details on what is in them are below. There are some notable things which I mention in context with the code.</p> <a href="http://pivotallabs.com/fixture-builder-and-rspec-acceptance/">Continue reading <span class="meta-nav">&#8594;</span></a></p><p>The post <a href="http://pivotallabs.com/fixture-builder-and-rspec-acceptance/">Fixture builder and rspec-acceptance</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Getting rspec-acceptance &#40;webdriver, no cucumber&#41; to work correctly with <a href="https://github.com/rdy/fixture_builder" title="fixture_builder on github">fixture_builder</a> and <a href="https://github.com/bmabey/database_cleaner" title="database_cleaner on github">database_cleaner</a> can be a bit of a drag. </p>
<p>It is actually not that hard and there are resources all over the inter tubes, you just have to find them.<br />
For the sake of saving myself and some fellow programmers some time I will summarize the process we followed.</p>
<p>First, you need to make sure to have the <a href="https://github.com/rdy/fixture_builder" title="fixture_builder on github">fixture_builder</a>, <a href="https://github.com/bmabey/database_cleaner" title="database_cleaner on github">database_cleaner</a> and while we&#8217;re at it <a href="https://github.com/leonid-shevtsov/headless">headless</a> gems installed.<br />
Then the bulk of the work happens in <em>acceptance_helper.rb</em>, <em>spec_helper.rb</em> and <em>fixture_builder.rb</em>.</p>
<p>Details on what is in them are below. There are some notable things which I mention in context with the code.</p>
<h1><code>spec_helper.rb</code></h1>
<p>If you need you fixtures loaded in a particular order<br />
you can load them in that order by specifying them as argument for the config.global_fixtures variable in spec_helper.</p>
<pre>
ENV[&quot;RAILS_ENV&quot;] ||= 'test'
require File.expand_path&#40;&quot;../../config/environment&quot;, __FILE__&#41;
require 'rspec/rails'

Dir[Rails.root.join&#40;&quot;spec/support/**/*.rb&quot;&#41;].each {|f| require f}

RSpec.configure do |config|

  config.include ObjectCreationHelper
  config.include ObjectCreationMethods
  config.mock_with :rspec

  config.global_fixtures = :all

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = &quot;#{::Rails.root}/spec/fixtures&quot;

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true

  config.before&#40;js: nil&#41; do
    config.use_transactional_fixtures = true
  end

end
</pre>
<h1><code>accptance_helper.rb</code></h1>
<p>Here headless &#40;enables running selenium tests on a ci-server without a browser&#41; and data_base cleaner are set up.<br />
Database_cleaner will clean everything in the specified interval &#40;in my case after each test&#41; unless tables are specified in the &#8220;except&#8221; option for the database_cleaner strategy.<br />
It is important to turn transactional fixtures off before running specs that require js and turn them back on after they have run<br />
to ensure <code>rspec spec</code> still runs, assuming that there are spec files that have both test that require js and some that don&#8217;t require js.</p>
<pre>
require 'spec_helper'
require 'capybara/rspec'
require 'capybara/rails'
require 'database_cleaner'
require 'headless'

headless = Headless.new
headless.start

at_exit do
  unless ENV['RUNNING_CI']
    headless.destroy
  end
end

def build_fixtures
  Fixtures.reset_cache
  fixtures_folder = File.join&#40;Rails.root.to_s, 'spec', 'fixtures'&#41;
  fixtures = Dir[File.join&#40;fixtures_folder, '*.yml'&#41;].map { |f| File.basename&#40;f, '.yml'&#41; }
  DatabaseCleaner.clean
  Fixtures.create_fixtures&#40;fixtures_folder, fixtures&#41;
end

RSpec.configure do |config|
  config.before&#40;:suite&#41; do
    DatabaseCleaner.strategy = :truncation, {:except =&gt; %w[ ]}
    DatabaseCleaner.clean_with&#40;:truncation&#41;
  end

  # before each test that requires js, turn transactional fixtures off
  # build the fixtures and start the db cleaner
  config.before&#40;js: true&#41; do
    config.use_transactional_fixtures = false
    build_fixtures&#40;&#41;
    DatabaseCleaner.start
  end

  # after each spec with js, turn transactional fixtures back on
  # rebuild fixtures
  config.after&#40;:each, js: true&#41; do
    config.use_transactional_fixtures = true
    build_fixtures&#40;&#41;
  end
end
</pre>
<h1><code>fixture_builder.rb</code></h1>
<p>Pretty straight forward, some clean up and checking if fixtures need rebuilding. Since database_cleaner will try to clean all exisiting tables<br />
it is important to exclude database views specifically.</p>
<pre>
FixtureBuilder::Configuration.class_eval do

  def rebuild_fixtures?
    &#40;@file_hashes != read_config&#41; || Dir.glob&#40;'spec/fixtures/**/*.yml'&#41;.empty?
  end

  def files_to_check
    @files_to_check ||= []
  end

  def delete_tables
    ActiveRecord::Base.connection.execute&#40;'SET FOREIGN_KEY_CHECKS=0'&#41;
    tables.each { |t| ActiveRecord::Base.connection.delete&#40;delete_sql % ActiveRecord::Base.connection.quote_table_name&#40;t&#41;&#41; }
  ensure
    ActiveRecord::Base.connection.execute&#40;'SET FOREIGN_KEY_CHECKS=1'&#41;
  end

end

FixtureBuilder.configure do |builder|
  builder.files_to_check = Dir[&quot;spec/support/fixture_builder.rb&quot;]
  builder.skip_tables += [&quot;current_post_stats_view&quot;]
  builder.factory do

    united_states = Country.create! :name =&gt; &quot;United States&quot;, :country_code =&gt; &quot;US&quot;
    Country.create! :name =&gt; &quot;Canada&quot;, :country_code =&gt; &quot;CA&quot;

    admin_user = User.create! do |user|
      user.first_name = &quot;Admin&quot;
      user.last_name = &quot;User&quot;
      user.email = &quot;admin@super_site_.com&quot;
      user.password = &quot;password&quot;
      user.password_confirmation = &quot;password&quot;
      user.role = &quot;admin&quot;
    end
    name&#40;&quot;admin&quot;, admin_user&#41;

  end
end
</pre>
<p>The post <a href="http://pivotallabs.com/fixture-builder-and-rspec-acceptance/">Fixture builder and rspec-acceptance</a> appeared first on <a href="http://pivotallabs.com">Pivotal Labs</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://pivotallabs.com/fixture-builder-and-rspec-acceptance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using apc
Database Caching using apc
Object Caching 823/914 objects using apc

 Served from: pivotallabs.com @ 2013-05-24 05:55:17 by W3 Total Cache -->