From 7260f36be7e3143932179c2fa3355f555d20468c Mon Sep 17 00:00:00 2001 From: Mario Visic Date: Fri, 6 Apr 2012 23:10:16 +0800 Subject: [PATCH] Downcase subdomains and domains when given as user input. --- .../extensions/site/subdomain_domains.rb | 8 +++++-- .../extensions/site/subdomain_domains_spec.rb | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 spec/models/locomotive/extensions/site/subdomain_domains_spec.rb diff --git a/app/models/locomotive/extensions/site/subdomain_domains.rb b/app/models/locomotive/extensions/site/subdomain_domains.rb index 46f1df2a..71963b5f 100644 --- a/app/models/locomotive/extensions/site/subdomain_domains.rb +++ b/app/models/locomotive/extensions/site/subdomain_domains.rb @@ -37,9 +37,13 @@ module Locomotive module InstanceMethods + def subdomain=(subdomain) + super(subdomain.try(:downcase)) + end + def domains=(array) array.reject!(&:blank?) - array = [] if array.blank?; super(array) + array = [] if array.blank?; super(array.map(&:downcase)) end def add_subdomain_to_domains @@ -84,4 +88,4 @@ module Locomotive end end end -end \ No newline at end of file +end diff --git a/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb b/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb new file mode 100644 index 00000000..f9fb33e4 --- /dev/null +++ b/spec/models/locomotive/extensions/site/subdomain_domains_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Locomotive::Extensions::Site::SubdomainDomains do + describe '#subdomain=' do + let(:site) { Locomotive::Site.new } + + it 'downcases the subdomain' do + site.subdomain = 'MiXeDCaSe' + + site.subdomain.should == 'mixedcase' + end + end + + describe '#domains=' do + let(:site) { Locomotive::Site.new } + + it 'downcases the domains' do + site.domains = ['FIRST.com', 'second.com', 'THIRD.com'] + + site.domains.should == ['first.com', 'second.com', 'third.com'] + end + end +end