FIX: Invalid creation of `Theme` in wizard builder.
This commit is contained in:
parent
58edd203a9
commit
4101db8b36
|
@ -138,15 +138,14 @@ class Wizard
|
|||
|
||||
theme = Theme.find_by(color_scheme_id: scheme.id)
|
||||
name = I18n.t('color_schemes.dark_theme_name')
|
||||
theme ||= Theme.create(name: name, color_scheme_id: scheme.id)
|
||||
theme ||= Theme.create(name: name, color_scheme_id: scheme.id, user_id: @wizard.user.id)
|
||||
else
|
||||
|
||||
themes = Theme.where(color_scheme_id: nil).order(:id).to_a
|
||||
theme = themes.find(&:default?)
|
||||
theme ||= themes.first
|
||||
|
||||
name = I18n.t('color_schemes.light_theme_name')
|
||||
theme ||= Theme.create(name: name)
|
||||
theme ||= Theme.create(name: name, user_id: @wizard.user.id)
|
||||
end
|
||||
|
||||
theme.set_default!
|
||||
|
|
|
@ -160,6 +160,38 @@ describe Wizard::StepUpdater do
|
|||
end
|
||||
end
|
||||
|
||||
context "without an existing theme" do
|
||||
before do
|
||||
Theme.delete_all
|
||||
end
|
||||
|
||||
context 'dark theme' do
|
||||
it "creates the theme" do
|
||||
updater = wizard.create_updater('colors', base_scheme_id: 'dark', allow_dark_light_selection: true)
|
||||
|
||||
expect { updater.update }.to change { Theme.count }.by(1)
|
||||
|
||||
theme = Theme.last
|
||||
|
||||
expect(theme.user_id).to eq(wizard.user.id)
|
||||
expect(theme.color_scheme.base_scheme_id).to eq('dark')
|
||||
end
|
||||
end
|
||||
|
||||
context 'light theme' do
|
||||
it "creates the theme" do
|
||||
updater = wizard.create_updater('colors', allow_dark_light_selection: true)
|
||||
|
||||
expect { updater.update }.to change { Theme.count }.by(1)
|
||||
|
||||
theme = Theme.last
|
||||
|
||||
expect(theme.user_id).to eq(wizard.user.id)
|
||||
expect(theme.color_scheme).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "without an existing scheme" do
|
||||
it "creates the scheme" do
|
||||
updater = wizard.create_updater('colors', base_scheme_id: 'dark', allow_dark_light_selection: true)
|
||||
|
|
Loading…
Reference in New Issue