diff --git a/app/controllers/account/site_settings_controller.rb b/app/controllers/account/site_settings_controller.rb index 56541ac4e..767758921 100644 --- a/app/controllers/account/site_settings_controller.rb +++ b/app/controllers/account/site_settings_controller.rb @@ -20,7 +20,7 @@ def update def revert @site_setting = resource - @site_setting.update(title: "Zero Waste", favicon: { + @site_setting.update(title: "ZeroWaste", favicon: { io: File.open("app/assets/images/logo_zerowaste.png"), filename: "logo_zerowaste.png", content_type: "image/png" diff --git a/spec/factories/site_settings.rb b/spec/factories/site_settings.rb index 54ab71163..039ef3893 100644 --- a/spec/factories/site_settings.rb +++ b/spec/factories/site_settings.rb @@ -22,5 +22,10 @@ title { "Test title" } favicon { Rack::Test::UploadedFile.new("app/assets/images/logo_zerowaste.png", "image/png") } end + + trait :custom_setting do + title { "Custom Waste" } + favicon { Rack::Test::UploadedFile.new("app/assets/images/user.png", "image/png") } + end end end diff --git a/spec/requests/site_setting_spec.rb b/spec/requests/site_setting_spec.rb index 37c57731a..4e39ac6f9 100644 --- a/spec/requests/site_setting_spec.rb +++ b/spec/requests/site_setting_spec.rb @@ -52,4 +52,29 @@ end end end + + describe "GET revert" do + include_context :authorize_admin + + context "with valid params" do + let(:site_setting) { SiteSetting.current } + let(:site_setting_params) { FactoryBot.attributes_for(:site_setting, :custom_setting) } + let(:site_setting_default_params) { FactoryBot.attributes_for(:site_setting, :with_valid_site_setting) } + + before { site_setting.update(site_setting_params) } + + it "reverts site setting" do + get account_site_settings_revert_path + + expect(response).to redirect_to(edit_account_site_setting_path) + expect(flash[:notice]).to eq(I18n.t("notifications.site_setting_reverted")) + + expect(SiteSetting.current).to be_valid + expect(SiteSetting.current.favicon.attached?).to be_truthy + + expect(SiteSetting.current.title).to eq(site_setting_default_params[:title]) + expect(SiteSetting.current.favicon.filename).to eq(site_setting_default_params[:favicon].original_filename) + end + end + end end