Skip to content

Commit

Permalink
FIX: remote theme record not saved when checking for updates (#8054)
Browse files Browse the repository at this point in the history
  • Loading branch information
OsamaSayegh committed Aug 29, 2019
1 parent 1a909c1 commit ff8cc24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 0 additions & 6 deletions app/controllers/admin/themes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,22 +186,16 @@ def update
update_translations
handle_switch

save_remote = false
if params[:theme][:remote_check]
@theme.remote_theme.update_remote_version
save_remote = true
end

if params[:theme][:remote_update]
@theme.remote_theme.update_from_remote
save_remote = true
end

respond_to do |format|
if @theme.save

@theme.remote_theme.save! if save_remote

update_default_theme

@theme.reload
Expand Down
4 changes: 4 additions & 0 deletions app/models/remote_theme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def update_remote_version
self.updated_at = Time.zone.now
self.remote_version, self.commits_behind = importer.commits_since(local_version)
self.last_error_text = nil
ensure
self.save!
end
end

Expand All @@ -119,6 +121,7 @@ def update_from_remote(importer = nil, skip_update: false)
importer.import!
rescue RemoteTheme::ImportError => err
self.last_error_text = err.message
self.save!
return self
else
self.last_error_text = nil
Expand Down Expand Up @@ -163,6 +166,7 @@ def update_from_remote(importer = nil, skip_update: false)

update_theme_color_schemes(theme, theme_info["color_schemes"]) unless theme.component

self.save!
self
ensure
begin
Expand Down
16 changes: 16 additions & 0 deletions spec/requests/admin/themes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,22 @@
expect(theme.theme_translation_overrides.count).to eq(0)
end

it 'checking for updates saves the remote_theme record' do
theme.remote_theme = RemoteTheme.create!(remote_url: "http://discourse.org", remote_version: "a", local_version: "a", commits_behind: 0)
theme.save!
ThemeStore::GitImporter.any_instance.stubs(:import!)
ThemeStore::GitImporter.any_instance.stubs(:commits_since).returns(["b", 1])

put "/admin/themes/#{theme.id}.json", params: {
theme: {
remote_check: true
}
}
theme.reload
expect(theme.remote_theme.remote_version).to eq("b")
expect(theme.remote_theme.commits_behind).to eq(1)
end

it 'can disable component' do
child = Fabricate(:theme, component: true)

Expand Down

0 comments on commit ff8cc24

Please sign in to comment.