Skip to content

Commit

Permalink
Don't keep default theme name as empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Feb 15, 2017
1 parent 32e097c commit 21ba8ce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/models/asciicast.rb
Expand Up @@ -81,6 +81,13 @@ def command=(value)
value ? super(value.strip[0...255]) : super
end

def theme_name=(value)
if value == ""
value = nil
end
super(value)
end

def self.generate_secret_token
SecureRandom.hex.to_i(16).to_s(36).rjust(25, '0')
end
Expand Down Expand Up @@ -126,7 +133,7 @@ def with_terminal
end

def theme
theme_name.presence && Theme.for_name(theme_name)
theme_name && Theme.for_name(theme_name)
end

def image_filename
Expand Down
9 changes: 8 additions & 1 deletion app/models/user.rb
Expand Up @@ -79,8 +79,15 @@ def email=(value)
value ? super(value.strip) : super
end

def theme_name=(value)
if value == ""
value = nil
end
super(value)
end

def theme
theme_name.presence && Theme.for_name(theme_name)
theme_name && Theme.for_name(theme_name)
end

def assign_api_token(token)
Expand Down
@@ -0,0 +1,6 @@
class ConvertEmptyStringThemeToNil < ActiveRecord::Migration
def change
execute "UPDATE users SET theme_name=NULL WHERE theme_name=''"
execute "UPDATE asciicasts SET theme_name=NULL WHERE theme_name=''"
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150510164222) do
ActiveRecord::Schema.define(version: 20170215120234) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down

0 comments on commit 21ba8ce

Please sign in to comment.