<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>validates_presence_of :purpose : Tag bug, everything about bug</title>
    <link>http://lenaherrmann.net</link>
    <language>en_US</language>
    <ttl>40</ttl>
    <description>Lena Herrmann</description>
    <item>
      <title>Testing PUT requests with Culerity</title>
      <description>&lt;p&gt;&lt;img style="float:left;margin-right:10px;" width="250"  src="/files/Image/Bildschirmfoto%202010-02-02%20um%2012.38.41.png" alt="All green!" /&gt;&lt;/p&gt;


&lt;p&gt;One major pain at testing with culerity so far was a HtmlUnit bug that causes a ScriptException with PUT AJAX requests in jQuery. When you tried to test an update you got a &amp;#8220;java.lang.IllegalArgumentException: The content cannot be null&amp;#8221;. Fortunately, this bug is fixed now. With latest HtmlUnit build culerity should run fine, and I tell you how.&lt;/p&gt;


&lt;p&gt;I assume you have culerity installed already. If not, follow &lt;a href="http://github.com/langalex/culerity"&gt;these instructions&lt;/a&gt; for testing Rails apps &lt;a href="http://upstre.am/2009/10/25/testing-couchapps-with-cucumber-and-culerity/"&gt;or these&lt;/a&gt; for testing Couchapps.&lt;/p&gt;


&lt;p&gt;1. Make sure you have up-to-date versions of celerity and culerity:&lt;br/&gt;
$ jruby -S gem install celerity #(gives you celerity-0.7.8)&lt;br/&gt;
$ gem install culerity &amp;#8211;source http://gemcutter.org #(gives you culerity-0.2.7)&lt;/p&gt;


&lt;p&gt;2. Get the latest HtmlUnit nightly build:&lt;br/&gt;
$ wget http://build.canoo.com/htmlunit/artifacts/htmlunit-2.7-SNAPSHOT-with-dependencies.zip&lt;br/&gt;
$ unzip htmlunit-2.7-SNAPSHOT-with-dependencies.zip &lt;br/&gt;
$ cd htmlunit-2.7-SNAPSHOT-with-dependencies/lib&lt;br/&gt;
These are the jar files you need to copy into your celerity gem.&lt;/p&gt;


&lt;p&gt;3. Find your celerity gem and copy the files:&lt;br/&gt;
$ jruby -S gem which celerity&lt;br/&gt;
$ cp * PATH_OF_JRUBY_INSTALLATION/lib/ruby/gems/1.8/gems/celerity-0.7.7/lib/celerity/htmlunit&lt;/p&gt;


&lt;p&gt;4. The new HtmlUnit needs JQuery 1.4, so you &lt;a href="http://docs.jquery.com/Downloading_jQuery#Current_Release"&gt;need to upgrade&lt;/a&gt; if you haven&amp;#8217;t done already. There&amp;#8217;s a &lt;a href="http://github.com/jquery/jquery-compat-1.3"&gt;backwards compatibility plugin for 1.3&lt;/a&gt; if this gives you trouble.
&lt;/p&gt;


&lt;p&gt;Have fun!&lt;/p&gt;
</description>
      <pubDate>Sun, 31 Jan 2010 21:22:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:40dcb9ab-9661-4888-bdb1-d9ac36fb7fc2</guid>
      <comments>http://lenaherrmann.net/2010/01/31/testing-put-requests-with-culerity#comments</comments>
      <category>testing</category>
      <category>culerity</category>
      <category>ajax</category>
      <category>htmlunit</category>
      <category>bug</category>
      <category>celerity</category>
      <trackback:ping>http://lenaherrmann.net/trackbacks?article_id=10</trackback:ping>
      <link>http://lenaherrmann.net/2010/01/31/testing-put-requests-with-culerity</link>
    </item>
    <item>
      <title>Couchapp / Culerity glitches, part 1</title>
      <description>&lt;p&gt;Do you know what's behind these buzzwords: &lt;a href="http://couchdb.apache.org"&gt;CouchDB&lt;/a&gt; / &lt;a href="http://github.com/couchapp/couchapp"&gt;Couchapp&lt;/a&gt; / &lt;a href="http://code.quirkey.com/sammy/"&gt;Sammy.js&lt;/a&gt;? Not really? Then please look at this article now: &lt;a href="http://www.quirkey.com/blog/2009/09/15/sammy-js-couchdb-and-the-new-web-architecture"&gt;Sammy.js, CouchDB, and the new web architecture&lt;/a&gt;. The title says it all.&lt;/p&gt;


&lt;p&gt;This setup happens to be the field of my diploma thesis, friendly sponsored and supported by &lt;a href="http://upstream-berlin.com"&gt;Upstream&lt;/a&gt;. During the next months I'll develop a super duper thing with these technologies, and then I'll write 80 scientific pages about it. Yees, I'm not that much looking forward to the second part! Until then, I'm planning to semi-regularly blog about my findings.&lt;/p&gt;


&lt;p&gt;I'm not allowed to share the code before I have the diploma in my hands. But, because my workmate &lt;a href="http://twitter.com/bionadeholunder"&gt;Frank Proessdorf&lt;/a&gt; is so jealous of what I do, he and I started working on an app with a similar setup on our Upstream Research Fridays, to try things out. &lt;a href="http://github.com/lenalena/jsdoodle"&gt;Here it is&lt;/a&gt;. Don't expect anything yet.&lt;/p&gt;


&lt;p&gt;Today I'm going to tell you about some details of my testing setup. My *cough* supervising tutor &lt;a href="http://twitter.com/langalex"&gt;Alexander Lang&lt;/a&gt; already wrote down &lt;a href="http://upstream-berlin.com/2009/10/25/testing-couchapps-with-cucumber-and-culerity"&gt;all there is to know yet&lt;/a&gt; about Test-Driven Development with Cucumber-Culerity-Celerity and Couchapps.&lt;/p&gt;


&lt;p&gt;But there are a few things that will make your life hard, when the almost perfect Rails testing world has spoiled you as much as me. One thing is that we have to deal with a lot of asynchrony. Sammy renders the page, loads the data from the couch, and whenever the data is there it gets rendered into the page. The best way to do this is via callbacks. I'm going to write another blog post about that soon.&lt;/p&gt;


&lt;p&gt;In the integration test the problem is that celerity doesn't behave as it claims it does:&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="gv"&gt;$browser&lt;/span&gt;.wait&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;is &lt;em&gt;supposed&lt;/em&gt; to make the test wait until everything is rendered completely. But for whatever reason it doesn't. The result is that your test fails because it searches for your expressions in an unfinished page.&lt;/p&gt;

&lt;p&gt;Because of that, in culerity we need something like:&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;sleep &lt;span class="fl"&gt;0.4&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;after every follow, press and go-to-path step. When using culerity in a Rails environment, this usually is enough. Sammy behaves a bit more unpredictable - it sometimes takes more than a whole second until everything is loaded.&lt;/p&gt;

&lt;p&gt;Solution? We can either increase the sleep time a lot, but that's not very nice, the features need long enough to run as it is. Fortunately we can use another method that's build into celerity: wait_while.&lt;/p&gt;

&lt;p&gt;I created a div "spinner" somewhere in index.html:
&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt; &lt;span class="ta"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="an"&gt;id&lt;/span&gt;=&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;spinner&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class="ta"&gt;&amp;gt;&lt;/span&gt;&lt;span class="ta"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;You can also add an actual spinner gif here. Just take care to place the div outside of your sammy element selector ("#main" by default), because this div gets replaced all the time.&lt;/p&gt;

&lt;p&gt;We need to show that div before every route that gets run. In application.js:
&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;before(&lt;span class="kw"&gt;function&lt;/span&gt;() {
  &lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;#spinner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).show();
});&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;And we need to hide it after your rendering is completed. I haven't found an ideal solution where to do that, it depends on the application you are writing. As a quick and dirty fix, you can add it as a last line in sammy's partial function, in sammy.js:&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;partial: &lt;span class="kw"&gt;function&lt;/span&gt;(path, data, callback) {
  &lt;span class="c"&gt;//...&lt;/span&gt;
  &lt;span class="pd"&gt;$&lt;/span&gt;(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;#spinner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).hide();
},&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I prefer to have more control about when I hide it, as my partial calls sometimes have nested callbacks. So I put it in application.js, resp. in my controllers, after each render call or in the partial callbacks. I admit this still sucks a bit.&lt;/p&gt;

&lt;p&gt;Finally, amend the cucumber step:&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="co"&gt;When&lt;/span&gt; &lt;span class="rx"&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="k"&gt;I wait for the AJAX call to finish&lt;/span&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;/span&gt; &lt;span class="r"&gt;do&lt;/span&gt;
  sleep &lt;span class="fl"&gt;0.2&lt;/span&gt;
  puts &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;Waiting for page to load ...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt; &lt;span class="r"&gt;if&lt;/span&gt; &lt;span class="gv"&gt;$browser&lt;/span&gt;.div(&lt;span class="sy"&gt;:id&lt;/span&gt;, &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;spinner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).visible?
  &lt;span class="gv"&gt;$browser&lt;/span&gt;.wait_while { &lt;span class="gv"&gt;$browser&lt;/span&gt;.div(&lt;span class="sy"&gt;:id&lt;/span&gt;, &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;spinner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;).visible?} 
&lt;span class="r"&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The browser still needs to sleep a bit before it actually finds the spinner div. But with this step in my common_culerity_steps.rb, the features finally run smoothly.&lt;/p&gt;</description>
      <pubDate>Wed, 04 Nov 2009 10:07:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:3e495ea7-1021-404e-b3ba-18267d409146</guid>
      <comments>http://lenaherrmann.net/2009/11/04/couchapp-culerity-glitches-part-1#comments</comments>
      <category>cucumber</category>
      <category>culerity</category>
      <category>celerity</category>
      <category>couchapp</category>
      <category>couchdb</category>
      <category>sammy.js</category>
      <category>javascript</category>
      <category>bug</category>
      <category>testing</category>
      <trackback:ping>http://lenaherrmann.net/trackbacks?article_id=6</trackback:ping>
      <link>http://lenaherrmann.net/2009/11/04/couchapp-culerity-glitches-part-1</link>
    </item>
    <item>
      <title>Comatose bug when creating pages in migrations</title>
      <description>&lt;p&gt;&lt;a href="http://comatose.rubyforge.org/"&gt;Comatose&lt;/a&gt; is a micro CMS, easy to embed in your Rails app, ideal when the customer wants to update her FAQ once in a while. I work on a few projects where comatose is integrated, and it's been the second time now that one specific problem has given headaches to me and my colleagues. Time to document the solution.&lt;/p&gt;


&lt;p&gt;Comatose has a hierarchical structure. All the pages are children of the comatose root page, which is usually not in use. This root page is created by the migration AddComatoseSupport. When we add comatose to a project, we usually create another migration, where some child pages are created and populated (because the customer usually already knows what pages she wants). This can look like this:&lt;/p&gt;


&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;root = &lt;span class="co"&gt;ComatosePage&lt;/span&gt;.find_by_title(&lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;Home Page&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;)
faq = &lt;span class="co"&gt;ComatosePage&lt;/span&gt;.create(&lt;span class="sy"&gt;:title&lt;/span&gt; =&amp;gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;FAQ&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="sy"&gt;:author&lt;/span&gt; =&amp;gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;System&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="sy"&gt;:body&lt;/span&gt; =&amp;gt; &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;Text goes here.&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class="sy"&gt;:parent_id&lt;/span&gt; =&amp;gt; root.id&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;All will be fine if you run the AddComatoseSupport migration first, and then the other one. If you run both of them in one go, all will look correctly first, too. But then - try to access the application and you get "a nil object when you didn't expect it!" A look in the database will tell you that your root page and your FAQ page are both there - but the slugs (needed to access the pages) are nil. Why is that?&lt;/p&gt;

&lt;p&gt;The answer: The class ComatosePage gets overwritten in the AddComatoseSupport migration, to make sure the comatose root page can be created (they are invalid without parent_id). But if you have another migration following this one, where you create a couple of comatose pages, they still are instances of that overwritten class. Especially the before/after filters from the original ComatosePage aren't evaluated. In those filters the slug fields are meant to be populated, so they are nil.&lt;/p&gt;

&lt;p&gt;First soluton: Define a class ComatoseRootPage instead, so you won't override anything.&lt;/p&gt;

&lt;p&gt;Second and much easier solution: Remove the class redefinition altogether, for the root page just do
&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="co"&gt;ComatosePage&lt;/span&gt;.new(...).save(&lt;span class="pc"&gt;false&lt;/span&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
 &lt;a href="http://github.com/lenalena/comatose/commit/4005cf44f11165393b18b3fed2837a9afb57814a"&gt;See on github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Unfortunately the comatose project is not updated very often, so this bug is still unsolved in the generated migrations.&lt;/p&gt;</description>
      <pubDate>Tue, 27 Oct 2009 22:27:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:0f740e51-8617-4048-a94b-90528f912f58</guid>
      <comments>http://lenaherrmann.net/2009/10/27/comatose-bug-when-creating-pages-in-migrations#comments</comments>
      <category>rails</category>
      <category>comatose</category>
      <category>bug</category>
      <trackback:ping>http://lenaherrmann.net/trackbacks?article_id=4</trackback:ping>
      <link>http://lenaherrmann.net/2009/10/27/comatose-bug-when-creating-pages-in-migrations</link>
    </item>
  </channel>
</rss>
