Created
June 24, 2012 10:18
-
-
Save jeffrafter/2982727 to your computer and use it in GitHub Desktop.
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
| class Center < ActiveRecord::Base | |
| belongs_to :thing | |
| validates :thing_id, :presence => true | |
| 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
| class Thing < ActiveRecord::Base | |
| has_many :centers | |
| has_one :default_center, :class_name => 'Center', :conditions => ['centers.default = ?', true] | |
| accepts_nested_attributes_for :default_center | |
| 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
| describe "default_centers" do | |
| fit "should create a default center with nested attributes" do | |
| params = HashWithIndifferentAccess.new({ | |
| "thing"=>{ | |
| "default_center_attributes"=>{ | |
| "name"=>"Very very good sample name", | |
| "default" => true | |
| } | |
| }) | |
| thing = Thing.create!(params[:thing]) | |
| thing.should be_valid | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment