Created
June 17, 2013 09:31
-
-
Save eval/5795759 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
# Source: https://gist.github.com/neerajdotname/5187092 | |
#gem 'activerecord', '4.0.0.rc2' | |
gem 'activerecord', '3.2.13' | |
require 'active_record' | |
require "minitest/autorun" | |
require 'minitest/pride' | |
require 'logger' | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :notices, force: true do |t| | |
t.string :title | |
end | |
create_table :entity_roles, force: true do |t| | |
t.string :name | |
t.integer :notice_id | |
t.integer :entity_id | |
end | |
create_table :entities, force: true do |t| | |
t.string :name, :address | |
end | |
end | |
class Notice < ActiveRecord::Base | |
has_many :entity_roles | |
has_many :entities, through: :entity_roles | |
end | |
class EntityRole < ActiveRecord::Base | |
belongs_to :entity | |
belongs_to :notice | |
end | |
class Entity < ActiveRecord::Base | |
has_many :entity_roles | |
has_many :notices, through: :entity_roles | |
end | |
class TestInitializingRole < MiniTest::Unit::TestCase | |
def setup | |
@notice = Notice.new | |
end | |
def test_initialize_role | |
@notice.entity_roles(name: 'role1').build.build_entity | |
assert '', @notice.entity_roles.first.name | |
end | |
def test_initialize_role2 | |
@notice.entity_roles.build(name: 'role1').build_entity | |
assert 'role1', @notice.entity_roles.first.name | |
end | |
def teardown | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment