Commit 6a02c97ef9217d3a638c5ae81e8b5ec4b4975816
1 parent
411cbf6d
Exists in
master
and in
28 other branches
Moving duplicated creation code into factory
This way we can reuse that logic (fast creation with a category and/or adding a category) in other tests for search functionality.
Showing
2 changed files
with
16 additions
and
9 deletions
Show diff stats
test/factories.rb
| ... | ... | @@ -11,7 +11,20 @@ module Noosfero::Factory |
| 11 | 11 | else |
| 12 | 12 | fast_insert(klass, data) |
| 13 | 13 | end |
| 14 | - return klass.last(:order => "id") | |
| 14 | + obj = klass.last(:order => "id") | |
| 15 | + if options[:category] | |
| 16 | + categories = options[:category] | |
| 17 | + unless categories.is_a?(Array) | |
| 18 | + categories = [categories] | |
| 19 | + end | |
| 20 | + categories.each do |category| | |
| 21 | + obj.add_category(category) | |
| 22 | + end | |
| 23 | + end | |
| 24 | + if options[:search] | |
| 25 | + obj.ferret_create | |
| 26 | + end | |
| 27 | + obj | |
| 15 | 28 | end |
| 16 | 29 | |
| 17 | 30 | def create(name, attrs = {}) | ... | ... |
test/functional/search_controller_test.rb
| ... | ... | @@ -14,17 +14,11 @@ class SearchControllerTest < Test::Unit::TestCase |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | 16 | def create_article_with_optional_category(name, profile, category = nil) |
| 17 | - article = fast_create(Article, :name => name, :profile_id => profile.id) | |
| 18 | - article.add_category(category) if category | |
| 19 | - article.ferret_create | |
| 20 | - article | |
| 17 | + fast_create(Article, {:name => name, :profile_id => profile.id }, :search => true, :category => category) | |
| 21 | 18 | end |
| 22 | 19 | |
| 23 | 20 | def create_profile_with_optional_category(klass, name, category = nil, data = {}) |
| 24 | - profile = fast_create(klass, { :name => name }.merge(data)) | |
| 25 | - profile.add_category(category) if category | |
| 26 | - profile.ferret_create | |
| 27 | - profile | |
| 21 | + fast_create(klass, { :name => name }.merge(data), :search => true, :category => category) | |
| 28 | 22 | end |
| 29 | 23 | |
| 30 | 24 | def test_local_files_reference | ... | ... |