From c8b1aabb3ab0b973f2de3f0898e3d63380d8ebc2 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Mon, 30 Jul 2007 19:38:01 +0000 Subject: [PATCH] ActionItem6: pending enterprises is now shown --- app/controllers/enterprise_controller.rb | 3 ++- app/models/person.rb | 4 ++-- app/models/profile.rb | 4 +--- app/views/enterprise/index.rhtml | 10 ++++++---- test/fixtures/affiliations.yml | 2 ++ 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/controllers/enterprise_controller.rb b/app/controllers/enterprise_controller.rb index 23a1209..878ce98 100644 --- a/app/controllers/enterprise_controller.rb +++ b/app/controllers/enterprise_controller.rb @@ -5,6 +5,7 @@ class EnterpriseController < ApplicationController def index @enterprises = Enterprise.find(:all) - @my_enterprises + @pending_enterprises = current_user.person.my_enterprises(false) end def register_form @@ -21,7 +22,7 @@ class EnterpriseController < ApplicationController redirect_to :action => 'index' else flash[:notice] = _('Enterprise was not created') - render :action => 'register' + render :action => 'register_form' end end diff --git a/app/models/person.rb b/app/models/person.rb index ab05ec6..dde7c9d 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -9,7 +9,7 @@ class Person < Profile has_many :other_friendships has_many :other_friend, :class_name => 'Person', :through => :other_friendships, :foreign_key => 'friend_id' - def my_enterprises - related_profiles.select{ |p| p.kind_of?(Enterprise) } + def my_enterprises(status = true) + related_profiles.find(:all, :conditions => ['type = ? and active = ?', 'Enterprise', status]) end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 055cbc9..2ce2434 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -45,9 +45,7 @@ class Profile < ActiveRecord::Base # A profile_owner cannot have more than one profile, but many profiles can exist # without being associated to a particular user. - validates_uniqueness_of :user_id, :if => (lambda do |profile| - ! profile.user_id.nil? - end) + validates_uniqueness_of :user_id, :allow_nil =>true # creates a new Profile. By default, it is attached to the default # VirtualCommunity (see VirtualCommunity#default), unless you tell it diff --git a/app/views/enterprise/index.rhtml b/app/views/enterprise/index.rhtml index 1d47945..25fd449 100644 --- a/app/views/enterprise/index.rhtml +++ b/app/views/enterprise/index.rhtml @@ -4,7 +4,9 @@ <%= render :partial => 'enterprise', :collection => @my_enterprises %> -

<%= _('Listing pending enterprises') %>

- +<% unless @pending_enterprises.blank? %> +

<%= _('Listing pending enterprises') %>

+ +<% end %> diff --git a/test/fixtures/affiliations.yml b/test/fixtures/affiliations.yml index b49c4eb..6fb3987 100644 --- a/test/fixtures/affiliations.yml +++ b/test/fixtures/affiliations.yml @@ -1,5 +1,7 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html one: id: 1 + person_id: 4 + profile_id: 5 two: id: 2 -- libgit2 0.21.2