<?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>42 &#187; model</title>
	<atom:link href="http://www.42.mach7x.com/tag/model/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.42.mach7x.com</link>
	<description>Thoughts and tips about programming with Ruby on Rails</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:38:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Testing associations in Rspec</title>
		<link>http://www.42.mach7x.com/2011/07/22/testing-associations-in-rspec/</link>
		<comments>http://www.42.mach7x.com/2011/07/22/testing-associations-in-rspec/#comments</comments>
		<pubDate>Fri, 22 Jul 2011 09:06:15 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[RSpec]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[belons_to]]></category>
		<category><![CDATA[has_many]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/?p=373</guid>
		<description><![CDATA[Problem You would like to test your model associations in an RSpec model spec, to make sure that they are correctly set up. Solution After some Google searching and coming across this article here, ended up using the second method described there with the reflect_on_association method, as it doesn&#8217;t need the inclusion of another gem. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong><br />
You would like to test your model associations in an RSpec model spec, to make sure that they are correctly set up.</p>
<p><strong>Solution</strong><br />
After some Google searching and coming across this article <a href="http://liahhansen.com/2011/04/14/testing-model-associations-in-rspec.html">here</a>, ended up using the second method described there with the reflect_on_association method, as it doesn&#8217;t need the inclusion of another gem.<br />
So for example to to test multiple has_many or belongs_to associations in your model rspec you could use something like:<br />
<code>context "check associations" do<br />
    # belongs_to associations<br />
    %w{bel_to1 bel_to2}.each do |bt|<br />
      it "should belong to #{bt}" do<br />
        m = Model.reflect_on_association(:"#{bt}")<br />
        m.macro.should == :belongs_to<br />
      end<br />
    end<br />
    # has_many associations<br />
    %w{has_many1 has_many2 has_many3}.each do |hm|<br />
      it "should have many #{hm}" do<br />
        m = Model.reflect_on_association(:"#{hm}")<br />
        m.macro.should == :has_many<br />
      end<br />
    end<br />
  end</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2011/07/22/testing-associations-in-rspec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ArgumentError (3 elements of civil date are necessary)</title>
		<link>http://www.42.mach7x.com/2007/12/03/argumenterror-3-elements-of-civil-date-are-necessary/</link>
		<comments>http://www.42.mach7x.com/2007/12/03/argumenterror-3-elements-of-civil-date-are-necessary/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 15:25:57 +0000</pubDate>
		<dc:creator>kosmas</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[Date]]></category>
		<category><![CDATA[Date.civil]]></category>
		<category><![CDATA[model]]></category>

		<guid isPermaLink="false">http://www.42.mach7x.com/2007/12/03/argumenterror-3-elements-of-civil-date-are-necessary/</guid>
		<description><![CDATA[Problem On creating a default date on a model using the after create, and by using Model.date_field = &#8217;2007-01-01&#8242; we get the error ArgumentError (3 elements of civil date are necessary) Solution The workaround is to use: Model.date_field = Date.civil(2007,01,01)]]></description>
			<content:encoded><![CDATA[<p><b>Problem</b><br />
On creating a default date on a model using the after create, and by using <i>Model.date_field = &#8217;2007-01-01&#8242;</i> we get the error <i> ArgumentError (3 elements of civil date are necessary)</i></p>
<p><b>Solution</b><br />
The workaround is to use:</p>
<pre class="code">
Model.date_field = Date.civil(2007,01,01)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.42.mach7x.com/2007/12/03/argumenterror-3-elements-of-civil-date-are-necessary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

