Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Created OrganizationManager model. An Organization has_many :organiza…

…tion_managers
  • Loading branch information...
commit 5bd8026f1469bdce2809f99a4b69c176e3b2a9e4 1 parent 657f558
@cthielen cthielen authored
View
3  app/models/organization.rb
@@ -18,6 +18,9 @@ class Organization < ActiveRecord::Base
has_many :organization_entity_associations
has_many :entities, :through => :organization_entity_associations
+ has_many :organization_managers
+ has_many :managers, :through => :organization_managers
+
# Returns all people associated with this organization and all organizations within
# the children trees. Does _not_ include members of groups associated with any of
# those organizations by design.
View
19 app/models/organization_manager.rb
@@ -0,0 +1,19 @@
+class OrganizationManager < ActiveRecord::Base
+ attr_accessible :manager_id, :organization_id
+
+ belongs_to :organization, :touch => true
+ belongs_to :manager, :class_name => 'Entity', :touch => true
+
+ validates_presence_of :organization_id, :manager_id
+ validates_uniqueness_of :manager_id, :scope => [:organization_id]
+
+ validate :manager_entity_is_a_person
+
+ private
+
+ def manager_entity_is_a_person
+ if manager.type != 'Person'
+ errors[:base] << "Organization manager must be a Person"
+ end
+ end
+end
View
2  config/initializers/last_updated.rb
@@ -1 +1 @@
-LAST_UPDATED = 'Thu Feb 27 09:46:17 PST 2014'
+LAST_UPDATED = 'Thu Feb 27 10:21:32 PST 2014'
View
10 db/migrate/20140227181541_create_organization_managers.rb
@@ -0,0 +1,10 @@
+class CreateOrganizationManagers < ActiveRecord::Migration
+ def change
+ create_table :organization_managers do |t|
+ t.integer :organization_id
+ t.integer :manager_id
+
+ t.timestamps
+ end
+ end
+end
View
6 db/migrate/20140227181618_add_indicies_to_organization_manager_table.rb
@@ -0,0 +1,6 @@
+class AddIndiciesToOrganizationManagerTable < ActiveRecord::Migration
+ def change
+ add_index :organization_managers, :organization_id
+ add_index :organization_managers, :manager_id
+ end
+end
View
12 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20140214015018) do
+ActiveRecord::Schema.define(:version => 20140227181618) do
create_table "affiliation_assignments", :force => true do |t|
t.integer "affiliation_id"
@@ -206,6 +206,16 @@
t.integer "title_id"
end
+ create_table "organization_managers", :force => true do |t|
+ t.integer "organization_id"
+ t.integer "manager_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "organization_managers", ["manager_id"], :name => "index_organization_managers_on_manager_id"
+ add_index "organization_managers", ["organization_id"], :name => "index_organization_managers_on_organization_id"
+
create_table "organization_org_ids", :force => true do |t|
t.integer "organization_id"
t.string "org_id"
View
9 test/fixtures/organization_managers.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ organization_id: 1
+ manager_id: 1
+
+two:
+ organization_id: 1
+ manager_id: 1
View
7 test/unit/organization_manager_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class OrganizationManagerTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.