diff --git a/app/controllers/public/enterprise_registration_controller.rb b/app/controllers/public/enterprise_registration_controller.rb index 289bee4..4804491 100644 --- a/app/controllers/public/enterprise_registration_controller.rb +++ b/app/controllers/public/enterprise_registration_controller.rb @@ -16,9 +16,9 @@ class EnterpriseRegistrationController < ApplicationController @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) end elsif @validation == :admin || @validation == :none - @create_enterprise.target = @create_enterprise.environment + @create_enterprise.target = environment end - @create_enterprise.requestor = current_user.person + @create_enterprise.requestor = user the_action = if request.post? if @create_enterprise.valid_before_selecting_target? diff --git a/app/models/create_enterprise.rb b/app/models/create_enterprise.rb index 36d7c86..f5ecfa4 100644 --- a/app/models/create_enterprise.rb +++ b/app/models/create_enterprise.rb @@ -91,7 +91,7 @@ class CreateEnterprise < Task end def environment - region ? region.environment : self.requestor ? self.requestor.environment : Environment.default + requestor.environment end def available_regions diff --git a/db/migrate/20100730141134_set_owner_environment_to_enterprises_environment.rb b/db/migrate/20100730141134_set_owner_environment_to_enterprises_environment.rb new file mode 100644 index 0000000..625be71 --- /dev/null +++ b/db/migrate/20100730141134_set_owner_environment_to_enterprises_environment.rb @@ -0,0 +1,14 @@ +class SetOwnerEnvironmentToEnterprisesEnvironment < ActiveRecord::Migration + def self.up + CreateEnterprise.find_all_by_status(3).each do |t| + if(Enterprise.find_by_identifier(t.data[:identifier])) + update("UPDATE profiles SET environment_id = '%s' WHERE identifier = '%s'" % + [Person.find(t.requestor_id).environment.id, t.data[:identifier]]) + end + end + end + + def self.down + say "this migration can't be reverted" + end +end diff --git a/db/schema.rb b/db/schema.rb index e287b35..be31aa4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20100722020357) do +ActiveRecord::Schema.define(:version => 20100730141134) do create_table "article_versions", :force => true do |t| t.integer "article_id" diff --git a/features/register_enterprise.feature b/features/register_enterprise.feature index 3425bcf..f906388 100644 --- a/features/register_enterprise.feature +++ b/features/register_enterprise.feature @@ -5,8 +5,8 @@ Feature: register enterprise Background: Given the following users - | login | name | - | joaosilva | Joao Silva | + | login | name | email | + | joaosilva | Joao Silva | joaosilva@example.com | And I am logged in as "joaosilva" And I am on Joao Silva's control panel @@ -80,22 +80,24 @@ Feature: register enterprise Scenario: a user register an enterprise successfully through the admin validator method and the admin accepts Given organization_approval_method is "admin" on environment + And the mailbox is empty And I follow "Manage my groups" And the following states | name | | Sample State | And I follow "Register a new enterprise" And I fill in the following: - | Address | my-enterprise | - | Name | My Enterprise | + | Address | my-enterprise | + | Name | My Enterprise | And I press "Next" Then I should see "Enterprise registration completed" And I am logged in as admin And I follow "Control panel" When I follow "Tasks" Then I should see /Processing task: Enterprise registration: "My Enterprise"/ - And I choose "Ok" + And the first mail is to admin_user@example.com And I press "Ok" + Then the last mail is to joaosilva@example.com And I am logged in as "joaosilva" And I am on Joao Silva's control panel When I follow "Manage my groups" @@ -104,23 +106,26 @@ Feature: register enterprise Scenario: a user register an enterprise successfully through the admin validator method and the admin rejects Given organization_approval_method is "admin" on environment + And the mailbox is empty And I follow "Manage my groups" And the following states | name | | Sample State | And I follow "Register a new enterprise" And I fill in the following: - | Address | my-enterprise | - | Name | My Enterprise | + | Address | my-enterprise | + | Name | My Enterprise | And I press "Next" Then I should see "Enterprise registration completed" And I am logged in as admin And I follow "Control panel" When I follow "Tasks" Then I should see /Processing task: Enterprise registration: "My Enterprise"/ + And the first mail is to admin_user@example.com And I choose "Cancel" And I fill in "Rejection explanation" with "This enterprise has some irregularities." - And I press "Ok" + When I press "Ok" + Then the last mail is to joaosilva@example.com And I am logged in as "joaosilva" And I am on Joao Silva's control panel When I follow "Manage my groups" diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index f779e1f..736707a 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -205,3 +205,24 @@ end Then /^The page title should contain "(.*)"$/ do |text| response.should have_selector("title:contains('#{text}')") end + +Given /^the mailbox is empty$/ do + ActionMailer::Base.deliveries = [] +end + +Given /^the (.+) mail (?:is|has) (.+) (.+)$/ do |position, field, value| + if(/^[0-9]+$/ =~ position) + ActionMailer::Base.deliveries[position.to_i][field] == value + else + ActionMailer::Base.deliveries.send(position)[field] == value + end +end + +Given /^the (.+) mail (.+) is like (.+)$/ do |position, field, regexp| + re = Regexp.new(regexp) + if(/^[0-9]+$/ =~ position) + re =~ ActionMailer::Base.deliveries[position.to_i][field.to_sym] + else + re =~ ActionMailer::Base.deliveries.send(position)[field.to_sym] + end +end diff --git a/test/functional/enterprise_registration_controller_test.rb b/test/functional/enterprise_registration_controller_test.rb index 1adc76c..e78eab9 100644 --- a/test/functional/enterprise_registration_controller_test.rb +++ b/test/functional/enterprise_registration_controller_test.rb @@ -170,4 +170,14 @@ all_fixtures assert_no_tag :tag => 'option', :content => "Region without validator" end + should 'set current environment as the task target if approval method is admin' do + environment = Environment.new(:name => "Another environment") + environment.organization_approval_method = :admin + environment.save + @controller.stubs(:environment).returns(environment) + + get :index + assert_equal assigns(:create_enterprise).target, environment + end + end diff --git a/test/functional/enterprise_validation_controller_test.rb b/test/functional/enterprise_validation_controller_test.rb index f048fcd..c804bd5 100644 --- a/test/functional/enterprise_validation_controller_test.rb +++ b/test/functional/enterprise_validation_controller_test.rb @@ -74,6 +74,7 @@ class EnterpriseValidationControllerTest < Test::Unit::TestCase should 'require the user to fill in the explanation for an rejection' do validation = CreateEnterprise.new + validation.stubs(:environment).returns(Environment.default) @org.expects(:find_pending_validation).with('kakakaka').returns(validation) # FIXME: this is not working, but should. Anyway the assert_response and diff --git a/test/unit/create_enterprise_test.rb b/test/unit/create_enterprise_test.rb index ff07a25..67e2e4c 100644 --- a/test/unit/create_enterprise_test.rb +++ b/test/unit/create_enterprise_test.rb @@ -13,6 +13,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'accept only numbers as foundation year' do task = CreateEnterprise.new + task.stubs(:environment).returns(Environment.default) task.foundation_year = "test" task.valid? @@ -25,6 +26,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'require a requestor' do task = CreateEnterprise.new + task.stubs(:environment).returns(Environment.default) task.valid? assert task.errors.invalid?(:requestor_id) @@ -35,6 +37,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'require a target (validator organization)' do task = CreateEnterprise.new + task.stubs(:environment).returns(Environment.default) task.valid? assert task.errors.invalid?(:target_id) @@ -50,6 +53,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) task = CreateEnterprise.new + task.stubs(:environment).returns(Environment.default) task.region = region task.target = validator @@ -71,6 +75,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'require an explanation for rejecting enterprise creation' do task = CreateEnterprise.new + task.stubs(:environment).returns(Environment.default) task.reject_explanation = nil task.valid? @@ -98,6 +103,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) region.validators << validator person = create_user('testuser').person + person.environment = environment + person.save task = CreateEnterprise.create!({ :name => 'My new enterprise', @@ -132,6 +139,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) region.validators << validator person = create_user('testuser').person + person.environment = environment + person.save task = CreateEnterprise.create!({ :name => 'My new enterprise', @@ -161,6 +170,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'override message methods from Task' do specific = CreateEnterprise.new + specific.stubs(:environment).returns(Environment.default) %w[ task_created_message task_finished_message task_cancelled_message ].each do |method| assert_nothing_raised NotImplementedError do specific.send(method) @@ -193,7 +203,9 @@ class CreateEnterpriseTest < Test::Unit::TestCase end should 'provide a message to be sent to the target' do - assert_not_nil CreateEnterprise.new.target_notification_message + task = CreateEnterprise.new + task.stubs(:environment).returns(Environment.default) + assert_not_nil task.target_notification_message end should 'report as approved when approved' do @@ -210,6 +222,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'refuse to create an enterprise creation request with an identifier already used by another profile' do request = CreateEnterprise.new + request.stubs(:environment).returns(Environment.default) request.identifier = 'testid' request.valid? assert !request.errors.invalid?(:identifier) -- libgit2 0.21.2