From 852dce2dffa051912fc208c71f5802f9322dbef3 Mon Sep 17 00:00:00 2001 From: Bing Xie Date: Fri, 8 Apr 2016 10:43:23 +1000 Subject: [PATCH] Add default logos and home_hero --- app/models/content_configuration.rb | 8 ++++---- spec/models/content_configuration_spec.rb | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 spec/models/content_configuration_spec.rb diff --git a/app/models/content_configuration.rb b/app/models/content_configuration.rb index 2357f8dfa3..e20279f5ee 100644 --- a/app/models/content_configuration.rb +++ b/app/models/content_configuration.rb @@ -7,14 +7,14 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration preference :logo, :file preference :logo_mobile, :file preference :logo_mobile_svg, :file - has_attached_file :logo + has_attached_file :logo, default_url: "/assets/ofn-logo.png" has_attached_file :logo_mobile - has_attached_file :logo_mobile_svg + has_attached_file :logo_mobile_svg, default_url: "/assets/ofn-logo-mobile.svg" # Home page preference :home_hero, :file preference :home_show_stats, :boolean, default: true - has_attached_file :home_hero + has_attached_file :home_hero, default_url: "/assets/home/home.jpg" # Producer sign-up page preference :producer_signup_pricing_table_html, :text, default: "(TODO: Pricing table)" @@ -33,7 +33,7 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration # Footer preference :footer_logo, :file - has_attached_file :footer_logo + has_attached_file :footer_logo, default_url: "/assets/ofn-logo-footer.png" preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet" preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet" preference :footer_instagram_url, :string, default: "" diff --git a/spec/models/content_configuration_spec.rb b/spec/models/content_configuration_spec.rb new file mode 100644 index 0000000000..6b7bc8a4e0 --- /dev/null +++ b/spec/models/content_configuration_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe ContentConfiguration do + describe "default logos and home_hero" do + it "sets a default url with existing image" do + expect(image_exist?(ContentConfig.logo.options[:default_url])).to be_true + expect(image_exist?(ContentConfig.logo_mobile_svg.options[:default_url])).to be_true + expect(image_exist?(ContentConfig.home_hero.options[:default_url])).to be_true + expect(image_exist?(ContentConfig.footer_logo.options[:default_url])).to be_true + end + + def image_exist?(default_url) + image_path = default_url.gsub(/\/assets\//,'/assets/images/') + File.exist?(File.join(Rails.root, 'app', image_path)) + end + end +end