public
Fork of drnic/ruby-on-rails-tmbundle
Description: Ruby on Rails TextMate bundle [master branch is svn trunk; patches to drnicwilliams@gmail.com]
Homepage: http://macromates.com
Clone URL: git://github.com/Infininight/ruby-on-rails-tmbundle.git
Finished up demo of migrations
lawrencepit (author)
Wed Feb 27 23:11:36 -0800 2008
commit  be7941b6ba3687b02512fecd4182c548222cd856
tree    8089ce4f3ef4e0877a6966a87feb6abf54f4d266
parent  ec86db637aaa118ad9442a03a6e1fea5f630a83c
...
908
909
910
911
 
912
913
914
...
948
949
950
951
 
952
953
954
...
957
958
959
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
960
961
962
...
908
909
910
 
911
912
913
914
...
948
949
950
 
951
952
953
954
...
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
0
@@ -908,7 +908,7 @@ and then view them as a blog visitor at <a href="http://localhost:3000/blog">htt
0
   <p>Notice how the <code>down</code> method calls are in reversed order of the <code>up</code> method calls.</p>
0
 
0
 
0
- <p>Save the file (&#x2318; S) and migrate to current (&#x2303; |, option 3).</p>
0
+ <p>Save the file (&#x2318; S) and migrate to current (&#x2303; |).</p>
0
 
0
 
0
   <p>Be sure to modify the comments fixture file. Go there (&#x2318; T, press <code>cy</code>, choose <code>comments.yml</code>). Rename <code>name</code> to <code>author</code> and add a row for <code>author_url</code> for each comment. Check your tests again (&#x2303; \, choose option 1). All tests should pass.</p>
0
@@ -948,7 +948,7 @@ and then view them as a blog visitor at <a href="http://localhost:3000/blog">htt
0
   <p>Notice how the <code>Remove / Add Column</code> command automagically determined in the <code>down</code> method the column type of column <code>published</code> to be a <code>boolean</code>. It determines this by looking at the current state of your <code>db/schema.rb</code> file.</p>
0
 
0
 
0
- <p>Save the file (&#x2318; S) and migrate to current (&#x2303; |, option 3).</p>
0
+ <p>Save the file (&#x2318; S) and migrate to current (&#x2303; |).</p>
0
 
0
 
0
   <p>Now we need to modify the posts fixtures file. Go there (&#x2318; T, type <code>pyml</code>, choose <code>posts.yml</code>). Replace the line <code>published: true</code> by <code>published_at: 2008-1-1</code>.</p>
0
@@ -957,6 +957,32 @@ and then view them as a blog visitor at <a href="http://localhost:3000/blog">htt
0
   <p>Modify the posts functional test, first go there (&#x21E7; &#x2325; &#x2318; &#x2193;, choose &#8220;Go to Functional Test&#8221;). Replace <code>:published =&gt; '1'</code> by <code>:published_at =&gt; Date.new(2008, 1, 1)</code>.</p>
0
 
0
 
0
+ <p>Modify the post model, first go there (&#x21E7; &#x2325; &#x2318; &#x2193;, choose &#8220;Go to Model&#8221;). Have the code look like:</p>
0
+
0
+
0
+ <p><pre class='syntax'><span class="keyword">class </span><span class="class">Post</span> <span class="punct">&lt;</span> <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span>
0
+ <span class="ident">has_many</span> <span class="symbol">:comments</span>
0
+
0
+ <span class="keyword">def </span><span class="method">published</span>
0
+ <span class="punct">!</span><span class="constant">self</span><span class="punct">.</span><span class="ident">published_at</span><span class="punct">.</span><span class="ident">nil?</span>
0
+ <span class="keyword">end</span>
0
+
0
+ <span class="keyword">def </span><span class="method">published=</span><span class="punct">(</span><span class="ident">publish</span><span class="punct">)</span>
0
+ <span class="keyword">if</span> <span class="ident">publish</span>
0
+ <span class="constant">self</span><span class="punct">.</span><span class="ident">published_at</span> <span class="punct">=</span> <span class="constant">DateTime</span><span class="punct">.</span><span class="ident">now</span> <span class="keyword">if</span> <span class="constant">self</span><span class="punct">.</span><span class="ident">published_at</span><span class="punct">.</span><span class="ident">nil?</span>
0
+ <span class="keyword">else</span>
0
+ <span class="constant">self</span><span class="punct">.</span><span class="ident">published_at</span> <span class="punct">=</span> <span class="constant">nil</span>
0
+ <span class="keyword">end</span>
0
+ <span class="keyword">end</span>
0
+<span class="keyword">end</span></pre></p>
0
+
0
+
0
+ <p>Modify the <code>blog_controller.rb</code> file. Replace <code>Post.find_all_by_published(true)</code> by <code>Post.find(:all, :conditions =&gt; "published_at IS NOT NULL")</code>.</p>
0
+
0
+
0
+ <p>Finally, check your tests again (&#x2303; \). All tests should pass.</p>
0
+
0
+
0
   <h1><span class="caps">TODO</span></h1>
0
 
0
 
...
672
673
674
675
 
676
677
678
...
701
702
703
704
 
705
706
707
708
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709
710
711
...
672
673
674
 
675
676
677
678
...
701
702
703
 
704
705
706
707
 
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
0
@@ -672,7 +672,7 @@ end</pre>
0
 
0
 Notice how the <code>down</code> method calls are in reversed order of the <code>up</code> method calls.
0
 
0
-Save the file (COMMAND S) and migrate to current (CONTROL |, option 3).
0
+Save the file (COMMAND S) and migrate to current (CONTROL |).
0
 
0
 Be sure to modify the comments fixture file. Go there (COMMAND T, press <code>cy</code>, choose <code>comments.yml</code>). Rename <code>name</code> to <code>author</code> and add a row for <code>author_url</code> for each comment. Check your tests again (CONTROL \, choose option 1). All tests should pass.
0
                       
0
@@ -701,11 +701,34 @@ end</pre>
0
 
0
 Notice how the <code>Remove / Add Column</code> command automagically determined in the <code>down</code> method the column type of column <code>published</code> to be a <code>boolean</code>. It determines this by looking at the current state of your <code>db/schema.rb</code> file.
0
                                
0
-Save the file (COMMAND S) and migrate to current (CONTROL |, option 3).
0
+Save the file (COMMAND S) and migrate to current (CONTROL |).
0
 
0
 Now we need to modify the posts fixtures file. Go there (COMMAND T, type <code>pyml</code>, choose <code>posts.yml</code>). Replace the line <code>published: true</code> by <code>published_at: 2008-1-1</code>.
0
 
0
-Modify the posts functional test, first go there (SHIFT OPTION COMMAND DOWN, choose "Go to Functional Test"). Replace <code>:published => '1'</code> by <code>:published_at => Date.new(2008, 1, 1)</code>.
0
+Modify the posts functional test, first go there (SHIFT OPTION COMMAND DOWN, choose "Go to Functional Test"). Replace <code>:published => '1'</code> by <code>:published_at => Date.new(2008, 1, 1)</code>.
0
+
0
+Modify the post model, first go there (SHIFT OPTION COMMAND DOWN, choose "Go to Model"). Have the code look like:
0
+
0
+<pre syntax="ruby">class Post < ActiveRecord::Base
0
+ has_many :comments
0
+
0
+ def published
0
+ !self.published_at.nil?
0
+ end
0
+
0
+ def published=(publish)
0
+ if publish
0
+ self.published_at = DateTime.now if self.published_at.nil?
0
+ else
0
+ self.published_at = nil
0
+ end
0
+ end
0
+end</pre>
0
+
0
+Modify the <code>blog_controller.rb</code> file. Replace <code>Post.find_all_by_published(true)</code> by <code>Post.find(:all, :conditions => "published_at IS NOT NULL")</code>.
0
+
0
+Finally, check your tests again (CONTROL \). All tests should pass.
0
+
0
 
0
 h1. TODO
0
 

Comments

    No one has commented yet.