2022-06-25 17:59:44 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe Settings::ThemeController, type: :controller do
|
|
|
|
describe "#edit" do
|
|
|
|
subject { get :edit }
|
|
|
|
|
|
|
|
context "user signed in" do
|
|
|
|
let(:user) { FactoryBot.create(:user) }
|
|
|
|
|
|
|
|
before { sign_in user }
|
|
|
|
|
|
|
|
it "renders the edit template" do
|
|
|
|
subject
|
|
|
|
expect(response).to render_template(:edit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update" do
|
|
|
|
let(:user) { FactoryBot.create(:user) }
|
|
|
|
|
2022-06-25 18:07:59 -07:00
|
|
|
let(:update_attributes) do
|
|
|
|
{
|
2022-06-25 17:59:44 -07:00
|
|
|
theme: {
|
2022-06-25 18:07:59 -07:00
|
|
|
primary_color: 6174129,
|
|
|
|
primary_text: 16777215,
|
|
|
|
danger_color: 14431557,
|
|
|
|
danger_text: 16777215,
|
|
|
|
success_color: 2664261,
|
|
|
|
success_text: 16777215,
|
|
|
|
warning_color: 16761095,
|
|
|
|
warning_text: 2697513,
|
|
|
|
info_color: 1548984,
|
|
|
|
info_text: 16777215,
|
|
|
|
dark_color: 3422784,
|
|
|
|
dark_text: 15658734,
|
|
|
|
light_color: 16316922,
|
|
|
|
light_text: 0,
|
2022-06-25 17:59:44 -07:00
|
|
|
raised_background: 16777215,
|
2022-06-25 18:07:59 -07:00
|
|
|
raised_accent: 16250871,
|
|
|
|
background_color: 15789556,
|
|
|
|
body_text: 0,
|
|
|
|
muted_text: 7107965,
|
|
|
|
input_color: 15789556,
|
|
|
|
input_text: 0
|
|
|
|
}
|
2022-06-25 17:59:44 -07:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { patch :update, params: update_attributes }
|
|
|
|
|
|
|
|
context "user signed in" do
|
|
|
|
before { sign_in user }
|
|
|
|
|
|
|
|
context "user has no theme" do
|
|
|
|
it "creates a new theme" do
|
2022-06-25 18:19:18 -07:00
|
|
|
expect { subject }.to(change { user.reload.theme })
|
2022-06-25 17:59:44 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the edit template" do
|
|
|
|
subject
|
2023-10-19 17:21:52 -07:00
|
|
|
expect(response).to render_template(:edit)
|
2022-06-25 17:59:44 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "user has a theme" do
|
|
|
|
let(:user) { FactoryBot.create(:user) }
|
|
|
|
let(:theme) { FactoryBot.create(:theme, user: user) }
|
|
|
|
|
|
|
|
it "updates the theme" do
|
2022-06-25 18:19:18 -07:00
|
|
|
expect { subject }.to(change { theme.reload.attributes })
|
2022-06-25 17:59:44 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
it "renders the edit template" do
|
|
|
|
subject
|
2023-10-19 17:21:52 -07:00
|
|
|
expect(response).to render_template(:edit)
|
2022-06-25 17:59:44 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|