Commit 71e0f420ae356b63ecc800341611566cd2c39e26
1 parent
aa24ce6d
Exists in
staging
and in
42 other branches
ActionItem1024: bypas validation in some places
Showing
5 changed files
with
49 additions
and
4 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
| @@ -64,7 +64,7 @@ class ProfileEditorController < MyProfileController | @@ -64,7 +64,7 @@ class ProfileEditorController < MyProfileController | ||
| 64 | def header_footer | 64 | def header_footer |
| 65 | @no_design_blocks = true | 65 | @no_design_blocks = true |
| 66 | if request.post? | 66 | if request.post? |
| 67 | - @profile.update_attributes!(:custom_footer => params[:custom_footer], :custom_header => params[:custom_header]) | 67 | + @profile.update_header_and_footer(params[:custom_header], params[:custom_footer]) |
| 68 | redirect_to :action => 'index' | 68 | redirect_to :action => 'index' |
| 69 | else | 69 | else |
| 70 | @header = boxes_holder.custom_header | 70 | @header = boxes_holder.custom_header |
app/controllers/my_profile/themes_controller.rb
| @@ -4,7 +4,7 @@ class ThemesController < MyProfileController | @@ -4,7 +4,7 @@ class ThemesController < MyProfileController | ||
| 4 | no_design_blocks | 4 | no_design_blocks |
| 5 | 5 | ||
| 6 | def set | 6 | def set |
| 7 | - profile.update_attributes!(:theme => params[:id]) | 7 | + profile.update_theme(params[:id]) |
| 8 | redirect_to :action => 'index' | 8 | redirect_to :action => 'index' |
| 9 | end | 9 | end |
| 10 | 10 | ||
| @@ -79,8 +79,7 @@ class ThemesController < MyProfileController | @@ -79,8 +79,7 @@ class ThemesController < MyProfileController | ||
| 79 | end | 79 | end |
| 80 | 80 | ||
| 81 | def set_layout_template | 81 | def set_layout_template |
| 82 | - profile.layout_template = params[:id] | ||
| 83 | - profile.save! | 82 | + profile.update_layout_template(params[:id]) |
| 84 | redirect_to :action => 'index' | 83 | redirect_to :action => 'index' |
| 85 | end | 84 | end |
| 86 | 85 |
app/models/profile.rb
| @@ -643,4 +643,18 @@ class Profile < ActiveRecord::Base | @@ -643,4 +643,18 @@ class Profile < ActiveRecord::Base | ||
| 643 | ProfileSweeper.new().after_create(profile) | 643 | ProfileSweeper.new().after_create(profile) |
| 644 | end | 644 | end |
| 645 | 645 | ||
| 646 | + def update_header_and_footer(header, footer) | ||
| 647 | + self.custom_header = header | ||
| 648 | + self.custom_footer = footer | ||
| 649 | + self.save(false) | ||
| 650 | + end | ||
| 651 | + | ||
| 652 | + def update_theme(theme) | ||
| 653 | + self.update_attribute(:theme, theme) | ||
| 654 | + end | ||
| 655 | + | ||
| 656 | + def update_layout_template(template) | ||
| 657 | + self.update_attribute(:layout_template, template) | ||
| 658 | + end | ||
| 659 | + | ||
| 646 | end | 660 | end |
test/functional/profile_editor_controller_test.rb
| @@ -534,6 +534,17 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -534,6 +534,17 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
| 534 | assert_equal 'new footer', person.custom_footer | 534 | assert_equal 'new footer', person.custom_footer |
| 535 | end | 535 | end |
| 536 | 536 | ||
| 537 | + should 'save header and footer even if model is invalid' do | ||
| 538 | + person = create_user('designtestuser').person | ||
| 539 | + person.sex = nil; person.save! | ||
| 540 | + person.environment.custom_person_fields = {'sex' => {'required' => 'true', 'active' => 'true'} }; person.environment.save! | ||
| 541 | + | ||
| 542 | + post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' | ||
| 543 | + person = Person.find(person.id) | ||
| 544 | + assert_equal 'new header', person.custom_header | ||
| 545 | + assert_equal 'new footer', person.custom_footer | ||
| 546 | + end | ||
| 547 | + | ||
| 537 | should 'go back to editor after saving header/footer' do | 548 | should 'go back to editor after saving header/footer' do |
| 538 | person = create_user('designtestuser').person | 549 | person = create_user('designtestuser').person |
| 539 | post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' | 550 | post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' |
test/functional/themes_controller_test.rb
| @@ -78,6 +78,16 @@ class ThemesControllerTest < Test::Unit::TestCase | @@ -78,6 +78,16 @@ class ThemesControllerTest < Test::Unit::TestCase | ||
| 78 | assert_equal 'onetheme', profile.theme | 78 | assert_equal 'onetheme', profile.theme |
| 79 | end | 79 | end |
| 80 | 80 | ||
| 81 | + should 'save selection of theme even if model is invalid' do | ||
| 82 | + @profile.sex = nil | ||
| 83 | + @profile.save! | ||
| 84 | + @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save! | ||
| 85 | + | ||
| 86 | + get :set, :profile => 'testinguser', :id => 'onetheme' | ||
| 87 | + profile = Profile.find(@profile.id) | ||
| 88 | + assert_equal 'onetheme', profile.theme | ||
| 89 | + end | ||
| 90 | + | ||
| 81 | should 'point back to control panel' do | 91 | should 'point back to control panel' do |
| 82 | get :index, :profile => 'testinguser' | 92 | get :index, :profile => 'testinguser' |
| 83 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back' | 93 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back' |
| @@ -258,6 +268,17 @@ class ThemesControllerTest < Test::Unit::TestCase | @@ -258,6 +268,17 @@ class ThemesControllerTest < Test::Unit::TestCase | ||
| 258 | assert_redirected_to :action => 'index' | 268 | assert_redirected_to :action => 'index' |
| 259 | end | 269 | end |
| 260 | 270 | ||
| 271 | + should 'set template even if the model is invalid' do | ||
| 272 | + @profile.sex = nil | ||
| 273 | + @profile.save! | ||
| 274 | + @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save! | ||
| 275 | + | ||
| 276 | + post :set_layout_template, :profile => 'testinguser', :id => 'leftbar' | ||
| 277 | + profile = Profile.find(@profile.id) | ||
| 278 | + assert_equal 'leftbar', profile.layout_template | ||
| 279 | + assert_redirected_to :action => 'index' | ||
| 280 | + end | ||
| 281 | + | ||
| 261 | should 'not display "new theme" button when user themes are disabled' do | 282 | should 'not display "new theme" button when user themes are disabled' do |
| 262 | env.disable('user_themes') | 283 | env.disable('user_themes') |
| 263 | env.save! | 284 | env.save! |