Commit 014ac44299b51921e20c8ea7d7d41cd1a33a08d2
1 parent
b6aaca22
Exists in
master
and in
29 other branches
ActionItem703: removing www from email address
Showing
5 changed files
with
37 additions
and
3 deletions
Show diff stats
app/models/environment.rb
... | ... | @@ -274,12 +274,12 @@ class Environment < ActiveRecord::Base |
274 | 274 | # |
275 | 275 | # If #force_www is true, adds 'www.' at the beginning of the hostname. If the |
276 | 276 | # environment has not associated domains, returns 'localhost'. |
277 | - def default_hostname | |
277 | + def default_hostname(email_hostname = false) | |
278 | 278 | if self.domains(true).empty? |
279 | 279 | 'localhost' |
280 | 280 | else |
281 | 281 | domain = self.domains.find(:first, :order => 'id').name |
282 | - force_www ? ('www.' + domain) : domain | |
282 | + email_hostname ? domain : (force_www ? ('www.' + domain) : domain) | |
283 | 283 | end |
284 | 284 | end |
285 | 285 | ... | ... |
app/models/person.rb
... | ... | @@ -98,7 +98,7 @@ class Person < Profile |
98 | 98 | |
99 | 99 | def email_addresses |
100 | 100 | # TODO for now, only one e-mail address |
101 | - ['%s@%s' % [self.identifier, self.environment.default_hostname ] ] | |
101 | + ['%s@%s' % [self.identifier, self.environment.default_hostname(true) ] ] | |
102 | 102 | end |
103 | 103 | |
104 | 104 | def display_info_to?(user) | ... | ... |
test/functional/mailconf_controller_test.rb
... | ... | @@ -74,6 +74,24 @@ class MailconfControllerTest < Test::Unit::TestCase |
74 | 74 | assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'hidden', :value => '0' } |
75 | 75 | end |
76 | 76 | |
77 | + should 'not display www in email address when force_www=true' do | |
78 | + login_as('ze') | |
79 | + env = Environment.default | |
80 | + env.force_www = true | |
81 | + env.save! | |
82 | + get :index, :profile => 'ze' | |
83 | + assert_tag :tag => 'label', :attributes => { :for => 'user_enable_email' }, :content => /ze@colivre.net/ | |
84 | + end | |
85 | + | |
86 | + should 'not display www in email address when force_www=false' do | |
87 | + login_as('ze') | |
88 | + env = Environment.default | |
89 | + env.force_www = false | |
90 | + env.save! | |
91 | + get :index, :profile => 'ze' | |
92 | + assert_tag :tag => 'label', :attributes => { :for => 'user_enable_email' }, :content => /ze@colivre.net/ | |
93 | + end | |
94 | + | |
77 | 95 | should 'save mail enable/disable as true' do |
78 | 96 | login_as('ze') |
79 | 97 | post :save, :profile => 'ze', :user => { :enable_email => '1' } | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -178,6 +178,12 @@ class EnvironmentTest < Test::Unit::TestCase |
178 | 178 | assert_equal 'www.example.com', env.default_hostname |
179 | 179 | end |
180 | 180 | |
181 | + should 'not add www when requesting domain for email address' do | |
182 | + env = Environment.create!(:name => 'test environment', :force_www => true) | |
183 | + env.domains << Domain.create(:name => 'example.com') | |
184 | + assert_equal 'example.com', env.default_hostname(true) | |
185 | + end | |
186 | + | |
181 | 187 | should 'provide default top URL' do |
182 | 188 | env = Environment.new |
183 | 189 | env.expects(:default_hostname).returns('www.lalala.net') | ... | ... |
test/unit/person_test.rb
... | ... | @@ -280,6 +280,16 @@ class PersonTest < Test::Unit::TestCase |
280 | 280 | assert_equal ['testuser@somedomain.com'], person.email_addresses |
281 | 281 | end |
282 | 282 | |
283 | + should 'not show www in e-mail addresses when force_www=true' do | |
284 | + env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) | |
285 | + env.force_www = true | |
286 | + env.save | |
287 | + person = Person.new(:identifier => 'testuser') | |
288 | + person.expects(:environment).returns(env) | |
289 | + | |
290 | + assert_equal ['testuser@somedomain.com'], person.email_addresses | |
291 | + end | |
292 | + | |
283 | 293 | should 'show profile info to friend' do |
284 | 294 | person = create_user('test_user').person |
285 | 295 | person.public_profile = false | ... | ... |