diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index 472112c..f30e017 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -64,7 +64,7 @@ class ProfileEditorController < MyProfileController def header_footer @no_design_blocks = true if request.post? - @profile.update_attributes!(:custom_footer => params[:custom_footer], :custom_header => params[:custom_header]) + @profile.update_header_and_footer(params[:custom_header], params[:custom_footer]) redirect_to :action => 'index' else @header = boxes_holder.custom_header diff --git a/app/controllers/my_profile/themes_controller.rb b/app/controllers/my_profile/themes_controller.rb index 650fc45..06ff502 100644 --- a/app/controllers/my_profile/themes_controller.rb +++ b/app/controllers/my_profile/themes_controller.rb @@ -4,7 +4,7 @@ class ThemesController < MyProfileController no_design_blocks def set - profile.update_attributes!(:theme => params[:id]) + profile.update_theme(params[:id]) redirect_to :action => 'index' end @@ -79,8 +79,7 @@ class ThemesController < MyProfileController end def set_layout_template - profile.layout_template = params[:id] - profile.save! + profile.update_layout_template(params[:id]) redirect_to :action => 'index' end diff --git a/app/models/profile.rb b/app/models/profile.rb index 05aeb6f..c3316c3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -643,4 +643,18 @@ class Profile < ActiveRecord::Base ProfileSweeper.new().after_create(profile) end + def update_header_and_footer(header, footer) + self.custom_header = header + self.custom_footer = footer + self.save(false) + end + + def update_theme(theme) + self.update_attribute(:theme, theme) + end + + def update_layout_template(template) + self.update_attribute(:layout_template, template) + end + end diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 2170050..9430143 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -534,6 +534,17 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_equal 'new footer', person.custom_footer end + should 'save header and footer even if model is invalid' do + person = create_user('designtestuser').person + person.sex = nil; person.save! + person.environment.custom_person_fields = {'sex' => {'required' => 'true', 'active' => 'true'} }; person.environment.save! + + post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' + person = Person.find(person.id) + assert_equal 'new header', person.custom_header + assert_equal 'new footer', person.custom_footer + end + should 'go back to editor after saving header/footer' do person = create_user('designtestuser').person post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' diff --git a/test/functional/themes_controller_test.rb b/test/functional/themes_controller_test.rb index ed6ac6d..1d62456 100644 --- a/test/functional/themes_controller_test.rb +++ b/test/functional/themes_controller_test.rb @@ -78,6 +78,16 @@ class ThemesControllerTest < Test::Unit::TestCase assert_equal 'onetheme', profile.theme end + should 'save selection of theme even if model is invalid' do + @profile.sex = nil + @profile.save! + @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save! + + get :set, :profile => 'testinguser', :id => 'onetheme' + profile = Profile.find(@profile.id) + assert_equal 'onetheme', profile.theme + end + should 'point back to control panel' do get :index, :profile => 'testinguser' assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back' @@ -258,6 +268,17 @@ class ThemesControllerTest < Test::Unit::TestCase assert_redirected_to :action => 'index' end + should 'set template even if the model is invalid' do + @profile.sex = nil + @profile.save! + @profile.environment.custom_person_fields = { 'sex' => {'required' => 'true', 'active' => 'true'} }; @profile.environment.save! + + post :set_layout_template, :profile => 'testinguser', :id => 'leftbar' + profile = Profile.find(@profile.id) + assert_equal 'leftbar', profile.layout_template + assert_redirected_to :action => 'index' + end + should 'not display "new theme" button when user themes are disabled' do env.disable('user_themes') env.save! -- libgit2 0.21.2