Commit db00f92d4377ca761993f5635faded2125255c7d
1 parent
0d65584a
Exists in
master
and in
29 other branches
ActionItem791: fix bug when state or city is blank
Showing
2 changed files
with
11 additions
and
3 deletions
Show diff stats
app/controllers/public/contact_controller.rb
@@ -7,8 +7,8 @@ class ContactController < PublicController | @@ -7,8 +7,8 @@ class ContactController < PublicController | ||
7 | if request.post? | 7 | if request.post? |
8 | @contact = Contact.new(params[:contact]) | 8 | @contact = Contact.new(params[:contact]) |
9 | @contact.dest = profile | 9 | @contact.dest = profile |
10 | - @contact.city = City.exists?(params[:city]) ? City.find(params[:city]).name : _('Missing') | ||
11 | - @contact.state = State.exists?(params[:state]) ? State.find(params[:state]).name : _('Missing') | 10 | + @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : _('Missing') |
11 | + @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : _('Missing') | ||
12 | if @contact.deliver | 12 | if @contact.deliver |
13 | flash[:notice] = _('Contact successfully sent') | 13 | flash[:notice] = _('Contact successfully sent') |
14 | redirect_to :action => 'new' | 14 | redirect_to :action => 'new' |
test/functional/contact_controller_test.rb
@@ -64,7 +64,7 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -64,7 +64,7 @@ class ContactControllerTest < Test::Unit::TestCase | ||
64 | should 'define city and state' do | 64 | should 'define city and state' do |
65 | City.stubs(:find).returns(City.new(:name => 'Camaçari')) | 65 | City.stubs(:find).returns(City.new(:name => 'Camaçari')) |
66 | State.stubs(:find).returns(State.new(:name => 'Bahia')) | 66 | State.stubs(:find).returns(State.new(:name => 'Bahia')) |
67 | - post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => 1, :city => 1} | 67 | + post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all'}, :state => '1', :city => '1' |
68 | assert_equal 'Camaçari', assigns(:contact).city | 68 | assert_equal 'Camaçari', assigns(:contact).city |
69 | assert_equal 'Bahia', assigns(:contact).state | 69 | assert_equal 'Bahia', assigns(:contact).state |
70 | end | 70 | end |
@@ -80,4 +80,12 @@ class ContactControllerTest < Test::Unit::TestCase | @@ -80,4 +80,12 @@ class ContactControllerTest < Test::Unit::TestCase | ||
80 | assert_template 'new' | 80 | assert_template 'new' |
81 | end | 81 | end |
82 | 82 | ||
83 | + should 'not throws exception when city and state is blank' do | ||
84 | + State.expects(:exists?).with('').never | ||
85 | + City.expects(:exists?).with('').never | ||
86 | + assert_nothing_raised do | ||
87 | + post :new, :profile => enterprise.identifier, :contact => {:name => 'john', :subject => 'Hi', :email => 'visitor@mail.invalid', :message => 'Hi, all', :state => '', :city => ''} | ||
88 | + end | ||
89 | + end | ||
90 | + | ||
83 | end | 91 | end |