[noosfero/noosfero][rails4] 4 commits: rails4: port comments on action_tracker
Bráulio Bhavamitra
gitlab at gitlab.com
Sat Apr 11 22:30:02 BRT 2015
Bráulio Bhavamitra pushed to rails4 at Noosfero / noosfero
Commits:
bf567b00 by Braulio Bhavamitra at 2015-04-11T17:37:26Z
rails4: port comments on action_tracker
- - - - -
0108f890 by Braulio Bhavamitra at 2015-04-11T18:05:18Z
rails4: fix uploaded file tests
- - - - -
7932e28c by Braulio Bhavamitra at 2015-04-11T19:57:40Z
rails4: only load minitest on test and use minitest-reporters
- - - - -
2708afa1 by Braulio Bhavamitra at 2015-04-11T22:29:46Z
rails4: simplify and fix find_tag_in_string
- - - - -
8 changed files:
- Gemfile
- app/models/thumbnail.rb
- test/factories.rb
- test/test_helper.rb
- test/unit/cms_helper_test.rb
- test/unit/comment_test.rb
- test/unit/uploaded_file_test.rb
- vendor/plugins/action_tracker_has_comments/init.rb
Changes:
=====================================
Gemfile
=====================================
--- a/Gemfile
+++ b/Gemfile
@@ -1,6 +1,5 @@
source "https://rubygems.org"
gem 'rails', '~> 4.2.0'
-gem 'minitest'
gem 'fast_gettext', '~> 0.6.8'
gem 'acts-as-taggable-on', '~> 3.4.2'
gem 'rails_autolink', '~> 1.1.5'
@@ -43,6 +42,8 @@ group :test do
gem 'rspec', '~> 2.10.0'
gem 'rspec-rails', '~> 2.10.1'
gem 'mocha', '~> 1.1.0', :require => false
+ gem 'minitest'
+ gem 'minitest-reporters'
end
group :cucumber do
=====================================
app/models/thumbnail.rb
=====================================
--- a/app/models/thumbnail.rb
+++ b/app/models/thumbnail.rb
@@ -1,4 +1,9 @@
class Thumbnail < ActiveRecord::Base
+
+ attr_accessible :uploaded_data
+ # mass assigned by attachment_fu
+ attr_accessible :content_type, :filename, :thumbnail_resize_options, :thumbnail, :parent_id
+
has_attachment :storage => :file_system,
:content_type => :image, :max_size => 5.megabytes, processor: 'Rmagick'
validates_as_attachment
@@ -7,5 +12,4 @@ class Thumbnail < ActiveRecord::Base
postgresql_attachment_fu
- attr_accessible :uploaded_data
end
=====================================
test/factories.rb
=====================================
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -31,7 +31,8 @@ module Noosfero::Factory
if respond_to?(target)
send(target, attrs)
else
- obj = build(name, attrs)
+ obj = build name
+ attrs.each{ |a, v| obj.send "#{a}=", v }
obj.save!
obj
end
=====================================
test/test_helper.rb
=====================================
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -2,9 +2,13 @@ ENV["RAILS_ENV"] = "test"
require_relative "../config/environment"
require 'rails/test_help'
+
require 'mocha'
require 'mocha/mini_test'
+require "minitest/reporters"
+Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new, ENV, Minitest.backtrace_filter
+
require 'authenticated_test_helper'
require_relative 'factories'
require_relative 'noosfero_doc_test'
@@ -137,19 +141,8 @@ class ActiveSupport::TestCase
def find_tag_in_string text, options
doc = Nokogiri::HTML.fragment text
- tag = doc.css(options[:tag]).first
- content = tag.text.strip
-
- attributes = {}; tag.attributes.each do |a, v|
- a = a.to_sym
- next unless options[:attributes].has_key? a
- attributes[a] = v.value
- end
-
- ret = tag.present?
- ret &&= options[:attributes].blank? || attributes == options[:attributes]
- ret &&= options[:content].blank? || content == options[:content]
- ret
+ tag = doc.css("#{options[:tag]}#{options[:attributes].map{ |a, v| "[#{a}=\"#{v}\"]" }.join}").first
+ tag
end
def assert_tag_in_string(text, options)
=====================================
test/unit/cms_helper_test.rb
=====================================
--- a/test/unit/cms_helper_test.rb
+++ b/test/unit/cms_helper_test.rb
@@ -10,9 +10,9 @@ class CmsHelperTest < ActionView::TestCase
should 'show default options for article' do
result = options_for_article(build(RssFeed, :profile => Profile.new))
- assert_match /id="article_published_true" name="article\[published\]" type="radio" value="true"/, result
- assert_match /id="article_published_false" name="article\[published\]" type="radio" value="false"/, result
- assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result
+ assert_tag_in_string result, tag: 'input', attributes: {id: 'article_published_true', name:'article[published]', type: 'radio', value: 'true'}
+ assert_tag_in_string result, tag: 'input', attributes: {id: 'article_published_false', name:'article[published]', type: 'radio', value: 'false'}
+ assert_tag_in_string result, tag: 'input', attributes: {id: 'article_accept_comments', name:'article[accept_comments]', type: 'checkbox', value: '1'}
end
should 'show custom options for blog' do
=====================================
test/unit/comment_test.rb
=====================================
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -294,6 +294,7 @@ class CommentTest < ActiveSupport::TestCase
c3 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)
c4 = Comment.create!(:source => a, :body => 'My comment', :author => person)
result = a.activity.comments
+ assert result.present?
assert_equal c0, result[0]
assert_equal [c1, c3], result[0].replies
assert_equal [c2], result[0].replies[0].replies
=====================================
test/unit/uploaded_file_test.rb
=====================================
--- a/test/unit/uploaded_file_test.rb
+++ b/test/unit/uploaded_file_test.rb
@@ -347,13 +347,13 @@ class UploadedFileTest < ActiveSupport::TestCase
'INVALID' => 5.megabytes, # use default for invalid input
'1ZYX' => 5.megabytes, # use default for invalid input
}.each do |input,output|
- test 'maximum upload size: convert %s into %s' % [input, output] do
+ should 'maximum upload size: convert %s into %s' % [input, output] do
NOOSFERO_CONF.expects(:[]).with('max_upload_size').returns(input)
assert_equal output, UploadedFile.max_size
end
end
- test 'max_size should always return an integer' do
- NOOSFERO_CONF.expects(:[]).with('max_upload_size').returns("0.5 GB")
+ should 'max_size should always return an integer' do
+ NOOSFERO_CONF.expects(:[]).with('max_upload_size').returns("0.5 GB").at_least_once
assert_instance_of Fixnum, UploadedFile.max_size
end
=====================================
vendor/plugins/action_tracker_has_comments/init.rb
=====================================
--- a/vendor/plugins/action_tracker_has_comments/init.rb
+++ b/vendor/plugins/action_tracker_has_comments/init.rb
@@ -3,15 +3,11 @@
Rails.configuration.to_prepare do
ActionTracker::Record.module_eval do
- has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy
- #FIXME rails 4.1 removes finder_sql
- #:finder_sql => Proc.new { %Q{SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC}},
- #:counter_sql => Proc.new { %Q{SELECT COUNT(*) FROM comments WHERE #{conditions_for_comments}} }
-
- def conditions_for_comments
- type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id])
- "source_type = '#{type}' AND source_id = '#{id}' AND spam IS NOT TRUE AND reply_of_id IS NULL"
+ def comments
+ type, id = if self.target_type == 'Article' then ['Article', self.target_id] else [self.class.to_s, self.id] end
+ Comment.order('created_at ASC').
+ where('comments.spam IS NOT TRUE AND comments.reply_of_id IS NULL').
+ where('source_type = ? AND source_id = ?', type, id)
end
-
end
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/b2f7edb5d76b982c9fa5efc67ae3333c0d813792...2708afa1b13bfd55f27bd27d45704a75fa669c9b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150412/405b13c5/attachment.html>
More information about the Noosfero-dev
mailing list