Commit c798281d5d9a2156c73e23e2c336ed4b11013cc5
1 parent
923d4164
Exists in
master
and in
29 other branches
Fixing route to tasks when profile has its own domain
(ActionItem2529)
Showing
5 changed files
with
21 additions
and
15 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -463,6 +463,10 @@ class Profile < ActiveRecord::Base |
463 | 463 | { :profile => identifier, :controller => 'profile_editor', :action => 'index' } |
464 | 464 | end |
465 | 465 | |
466 | + def tasks_url | |
467 | + { :profile => identifier, :controller => 'tasks', :action => 'index', :host => default_hostname } | |
468 | + end | |
469 | + | |
466 | 470 | def leave_url(reload = false) |
467 | 471 | { :profile => identifier, :controller => 'profile', :action => 'leave', :reload => reload } |
468 | 472 | end | ... | ... |
app/models/task_mailer.rb
... | ... | @@ -14,7 +14,7 @@ class TaskMailer < ActionMailer::Base |
14 | 14 | |
15 | 15 | recipients task.target.notification_emails |
16 | 16 | |
17 | - url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.url.merge(:controller => 'tasks', :action => 'index')) | |
17 | + url_for_tasks_list = task.target.kind_of?(Environment) ? '' : url_for(task.target.tasks_url) | |
18 | 18 | |
19 | 19 | from self.class.generate_from(task) |
20 | 20 | subject '[%s] %s' % [task.environment.name, task.target_notification_description] | ... | ... |
test/unit/approve_article_test.rb
... | ... | @@ -422,4 +422,12 @@ class ApproveArticleTest < ActiveSupport::TestCase |
422 | 422 | assert_nil new_article.last_changed_by_id |
423 | 423 | end |
424 | 424 | |
425 | + should 'not crash if target has its own domain' do | |
426 | + article = fast_create(Article) | |
427 | + profile.domains << Domain.create(:name => 'example.org') | |
428 | + assert_nothing_raised do | |
429 | + ApproveArticle.create!(:article => article, :target => profile, :requestor => community) | |
430 | + end | |
431 | + end | |
432 | + | |
425 | 433 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -246,6 +246,13 @@ class ProfileTest < ActiveSupport::TestCase |
246 | 246 | assert_equal({ :profile => 'testprofile', :controller => 'profile_editor', :action => 'index'}, profile.admin_url) |
247 | 247 | end |
248 | 248 | |
249 | + should 'provide URL to tasks area' do | |
250 | + environment = create_environment('mycolivre.net') | |
251 | + profile = build(Profile, :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | |
252 | + | |
253 | + assert_equal({ :host => profile.default_hostname, :profile => 'testprofile', :controller => 'tasks', :action => 'index'}, profile.tasks_url) | |
254 | + end | |
255 | + | |
249 | 256 | should 'provide URL to public profile' do |
250 | 257 | environment = create_environment('mycolivre.net') |
251 | 258 | profile = build(Profile, :identifier => 'testprofile', :environment_id => environment.id) | ... | ... |
test/unit/task_mailer_test.rb
... | ... | @@ -84,22 +84,9 @@ class TaskMailerTest < ActiveSupport::TestCase |
84 | 84 | end |
85 | 85 | |
86 | 86 | should 'be able to send a "target notification" message' do |
87 | - task = Task.new | |
87 | + task = Task.new(:target => fast_create(Person)) | |
88 | 88 | task.expects(:target_notification_description).returns('the task') |
89 | 89 | |
90 | - target = mock() | |
91 | - target.expects(:notification_emails).returns(['target@example.com']) | |
92 | - target.expects(:name).returns('Target') | |
93 | - target.expects(:url).returns({:host => 'my.domain.com', :profile => 'testprofile'}) | |
94 | - | |
95 | - environment = mock() | |
96 | - environment.expects(:contact_email).returns('sender@example.com') | |
97 | - environment.expects(:default_hostname).returns('example.com') | |
98 | - environment.expects(:name).returns('example').at_least_once | |
99 | - | |
100 | - task.expects(:target).returns(target).at_least_once | |
101 | - task.expects(:environment).returns(environment).at_least_once | |
102 | - | |
103 | 90 | TaskMailer.deliver_target_notification(task, 'the message') |
104 | 91 | assert !ActionMailer::Base.deliveries.empty? |
105 | 92 | end | ... | ... |