Created
September 13, 2011 00:10
-
-
Save brenes/1212838 to your computer and use it in GitHub Desktop.
Weird bug (or something I just don't get) on ActiveRecord relationships
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # WikiPage(id: integer, title: string, fetched_at: date, created_at: datetime, updated_at: datetime, ancestry: string, url: string, is_root: boolean, wiki_tree_id: integer) | |
| # The whole code is at https://github.com/brenes/Wiki-Roots | |
| class WikiPage < ActiveRecord::Base | |
| belongs_to :tree, :class_name => "WikiTree" | |
| # ... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "spec_helper.rb" | |
| describe WikiPage do | |
| describe "when a page belongs to a tree" do | |
| it "should.. you know... belong" do | |
| page = WikiPage.create! :title => 'The page' | |
| tree = WikiTree.create! :name => 'The tree' | |
| page.wiki_tree_id = tree.id | |
| page.save! | |
| assert_equal WikiPage.first.tree, WikiTree.find(WikiPage.first.wiki_tree_id), "WTF!" | |
| # It fails as WikiPage.first.tree is nil !!! | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment