From ef0730ccc6e1269eb7b55281780fc7dd6a33ce72 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 13 Feb 2014 17:10:28 -0300 Subject: [PATCH] rails3: fix unit tests --- app/helpers/application_helper.rb | 4 ++-- app/models/block.rb | 10 +++++----- app/models/forum.rb | 2 ++ app/models/product_categories_block.rb | 2 +- app/models/profile.rb | 13 ------------- app/views/comment/_comment_actions.html.erb | 22 ++++++++++++++++++++++ app/views/comment/_comment_actions.rhtml | 22 ---------------------- app/views/search/_sellers_form.html.erb | 2 +- lib/scope_tool.rb | 2 +- lib/tasks/plugins.rake | 2 +- test/factories.rb | 6 +++++- test/unit/application_helper_test.rb | 16 ++++++---------- test/unit/article_test.rb | 6 +++--- test/unit/block_test.rb | 12 ++++++------ test/unit/box_test.rb | 10 +++++----- test/unit/catalog_helper_test.rb | 2 +- test/unit/forum_test.rb | 2 +- test/unit/person_test.rb | 2 +- 18 files changed, 63 insertions(+), 74 deletions(-) create mode 100644 app/views/comment/_comment_actions.html.erb delete mode 100644 app/views/comment/_comment_actions.rhtml diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 22d2365..2fa13ea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -295,7 +295,7 @@ module ApplicationHelper search_name = "_" + search_name end - path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name + 'html.erb') : File.join(view_path, search_name + 'html.erb') + path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name + '.html.erb') : File.join(view_path, search_name + '.html.erb') return name if File.exists?(File.join(path)) partial_for_class_in_view_path(klass.superclass, view_path, prefix, suffix) @@ -403,7 +403,7 @@ module ApplicationHelper def theme_view_file(template) # Since we cannot control what people are doing in external themes, we # will keep looking for the deprecated .rhtml extension here. - file = Rails.root.join('public', theme_path[1..-1], template + 'html.erb') + file = Rails.root.join('public', theme_path[1..-1], template + '.html.erb') return file if File.exists?(file) nil end diff --git a/app/models/block.rb b/app/models/block.rb index 3ca7dad..3644f7e 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -167,10 +167,10 @@ class Block < ActiveRecord::Base end DISPLAY_OPTIONS = { - 'always' => __('In all pages'), - 'home_page_only' => __('Only in the homepage'), - 'except_home_page' => __('In all pages, except in the homepage'), - 'never' => __('Don\'t display'), + 'always' => _('In all pages'), + 'home_page_only' => _('Only in the homepage'), + 'except_home_page' => _('In all pages, except in the homepage'), + 'never' => _('Don\'t display'), } def display_options @@ -182,7 +182,7 @@ class Block < ActiveRecord::Base end def duplicate - duplicated_block = self.clone + duplicated_block = self.dup duplicated_block.display = 'never' duplicated_block.created_at = nil duplicated_block.updated_at = nil diff --git a/app/models/forum.rb b/app/models/forum.rb index 665d4c6..f432acd 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -3,6 +3,8 @@ class Forum < Folder acts_as_having_posts :order => 'updated_at DESC' include PostsLimit + attr_accessible :has_terms_of_use + settings_items :terms_of_use, :type => :string, :default => "" settings_items :has_terms_of_use, :type => :boolean, :default => false has_and_belongs_to_many :users_with_agreement, :class_name => 'Person', :join_table => 'terms_forum_people' diff --git a/app/models/product_categories_block.rb b/app/models/product_categories_block.rb index c67a499..9f0fd02 100644 --- a/app/models/product_categories_block.rb +++ b/app/models/product_categories_block.rb @@ -33,7 +33,7 @@ class ProductCategoriesBlock < Block end end - DISPLAY_OPTIONS['catalog_only'] = __('Only on the catalog') + DISPLAY_OPTIONS['catalog_only'] = _('Only on the catalog') def display settings[:display].nil? ? 'catalog_only' : super diff --git a/app/models/profile.rb b/app/models/profile.rb index b1e8ecd..4e90cf1 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -92,21 +92,8 @@ class Profile < ActiveRecord::Base def members scopes = plugins.dispatch_scopes(:organization_members, self) scopes << Person.members_of(self) -# FIXME Review this change after the refactoring on or_scopes, now done through the ScopeTool. -#<<<<<<< HEAD -# -# clauses = scopes.map do |relation| -# clause = relation.arel.where_clauses.map { |clause| "(#{clause})" }.join(' AND ') -# "(#{clause})" -# end.join(' OR ') -# -# joins = scopes.map { |relation| relation.joins_values }.flatten.uniq -# selects = scopes.map { |relation| relation.select_values }.flatten.uniq -# Person.select(selects).joins(joins).where(clauses) -#======= return scopes.first if scopes.size == 1 ScopeTool.union *scopes -#>>>>>>> master end def members_count diff --git a/app/views/comment/_comment_actions.html.erb b/app/views/comment/_comment_actions.html.erb new file mode 100644 index 0000000..52a6f60 --- /dev/null +++ b/app/views/comment/_comment_actions.html.erb @@ -0,0 +1,22 @@ + +
+ <% unless comment.spam? %> + <%= link_to_function '', + "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, + :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', + :id => 'comment-reply-to-' + comment.id.to_s, + :title => _('Reply') + %> + <% end %> + <% links_action_bar.collect do |link| %> + <%= link[:link] %> + <% end %> +
diff --git a/app/views/comment/_comment_actions.rhtml b/app/views/comment/_comment_actions.rhtml deleted file mode 100644 index 52a6f60..0000000 --- a/app/views/comment/_comment_actions.rhtml +++ /dev/null @@ -1,22 +0,0 @@ - -
- <% unless comment.spam? %> - <%= link_to_function '', - "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, - :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', - :id => 'comment-reply-to-' + comment.id.to_s, - :title => _('Reply') - %> - <% end %> - <% links_action_bar.collect do |link| %> - <%= link[:link] %> - <% end %> -
diff --git a/app/views/search/_sellers_form.html.erb b/app/views/search/_sellers_form.html.erb index 103d2f4..b59ae8b 100644 --- a/app/views/search/_sellers_form.html.erb +++ b/app/views/search/_sellers_form.html.erb @@ -4,7 +4,7 @@
<%= _('Search in:') %> - <%= labelled_radio_button __('Enterprises'), 'asset', 'enterprises', true %>
+ <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', true %>
<%= labelled_radio_button _('Products'), 'asset', 'products', false %>
diff --git a/lib/scope_tool.rb b/lib/scope_tool.rb index b65a47a..f0cbf61 100644 --- a/lib/scope_tool.rb +++ b/lib/scope_tool.rb @@ -2,7 +2,7 @@ module ScopeTool # Sum scope results by SQL, allowing post filtering of the group. def union(*scopes) - model = scopes.first.class_name.constantize + model = scopes.first.klass.name.constantize scopes = scopes.map &:to_sql model.from "(\n#{scopes.join("\nUNION\n")}\n) as #{model.table_name}" end diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake index 83d7e2f..757c0e4 100644 --- a/lib/tasks/plugins.rake +++ b/lib/tasks/plugins.rake @@ -1,5 +1,5 @@ require 'active_record' -require_dependency 'active_record/migration' +#require_dependency 'active_record/migration' class ActiveRecord::Migrator alias_method :orig_initialize, :initialize diff --git a/test/factories.rb b/test/factories.rb index 8e59322..2bcab8c 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -42,7 +42,11 @@ module Noosfero::Factory attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present? data = defaults_for(name).merge(attrs) object = name.to_s.camelize.constantize.new - object.assign_attributes(data, :without_protection => true) + if object.respond_to?(:assign_attributes) + object.assign_attributes(data, :without_protection => true) + else + data.each { |attribute, value| object.send(attribute.to_s+'=', value) } + end object end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 349a322..76eebe5 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -18,7 +18,7 @@ class ApplicationHelperTest < ActionView::TestCase self.stubs(:params).returns({:controller => 'test'}) File.stubs(:exists?).returns(false) - File.expects(:exists?).with(p1+"test/_integer.rhtml").returns(true) + File.expects(:exists?).with(p1+"test/_integer.html.erb").returns(true) assert_equal 'integer', partial_for_class(Integer) File.expects(:exists?).with(p1+"test/_numeric.html.erb").returns(true) @@ -38,7 +38,7 @@ class ApplicationHelperTest < ActionView::TestCase class School; class Project; end; end File.stubs(:exists?).returns(false) - File.expects(:exists?).with(p+"test/application_helper_test/school/_project.rhtml").returns(true) + File.expects(:exists?).with(p+"test/application_helper_test/school/_project.html.erb").returns(true) assert_equal 'test/application_helper_test/school/project', partial_for_class(School::Project) end @@ -175,7 +175,7 @@ class ApplicationHelperTest < ActionView::TestCase should 'render theme footer' do stubs(:theme_path).returns('/user_themes/mytheme') - footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.rhtml') + footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb') File.expects(:exists?).with(footer_path).returns(true) expects(:render).with(:file => footer_path, :use_full_path => false).returns("BLI") @@ -185,11 +185,9 @@ class ApplicationHelperTest < ActionView::TestCase should 'ignore unexisting theme footer' do stubs(:theme_path).returns('/user_themes/mytheme') - footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.rhtml') - alternate_footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb') + footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb') File.expects(:exists?).with(footer_path).returns(false) - File.expects(:exists?).with(alternate_footer_path).returns(false) expects(:render).with(:file => footer).never assert_nil theme_footer @@ -197,7 +195,7 @@ class ApplicationHelperTest < ActionView::TestCase should 'render theme site title' do stubs(:theme_path).returns('/user_themes/mytheme') - site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.rhtml') + site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.html.erb') File.expects(:exists?).with(site_title_path).returns(true) expects(:render).with(:file => site_title_path, :use_full_path => false).returns("Site title") @@ -207,11 +205,9 @@ class ApplicationHelperTest < ActionView::TestCase should 'ignore unexisting theme site title' do stubs(:theme_path).returns('/user_themes/mytheme') - site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.rhtml') - alternate_site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.html.erb') + site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.html.erb') File.expects(:exists?).with(site_title_path).returns(false) - File.expects(:exists?).with(alternate_site_title_path).returns(false) expects(:render).with(:file => site_title_path).never assert_nil theme_site_title diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 5ac157a..00e75b6 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -1697,7 +1697,7 @@ class ArticleTest < ActiveSupport::TestCase should 'return license from a specific version' do cc = License.create!(:name => 'CC (by)', :environment => Environment.default) gpl = License.create!(:name => 'GPLv3', :environment => Environment.default) - article = Article.create!(:name => 'first version', :profile => profile, :license => cc) + article = create(Article, :name => 'first version', :profile => profile, :license => cc) article.license = gpl article.save assert_equal cc, article.version_license(1) @@ -1766,7 +1766,7 @@ class ArticleTest < ActiveSupport::TestCase should "return the author of a specific version" do author1 = fast_create(Person) author2 = fast_create(Person) - article = Article.create!(:name => 'first version', :profile => profile, :last_changed_by => author1) + article = create(Article, :name => 'first version', :profile => profile, :last_changed_by => author1) article.name = 'second version' article.last_changed_by = author2 article.save @@ -1777,7 +1777,7 @@ class ArticleTest < ActiveSupport::TestCase should "return the author_name of a specific version" do author1 = fast_create(Person) author2 = fast_create(Person) - article = Article.create!(:name => 'first version', :profile => profile, :last_changed_by => author1) + article = create(Article, :name => 'first version', :profile => profile, :last_changed_by => author1) article.name = 'second version' article.last_changed_by = author2 article.save diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index dae23cd..25a7a41 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -169,14 +169,14 @@ class BlockTest < ActiveSupport::TestCase should 'create a cloned block' do block = fast_create(Block, :title => 'test 1', :position => 1) - assert_difference Block, :count, 1 do + assert_difference 'Block.count', 1 do block.duplicate end end should 'clone and keep some fields' do box = fast_create(Box, :owner_id => fast_create(Profile).id) - block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}) + block = create(TagsBlock, :title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}) duplicated = block.duplicate [:title, :box_id, :type].each do |f| assert_equal duplicated.send(f), block.send(f) @@ -186,8 +186,8 @@ class BlockTest < ActiveSupport::TestCase should 'clone block and set fields' do box = fast_create(Box, :owner_id => fast_create(Profile).id) - block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) - block2 = TagsBlock.create!(:title => 'test 2', :box_id => box.id, :settings => {:test => 'test'}, :position => 2) + block = create(TagsBlock, :title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) + block2 = create(TagsBlock, :title => 'test 2', :box_id => box.id, :settings => {:test => 'test'}, :position => 2) duplicated = block.duplicate block2.reload block.reload @@ -198,8 +198,8 @@ class BlockTest < ActiveSupport::TestCase end should 'not clone date creation and update attributes' do - box = fast_create(Box, :owner_id => fast_create(Profile).id) - block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) + box = fast_create(Box, :owner_id => fast_create(Profile).id) + block = create(TagsBlock, :title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) duplicated = block.duplicate assert_not_equal block.created_at, duplicated.created_at diff --git a/test/unit/box_test.rb b/test/unit/box_test.rb index d909fc3..4470893 100644 --- a/test/unit/box_test.rb +++ b/test/unit/box_test.rb @@ -96,7 +96,7 @@ class BoxTest < ActiveSupport::TestCase end end class PluginBlock < Block - def self.name; 'plugin-block'; end + def self.to_s; 'plugin-block'; end end Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) @@ -111,7 +111,7 @@ class BoxTest < ActiveSupport::TestCase end end class PluginBlock < Block - def self.name; 'plugin-block'; end + def self.to_s; 'plugin-block'; end end Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) @@ -130,13 +130,13 @@ class BoxTest < ActiveSupport::TestCase end Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) - blocks = Box.new(:position => 1, :owner => Person.new).acceptable_blocks + blocks = build(Box, :position => 1, :owner => Person.new).acceptable_blocks assert blocks.include?('box-test_plugin-block') - blocks = Box.new(:position => 1, :owner => Enterprise.new).acceptable_blocks + blocks = build(Box, :position => 1, :owner => Enterprise.new).acceptable_blocks assert blocks.include?('box-test_plugin-block') - blocks = Box.new(:position => 1, :owner => Community.new).acceptable_blocks + blocks = build(Box, :position => 1, :owner => Community.new).acceptable_blocks assert !blocks.include?('box-test_plugin-block') end diff --git a/test/unit/catalog_helper_test.rb b/test/unit/catalog_helper_test.rb index 37e7a5c..32dde21 100644 --- a/test/unit/catalog_helper_test.rb +++ b/test/unit/catalog_helper_test.rb @@ -6,7 +6,7 @@ class CatalogHelperTest < ActiveSupport::TestCase include ActionView::Helpers::TextHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers::TagHelper - include ActionController::Assertions::SelectorAssertions + include ActionDispatch::Assertions::SelectorAssertions def url_for(opts) #{:controller => 'catalog', :action => 'index', :level => category.id} diff --git a/test/unit/forum_test.rb b/test/unit/forum_test.rb index 0f60579..879ab09 100644 --- a/test/unit/forum_test.rb +++ b/test/unit/forum_test.rb @@ -137,7 +137,7 @@ class ForumTest < ActiveSupport::TestCase should 'include user that changes a forum as agreed with terms' do author = fast_create(Person) editor = fast_create(Person) - forum = Forum.create(:profile => author, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true, :last_changed_by => author) + forum = create(Forum, :profile => author, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true, :last_changed_by => author) forum.last_changed_by = editor forum.save diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 9f1de38..2936c23 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1444,7 +1444,7 @@ class PersonTest < ActiveSupport::TestCase assert_includes original_person.memberships, original_cmm assert_includes original_person.memberships, plugin1_cmm assert_includes original_person.memberships, plugin2_cmm - assert 3, original_person.memberships.count + assert_equal 3, original_person.memberships.count end end -- libgit2 0.21.2