Commit ede05a1fafc0de428d532c7f5e5276200da1e709
Committed by
Joenio Costa
1 parent
14c18eaa
Exists in
master
and in
29 other branches
Enterprises with wrong environments
* CreateEnterprise#environment uses the requestor environment as the requestor is always required. * Migration to fix the enterprises with wrong environments. (ActionItem1555)
Showing
9 changed files
with
77 additions
and
13 deletions
Show diff stats
app/controllers/public/enterprise_registration_controller.rb
... | ... | @@ -16,9 +16,9 @@ class EnterpriseRegistrationController < ApplicationController |
16 | 16 | @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) |
17 | 17 | end |
18 | 18 | elsif @validation == :admin || @validation == :none |
19 | - @create_enterprise.target = @create_enterprise.environment | |
19 | + @create_enterprise.target = environment | |
20 | 20 | end |
21 | - @create_enterprise.requestor = current_user.person | |
21 | + @create_enterprise.requestor = user | |
22 | 22 | the_action = |
23 | 23 | if request.post? |
24 | 24 | if @create_enterprise.valid_before_selecting_target? | ... | ... |
app/models/create_enterprise.rb
db/migrate/20100730141134_set_owner_environment_to_enterprises_environment.rb
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +class SetOwnerEnvironmentToEnterprisesEnvironment < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + CreateEnterprise.find_all_by_status(3).each do |t| | |
4 | + if(Enterprise.find_by_identifier(t.data[:identifier])) | |
5 | + update("UPDATE profiles SET environment_id = '%s' WHERE identifier = '%s'" % | |
6 | + [Person.find(t.requestor_id).environment.id, t.data[:identifier]]) | |
7 | + end | |
8 | + end | |
9 | + end | |
10 | + | |
11 | + def self.down | |
12 | + say "this migration can't be reverted" | |
13 | + end | |
14 | +end | ... | ... |
db/schema.rb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | # |
10 | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | |
12 | -ActiveRecord::Schema.define(:version => 20100722020357) do | |
12 | +ActiveRecord::Schema.define(:version => 20100730141134) do | |
13 | 13 | |
14 | 14 | create_table "article_versions", :force => true do |t| |
15 | 15 | t.integer "article_id" | ... | ... |
features/register_enterprise.feature
... | ... | @@ -5,8 +5,8 @@ Feature: register enterprise |
5 | 5 | |
6 | 6 | Background: |
7 | 7 | Given the following users |
8 | - | login | name | | |
9 | - | joaosilva | Joao Silva | | |
8 | + | login | name | email | | |
9 | + | joaosilva | Joao Silva | joaosilva@example.com | | |
10 | 10 | |
11 | 11 | And I am logged in as "joaosilva" |
12 | 12 | And I am on Joao Silva's control panel |
... | ... | @@ -80,22 +80,24 @@ Feature: register enterprise |
80 | 80 | Scenario: a user register an enterprise successfully through the admin |
81 | 81 | validator method and the admin accepts |
82 | 82 | Given organization_approval_method is "admin" on environment |
83 | + And the mailbox is empty | |
83 | 84 | And I follow "Manage my groups" |
84 | 85 | And the following states |
85 | 86 | | name | |
86 | 87 | | Sample State | |
87 | 88 | And I follow "Register a new enterprise" |
88 | 89 | And I fill in the following: |
89 | - | Address | my-enterprise | | |
90 | - | Name | My Enterprise | | |
90 | + | Address | my-enterprise | | |
91 | + | Name | My Enterprise | | |
91 | 92 | And I press "Next" |
92 | 93 | Then I should see "Enterprise registration completed" |
93 | 94 | And I am logged in as admin |
94 | 95 | And I follow "Control panel" |
95 | 96 | When I follow "Tasks" |
96 | 97 | Then I should see /Processing task: Enterprise registration: "My Enterprise"/ |
97 | - And I choose "Ok" | |
98 | + And the first mail is to admin_user@example.com | |
98 | 99 | And I press "Ok" |
100 | + Then the last mail is to joaosilva@example.com | |
99 | 101 | And I am logged in as "joaosilva" |
100 | 102 | And I am on Joao Silva's control panel |
101 | 103 | When I follow "Manage my groups" |
... | ... | @@ -104,23 +106,26 @@ Feature: register enterprise |
104 | 106 | Scenario: a user register an enterprise successfully through the admin |
105 | 107 | validator method and the admin rejects |
106 | 108 | Given organization_approval_method is "admin" on environment |
109 | + And the mailbox is empty | |
107 | 110 | And I follow "Manage my groups" |
108 | 111 | And the following states |
109 | 112 | | name | |
110 | 113 | | Sample State | |
111 | 114 | And I follow "Register a new enterprise" |
112 | 115 | And I fill in the following: |
113 | - | Address | my-enterprise | | |
114 | - | Name | My Enterprise | | |
116 | + | Address | my-enterprise | | |
117 | + | Name | My Enterprise | | |
115 | 118 | And I press "Next" |
116 | 119 | Then I should see "Enterprise registration completed" |
117 | 120 | And I am logged in as admin |
118 | 121 | And I follow "Control panel" |
119 | 122 | When I follow "Tasks" |
120 | 123 | Then I should see /Processing task: Enterprise registration: "My Enterprise"/ |
124 | + And the first mail is to admin_user@example.com | |
121 | 125 | And I choose "Cancel" |
122 | 126 | And I fill in "Rejection explanation" with "This enterprise has some irregularities." |
123 | - And I press "Ok" | |
127 | + When I press "Ok" | |
128 | + Then the last mail is to joaosilva@example.com | |
124 | 129 | And I am logged in as "joaosilva" |
125 | 130 | And I am on Joao Silva's control panel |
126 | 131 | When I follow "Manage my groups" | ... | ... |
features/step_definitions/noosfero_steps.rb
... | ... | @@ -205,3 +205,24 @@ end |
205 | 205 | Then /^The page title should contain "(.*)"$/ do |text| |
206 | 206 | response.should have_selector("title:contains('#{text}')") |
207 | 207 | end |
208 | + | |
209 | +Given /^the mailbox is empty$/ do | |
210 | + ActionMailer::Base.deliveries = [] | |
211 | +end | |
212 | + | |
213 | +Given /^the (.+) mail (?:is|has) (.+) (.+)$/ do |position, field, value| | |
214 | + if(/^[0-9]+$/ =~ position) | |
215 | + ActionMailer::Base.deliveries[position.to_i][field] == value | |
216 | + else | |
217 | + ActionMailer::Base.deliveries.send(position)[field] == value | |
218 | + end | |
219 | +end | |
220 | + | |
221 | +Given /^the (.+) mail (.+) is like (.+)$/ do |position, field, regexp| | |
222 | + re = Regexp.new(regexp) | |
223 | + if(/^[0-9]+$/ =~ position) | |
224 | + re =~ ActionMailer::Base.deliveries[position.to_i][field.to_sym] | |
225 | + else | |
226 | + re =~ ActionMailer::Base.deliveries.send(position)[field.to_sym] | |
227 | + end | |
228 | +end | ... | ... |
test/functional/enterprise_registration_controller_test.rb
... | ... | @@ -170,4 +170,14 @@ all_fixtures |
170 | 170 | assert_no_tag :tag => 'option', :content => "Region without validator" |
171 | 171 | end |
172 | 172 | |
173 | + should 'set current environment as the task target if approval method is admin' do | |
174 | + environment = Environment.new(:name => "Another environment") | |
175 | + environment.organization_approval_method = :admin | |
176 | + environment.save | |
177 | + @controller.stubs(:environment).returns(environment) | |
178 | + | |
179 | + get :index | |
180 | + assert_equal assigns(:create_enterprise).target, environment | |
181 | + end | |
182 | + | |
173 | 183 | end | ... | ... |
test/functional/enterprise_validation_controller_test.rb
... | ... | @@ -74,6 +74,7 @@ class EnterpriseValidationControllerTest < Test::Unit::TestCase |
74 | 74 | |
75 | 75 | should 'require the user to fill in the explanation for an rejection' do |
76 | 76 | validation = CreateEnterprise.new |
77 | + validation.stubs(:environment).returns(Environment.default) | |
77 | 78 | @org.expects(:find_pending_validation).with('kakakaka').returns(validation) |
78 | 79 | |
79 | 80 | # FIXME: this is not working, but should. Anyway the assert_response and | ... | ... |
test/unit/create_enterprise_test.rb
... | ... | @@ -13,6 +13,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
13 | 13 | |
14 | 14 | should 'accept only numbers as foundation year' do |
15 | 15 | task = CreateEnterprise.new |
16 | + task.stubs(:environment).returns(Environment.default) | |
16 | 17 | |
17 | 18 | task.foundation_year = "test" |
18 | 19 | task.valid? |
... | ... | @@ -25,6 +26,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
25 | 26 | |
26 | 27 | should 'require a requestor' do |
27 | 28 | task = CreateEnterprise.new |
29 | + task.stubs(:environment).returns(Environment.default) | |
28 | 30 | task.valid? |
29 | 31 | |
30 | 32 | assert task.errors.invalid?(:requestor_id) |
... | ... | @@ -35,6 +37,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
35 | 37 | |
36 | 38 | should 'require a target (validator organization)' do |
37 | 39 | task = CreateEnterprise.new |
40 | + task.stubs(:environment).returns(Environment.default) | |
38 | 41 | task.valid? |
39 | 42 | |
40 | 43 | assert task.errors.invalid?(:target_id) |
... | ... | @@ -50,6 +53,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
50 | 53 | validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
51 | 54 | |
52 | 55 | task = CreateEnterprise.new |
56 | + task.stubs(:environment).returns(Environment.default) | |
53 | 57 | |
54 | 58 | task.region = region |
55 | 59 | task.target = validator |
... | ... | @@ -71,6 +75,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
71 | 75 | |
72 | 76 | should 'require an explanation for rejecting enterprise creation' do |
73 | 77 | task = CreateEnterprise.new |
78 | + task.stubs(:environment).returns(Environment.default) | |
74 | 79 | task.reject_explanation = nil |
75 | 80 | |
76 | 81 | task.valid? |
... | ... | @@ -98,6 +103,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
98 | 103 | validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
99 | 104 | region.validators << validator |
100 | 105 | person = create_user('testuser').person |
106 | + person.environment = environment | |
107 | + person.save | |
101 | 108 | |
102 | 109 | task = CreateEnterprise.create!({ |
103 | 110 | :name => 'My new enterprise', |
... | ... | @@ -132,6 +139,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
132 | 139 | validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
133 | 140 | region.validators << validator |
134 | 141 | person = create_user('testuser').person |
142 | + person.environment = environment | |
143 | + person.save | |
135 | 144 | |
136 | 145 | task = CreateEnterprise.create!({ |
137 | 146 | :name => 'My new enterprise', |
... | ... | @@ -161,6 +170,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
161 | 170 | |
162 | 171 | should 'override message methods from Task' do |
163 | 172 | specific = CreateEnterprise.new |
173 | + specific.stubs(:environment).returns(Environment.default) | |
164 | 174 | %w[ task_created_message task_finished_message task_cancelled_message ].each do |method| |
165 | 175 | assert_nothing_raised NotImplementedError do |
166 | 176 | specific.send(method) |
... | ... | @@ -193,7 +203,9 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
193 | 203 | end |
194 | 204 | |
195 | 205 | should 'provide a message to be sent to the target' do |
196 | - assert_not_nil CreateEnterprise.new.target_notification_message | |
206 | + task = CreateEnterprise.new | |
207 | + task.stubs(:environment).returns(Environment.default) | |
208 | + assert_not_nil task.target_notification_message | |
197 | 209 | end |
198 | 210 | |
199 | 211 | should 'report as approved when approved' do |
... | ... | @@ -210,6 +222,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase |
210 | 222 | |
211 | 223 | should 'refuse to create an enterprise creation request with an identifier already used by another profile' do |
212 | 224 | request = CreateEnterprise.new |
225 | + request.stubs(:environment).returns(Environment.default) | |
213 | 226 | request.identifier = 'testid' |
214 | 227 | request.valid? |
215 | 228 | assert !request.errors.invalid?(:identifier) | ... | ... |