Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floehopper/346819 to your computer and use it in GitHub Desktop.
Save floehopper/346819 to your computer and use it in GitHub Desktop.
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