From ede8f229715b52ff92eea28566925345aa8e25cf Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 17 Jul 2014 12:31:37 -0400 Subject: [PATCH] Use the header background color for a site in the digest email. --- app/mailers/user_notifications.rb | 1 + app/models/color_scheme.rb | 4 ++++ app/views/user_notifications/digest.html.erb | 2 +- spec/models/color_scheme_spec.rb | 12 ++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index 56802bb3088..6ada3e2e4dd 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -39,6 +39,7 @@ class UserNotifications < ActionMailer::Base @site_name = SiteSetting.title + @header_color = ColorScheme.hex_for_name('header_background') @last_seen_at = I18n.l(@user.last_seen_at || @user.created_at, format: :short) # A list of topics to show the user diff --git a/app/models/color_scheme.rb b/app/models/color_scheme.rb index a4fe017e47c..c63e8862fa4 100644 --- a/app/models/color_scheme.rb +++ b/app/models/color_scheme.rb @@ -60,6 +60,10 @@ class ColorScheme < ActiveRecord::Base new_color_scheme end + def self.hex_for_name(name) + # Can't use `where` here because base doesn't allow it + (enabled || base).colors.find {|c| c.name == name }.try(:hex) + end def colors=(arr) @colors_by_name = nil diff --git a/app/views/user_notifications/digest.html.erb b/app/views/user_notifications/digest.html.erb index e35fc1db9a3..b2b47eda2e8 100644 --- a/app/views/user_notifications/digest.html.erb +++ b/app/views/user_notifications/digest.html.erb @@ -1,6 +1,6 @@ - diff --git a/spec/models/color_scheme_spec.rb b/spec/models/color_scheme_spec.rb index 1e15de52ace..5770c1ba330 100644 --- a/spec/models/color_scheme_spec.rb +++ b/spec/models/color_scheme_spec.rb @@ -40,6 +40,16 @@ describe ColorScheme do second.hex.should == base_colors[:second_one] third.hex.should == 'F00D33' end + + context "hex_for_name without anything enabled" do + it "returns nil for a missing attribute" do + described_class.hex_for_name('undefined').should be_nil + end + + it "returns the base color for an attribute" do + described_class.hex_for_name('second_one').should == base_colors[:second_one] + end + end end describe "destroy" do @@ -59,8 +69,10 @@ describe ColorScheme do end it "returns the enabled color scheme" do + described_class.hex_for_name('$primary_background_color').should be_nil c = described_class.create(valid_params.merge(enabled: true)) described_class.enabled.id.should == c.id + described_class.hex_for_name('$primary_background_color').should == "FFBB00" end end end
+