Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add a spec helper to upload a theme or a component

Loïc Guitautebed9cd013c4
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
index efc714b2116..ee345027b31 100644
--- a/spec/support/helpers.rb
+++ b/spec/support/helpers.rb
@@ -6,6 +6,11 @@ GIT_INITIAL_BRANCH_SUPPORTED =
module Helpers
extend ActiveSupport::Concern
+ class NotAThemeError < StandardError
+ end
+ class NotAComponentThemeError < StandardError
+ end
+
def self.next_seq
@next_seq = (@next_seq || 0) + 1
end
@@ -244,7 +249,8 @@ module Helpers
theme = RemoteTheme.import_theme_from_directory(directory_from_caller)
if theme.component
- raise "Uploaded theme is a theme component, please use the `upload_theme_component` method instead."
+ raise NotAThemeError,
+ "Uploaded theme is a theme component, please use the `upload_theme_component` method instead."
end
theme.set_default! if set_theme_as_default
@@ -273,13 +279,20 @@ module Helpers
theme = RemoteTheme.import_theme_from_directory(directory_from_caller)
if !theme.component
- raise "Uploaded theme is not a theme component, please use the `upload_theme` method instead."
+ raise NotAComponentThemeError,
+ "Uploaded theme is not a theme component, please use the `upload_theme` method instead."
end
Theme.find(parent_theme_id).child_themes << theme
theme
end
+ def upload_theme_or_component
+ upload_theme
+ rescue NotAThemeError
+ upload_theme_component
+ end
+
# Runs named migration for a given theme.
#
# @params [Theme] theme The theme to run the migration for.