Commit c4375964727c6573a9eca1e7000e3e21ea31ccbc

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent e784be49

ActionItem1154: require login to send contact

app/controllers/public/contact_controller.rb
1 class ContactController < PublicController 1 class ContactController < PublicController
2 2
  3 + before_filter :login_required
  4 +
3 needs_profile 5 needs_profile
4 6
5 inverse_captcha :field => 'e_mail' 7 inverse_captcha :field => 'e_mail'
test/functional/contact_controller_test.rb
@@ -15,6 +15,8 @@ class ContactControllerTest &lt; Test::Unit::TestCase @@ -15,6 +15,8 @@ class ContactControllerTest &lt; Test::Unit::TestCase
15 15
16 @profile = create_user('contact_test_user').person 16 @profile = create_user('contact_test_user').person
17 @enterprise = Enterprise.create!(:identifier => 'contact_test_enterprise', :name => 'Test contact enteprise') 17 @enterprise = Enterprise.create!(:identifier => 'contact_test_enterprise', :name => 'Test contact enteprise')
  18 +
  19 + login_as('contact_test_user')
18 end 20 end
19 attr_reader :profile, :enterprise 21 attr_reader :profile, :enterprise
20 22
@@ -50,13 +52,11 @@ class ContactControllerTest &lt; Test::Unit::TestCase @@ -50,13 +52,11 @@ class ContactControllerTest &lt; Test::Unit::TestCase
50 end 52 end
51 53
52 should 'fill email if user logged in' do 54 should 'fill email if user logged in' do
53 - login_as(profile.identifier)  
54 get :new, :profile => enterprise.identifier 55 get :new, :profile => enterprise.identifier
55 assert_tag :tag => 'input', :attributes => {:name => 'contact[email]', :value => profile.email} 56 assert_tag :tag => 'input', :attributes => {:name => 'contact[email]', :value => profile.email}
56 end 57 end
57 58
58 should 'fill name if user logged in' do 59 should 'fill name if user logged in' do
59 - login_as(profile.identifier)  
60 get :new, :profile => enterprise.identifier 60 get :new, :profile => enterprise.identifier
61 assert_tag :tag => 'input', :attributes => {:name => 'contact[name]', :value => profile.name} 61 assert_tag :tag => 'input', :attributes => {:name => 'contact[name]', :value => profile.name}
62 end 62 end
@@ -111,5 +111,11 @@ class ContactControllerTest &lt; Test::Unit::TestCase @@ -111,5 +111,11 @@ class ContactControllerTest &lt; Test::Unit::TestCase
111 assert_response :success 111 assert_response :success
112 assert_template 'new' 112 assert_template 'new'
113 end 113 end
114 - 114 +
  115 + should 'not allow if not logged' do
  116 + logout
  117 + get :new, :profile => profile.identifier
  118 + assert_response :redirect
  119 + assert_redirected_to :controller => 'account', :action => 'login'
  120 + end
115 end 121 end