Commit 9c9f424b347234ee8cb33db7256f29933aa1fc48
1 parent
15262820
Exists in
master
and in
22 other branches
ActionItem12: acceptance of terms of communities implemeted and unit tested
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@421 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
31 additions
and
0 deletions
Show diff stats
app/controllers/account_controller.rb
... | ... | @@ -26,9 +26,17 @@ class AccountController < ApplicationController |
26 | 26 | # action to register an user to the application |
27 | 27 | def signup |
28 | 28 | begin |
29 | + @terms_of_use = virtual_community.terms_of_use | |
30 | + terms_accepted = params[:user].delete(:terms_accepted) | |
29 | 31 | @user = User.new(params[:user]) |
30 | 32 | return unless request.post? |
33 | + if @terms_of_use and !terms_accepted | |
34 | + flash[:notice] = _("You have to accept the terms of service to signup") | |
35 | + return | |
36 | + end | |
31 | 37 | @user.save! |
38 | + @user.person.virtual_community = virtual_community | |
39 | + @user.person.save! | |
32 | 40 | self.current_user = @user |
33 | 41 | redirect_back_or_default(:controller => 'account', :action => 'index') |
34 | 42 | flash[:notice] = _("Thanks for signing up!") | ... | ... |
app/models/virtual_community.rb
app/views/account/signup.rhtml
... | ... | @@ -14,5 +14,11 @@ |
14 | 14 | <p><label for="password_confirmation">Confirm Password</label><br/> |
15 | 15 | <%= f.password_field :password_confirmation %></p> |
16 | 16 | |
17 | +<% if @terms_of_use %> | |
18 | + <p> <%= @terms_of_use %> </p> | |
19 | + <p> <%= check_box 'user', 'terms_accepted' %> | |
20 | + <label for="terms_accepted">I accept the terms of use</label> </p> | |
21 | +<% end %> | |
22 | + | |
17 | 23 | <p><%= submit_tag 'Sign up' %></p> |
18 | 24 | <% end -%> | ... | ... |
test/functional/account_controller_test.rb
... | ... | @@ -68,6 +68,22 @@ class AccountControllerTest < Test::Unit::TestCase |
68 | 68 | end |
69 | 69 | end |
70 | 70 | |
71 | + def test_shoud_not_save_without_acceptance_of_terms_of_use_on_signup | |
72 | + assert_no_difference User, :count do | |
73 | + VirtualCommunity.default.update_attributes(:terms_of_use => 'some terms ...') | |
74 | + create_user | |
75 | + assert_response :success | |
76 | + end | |
77 | + end | |
78 | + | |
79 | + def test_shoud_save_with_acceptance_of_terms_of_use_on_signup | |
80 | + assert_difference User, :count do | |
81 | + VirtualCommunity.default.update_attributes(:terms_of_use => 'some terms ...') | |
82 | + create_user(:terms_accepted => true) | |
83 | + assert_response :redirect | |
84 | + end | |
85 | + end | |
86 | + | |
71 | 87 | def test_should_logout |
72 | 88 | login_as :johndoe |
73 | 89 | get :logout | ... | ... |