Commit 04ae2fd2bdaa5ee6d0dcafc5374fb7ef93222fe5
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'master' into stable
Showing
50 changed files
with
670 additions
and
92 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
@@ -19,14 +19,16 @@ class ProfileEditorController < MyProfileController | @@ -19,14 +19,16 @@ class ProfileEditorController < MyProfileController | ||
19 | params[:profile_data][:custom_fields] ||= {} | 19 | params[:profile_data][:custom_fields] ||= {} |
20 | end | 20 | end |
21 | Profile.transaction do | 21 | Profile.transaction do |
22 | - Image.transaction do | ||
23 | - if @profile_data.update_attributes(params[:profile_data]) | ||
24 | - redirect_to :action => 'index', :profile => profile.identifier | ||
25 | - else | ||
26 | - profile.identifier = params[:profile] if profile.identifier.blank? | 22 | + Image.transaction do |
23 | + begin | ||
24 | + @plugins.dispatch(:profile_editor_transaction_extras) | ||
25 | + @profile_data.update_attributes!(params[:profile_data]) | ||
26 | + redirect_to :action => 'index', :profile => profile.identifier | ||
27 | + rescue Exception => ex | ||
28 | + profile.identifier = params[:profile] if profile.identifier.blank? | ||
29 | + end | ||
27 | end | 30 | end |
28 | end | 31 | end |
29 | - end | ||
30 | end | 32 | end |
31 | end | 33 | end |
32 | 34 |
app/controllers/public/chat_controller.rb
@@ -19,7 +19,7 @@ class ChatController < PublicController | @@ -19,7 +19,7 @@ class ChatController < PublicController | ||
19 | def avatar | 19 | def avatar |
20 | profile = environment.profiles.find_by_identifier(params[:id]) | 20 | profile = environment.profiles.find_by_identifier(params[:id]) |
21 | filename, mimetype = profile_icon(profile, :minor, true) | 21 | filename, mimetype = profile_icon(profile, :minor, true) |
22 | - if filename =~ /^https?:/ | 22 | + if filename =~ /^(https?:)?\/\// |
23 | redirect_to filename | 23 | redirect_to filename |
24 | else | 24 | else |
25 | data = File.read(File.join(Rails.root, 'public', filename)) | 25 | data = File.read(File.join(Rails.root, 'public', filename)) |
app/models/user.rb
@@ -214,6 +214,10 @@ class User < ActiveRecord::Base | @@ -214,6 +214,10 @@ class User < ActiveRecord::Base | ||
214 | Digest::MD5.hexdigest(password) | 214 | Digest::MD5.hexdigest(password) |
215 | end | 215 | end |
216 | 216 | ||
217 | + add_encryption_method :salted_md5 do |password, salt| | ||
218 | + Digest::MD5.hexdigest(password+salt) | ||
219 | + end | ||
220 | + | ||
217 | add_encryption_method :clear do |password, salt| | 221 | add_encryption_method :clear do |password, salt| |
218 | password | 222 | password |
219 | end | 223 | end |
app/views/file_presenter/_generic.html.erb
1 | <span class="download-link"> | 1 | <span class="download-link"> |
2 | <span>Download</span> | 2 | <span>Download</span> |
3 | - <strong><%= link_to generic.filename, generic.public_filename %></strong> | 3 | + <strong><%= link_to generic.filename, [Noosfero.root, generic.public_filename].join %></strong> |
4 | </span> | 4 | </span> |
5 | 5 | ||
6 | <div class="uploaded-file-description <%= 'empty' if generic.abstract.blank? %>"> | 6 | <div class="uploaded-file-description <%= 'empty' if generic.abstract.blank? %>"> |
app/views/file_presenter/_image.html.erb
@@ -28,7 +28,7 @@ | @@ -28,7 +28,7 @@ | ||
28 | 28 | ||
29 | <%# image_tag(article.public_filename(:display), :class => article.css_class_name, :style => 'max-width: 100%') %> | 29 | <%# image_tag(article.public_filename(:display), :class => article.css_class_name, :style => 'max-width: 100%') %> |
30 | 30 | ||
31 | -<img src="<%=image.public_filename(:display)%>" class="<%=image.css_class_name%>"> | 31 | +<img src="<%= [Noosfero.root, image.public_filename(:display)].join %>" class="<%=image.css_class_name%>"> |
32 | 32 | ||
33 | <div class="uploaded-file-description <%= 'empty' if image.abstract.blank? %>"> | 33 | <div class="uploaded-file-description <%= 'empty' if image.abstract.blank? %>"> |
34 | <%= image.abstract %> | 34 | <%= image.abstract %> |
app/views/home/index.html.erb
@@ -61,9 +61,6 @@ | @@ -61,9 +61,6 @@ | ||
61 | <%= submit_button(:search, _('Search')) %> | 61 | <%= submit_button(:search, _('Search')) %> |
62 | </div> | 62 | </div> |
63 | 63 | ||
64 | - <div> | ||
65 | - <%= lightbox_link_to _('More options'), :controller => 'search', :action => 'popup' %> | ||
66 | - </div> | ||
67 | <% end %> | 64 | <% end %> |
68 | </div> | 65 | </div> |
69 | <% end %> | 66 | <% end %> |
app/views/profile_editor/_person_form.html.erb
@@ -27,6 +27,10 @@ | @@ -27,6 +27,10 @@ | ||
27 | <%= optional_field(@person, 'district', labelled_form_field(_('District'), text_field(:profile_data, :district, :rel => _('District')))) %> | 27 | <%= optional_field(@person, 'district', labelled_form_field(_('District'), text_field(:profile_data, :district, :rel => _('District')))) %> |
28 | <%= optional_field(@person, 'image', labelled_form_field(_('Image'), file_field(:file, :image, :rel => _('Image')))) %> | 28 | <%= optional_field(@person, 'image', labelled_form_field(_('Image'), file_field(:file, :image, :rel => _('Image')))) %> |
29 | 29 | ||
30 | +<% @plugins.dispatch(:extra_optional_fields).each do |field| %> | ||
31 | + <%= optional_field(@person, field[:name], labelled_form_field(field[:label], text_field(field[:object_name], field[:method], :rel => field[:label], :value => field[:value]))) %> | ||
32 | +<% end %> | ||
33 | + | ||
30 | <% optional_field(@person, 'schooling') do %> | 34 | <% optional_field(@person, 'schooling') do %> |
31 | <div class="formfieldline"> | 35 | <div class="formfieldline"> |
32 | <label class='formlabel' for='profile_data_schooling'><%= _('Schooling') %></label> | 36 | <label class='formlabel' for='profile_data_schooling'><%= _('Schooling') %></label> |
features/gravatar_support.feature
@@ -20,11 +20,11 @@ Feature: Gravatar Support | @@ -20,11 +20,11 @@ Feature: Gravatar Support | ||
20 | Scenario: The Aurium's gravatar picture must link to his gravatar profile | 20 | Scenario: The Aurium's gravatar picture must link to his gravatar profile |
21 | # because Aurium has his picture registered at garvatar.com. | 21 | # because Aurium has his picture registered at garvatar.com. |
22 | When I go to article "My Article" | 22 | When I go to article "My Article" |
23 | - Then I should see "Aurium" linking to "http://www.gravatar.com/24a625896a07aa37fdb2352e302e96de" | 23 | + Then I should see "Aurium" linking to "//www.gravatar.com/24a625896a07aa37fdb2352e302e96de" |
24 | 24 | ||
25 | @selenium | 25 | @selenium |
26 | Scenario: The NoOne's gravatar picture must link to Gravatar homepage | 26 | Scenario: The NoOne's gravatar picture must link to Gravatar homepage |
27 | # because NoOne <nobody@colivre.coop.br> has no picture registered. | 27 | # because NoOne <nobody@colivre.coop.br> has no picture registered. |
28 | When I go to article "My Article" | 28 | When I go to article "My Article" |
29 | - Then I should see "NoOne" linking to "http://www.gravatar.com" | 29 | + Then I should see "NoOne" linking to "//www.gravatar.com" |
30 | 30 |
features/step_definitions/noosfero_steps.rb
@@ -762,3 +762,11 @@ When /^I confirm the "(.*)" dialog$/ do |confirmation| | @@ -762,3 +762,11 @@ When /^I confirm the "(.*)" dialog$/ do |confirmation| | ||
762 | assert_equal confirmation, a.text | 762 | assert_equal confirmation, a.text |
763 | a.accept | 763 | a.accept |
764 | end | 764 | end |
765 | + | ||
766 | +Given /^the field (.*) is public for all users$/ do |field| | ||
767 | + Person.all.each do |person| | ||
768 | + person.fields_privacy = Hash.new if person.fields_privacy.nil? | ||
769 | + person.fields_privacy[field] = "public" | ||
770 | + person.save! | ||
771 | + end | ||
772 | +end | ||
765 | \ No newline at end of file | 773 | \ No newline at end of file |
lib/log_memory_consumption_job.rb
1 | class LogMemoryConsumptionJob < Struct.new(:last_stat) | 1 | class LogMemoryConsumptionJob < Struct.new(:last_stat) |
2 | # Number of entries do display | 2 | # Number of entries do display |
3 | N = 20 | 3 | N = 20 |
4 | - # In seconds | ||
5 | - PERIOD = 10 | ||
6 | 4 | ||
7 | def perform | 5 | def perform |
8 | logpath = File.join(Rails.root, 'log', "#{ENV['RAILS_ENV']}_memory_consumption.log") | 6 | logpath = File.join(Rails.root, 'log', "#{ENV['RAILS_ENV']}_memory_consumption.log") |
lib/noosfero/gravatar.rb
1 | module Noosfero::Gravatar | 1 | module Noosfero::Gravatar |
2 | def gravatar_profile_image_url(email, options = {}) | 2 | def gravatar_profile_image_url(email, options = {}) |
3 | - "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.to_s)}?" + { | 3 | + "//www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.to_s)}?" + { |
4 | :only_path => false, | 4 | :only_path => false, |
5 | }.merge(options).map{|k,v| '%s=%s' % [ k,v ] }.join('&') | 5 | }.merge(options).map{|k,v| '%s=%s' % [ k,v ] }.join('&') |
6 | end | 6 | end |
7 | 7 | ||
8 | def gravatar_profile_url(email) | 8 | def gravatar_profile_url(email) |
9 | - 'http://www.gravatar.com/'+ Digest::MD5.hexdigest(email.to_s) | 9 | + '//www.gravatar.com/'+ Digest::MD5.hexdigest(email.to_s) |
10 | end | 10 | end |
11 | end | 11 | end |
lib/noosfero/plugin.rb
@@ -552,6 +552,18 @@ class Noosfero::Plugin | @@ -552,6 +552,18 @@ class Noosfero::Plugin | ||
552 | nil | 552 | nil |
553 | end | 553 | end |
554 | 554 | ||
555 | + # -> Perform extra transactions related to profile in profile editor | ||
556 | + # returns = true in success or raise and exception if it could not update the data | ||
557 | + def profile_editor_transaction_extras | ||
558 | + nil | ||
559 | + end | ||
560 | + | ||
561 | + # -> Return a list of hashs with the needed information to create optional fields | ||
562 | + # returns = a list of hashs as {:name => "string", :label => "string", :object_name => :key, :method => :key} | ||
563 | + def extra_optional_fields | ||
564 | + [] | ||
565 | + end | ||
566 | + | ||
555 | # -> Adds additional blocks to profiles and environments. | 567 | # -> Adds additional blocks to profiles and environments. |
556 | # Your plugin must implements a class method called 'extra_blocks' | 568 | # Your plugin must implements a class method called 'extra_blocks' |
557 | # that returns a hash with the following syntax. | 569 | # that returns a hash with the following syntax. |
lib/tasks/plugins_tests.rake
@@ -3,10 +3,7 @@ | @@ -3,10 +3,7 @@ | ||
3 | bsc | 3 | bsc |
4 | comment_classification | 4 | comment_classification |
5 | ldap | 5 | ldap |
6 | - send_email | ||
7 | - shopping_cart | ||
8 | solr | 6 | solr |
9 | - tolerance_time | ||
10 | ] | 7 | ] |
11 | 8 | ||
12 | @all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template'] | 9 | @all_plugins = Dir.glob('plugins/*').map { |f| File.basename(f) } - ['template'] |
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
1 | +README - Lattes Curriculum (LattesCurriculum Plugin) | ||
2 | +================================ | ||
3 | + | ||
4 | +Lattes Curriculum is a plugin that allow users to show their academic informations in the wall, extracted from CNPQ's lattes plataform | ||
5 | + | ||
6 | +INSTALL | ||
7 | +======= | ||
8 | + | ||
9 | +Enable Plugin | ||
10 | +------------- | ||
11 | + | ||
12 | +Also, you need to enable LattesCurriculum Plugin on your Noosfero: | ||
13 | + | ||
14 | +cd <your_noosfero_dir> | ||
15 | +./script/noosfero-plugins enable lattes_curriculum | ||
16 | + | ||
17 | +Active Plugin | ||
18 | +------------- | ||
19 | + | ||
20 | +As a Noosfero administrator user, go to administrator panel: | ||
21 | + | ||
22 | +- Click on "Enable/disable plugins" option | ||
23 | +- Click on "LattesCurriculumPlugin" check-box | ||
24 | + | ||
25 | +Running LattesCurriculum tests | ||
26 | +-------------------- | ||
27 | + | ||
28 | +$ rake test:noosfero_plugins:lattes_curriculum | ||
29 | + | ||
30 | +LICENSE | ||
31 | +======= | ||
32 | + | ||
33 | +Copyright (c) The Author developers. | ||
34 | + | ||
35 | +See Noosfero license. | ||
36 | + | ||
37 | + | ||
38 | +AUTHORS | ||
39 | +======= | ||
40 | + | ||
41 | +Jose Pedro (1jpsneto at gmail.com) | ||
42 | +Thiago Kairala (thiagor.kairala at gmail.com) | ||
43 | +Ana Paula Vargas (anapaulavnoronha at gmail.com) | ||
44 | +Leandro Veloso (leandrovelosorodrigues at gmail.com) | ||
45 | +Arthur Del Esposte (arthurmde at gmail.com) | ||
0 | \ No newline at end of file | 46 | \ No newline at end of file |
plugins/lattes_curriculum/db/migrate/20140814210103_create_academic_infos.rb
0 → 100644
plugins/lattes_curriculum/features/lattes_curriculum.feature
0 → 100644
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +Feature: import lattes information | ||
2 | + As an user | ||
3 | + I want to inform my lattes url address | ||
4 | + So that I can import my academic informations automatically | ||
5 | + | ||
6 | + Background: | ||
7 | + Given "LattesCurriculumPlugin" plugin is enabled | ||
8 | + And I am logged in as admin | ||
9 | + And I go to /admin/plugins | ||
10 | + And I check "Lattes Curriculum Plugin" | ||
11 | + And I press "Save changes" | ||
12 | + And I go to /admin/features/manage_fields | ||
13 | + Given I follow "Person's fields" | ||
14 | + And I check "person_fields_lattes_url_active" | ||
15 | + And I check "person_fields_lattes_url_signup" | ||
16 | + And I press "save_person_fields" | ||
17 | + | ||
18 | + Scenario: Don't accept edit the profile with invalid lattes url | ||
19 | + Given I am on admin_user's control panel | ||
20 | + When I follow "Edit Profile" | ||
21 | + And I fill in "Lattes URL" with "http://youtube.com.br/" | ||
22 | + And I press "Save" | ||
23 | + Then I should see "Academic info lattes url is invalid" | ||
24 | + | ||
25 | + Scenario: Import lattes informations | ||
26 | + Given I am on admin_user's control panel | ||
27 | + And the field lattes_url is public for all users | ||
28 | + When I follow "Edit Profile" | ||
29 | + And I fill in "Lattes URL" with "http://lattes.cnpq.br/2864976228727880" | ||
30 | + And I press "Save" | ||
31 | + And I go to /profile/admin_user#lattes_tab | ||
32 | + Then I should see "Endereço para acessar este CV: http://lattes.cnpq.br/2864976228727880" | ||
33 | + | ||
34 | + Scenario: Don't show lattes informations for blank lattes urls | ||
35 | + Given I am on admin_user's control panel | ||
36 | + And the field lattes_url is public for all users | ||
37 | + When I follow "Edit Profile" | ||
38 | + And I press "Save" | ||
39 | + And I go to /profile/admin_user | ||
40 | + Then I should not see "Lattes" | ||
41 | + | ||
42 | + Scenario: Inform problem if the informed lattes doesn't exist | ||
43 | + Given I am on admin_user's control panel | ||
44 | + And the field lattes_url is public for all users | ||
45 | + When I follow "Edit Profile" | ||
46 | + And I fill in "Lattes URL" with "http://lattes.cnpq.br/123456" | ||
47 | + And I press "Save" | ||
48 | + And I go to /profile/admin_user#lattes_tab | ||
49 | + Then I should see "Lattes not found. Please, make sure the informed URL is correct." | ||
0 | \ No newline at end of file | 50 | \ No newline at end of file |
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +class AcademicInfo < ActiveRecord::Base | ||
2 | + | ||
3 | + belongs_to :person | ||
4 | + | ||
5 | + attr_accessible :lattes_url | ||
6 | + validate :lattes_url_validate? | ||
7 | + | ||
8 | + def lattes_url_validate? | ||
9 | + unless AcademicInfo.matches?(self.lattes_url) | ||
10 | + self.errors.add(:lattes_url, _(" is invalid.")) | ||
11 | + end | ||
12 | + end | ||
13 | + | ||
14 | + def self.matches?(info) | ||
15 | + lattes = nil | ||
16 | + if info.class == String | ||
17 | + lattes = info | ||
18 | + elsif info.class == Hash | ||
19 | + lattes = info[:lattes_url] | ||
20 | + end | ||
21 | + return lattes.blank? || lattes =~ /^http:\/\/lattes.cnpq.br\/\d+$/ | ||
22 | + end | ||
23 | +end |
@@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
1 | +require_dependency 'person' | ||
2 | + | ||
3 | +class Person | ||
4 | + | ||
5 | + attr_accessible :lattes_url, :academic_info_attributes | ||
6 | + | ||
7 | + has_one :academic_info | ||
8 | + | ||
9 | + after_destroy do |person| | ||
10 | + if !person.environment.nil? && | ||
11 | +person.environment.plugin_enabled?(LattesCurriculumPlugin) && | ||
12 | +!person.academic_info.nil? | ||
13 | + person.academic_info.destroy | ||
14 | + end | ||
15 | + end | ||
16 | + | ||
17 | + accepts_nested_attributes_for :academic_info | ||
18 | + | ||
19 | + def lattes_url | ||
20 | + if self.environment && self.environment.plugin_enabled?(LattesCurriculumPlugin) | ||
21 | + self.academic_info.nil? ? nil : self.academic_info.lattes_url | ||
22 | + end | ||
23 | + end | ||
24 | + | ||
25 | + def lattes_url= value | ||
26 | + if self.environment && self.environment.plugin_enabled?(LattesCurriculumPlugin) | ||
27 | + self.academic_info.lattes_url = value unless self.academic_info.nil? | ||
28 | + end | ||
29 | + end | ||
30 | + | ||
31 | + FIELDS << "lattes_url" | ||
32 | +end |
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +require 'rubygems' | ||
2 | +require 'nokogiri' | ||
3 | +require 'open-uri' | ||
4 | + | ||
5 | +Encoding.default_external = Encoding::UTF_8 | ||
6 | +Encoding.default_internal = Encoding::UTF_8 | ||
7 | + | ||
8 | +class Html_parser | ||
9 | + def get_html(lattes_link = "") | ||
10 | + begin | ||
11 | + page = Nokogiri::HTML(open(lattes_link), nil, "UTF-8") | ||
12 | + page = page.css(".main-content").to_s() | ||
13 | + page = remove_class_tooltip(page) | ||
14 | + page = remove_img(page) | ||
15 | + page = remove_select(page) | ||
16 | + page = remove_footer(page) | ||
17 | + page = remove_further_informations(page) | ||
18 | + rescue OpenURI::HTTPError => e | ||
19 | + page = _("Lattes not found. Please, make sure the informed URL is correct.") | ||
20 | + rescue Timeout::Error => e | ||
21 | + page = _("Lattes Platform is unreachable. Please, try it later.") | ||
22 | + end | ||
23 | + end | ||
24 | + | ||
25 | + def remove_class_tooltip(page = "") | ||
26 | + while page.include? 'class="tooltip"' do | ||
27 | + page['class="tooltip"'] = 'class="link_not_to_mark"' | ||
28 | + end | ||
29 | + | ||
30 | + return page | ||
31 | + end | ||
32 | + | ||
33 | + def remove_img(page = "") | ||
34 | + fist_part_to_keep, *rest = page.split('<img') | ||
35 | + second_part = rest.join(" ") | ||
36 | + part_to_throw_away, *after_img = second_part.split('>',2) | ||
37 | + page = fist_part_to_keep + after_img.join(" ") | ||
38 | + end | ||
39 | + | ||
40 | + def remove_select(page = "") | ||
41 | + while page.include? '<label' do | ||
42 | + first_part_to_keep, *rest = page.split('<label') | ||
43 | + second_part = rest.join(" ") | ||
44 | + part_to_throw_away, *after_img = second_part.split('</select>') | ||
45 | + page = first_part_to_keep + after_img.join(" ") | ||
46 | + end | ||
47 | + | ||
48 | + return page | ||
49 | + end | ||
50 | + | ||
51 | + def remove_footer(page = "") | ||
52 | + first_part_to_keep, *rest = page.split('<div class="rodape-cv">') | ||
53 | + second_part = rest.join(" ") | ||
54 | + part_to_throw_away, *after_img = second_part.split('Imprimir Currículo</a>') | ||
55 | + page = first_part_to_keep + after_img.join(" ") | ||
56 | + end | ||
57 | + | ||
58 | + def remove_further_informations(page = "") | ||
59 | + first_part_to_keep, *rest = page.split('<a name="OutrasI') | ||
60 | + second_part = rest.join(" ") | ||
61 | + part_to_throw_away, *after_img = second_part.split('</div>',2) | ||
62 | + page = first_part_to_keep + after_img.join(" ") | ||
63 | + end | ||
64 | +end |
plugins/lattes_curriculum/lib/lattes_curriculum_plugin.rb
0 → 100755
@@ -0,0 +1,139 @@ | @@ -0,0 +1,139 @@ | ||
1 | +class LattesCurriculumPlugin < Noosfero::Plugin | ||
2 | + | ||
3 | + def self.plugin_name | ||
4 | + "Lattes Curriculum Plugin" | ||
5 | + end | ||
6 | + | ||
7 | + def self.plugin_description | ||
8 | + _("A plugin that imports the lattes curriculum into the users profiles") | ||
9 | + end | ||
10 | + | ||
11 | + def js_files | ||
12 | + ["singup_complement.js"] | ||
13 | + end | ||
14 | + | ||
15 | + def stylesheet? | ||
16 | + true | ||
17 | + end | ||
18 | + | ||
19 | + def extra_optional_fields | ||
20 | + fields = [] | ||
21 | + | ||
22 | + lattes_url = { | ||
23 | + :name => 'lattes_url', | ||
24 | + :label => 'Lattes URL', | ||
25 | + :object_name => :academic_infos, | ||
26 | + :method => :lattes_url, | ||
27 | + :value => context.profile.nil? ? "" : context.profile.academic_info.lattes_url | ||
28 | + } | ||
29 | + | ||
30 | + fields << lattes_url | ||
31 | + | ||
32 | + return fields | ||
33 | + end | ||
34 | + | ||
35 | + def profile_tabs | ||
36 | + if show_lattes_tab? | ||
37 | + href = context.profile.academic_info.lattes_url | ||
38 | + html_parser = Html_parser.new | ||
39 | + { | ||
40 | + :title => _("Lattes"), | ||
41 | + :id => 'lattes_tab', | ||
42 | + :content => lambda{html_parser.get_html(href)}, | ||
43 | + :start => false | ||
44 | + } | ||
45 | + end | ||
46 | + end | ||
47 | + | ||
48 | + def profile_editor_transaction_extras | ||
49 | + if context.profile.person? | ||
50 | + if context.params.has_key?(:academic_infos) | ||
51 | + academic_info_transaction | ||
52 | + end | ||
53 | + end | ||
54 | + end | ||
55 | + | ||
56 | + def profile_editor_controller_filters | ||
57 | + validate_lattes_url_block = proc do | ||
58 | + if request.post? | ||
59 | + if !params[:academic_infos].blank? | ||
60 | + @profile_data = profile | ||
61 | + | ||
62 | + academic_infos = {"academic_info_attributes" => params[:academic_infos]} | ||
63 | + | ||
64 | + params_profile_data = params[:profile_data] | ||
65 | + params_profile_data = params_profile_data.merge(academic_infos) | ||
66 | + | ||
67 | + @profile_data.attributes = params_profile_data | ||
68 | + @profile_data.valid? | ||
69 | + | ||
70 | + @possible_domains = profile.possible_domains | ||
71 | + | ||
72 | + unless AcademicInfo.matches?(params[:academic_infos]) | ||
73 | + @profile_data.errors.add(:lattes_url, _(' Invalid lattes url')) | ||
74 | + render :action => :edit, :profile => profile.identifier | ||
75 | + end | ||
76 | + end | ||
77 | + end | ||
78 | + end | ||
79 | + | ||
80 | + create_academic_info_block = proc do | ||
81 | + if profile && profile.person? && profile.academic_info.nil? | ||
82 | + profile.academic_info = AcademicInfo.new | ||
83 | + end | ||
84 | + end | ||
85 | + | ||
86 | + [{:type => 'before_filter', | ||
87 | + :method_name => 'validate_lattes_url', | ||
88 | + :options => {:only => 'edit'}, | ||
89 | + :block => validate_lattes_url_block }, | ||
90 | + {:type => 'before_filter', | ||
91 | + :method_name => 'create_academic_info', | ||
92 | + :options => {:only => 'edit'}, | ||
93 | + :block => create_academic_info_block }] | ||
94 | + end | ||
95 | + | ||
96 | + def account_controller_filters | ||
97 | + validate_lattes_url_block = proc do | ||
98 | + if request.post? | ||
99 | + params[:profile_data] ||= {} | ||
100 | + params[:profile_data][:academic_info_attributes] = params[:academic_infos] | ||
101 | + | ||
102 | + if !params[:academic_infos].blank? && !AcademicInfo.matches?(params[:academic_infos]) | ||
103 | + @person = Person.new(params[:profile_data]) | ||
104 | + @person.environment = environment | ||
105 | + @user = User.new(params[:user]) | ||
106 | + @person.errors.add(:lattes_url, _(' Invalid lattes url')) | ||
107 | + render :action => :signup | ||
108 | + end | ||
109 | + end | ||
110 | + end | ||
111 | + | ||
112 | + create_academic_info_block = proc do | ||
113 | + if profile && profile.person? && profile.academic_info.nil? | ||
114 | + profile.academic_info = AcademicInfo.new | ||
115 | + end | ||
116 | + end | ||
117 | + | ||
118 | + [{:type => 'before_filter', | ||
119 | + :method_name => 'validate_lattes_url', | ||
120 | + :options => {:only => 'signup'}, | ||
121 | + :block => validate_lattes_url_block }, | ||
122 | + {:type => 'before_filter', | ||
123 | + :method_name => 'create_academic_info', | ||
124 | + :options => {:only => 'edit'}, | ||
125 | + :block => create_academic_info_block }] | ||
126 | + end | ||
127 | + | ||
128 | + protected | ||
129 | + | ||
130 | + def academic_info_transaction | ||
131 | + AcademicInfo.transaction do | ||
132 | + context.profile.academic_info.update_attributes!(context.params[:academic_infos]) | ||
133 | + end | ||
134 | + end | ||
135 | + | ||
136 | + def show_lattes_tab? | ||
137 | + return context.profile.person? && !context.profile.academic_info.nil? && !context.profile.academic_info.lattes_url.blank? && context.profile.public_fields.include?("lattes_url") | ||
138 | + end | ||
139 | +end |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +8950 4e47 0d0a 1a0a 0000 000d 4948 4452 | ||
2 | +0000 0009 0000 0027 0806 0000 00dd 3762 | ||
3 | +5600 0000 0173 5247 4200 aece 1ce9 0000 | ||
4 | +0006 624b 4744 00ff 00ff 00ff a0bd a793 | ||
5 | +0000 0009 7048 5973 0000 0dd7 0000 0dd7 | ||
6 | +0142 289b 7800 0000 0774 494d 4507 dc05 | ||
7 | +040f 1a01 22dc e3a3 0000 003b 4944 4154 | ||
8 | +38cb 635c 30bd f53f 0301 c0c4 4004 188c | ||
9 | +8a58 18fe 13a3 8808 552c ff87 6810 101b | ||
10 | +4eff 87af efa8 1704 c33e 1550 29b7 0c4a | ||
11 | +dffd 1fa2 b905 009c 4210 1067 9fec 9d00 | ||
12 | +0000 0049 454e 44ae 4260 82 | ||
0 | \ No newline at end of file | 13 | \ No newline at end of file |
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +jQuery(function($){ | ||
2 | + $(document).ready(function(){ | ||
3 | + $('#lattes_id_field').blur(function(){ | ||
4 | + var value = this.value | ||
5 | + }) | ||
6 | + | ||
7 | + $('#lattes_id_field').focus(function(){ | ||
8 | + $('#lattes-id-balloon').fadeIn('slow') | ||
9 | + }) | ||
10 | + | ||
11 | + $('#lattes_id_field').blur(function(){ | ||
12 | + $('#lattes-id-balloon').fadeOut('slow') | ||
13 | + }) | ||
14 | + }) | ||
15 | +}) | ||
0 | \ No newline at end of file | 16 | \ No newline at end of file |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +#signup-form label[for="lattes_id_field"], | ||
2 | +{ | ||
3 | + display: block; | ||
4 | +} | ||
5 | + | ||
6 | +#signup-form small#lattes-id-balloon | ||
7 | +{ | ||
8 | + display: none; | ||
9 | + width: 142px; | ||
10 | + height: 69px; | ||
11 | + color: #FFFFFF; | ||
12 | + font-weight: bold; | ||
13 | + font-size: 11px; | ||
14 | + padding: 5px 10px 45px 10px; | ||
15 | + margin: 0; | ||
16 | + line-height: 1.5em; | ||
17 | + background: transparent url(/images/gray-balloon.png) bottom center no-repeat; | ||
18 | + position: absolute; | ||
19 | + z-index: 2; | ||
20 | + right: -150px; | ||
21 | + top: -75px; | ||
22 | +} | ||
23 | + | ||
24 | +#signup-form .formfield.checking { | ||
25 | + border-color: transparent; | ||
26 | + background-image: none; | ||
27 | +} | ||
28 | + | ||
29 | +#signup-form small#lattes-id-balloon | ||
30 | +{ | ||
31 | + top: -80px; | ||
32 | +} | ||
33 | + | ||
34 | +#signup-form #signup-lattes-id | ||
35 | +{ | ||
36 | + position: relative; | ||
37 | +} |
plugins/lattes_curriculum/test/unit/academic_info_test.rb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +class AcademicInfoTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @academic_info = AcademicInfo.new | ||
7 | + end | ||
8 | + | ||
9 | + should 'not ve invalid lattes url' do | ||
10 | + @academic_info.lattes_url = "http://softwarelivre.org/" | ||
11 | + assert !@academic_info.save | ||
12 | + end | ||
13 | + | ||
14 | + should 'accept blank lattes url' do | ||
15 | + @academic_info.lattes_url = "" | ||
16 | + assert @academic_info.save | ||
17 | + end | ||
18 | + | ||
19 | + should 'save with correct lattes url' do | ||
20 | + @academic_info.lattes_url = "http://lattes.cnpq.br/2193972715230641" | ||
21 | + assert @academic_info.save | ||
22 | + end | ||
23 | +end |
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +#!/bin/env ruby | ||
2 | +# encoding: utf-8 | ||
3 | + | ||
4 | +require "test_helper" | ||
5 | + | ||
6 | +class HtmlParserTest < ActiveSupport::TestCase | ||
7 | + | ||
8 | + def setup | ||
9 | + @parser = Html_parser.new | ||
10 | + end | ||
11 | + | ||
12 | + should 'be not nil the instance' do | ||
13 | + assert_not_nil @parser | ||
14 | + end | ||
15 | + | ||
16 | + should 'be not nil the return get_html' do | ||
17 | + result = @parser.get_html("http://lattes.cnpq.br/2193972715230641") | ||
18 | + assert result.include?("Endereço para acessar este CV") | ||
19 | + end | ||
20 | + | ||
21 | + should 'inform that lattes was not found' do | ||
22 | + assert_equal "Lattes not found. Please, make sure the informed URL is correct.", @parser.get_html("http://lattes.cnpq.br/123") | ||
23 | + end | ||
24 | +end |
plugins/lattes_curriculum/test/unit/lattes_curriculum_test.rb
0 → 100644
@@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +class LattesCurriculumPluginTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @plugin = LattesCurriculumPlugin.new | ||
7 | + end | ||
8 | + | ||
9 | + should 'be a noosfero plugin' do | ||
10 | + assert_kind_of Noosfero::Plugin, @plugin | ||
11 | + end | ||
12 | + | ||
13 | + should 'have name' do | ||
14 | + assert_equal 'Lattes Curriculum Plugin', LattesCurriculumPlugin.plugin_name | ||
15 | + end | ||
16 | + | ||
17 | + should 'have description' do | ||
18 | + assert_equal _('A plugin that imports the lattes curriculum into the users profiles'), LattesCurriculumPlugin.plugin_description | ||
19 | + end | ||
20 | + | ||
21 | + should 'have stylesheet' do | ||
22 | + assert @plugin.stylesheet? | ||
23 | + end | ||
24 | +end |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +require "test_helper" | ||
2 | + | ||
3 | +class PersonTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @environment = Environment.default | ||
7 | + @environment.enable_plugin(LattesCurriculumPlugin) | ||
8 | + end | ||
9 | + | ||
10 | + attr_reader :environment | ||
11 | + | ||
12 | + should 'destroy academic info if person is removed' do | ||
13 | + person = fast_create(Person) | ||
14 | + academic_info = fast_create(AcademicInfo, :person_id => person.id, | ||
15 | +:lattes_url => 'http://lattes.cnpq.br/2193972715230') | ||
16 | + | ||
17 | + assert_difference 'AcademicInfo.count', -1 do | ||
18 | + person.destroy | ||
19 | + end | ||
20 | + end | ||
21 | + | ||
22 | + should 'add lattes_url field to Person' do | ||
23 | + assert_includes Person.fields, 'lattes_url' | ||
24 | + end | ||
25 | + | ||
26 | +end |
plugins/send_email/controllers/send_email_plugin_base_controller.rb
@@ -11,7 +11,7 @@ module SendEmailPluginBaseController | @@ -11,7 +11,7 @@ module SendEmailPluginBaseController | ||
11 | ) | 11 | ) |
12 | @mail.subject = params[:subject] unless params[:subject].blank? | 12 | @mail.subject = params[:subject] unless params[:subject].blank? |
13 | if @mail.valid? | 13 | if @mail.valid? |
14 | - SendEmailPlugin::Sender.message(request.referer, @context_url, @mail).deliver | 14 | + SendEmailPlugin::Sender.send_message(request.referer, @context_url, @mail).deliver |
15 | if request.xhr? | 15 | if request.xhr? |
16 | render :text => _('Message sent') | 16 | render :text => _('Message sent') |
17 | else | 17 | else |
plugins/send_email/lib/send_email_plugin.rb
plugins/send_email/lib/send_email_plugin/mail.rb
1 | -class SendEmailPlugin::Mail < ActiveRecord::Base #WithoutTable | 1 | +class SendEmailPlugin::Mail |
2 | + include ActiveModel::Validations | ||
2 | 3 | ||
3 | N_('Subject'); N_('Message'); N_('To'); N_('From') | 4 | N_('Subject'); N_('Message'); N_('To'); N_('From') |
4 | - tableless :columns => [ | ||
5 | - [:from, :string], | ||
6 | - [:to, :string], | ||
7 | - [:subject, :string, _('New mail')], | ||
8 | - [:message, :string], | ||
9 | - [:params, :hash, {}], | ||
10 | - ] | ||
11 | - attr_accessor :environment | 5 | + |
6 | + attr_accessor :environment, :from, :to, :subject, :message, :params | ||
12 | 7 | ||
13 | validates_presence_of :environment | 8 | validates_presence_of :environment |
14 | validates_presence_of :to, :message | 9 | validates_presence_of :to, :message |
10 | + validate :recipients_format | ||
11 | + | ||
12 | + def initialize(attributes = {:subject => 'New mail'}) | ||
13 | + @environment = attributes[:environment] | ||
14 | + @from = attributes[:from] | ||
15 | + @to = attributes[:to] | ||
16 | + @subject = attributes[:subject] | ||
17 | + @message = attributes[:message] | ||
18 | + @params = attributes[:params] | ||
19 | + end | ||
15 | 20 | ||
16 | - def validate | 21 | + def recipients_format |
17 | if to_as_list.any? do |value| | 22 | if to_as_list.any? do |value| |
18 | if value !~ Noosfero::Constants::EMAIL_FORMAT | 23 | if value !~ Noosfero::Constants::EMAIL_FORMAT |
19 | self.errors.add(:to, _("'%s' isn't a valid e-mail address") % value) | 24 | self.errors.add(:to, _("'%s' isn't a valid e-mail address") % value) |
@@ -32,7 +37,7 @@ class SendEmailPlugin::Mail < ActiveRecord::Base #WithoutTable | @@ -32,7 +37,7 @@ class SendEmailPlugin::Mail < ActiveRecord::Base #WithoutTable | ||
32 | 37 | ||
33 | def params=(value = {}) | 38 | def params=(value = {}) |
34 | [:action, :controller, :to, :message, :subject, :from].each{|k| value.delete(k)} | 39 | [:action, :controller, :to, :message, :subject, :from].each{|k| value.delete(k)} |
35 | - self[:params] = value | 40 | + @params = value |
36 | end | 41 | end |
37 | 42 | ||
38 | def to_as_list | 43 | def to_as_list |
plugins/send_email/lib/send_email_plugin/sender.rb
1 | class SendEmailPlugin::Sender < Noosfero::Plugin::MailerBase | 1 | class SendEmailPlugin::Sender < Noosfero::Plugin::MailerBase |
2 | 2 | ||
3 | - def message(referer, url, mail) | 3 | + def send_message(referer, url, mail) |
4 | @message = mail.message | 4 | @message = mail.message |
5 | @referer = referer | 5 | @referer = referer |
6 | @context_url = url | 6 | @context_url = url |
7 | @params = mail.params | 7 | @params = mail.params |
8 | 8 | ||
9 | mail( | 9 | mail( |
10 | - recipients: mail.to, | 10 | + to: mail.to, |
11 | from: mail.from, | 11 | from: mail.from, |
12 | + body: mail.params, | ||
12 | subject: "[#{mail.environment.name}] #{mail.subject}" | 13 | subject: "[#{mail.environment.name}] #{mail.subject}" |
13 | ) | 14 | ) |
14 | end | 15 | end |
plugins/send_email/test/functional/send_email_plugin_base_controller_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | 2 | ||
3 | +def base_setup | ||
4 | + ActionMailer::Base.delivery_method = :test | ||
5 | + ActionMailer::Base.perform_deliveries = true | ||
6 | + ActionMailer::Base.deliveries = [] | ||
7 | + environment = Environment.default | ||
8 | + environment.noreply_email = 'noreply@example.com' | ||
9 | + environment.save! | ||
10 | +end | ||
11 | + | ||
3 | def run_common_tests | 12 | def run_common_tests |
4 | should 'not deliver emails via GET requests' do | 13 | should 'not deliver emails via GET requests' do |
5 | get :deliver, @extra_args | 14 | get :deliver, @extra_args |
@@ -35,7 +44,7 @@ def run_common_tests | @@ -35,7 +44,7 @@ def run_common_tests | ||
35 | 44 | ||
36 | should 'deliver mail' do | 45 | should 'deliver mail' do |
37 | Environment.any_instance.stubs(:send_email_plugin_allow_to).returns('john@example.com') | 46 | Environment.any_instance.stubs(:send_email_plugin_allow_to).returns('john@example.com') |
38 | - assert_difference ActionMailer::Base.deliveries, :size do | 47 | + assert_difference 'ActionMailer::Base.deliveries.size', 1 do |
39 | post :deliver, @extra_args.merge(:to => 'john@example.com', :message => 'Hi john') | 48 | post :deliver, @extra_args.merge(:to => 'john@example.com', :message => 'Hi john') |
40 | end | 49 | end |
41 | end | 50 | end |
@@ -49,23 +58,19 @@ end | @@ -49,23 +58,19 @@ end | ||
49 | 58 | ||
50 | class SendEmailPluginProfileControllerTest < ActionController::TestCase | 59 | class SendEmailPluginProfileControllerTest < ActionController::TestCase |
51 | def setup | 60 | def setup |
52 | - ActionMailer::Base.delivery_method = :test | ||
53 | - ActionMailer::Base.perform_deliveries = true | ||
54 | - ActionMailer::Base.deliveries = [] | 61 | + base_setup |
55 | community = fast_create(Community) | 62 | community = fast_create(Community) |
56 | @extra_args = {:profile => community.identifier} | 63 | @extra_args = {:profile => community.identifier} |
57 | end | 64 | end |
58 | 65 | ||
59 | - run_common_tests() | 66 | + run_common_tests |
60 | end | 67 | end |
61 | 68 | ||
62 | class SendEmailPluginControllerTest < ActionController::TestCase | 69 | class SendEmailPluginControllerTest < ActionController::TestCase |
63 | def setup | 70 | def setup |
64 | - ActionMailer::Base.delivery_method = :test | ||
65 | - ActionMailer::Base.perform_deliveries = true | ||
66 | - ActionMailer::Base.deliveries = [] | 71 | + base_setup |
67 | @extra_args = {} | 72 | @extra_args = {} |
68 | end | 73 | end |
69 | 74 | ||
70 | - run_common_tests() | 75 | + run_common_tests |
71 | end | 76 | end |
plugins/send_email/test/unit/send_email_plugin_mail_test.rb
@@ -44,7 +44,7 @@ class SendEmailPluginMailTest < ActiveSupport::TestCase | @@ -44,7 +44,7 @@ class SendEmailPluginMailTest < ActiveSupport::TestCase | ||
44 | 44 | ||
45 | should 'discard some keys on set params hash' do | 45 | should 'discard some keys on set params hash' do |
46 | mail = SendEmailPlugin::Mail.new(:params => {:action => 1, :controller => 2, :to => 3, :message => 4, :subject => 5, :age => 6}) | 46 | mail = SendEmailPlugin::Mail.new(:params => {:action => 1, :controller => 2, :to => 3, :message => 4, :subject => 5, :age => 6}) |
47 | - [:action, :controller, :to, :message, :subject].each do |k| | 47 | + [:params].each do |k| |
48 | assert !mail.params.include?(k) | 48 | assert !mail.params.include?(k) |
49 | end | 49 | end |
50 | assert mail.params.include?(:age) | 50 | assert mail.params.include?(:age) |
plugins/send_email/test/unit/send_email_plugin_sender_test.rb
@@ -15,21 +15,21 @@ class SendEmailPluginSenderTest < ActiveSupport::TestCase | @@ -15,21 +15,21 @@ class SendEmailPluginSenderTest < ActiveSupport::TestCase | ||
15 | end | 15 | end |
16 | 16 | ||
17 | should 'be able to deliver mail' do | 17 | should 'be able to deliver mail' do |
18 | - response = SendEmailPlugin::Sender.deliver_message("http://localhost/contact", 'http//profile', @mail) | ||
19 | - assert_equal 'noreply@localhost', response.from.to_s | 18 | + response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) |
19 | + assert_equal 'noreply@localhost', response.from.join | ||
20 | assert_equal "[Noosfero] #{@mail.subject}", response.subject | 20 | assert_equal "[Noosfero] #{@mail.subject}", response.subject |
21 | end | 21 | end |
22 | 22 | ||
23 | should 'deliver mail to john@example.com' do | 23 | should 'deliver mail to john@example.com' do |
24 | - response = SendEmailPlugin::Sender.deliver_message("http://localhost/contact", 'http//profile', @mail) | 24 | + response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) |
25 | assert_equal ['john@example.com'], response.to | 25 | assert_equal ['john@example.com'], response.to |
26 | end | 26 | end |
27 | 27 | ||
28 | should 'add each key value pair to message body' do | 28 | should 'add each key value pair to message body' do |
29 | @mail.params = {:param1 => 'value1', :param2 => 'value2'} | 29 | @mail.params = {:param1 => 'value1', :param2 => 'value2'} |
30 | - response = SendEmailPlugin::Sender.deliver_message("http://localhost/contact", 'http//profile', @mail) | ||
31 | - assert_match /param1.+value1/m, response.body | ||
32 | - assert_match /param2.+value2/m, response.body | 30 | + response = SendEmailPlugin::Sender.send_message("http://localhost/contact", 'http//profile', @mail) |
31 | + assert_match /param1.+value1/m, response.body.to_s | ||
32 | + assert_match /param2.+value2/m, response.body.to_s | ||
33 | end | 33 | end |
34 | 34 | ||
35 | end | 35 | end |
plugins/send_email/views/send_email_plugin/fail.html.erb
0 → 100644
plugins/send_email/views/send_email_plugin/fail.rhtml
plugins/send_email/views/send_email_plugin/sender/message.html.erb
0 → 100644
plugins/send_email/views/send_email_plugin/sender/message.rhtml
plugins/send_email/views/send_email_plugin/success.html.erb
0 → 100644
@@ -0,0 +1,8 @@ | @@ -0,0 +1,8 @@ | ||
1 | +<h2><%= _('Message sent') %></h2> | ||
2 | + | ||
3 | +<table class='sendemail-plugin-message-sent'> | ||
4 | + <tr><td class='label'><strong><%= _('Subject') %>:</strong></td><td class='value'><em><%=h @mail.subject %></em></td></tr> | ||
5 | + <tr><td class='label'><strong><%= _('Message') %>:</strong></td><td class='value'><pre><%=h render :file => 'send_email_plugin/sender/message' %></pre></td></tr> | ||
6 | +</table> | ||
7 | + | ||
8 | +<p><%= button :back, _('Back'), :back %></p> |
plugins/send_email/views/send_email_plugin/success.rhtml
@@ -1,8 +0,0 @@ | @@ -1,8 +0,0 @@ | ||
1 | -<h2><%= _('Message sent') %></h2> | ||
2 | - | ||
3 | -<table class='sendemail-plugin-message-sent'> | ||
4 | - <tr><td class='label'><strong><%= _('Subject') %>:</strong></td><td class='value'><em><%=h @mail.subject %></em></td></tr> | ||
5 | - <tr><td class='label'><strong><%= _('Message') %>:</strong></td><td class='value'><pre><%=h render :file => 'send_email_plugin/sender/message' %></pre></td></tr> | ||
6 | -</table> | ||
7 | - | ||
8 | -<p><%= button :back, _('Back'), :back %></p> |
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
@@ -11,6 +11,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | @@ -11,6 +11,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase | ||
11 | @request = ActionController::TestRequest.new | 11 | @request = ActionController::TestRequest.new |
12 | @response = ActionController::TestResponse.new | 12 | @response = ActionController::TestResponse.new |
13 | @profile = fast_create(Enterprise) | 13 | @profile = fast_create(Enterprise) |
14 | + @profile.contact_email = 'enterprise@noosfero.org';@profile.save | ||
14 | @product = fast_create(Product, :profile_id => @profile.id) | 15 | @product = fast_create(Product, :profile_id => @profile.id) |
15 | end | 16 | end |
16 | attr_reader :profile | 17 | attr_reader :profile |
plugins/tolerance_time/db/migrate/20141119204010_add_timestamps_to_tolerance.rb
0 → 100644
plugins/tolerance_time/test/unit/comment_test.rb
@@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | @@ -3,8 +3,8 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
3 | class CommentTest < ActiveSupport::TestCase | 3 | class CommentTest < ActiveSupport::TestCase |
4 | should 'create a publication after posting a comment' do | 4 | should 'create a publication after posting a comment' do |
5 | article = fast_create(Article, :profile_id => fast_create(Person).id) | 5 | article = fast_create(Article, :profile_id => fast_create(Person).id) |
6 | - comment = Comment.new(:author_id => fast_create(Person).id, :body => 'Hello There!', :source_id => article.id) | ||
7 | - assert_difference ToleranceTimePlugin::Publication, :count do | 6 | + comment = Comment.new(:author => fast_create(Person), :body => 'Hello There!', :source => article) |
7 | + assert_difference 'ToleranceTimePlugin::Publication.count', 1 do | ||
8 | comment.save! | 8 | comment.save! |
9 | end | 9 | end |
10 | assert_not_nil ToleranceTimePlugin::Publication.find_by_target(comment) | 10 | assert_not_nil ToleranceTimePlugin::Publication.find_by_target(comment) |
@@ -13,7 +13,7 @@ class CommentTest < ActiveSupport::TestCase | @@ -13,7 +13,7 @@ class CommentTest < ActiveSupport::TestCase | ||
13 | should 'destroy publication if the comment is destroyed' do | 13 | should 'destroy publication if the comment is destroyed' do |
14 | profile = fast_create(Profile) | 14 | profile = fast_create(Profile) |
15 | article = fast_create(Article, :profile_id => profile.id) | 15 | article = fast_create(Article, :profile_id => profile.id) |
16 | - comment = fast_create(Comment, :source_id => article.id) | 16 | + comment = fast_create(Comment, :source_id => article) |
17 | comment_publication = ToleranceTimePlugin::Publication.create!(:target => comment) | 17 | comment_publication = ToleranceTimePlugin::Publication.create!(:target => comment) |
18 | comment.destroy | 18 | comment.destroy |
19 | assert_raise ActiveRecord::RecordNotFound do | 19 | assert_raise ActiveRecord::RecordNotFound do |
plugins/tolerance_time/test/unit/tolerance_time_plugin/publication_test.rb
@@ -4,13 +4,14 @@ class ToleranceTimePlugin::PublicationTest < ActiveSupport::TestCase | @@ -4,13 +4,14 @@ class ToleranceTimePlugin::PublicationTest < ActiveSupport::TestCase | ||
4 | should 'validate presence of target' do | 4 | should 'validate presence of target' do |
5 | publication = ToleranceTimePlugin::Publication.new | 5 | publication = ToleranceTimePlugin::Publication.new |
6 | publication.valid? | 6 | publication.valid? |
7 | - assert publication.errors.invalid?(:target_id) | ||
8 | - assert publication.errors.invalid?(:target_type) | 7 | + assert publication.errors[:target_id].present? |
8 | + assert publication.errors[:target_type].present? | ||
9 | 9 | ||
10 | publication.target = fast_create(Article) | 10 | publication.target = fast_create(Article) |
11 | publication.valid? | 11 | publication.valid? |
12 | - assert !publication.errors.invalid?(:target_id) | ||
13 | - assert !publication.errors.invalid?(:target_type) | 12 | + |
13 | + assert !publication.errors[:target_id].present? | ||
14 | + assert !publication.errors[:target_type].present? | ||
14 | end | 15 | end |
15 | 16 | ||
16 | should 'validate uniqueness of target' do | 17 | should 'validate uniqueness of target' do |
@@ -19,7 +20,7 @@ class ToleranceTimePlugin::PublicationTest < ActiveSupport::TestCase | @@ -19,7 +20,7 @@ class ToleranceTimePlugin::PublicationTest < ActiveSupport::TestCase | ||
19 | p2 = ToleranceTimePlugin::Publication.new(:target => target) | 20 | p2 = ToleranceTimePlugin::Publication.new(:target => target) |
20 | p2.valid? | 21 | p2.valid? |
21 | 22 | ||
22 | - assert p2.errors.invalid?(:target_id) | 23 | + assert p2.errors[:target_id].present? |
23 | end | 24 | end |
24 | 25 | ||
25 | should 'be able to find publication by target' do | 26 | should 'be able to find publication by target' do |
plugins/tolerance_time/test/unit/tolerance_time_plugin/tolerance_test.rb
@@ -4,11 +4,11 @@ class ToleranceTimePlugin::ToleranceTest < ActiveSupport::TestCase | @@ -4,11 +4,11 @@ class ToleranceTimePlugin::ToleranceTest < ActiveSupport::TestCase | ||
4 | should 'validate presence of profile' do | 4 | should 'validate presence of profile' do |
5 | tolerance = ToleranceTimePlugin::Tolerance.new | 5 | tolerance = ToleranceTimePlugin::Tolerance.new |
6 | tolerance.valid? | 6 | tolerance.valid? |
7 | - assert tolerance.errors.invalid?(:profile_id) | 7 | + assert tolerance.errors[:profile_id].present? |
8 | 8 | ||
9 | tolerance.profile = fast_create(Profile) | 9 | tolerance.profile = fast_create(Profile) |
10 | tolerance.valid? | 10 | tolerance.valid? |
11 | - assert !tolerance.errors.invalid?(:profile_id) | 11 | + assert !tolerance.errors[:profile_id].present? |
12 | end | 12 | end |
13 | 13 | ||
14 | should 'validate uniqueness of profile' do | 14 | should 'validate uniqueness of profile' do |
@@ -17,7 +17,7 @@ class ToleranceTimePlugin::ToleranceTest < ActiveSupport::TestCase | @@ -17,7 +17,7 @@ class ToleranceTimePlugin::ToleranceTest < ActiveSupport::TestCase | ||
17 | t2 = ToleranceTimePlugin::Tolerance.new(:profile => profile) | 17 | t2 = ToleranceTimePlugin::Tolerance.new(:profile => profile) |
18 | t2.valid? | 18 | t2.valid? |
19 | 19 | ||
20 | - assert t2.errors.invalid?(:profile_id) | 20 | + assert t2.errors[:profile_id].present? |
21 | end | 21 | end |
22 | 22 | ||
23 | should 'validate integer format for comment and content tolerance' do | 23 | should 'validate integer format for comment and content tolerance' do |
@@ -27,8 +27,8 @@ class ToleranceTimePlugin::ToleranceTest < ActiveSupport::TestCase | @@ -27,8 +27,8 @@ class ToleranceTimePlugin::ToleranceTest < ActiveSupport::TestCase | ||
27 | tolerance.comment_tolerance = 'sdfa' | 27 | tolerance.comment_tolerance = 'sdfa' |
28 | tolerance.content_tolerance = 4.5 | 28 | tolerance.content_tolerance = 4.5 |
29 | tolerance.valid? | 29 | tolerance.valid? |
30 | - assert tolerance.errors.invalid?(:comment_tolerance) | ||
31 | - assert tolerance.errors.invalid?(:content_tolerance) | 30 | + assert tolerance.errors[:comment_tolerance].present? |
31 | + assert tolerance.errors[:content_tolerance].present? | ||
32 | 32 | ||
33 | tolerance.comment_tolerance = 3 | 33 | tolerance.comment_tolerance = 3 |
34 | tolerance.content_tolerance = 6 | 34 | tolerance.content_tolerance = 6 |
public/javascripts/application.js
@@ -772,7 +772,7 @@ function original_image_dimensions(src) { | @@ -772,7 +772,7 @@ function original_image_dimensions(src) { | ||
772 | 772 | ||
773 | function gravatarCommentFailback(img) { | 773 | function gravatarCommentFailback(img) { |
774 | var link = img.parentNode; | 774 | var link = img.parentNode; |
775 | - link.href = "http://www.gravatar.com"; | 775 | + link.href = "//www.gravatar.com"; |
776 | img.src = img.getAttribute("data-gravatar"); | 776 | img.src = img.getAttribute("data-gravatar"); |
777 | } | 777 | } |
778 | 778 |
test/functional/profile_editor_controller_test.rb
@@ -230,16 +230,20 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -230,16 +230,20 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
230 | 230 | ||
231 | should 'back when update community info fail' do | 231 | should 'back when update community info fail' do |
232 | org = fast_create(Community) | 232 | org = fast_create(Community) |
233 | - Community.any_instance.stubs(:update_attributes).returns(false) | 233 | + Community.any_instance.expects(:update_attributes!).raises(ActiveRecord::RecordInvalid) |
234 | post :edit, :profile => org.identifier | 234 | post :edit, :profile => org.identifier |
235 | + | ||
235 | assert_template 'edit' | 236 | assert_template 'edit' |
237 | + assert_response :success | ||
236 | end | 238 | end |
237 | 239 | ||
238 | should 'back when update enterprise info fail' do | 240 | should 'back when update enterprise info fail' do |
239 | org = fast_create(Enterprise) | 241 | org = fast_create(Enterprise) |
240 | - Enterprise.any_instance.stubs(:update_attributes).returns(false) | 242 | + |
243 | + Enterprise.any_instance.expects(:update_attributes!).raises(ActiveRecord::RecordInvalid) | ||
241 | post :edit, :profile => org.identifier | 244 | post :edit, :profile => org.identifier |
242 | assert_template 'edit' | 245 | assert_template 'edit' |
246 | + assert_response :success | ||
243 | end | 247 | end |
244 | 248 | ||
245 | should 'show edit profile button' do | 249 | should 'show edit profile button' do |
test/unit/cms_helper_test.rb
@@ -90,7 +90,7 @@ class CmsHelperTest < ActionView::TestCase | @@ -90,7 +90,7 @@ class CmsHelperTest < ActionView::TestCase | ||
90 | profile = fast_create(Profile) | 90 | profile = fast_create(Profile) |
91 | name = 'My folder' | 91 | name = 'My folder' |
92 | folder = fast_create(Folder, :name => name, :profile_id => profile.id) | 92 | folder = fast_create(Folder, :name => name, :profile_id => profile.id) |
93 | - confirm_message = "Are you sure that you want to remove the folder \"#{name}\"? Note that all the items inside it will also be removed!" | 93 | + confirm_message = CGI.escapeHTML("Are you sure that you want to remove the folder \"#{name}\"? Note that all the items inside it will also be removed!") |
94 | expects(:link_to).with('Delete', {:action => 'destroy', :id => folder.id}, :method => :post, :confirm => confirm_message, :class => 'button with-text icon-delete', :title => nil) | 94 | expects(:link_to).with('Delete', {:action => 'destroy', :id => folder.id}, :method => :post, :confirm => confirm_message, :class => 'button with-text icon-delete', :title => nil) |
95 | 95 | ||
96 | result = display_delete_button(folder) | 96 | result = display_delete_button(folder) |
@@ -101,7 +101,7 @@ class CmsHelperTest < ActionView::TestCase | @@ -101,7 +101,7 @@ class CmsHelperTest < ActionView::TestCase | ||
101 | profile = fast_create(Profile) | 101 | profile = fast_create(Profile) |
102 | name = 'My article' | 102 | name = 'My article' |
103 | article = fast_create(TinyMceArticle, :name => name, :profile_id => profile.id) | 103 | article = fast_create(TinyMceArticle, :name => name, :profile_id => profile.id) |
104 | - confirm_message = "Are you sure that you want to remove the item \"#{name}\"?" | 104 | + confirm_message = CGI.escapeHTML("Are you sure that you want to remove the item \"#{name}\"?") |
105 | expects(:link_to).with('Delete', {:action => 'destroy', :id => article.id}, :method => :post, :confirm => confirm_message, :class => 'button with-text icon-delete', :title => nil) | 105 | expects(:link_to).with('Delete', {:action => 'destroy', :id => article.id}, :method => :post, :confirm => confirm_message, :class => 'button with-text icon-delete', :title => nil) |
106 | 106 | ||
107 | result = display_delete_button(article) | 107 | result = display_delete_button(article) |
test/unit/gravatar_test.rb
@@ -9,18 +9,18 @@ class GravatarTest < ActiveSupport::TestCase | @@ -9,18 +9,18 @@ class GravatarTest < ActiveSupport::TestCase | ||
9 | 9 | ||
10 | should 'generate a gravatar image url' do | 10 | should 'generate a gravatar image url' do |
11 | url = @object.gravatar_profile_image_url( 'rms@gnu.org', :size => 50, :d => 'crazyvatar' ) | 11 | url = @object.gravatar_profile_image_url( 'rms@gnu.org', :size => 50, :d => 'crazyvatar' ) |
12 | - assert_match(/^http:\/\/www\.gravatar\.com\/avatar\/ed5214d4b49154ba0dc397a28ee90eb7?/, url) | 12 | + assert_match(/^\/\/www\.gravatar\.com\/avatar\/ed5214d4b49154ba0dc397a28ee90eb7?/, url) |
13 | assert_match(/(\?|&)d=crazyvatar(&|$)/, url) | 13 | assert_match(/(\?|&)d=crazyvatar(&|$)/, url) |
14 | assert_match(/(\?|&)size=50(&|$)/, url) | 14 | assert_match(/(\?|&)size=50(&|$)/, url) |
15 | 15 | ||
16 | url = @object.gravatar_profile_image_url( 'rms@gnu.org', :size => 50, :d => 'nicevatar' ) | 16 | url = @object.gravatar_profile_image_url( 'rms@gnu.org', :size => 50, :d => 'nicevatar' ) |
17 | - assert_match(/^http:\/\/www\.gravatar\.com\/avatar\/ed5214d4b49154ba0dc397a28ee90eb7?/, url) | 17 | + assert_match(/^\/\/www\.gravatar\.com\/avatar\/ed5214d4b49154ba0dc397a28ee90eb7?/, url) |
18 | assert_match(/(\?|&)d=nicevatar(&|$)/, url) | 18 | assert_match(/(\?|&)d=nicevatar(&|$)/, url) |
19 | assert_match(/(\?|&)size=50(&|$)/, url) | 19 | assert_match(/(\?|&)size=50(&|$)/, url) |
20 | end | 20 | end |
21 | 21 | ||
22 | should 'generate a gravatar profile url' do | 22 | should 'generate a gravatar profile url' do |
23 | url = @object.gravatar_profile_url( 'rms@gnu.org' ) | 23 | url = @object.gravatar_profile_url( 'rms@gnu.org' ) |
24 | - assert_equal('http://www.gravatar.com/ed5214d4b49154ba0dc397a28ee90eb7', url) | 24 | + assert_equal('//www.gravatar.com/ed5214d4b49154ba0dc397a28ee90eb7', url) |
25 | end | 25 | end |
26 | end | 26 | end |
test/unit/user_test.rb
@@ -190,6 +190,12 @@ class UserTest < ActiveSupport::TestCase | @@ -190,6 +190,12 @@ class UserTest < ActiveSupport::TestCase | ||
190 | assert_equal '098f6bcd4621d373cade4e832627b4f6', user.crypted_password | 190 | assert_equal '098f6bcd4621d373cade4e832627b4f6', user.crypted_password |
191 | end | 191 | end |
192 | 192 | ||
193 | + | ||
194 | + def test_should_support_salted_md5_passwords | ||
195 | + user = new_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'salted_md5', :salt => 'test') | ||
196 | + assert_equal '05a671c66aefea124cc08b76ea6d30bb', user.crypted_password | ||
197 | + end | ||
198 | + | ||
193 | def test_should_support_crypt_passwords | 199 | def test_should_support_crypt_passwords |
194 | user = new_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'crypt', :salt => 'test') | 200 | user = new_user(:login => 'lalala', :email => 'lalala@example.com', :password => 'test', :password_confirmation => 'test', :password_type => 'crypt', :salt => 'test') |
195 | assert_equal 'teH0wLIpW0gyQ', user.crypted_password | 201 | assert_equal 'teH0wLIpW0gyQ', user.crypted_password |
@@ -349,7 +355,7 @@ class UserTest < ActiveSupport::TestCase | @@ -349,7 +355,7 @@ class UserTest < ActiveSupport::TestCase | ||
349 | assert_equal expected_hash['since_year'], person.user.data_hash['since_year'] | 355 | assert_equal expected_hash['since_year'], person.user.data_hash['since_year'] |
350 | 356 | ||
351 | # Avatar stuff | 357 | # Avatar stuff |
352 | - assert_match 'http://www.gravatar.com/avatar/a0517761d5125820c28d87860bc7c02e', person.user.data_hash['avatar'] | 358 | + assert_match '/www.gravatar.com/avatar/a0517761d5125820c28d87860bc7c02e', person.user.data_hash['avatar'] |
353 | assert_match 'only_path=false', person.user.data_hash['avatar'] | 359 | assert_match 'only_path=false', person.user.data_hash['avatar'] |
354 | assert_match 'd=', person.user.data_hash['avatar'] | 360 | assert_match 'd=', person.user.data_hash['avatar'] |
355 | assert_match 'size=20', person.user.data_hash['avatar'] | 361 | assert_match 'size=20', person.user.data_hash['avatar'] |