Commit 3aa65efa4647e9fddfa80a79aca5b6d479f98d26
1 parent
bafa8c0d
Exists in
master
and in
28 other branches
ActionItem629: merging 0.10.x commits
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2393 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
15 changed files
with
307 additions
and
146 deletions
Show diff stats
app/controllers/public/account_controller.rb
... | ... | @@ -13,17 +13,17 @@ class AccountController < PublicController |
13 | 13 | def login |
14 | 14 | @user = User.new |
15 | 15 | return unless request.post? |
16 | - self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) | |
16 | + self.current_user = User.authenticate(params[:user][:login], params[:user][:password]) if params[:user] | |
17 | 17 | if logged_in? |
18 | 18 | if params[:remember_me] == "1" |
19 | 19 | self.current_user.remember_me |
20 | 20 | cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } |
21 | 21 | end |
22 | - go_to_user_initial_page | |
22 | + go_to_user_initial_page if redirect? | |
23 | 23 | flash[:notice] = _("Logged in successfully") |
24 | 24 | else |
25 | 25 | flash[:notice] = _('Incorrect username or password') |
26 | - redirect_to :back | |
26 | + redirect_to :back if redirect? | |
27 | 27 | end |
28 | 28 | end |
29 | 29 | |
... | ... | @@ -32,6 +32,7 @@ class AccountController < PublicController |
32 | 32 | end |
33 | 33 | |
34 | 34 | def login_popup |
35 | + @user = User.new | |
35 | 36 | render :action => 'login', :layout => false |
36 | 37 | end |
37 | 38 | |
... | ... | @@ -41,25 +42,18 @@ class AccountController < PublicController |
41 | 42 | @user = User.new(params[:user]) |
42 | 43 | @user.terms_of_use = environment.terms_of_use |
43 | 44 | @terms_of_use = environment.terms_of_use |
44 | - if request.post? && params[self.icaptcha_field].blank? && answer_correct | |
45 | + if request.post? && params[self.icaptcha_field].blank? | |
45 | 46 | @user.save! |
46 | 47 | @user.person.environment = environment |
47 | 48 | @user.person.save! |
48 | 49 | self.current_user = @user |
49 | 50 | owner_role = Role.find_by_name('owner') |
50 | 51 | @user.person.affiliate(@user.person, [owner_role]) if owner_role |
51 | - post_activate_enterprise if params[:enterprise_code] | |
52 | - go_to_user_initial_page | |
52 | + go_to_user_initial_page if redirect? | |
53 | 53 | flash[:notice] = _("Thanks for signing up!") |
54 | - else | |
55 | - activate_enterprise if params[:enterprise_code] | |
56 | 54 | end |
57 | 55 | rescue ActiveRecord::RecordInvalid |
58 | - if params[:enterprise_code] | |
59 | - render :action => 'activate_enterprise' | |
60 | - else | |
61 | - render :action => 'signup' | |
62 | - end | |
56 | + render :action => 'signup' | |
63 | 57 | end |
64 | 58 | end |
65 | 59 | |
... | ... | @@ -128,47 +122,87 @@ class AccountController < PublicController |
128 | 122 | end |
129 | 123 | end |
130 | 124 | |
131 | - protected | |
132 | - | |
133 | - def activate_enterprise | |
134 | - enterprise = load_enterprise | |
135 | - @enterprise = enterprise | |
136 | - | |
137 | - unless enterprise | |
125 | + def activation_question | |
126 | + @enterprise = load_enterprise | |
127 | + unless @enterprise | |
138 | 128 | render :action => 'invalid_enterprise_code' |
139 | 129 | return |
140 | 130 | end |
141 | - | |
142 | - if enterprise.enabled | |
131 | + if @enterprise.enabled | |
143 | 132 | render :action => 'already_activated' |
144 | 133 | return |
145 | 134 | end |
146 | - | |
147 | - # Reaches here only if answer is not correct | |
148 | - if request.post? && !answer_correct | |
149 | - enterprise.block | |
150 | - end | |
151 | 135 | |
152 | - @question = enterprise.question | |
153 | - | |
154 | - if !@question || enterprise.blocked? | |
136 | + @question = @enterprise.question | |
137 | + if !@question || @enterprise.blocked? | |
155 | 138 | render :action => 'blocked' |
156 | 139 | return |
157 | 140 | end |
141 | + end | |
158 | 142 | |
159 | - render :action => 'activate_enterprise' | |
143 | + def accept_terms | |
144 | + @enterprise = load_enterprise | |
145 | + @question = @enterprise.question | |
146 | + check_answer | |
147 | + @terms_of_enterprise_use = environment.terms_of_enterprise_use | |
160 | 148 | end |
161 | 149 | |
162 | - def post_activate_enterprise | |
150 | + def activate_enterprise | |
151 | + @enterprise = load_enterprise | |
152 | + @question = @enterprise.question | |
153 | + return unless check_answer | |
154 | + return unless check_acceptance_of_terms | |
155 | + load_user | |
156 | + | |
163 | 157 | activation = load_enterprise_activation |
164 | - if activation | |
158 | + if activation && user | |
165 | 159 | activation.requestor = user |
166 | 160 | activation.finish |
161 | + redirect_to :controller => 'profile_editor', :action => 'index', :profile => @enterprise.identifier | |
162 | + end | |
163 | + end | |
164 | + | |
165 | + protected | |
166 | + | |
167 | + def redirect? | |
168 | + !@cannot_redirect | |
169 | + end | |
170 | + | |
171 | + def no_redirect | |
172 | + @cannot_redirect = true | |
173 | + end | |
174 | + | |
175 | + def load_user | |
176 | + unless logged_in? | |
177 | + no_redirect | |
178 | + if params[:new_user] | |
179 | + signup | |
180 | + else | |
181 | + login | |
182 | + end | |
183 | + end | |
184 | + true | |
185 | + end | |
186 | + | |
187 | + def check_answer | |
188 | + unless answer_correct | |
189 | + @enterprise.block | |
190 | + render :action => 'blocked' | |
191 | + return | |
192 | + end | |
193 | + true | |
194 | + end | |
195 | + | |
196 | + def check_acceptance_of_terms | |
197 | + unless params[:terms_accepted] | |
198 | + redirect_to :action => 'index' | |
199 | + return | |
167 | 200 | end |
201 | + true | |
168 | 202 | end |
169 | 203 | |
170 | 204 | def load_enterprise_activation |
171 | - EnterpriseActivation.find_by_code(params[:enterprise_code]) | |
205 | + @enterprise_activation ||= EnterpriseActivation.find_by_code(params[:enterprise_code]) | |
172 | 206 | end |
173 | 207 | |
174 | 208 | def load_enterprise | ... | ... |
app/controllers/public/search_controller.rb
... | ... | @@ -195,7 +195,7 @@ class SearchController < ApplicationController |
195 | 195 | [ |
196 | 196 | [ :people, _('People'), @finder.recent('people', limit) ], |
197 | 197 | [ :enterprises, __('Enterprises'), @finder.recent('enterprises', limit) ], |
198 | - [ :products, ('Products'), @finder.recent('products', limit) ], | |
198 | + [ :products, _('Products'), @finder.recent('products', limit) ], | |
199 | 199 | [ :events, _('Upcoming events'), @finder.upcoming_events({:per_page => limit}) ], |
200 | 200 | [ :communities, __('Communities'), @finder.recent('communities', limit) ], |
201 | 201 | [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles(limit) ], | ... | ... |
app/models/environment.rb
... | ... | @@ -136,6 +136,23 @@ class Environment < ActiveRecord::Base |
136 | 136 | ! self.settings['terms_of_use'].nil? |
137 | 137 | end |
138 | 138 | |
139 | + # the environment's terms of enterprise use: every enterprise member must accept them before | |
140 | + # registering or activating enterprises. | |
141 | + def terms_of_enterprise_use | |
142 | + self.settings['terms_of_enterprise_use'] | |
143 | + end | |
144 | + | |
145 | + # sets the environment's terms of enterprise use. | |
146 | + def terms_of_enterprise_use=(value) | |
147 | + self.settings['terms_of_enterprise_use'] = value | |
148 | + end | |
149 | + | |
150 | + # returns <tt>true</tt> if this Environment has terms of enterprise use to be | |
151 | + # accepted by users before registration or activation of enterprises. | |
152 | + def has_terms_of_enterprise_use? | |
153 | + ! self.settings['terms_of_enterprise_use'].blank? | |
154 | + end | |
155 | + | |
139 | 156 | def message_for_disabled_enterprise |
140 | 157 | self.settings['message_for_disabled_enterprise'] |
141 | 158 | end | ... | ... |
app/models/environment_statistics_block.rb
... | ... | @@ -15,8 +15,8 @@ class EnvironmentStatisticsBlock < Block |
15 | 15 | |
16 | 16 | info = [ |
17 | 17 | n_('One user', '%{num} users', users) % { :num => users }, |
18 | - n__('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises }, | |
19 | - n__('One community', '%{num} communities', communities) % { :num => communities }, | |
18 | + n_('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises }, | |
19 | + n_('One community', '%{num} communities', communities) % { :num => communities }, | |
20 | 20 | ] |
21 | 21 | |
22 | 22 | block_title(title) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +<% labelled_form_for :user, @user, | |
2 | + :url => { :controller => 'account', :action => 'login' }, | |
3 | + :html => { :help => _('If you are a registered user, enter your username and password to be authenticated.')+'<p/>'+_('To join on this environment, click on "<b>I want to be an user!</b>".')+'<p/>'+_('If you forgot your password, click on "<b>I forgot my password!</b>" link.') } do |f| %> | |
4 | + | |
5 | +<%= f.text_field :login, | |
6 | + :id => ( lightbox? ? 'lightbox_' : '' ) + 'user_login', | |
7 | + :help => _('Here goes the nickname that you give on the registration.'), | |
8 | + :onchange => 'this.value = convToValidLogin( this.value )' %> | |
9 | + | |
10 | +<%= f.password_field :password, | |
11 | + :id => ( lightbox? ? 'lightbox_' : '' ) + 'user_password', | |
12 | + :help => _('your password is personal, protect it.') %> | |
13 | + | |
14 | +<% button_bar do %> | |
15 | + <%= submit_button( 'login', _('Log in') )%> | |
16 | + <%= lightbox_close_button(_('Cancel')) if lightbox? %> | |
17 | +<% end %> | |
18 | + | |
19 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,42 @@ |
1 | +<h1><%= _('Register') %></h1> | |
2 | + | |
3 | +<%= error_messages_for :user %> | |
4 | +<% labelled_form_for :user, @user, | |
5 | + :html => { :help=>_('Fill all this fields to join in this environment.' + | |
6 | + '<p/>If you forgot your password, do not create a new account,' + | |
7 | + ' click on the "<b>I forgot my password!</b>" link. ;-)') | |
8 | + } do |f| -%> | |
9 | + | |
10 | +<%= f.text_field :login, | |
11 | + :help => help=_('"Username" is a simple nickname to recognize you on this environment.'), | |
12 | + :onchange => 'this.value = convToValidLogin( this.value )' %> | |
13 | +<small><%= help %></small> | |
14 | + | |
15 | +<%= f.text_field :email, | |
16 | + :help => help=_('We\'ll send you an e-mail to validate your registration.') %> | |
17 | +<small><%= help %></small> | |
18 | + | |
19 | +<%= f.password_field :password, | |
20 | + :help => help=_('Do not use a obviously password, but try some unforgettable word.') %> | |
21 | +<small><%= help %></small> | |
22 | + | |
23 | +<%= f.password_field :password_confirmation, | |
24 | + :help => help=_('We need to be sure that you wrote correctly your password.') %> | |
25 | +<small><%= help %></small> | |
26 | + | |
27 | +<%= icaptcha_field() %> | |
28 | + | |
29 | +<% if @terms_of_use %> | |
30 | + <p> | |
31 | + <%= @terms_of_use %> | |
32 | + </p> | |
33 | + <p> | |
34 | + <%= check_box 'user', 'terms_accepted' %> | |
35 | + <%= _('I accept the terms of use') %> | |
36 | + </p> | |
37 | +<% end %> | |
38 | + | |
39 | +<% button_bar do %> | |
40 | + <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> | |
41 | +<% end %> | |
42 | +<% end -%> | ... | ... |
... | ... | @@ -0,0 +1,6 @@ |
1 | +<div id='terms-of-enterprise-use'><%= @terms_of_enterprise_use %></div> | |
2 | + | |
3 | +<% button_bar do %> | |
4 | + <%= button_to(_('I accept the terms'), {:action => 'activate_enterprise', :terms_accepted => true, :enterprise_code => params[:enterprise_code], :answer => params[:answer]} ) %> | |
5 | + <%= button_to(_('I do NOT accept the terms'), {:controller => 'home', :action => 'index'} ) %> | |
6 | +<% end %> | ... | ... |
app/views/account/activate_enterprise.rhtml
1 | -<h1><%= _('Register and activate enterprise') %></h1> | |
1 | +<h1><%= _('What user should be the admin of the enterprise page') %></h1> | |
2 | 2 | |
3 | 3 | <%= error_messages_for :user %> |
4 | -<% labelled_form_for :user, @user, | |
5 | - :html => { :help=>_('Fill all this fields to activate your enterprise and join in this environment.' + | |
6 | - '<p/>If you forgot your password, do not create a new account,' + | |
7 | - ' click on the "<b>I forgot my password!</b>" link. ;-)') | |
8 | - } do |f| -%> | |
9 | 4 | |
10 | -<%= f.text_field :login, | |
11 | - :help => help=_('"Username" is a simple nickname to recognize you on this environment.'), | |
12 | - :onchange => 'this.value = convToValidLogin( this.value )' %> | |
13 | -<small><%= help %></small> | |
5 | +<div id="enterprise-activation-create-user-or-login-button"> | |
6 | + <%= link_to_function _('Already have user') %> | |
7 | + <%= link_to_function _('Create new user') %> | |
8 | +</div> | |
14 | 9 | |
15 | -<%= f.text_field :email, | |
16 | - :help => help=_('We\'ll send you an e-mail to validate your registration.') %> | |
17 | -<small><%= help %></small> | |
10 | +<div id="enterprise-activation-create-user-form"> | |
11 | + <%= render :partial => 'signup_form' %> | |
12 | +</div> | |
18 | 13 | |
19 | -<%= f.password_field :password, | |
20 | - :help => help=_('Do not use a obviously password, but try some unforgettable word.') %> | |
21 | -<small><%= help %></small> | |
22 | - | |
23 | -<%= f.password_field :password_confirmation, | |
24 | - :help => help=_('We need to be sure that you wrote correctly your password.') %> | |
25 | -<small><%= help %></small> | |
26 | - | |
27 | -<%= ApplicationHelper::NoosferoFormBuilder::output_field(@question == :foundation_year ? _('What year your enterprise was founded?') : _('What is the CNPJ of your enterprise?'), text_field_tag(:answer, nil,:help => help=_('We need to be sure that this is your enterprise'))) %> | |
28 | - | |
29 | -<%= hidden_field_tag :enterprise_code, params[:enterprise_code] %> | |
30 | - | |
31 | -<% if @terms_of_use %> | |
32 | - <p> | |
33 | - <%= @terms_of_use %> | |
34 | - </p> | |
35 | - <p> | |
36 | - <%= check_box 'user', 'terms_accepted' %> | |
37 | - <%= _('I accept the terms of use') %> | |
38 | - </p> | |
39 | -<% end %> | |
40 | - | |
41 | -<% button_bar do %> | |
42 | - <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> | |
43 | -<% end %> | |
44 | -<% end -%> | |
14 | +<div id="enterprise-activation-login-form"> | |
15 | + <%= render :partial => 'login_form' %> | |
16 | +</div> | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | +<% form_tag :action => 'accept_terms' do %> | |
2 | + | |
3 | + <%= ApplicationHelper::NoosferoFormBuilder::output_field(@question == :foundation_year ? _('What year your enterprise was founded?') : _('What is the CNPJ of your enterprise?'), text_field_tag(:answer, nil,:help => help=_('We need to be sure that this is your enterprise'))) %> | |
4 | + | |
5 | + <%= hidden_field_tag :enterprise_code, params[:enterprise_code] %> | |
6 | + | |
7 | + <% button_bar do %> | |
8 | + <%= submit_button('answer', _('Answer'), :cancel => {:action => 'index'} ) %> | |
9 | + <% end %> | |
10 | +<% end %> | ... | ... |
app/views/account/login.rhtml
app/views/account/signup.rhtml
1 | -<h1><%= _('Register') %></h1> | |
2 | - | |
3 | -<%= error_messages_for :user %> | |
4 | -<% labelled_form_for :user, @user, | |
5 | - :html => { :help=>_('Fill all this fields to join in this environment.' + | |
6 | - '<p/>If you forgot your password, do not create a new account,' + | |
7 | - ' click on the "<b>I forgot my password!</b>" link. ;-)') | |
8 | - } do |f| -%> | |
9 | - | |
10 | -<%= f.text_field :login, | |
11 | - :help => help=_('"Username" is a simple nickname to recognize you on this environment.'), | |
12 | - :onchange => 'this.value = convToValidLogin( this.value )' %> | |
13 | -<small><%= help %></small> | |
14 | - | |
15 | -<%= f.text_field :email, | |
16 | - :help => help=_('We\'ll send you an e-mail to validate your registration.') %> | |
17 | -<small><%= help %></small> | |
18 | - | |
19 | -<%= f.password_field :password, | |
20 | - :help => help=_('Do not use a obviously password, but try some unforgettable word.') %> | |
21 | -<small><%= help %></small> | |
22 | - | |
23 | -<%= f.password_field :password_confirmation, | |
24 | - :help => help=_('We need to be sure that you wrote correctly your password.') %> | |
25 | -<small><%= help %></small> | |
26 | - | |
27 | -<%= icaptcha_field() %> | |
28 | - | |
29 | -<% if @terms_of_use %> | |
30 | - <p> | |
31 | - <%= @terms_of_use %> | |
32 | - </p> | |
33 | - <p> | |
34 | - <%= check_box 'user', 'terms_accepted' %> | |
35 | - <%= _('I accept the terms of use') %> | |
36 | - </p> | |
37 | -<% end %> | |
38 | - | |
39 | -<% button_bar do %> | |
40 | - <%= submit_button('save', _('Sign up'), :cancel => {:action => 'index'}, :class => 'icon-menu-login') %> | |
41 | -<% end %> | |
42 | -<% end -%> | |
1 | +<%= render :partial => 'signup_form' %> | ... | ... |
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 => 49) do | |
12 | +ActiveRecord::Schema.define(:version => 50) do | |
13 | 13 | |
14 | 14 | create_table "article_versions", :force => true do |t| |
15 | 15 | t.integer "article_id" |
... | ... | @@ -219,6 +219,7 @@ ActiveRecord::Schema.define(:version => 49) do |
219 | 219 | t.text "custom_header" |
220 | 220 | t.text "custom_footer" |
221 | 221 | t.string "theme" |
222 | + t.boolean "public_profile", :default => true | |
222 | 223 | end |
223 | 224 | |
224 | 225 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" | ... | ... |
test/functional/account_controller_test.rb
... | ... | @@ -277,10 +277,16 @@ class AccountControllerTest < Test::Unit::TestCase |
277 | 277 | assert_redirected_to :controller => 'profile_editor' |
278 | 278 | end |
279 | 279 | |
280 | +################################ | |
281 | +# # | |
282 | +# Enterprise activation tests # | |
283 | +# # | |
284 | +################################ | |
285 | + | |
280 | 286 | should 'report invalid enterprise code on signup' do |
281 | 287 | EnterpriseActivation.expects(:find_by_code).with('some_invalid_code').returns(nil).at_least_once |
282 | 288 | |
283 | - get :signup, :enterprise_code => 'some_invalid_code' | |
289 | + get :activation_question, :enterprise_code => 'some_invalid_code' | |
284 | 290 | |
285 | 291 | assert_template 'invalid_enterprise_code' |
286 | 292 | end |
... | ... | @@ -291,19 +297,19 @@ class AccountControllerTest < Test::Unit::TestCase |
291 | 297 | task.expects(:enterprise).returns(ent).at_least_once |
292 | 298 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
293 | 299 | |
294 | - get :signup, :enterprise_code => '0123456789' | |
300 | + get :activation_question, :enterprise_code => '0123456789' | |
295 | 301 | |
296 | 302 | assert_template 'already_activated' |
297 | 303 | end |
298 | 304 | |
299 | - should 'load enterprise from code on signup' do | |
305 | + should 'load enterprise from code on for validation question' do | |
300 | 306 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent') |
301 | 307 | |
302 | 308 | task = mock |
303 | 309 | task.expects(:enterprise).returns(ent).at_least_once |
304 | 310 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
305 | 311 | |
306 | - get :signup, :enterprise_code => '0123456789' | |
312 | + get :activation_question, :enterprise_code => '0123456789' | |
307 | 313 | |
308 | 314 | assert_equal ent, assigns(:enterprise) |
309 | 315 | end |
... | ... | @@ -315,7 +321,7 @@ class AccountControllerTest < Test::Unit::TestCase |
315 | 321 | task.expects(:enterprise).returns(ent).at_least_once |
316 | 322 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
317 | 323 | |
318 | - get :signup, :enterprise_code => '0123456789' | |
324 | + get :activation_question, :enterprise_code => '0123456789' | |
319 | 325 | |
320 | 326 | assert_template 'blocked' |
321 | 327 | end |
... | ... | @@ -327,34 +333,32 @@ class AccountControllerTest < Test::Unit::TestCase |
327 | 333 | task.expects(:enterprise).returns(ent).at_least_once |
328 | 334 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
329 | 335 | |
330 | - get :signup, :enterprise_code => '0123456789' | |
336 | + get :activation_question, :enterprise_code => '0123456789' | |
331 | 337 | |
332 | - assert_template 'activate_enterprise' | |
338 | + assert_template 'activation_question' | |
333 | 339 | end |
334 | 340 | |
335 | 341 | should 'show form to those enterprises that have cnpj' do |
336 | 342 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :cnpj => '0'*14, :enabled => false) |
337 | 343 | |
338 | - | |
339 | 344 | task = mock |
340 | 345 | task.expects(:enterprise).returns(ent).at_least_once |
341 | 346 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
342 | 347 | |
343 | - get :signup, :enterprise_code => '0123456789' | |
348 | + get :activation_question, :enterprise_code => '0123456789' | |
344 | 349 | |
345 | - assert_template 'activate_enterprise' | |
350 | + assert_template 'activation_question' | |
346 | 351 | end |
347 | 352 | |
348 | 353 | should 'block those who are blocked' do |
349 | 354 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => '1998', :enabled => false) |
350 | 355 | ent.block |
351 | 356 | |
352 | - | |
353 | 357 | task = mock |
354 | 358 | task.expects(:enterprise).returns(ent).at_least_once |
355 | 359 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
356 | 360 | |
357 | - get :signup, :enterprise_code => '0123456789' | |
361 | + get :activation_question, :enterprise_code => '0123456789' | |
358 | 362 | |
359 | 363 | assert_template 'blocked' |
360 | 364 | end |
... | ... | @@ -366,7 +370,8 @@ class AccountControllerTest < Test::Unit::TestCase |
366 | 370 | task.expects(:enterprise).returns(ent).at_least_once |
367 | 371 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
368 | 372 | |
369 | - create_user({}, :enterprise_code => '0123456789', :answer => '1997') | |
373 | + post :accept_terms, :enterprise_code => '0123456789', :answer => '1997' | |
374 | + | |
370 | 375 | ent.reload |
371 | 376 | |
372 | 377 | assert_nil User.find_by_login('test_user') |
... | ... | @@ -374,17 +379,97 @@ class AccountControllerTest < Test::Unit::TestCase |
374 | 379 | assert_template 'blocked' |
375 | 380 | end |
376 | 381 | |
377 | - should 'activate enterprise for those who answer the question right and make them admin of the enterprise' do | |
382 | + should 'show terms of use for enterprise owners' do | |
383 | + env = Environment.default | |
384 | + env.terms_of_enterprise_use = 'Some terms' | |
385 | + env.save! | |
386 | + | |
387 | + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
388 | + task = EnterpriseActivation.create!(:enterprise => ent) | |
389 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
390 | + | |
391 | + post :accept_terms, :enterprise_code => '0123456789', :answer => '1998' | |
392 | + | |
393 | + assert_template 'accept_terms' | |
394 | + assert_tag :tag => 'div', :content => 'Some terms' | |
395 | + end | |
396 | + | |
397 | + should 'not activate if user does not accept terms' do | |
398 | + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
399 | + p = User.create!(:login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person | |
400 | + login_as(p.identifier) | |
401 | + | |
402 | + task = EnterpriseActivation.create!(:enterprise => ent) | |
403 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
404 | + | |
405 | + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => false | |
406 | + ent.reload | |
407 | + | |
408 | + assert !ent.enabled | |
409 | + assert_not_includes ent.members, p | |
410 | + end | |
411 | + | |
412 | + should 'ask for login or singup if not logged in' do | |
413 | + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
414 | + task = EnterpriseActivation.create!(:enterprise => ent) | |
415 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
416 | + | |
417 | + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true | |
418 | + | |
419 | + assert_template 'activate_enterprise' | |
420 | + end | |
421 | + | |
422 | + should 'activate enterprise and make logged user admin' do | |
378 | 423 | ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) |
424 | + p = User.create!(:login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person | |
425 | + login_as(p.identifier) | |
379 | 426 | |
380 | 427 | task = EnterpriseActivation.create!(:enterprise => ent) |
381 | 428 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
382 | 429 | |
383 | - create_user({}, :enterprise_code => '0123456789', :answer => '1998') | |
430 | + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true | |
384 | 431 | ent.reload |
385 | 432 | |
386 | 433 | assert ent.enabled |
387 | - assert_includes ent.members, assigns(:user).person | |
434 | + assert_includes ent.members, p | |
435 | + end | |
436 | + | |
437 | + should 'not activate enterprise for inexistent user' do | |
438 | + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
439 | + task = EnterpriseActivation.create!(:enterprise => ent) | |
440 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
441 | + | |
442 | + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true, :user => { :login => 'inexistent_user', :password => 'inexistent_password' } | |
443 | + ent.reload | |
444 | + | |
445 | + assert !ent.enabled | |
446 | + end | |
447 | + | |
448 | + should 'activate enterprise and make unlogged user admin' do | |
449 | + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
450 | + p = User.create!(:login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com').person | |
451 | + | |
452 | + task = EnterpriseActivation.create!(:enterprise => ent) | |
453 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
454 | + | |
455 | + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true, :user => { :login => 'test_user', :password => 'blih' } | |
456 | + ent.reload | |
457 | + | |
458 | + assert ent.enabled | |
459 | + assert_includes ent.members, p | |
460 | + end | |
461 | + | |
462 | + should 'activate enterprise, create user and make admin' do | |
463 | + ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :foundation_year => 1998, :enabled => false) | |
464 | + | |
465 | + task = EnterpriseActivation.create!(:enterprise => ent) | |
466 | + EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once | |
467 | + | |
468 | + post :activate_enterprise, :enterprise_code => '0123456789', :answer => '1998', :terms_accepted => true, :new_user => true, :user => { :login => 'test_user', :password => 'blih', :password_confirmation => 'blih', :email => 'test@noosfero.com' } | |
469 | + ent.reload | |
470 | + | |
471 | + assert ent.enabled | |
472 | + assert_includes ent.members.map(&:identifier), 'test_user' | |
388 | 473 | end |
389 | 474 | |
390 | 475 | should 'put hidden field with enterprise code for answering question' do |
... | ... | @@ -394,12 +479,13 @@ class AccountControllerTest < Test::Unit::TestCase |
394 | 479 | task.expects(:enterprise).returns(ent).at_least_once |
395 | 480 | EnterpriseActivation.expects(:find_by_code).with('0123456789').returns(task).at_least_once |
396 | 481 | |
397 | - get :signup, :enterprise_code => '0123456789' | |
482 | + get :activation_question, :enterprise_code => '0123456789' | |
398 | 483 | |
399 | 484 | assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'enterprise_code', :value => '0123456789'} |
400 | - | |
401 | 485 | end |
402 | 486 | |
487 | +# end of enterprise activation tests | |
488 | + | |
403 | 489 | should 'not be able to signup while inverse captcha field filled' do |
404 | 490 | assert_no_difference User, :count do |
405 | 491 | create_user({}, @controller.icaptcha_field => 'bli@bla.email.foo') | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -307,15 +307,16 @@ class SearchControllerTest < Test::Unit::TestCase |
307 | 307 | get :index, :query => 'display' |
308 | 308 | |
309 | 309 | names = { |
310 | - :articles => 'Articles', | |
311 | - :enterprises => 'Enterprises', | |
312 | - :communities => 'Communities', | |
313 | - :products => 'Products', | |
314 | - :events => 'Events', | |
310 | + :articles => ['Articles', article], | |
311 | + :enterprises => ['Enterprises', ent], | |
312 | + :communities => ['Communities', community], | |
313 | + :products => ['Products', product], | |
314 | + :events => ['Events', event], | |
315 | 315 | } |
316 | 316 | names.each do |thing, description| |
317 | + description, object = description | |
317 | 318 | assert_tag :tag => 'div', :attributes => { :class => /search-results-#{thing}/ }, :descendant => { :tag => 'h3', :content => Regexp.new(description) } |
318 | - assert_tag :tag => 'a', :content => "display #{thing.to_s.singularize}" | |
319 | + assert_tag :tag => 'a', :content => object.respond_to?(:short_name) ? object.short_name : object.name | |
319 | 320 | end |
320 | 321 | |
321 | 322 | # display only first name on people listing | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -78,6 +78,22 @@ class EnvironmentTest < Test::Unit::TestCase |
78 | 78 | assert v.has_terms_of_use? |
79 | 79 | end |
80 | 80 | |
81 | + def test_terms_of_enterprise_use | |
82 | + v = Environment.new(:name => 'My test environment') | |
83 | + assert_nil v.terms_of_enterprise_use | |
84 | + v.terms_of_enterprise_use = 'To be owner of an enterprise in this environment, you must accept the following terms: ...' | |
85 | + assert v.save | |
86 | + id = v.id | |
87 | + assert_equal 'To be owner of an enterprise in this environment, you must accept the following terms: ...', Environment.find(id).terms_of_enterprise_use | |
88 | + end | |
89 | + | |
90 | + def test_has_terms_of_enterprise_use | |
91 | + v = Environment.new | |
92 | + assert !v.has_terms_of_enterprise_use? | |
93 | + v.terms_of_enterprise_use = 'some terms of enterprise use' | |
94 | + assert v.has_terms_of_enterprise_use? | |
95 | + end | |
96 | + | |
81 | 97 | def test_should_list_top_level_categories |
82 | 98 | env = Environment.create!(:name => 'a test environment') |
83 | 99 | cat1 = Category.create!(:name => 'first category', :environment_id => env.id) | ... | ... |