Commit ef0730ccc6e1269eb7b55281780fc7dd6a33ce72
1 parent
59d5b8f6
Exists in
master
and in
27 other branches
rails3: fix unit tests
Showing
18 changed files
with
63 additions
and
74 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -295,7 +295,7 @@ module ApplicationHelper |
295 | 295 | search_name = "_" + search_name |
296 | 296 | end |
297 | 297 | |
298 | - path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name + 'html.erb') : File.join(view_path, search_name + 'html.erb') | |
298 | + path = defined?(params) && params[:controller] ? File.join(view_path, params[:controller], search_name + '.html.erb') : File.join(view_path, search_name + '.html.erb') | |
299 | 299 | return name if File.exists?(File.join(path)) |
300 | 300 | |
301 | 301 | partial_for_class_in_view_path(klass.superclass, view_path, prefix, suffix) |
... | ... | @@ -403,7 +403,7 @@ module ApplicationHelper |
403 | 403 | def theme_view_file(template) |
404 | 404 | # Since we cannot control what people are doing in external themes, we |
405 | 405 | # will keep looking for the deprecated .rhtml extension here. |
406 | - file = Rails.root.join('public', theme_path[1..-1], template + 'html.erb') | |
406 | + file = Rails.root.join('public', theme_path[1..-1], template + '.html.erb') | |
407 | 407 | return file if File.exists?(file) |
408 | 408 | nil |
409 | 409 | end | ... | ... |
app/models/block.rb
... | ... | @@ -167,10 +167,10 @@ class Block < ActiveRecord::Base |
167 | 167 | end |
168 | 168 | |
169 | 169 | DISPLAY_OPTIONS = { |
170 | - 'always' => __('In all pages'), | |
171 | - 'home_page_only' => __('Only in the homepage'), | |
172 | - 'except_home_page' => __('In all pages, except in the homepage'), | |
173 | - 'never' => __('Don\'t display'), | |
170 | + 'always' => _('In all pages'), | |
171 | + 'home_page_only' => _('Only in the homepage'), | |
172 | + 'except_home_page' => _('In all pages, except in the homepage'), | |
173 | + 'never' => _('Don\'t display'), | |
174 | 174 | } |
175 | 175 | |
176 | 176 | def display_options |
... | ... | @@ -182,7 +182,7 @@ class Block < ActiveRecord::Base |
182 | 182 | end |
183 | 183 | |
184 | 184 | def duplicate |
185 | - duplicated_block = self.clone | |
185 | + duplicated_block = self.dup | |
186 | 186 | duplicated_block.display = 'never' |
187 | 187 | duplicated_block.created_at = nil |
188 | 188 | duplicated_block.updated_at = nil | ... | ... |
app/models/forum.rb
... | ... | @@ -3,6 +3,8 @@ class Forum < Folder |
3 | 3 | acts_as_having_posts :order => 'updated_at DESC' |
4 | 4 | include PostsLimit |
5 | 5 | |
6 | + attr_accessible :has_terms_of_use | |
7 | + | |
6 | 8 | settings_items :terms_of_use, :type => :string, :default => "" |
7 | 9 | settings_items :has_terms_of_use, :type => :boolean, :default => false |
8 | 10 | has_and_belongs_to_many :users_with_agreement, :class_name => 'Person', :join_table => 'terms_forum_people' | ... | ... |
app/models/product_categories_block.rb
... | ... | @@ -33,7 +33,7 @@ class ProductCategoriesBlock < Block |
33 | 33 | end |
34 | 34 | end |
35 | 35 | |
36 | - DISPLAY_OPTIONS['catalog_only'] = __('Only on the catalog') | |
36 | + DISPLAY_OPTIONS['catalog_only'] = _('Only on the catalog') | |
37 | 37 | |
38 | 38 | def display |
39 | 39 | settings[:display].nil? ? 'catalog_only' : super | ... | ... |
app/models/profile.rb
... | ... | @@ -92,21 +92,8 @@ class Profile < ActiveRecord::Base |
92 | 92 | def members |
93 | 93 | scopes = plugins.dispatch_scopes(:organization_members, self) |
94 | 94 | scopes << Person.members_of(self) |
95 | -# FIXME Review this change after the refactoring on or_scopes, now done through the ScopeTool. | |
96 | -#<<<<<<< HEAD | |
97 | -# | |
98 | -# clauses = scopes.map do |relation| | |
99 | -# clause = relation.arel.where_clauses.map { |clause| "(#{clause})" }.join(' AND ') | |
100 | -# "(#{clause})" | |
101 | -# end.join(' OR ') | |
102 | -# | |
103 | -# joins = scopes.map { |relation| relation.joins_values }.flatten.uniq | |
104 | -# selects = scopes.map { |relation| relation.select_values }.flatten.uniq | |
105 | -# Person.select(selects).joins(joins).where(clauses) | |
106 | -#======= | |
107 | 95 | return scopes.first if scopes.size == 1 |
108 | 96 | ScopeTool.union *scopes |
109 | -#>>>>>>> master | |
110 | 97 | end |
111 | 98 | |
112 | 99 | def members_count | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +<ul> | |
2 | + <% if !links_submenu.empty? %> | |
3 | + <div class="comment-actions"> | |
4 | + <li class="vcard"> | |
5 | + <%= link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links_submenu.to_json}); return false", :class => 'menu-submenu-trigger comment-trigger', :url => url) %> | |
6 | + </li> | |
7 | + </div> | |
8 | + <% end %> | |
9 | +</ul> | |
10 | +<div class="comments-action-bar"> | |
11 | + <% unless comment.spam? %> | |
12 | + <%= link_to_function '', | |
13 | + "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, | |
14 | + :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', | |
15 | + :id => 'comment-reply-to-' + comment.id.to_s, | |
16 | + :title => _('Reply') | |
17 | + %> | |
18 | + <% end %> | |
19 | + <% links_action_bar.collect do |link| %> | |
20 | + <%= link[:link] %> | |
21 | + <% end %> | |
22 | +</div> | ... | ... |
app/views/comment/_comment_actions.rhtml
... | ... | @@ -1,22 +0,0 @@ |
1 | -<ul> | |
2 | - <% if !links_submenu.empty? %> | |
3 | - <div class="comment-actions"> | |
4 | - <li class="vcard"> | |
5 | - <%= link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links_submenu.to_json}); return false", :class => 'menu-submenu-trigger comment-trigger', :url => url) %> | |
6 | - </li> | |
7 | - </div> | |
8 | - <% end %> | |
9 | -</ul> | |
10 | -<div class="comments-action-bar"> | |
11 | - <% unless comment.spam? %> | |
12 | - <%= link_to_function '', | |
13 | - "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, | |
14 | - :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', | |
15 | - :id => 'comment-reply-to-' + comment.id.to_s, | |
16 | - :title => _('Reply') | |
17 | - %> | |
18 | - <% end %> | |
19 | - <% links_action_bar.collect do |link| %> | |
20 | - <%= link[:link] %> | |
21 | - <% end %> | |
22 | -</div> |
app/views/search/_sellers_form.html.erb
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | |
5 | 5 | <div class="search-in-opt"><%= _('Search in:') %> |
6 | 6 | <dir> |
7 | - <%= labelled_radio_button __('Enterprises'), 'asset', 'enterprises', true %><br /> | |
7 | + <%= labelled_radio_button _('Enterprises'), 'asset', 'enterprises', true %><br /> | |
8 | 8 | <%= labelled_radio_button _('Products'), 'asset', 'products', false %> |
9 | 9 | </dir> |
10 | 10 | </div> | ... | ... |
lib/scope_tool.rb
... | ... | @@ -2,7 +2,7 @@ module ScopeTool |
2 | 2 | |
3 | 3 | # Sum scope results by SQL, allowing post filtering of the group. |
4 | 4 | def union(*scopes) |
5 | - model = scopes.first.class_name.constantize | |
5 | + model = scopes.first.klass.name.constantize | |
6 | 6 | scopes = scopes.map &:to_sql |
7 | 7 | model.from "(\n#{scopes.join("\nUNION\n")}\n) as #{model.table_name}" |
8 | 8 | end | ... | ... |
lib/tasks/plugins.rake
test/factories.rb
... | ... | @@ -42,7 +42,11 @@ module Noosfero::Factory |
42 | 42 | attrs[:slug] = attrs[:name].to_slug if attrs[:name].present? && attrs[:slug].blank? && defaults[:slug].present? |
43 | 43 | data = defaults_for(name).merge(attrs) |
44 | 44 | object = name.to_s.camelize.constantize.new |
45 | - object.assign_attributes(data, :without_protection => true) | |
45 | + if object.respond_to?(:assign_attributes) | |
46 | + object.assign_attributes(data, :without_protection => true) | |
47 | + else | |
48 | + data.each { |attribute, value| object.send(attribute.to_s+'=', value) } | |
49 | + end | |
46 | 50 | object |
47 | 51 | end |
48 | 52 | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -18,7 +18,7 @@ class ApplicationHelperTest < ActionView::TestCase |
18 | 18 | self.stubs(:params).returns({:controller => 'test'}) |
19 | 19 | File.stubs(:exists?).returns(false) |
20 | 20 | |
21 | - File.expects(:exists?).with(p1+"test/_integer.rhtml").returns(true) | |
21 | + File.expects(:exists?).with(p1+"test/_integer.html.erb").returns(true) | |
22 | 22 | assert_equal 'integer', partial_for_class(Integer) |
23 | 23 | |
24 | 24 | File.expects(:exists?).with(p1+"test/_numeric.html.erb").returns(true) |
... | ... | @@ -38,7 +38,7 @@ class ApplicationHelperTest < ActionView::TestCase |
38 | 38 | class School; class Project; end; end |
39 | 39 | |
40 | 40 | File.stubs(:exists?).returns(false) |
41 | - File.expects(:exists?).with(p+"test/application_helper_test/school/_project.rhtml").returns(true) | |
41 | + File.expects(:exists?).with(p+"test/application_helper_test/school/_project.html.erb").returns(true) | |
42 | 42 | |
43 | 43 | assert_equal 'test/application_helper_test/school/project', partial_for_class(School::Project) |
44 | 44 | end |
... | ... | @@ -175,7 +175,7 @@ class ApplicationHelperTest < ActionView::TestCase |
175 | 175 | |
176 | 176 | should 'render theme footer' do |
177 | 177 | stubs(:theme_path).returns('/user_themes/mytheme') |
178 | - footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.rhtml') | |
178 | + footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb') | |
179 | 179 | |
180 | 180 | File.expects(:exists?).with(footer_path).returns(true) |
181 | 181 | expects(:render).with(:file => footer_path, :use_full_path => false).returns("BLI") |
... | ... | @@ -185,11 +185,9 @@ class ApplicationHelperTest < ActionView::TestCase |
185 | 185 | |
186 | 186 | should 'ignore unexisting theme footer' do |
187 | 187 | stubs(:theme_path).returns('/user_themes/mytheme') |
188 | - footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.rhtml') | |
189 | - alternate_footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb') | |
188 | + footer_path = Rails.root.join('public', 'user_themes', 'mytheme', 'footer.html.erb') | |
190 | 189 | |
191 | 190 | File.expects(:exists?).with(footer_path).returns(false) |
192 | - File.expects(:exists?).with(alternate_footer_path).returns(false) | |
193 | 191 | expects(:render).with(:file => footer).never |
194 | 192 | |
195 | 193 | assert_nil theme_footer |
... | ... | @@ -197,7 +195,7 @@ class ApplicationHelperTest < ActionView::TestCase |
197 | 195 | |
198 | 196 | should 'render theme site title' do |
199 | 197 | stubs(:theme_path).returns('/user_themes/mytheme') |
200 | - site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.rhtml') | |
198 | + site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.html.erb') | |
201 | 199 | |
202 | 200 | File.expects(:exists?).with(site_title_path).returns(true) |
203 | 201 | expects(:render).with(:file => site_title_path, :use_full_path => false).returns("Site title") |
... | ... | @@ -207,11 +205,9 @@ class ApplicationHelperTest < ActionView::TestCase |
207 | 205 | |
208 | 206 | should 'ignore unexisting theme site title' do |
209 | 207 | stubs(:theme_path).returns('/user_themes/mytheme') |
210 | - site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.rhtml') | |
211 | - alternate_site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.html.erb') | |
208 | + site_title_path = Rails.root.join('public', 'user_themes', 'mytheme', 'site_title.html.erb') | |
212 | 209 | |
213 | 210 | File.expects(:exists?).with(site_title_path).returns(false) |
214 | - File.expects(:exists?).with(alternate_site_title_path).returns(false) | |
215 | 211 | expects(:render).with(:file => site_title_path).never |
216 | 212 | |
217 | 213 | assert_nil theme_site_title | ... | ... |
test/unit/article_test.rb
... | ... | @@ -1697,7 +1697,7 @@ class ArticleTest < ActiveSupport::TestCase |
1697 | 1697 | should 'return license from a specific version' do |
1698 | 1698 | cc = License.create!(:name => 'CC (by)', :environment => Environment.default) |
1699 | 1699 | gpl = License.create!(:name => 'GPLv3', :environment => Environment.default) |
1700 | - article = Article.create!(:name => 'first version', :profile => profile, :license => cc) | |
1700 | + article = create(Article, :name => 'first version', :profile => profile, :license => cc) | |
1701 | 1701 | article.license = gpl |
1702 | 1702 | article.save |
1703 | 1703 | assert_equal cc, article.version_license(1) |
... | ... | @@ -1766,7 +1766,7 @@ class ArticleTest < ActiveSupport::TestCase |
1766 | 1766 | should "return the author of a specific version" do |
1767 | 1767 | author1 = fast_create(Person) |
1768 | 1768 | author2 = fast_create(Person) |
1769 | - article = Article.create!(:name => 'first version', :profile => profile, :last_changed_by => author1) | |
1769 | + article = create(Article, :name => 'first version', :profile => profile, :last_changed_by => author1) | |
1770 | 1770 | article.name = 'second version' |
1771 | 1771 | article.last_changed_by = author2 |
1772 | 1772 | article.save |
... | ... | @@ -1777,7 +1777,7 @@ class ArticleTest < ActiveSupport::TestCase |
1777 | 1777 | should "return the author_name of a specific version" do |
1778 | 1778 | author1 = fast_create(Person) |
1779 | 1779 | author2 = fast_create(Person) |
1780 | - article = Article.create!(:name => 'first version', :profile => profile, :last_changed_by => author1) | |
1780 | + article = create(Article, :name => 'first version', :profile => profile, :last_changed_by => author1) | |
1781 | 1781 | article.name = 'second version' |
1782 | 1782 | article.last_changed_by = author2 |
1783 | 1783 | article.save | ... | ... |
test/unit/block_test.rb
... | ... | @@ -169,14 +169,14 @@ class BlockTest < ActiveSupport::TestCase |
169 | 169 | |
170 | 170 | should 'create a cloned block' do |
171 | 171 | block = fast_create(Block, :title => 'test 1', :position => 1) |
172 | - assert_difference Block, :count, 1 do | |
172 | + assert_difference 'Block.count', 1 do | |
173 | 173 | block.duplicate |
174 | 174 | end |
175 | 175 | end |
176 | 176 | |
177 | 177 | should 'clone and keep some fields' do |
178 | 178 | box = fast_create(Box, :owner_id => fast_create(Profile).id) |
179 | - block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}) | |
179 | + block = create(TagsBlock, :title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}) | |
180 | 180 | duplicated = block.duplicate |
181 | 181 | [:title, :box_id, :type].each do |f| |
182 | 182 | assert_equal duplicated.send(f), block.send(f) |
... | ... | @@ -186,8 +186,8 @@ class BlockTest < ActiveSupport::TestCase |
186 | 186 | |
187 | 187 | should 'clone block and set fields' do |
188 | 188 | box = fast_create(Box, :owner_id => fast_create(Profile).id) |
189 | - block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) | |
190 | - block2 = TagsBlock.create!(:title => 'test 2', :box_id => box.id, :settings => {:test => 'test'}, :position => 2) | |
189 | + block = create(TagsBlock, :title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) | |
190 | + block2 = create(TagsBlock, :title => 'test 2', :box_id => box.id, :settings => {:test => 'test'}, :position => 2) | |
191 | 191 | duplicated = block.duplicate |
192 | 192 | block2.reload |
193 | 193 | block.reload |
... | ... | @@ -198,8 +198,8 @@ class BlockTest < ActiveSupport::TestCase |
198 | 198 | end |
199 | 199 | |
200 | 200 | should 'not clone date creation and update attributes' do |
201 | - box = fast_create(Box, :owner_id => fast_create(Profile).id) | |
202 | - block = TagsBlock.create!(:title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) | |
201 | + box = fast_create(Box, :owner_id => fast_create(Profile).id) | |
202 | + block = create(TagsBlock, :title => 'test 1', :box_id => box.id, :settings => {:test => 'test'}, :position => 1) | |
203 | 203 | duplicated = block.duplicate |
204 | 204 | |
205 | 205 | assert_not_equal block.created_at, duplicated.created_at | ... | ... |
test/unit/box_test.rb
... | ... | @@ -96,7 +96,7 @@ class BoxTest < ActiveSupport::TestCase |
96 | 96 | end |
97 | 97 | end |
98 | 98 | class PluginBlock < Block |
99 | - def self.name; 'plugin-block'; end | |
99 | + def self.to_s; 'plugin-block'; end | |
100 | 100 | end |
101 | 101 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) |
102 | 102 | |
... | ... | @@ -111,7 +111,7 @@ class BoxTest < ActiveSupport::TestCase |
111 | 111 | end |
112 | 112 | end |
113 | 113 | class PluginBlock < Block |
114 | - def self.name; 'plugin-block'; end | |
114 | + def self.to_s; 'plugin-block'; end | |
115 | 115 | end |
116 | 116 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) |
117 | 117 | |
... | ... | @@ -130,13 +130,13 @@ class BoxTest < ActiveSupport::TestCase |
130 | 130 | end |
131 | 131 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) |
132 | 132 | |
133 | - blocks = Box.new(:position => 1, :owner => Person.new).acceptable_blocks | |
133 | + blocks = build(Box, :position => 1, :owner => Person.new).acceptable_blocks | |
134 | 134 | assert blocks.include?('box-test_plugin-block') |
135 | 135 | |
136 | - blocks = Box.new(:position => 1, :owner => Enterprise.new).acceptable_blocks | |
136 | + blocks = build(Box, :position => 1, :owner => Enterprise.new).acceptable_blocks | |
137 | 137 | assert blocks.include?('box-test_plugin-block') |
138 | 138 | |
139 | - blocks = Box.new(:position => 1, :owner => Community.new).acceptable_blocks | |
139 | + blocks = build(Box, :position => 1, :owner => Community.new).acceptable_blocks | |
140 | 140 | assert !blocks.include?('box-test_plugin-block') |
141 | 141 | end |
142 | 142 | ... | ... |
test/unit/catalog_helper_test.rb
... | ... | @@ -6,7 +6,7 @@ class CatalogHelperTest < ActiveSupport::TestCase |
6 | 6 | include ActionView::Helpers::TextHelper |
7 | 7 | include ActionView::Helpers::UrlHelper |
8 | 8 | include ActionView::Helpers::TagHelper |
9 | - include ActionController::Assertions::SelectorAssertions | |
9 | + include ActionDispatch::Assertions::SelectorAssertions | |
10 | 10 | |
11 | 11 | def url_for(opts) |
12 | 12 | #{:controller => 'catalog', :action => 'index', :level => category.id} | ... | ... |
test/unit/forum_test.rb
... | ... | @@ -137,7 +137,7 @@ class ForumTest < ActiveSupport::TestCase |
137 | 137 | should 'include user that changes a forum as agreed with terms' do |
138 | 138 | author = fast_create(Person) |
139 | 139 | editor = fast_create(Person) |
140 | - forum = Forum.create(:profile => author, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true, :last_changed_by => author) | |
140 | + forum = create(Forum, :profile => author, :name => 'Forum test', :body => 'Forum test', :has_terms_of_use => true, :last_changed_by => author) | |
141 | 141 | forum.last_changed_by = editor |
142 | 142 | forum.save |
143 | 143 | ... | ... |
test/unit/person_test.rb
... | ... | @@ -1444,7 +1444,7 @@ class PersonTest < ActiveSupport::TestCase |
1444 | 1444 | assert_includes original_person.memberships, original_cmm |
1445 | 1445 | assert_includes original_person.memberships, plugin1_cmm |
1446 | 1446 | assert_includes original_person.memberships, plugin2_cmm |
1447 | - assert 3, original_person.memberships.count | |
1447 | + assert_equal 3, original_person.memberships.count | |
1448 | 1448 | end |
1449 | 1449 | |
1450 | 1450 | end | ... | ... |