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