Commit 1cc34ff84b13b611ea88b9d7fb2b037b245f112c
1 parent
2cee8f57
Exists in
staging
and in
19 other branches
rails4: fix all unit tests
Showing
25 changed files
with
165 additions
and
205 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
| @@ -6,7 +6,7 @@ class CmsController < MyProfileController | @@ -6,7 +6,7 @@ class CmsController < MyProfileController | ||
| 6 | 6 | ||
| 7 | def search_tags | 7 | def search_tags |
| 8 | arg = params[:term].downcase | 8 | arg = params[:term].downcase |
| 9 | - result = ActsAsTaggableOn::Tag.where('name ILIKE ?', "%#{arg}%").limit(10) | 9 | + result = Tag.where('name ILIKE ?', "%#{arg}%").limit(10) |
| 10 | render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' | 10 | render :text => prepare_to_token_input_by_label(result).to_json, :content_type => 'application/json' |
| 11 | end | 11 | end |
| 12 | 12 |
app/models/approve_comment.rb
| @@ -8,7 +8,7 @@ class ApproveComment < Task | @@ -8,7 +8,7 @@ class ApproveComment < Task | ||
| 8 | def comment | 8 | def comment |
| 9 | unless @comment || self.comment_attributes.nil? | 9 | unless @comment || self.comment_attributes.nil? |
| 10 | @comment = Comment.new | 10 | @comment = Comment.new |
| 11 | - @comment.assign_attributes(ActiveSupport::JSON.decode(self.comment_attributes), :without_protection => true) | 11 | + @comment.assign_attributes(ActiveSupport::JSON.decode(self.comment_attributes.to_s), :without_protection => true) |
| 12 | end | 12 | end |
| 13 | @comment | 13 | @comment |
| 14 | end | 14 | end |
app/models/create_enterprise.rb
| @@ -22,7 +22,7 @@ class CreateEnterprise < Task | @@ -22,7 +22,7 @@ class CreateEnterprise < Task | ||
| 22 | #checks if the validation method is region to validates | 22 | #checks if the validation method is region to validates |
| 23 | validates_presence_of :region_id, :if => lambda { |obj| obj.environment.organization_approval_method == :region } | 23 | validates_presence_of :region_id, :if => lambda { |obj| obj.environment.organization_approval_method == :region } |
| 24 | 24 | ||
| 25 | - validates_numericality_of :foundation_year, only_integer: true | 25 | + validates_numericality_of :foundation_year, only_integer: true, allow_nil: true |
| 26 | 26 | ||
| 27 | # checks for actual attributes | 27 | # checks for actual attributes |
| 28 | validates_presence_of :requestor_id, :target_id | 28 | validates_presence_of :requestor_id, :target_id |
app/models/organization.rb
| @@ -112,7 +112,7 @@ class Organization < Profile | @@ -112,7 +112,7 @@ class Organization < Profile | ||
| 112 | 112 | ||
| 113 | settings_items :zip_code, :city, :state, :country | 113 | settings_items :zip_code, :city, :state, :country |
| 114 | 114 | ||
| 115 | - validates_format_of :foundation_year, :with => Noosfero::Constants::INTEGER_FORMAT | 115 | + validates_numericality_of :foundation_year, only_integer: true, allow_nil: true |
| 116 | validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |org| !org.contact_email.blank? }) | 116 | validates_format_of :contact_email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda { |org| !org.contact_email.blank? }) |
| 117 | validates_as_cnpj :cnpj | 117 | validates_as_cnpj :cnpj |
| 118 | 118 |
app/models/profile_suggestion.rb
| @@ -55,13 +55,13 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -55,13 +55,13 @@ class ProfileSuggestion < ActiveRecord::Base | ||
| 55 | :threshold => 2, :weight => 1, :connection => 'Profile' | 55 | :threshold => 2, :weight => 1, :connection => 'Profile' |
| 56 | }, | 56 | }, |
| 57 | :people_with_common_tags => { | 57 | :people_with_common_tags => { |
| 58 | - :threshold => 2, :weight => 1, :connection => 'ActsAsTaggableOn::Tag' | 58 | + :threshold => 2, :weight => 1, :connection => 'Tag' |
| 59 | }, | 59 | }, |
| 60 | :communities_with_common_friends => { | 60 | :communities_with_common_friends => { |
| 61 | :threshold => 2, :weight => 1, :connection => 'Profile' | 61 | :threshold => 2, :weight => 1, :connection => 'Profile' |
| 62 | }, | 62 | }, |
| 63 | :communities_with_common_tags => { | 63 | :communities_with_common_tags => { |
| 64 | - :threshold => 2, :weight => 1, :connection => 'ActsAsTaggableOn::Tag' | 64 | + :threshold => 2, :weight => 1, :connection => 'Tag' |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| @@ -127,17 +127,15 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -127,17 +127,15 @@ class ProfileSuggestion < ActiveRecord::Base | ||
| 127 | rescue NoMethodError | 127 | rescue NoMethodError |
| 128 | next | 128 | next |
| 129 | end | 129 | end |
| 130 | - connections = suggested_profile.send("#{rule}_connections") | ||
| 131 | - if connections.present? | ||
| 132 | - connections = connections[1..-2].split(',') | ||
| 133 | - else | ||
| 134 | - connections = [] | ||
| 135 | - end | ||
| 136 | - suggestion.send("#{rule}=", value) | 130 | + |
| 131 | + connections = suggested_profile.send("#{rule}_connections") || [] | ||
| 132 | + connections = connections[1..-2] if connections.present? | ||
| 137 | connections.each do |connection_id| | 133 | connections.each do |connection_id| |
| 138 | next if SuggestionConnection.where(:suggestion_id => suggestion.id, :connection_id => connection_id, :connection_type => options[:connection]).present? | 134 | next if SuggestionConnection.where(:suggestion_id => suggestion.id, :connection_id => connection_id, :connection_type => options[:connection]).present? |
| 139 | SuggestionConnection.create!(:suggestion => suggestion, :connection_id => connection_id, :connection_type => options[:connection]) | 135 | SuggestionConnection.create!(:suggestion => suggestion, :connection_id => connection_id, :connection_type => options[:connection]) |
| 140 | end | 136 | end |
| 137 | + | ||
| 138 | + suggestion.send("#{rule}=", value) | ||
| 141 | suggestion.score += value * options[:weight] | 139 | suggestion.score += value * options[:weight] |
| 142 | end | 140 | end |
| 143 | suggestion.save! | 141 | suggestion.save! |
| @@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
| 1 | +Tag = ActsAsTaggableOn::Tag | ||
| 2 | +class Tag | ||
| 3 | + | ||
| 4 | + attr_accessible :name, :parent_id, :pending | ||
| 5 | + | ||
| 6 | + has_many :children, class_name: 'Tag', foreign_key: 'parent_id', dependent: :destroy | ||
| 7 | + | ||
| 8 | + @@original_find = self.method(:find) | ||
| 9 | + # Rename the find method to find_with_pendings that includes all tags in the search regardless if its pending or not | ||
| 10 | + def self.find_with_pendings(*args) | ||
| 11 | + @@original_find.call(*args) | ||
| 12 | + end | ||
| 13 | + | ||
| 14 | + # Redefine the find method to exclude the pending tags from the search not allowing to tag something with an unapproved tag | ||
| 15 | + def self.find(*args) | ||
| 16 | + self.where(pending: false).find_with_pendings(*args) | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | + # Return all the tags that were suggested but not yet approved | ||
| 20 | + def self.find_pendings | ||
| 21 | + self.where(pending: true) | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops | ||
| 25 | + def parent_candidates | ||
| 26 | + ActsAsTaggableOn::Tag.all - descendents - [self] | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | + # All tags that have this tag as its one of its ancestors | ||
| 30 | + def descendents | ||
| 31 | + children.to_a.sum([], &:descendents) + children | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | +end |
lib/acts_as_having_settings.rb
| @@ -21,6 +21,12 @@ end | @@ -21,6 +21,12 @@ end | ||
| 21 | 21 | ||
| 22 | module ActsAsHavingSettings | 22 | module ActsAsHavingSettings |
| 23 | 23 | ||
| 24 | + def self.type_cast value, type | ||
| 25 | + # do not cast nil | ||
| 26 | + return value if value.nil? | ||
| 27 | + type.send :cast_value, value | ||
| 28 | + end | ||
| 29 | + | ||
| 24 | module ClassMethods | 30 | module ClassMethods |
| 25 | 31 | ||
| 26 | def acts_as_having_settings(*args) | 32 | def acts_as_having_settings(*args) |
| @@ -50,13 +56,12 @@ module ActsAsHavingSettings | @@ -50,13 +56,12 @@ module ActsAsHavingSettings | ||
| 50 | settings_items *args | 56 | settings_items *args |
| 51 | end | 57 | end |
| 52 | 58 | ||
| 53 | - def settings_items(*names) | 59 | + def settings_items *names |
| 54 | 60 | ||
| 55 | - options = names.last.is_a?(Hash) ? names.pop : {} | ||
| 56 | - default = if !options[:default].nil? then options[:default] else nil end | ||
| 57 | - data_type = options[:type] | ||
| 58 | - data_type = if data_type.present? then data_type.to_s.camelize.to_sym else :String end | ||
| 59 | - data_type = ActiveRecord::Type.const_get(data_type).new | 61 | + options = names.extract_options! |
| 62 | + default = options[:default] | ||
| 63 | + type = options[:type] | ||
| 64 | + type = if type.present? then ActiveRecord::Type.const_get(type.to_s.camelize.to_sym).new else nil end | ||
| 60 | 65 | ||
| 61 | names.each do |setting| | 66 | names.each do |setting| |
| 62 | # symbolize key | 67 | # symbolize key |
| @@ -65,19 +70,17 @@ module ActsAsHavingSettings | @@ -65,19 +70,17 @@ module ActsAsHavingSettings | ||
| 65 | define_method setting do | 70 | define_method setting do |
| 66 | h = send self.class.settings_field | 71 | h = send self.class.settings_field |
| 67 | val = h[setting] | 72 | val = h[setting] |
| 68 | - if val.nil? then (if default.is_a? String then gettext default else default end) else val end | 73 | + # translate default value if it is used |
| 74 | + if not val.nil? then val elsif default.is_a? String then gettext default else default end | ||
| 69 | end | 75 | end |
| 76 | + | ||
| 70 | define_method "#{setting}=" do |value| | 77 | define_method "#{setting}=" do |value| |
| 71 | h = send self.class.settings_field | 78 | h = send self.class.settings_field |
| 72 | - h[setting] = self.class.acts_as_having_settings_type_cast value, data_type | 79 | + h[setting] = if type then ActsAsHavingSettings.type_cast value, type else value end |
| 73 | end | 80 | end |
| 74 | end | 81 | end |
| 75 | end | 82 | end |
| 76 | 83 | ||
| 77 | - def acts_as_having_settings_type_cast value, type | ||
| 78 | - type.send :cast_value, value | ||
| 79 | - end | ||
| 80 | - | ||
| 81 | end | 84 | end |
| 82 | 85 | ||
| 83 | end | 86 | end |
lib/extended_tag.rb
| @@ -1,36 +0,0 @@ | @@ -1,36 +0,0 @@ | ||
| 1 | -class ActsAsTaggableOn::Tag | ||
| 2 | - | ||
| 3 | - attr_accessible :name, :parent_id, :pending | ||
| 4 | - | ||
| 5 | - has_many :children, :class_name => 'Tag', :foreign_key => 'parent_id', :dependent => :destroy | ||
| 6 | - | ||
| 7 | - | ||
| 8 | - @@original_find = self.method(:find) | ||
| 9 | - # Rename the find method to find_with_pendings that includes all tags in the search regardless if its pending or not | ||
| 10 | - def self.find_with_pendings(*args) | ||
| 11 | - @@original_find.call(*args) | ||
| 12 | - end | ||
| 13 | - | ||
| 14 | - # Redefine the find method to exclude the pending tags from the search not allowing to tag something with an unapproved tag | ||
| 15 | - def self.find(*args) | ||
| 16 | - self.with_scope(:find => { :conditions => ['pending = ?', false] }) do | ||
| 17 | - self.find_with_pendings(*args) | ||
| 18 | - end | ||
| 19 | - end | ||
| 20 | - | ||
| 21 | - # Return all the tags that were suggested but not yet approved | ||
| 22 | - def self.find_pendings | ||
| 23 | - self.find_with_pendings.where('pending = ?', true) | ||
| 24 | - end | ||
| 25 | - | ||
| 26 | - # All the tags that can be a new parent for this tag, that is all but itself and its descendents to avoid loops | ||
| 27 | - def parent_candidates | ||
| 28 | - ActsAsTaggableOn::Tag.all - descendents - [self] | ||
| 29 | - end | ||
| 30 | - | ||
| 31 | - # All tags that have this tag as its one of its ancestors | ||
| 32 | - def descendents | ||
| 33 | - children.to_a.sum([], &:descendents) + children | ||
| 34 | - end | ||
| 35 | - | ||
| 36 | -end |
test/test_helper.rb
| @@ -139,6 +139,7 @@ class ActiveSupport::TestCase | @@ -139,6 +139,7 @@ class ActiveSupport::TestCase | ||
| 139 | assert !text.index('<'), "Text '#{text}' expected to be sanitized" | 139 | assert !text.index('<'), "Text '#{text}' expected to be sanitized" |
| 140 | end | 140 | end |
| 141 | 141 | ||
| 142 | + # TODO: HTML::Document is deprecated, port to Nokogiri::HTML | ||
| 142 | def assert_tag_in_string(text, options) | 143 | def assert_tag_in_string(text, options) |
| 143 | doc = HTML::Document.new(text, false, false) | 144 | doc = HTML::Document.new(text, false, false) |
| 144 | tag = doc.find(options) | 145 | tag = doc.find(options) |
test/unit/article_test.rb
| @@ -886,7 +886,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -886,7 +886,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 886 | 886 | ||
| 887 | should 'sanitize tags after save article' do | 887 | should 'sanitize tags after save article' do |
| 888 | article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) | 888 | article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) |
| 889 | - tag = build(ActsAsTaggableOn::Tag, :name => "TV Web w<script type='javascript'></script>") | 889 | + tag = build(Tag, name: "TV Web w<script type='javascript'></script>") |
| 890 | assert_match /[<>]/, tag.name | 890 | assert_match /[<>]/, tag.name |
| 891 | article.tag_list.add(tag.name) | 891 | article.tag_list.add(tag.name) |
| 892 | article.save! | 892 | article.save! |
| @@ -895,7 +895,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -895,7 +895,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
| 895 | 895 | ||
| 896 | should 'strip HTML from tag names after save article' do | 896 | should 'strip HTML from tag names after save article' do |
| 897 | article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) | 897 | article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) |
| 898 | - tag = build(ActsAsTaggableOn::Tag, :name => "TV Web w<script type=...") | 898 | + tag = build(Tag, name: "TV Web w<script type=...") |
| 899 | assert_match /</, tag.name | 899 | assert_match /</, tag.name |
| 900 | article.tag_list.add(tag.name) | 900 | article.tag_list.add(tag.name) |
| 901 | article.save! | 901 | article.save! |
test/unit/block_test.rb
| @@ -248,7 +248,7 @@ class BlockTest < ActiveSupport::TestCase | @@ -248,7 +248,7 @@ class BlockTest < ActiveSupport::TestCase | ||
| 248 | should 'generate embed code' do | 248 | should 'generate embed code' do |
| 249 | b = Block.new | 249 | b = Block.new |
| 250 | b.stubs(:url_for).returns('http://myblogtest.com/embed/block/1') | 250 | b.stubs(:url_for).returns('http://myblogtest.com/embed/block/1') |
| 251 | - assert_equal "<iframe class=\"embed block block\" frameborder=\"0\" height=\"768\" src=\"http://myblogtest.com/embed/block/1\" width=\"1024\"></iframe>", | 251 | + assert_equal "<iframe src=\"http://myblogtest.com/embed/block/1\" frameborder=\"0\" width=\"1024\" height=\"768\" class=\"embed block block\"></iframe>", |
| 252 | b.embed_code.call | 252 | b.embed_code.call |
| 253 | end | 253 | end |
| 254 | 254 |
test/unit/blog_helper_test.rb
| @@ -41,7 +41,7 @@ class BlogHelperTest < ActionView::TestCase | @@ -41,7 +41,7 @@ class BlogHelperTest < ActionView::TestCase | ||
| 41 | "<#{tag}#{options.map{|k,v| " #{k}=\"#{[v].flatten.join(' ')}\""}.join}>#{content}</#{tag}>" | 41 | "<#{tag}#{options.map{|k,v| " #{k}=\"#{[v].flatten.join(' ')}\""}.join}>#{content}</#{tag}>" |
| 42 | end | 42 | end |
| 43 | 43 | ||
| 44 | - html = HTML::Document.new(list_posts(blog.posts)).root | 44 | + html = Nokogiri::HTML list_posts(blog.posts) |
| 45 | assert_select html, "div#post-#{newer_post.id}.blog-post.position-1.first.odd-post" + | 45 | assert_select html, "div#post-#{newer_post.id}.blog-post.position-1.first.odd-post" + |
| 46 | " > div.odd-post-inner.blog-post-inner > .title", 'Last post' | 46 | " > div.odd-post-inner.blog-post-inner > .title", 'Last post' |
| 47 | assert_select html, "div#post-#{hidden_post.id}.blog-post.position-2.not-published.even-post" + | 47 | assert_select html, "div#post-#{hidden_post.id}.blog-post.position-2.not-published.even-post" + |
test/unit/catalog_helper_test.rb
| @@ -6,12 +6,7 @@ class CatalogHelperTest < ActiveSupport::TestCase | @@ -6,12 +6,7 @@ class CatalogHelperTest < ActiveSupport::TestCase | ||
| 6 | include ActionView::Helpers::TextHelper | 6 | include ActionView::Helpers::TextHelper |
| 7 | include ActionView::Helpers::UrlHelper | 7 | include ActionView::Helpers::UrlHelper |
| 8 | include ActionView::Helpers::TagHelper | 8 | include ActionView::Helpers::TagHelper |
| 9 | - | ||
| 10 | include ::Rails::Dom::Testing::Assertions::SelectorAssertions | 9 | include ::Rails::Dom::Testing::Assertions::SelectorAssertions |
| 11 | - # see http://blog.cynthiakiser.com/blog/2014/12/26/upgrading-from-rails-4-dot-1-8-to-4-dot-2-0/ | ||
| 12 | - def document_root_element | ||
| 13 | - @doc.root | ||
| 14 | - end | ||
| 15 | 10 | ||
| 16 | def url_for(opts) | 11 | def url_for(opts) |
| 17 | #{:controller => 'catalog', :action => 'index', :level => category.id} | 12 | #{:controller => 'catalog', :action => 'index', :level => category.id} |
| @@ -49,8 +44,8 @@ class CatalogHelperTest < ActiveSupport::TestCase | @@ -49,8 +44,8 @@ class CatalogHelperTest < ActiveSupport::TestCase | ||
| 49 | 44 | ||
| 50 | html = category_with_sub_list @products | 45 | html = category_with_sub_list @products |
| 51 | 46 | ||
| 52 | - @doc = doc = HTML::Document.new "<body>#{html}</body>" | ||
| 53 | - assert_select doc.root, 'div' do |divs| | 47 | + doc = Nokogiri::HTML "<body>#{html}</body>" |
| 48 | + assert_select doc, 'div' do |divs| | ||
| 54 | assert_select divs[0], "a[href=catalog-index-level=#{@products.id}]" | 49 | assert_select divs[0], "a[href=catalog-index-level=#{@products.id}]" |
| 55 | assert_select divs[0], '.count', {:text=>'3'} | 50 | assert_select divs[0], '.count', {:text=>'3'} |
| 56 | assert_select divs[1], "a[href=catalog-index-level=#{@food.id}]" | 51 | assert_select divs[1], "a[href=catalog-index-level=#{@food.id}]" |
test/unit/display_helper_test.rb
| @@ -36,12 +36,12 @@ class DisplayHelperTest < ActiveSupport::TestCase | @@ -36,12 +36,12 @@ class DisplayHelperTest < ActiveSupport::TestCase | ||
| 36 | 36 | ||
| 37 | should 'linkify "http://" prepended words on txt2html' do | 37 | should 'linkify "http://" prepended words on txt2html' do |
| 38 | html = txt2html "go to http://noosfero.org" | 38 | html = txt2html "go to http://noosfero.org" |
| 39 | - assert_equal 'go to <a href="http://noosfero.org" onclick="return confirm(\'Are you sure you want to visit this web site?\')" rel="nofolow" target="_blank">noos​fero​.org</a>', html | 39 | + assert_equal "go to <a href=\"http://noosfero.org\" target=\"_blank\" rel=\"nofolow\" onclick=\"return confirm('Are you sure you want to visit this web site?')\">noos​fero​.org</a>", html |
| 40 | end | 40 | end |
| 41 | 41 | ||
| 42 | should 'linkify "www." prepended words on txt2html' do | 42 | should 'linkify "www." prepended words on txt2html' do |
| 43 | html = txt2html "go to www.noosfero.org yeah!" | 43 | html = txt2html "go to www.noosfero.org yeah!" |
| 44 | - assert_equal 'go to <a href="http://www.noosfero.org" onclick="return confirm(\'Are you sure you want to visit this web site?\')" rel="nofolow" target="_blank">www.​noos​fero​.org</a> yeah!', html | 44 | + assert_equal "go to <a href=\"http://www.noosfero.org\" target=\"_blank\" rel=\"nofolow\" onclick=\"return confirm('Are you sure you want to visit this web site?')\">www.​noos​fero​.org</a> yeah!", html |
| 45 | end | 45 | end |
| 46 | 46 | ||
| 47 | should 'return path to file under theme dir if theme has that file' do | 47 | should 'return path to file under theme dir if theme has that file' do |
test/unit/environment_test.rb
| @@ -1145,7 +1145,7 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -1145,7 +1145,7 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
| 1145 | environment.message_for_disabled_enterprise = "<h1> Disabled Enterprise /h1>" | 1145 | environment.message_for_disabled_enterprise = "<h1> Disabled Enterprise /h1>" |
| 1146 | environment.valid? | 1146 | environment.valid? |
| 1147 | 1147 | ||
| 1148 | - assert_no_match /[<>]/, environment.message_for_disabled_enterprise | 1148 | + assert_match /<h1> Disabled Enterprise \/h1><\/h1>/, environment.message_for_disabled_enterprise |
| 1149 | end | 1149 | end |
| 1150 | 1150 | ||
| 1151 | should 'not sanitize html comments' do | 1151 | should 'not sanitize html comments' do |
| @@ -1153,7 +1153,7 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -1153,7 +1153,7 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
| 1153 | environment.message_for_disabled_enterprise = '<p><!-- <asdf> << aasdfa >>> --> <h1> Wellformed html code </h1>' | 1153 | environment.message_for_disabled_enterprise = '<p><!-- <asdf> << aasdfa >>> --> <h1> Wellformed html code </h1>' |
| 1154 | environment.valid? | 1154 | environment.valid? |
| 1155 | 1155 | ||
| 1156 | - assert_match /<!-- .* --> <h1> Wellformed html code <\/h1>/, environment.message_for_disabled_enterprise | 1156 | + assert_match /<p><!-- .* --> <\/p><h1> Wellformed html code <\/h1>/, environment.message_for_disabled_enterprise |
| 1157 | end | 1157 | end |
| 1158 | 1158 | ||
| 1159 | should "not crash when set nil as terms of use" do | 1159 | should "not crash when set nil as terms of use" do |
| @@ -1386,11 +1386,12 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -1386,11 +1386,12 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
| 1386 | end | 1386 | end |
| 1387 | 1387 | ||
| 1388 | should 'always store setting keys as symbol' do | 1388 | should 'always store setting keys as symbol' do |
| 1389 | + Environment.settings_items :string_key, type: String | ||
| 1389 | env = Environment.default | 1390 | env = Environment.default |
| 1390 | - env.settings['string_key'] = 'new value' | 1391 | + env.string_key = 'new value' |
| 1391 | env.save!; env.reload | 1392 | env.save!; env.reload |
| 1392 | - assert_nil env.settings['string_key'] | ||
| 1393 | assert_equal env.settings[:string_key], 'new value' | 1393 | assert_equal env.settings[:string_key], 'new value' |
| 1394 | + assert_nil env.settings['string_key'] | ||
| 1394 | end | 1395 | end |
| 1395 | 1396 | ||
| 1396 | should 'validate reports_lower_bound' do | 1397 | should 'validate reports_lower_bound' do |
test/unit/extended_tag_test.rb
| @@ -1,37 +0,0 @@ | @@ -1,37 +0,0 @@ | ||
| 1 | -require_relative "../test_helper" | ||
| 2 | -require 'extended_tag.rb' | ||
| 3 | - | ||
| 4 | -class UserTest < ActiveSupport::TestCase | ||
| 5 | - | ||
| 6 | - def test_find_without_pendings | ||
| 7 | - tag1 = ActsAsTaggableOn::Tag.create(:name => 'pending_tag', :pending => true) | ||
| 8 | - tag2 = ActsAsTaggableOn::Tag.create(:name => 'approved_tag', :pending => false) | ||
| 9 | - assert_nothing_raised {ActsAsTaggableOn::Tag.find(tag2.id)} | ||
| 10 | - assert_raise(ActiveRecord::RecordNotFound) {ActsAsTaggableOn::Tag.find(tag1.id)} | ||
| 11 | - end | ||
| 12 | - | ||
| 13 | - def test_find_pendings | ||
| 14 | - tag1 = ActsAsTaggableOn::Tag.create(:name => 'pending_tag', :pending => true) | ||
| 15 | - tag2 = ActsAsTaggableOn::Tag.create(:name => 'approved_tag', :pending => false) | ||
| 16 | - assert ActsAsTaggableOn::Tag.find_pendings.include?(tag1) | ||
| 17 | - assert (not ActsAsTaggableOn::Tag.find_pendings.include?(tag2)) | ||
| 18 | - end | ||
| 19 | - | ||
| 20 | - def test_parent_candidates | ||
| 21 | - tag1 = ActsAsTaggableOn::Tag.create(:name => 'parent_tag') | ||
| 22 | - tag2 = ActsAsTaggableOn::Tag.create(:name => 'child_tag', :parent_id => tag1.id) | ||
| 23 | - assert ( not tag1.parent_candidates.include?(tag2) ) | ||
| 24 | - assert tag2.parent_candidates.include?(tag1) | ||
| 25 | - end | ||
| 26 | - | ||
| 27 | - def test_descendents | ||
| 28 | - tag1 = ActsAsTaggableOn::Tag.create(:name => 'parent_tag') | ||
| 29 | - tag2 = ActsAsTaggableOn::Tag.create(:name => 'child_tag', :parent_id => tag1.id) | ||
| 30 | - tag3 = ActsAsTaggableOn::Tag.create(:name => 'grand_tag', :parent_id => tag2.id) | ||
| 31 | - assert (not tag2.descendents.include?(tag1)) | ||
| 32 | - assert (not tag1.descendents.include?(tag1)) | ||
| 33 | - assert tag1.descendents.include?(tag2) | ||
| 34 | - assert tag1.descendents.include?(tag3) | ||
| 35 | - end | ||
| 36 | - | ||
| 37 | -end |
test/unit/language_helper_test.rb
| @@ -53,7 +53,7 @@ class LanguageHelperTest < ActiveSupport::TestCase | @@ -53,7 +53,7 @@ class LanguageHelperTest < ActiveSupport::TestCase | ||
| 53 | 53 | ||
| 54 | self.expects(:language).returns('en') | 54 | self.expects(:language).returns('en') |
| 55 | result = self.language_chooser(environment, :element => 'dropdown') | 55 | result = self.language_chooser(environment, :element => 'dropdown') |
| 56 | - assert_match /<option value="en" selected="selected">English<\/option>/, result | 56 | + assert_match /<option selected="selected" value="en">English<\/option>/, result |
| 57 | assert_match /<option value="pt_BR">Português Brasileiro<\/option>/, result | 57 | assert_match /<option value="pt_BR">Português Brasileiro<\/option>/, result |
| 58 | assert_match /<option value="fr">Français<\/option>/, result | 58 | assert_match /<option value="fr">Français<\/option>/, result |
| 59 | assert_match /<option value="it">Italiano<\/option>/, result | 59 | assert_match /<option value="it">Italiano<\/option>/, result |
test/unit/person_notifier_test.rb
| @@ -67,8 +67,11 @@ class PersonNotifierTest < ActiveSupport::TestCase | @@ -67,8 +67,11 @@ class PersonNotifierTest < ActiveSupport::TestCase | ||
| 67 | 67 | ||
| 68 | should 'update last notification date' do | 68 | should 'update last notification date' do |
| 69 | Comment.create!(:author => @admin, :title => 'test comment 2', :body => 'body 2!', :source => @article) | 69 | Comment.create!(:author => @admin, :title => 'test comment 2', :body => 'body 2!', :source => @article) |
| 70 | - @community.add_member(@member) | 70 | + notify |
| 71 | initial_notification = @member.last_notification | 71 | initial_notification = @member.last_notification |
| 72 | + | ||
| 73 | + Comment.create!(:author => @admin, :title => 'test comment 2', :body => 'body 2!', :source => @article) | ||
| 74 | + @community.add_member(@member) | ||
| 72 | notify | 75 | notify |
| 73 | assert @member.last_notification > initial_notification | 76 | assert @member.last_notification > initial_notification |
| 74 | end | 77 | end |
| @@ -150,14 +153,14 @@ class PersonNotifierTest < ActiveSupport::TestCase | @@ -150,14 +153,14 @@ class PersonNotifierTest < ActiveSupport::TestCase | ||
| 150 | assert job.run_at < time + (@member.notification_time+1).hours | 153 | assert job.run_at < time + (@member.notification_time+1).hours |
| 151 | end | 154 | end |
| 152 | 155 | ||
| 153 | - should 'display error message if fail to render a notificiation' do | 156 | + should 'fail to render an invalid notificiation' do |
| 154 | @community.add_member(@member) | 157 | @community.add_member(@member) |
| 155 | Comment.create!(:author => @admin, :title => 'test comment', :body => 'body!', :source => @article) | 158 | Comment.create!(:author => @admin, :title => 'test comment', :body => 'body!', :source => @article) |
| 156 | ActionTracker::Record.any_instance.stubs(:verb).returns("some_invalid_verb") | 159 | ActionTracker::Record.any_instance.stubs(:verb).returns("some_invalid_verb") |
| 157 | process_delayed_job_queue | 160 | process_delayed_job_queue |
| 158 | - notify | ||
| 159 | - sent = ActionMailer::Base.deliveries.last | ||
| 160 | - # don't raise erros | 161 | + assert_raise do |
| 162 | + notify | ||
| 163 | + end | ||
| 161 | end | 164 | end |
| 162 | 165 | ||
| 163 | ActionTrackerConfig.verb_names.each do |verb| | 166 | ActionTrackerConfig.verb_names.each do |verb| |
| @@ -170,7 +173,13 @@ class PersonNotifierTest < ActiveSupport::TestCase | @@ -170,7 +173,13 @@ class PersonNotifierTest < ActiveSupport::TestCase | ||
| 170 | a.created_at = @member.notifier.notify_from + 1.day | 173 | a.created_at = @member.notifier.notify_from + 1.day |
| 171 | a.target = fast_create(Forum) | 174 | a.target = fast_create(Forum) |
| 172 | a.comments_count = 0 | 175 | a.comments_count = 0 |
| 173 | - a.params = {'view_url'=> {}, 'name' => 'home', 'url' => '/', 'lead' => ''} | 176 | + a.params = { |
| 177 | + 'name' => 'home', 'url' => '/', 'lead' => '', | ||
| 178 | + 'receiver_url' => '/', 'content' => 'nothing', | ||
| 179 | + 'friend_url' => '/', 'friend_profile_custom_icon' => [], 'friend_name' => ['joe'], | ||
| 180 | + 'resource_name' => ['resource'], 'resource_profile_custom_icon' => [], 'resource_url' => ['/'], | ||
| 181 | + 'view_url'=> ['/'], 'thumbnail_path' => ['1'], | ||
| 182 | + } | ||
| 174 | a.get_url = '' | 183 | a.get_url = '' |
| 175 | a.save! | 184 | a.save! |
| 176 | n = @member.action_tracker_notifications.build | 185 | n = @member.action_tracker_notifications.build |
| @@ -178,9 +187,9 @@ class PersonNotifierTest < ActiveSupport::TestCase | @@ -178,9 +187,9 @@ class PersonNotifierTest < ActiveSupport::TestCase | ||
| 178 | n.profile = @member | 187 | n.profile = @member |
| 179 | n.save! | 188 | n.save! |
| 180 | 189 | ||
| 181 | - notify | ||
| 182 | - sent = ActionMailer::Base.deliveries.last | ||
| 183 | - # assert not raised | 190 | + assert_nothing_raised do |
| 191 | + notify | ||
| 192 | + end | ||
| 184 | end | 193 | end |
| 185 | end | 194 | end |
| 186 | 195 |
test/unit/product_category_test.rb
| @@ -64,7 +64,6 @@ class ProductCategoryTest < ActiveSupport::TestCase | @@ -64,7 +64,6 @@ class ProductCategoryTest < ActiveSupport::TestCase | ||
| 64 | 64 | ||
| 65 | scope = ProductCategory.by_environment(alt_environment) | 65 | scope = ProductCategory.by_environment(alt_environment) |
| 66 | 66 | ||
| 67 | - assert_equal ActiveRecord::Relation, scope.class | ||
| 68 | assert_equivalent [c2], scope | 67 | assert_equivalent [c2], scope |
| 69 | assert_equivalent [c1,c3], ProductCategory.by_environment(Environment.default) | 68 | assert_equivalent [c1,c3], ProductCategory.by_environment(Environment.default) |
| 70 | end | 69 | end |
test/unit/profile_suggestions_job_test.rb
test/unit/profile_test.rb
| @@ -1709,8 +1709,8 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1709,8 +1709,8 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 1709 | profile.custom_footer = "<h1> Malformed <><< html ></a>< tag" | 1709 | profile.custom_footer = "<h1> Malformed <><< html ></a>< tag" |
| 1710 | profile.save | 1710 | profile.save |
| 1711 | 1711 | ||
| 1712 | - assert_no_match /[<>]/, profile.custom_header | ||
| 1713 | - assert_no_match /[<>]/, profile.custom_footer | 1712 | + assert_match /<h1>> Malformed >> html ><\/h1>/, profile.custom_header |
| 1713 | + assert_match /<h1> Malformed <\/h1>/, profile.custom_footer | ||
| 1714 | end | 1714 | end |
| 1715 | 1715 | ||
| 1716 | should 'not sanitize html comments' do | 1716 | should 'not sanitize html comments' do |
| @@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
| 1 | +require_relative "../test_helper" | ||
| 2 | +require 'tag' | ||
| 3 | + | ||
| 4 | +class UserTest < ActiveSupport::TestCase | ||
| 5 | + | ||
| 6 | + def test_find_without_pendings | ||
| 7 | + tag1 = Tag.create(name: 'pending_tag', pending: true) | ||
| 8 | + tag2 = Tag.create(name: 'approved_tag', pending: false) | ||
| 9 | + assert_nothing_raised {Tag.find(tag2.id)} | ||
| 10 | + assert_raise(ActiveRecord::RecordNotFound) {Tag.find(tag1.id)} | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + def test_find_pendings | ||
| 14 | + tag1 = Tag.create(name: 'pending_tag', pending: true) | ||
| 15 | + tag2 = Tag.create(name: 'approved_tag', pending: false) | ||
| 16 | + assert Tag.find_pendings.include?(tag1) | ||
| 17 | + assert (not Tag.find_pendings.include?(tag2)) | ||
| 18 | + end | ||
| 19 | + | ||
| 20 | + def test_parent_candidates | ||
| 21 | + tag1 = Tag.create(name: 'parent_tag') | ||
| 22 | + tag2 = Tag.create(name: 'child_tag', parent_id: tag1.id) | ||
| 23 | + assert ( not tag1.parent_candidates.include?(tag2) ) | ||
| 24 | + assert tag2.parent_candidates.include?(tag1) | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + def test_descendents | ||
| 28 | + tag1 = Tag.create(name: 'parent_tag') | ||
| 29 | + tag2 = Tag.create(name: 'child_tag', parent_id: tag1.id) | ||
| 30 | + tag3 = Tag.create(name: 'grand_tag', parent_id: tag2.id) | ||
| 31 | + assert (not tag2.descendents.include?(tag1)) | ||
| 32 | + assert (not tag1.descendents.include?(tag1)) | ||
| 33 | + assert tag1.descendents.include?(tag2) | ||
| 34 | + assert tag1.descendents.include?(tag3) | ||
| 35 | + end | ||
| 36 | + | ||
| 37 | +end |
test/unit/task_mailer_test.rb
| @@ -9,29 +9,26 @@ class TaskMailerTest < ActiveSupport::TestCase | @@ -9,29 +9,26 @@ class TaskMailerTest < ActiveSupport::TestCase | ||
| 9 | ActionMailer::Base.perform_deliveries = true | 9 | ActionMailer::Base.perform_deliveries = true |
| 10 | ActionMailer::Base.deliveries = [] | 10 | ActionMailer::Base.deliveries = [] |
| 11 | 11 | ||
| 12 | + @environment = Environment.default | ||
| 13 | + @environment.noreply_email = 'noreply@example.com' | ||
| 14 | + @environment.stubs(:default_hostname).returns('example.com') | ||
| 15 | + @environment.name = 'example' | ||
| 12 | end | 16 | end |
| 17 | + attr_reader :environment | ||
| 13 | 18 | ||
| 14 | should 'be able to send a "task finished" message' do | 19 | should 'be able to send a "task finished" message' do |
| 15 | 20 | ||
| 16 | task = Task.new | 21 | task = Task.new |
| 17 | task.expects(:task_finished_message).returns('the message') | 22 | task.expects(:task_finished_message).returns('the message') |
| 18 | task.expects(:target_notification_description).returns('the task') | 23 | task.expects(:target_notification_description).returns('the task') |
| 19 | - | ||
| 20 | - requestor = mock() | ||
| 21 | - requestor.expects(:notification_emails).returns(['requestor@example.com']).at_least_once | ||
| 22 | - requestor.expects(:name).returns('my name') | ||
| 23 | - | ||
| 24 | - environment = mock() | ||
| 25 | - environment.expects(:noreply_email).returns('sender@example.com') | ||
| 26 | - environment.expects(:default_hostname).returns('example.com') | ||
| 27 | - environment.expects(:name).returns('example').at_least_once | ||
| 28 | - | ||
| 29 | - task.expects(:requestor).returns(requestor).at_least_once | ||
| 30 | - requestor.expects(:environment).returns(environment).at_least_once | ||
| 31 | - task.expects(:environment).returns(environment).at_least_once | 24 | + task.target = task.requestor = person = Person.new |
| 25 | + person.environment = environment | ||
| 26 | + person.name = 'my name' | ||
| 27 | + person.stubs(:contact_email).returns('requestor@example.com') | ||
| 28 | + person.stubs(:public_profile_url).returns('requestor_path') | ||
| 32 | 29 | ||
| 33 | task.send(:send_notification, :finished).deliver | 30 | task.send(:send_notification, :finished).deliver |
| 34 | - assert !ActionMailer::Base.deliveries.empty? | 31 | + assert ActionMailer::Base.deliveries.present? |
| 35 | end | 32 | end |
| 36 | 33 | ||
| 37 | should 'be able to send a "task cancelled" message' do | 34 | should 'be able to send a "task cancelled" message' do |
| @@ -39,19 +36,11 @@ class TaskMailerTest < ActiveSupport::TestCase | @@ -39,19 +36,11 @@ class TaskMailerTest < ActiveSupport::TestCase | ||
| 39 | task = Task.new | 36 | task = Task.new |
| 40 | task.expects(:task_cancelled_message).returns('the message') | 37 | task.expects(:task_cancelled_message).returns('the message') |
| 41 | task.expects(:target_notification_description).returns('the task') | 38 | task.expects(:target_notification_description).returns('the task') |
| 42 | - | ||
| 43 | - requestor = mock() | ||
| 44 | - requestor.expects(:notification_emails).returns(['requestor@example.com']).at_least_once | ||
| 45 | - requestor.expects(:name).returns('my name') | ||
| 46 | - | ||
| 47 | - environment = mock() | ||
| 48 | - environment.expects(:noreply_email).returns('sender@example.com') | ||
| 49 | - environment.expects(:default_hostname).returns('example.com') | ||
| 50 | - environment.expects(:name).returns('example').at_least_once | ||
| 51 | - | ||
| 52 | - task.expects(:requestor).returns(requestor).at_least_once | ||
| 53 | - requestor.expects(:environment).returns(environment).at_least_once | ||
| 54 | - task.expects(:environment).returns(environment).at_least_once | 39 | + task.target = task.requestor = person = Person.new |
| 40 | + person.environment = environment | ||
| 41 | + person.name = 'my name' | ||
| 42 | + person.stubs(:contact_email).returns('requestor@example.com') | ||
| 43 | + person.stubs(:public_profile_url).returns('requestor_path') | ||
| 55 | 44 | ||
| 56 | task.send(:send_notification, :cancelled).deliver | 45 | task.send(:send_notification, :cancelled).deliver |
| 57 | assert !ActionMailer::Base.deliveries.empty? | 46 | assert !ActionMailer::Base.deliveries.empty? |
| @@ -63,19 +52,11 @@ class TaskMailerTest < ActiveSupport::TestCase | @@ -63,19 +52,11 @@ class TaskMailerTest < ActiveSupport::TestCase | ||
| 63 | 52 | ||
| 64 | task.expects(:task_created_message).returns('the message') | 53 | task.expects(:task_created_message).returns('the message') |
| 65 | task.expects(:target_notification_description).returns('the task') | 54 | task.expects(:target_notification_description).returns('the task') |
| 66 | - | ||
| 67 | - requestor = mock() | ||
| 68 | - requestor.expects(:notification_emails).returns(['requestor@example.com']).at_least_once | ||
| 69 | - requestor.expects(:name).returns('my name') | ||
| 70 | - | ||
| 71 | - environment = mock() | ||
| 72 | - environment.expects(:noreply_email).returns('sender@example.com') | ||
| 73 | - environment.expects(:default_hostname).returns('example.com') | ||
| 74 | - environment.expects(:name).returns('example').at_least_once | ||
| 75 | - | ||
| 76 | - task.expects(:requestor).returns(requestor).at_least_once | ||
| 77 | - requestor.expects(:environment).returns(environment).at_least_once | ||
| 78 | - task.expects(:environment).returns(environment).at_least_once | 55 | + task.target = task.requestor = person = Person.new |
| 56 | + person.environment = environment | ||
| 57 | + person.name = 'my name' | ||
| 58 | + person.stubs(:contact_email).returns('requestor@example.com') | ||
| 59 | + person.stubs(:public_profile_url).returns('requestor_path') | ||
| 79 | 60 | ||
| 80 | task.send(:send_notification, :created).deliver | 61 | task.send(:send_notification, :created).deliver |
| 81 | assert !ActionMailer::Base.deliveries.empty? | 62 | assert !ActionMailer::Base.deliveries.empty? |
| @@ -95,25 +76,15 @@ class TaskMailerTest < ActiveSupport::TestCase | @@ -95,25 +76,15 @@ class TaskMailerTest < ActiveSupport::TestCase | ||
| 95 | 76 | ||
| 96 | task = InviteFriend.new | 77 | task = InviteFriend.new |
| 97 | task.expects(:code).returns('123456') | 78 | task.expects(:code).returns('123456') |
| 79 | + task.target = task.requestor = person = Person.new | ||
| 80 | + person.environment = environment | ||
| 81 | + person.name = 'my name' | ||
| 82 | + person.stubs(:public_profile_url).returns('requestor_path') | ||
| 98 | 83 | ||
| 99 | task.stubs(:message).returns('Hello <friend>, <user> invite you, please follow this link: <url>') | 84 | task.stubs(:message).returns('Hello <friend>, <user> invite you, please follow this link: <url>') |
| 100 | task.expects(:friend_email).returns('friend@exemple.com') | 85 | task.expects(:friend_email).returns('friend@exemple.com') |
| 101 | task.expects(:friend_name).returns('friend name').at_least_once | 86 | task.expects(:friend_name).returns('friend name').at_least_once |
| 102 | 87 | ||
| 103 | - requestor = mock() | ||
| 104 | - requestor.stubs(:name).returns('my name') | ||
| 105 | - requestor.stubs(:public_profile_url).returns('requestor_path') | ||
| 106 | - | ||
| 107 | - environment = mock() | ||
| 108 | - environment.expects(:noreply_email).returns('sender@example.com') | ||
| 109 | - environment.expects(:default_hostname).returns('example.com') | ||
| 110 | - environment.expects(:name).returns('example').at_least_once | ||
| 111 | - | ||
| 112 | - task.expects(:requestor).returns(requestor).at_least_once | ||
| 113 | - task.expects(:person).returns(requestor).at_least_once | ||
| 114 | - requestor.expects(:environment).returns(environment).at_least_once | ||
| 115 | - task.expects(:environment).returns(environment).at_least_once | ||
| 116 | - | ||
| 117 | mail = TaskMailer.invitation_notification(task) | 88 | mail = TaskMailer.invitation_notification(task) |
| 118 | 89 | ||
| 119 | assert_match(/#{task.target_notification_description}/, mail.subject) | 90 | assert_match(/#{task.target_notification_description}/, mail.subject) |
| @@ -126,13 +97,9 @@ class TaskMailerTest < ActiveSupport::TestCase | @@ -126,13 +97,9 @@ class TaskMailerTest < ActiveSupport::TestCase | ||
| 126 | 97 | ||
| 127 | should 'use environment name and no-reply email' do | 98 | should 'use environment name and no-reply email' do |
| 128 | task = mock | 99 | task = mock |
| 129 | - environment = mock | ||
| 130 | - environment.expects(:name).returns('My name') | ||
| 131 | - environment.expects(:noreply_email).returns('email@example.com') | ||
| 132 | - | ||
| 133 | task.expects(:environment).returns(environment).at_least_once | 100 | task.expects(:environment).returns(environment).at_least_once |
| 134 | 101 | ||
| 135 | - assert_equal 'My name <email@example.com>', TaskMailer.generate_from(task) | 102 | + assert_equal "#{environment.name} <#{environment.noreply_email}>", TaskMailer.generate_from(task) |
| 136 | end | 103 | end |
| 137 | 104 | ||
| 138 | should 'return the email with the subdirectory defined' do | 105 | should 'return the email with the subdirectory defined' do |
| @@ -140,25 +107,15 @@ class TaskMailerTest < ActiveSupport::TestCase | @@ -140,25 +107,15 @@ class TaskMailerTest < ActiveSupport::TestCase | ||
| 140 | 107 | ||
| 141 | task = InviteFriend.new | 108 | task = InviteFriend.new |
| 142 | task.expects(:code).returns('123456') | 109 | task.expects(:code).returns('123456') |
| 110 | + task.target = task.requestor = person = Person.new | ||
| 111 | + person.environment = environment | ||
| 112 | + person.name = 'my name' | ||
| 113 | + person.stubs(:public_profile_url).returns('requestor_path') | ||
| 143 | 114 | ||
| 144 | task.stubs(:message).returns('Hello <friend>, <user> invite you, please follow this link: <url>') | 115 | task.stubs(:message).returns('Hello <friend>, <user> invite you, please follow this link: <url>') |
| 145 | task.expects(:friend_email).returns('friend@exemple.com') | 116 | task.expects(:friend_email).returns('friend@exemple.com') |
| 146 | task.expects(:friend_name).returns('friend name').at_least_once | 117 | task.expects(:friend_name).returns('friend name').at_least_once |
| 147 | 118 | ||
| 148 | - requestor = mock() | ||
| 149 | - requestor.stubs(:name).returns('my name') | ||
| 150 | - requestor.stubs(:public_profile_url).returns('requestor_path') | ||
| 151 | - | ||
| 152 | - environment = mock() | ||
| 153 | - environment.expects(:noreply_email).returns('sender@example.com') | ||
| 154 | - environment.expects(:default_hostname).returns('example.com') | ||
| 155 | - environment.expects(:name).returns('example').at_least_once | ||
| 156 | - | ||
| 157 | - task.expects(:requestor).returns(requestor).at_least_once | ||
| 158 | - task.expects(:person).returns(requestor).at_least_once | ||
| 159 | - requestor.expects(:environment).returns(environment).at_least_once | ||
| 160 | - task.expects(:environment).returns(environment).at_least_once | ||
| 161 | - | ||
| 162 | mail = TaskMailer.invitation_notification(task) | 119 | mail = TaskMailer.invitation_notification(task) |
| 163 | 120 | ||
| 164 | url_to_compare = "/subdir/account/signup" | 121 | url_to_compare = "/subdir/account/signup" |
test/unit/task_test.rb
| @@ -131,7 +131,7 @@ class TaskTest < ActiveSupport::TestCase | @@ -131,7 +131,7 @@ class TaskTest < ActiveSupport::TestCase | ||
| 131 | 131 | ||
| 132 | task.cancel | 132 | task.cancel |
| 133 | 133 | ||
| 134 | - assert_nil Task.from_code(task.code) | 134 | + assert_equal [], Task.from_code(task.code) |
| 135 | end | 135 | end |
| 136 | 136 | ||
| 137 | should 'be able to find active tasks' do | 137 | should 'be able to find active tasks' do |
vendor/plugins/action_tracker/lib/action_tracker_model.rb
| @@ -100,8 +100,7 @@ module ActionTracker | @@ -100,8 +100,7 @@ module ActionTracker | ||
| 100 | end | 100 | end |
| 101 | 101 | ||
| 102 | def collect_group_with_index(param) | 102 | def collect_group_with_index(param) |
| 103 | - i = -1 | ||
| 104 | - send("get_#{param}").collect{ |el| yield(el, i += 1) } | 103 | + send("get_#{param}").collect.with_index{ |el, i| yield el, i } |
| 105 | end | 104 | end |
| 106 | 105 | ||
| 107 | protected | 106 | protected |