<?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>6502.fr &#187; Ruby on Rails</title>
	<atom:link href="http://www.6502.fr/category/ruby-on-rails/feed" rel="self" type="application/rss+xml" />
	<link>http://www.6502.fr</link>
	<description>L'Avant-dernier cri de la technologie</description>
	<lastBuildDate>Sat, 31 Jul 2010 15:39:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Les modifications de CSS n&#8217;apparaissent pas dans Spree</title>
		<link>http://www.6502.fr/les-modifications-de-css-napparaissent-pas-dans-spree/257</link>
		<comments>http://www.6502.fr/les-modifications-de-css-napparaissent-pas-dans-spree/257#comments</comments>
		<pubDate>Tue, 27 Jul 2010 15:19:18 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=257</guid>
		<description><![CDATA[En cours de développement, vos modifications de feuilles de style n&#8217;apparaissent pas sur le site ? C&#8217;est normal ! La structure de l&#8217;application est complexe. Si vous respectez l&#8217;architecture recommandée (version 0.11), vos feuilles de styles sont dans vendor/extensions/theme_xxxx/public/stylesheets/ (si votre thème s&#8217;appelle xxxx). Le serveur web n&#8217;est pas configuré pour aller chercher les assets [...]]]></description>
			<content:encoded><![CDATA[<p>En cours de développement, vos modifications de feuilles de style n&#8217;apparaissent pas sur le site ? C&#8217;est normal !</p>
<p>La structure de l&#8217;application est complexe. Si vous respectez l&#8217;architecture recommandée (version 0.11), vos feuilles de styles sont dans <code>vendor/extensions/theme_xxxx/public/stylesheets/</code> (si votre thème s&#8217;appelle <i>xxxx</i>).</p>
<p>Le serveur web n&#8217;est pas configuré pour aller chercher les <i>assets</i> ailleurs que dans <code>public</code>. Au démarrage de votre application, les fichiers CSS sont donc recopiés des répertoires des extensions dans le répertoire <code>public</code> principal.</p>
<p>Remarque finale : pour la même raison, un <i>commit</i> ou un <i>status</i> dans votre système de gestion de version vous montrera les vieux fichiers dans <code>public</code> si vous n&#8217;avez pas relancé votre serveur entre temps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/les-modifications-de-css-napparaissent-pas-dans-spree/257/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gérer plusieurs versions de Ruby sur Leopard</title>
		<link>http://www.6502.fr/plusieurs-versions-de-ruby-sur-leopard-avec-rvm/246</link>
		<comments>http://www.6502.fr/plusieurs-versions-de-ruby-sur-leopard-avec-rvm/246#comments</comments>
		<pubDate>Mon, 12 Jul 2010 14:15:34 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Outils]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=246</guid>
		<description><![CDATA[Un jour ou l&#8217;autre vous allez avoir besoin d&#8217;une gem qui exige une version plus récente de Ruby. Par exemple sqlite3. $ sudo gem install sqlite3 Password: ERROR: Error installing sqlite3: sqlite3 requires Ruby version &#62;= 1.9.1. Mais vous utilisez des gems qui ne sont pas compatibles avec Ruby&#160;1.9 et vous devez donc faire cohabiter [...]]]></description>
			<content:encoded><![CDATA[<p>Un jour ou l&#8217;autre vous allez avoir besoin d&#8217;une <i>gem</i> qui exige une version plus récente de Ruby. Par exemple <i>sqlite3</i>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> sqlite3
Password:
ERROR:  Error installing sqlite3:
	sqlite3 requires Ruby version <span style="color: #000000; font-weight: bold;">&gt;</span>= 1.9.1.</pre></div></div>

<p>Mais vous utilisez des <i>gems</i> qui ne sont pas compatibles avec Ruby&nbsp;1.9 et vous devez donc faire cohabiter plusieurs versions de Ruby. C&#8217;est là que <a title="RVM: Ruby Version Manager [en anglais]" href="http://rvm.beginrescueend.com/rvm/install/">RVM</a> intervient.</p>
<h3>Installer RVM sur Leopard</h3>
<p>Passez la commande suivante dans une fenêtre de Terminal&nbsp;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> curl http:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>rvm-install-head <span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Puis ajoutez cette ligne à la fin de votre fichier <i>~/.profile</i>&nbsp;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>rvm <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>rvm</pre></div></div>

<p>Pour tous les détails additionnels, allez <a title="RVM: Ruby Version Manager - Installing RVM [en anglais]" href="http://rvm.beginrescueend.com/rvm/install/">à la source</a>.</p>
<h3>Utiliser RVM</h3>
<p>Vous pouvez maintenant utiliser rvm, par exemple pour installer Ruby&nbsp;1.9.1.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.9.1 ; rvm 1.9.1
$ ruby <span style="color: #660033;">-v</span>
ruby 1.9.1p378 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2010</span>-01-<span style="color: #000000;">10</span> revision <span style="color: #000000;">26273</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i386-darwin9.8.0<span style="color: #7a0874; font-weight: bold;">&#93;</span>
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> sqlite3
Building native extensions.  This could take a while...
...
Successfully installed sqlite3-0.1.1</pre></div></div>

<p>Pour revenir à la version d&#8217;origine&nbsp;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ rvm system
$ ruby <span style="color: #660033;">-v</span>
ruby 1.8.7 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2009</span>-06-<span style="color: #000000;">12</span> patchlevel <span style="color: #000000;">174</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i686-darwin9.8.0<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/plusieurs-versions-de-ruby-sur-leopard-avec-rvm/246/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec have_tag et Rails assert_select cheat sheet</title>
		<link>http://www.6502.fr/rspec-have_tag-et-rails-assert_select-cheat-sheet/216</link>
		<comments>http://www.6502.fr/rspec-have_tag-et-rails-assert_select-cheat-sheet/216#comments</comments>
		<pubDate>Tue, 25 Nov 2008 23:18:30 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[assert_select]]></category>
		<category><![CDATA[have_tag]]></category>
		<category><![CDATA[RSpec]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=216</guid>
		<description><![CDATA[have_tag (RSpec) et assert_select (Rails) facilitent le test des vues grâce à une syntaxe proche de celle du CSS. Vérifions par exemple la présence d&#8217;un titre qui contient le texte Subtitle et d&#8217;un formulaire (id=&#160;&#187;swap&#160;&#187;) avec deux boutons radio et un bouton de soumission (class=&#160;&#187;button_save&#160;&#187;)&#160;: response.should have_tag("h2", /Subtitle/) response.should have_tag("form#swap[method=post]") response.should have_tag("form#swap input[type=radio][name=?]", 'part1') response.should [...]]]></description>
			<content:encoded><![CDATA[<p><code>have_tag</code> (RSpec) et <code>assert_select</code> (Rails) facilitent le test des vues grâce à une syntaxe proche de celle du CSS. Vérifions par exemple la présence d&#8217;un titre qui contient le texte <i>Subtitle</i> et d&#8217;un formulaire (id=&nbsp;&raquo;swap&nbsp;&raquo;) avec deux boutons radio et un bouton de soumission (class=&nbsp;&raquo;button_save&nbsp;&raquo;)&nbsp;:</p>
<pre lang=ruby>
response.should have_tag("h2", /Subtitle/)
response.should have_tag("form#swap[method=post]")
response.should have_tag("form#swap input[type=radio][name=?]", 'part1')
response.should have_tag("form#swap input[type=radio][name=?]", 'part2')
response.should have_tag("form#swap input.button_save[type=submit]")
</pre>
<p>Autre exemple, un formulaire AJAX dans sa <code>div</code> (id=&nbsp;&raquo;filter&nbsp;&raquo;, mais vous avez compris maintenant) avec une liste déroulante, avec soumission par GET sur changement de la sélection&nbsp;:</p>
<pre lang=ruby>
response.should have_tag("select option", "All")
response.should have_tag("select option", /20/)
response.should_not have_tag("select option", /21/)
response.should have_tag("div#filter form[method=?]", 'get')
response.should have_tag("div#filter form select[onchange=?]", 'this.form.submit()')
</pre>
<p>La syntaxe du sélecteur a beau être proche de celle du CSS, il est difficile de s&#8217;en rappeler toutes les subtilités. C&#8217;est là qu&#8217;intervient l&#8217;excellente <em><a href="http://labnotes.org/svn/public/ruby/rails_plugins/assert_select/cheat/assert_select.html">cheat sheet</a></em> créée par Assaf Arkin de <a href="http://blog.labnotes.org/2006/09/04/assert_select-cheat-sheet/">Labnotes</a>. Indispensable&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/rspec-have_tag-et-rails-assert_select-cheat-sheet/216/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Déploiement Capistrano à partir de Windows</title>
		<link>http://www.6502.fr/deploiement-capistrano-a-partir-de-windows/205</link>
		<comments>http://www.6502.fr/deploiement-capistrano-a-partir-de-windows/205#comments</comments>
		<pubDate>Tue, 11 Nov 2008 00:27:52 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Outils]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Windows Vista]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=205</guid>
		<description><![CDATA[Capistrano est un outil de déploiement puissant et facile d&#8217;emploi, dont j&#8217;ai déjà parlé. Il tourne sous Windows, Mac OS et Linux (entre autres) et est d&#8217;une mise en service aisée si l&#8217;on connait ssh et subversion. C&#8217;est pourquoi j&#8217;ai été fort (désagréablement) surpris quand mon récent cap deploy a échoué avec le message d&#8217;erreur [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Capistrano [en anglais]" href="http://www.capify.org/">Capistrano</a> est un outil de déploiement puissant et facile d&#8217;emploi, dont j&#8217;ai <a title="Capistrano – symboles :scm_user et :scm_username" href="/capistrano-scm_user-et-scm_username/196">déjà</a> <a title="Afficher une page de maintenance pendant le déploiement" href="/afficher-une-page-de-maintenance-pendant-le-deploiement/88">parlé</a>. Il tourne sous Windows, Mac OS et Linux (entre autres) et est d&#8217;une mise en service aisée si l&#8217;on connait ssh et <a title="Subversion [en anglais]" href="http://subversion.tigris.org/">subversion</a>.</p>
<p>C&#8217;est pourquoi j&#8217;ai été fort (désagréablement) surpris quand mon récent <code>cap deploy</code> a échoué avec le message d&#8217;erreur suivant :</p>
<pre>c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.1/lib/capistrano/recipes/deploy.rb:97:in ``': No such file or directory - svn info http://svn.example.com/</pre>
<p>On comprend bien qu&#8217;il s&#8217;agit de ma machine mobile et portable qui tourne sous Windows Vista. Le client SVN de choix sous Windows reste sans conteste <a title="TortoiseSVN [en anglais]" href="http://tortoisesvn.tigris.org/">TortoiseSVN</a>. Malheureusement (d&#8217;une certaine manière), TortoiseSVN est un vrai client Subversion et non un <em>wrapper </em>graphique s&#8217;appuyant sur l&#8217;exécutable svn (en ligne de commande donc).</p>
<p>Or Capistrano invoque l&#8217;exécutable sus-cité, et ne le trouve pas. Solution simple et rapide : installer le client officiel SVN, que l&#8217;on peut trouver <a href="http://subversion.tigris.org/getting.html#binary-packages">ici</a>.</p>
<p>Et hop !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/deploiement-capistrano-a-partir-de-windows/205/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec : tester le contenu d&#8217;un content_for</title>
		<link>http://www.6502.fr/rspec-tester-le-contenu-de-content_for/198</link>
		<comments>http://www.6502.fr/rspec-tester-le-contenu-de-content_for/198#comments</comments>
		<pubDate>Sun, 02 Nov 2008 15:38:55 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[RSpec]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=198</guid>
		<description><![CDATA[Une spécification de vue sous RSpec pourrait ressembler à ça&#160;: it &#34;should render column titles&#34; do render &#34;/feeds/index.html.erb&#34; response.should have_tag&#40;&#34;tr&#62;th&#34;, &#34;name&#34;&#41; response.should have_tag&#40;&#34;tr&#62;th&#34;, &#34;url&#34;&#41; end Mais cette méthode ne permet pas de tester les bribes de HTML qui sont produites dans un content_for. En effet, ces bribes sont incluses directement dans le layout, pas dans [...]]]></description>
			<content:encoded><![CDATA[<p>Une spécification de vue sous RSpec pourrait ressembler à ça&nbsp;:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  it <span style="color:#996600;">&quot;should render column titles&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    render <span style="color:#996600;">&quot;/feeds/index.html.erb&quot;</span>
    response.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;tr&gt;th&quot;</span>, <span style="color:#996600;">&quot;name&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    response.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;tr&gt;th&quot;</span>, <span style="color:#996600;">&quot;url&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Mais cette méthode ne permet pas de tester les bribes de HTML qui sont produites dans un <em>content_for</em>. En effet, ces bribes sont incluses directement dans le layout, pas dans la production de la vue. Pour ce faire, ajouter dans <em>spec_helper.rb</em>&nbsp;:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> content_for<span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span>
    response.<span style="color:#9900CC;">template</span>.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;@content_for_#{name}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Puis dans les specs&nbsp;:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  it <span style="color:#996600;">&quot;should render a 'New feed' link&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    render <span style="color:#996600;">&quot;/feeds/index.html.erb&quot;</span>
    content_for<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:somewhere</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> have_tag<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;a[href=?]&quot;</span>, new_feed_path<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Merci à <a title="rspec-users mailing list [en anglais]" href="http://rubyforge.org/pipermail/rspec-users/2007-June/001954.html">Carl-Johan Kihlbom</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/rspec-tester-le-contenu-de-content_for/198/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails : l&#8217;opérateur bang-bang !!</title>
		<link>http://www.6502.fr/ruby-on-rails-operateur-bang-bang/187</link>
		<comments>http://www.6502.fr/ruby-on-rails-operateur-bang-bang/187#comments</comments>
		<pubDate>Wed, 22 Oct 2008 07:30:17 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=187</guid>
		<description><![CDATA[Bon, ce n&#8217;est pas vraiment un opérateur, mais l&#8217;idiome est assez répandu et peut surprendre. Il est utilisé pour convertir nil en false, ce qui peut éviter des tests spécifiques comme if variable.nil? Deux petits rappels : ! est l&#8217;opérateur de négation logique. Seuls false et nil ont la valeur booléenne FAUX. Tout le reste [...]]]></description>
			<content:encoded><![CDATA[<p>Bon, ce n&#8217;est pas vraiment un opérateur, mais l&#8217;idiome est assez répandu et peut surprendre. Il est utilisé pour convertir <em>nil</em> en <em>false</em>, ce qui peut éviter des tests spécifiques comme <code>if variable.nil?</code></p>
<p>Deux petits rappels : </p>
<ol>
<li><strong>!</strong> est l&#8217;opérateur de négation logique.</li>
<li>Seuls <em>false</em> et <em>nil</em> ont la valeur booléenne FAUX. Tout le reste est vrai (y compris 0, la chaîne de caractère vide, etc.</li>
</ol>
<p>Nous en déduisons la table de vérité suivante :</p>
<table style="border: 1px solid #999999;">
<tr>
<td width="100px" style="text-align: center;"><strong>variable</strong></td>
<td width="100px" style="text-align: center;"><strong>!variable</strong></td>
<td width="100px" style="text-align: center;"><strong>!!variable</strong></td>
</tr>
<tr>
<td style="text-align: center;">*</td>
<td style="text-align: center;">false</td>
<td style="text-align: center;">true</td>
</tr>
<tr>
<td style="text-align: center;">false</td>
<td style="text-align: center;">true</td>
<td style="text-align: center;">false</td>
</tr>
<tr>
<td style="text-align: center;">nil</td>
<td style="text-align: center;">true</td>
<td style="text-align: center;">false</td>
</tr>
</table>
<p>* = n&#8217;importe quoi sauf <em>nil</em> ou <em>false</em>, donc de valeur booléenne <em>true</em>.</p>
<p>CQFD.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/ruby-on-rails-operateur-bang-bang/187/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rails : chargement des données initiales dans la base de données</title>
		<link>http://www.6502.fr/rails-chargement-des-donnees-initiales-dans-la-base-de-donnees/176</link>
		<comments>http://www.6502.fr/rails-chargement-des-donnees-initiales-dans-la-base-de-donnees/176#comments</comments>
		<pubDate>Mon, 15 Sep 2008 18:47:10 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=176</guid>
		<description><![CDATA[Il est fréquent que les applications aient besoin, pour fonctionner, de données initiales dans la base de données. Il y a plusieurs avis dans la communauté sur le moyen de charger ces données. Aucune méthode préférentielle ne se dégage. En particulier, les méthodes proposant de créer les données de test avec le code de l&#8217;application [...]]]></description>
			<content:encoded><![CDATA[<p>Il est fréquent que les applications aient besoin, pour fonctionner, de données initiales dans la base de données. Il y a plusieurs avis dans la communauté sur le moyen de charger ces données. </p>
<p>Aucune méthode préférentielle ne se dégage. En particulier, les méthodes proposant de créer les données de test avec le code de l&#8217;application sont inapplicables pour une importation sérieuse, tant par leur lourdeur que par la difficulté de maintenir les données de test au fur de l&#8217;évolution du code. J&#8217;ai choisi trois articles qui couvrent bien le sujet.</p>
<p>Luke Francl a écrit un article qui balaye les diverses possibilités <a href="http://railspikes.com/2008/2/1/loading-seed-data">Loading seed data</a>.</p>
<p><a href="http://www.intridea.com/authors/Michael%20Bleigh">Michael Bleigh</a> propose, dans son article <a href="http://www.intridea.com/2008/4/20/seed-fu-simple-seed-data-for-rails">Seed Fu: Simple Seed Data for Rails</a>, de créer les données grâce à des scripts Ruby placés dans le répertoire <em>db/fixtures</em>.</p>
<p>Enfin, Jeffrey Allan Hardy décrit dans <a href="http://quotedprintable.com/2007/11/16/seed-data-in-rails">Seed Data in Rails</a> la méthode simple et aisée à mettre en œuvre que j&#8217;ai retenue. Il s&#8217;agit d&#8217;utiliser le puissant mécanisme des fixtures dans une tâche <em>rake</em>.</p>
<p>Les données sont saisies dans des fichiers YAML placés dans le nouveau répertoire <em>db/fixtures</em>. Une tâche rake est ajouté en créant le fichier <em>db_seed.rake</em> dans le répertoire <em>lib/tasks</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:db</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#996600;">&quot;Load seed fixtures (from db/fixtures) into the current environment's database.&quot;</span> 
  task <span style="color:#ff3333; font-weight:bold;">:seed</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'active_record/fixtures'</span>
    <span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/db/fixtures/*.yml'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span>
      Fixtures.<span style="color:#9900CC;">create_fixtures</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'db/fixtures'</span>, <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>file, <span style="color:#996600;">'.*'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Et voilà&nbsp;! Les données sont chargées avec la commande <strong>rake db:seed</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/rails-chargement-des-donnees-initiales-dans-la-base-de-donnees/176/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Localisation de Ruby on Rails</title>
		<link>http://www.6502.fr/localisation-de-ruby-on-rails/172</link>
		<comments>http://www.6502.fr/localisation-de-ruby-on-rails/172#comments</comments>
		<pubDate>Sun, 14 Sep 2008 21:45:00 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[l10n]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=172</guid>
		<description><![CDATA[Je suis en train de traduire les fichiers de régionalisation (l10n, de l&#8217;anglais localization) de l&#8217;application de démonstration de Clemens Kofler. L&#8217;internationalisation de Rails sera intégrée dans la version 2.2 qui est prévue pour la fin de l&#8217;année]]></description>
			<content:encoded><![CDATA[<p>Je suis en train de traduire les fichiers de régionalisation (<a title="Internationalisation de logiciel sur Wikipedia" href="http://fr.wikipedia.org/wiki/L10n">l10n</a>, de l&#8217;anglais <em>localization</em>) de l&#8217;<a title="Application de démonstration l10n et i18n [multilingue]" href="http://localhost:3000/">application de démonstration</a> de <a title="Blog de Clemens Kofler [en anglais]" href="http://www.railway.at/">Clemens Kofler</a>.</p>
<p>L&#8217;<a title="The Ruby on Rails I18n core api [en anglais]" href="http://www.artweb-design.de/2008/7/18/the-ruby-on-rails-i18n-core-api">internationalisation</a> de Rails sera intégrée dans la version 2.2 qui est prévue pour la fin de l&#8217;année</p>
]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/localisation-de-ruby-on-rails/172/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Une commande Ubiquity pour accéder directement à l&#8217;API Ruby</title>
		<link>http://www.6502.fr/commande-ubiquity-acces-direct-api-ruby/166</link>
		<comments>http://www.6502.fr/commande-ubiquity-acces-direct-api-ruby/166#comments</comments>
		<pubDate>Fri, 12 Sep 2008 10:02:33 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Outils]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ubiquity]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=166</guid>
		<description><![CDATA[Jack Dempsey a créé une commande Ubiquity pour accéder directement à l&#8217;API Ruby sur APIdock. Vous pouvez l&#8217;installer en collant le code dans l&#8217;éditeur de commandes Ubiquity. ou en vous abonnant (le bouton apparaît en haut à droite du bandeau). L&#8217;utilisation est simple : invoquer Ubiquity (alt-espace sur mon Mac), taper ruby &#60;nom-de-fonction&#62; puis &#60;Enter&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Profil de Jack Dempsey sur Github [anglais]" href="http://github.com/jackdempsey">Jack Dempsey</a> a créé une <a title="ruby-search.ubiquity-command.js [javascript]" href="http://gist.github.com/8132">commande Ubiquity</a> pour accéder directement à l&#8217;API Ruby sur <a title="APIdock [anglais]" href="http://apidock.com/">APIdock</a>. Vous pouvez l&#8217;installer en collant le code dans l&#8217;<a title="Éditeur de commande Ubiquity [Firefox local]" href="chrome://ubiquity/content/editor.html">éditeur de commandes Ubiquity</a>. ou en vous abonnant (le bouton apparaît en haut à droite du bandeau).</p>
<p>L&#8217;utilisation est simple : invoquer Ubiquity (alt-espace sur mon Mac), taper <code>ruby &lt;nom-de-fonction&gt;</code> puis &lt;Enter&gt; et la page s&#8217;ouvre dans un nouvel onglet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/commande-ubiquity-acces-direct-api-ruby/166/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test fixture pour le plugin acts_as_authenticated</title>
		<link>http://www.6502.fr/test-fixture-pour-acts_as_authenticated/143</link>
		<comments>http://www.6502.fr/test-fixture-pour-acts_as_authenticated/143#comments</comments>
		<pubDate>Wed, 10 Sep 2008 16:36:47 +0000</pubDate>
		<dc:creator>Christian</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[acts_as_authenticated]]></category>
		<category><![CDATA[fixture]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://www.6502.fr/?p=143</guid>
		<description><![CDATA[Écrire des fixtures n&#8217;est généralement pas compliqué (je ne parle pas de maintenance ici). Les champs cryptés posent néanmoins un problème particulier, ne serait-ce que celui de trouver la bonne fonction de cryptage. Dans le cas du plugin acts_as_authenticated, voici la démarche à suivre. Méthode Nous voulons un salt raisonnable. Nous l&#8217;obtenons donc sur random.org. [...]]]></description>
			<content:encoded><![CDATA[<p>Écrire des fixtures n&#8217;est généralement pas compliqué (je ne parle pas de maintenance ici). Les champs cryptés posent néanmoins un problème particulier, ne serait-ce que celui de trouver la bonne fonction de cryptage. Dans le cas du plugin <em>acts_as_authenticated</em>, voici la démarche à suivre.</p>
<h3>Méthode</h3>
<p>Nous voulons un salt raisonnable. Nous l&#8217;obtenons donc sur <a href="http://random.org/integers/?num=8&#038;min=0&#038;max=65535&#038;col=8&#038;base=16&#038;format=plain&#038;rnd=new">random.org</a>. J&#8217;ai obtenu <strong>1290 9d9c 16f8 5fad d3b5 a11f 2fb9 f358</strong> que je recopie dans le champ <em>salt</em> (sans les espaces).</p>
<p>Pour encrypter le mot de passe <strong>SourceStuff</strong>, nous lançons la console et nous cryptons avec Digest::SHA1. Le résultat est bien sûr recopié dans le champ <em>crypted_password</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">xtian$ .<span style="color:#006600; font-weight:bold;">/</span>script<span style="color:#006600; font-weight:bold;">/</span>console 
Loading development environment <span style="color:#006600; font-weight:bold;">&#40;</span>Rails 2.1.0<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#6666ff; font-weight:bold;">Digest::SHA1</span>.<span style="color:#9900CC;">hexdigest</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;--12909d9c16f85fadd3b5a11f2fb9f358--SourceStuff--&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;843a3ec693ba69e5f09ba4554f0d0799c979b93c&quot;</span></pre></div></div>

<p>Euh&#8230; bien sûr vous remplacez le salt et le mot de passe par les votres?. Dois-je le dire&nbsp;?</p>
<h3>Résultat</h3>

<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">ErikSink:
  login: eric
  email: eric@softwarelegend.com
  salt: 12909d9c16f85fadd3b5a11f2fb9f358
  crypted_password: 843a3ec693ba69e5f09ba4554f0d0799c979b93c</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.6502.fr/test-fixture-pour-acts_as_authenticated/143/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
