Created
March 28, 2010 15:57
-
-
Save floehopper/346819 to your computer and use it in GitHub Desktop.
This file contains 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 CreateOrganizations < ActiveRecord::Migration | |
def self.up | |
create_table :organizations do |t| | |
end | |
end | |
end | |
class CreateChurches < ActiveRecord::Migration | |
def self.up | |
create_table :churches do |t| | |
t.integer :organization_id | |
t.string :name | |
end | |
end | |
end | |
class Organization < ActiveRecord::Base | |
has_one :church | |
accepts_nested_attributes_for :church | |
end | |
class Church < ActiveRecord::Base | |
validates_presence_of :name | |
end | |
class OrganizationTest < ActiveSupport::TestCase | |
test "should not be valid when associated church is not valid" do | |
errors = ActiveRecord::Errors.new(:name => 'message') | |
Church.any_instance.stubs(:errors).returns(errors) | |
organization = Organization.new(:church_attributes => { :name => 'name' }) | |
assert !organization.valid? | |
end | |
test "should be valid when associated church is valid" do | |
organization = Organization.new(:church_attributes => { :name => 'name' }) | |
assert organization.valid? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment