Commit ee0f0a5ee36af36198c6a565cbd8a0d4e61122d8
Committed by
Antonio Terceiro
1 parent
5fbaa212
Exists in
master
and in
29 other branches
ActionItem1272: fixing contact
Showing
3 changed files
with
15 additions
and
13 deletions
Show diff stats
app/controllers/public/contact_controller.rb
... | ... | @@ -8,9 +8,7 @@ class ContactController < PublicController |
8 | 8 | def new |
9 | 9 | @contact |
10 | 10 | if request.post? && params[self.icaptcha_field].blank? |
11 | - @contact = Contact.new(params[:contact]) | |
12 | - @contact.dest = profile | |
13 | - @contact.sender = user | |
11 | + @contact = user.build_contact(profile, params[:contact]) | |
14 | 12 | @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil |
15 | 13 | @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil |
16 | 14 | if @contact.deliver |
... | ... | @@ -20,7 +18,7 @@ class ContactController < PublicController |
20 | 18 | flash[:notice] = _('Contact not sent') |
21 | 19 | end |
22 | 20 | else |
23 | - @contact = Contact.new(:name => user.name, :email => user.email) | |
21 | + @contact = user.build_contact(profile) | |
24 | 22 | end |
25 | 23 | end |
26 | 24 | ... | ... |
app/models/person.rb
... | ... | @@ -233,6 +233,10 @@ class Person < Profile |
233 | 233 | organization.tasks.pending.select{|task| self.has_permission?(task.permission, organization)} |
234 | 234 | end |
235 | 235 | |
236 | + def build_contact(profile, params = {}) | |
237 | + Contact.new(params.merge(:name => name, :email => email, :sender => self, :dest => profile)) | |
238 | + end | |
239 | + | |
236 | 240 | def is_a_friend?(person) |
237 | 241 | self.friends.include?(person) |
238 | 242 | end | ... | ... |
test/functional/contact_controller_test.rb
... | ... | @@ -41,7 +41,7 @@ class ContactControllerTest < Test::Unit::TestCase |
41 | 41 | end |
42 | 42 | |
43 | 43 | should 'redirect back to contact page after send contact' do |
44 | - post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all'} | |
44 | + post :new, :profile => enterprise.identifier, :contact => {:subject => 'Hi', :message => 'Hi, all'} | |
45 | 45 | assert_response :redirect |
46 | 46 | assert_redirected_to :action => 'new' |
47 | 47 | end |
... | ... | @@ -61,7 +61,7 @@ class ContactControllerTest < Test::Unit::TestCase |
61 | 61 | City.stubs(:find).returns(City.new(:name => 'Camaçari')) |
62 | 62 | State.stubs(:exists?).returns(true) |
63 | 63 | State.stubs(:find).returns(State.new(:name => 'Bahia')) |
64 | - post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all'}, :state => '1', :city => '1' | |
64 | + post :new, :profile => enterprise.identifier, :contact => {:subject => 'Hi', :message => 'Hi, all'}, :state => '1', :city => '1' | |
65 | 65 | assert_equal 'Camaçari', assigns(:contact).city |
66 | 66 | assert_equal 'Bahia', assigns(:contact).state |
67 | 67 | end |
... | ... | @@ -71,17 +71,17 @@ class ContactControllerTest < Test::Unit::TestCase |
71 | 71 | assert_tag :tag => 'input', :attributes => {:name => 'contact[receive_a_copy]'} |
72 | 72 | end |
73 | 73 | |
74 | - should 'not deliver contact if mandatory field is blank' do | |
74 | + should 'deliver contact if subject and message are filled' do | |
75 | 75 | post :new, :profile => enterprise.identifier, :contact => {:subject => 'Hi', :message => 'Hi, all'} |
76 | - assert_response :success | |
77 | - assert_template 'new' | |
76 | + assert_response :redirect | |
77 | + assert_redirected_to :action => 'new' | |
78 | 78 | end |
79 | 79 | |
80 | 80 | should 'not throws exception when city and state is blank' do |
81 | 81 | State.expects(:exists?).with('').never |
82 | 82 | City.expects(:exists?).with('').never |
83 | 83 | assert_nothing_raised do |
84 | - post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | |
84 | + post :new, :profile => enterprise.identifier, :contact => {:subject => 'Hi', :message => 'Hi, all', :state => '', :city => ''} | |
85 | 85 | end |
86 | 86 | end |
87 | 87 | |
... | ... | @@ -96,14 +96,14 @@ class ContactControllerTest < Test::Unit::TestCase |
96 | 96 | end |
97 | 97 | |
98 | 98 | should 'be able to post contact while inverse captcha field filled' do |
99 | - post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | |
99 | + post :new, :profile => enterprise.identifier, :contact => {:subject => 'Hi', :message => 'Hi, all', :state => '', :city => ''} | |
100 | 100 | |
101 | 101 | assert_response :redirect |
102 | 102 | assert_redirected_to :action => 'new' |
103 | 103 | end |
104 | 104 | |
105 | 105 | should 'not be able to post contact while inverse captcha field filled' do |
106 | - post :new, :profile => enterprise.identifier, @controller.icaptcha_field => 'filled', :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | |
106 | + post :new, :profile => enterprise.identifier, @controller.icaptcha_field => 'filled', :contact => {:subject => 'Hi', :message => 'Hi, all', :state => '', :city => ''} | |
107 | 107 | |
108 | 108 | assert_response :success |
109 | 109 | assert_template 'new' |
... | ... | @@ -117,7 +117,7 @@ class ContactControllerTest < Test::Unit::TestCase |
117 | 117 | end |
118 | 118 | |
119 | 119 | should 'identify sender' do |
120 | - post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | |
120 | + post :new, :profile => enterprise.identifier, :contact => {:subject => 'Hi', :message => 'Hi, all', :state => '', :city => ''} | |
121 | 121 | assert_equal Person['contact_test_user'], assigns(:contact).sender |
122 | 122 | end |
123 | 123 | ... | ... |