Skip to content

Commit

Permalink
add tests for reverting default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriyAndriyovuch committed Sep 16, 2023
1 parent 58a23c5 commit 75a13ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/account/site_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/site_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions spec/requests/site_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 75a13ac

Please sign in to comment.