Downcase subdomains and domains when given as user input.

This commit is contained in:
Mario Visic 2012-04-06 23:10:16 +08:00
parent e413373858
commit 7260f36be7
2 changed files with 29 additions and 2 deletions

View File

@ -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
end

View File

@ -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