Commit 2e3c97a0e0cb698f1474d961ca37cc2b1b39dc78
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'fix_notification_mail' into stable
Showing
18 changed files
with
131 additions
and
34 deletions
Show diff stats
Gemfile
... | ... | @@ -47,8 +47,9 @@ group :cucumber do |
47 | 47 | gem 'selenium-webdriver', '~> 2.39.0' |
48 | 48 | end |
49 | 49 | |
50 | -# include plugin gemfiles | |
51 | -Dir.glob(File.join('config', 'plugins', '*')).each do |plugin| | |
52 | - plugin_gemfile = File.join(plugin, 'Gemfile') | |
53 | - eval File.read(plugin_gemfile) if File.exists?(plugin_gemfile) | |
50 | +# include gemfiles from enabled plugins | |
51 | +# plugins in baseplugins/ are not included on purpose. They should not have any | |
52 | +# dependencies. | |
53 | +Dir.glob('config/plugins/*/Gemfile').each do |gemfile| | |
54 | + eval File.read(gemfile) | |
54 | 55 | end | ... | ... |
app/controllers/public/account_controller.rb
... | ... | @@ -200,7 +200,7 @@ class AccountController < ApplicationController |
200 | 200 | else |
201 | 201 | @change_password.errors[:base] << _('Could not find any user with %s equal to "%s".') % [fields_label, params[:value]] |
202 | 202 | end |
203 | - rescue ActiveRecord::RecordInvald | |
203 | + rescue ActiveRecord::RecordInvalid | |
204 | 204 | @change_password.errors[:base] << _('Could not perform password recovery for the user.') |
205 | 205 | end |
206 | 206 | end | ... | ... |
app/models/task.rb
... | ... | @@ -286,7 +286,7 @@ class Task < ActiveRecord::Base |
286 | 286 | def send_notification(action) |
287 | 287 | if sends_email? |
288 | 288 | if self.requestor |
289 | - TaskMailer.generic_message("task_#{action}", self) | |
289 | + TaskMailer.generic_message("task_#{action}", self).deliver | |
290 | 290 | end |
291 | 291 | end |
292 | 292 | end | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<%= @message %> | ... | ... |
debian/control
lib/tasks/ci.rake
... | ... | @@ -10,6 +10,15 @@ namespace :ci do |
10 | 10 | File.exist?(f) |
11 | 11 | end |
12 | 12 | |
13 | + changed_plugin_files = changed_files.select do |f| | |
14 | + f.split(File::SEPARATOR).first == 'plugins' | |
15 | + end | |
16 | + changed_plugins = changed_plugin_files.map do |f| | |
17 | + f.split(File::SEPARATOR)[1] | |
18 | + end.uniq | |
19 | + | |
20 | + changed_files -= changed_plugin_files | |
21 | + | |
13 | 22 | # explicitly changed tests |
14 | 23 | tests = changed_files.select { |f| f =~ /test\/.*_test\.rb$/ } |
15 | 24 | features = changed_files.select { |f| f =~ /\.feature$/ } |
... | ... | @@ -27,6 +36,13 @@ namespace :ci do |
27 | 36 | sh 'testrb', '-Itest', *tests unless tests.empty? |
28 | 37 | sh 'cucumber', *features unless features.empty? |
29 | 38 | sh 'cucumber', '-p', 'selenium', *features unless features.empty? |
39 | + | |
40 | + changed_plugins.each do |plugin| | |
41 | + task = "test:noosfero_plugins:#{plugin}" | |
42 | + puts "Running #{task}" | |
43 | + Rake::Task[task].execute | |
44 | + end | |
45 | + | |
30 | 46 | end |
31 | 47 | |
32 | 48 | end | ... | ... |
plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
... | ... | @@ -101,9 +101,6 @@ class ContentViewerControllerTest < ActionController::TestCase |
101 | 101 | should 'render tracks in track list block' do |
102 | 102 | @block = CommunityTrackPlugin::TrackListBlock.create!(:box => @profile.boxes.last) |
103 | 103 | get :view_page, @step.url |
104 | - file = File.open('result.html', 'w+') | |
105 | - file.write(@response.body) | |
106 | - file.close | |
107 | 104 | assert_tag :tag => 'div', :attributes => { :class => "item category_#{@track.category_name}" }, :descendant => { :tag => 'div', :attributes => { :class => 'steps' }, :descendant => { :tag => 'span', :attributes => { :class => "step #{@block.status_class(@step)}" } } } |
108 | 105 | end |
109 | 106 | ... | ... |
plugins/custom_forms/test/functional/custom_forms_plugin_myprofile_controller_test.rb
... | ... | @@ -226,7 +226,7 @@ class CustomFormsPluginMyprofileControllerTest < ActionController::TestCase |
226 | 226 | end |
227 | 227 | |
228 | 228 | should 'list pending submissions for a form' do |
229 | - person = fast_create(Person) | |
229 | + person = create_user('john').person | |
230 | 230 | form = CustomFormsPlugin::Form.create!(:profile => profile, :name => 'Free Software', :for_admission => true) |
231 | 231 | task = CustomFormsPlugin::AdmissionSurvey.create!(:form_id => form.id, :target => person, :requestor => profile) |
232 | 232 | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/admission_survey_test.rb
... | ... | @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/../../../../../test/test_helper' |
3 | 3 | class CustomFormsPlugin::AdmissionSurveyTest < ActiveSupport::TestCase |
4 | 4 | should 'add member to community on perform' do |
5 | 5 | profile = fast_create(Community) |
6 | - person = fast_create(Person) | |
6 | + person = create_user('john').person | |
7 | 7 | form = CustomFormsPlugin::Form.create!(:name => 'Simple Form', :profile => profile) |
8 | 8 | task = CustomFormsPlugin::AdmissionSurvey.create!(:form_id => form.id, :target => person, :requestor => profile) |
9 | 9 | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/form_test.rb
... | ... | @@ -244,7 +244,7 @@ class CustomFormsPlugin::FormTest < ActiveSupport::TestCase |
244 | 244 | |
245 | 245 | should 'cancel survey tasks after removing a form' do |
246 | 246 | profile = fast_create(Profile) |
247 | - person = fast_create(Person) | |
247 | + person = create_user('john').person | |
248 | 248 | |
249 | 249 | form1 = CustomFormsPlugin::Form.create!(:name => 'Free Software', :profile => profile) |
250 | 250 | form2 = CustomFormsPlugin::Form.create!(:name => 'Operation System', :profile => profile) | ... | ... |
plugins/custom_forms/test/unit/custom_forms_plugin/membership_survey_test.rb
... | ... | @@ -13,7 +13,7 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase |
13 | 13 | |
14 | 14 | should 'create submission with answers on perform' do |
15 | 15 | profile = fast_create(Profile) |
16 | - person = fast_create(Person) | |
16 | + person = create_user('john').person | |
17 | 17 | form = CustomFormsPlugin::Form.create!(:name => 'Simple Form', :profile => profile) |
18 | 18 | field = CustomFormsPlugin::Field.create!(:name => 'Name', :form => form) |
19 | 19 | task = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :submission => {field.id.to_s => 'Jack'}, :target => person, :requestor => profile) |
... | ... | @@ -31,7 +31,7 @@ class CustomFormsPlugin::MembershipSurveyTest < ActiveSupport::TestCase |
31 | 31 | |
32 | 32 | should 'have a scope that retrieves all tasks requested by profile' do |
33 | 33 | profile = fast_create(Profile) |
34 | - person = fast_create(Person) | |
34 | + person = create_user('john').person | |
35 | 35 | form = CustomFormsPlugin::Form.create!(:name => 'Simple Form', :profile => profile) |
36 | 36 | task1 = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :target => person, :requestor => profile) |
37 | 37 | task2 = CustomFormsPlugin::MembershipSurvey.create!(:form_id => form.id, :target => person, :requestor => fast_create(Profile)) | ... | ... |
plugins/custom_forms/test/unit/ext/role_assingment_test.rb
... | ... | @@ -5,7 +5,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
5 | 5 | environment = Environment.default |
6 | 6 | environment.enable_plugin(CustomFormsPlugin) |
7 | 7 | organization = fast_create(Organization) |
8 | - person = fast_create(Person) | |
8 | + person = create_user('john').person | |
9 | 9 | f1 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 1', :on_membership => true) |
10 | 10 | f2 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 2', :on_membership => true) |
11 | 11 | f3 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 3', :on_membership => false) |
... | ... | @@ -19,7 +19,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
19 | 19 | environment = Environment.default |
20 | 20 | environment.enable_plugin(CustomFormsPlugin) |
21 | 21 | organization = fast_create(Organization) |
22 | - person = fast_create(Person) | |
22 | + person = create_user('john').person | |
23 | 23 | form = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form', :on_membership => true, :access => 'associated') |
24 | 24 | |
25 | 25 | assert_difference 'CustomFormsPlugin::MembershipSurvey.count', 1 do |
... | ... | @@ -31,7 +31,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
31 | 31 | environment = Environment.default |
32 | 32 | environment.enable_plugin(CustomFormsPlugin) |
33 | 33 | organization = fast_create(Organization) |
34 | - person = fast_create(Person) | |
34 | + person = create_user('john').person | |
35 | 35 | form1 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 1', :on_membership => true) |
36 | 36 | organization.add_member(person) |
37 | 37 | |
... | ... | @@ -59,7 +59,7 @@ class RoleAssignmentsTest < ActiveSupport::TestCase |
59 | 59 | environment = Environment.default |
60 | 60 | environment.enable_plugin(CustomFormsPlugin) |
61 | 61 | organization = fast_create(Organization) |
62 | - person = fast_create(Person) | |
62 | + person = create_user('john').person | |
63 | 63 | f1 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 1', :for_admission => true) |
64 | 64 | f2 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 2', :for_admission => true) |
65 | 65 | f3 = CustomFormsPlugin::Form.create!(:profile => organization, :name => 'Form 3', :for_admission => false) | ... | ... |
plugins/remote_user/lib/remote_user_plugin.rb
... | ... | @@ -13,17 +13,27 @@ class RemoteUserPlugin < Noosfero::Plugin |
13 | 13 | |
14 | 14 | begin |
15 | 15 | remote_user = request.headers["HTTP_REMOTE_USER"] |
16 | + user_data = request.env['HTTP_REMOTE_USER_DATA'] | |
16 | 17 | |
17 | - if remote_user.nil? | |
18 | + if remote_user.blank? | |
18 | 19 | if logged_in? |
19 | 20 | self.current_user.forget_me |
20 | 21 | reset_session |
21 | 22 | end |
22 | 23 | else |
24 | + if user_data.blank? | |
25 | + remote_user_email = remote_user + '@remote.user' | |
26 | + remote_user_name = remote_user | |
27 | + else | |
28 | + user_data = JSON.parse(user_data) | |
29 | + remote_user_email = user_data['email'] | |
30 | + remote_user_name = user_data['name'] | |
31 | + end | |
32 | + | |
23 | 33 | if !logged_in? |
24 | 34 | self.current_user = User.find_by_login(remote_user) |
25 | 35 | unless self.current_user |
26 | - self.current_user = User.create!(:login => remote_user, :email => (remote_user + '@remote.user'), :password => ('pw4'+remote_user), :password_confirmation => ('pw4'+remote_user)) | |
36 | + self.current_user = User.create!(:login => remote_user, :email => remote_user_email, :name => remote_user_name, :password => ('pw4'+remote_user), :password_confirmation => ('pw4'+remote_user)) | |
27 | 37 | self.current_user.activate |
28 | 38 | end |
29 | 39 | self.current_user.save! |
... | ... | @@ -34,7 +44,7 @@ class RemoteUserPlugin < Noosfero::Plugin |
34 | 44 | |
35 | 45 | self.current_user = User.find_by_login(remote_user) |
36 | 46 | unless self.current_user |
37 | - self.current_user = User.create!(:login => remote_user, :email => (remote_user + '@remote.user'), :password => ('pw4'+remote_user), :password_confirmation => ('pw4'+remote_user)) | |
47 | + self.current_user = User.create!(:login => remote_user, :email => remote_user_email, :name => remote_user_name, :password => ('pw4'+remote_user), :password_confirmation => ('pw4'+remote_user)) | |
38 | 48 | self.current_user.activate |
39 | 49 | end |
40 | 50 | self.current_user.save! | ... | ... |
plugins/remote_user/test/functional/remote_user_plugin_test.rb
... | ... | @@ -42,26 +42,64 @@ class AccountControllerTest < ActionController::TestCase |
42 | 42 | assert_equal user2.id, session[:user] |
43 | 43 | end |
44 | 44 | |
45 | - should 'create a new user if the remote user does not exist' do | |
45 | + should 'create a new user with remote_user_data if the remote user does not exist' do | |
46 | 46 | User.destroy_all |
47 | 47 | |
48 | 48 | assert_equal 0, User.count |
49 | 49 | |
50 | 50 | @request.env["HTTP_REMOTE_USER"] = "testuser" |
51 | + @request.env["CONTENT_TYPE"] = "application/json" | |
52 | + @request.env["HTTP_REMOTE_USER_DATA"] = '{"email":"testuser@domain.com", "name":"Test User"}' | |
51 | 53 | get :index |
52 | 54 | |
53 | 55 | assert_equal 1, User.count |
54 | 56 | assert_equal "testuser", User.last.login |
55 | 57 | assert_equal true, User.last.activated? |
56 | 58 | assert_equal User.last.id, session[:user] |
59 | + assert_equal "Test User", User.last.name | |
60 | + assert_equal "testuser@domain.com", User.last.email | |
57 | 61 | end |
58 | 62 | |
59 | - should 'create a new user even if there is a logged user but the remote user is different' do | |
63 | + should 'create a new user with remote_user_data even if there is a logged user but the remote user is different' do | |
60 | 64 | user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') |
61 | 65 | user.activate |
62 | 66 | |
63 | 67 | login_as user.login |
64 | 68 | |
69 | + @request.env["HTTP_REMOTE_USER"] = 'another_user' | |
70 | + @request.env["CONTENT_TYPE"] = "application/json" | |
71 | + @request.env["HTTP_REMOTE_USER_DATA"] = '{"email":"another_user@domain.com", "name":"Another User"}' | |
72 | + get :index | |
73 | + | |
74 | + assert_equal 2, User.count | |
75 | + assert_equal "another_user", User.last.login | |
76 | + assert_equal true, User.last.activated? | |
77 | + assert_equal User.last.id, session[:user] | |
78 | + assert_equal "Another User", User.last.name | |
79 | + assert_equal "another_user@domain.com", User.last.email | |
80 | + end | |
81 | + | |
82 | + should 'create a new user without remote_user_data if the remote user does not exist' do | |
83 | + User.destroy_all | |
84 | + | |
85 | + assert_equal 0, User.count | |
86 | + | |
87 | + @request.env["HTTP_REMOTE_USER"] = "testuser" | |
88 | + get :index | |
89 | + | |
90 | + assert_equal 1, User.count | |
91 | + assert_equal "testuser", User.last.login | |
92 | + assert_equal true, User.last.activated? | |
93 | + assert_equal User.last.id, session[:user] | |
94 | + assert_equal "testuser", User.last.name | |
95 | + assert_equal "testuser@remote.user", User.last.email | |
96 | + end | |
97 | + | |
98 | + should 'create a new user without remote_user_data even if there is a logged user but the remote user is different' do | |
99 | + user = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') | |
100 | + user.activate | |
101 | + | |
102 | + login_as user.login | |
65 | 103 | |
66 | 104 | @request.env["HTTP_REMOTE_USER"] = 'another_user' |
67 | 105 | get :index |
... | ... | @@ -70,5 +108,23 @@ class AccountControllerTest < ActionController::TestCase |
70 | 108 | assert_equal "another_user", User.last.login |
71 | 109 | assert_equal true, User.last.activated? |
72 | 110 | assert_equal User.last.id, session[:user] |
111 | + assert_equal "another_user", User.last.name | |
112 | + assert_equal "another_user@remote.user", User.last.email | |
113 | + end | |
114 | + | |
115 | + should 'logout if there is a current logged user but not a remote user' do | |
116 | + user1 = create_user('testuser', :email => 'testuser@example.com', :password => 'test', :password_confirmation => 'test') | |
117 | + user1.activate | |
118 | + | |
119 | + login_as user1.login | |
120 | + | |
121 | + get :index | |
122 | + | |
123 | + assert session[:user].blank? | |
124 | + | |
125 | + @request.env["HTTP_REMOTE_USER"] = "" | |
126 | + get :index | |
127 | + | |
128 | + assert session[:user].blank? | |
73 | 129 | end |
74 | 130 | end | ... | ... |
plugins/solr/install.rb
plugins/spaminator/test/unit/spaminator_plugin/spaminator_test.rb
... | ... | @@ -50,6 +50,7 @@ class SpaminatorPlugin::SpaminatorTest < ActiveSupport::TestCase |
50 | 50 | end |
51 | 51 | |
52 | 52 | should 'process only people from the environment and that are not abusers' do |
53 | + Person.delete_all | |
53 | 54 | p1 = fast_create(Person) |
54 | 55 | p2 = fast_create(Person) |
55 | 56 | p3 = fast_create(Person, :environment_id => fast_create(Environment)) | ... | ... |
script/noosfero-plugins
... | ... | @@ -98,9 +98,12 @@ _enable(){ |
98 | 98 | dependencies_ok=true |
99 | 99 | dependencies_file="$source/dependencies.rb" |
100 | 100 | if [ -e $source/Gemfile ]; then |
101 | - if ! (cd $source && bundle --local); then | |
101 | + gemfile=$(mktemp --tmpdir=.) | |
102 | + cat Gemfile $source/Gemfile > $gemfile | |
103 | + if ! RUBYOPT='' BUNDLE_GEMFILE="$gemfile" bundle --local --quiet; then | |
102 | 104 | dependencies_ok=false |
103 | 105 | fi |
106 | + rm -f $gemfile $gemfile.lock | |
104 | 107 | fi |
105 | 108 | if ! run $dependencies_file; then |
106 | 109 | dependencies_ok=false | ... | ... |
test/unit/task_test.rb
... | ... | @@ -29,7 +29,9 @@ class TaskTest < ActiveSupport::TestCase |
29 | 29 | end |
30 | 30 | |
31 | 31 | def test_should_call_perform_in_finish |
32 | - TaskMailer.expects(:generic_message).with('task_finished', anything) | |
32 | + mail = mock | |
33 | + mail.expects(:deliver) | |
34 | + TaskMailer.expects(:generic_message).with('task_finished', anything).returns(mail) | |
33 | 35 | t = Task.create |
34 | 36 | t.requestor = sample_user |
35 | 37 | t.expects(:perform) |
... | ... | @@ -38,7 +40,9 @@ class TaskTest < ActiveSupport::TestCase |
38 | 40 | end |
39 | 41 | |
40 | 42 | def test_should_have_cancelled_status_after_cancel |
41 | - TaskMailer.expects(:generic_message).with('task_cancelled', anything) | |
43 | + mail = mock | |
44 | + mail.expects(:deliver) | |
45 | + TaskMailer.expects(:generic_message).with('task_cancelled', anything).returns(mail) | |
42 | 46 | t = Task.create |
43 | 47 | t.requestor = sample_user |
44 | 48 | t.cancel |
... | ... | @@ -54,7 +58,9 @@ class TaskTest < ActiveSupport::TestCase |
54 | 58 | t = Task.create |
55 | 59 | t.requestor = sample_user |
56 | 60 | |
57 | - TaskMailer.expects(:generic_message).with('task_finished', t) | |
61 | + mail = mock | |
62 | + mail.expects(:deliver) | |
63 | + TaskMailer.expects(:generic_message).with('task_finished', t).returns(mail) | |
58 | 64 | |
59 | 65 | t.finish |
60 | 66 | end |
... | ... | @@ -63,7 +69,9 @@ class TaskTest < ActiveSupport::TestCase |
63 | 69 | t = Task.create |
64 | 70 | t.requestor = sample_user |
65 | 71 | |
66 | - TaskMailer.expects(:generic_message).with('task_cancelled', t) | |
72 | + mail = mock | |
73 | + mail.expects(:deliver) | |
74 | + TaskMailer.expects(:generic_message).with('task_cancelled', t).returns(mail) | |
67 | 75 | |
68 | 76 | t.cancel |
69 | 77 | end |
... | ... | @@ -93,7 +101,9 @@ class TaskTest < ActiveSupport::TestCase |
93 | 101 | task = Task.new |
94 | 102 | task.requestor = sample_user |
95 | 103 | |
96 | - TaskMailer.expects(:generic_message).with('task_created', task) | |
104 | + mail = mock | |
105 | + mail.expects(:deliver) | |
106 | + TaskMailer.expects(:generic_message).with('task_created', task).returns(mail) | |
97 | 107 | task.save! |
98 | 108 | end |
99 | 109 | |
... | ... | @@ -281,7 +291,9 @@ class TaskTest < ActiveSupport::TestCase |
281 | 291 | task.requestor = sample_user |
282 | 292 | task.save! |
283 | 293 | |
284 | - TaskMailer.expects(:generic_message).with('task_activated', task) | |
294 | + mail = mock | |
295 | + mail.expects(:deliver) | |
296 | + TaskMailer.expects(:generic_message).with('task_activated', task).returns(mail) | |
285 | 297 | task.activate |
286 | 298 | end |
287 | 299 | ... | ... |