diff --git a/app/models/create_enterprise.rb b/app/models/create_enterprise.rb
index 4d467ae..60e6a56 100644
--- a/app/models/create_enterprise.rb
+++ b/app/models/create_enterprise.rb
@@ -1,5 +1,16 @@
class CreateEnterprise < Task
+ N_('CreateEnterprise|Identifier')
+ N_('CreateEnterprise|Name')
+ N_('CreateEnterprise|Address')
+ N_('CreateEnterprise|Contact phone')
+ N_('CreateEnterprise|Contact person')
+ N_('CreateEnterprise|Acronym')
+ N_('CreateEnterprise|Foundation year')
+ N_('CreateEnterprise|Legal form')
+ N_('CreateEnterprise|Economic activity')
+ N_('CreateEnterprise|Management information')
+
DATA_FIELDS = %w[ name identifier address contact_phone contact_person acronym foundation_year legal_form economic_activity management_information region_id ]
serialize :data, Hash
diff --git a/app/models/organization.rb b/app/models/organization.rb
index 7d3e518..26d8a60 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -1,15 +1,18 @@
# Represents any organization of the system and has an organization_info object to hold its info
class Organization < Profile
has_one :organization_info
- has_many :validated_enterprises, :class_name => 'enterprise'
belongs_to :region
-# def info
-# organization_info
-# end
+ has_one :validation_info
-# def info=(infos)
-# organization_info.update_attributes(infos)
-# end
+ def validation_methodology
+ methodology = self.validation_info ? self.validation_info.validation_methodology : nil
+ methodology || ('' + _('(not informed)') + '')
+ end
+
+ def validation_restrictions
+ restrictions = self.validation_info ? self.validation_info.restrictions : nil
+ restrictions || ('' + _('(not informed)') + '')
+ end
end
diff --git a/app/models/validation_info.rb b/app/models/validation_info.rb
new file mode 100644
index 0000000..04c132a
--- /dev/null
+++ b/app/models/validation_info.rb
@@ -0,0 +1,5 @@
+class ValidationInfo < ActiveRecord::Base
+ validates_presence_of :validation_methodology
+
+ belongs_to :organization
+end
diff --git a/app/models/validator.rb b/app/models/validator.rb
deleted file mode 100644
index efb4c8f..0000000
--- a/app/models/validator.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-class Validator
- include ActiveRecord::Validations
- def new_record?
- true
- end
-end
diff --git a/app/views/enterprise_registration/select_validator.rhtml b/app/views/enterprise_registration/select_validator.rhtml
index a874dc5..98ec126 100644
--- a/app/views/enterprise_registration/select_validator.rhtml
+++ b/app/views/enterprise_registration/select_validator.rhtml
@@ -11,6 +11,9 @@
<%= radio_button_tag('create_enterprise[target_id]', validator.id) %>
<%= validator.name %>
+
+ <%= labelled_form_field(_('Validation Methodology:'), validator.validation_methodology) %>
+ <%= labelled_form_field(_('Restrictions (if any):'), validator.validation_restrictions) %>
<% end %>
diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml
index ad0aa13..3b7c1c5 100644
--- a/app/views/layouts/application.rhtml
+++ b/app/views/layouts/application.rhtml
@@ -5,7 +5,7 @@
<%= javascript_include_tag 'prototype' %>
<%# javascript_include_tag 'sweetTitles' %>
<%= javascript_include_tag 'tiny_mce/tiny_mce.js' %>
- <%= javascript_include_tag 'scriptaculous' %>
+ <%# javascript_include_tag 'scriptaculous' %>
<%= javascript_include_tag 'dragdrop' %>
<%= javascript_include_tag 'effects' %>
<%= javascript_include_tag 'noosfero_tiny_mce.js' %>
diff --git a/db/migrate/015_create_validation_infos.rb b/db/migrate/015_create_validation_infos.rb
new file mode 100644
index 0000000..a73cd18
--- /dev/null
+++ b/db/migrate/015_create_validation_infos.rb
@@ -0,0 +1,15 @@
+class CreateValidationInfos < ActiveRecord::Migration
+ def self.up
+ create_table :validation_infos do |t|
+ t.column :validation_methodology, :text
+ t.column :restrictions, :text
+
+ # foreign keys
+ t.column :organization_id, :integer
+ end
+ end
+
+ def self.down
+ drop_table :validation_infos
+ end
+end
diff --git a/public/stylesheets/menu.css b/public/stylesheets/menu.css
index 469c7ca..8a52675 100644
--- a/public/stylesheets/menu.css
+++ b/public/stylesheets/menu.css
@@ -22,7 +22,7 @@
#accessibility_menu a {
padding-left: 9px;
margin-left: 5px;
- background: url("../images/ico_enterlink.gif");
+ /* background: url("../images/ico_enterlink.gif"); */
background-repeat: no-repeat;
background-position: 0px 6px;
color: #dfdfdf;
diff --git a/script/anhetegua b/script/anhetegua
index e17090e..f607a29 100644
--- a/script/anhetegua
+++ b/script/anhetegua
@@ -2,6 +2,7 @@
require File.dirname(__FILE__) + '/../config/environment'
Environment.default.categories.destroy_all
+Organization.destroy_all
def new_category(parent, name, color = nil)
category = Environment.default.categories.build(:name => name, :display_color => color, :parent_id => (parent ? parent.id: nil))
@@ -15,6 +16,14 @@ def new_region(parent, name, color = nil)
region
end
+def new_validator(region, name, identifier)
+ org = Organization.new(:name => name, :identifier => identifier)
+ org.validation_info = ValidationInfo.new(:validation_methodology => 'some methodology we don\'t care about')
+ org.save!
+ region.validators << org
+ org
+end
+
tematicas = new_category(nil, 'Temáticas', 1)
new_category(tematicas, 'Finanças Solidárias')
new_category(tematicas, 'Marco Legal')
@@ -29,14 +38,13 @@ cadeias = new_category(nil, 'Cadeias', 3)
new_category(cadeias, 'Algodão')
new_category(cadeias, 'Tecnologia de Informação')
-
# validators
-ba.validators << Organization.create!(:name => "Colivre", :identifier => 'colivre')
-ba.validators << Organization.create!(:name => "Forum Baiano de Economia Solidaraia", :identifier => 'ecosolbahia')
+new_validator(ba, "Colivre", 'colivre')
+new_validator(ba, "Forum Baiano de Economia Solidaraia", 'ecosolbahia')
-df.validators << Organization.create!(:name => 'Caritas', :identifier => 'caritas')
-df.validators << Organization.create!(:name => 'Forum Brasileiro de Economia Solidaria', :identifier => 'fbes')
+new_validator(df, 'Caritas', 'caritas')
+new_validator(df, 'Forum Brasileiro de Economia Solidaria', 'fbes')
-rs.validators << Organization.create!(:name => 'Associacao Software Livre.Org', :identifier => 'asl')
-rs.validators << Organization.create!(:name => 'Forum Gaucho de Economia Solidaria', :identifier => 'ecosolrs')
+new_validator(rs, 'Associacao Software Livre.Org', 'asl')
+new_validator(rs, 'Forum Gaucho de Economia Solidaria', 'ecosolrs')
diff --git a/test/integration/enterprise_registration_test.rb b/test/integration/enterprise_registration_test.rb
new file mode 100644
index 0000000..45d16fe
--- /dev/null
+++ b/test/integration/enterprise_registration_test.rb
@@ -0,0 +1,51 @@
+require "#{File.dirname(__FILE__)}/../test_helper"
+
+class EnterpriseRegistrationTest < ActionController::IntegrationTest
+
+ fixtures :users, :profiles, :environments
+
+ # Replace this with your real tests.
+ should 'be able to create an enterprise registration request' do
+
+ environment = Environment.default
+ region1 = environment.regions.build(:name => 'A region')
+ region1.save!
+ region2 = environment.regions.build(:name => 'Other region')
+ region2.save!
+ org = Organization.create!(:name => "My organization", :identifier => 'myorg')
+ region1.validators << org
+
+ login('ze', 'test')
+
+ get '/enterprise_registration'
+ assert_response :success
+ assert_tag :tag => 'form', :attributes => { :action => '/enterprise_registration', :method => 'post' }, :descendant => { :tag => 'input', :attributes => { :type => 'text', :name => 'create_enterprise[identifier]'} }
+
+ data = {
+ :name => 'My new enterprise',
+ :identifier => 'mynewenterprise',
+ :address => 'satan street, 666',
+ :contact_phone => '1298372198',
+ :contact_person => 'random joe',
+ :legal_form => 'cooperative',
+ :economic_activity => 'free software',
+ :region_id => region1.id,
+ }
+
+ post '/enterprise_registration', :create_enterprise => data
+ assert_response :success
+ assert_tag :tag => 'form', :attributes => { :action => '/enterprise_registration', :method => 'post' }, :descendant => { :tag => 'input', :attributes => { :type => 'radio', :name => 'create_enterprise[target_id]', :value => org.id } }
+
+ assert_difference CreateEnterprise, :count do
+ post '/enterprise_registration', :create_enterprise => data.merge(:target_id => org.id)
+ end
+
+ assert_tag :tag => 'a', :attributes => { :href => '/' }
+
+ # FIXME: add here
+ # - the steps carried on by the validator organization to approve the registration
+ # - the steps carried on by the requestor after that
+
+ end
+
+end
diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb
index d05c0a7..7297ced 100644
--- a/test/unit/organization_test.rb
+++ b/test/unit/organization_test.rb
@@ -3,8 +3,54 @@ require File.dirname(__FILE__) + '/../test_helper'
class OrganizationTest < Test::Unit::TestCase
fixtures :profiles
- # FIXME: add actual organization tests here
- def test_truth
- assert_not_nil Organization.new
+ should 'reference organization info' do
+ org = Organization.new
+ assert_raise ActiveRecord::AssociationTypeMismatch do
+ org.organization_info = 1
+ end
+ assert_nothing_raised do
+ org.organization_info = OrganizationInfo.new
+ end
end
+
+ should 'reference region' do
+ org = Organization.new
+ assert_raise ActiveRecord::AssociationTypeMismatch do
+ org.region = 1
+ end
+ assert_nothing_raised do
+ org.region = Region.new
+ end
+ end
+
+ should 'reference validation info' do
+ org = Organization.new
+ assert_raise ActiveRecord::AssociationTypeMismatch do
+ org.validation_info = 1
+ end
+ assert_nothing_raised do
+ org.validation_info = ValidationInfo.new
+ end
+ end
+
+ should 'provide validation methodology' do
+ org = Organization.new
+ assert_equal '(not informed)', org.validation_methodology
+
+ info = ValidationInfo.new
+ info.expects(:validation_methodology).returns('something')
+ org.validation_info = info
+ assert_equal 'something', org.validation_methodology
+ end
+
+ should 'provide validation restrictions' do
+ org = Organization.new
+ assert_equal '(not informed)', org.validation_restrictions
+
+ info = ValidationInfo.new
+ info.expects(:restrictions).returns('something')
+ org.validation_info = info
+ assert_equal 'something', org.validation_restrictions
+ end
+
end
diff --git a/test/unit/validation_info_test.rb b/test/unit/validation_info_test.rb
new file mode 100644
index 0000000..301a912
--- /dev/null
+++ b/test/unit/validation_info_test.rb
@@ -0,0 +1,24 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class ValidationInfoTest < Test::Unit::TestCase
+
+ should 'validate the presence of validation methodology description' do
+ info = ValidationInfo.new
+ info.valid?
+ assert info.errors.invalid?(:validation_methodology)
+ info.validation_methodology = 'lalala'
+ info.valid?
+ assert !info.errors.invalid?(:validation_methodology)
+ end
+
+ should 'refer to and validate the presence of an organization' do
+ info = ValidationInfo.new
+ assert_raise ActiveRecord::AssociationTypeMismatch do
+ info.organization = 1
+ end
+ assert_nothing_raised do
+ info.organization = Organization.new
+ end
+ end
+
+end
--
libgit2 0.21.2