diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index a1e007e..c841a70 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -166,7 +166,7 @@ class CmsController < MyProfileController end if request.post? && params[:uploaded_files] params[:uploaded_files].each do |file| - @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent, :last_changed_by => user) unless file == '' + @uploaded_files << UploadedFile.create({:uploaded_data => file, :profile => profile, :parent => @parent, :last_changed_by => user}, :without_protection => true) unless file == '' end @errors = @uploaded_files.select { |f| f.errors.any? } if @errors.any? diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index 575d510..b78196f 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -85,7 +85,7 @@ class ManageProductsController < ApplicationController @edit = true @level = @category.level if request.post? - if @product.update_attributes(:product_category_id => params[:selected_category_id]) + if @product.update_attributes({:product_category_id => params[:selected_category_id]}, :without_protection => true) render :partial => 'shared/redirect_via_javascript', :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } else diff --git a/app/models/article.rb b/app/models/article.rb index 216adfa..1bb9672 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -2,7 +2,7 @@ require 'hpricot' class Article < ActiveRecord::Base - attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent + attr_accessible :name, :body, :abstract, :profile, :tag_list, :parent, :allow_members_to_edit, :translation_of_id, :language, :license_id, :parent_id, :display_posts_in_current_language, :category_ids, :posts_per_page, :moderate_comments, :accept_comments, :feed, :published, :source, :highlighted acts_as_having_image diff --git a/app/models/article_block.rb b/app/models/article_block.rb index 9a571d8..55ef642 100644 --- a/app/models/article_block.rb +++ b/app/models/article_block.rb @@ -1,5 +1,7 @@ class ArticleBlock < Block + attr_accessible :article_id + def self.description _('Display one of your contents') end diff --git a/app/models/block.rb b/app/models/block.rb index 2ec8446..5a8d757 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -1,6 +1,6 @@ class Block < ActiveRecord::Base - attr_accessible :title, :display + attr_accessible :title, :display, :limit, :box_id # to be able to generate HTML include ActionView::Helpers::UrlHelper diff --git a/app/models/blog.rb b/app/models/blog.rb index 72b1fe3..dcb64cf 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -1,5 +1,7 @@ class Blog < Folder + attr_accessible :visualization_format + acts_as_having_posts include PostsLimit diff --git a/app/models/category.rb b/app/models/category.rb index 800835c..bc2eddb 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,6 +1,6 @@ class Category < ActiveRecord::Base - attr_accessible :name, :parent_id + attr_accessible :name, :parent_id, :display_color, :display_in_menu, :image_builder SEARCHABLE_FIELDS = { :name => 10, diff --git a/app/models/comment.rb b/app/models/comment.rb index eaa7b9e..452f76a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -6,6 +6,8 @@ class Comment < ActiveRecord::Base :body => 2, } + attr_accessible :body, :author, :name, :email, :title, :reply_of_id + validates_presence_of :body belongs_to :source, :counter_cache => true, :polymorphic => true diff --git a/app/models/environment.rb b/app/models/environment.rb index bf2712d..2119be0 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -3,7 +3,7 @@ # domains. class Environment < ActiveRecord::Base - attr_accessible :name, :is_default + attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins has_many :users diff --git a/app/models/input.rb b/app/models/input.rb index 242d2e6..7ae373a 100644 --- a/app/models/input.rb +++ b/app/models/input.rb @@ -1,4 +1,7 @@ class Input < ActiveRecord::Base + + attr_accessible :product, :product_category + belongs_to :product belongs_to :product_category diff --git a/app/models/organization.rb b/app/models/organization.rb index 31c9e39..6547d01 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,6 +1,8 @@ # Represents any organization of the system class Organization < Profile + attr_accessible :moderated_articles + SEARCH_FILTERS += %w[ more_popular more_active diff --git a/app/models/person.rb b/app/models/person.rb index 1166229..5f7c07c 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,6 +1,8 @@ # A person is the profile of an user holding all relationships with the rest of the system class Person < Profile + attr_accessible :organization + SEARCH_FILTERS += %w[ more_popular more_active diff --git a/app/models/product.rb b/app/models/product.rb index 2f5fd50..0373b31 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -11,7 +11,7 @@ class Product < ActiveRecord::Base SEARCH_DISPLAYS = %w[map full] - attr_accessible :name, :product_category + attr_accessible :name, :product_category, :highlighted, :price def self.default_search_display 'full' diff --git a/app/models/production_cost.rb b/app/models/production_cost.rb index 28cfd01..0962776 100644 --- a/app/models/production_cost.rb +++ b/app/models/production_cost.rb @@ -1,5 +1,7 @@ class ProductionCost < ActiveRecord::Base + attr_accessible :name + belongs_to :owner, :polymorphic => true validates_presence_of :owner validates_presence_of :name diff --git a/app/models/products_block.rb b/app/models/products_block.rb index b9c75d2..f2bfd1e 100644 --- a/app/models/products_block.rb +++ b/app/models/products_block.rb @@ -1,5 +1,7 @@ class ProductsBlock < Block + attr_accessible :product_ids + include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers diff --git a/app/models/profile.rb b/app/models/profile.rb index cfd6650..00afc92 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,7 +3,7 @@ # which by default is the one returned by Environment:default. class Profile < ActiveRecord::Base - attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone + attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed # use for internationalizable human type names in search facets # reimplement on subclasses diff --git a/app/models/rss_feed.rb b/app/models/rss_feed.rb index 90a758e..b42ac4d 100644 --- a/app/models/rss_feed.rb +++ b/app/models/rss_feed.rb @@ -1,6 +1,6 @@ class RssFeed < Article - attr_accessible :limit, :enabled, :language + attr_accessible :limit, :enabled, :language, :include def self.type_name _('RssFeed') diff --git a/app/models/state.rb b/app/models/state.rb index ab91e0b..6b22335 100644 --- a/app/models/state.rb +++ b/app/models/state.rb @@ -1,3 +1,3 @@ class State < Region - attr_accessible :name, :acronym + attr_accessible :name, :acronym, :environment end diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index e25096b..c6bc2a0 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -6,7 +6,7 @@ require 'short_filename' # of the file itself is kept. (FIXME?) class UploadedFile < Article - attr_accessible :uploaded_data + attr_accessible :uploaded_data, :title def self.type_name _('File') diff --git a/app/models/validation_info.rb b/app/models/validation_info.rb index d78ccbd..2683531 100644 --- a/app/models/validation_info.rb +++ b/app/models/validation_info.rb @@ -1,4 +1,7 @@ class ValidationInfo < ActiveRecord::Base + + attr_accessible :validation_methodology, :restrictions + validates_presence_of :validation_methodology belongs_to :organization diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 5a39da0..c7e6f32 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -102,7 +102,7 @@ class AccountControllerTest < ActionController::TestCase def test_shoud_not_save_without_acceptance_of_terms_of_use_on_signup assert_no_difference 'User.count' do - Environment.default.update_attributes(:terms_of_use => 'some terms ...') + Environment.default.update_attribute(:terms_of_use, 'some terms ...') new_user assert_response :success assert_nil assigns(:register_pending) @@ -111,7 +111,7 @@ class AccountControllerTest < ActionController::TestCase def test_shoud_save_with_acceptance_of_terms_of_use_on_signup assert_difference 'User.count' do - Environment.default.update_attributes(:terms_of_use => 'some terms ...') + Environment.default.update_attribute(:terms_of_use, 'some terms ...') new_user(:terms_accepted => '1') assert_response :success assert_not_nil assigns(:register_pending) diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb index 5de2332..da36c0f 100644 --- a/test/functional/admin_panel_controller_test.rb +++ b/test/functional/admin_panel_controller_test.rb @@ -245,7 +245,7 @@ class AdminPanelControllerTest < ActionController::TestCase e = Environment.default @controller.stubs(:environment).returns(e) other_e = fast_create(Environment, :name => 'other environment') - c = Community.create!(:name => 'portal community', :environment => other_e) + c = create(Community, :name => 'portal community', :environment => other_e) post :set_portal_community, :portal_community_identifier => c.identifier e.reload diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index e475857..3c89c67 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -174,8 +174,8 @@ class ApplicationControllerTest < ActionController::TestCase should 'display only some categories in menu' do @controller.stubs(:get_layout).returns('application') - c1 = Environment.default.categories.create!(:name => 'Category 1', :display_color => 1, :parent => nil, :display_in_menu => true ) - c2 = Environment.default.categories.create!(:name => 'Category 2', :display_color => nil, :parent => c1, :display_in_menu => true ) + c1 = Environment.default.categories.create!(:name => 'Category 1', :display_color => 1, :parent_id => nil, :display_in_menu => true ) + c2 = Environment.default.categories.create!(:name => 'Category 2', :display_color => nil, :parent_id => c1.id, :display_in_menu => true ) get :index assert_tag :tag => 'a', :content => /Category 2/ end @@ -247,8 +247,8 @@ class ApplicationControllerTest < ActionController::TestCase should 'not display categories menu if categories feature disabled' do Environment.any_instance.stubs(:enabled?).with(anything).returns(true) - c1 = Environment.default.categories.create!(:name => 'Category 1', :display_color => 1, :parent => nil, :display_in_menu => true ) - c2 = Environment.default.categories.create!(:name => 'Category 2', :display_color => nil, :parent => c1, :display_in_menu => true ) + c1 = Environment.default.categories.create!(:name => 'Category 1', :display_color => 1, :parent_id => nil, :display_in_menu => true ) + c2 = Environment.default.categories.create!(:name => 'Category 2', :display_color => nil, :parent_id => c1.id, :display_in_menu => true ) get :index assert_no_tag :tag => 'a', :content => /Category 2/ end diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb index fe65d67..8150450 100644 --- a/test/functional/catalog_controller_test.rb +++ b/test/functional/catalog_controller_test.rb @@ -104,10 +104,10 @@ class CatalogControllerTest < ActionController::TestCase end should 'get categories of the right level' do - pc1 = ProductCategory.create!(:name => "PC1", :environment => @enterprise.environment) - pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) - pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) - pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) + pc1 = create(ProductCategory, :name => "PC1", :environment => @enterprise.environment) + pc2 = create(ProductCategory, :name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) + pc3 = create(ProductCategory, :name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) + pc4 = create(ProductCategory, :name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) @@ -122,10 +122,10 @@ class CatalogControllerTest < ActionController::TestCase end should 'filter products based on level selected' do - pc1 = ProductCategory.create!(:name => "PC1", :environment => @enterprise.environment) - pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) - pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) - pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) + pc1 = create(ProductCategory, :name => "PC1", :environment => @enterprise.environment) + pc2 = create(ProductCategory, :name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) + pc3 = create(ProductCategory, :name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) + pc4 = create(ProductCategory, :name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) @@ -171,10 +171,10 @@ class CatalogControllerTest < ActionController::TestCase end should 'display categories and sub-categories link' do - pc1 = ProductCategory.create!(:name => "PC1", :environment => @enterprise.environment) - pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) - pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) - pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) + pc1 = create(ProductCategory, :name => "PC1", :environment => @enterprise.environment) + pc2 = create(ProductCategory, :name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) + pc3 = create(ProductCategory, :name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) + pc4 = create(ProductCategory, :name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) @@ -190,10 +190,10 @@ class CatalogControllerTest < ActionController::TestCase should 'display categories on breadcrumb' do - pc1 = ProductCategory.create!(:name => "PC1", :environment => @enterprise.environment) - pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) - pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) - pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) + pc1 = create(ProductCategory, :name => "PC1", :environment => @enterprise.environment) + pc2 = create(ProductCategory, :name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) + pc3 = create(ProductCategory, :name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) + pc4 = create(ProductCategory, :name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) @@ -208,7 +208,7 @@ class CatalogControllerTest < ActionController::TestCase end should 'add product status on the class css' do - category = ProductCategory.create!(:name => "Cateogry", :environment => @enterprise.environment) + category = create(ProductCategory, :name => "Cateogry", :environment => @enterprise.environment) p1 = fast_create(Product, :product_category_id => category.id, :enterprise_id => @enterprise.id, :highlighted => true) p2 = fast_create(Product, :product_category_id => category.id, :enterprise_id => @enterprise.id, :available => false) @@ -221,10 +221,10 @@ class CatalogControllerTest < ActionController::TestCase should 'sort categories by name' do environment = @enterprise.environment environment.categories.destroy_all - pc1 = ProductCategory.create!(:name => "Drinks", :environment => environment) - pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment) - pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment) - pc4 = ProductCategory.create!(:name => "Pies", :environment => environment) + pc1 = create(ProductCategory, :name => "Drinks", :environment => environment) + pc2 = create(ProductCategory, :name => "Bananas", :environment => environment) + pc3 = create(ProductCategory, :name => "Sodas", :environment => environment) + pc4 = create(ProductCategory, :name => "Pies", :environment => environment) p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id) p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id) p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id) @@ -240,8 +240,8 @@ class CatalogControllerTest < ActionController::TestCase p2 = fast_create(Product, :product_category_id => @product_category.id, :enterprise_id => @enterprise.id) Product.any_instance.stubs(:price_described?).returns(true) production_cost = fast_create(ProductionCost) - pd1 = PriceDetail.create!(:product => p1, :production_cost => production_cost) - pd2 = PriceDetail.create!(:product => p2) + pd1 = create(PriceDetail, :product => p1, :production_cost_id => production_cost.id) + pd2 = create(PriceDetail, :product => p2) get :index, :profile => @enterprise.identifier diff --git a/test/functional/categories_controller_test.rb b/test/functional/categories_controller_test.rb index 765f0aa..ce4737c 100644 --- a/test/functional/categories_controller_test.rb +++ b/test/functional/categories_controller_test.rb @@ -74,7 +74,7 @@ class CategoriesControllerTest < ActionController::TestCase end def test_remove - cat = Category.create!(:name => 'a category to be removed', :environment_id => env.id) + cat = create(Category, :name => 'a category to be removed', :environment_id => env.id) post :remove, :id => cat.id assert_redirected_to :action => 'index' assert_raise ActiveRecord::RecordNotFound do @@ -90,13 +90,13 @@ class CategoriesControllerTest < ActionController::TestCase end should 'expire categories menu cache when some menu category is updated' do - cat = Category.create!(:name => 'test category in menu', :environment => Environment.default, :display_in_menu => true) + cat = create(Category, :name => 'test category in menu', :environment => Environment.default, :display_in_menu => true) @controller.expects(:expire_fragment).with(:controller => 'public', :action => 'categories_menu').at_least_once post :edit, :id => cat.id, :category => { :name => 'new name for category in menu' } end should 'not touch categories menu cache whem updated category is not in menu' do - cat = Category.create!(:name => 'test category not in menu', :environment => Environment.default, :display_in_menu => false) + cat = create(Category, :name => 'test category not in menu', :environment => Environment.default, :display_in_menu => false) @controller.expects(:expire_fragment).with(:controller => 'public', :action => 'categories_menu').never post :edit, :id => cat.id, :category => { :name => 'new name for category not in menu' } end @@ -107,7 +107,7 @@ class CategoriesControllerTest < ActionController::TestCase end should 'not handle cache when viewing "edit category" screen' do - cat = Category.create!(:name => 'test category in menu', :environment => Environment.default, :display_in_menu => true) + cat = create(Category, :name => 'test category in menu', :environment => Environment.default, :display_in_menu => true) @controller.expects(:expire_fragment).with(:controller => 'public', :action => 'categories_menu').never get :edit, :id => cat.id end @@ -123,7 +123,7 @@ class CategoriesControllerTest < ActionController::TestCase end should 'not expire cache when updating fails' do - cat = Category.create!(:name => 'test category in menu', :environment => Environment.default, :display_in_menu => true) + cat = create(Category, :name => 'test category in menu', :environment => Environment.default, :display_in_menu => true) @controller.expects(:expire_fragment).with(:controller => 'public', :action => 'categories_menu').never post :edit, :id => cat.id, :category => { :name => '' } @@ -155,9 +155,9 @@ class CategoriesControllerTest < ActionController::TestCase should 'not list regions and product categories' do Environment.default.categories.destroy_all - c = Category.create!(:name => 'Regular category', :environment => Environment.default) - p = ProductCategory.create!(:name => 'Product category', :environment => Environment.default) - r = Region.create!(:name => 'Some region', :environment => Environment.default) + c = create(Category, :name => 'Regular category', :environment => Environment.default) + p = create(ProductCategory, :name => 'Product category', :environment => Environment.default) + r = create(Region, :name => 'Some region', :environment => Environment.default) get :index assert_equal [c], assigns(:categories) @@ -166,7 +166,7 @@ class CategoriesControllerTest < ActionController::TestCase end should 'use parent\'s type to determine subcategory\'s type' do - parent = ProductCategory.create!(:name => 'Sample category', :environment => Environment.default) + parent = create(ProductCategory, :name => 'Sample category', :environment => Environment.default) post :new, :parent_id => parent.id, :parent_type => parent.class.name, :category => {:name => 'Subcategory'} sub = ProductCategory.find_by_name('Subcategory') assert_equal parent.class, sub.class diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 58a86e5..80ee9e3 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -284,7 +284,7 @@ class CmsControllerTest < ActionController::TestCase should 'be able to update a RSS feed' do login_as(profile.identifier) - feed = RssFeed.create!(:name => 'myfeed', :limit => 5, :include => 'all', :profile_id => profile.id) + feed = create(RssFeed, :name => 'myfeed', :limit => 5, :include => 'all', :profile_id => profile.id) post :edit, :profile => profile.identifier, :id => feed.id, :article => { :limit => 77, :include => 'parent_and_children' } assert_response :redirect @@ -585,7 +585,7 @@ class CmsControllerTest < ActionController::TestCase should 'redirect back to article after editing article inside a folder' do f = Folder.new(:name => 'f'); profile.articles << f; f.save! - a = TextileArticle.create!(:parent => f, :name => 'article-inside-folder', :profile_id => profile.id) + a = create(TextileArticle, :parent => f, :name => 'article-inside-folder', :profile_id => profile.id) post :edit, :profile => profile.identifier, :id => a.id assert_redirected_to @profile.articles.find_by_name('article-inside-folder').url @@ -612,7 +612,7 @@ class CmsControllerTest < ActionController::TestCase should 'point back to folder when cancelling edition of an article inside it' do f = Folder.new(:name => 'f'); profile.articles << f; f.save! - a = TextileArticle.create!(:name => 'test', :parent => f, :profile_id => profile.id) + a = create(TextileArticle, :name => 'test', :parent => f, :profile_id => profile.id) get :edit, :profile => profile.identifier, :id => a.id assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/view/#{f.id}" }, :descendant => { :content => /Cancel/ } @@ -641,7 +641,7 @@ class CmsControllerTest < ActionController::TestCase end should "display properly a non-published articles' status" do - article = profile.articles.create!(:name => 'test', :published => false) + article = create(Article, :profile => profile, :name => 'test', :published => false) get :edit, :profile => profile.identifier, :id => article.id assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'article[published]', :id => 'article_published_true' } @@ -734,7 +734,7 @@ class CmsControllerTest < ActionController::TestCase end should 'create a private article child of private folder' do - folder = Folder.new(:name => 'my intranet', :published => false); profile.articles << folder; folder.save! + folder = build(Folder, :name => 'my intranet', :published => false); profile.articles << folder; folder.save! post :new, :profile => profile.identifier, :type => 'TextileArticle', :parent_id => folder.id, :article => { :name => 'new-private-article'} folder.reload @@ -901,7 +901,7 @@ class CmsControllerTest < ActionController::TestCase end should 'remove the image of an article' do - blog = Blog.create(:profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) + blog = create(Blog, :profile_id => profile.id, :name=>'testblog', :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}) blog.save! post :edit, :profile => profile.identifier, :id => blog.id, :remove_image => 'true' blog.reload @@ -1194,7 +1194,7 @@ class CmsControllerTest < ActionController::TestCase should 'not allow user edit article if he is owner but has no publish permission' do c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') u = create_user_with_permission('test_user', 'bogus_permission', c) - a = c.articles.create!(:name => 'test_article', :last_changed_by => u) + a = create(Article, :profile => c, :name => 'test_article', :last_changed_by => u) login_as :test_user get :edit, :profile => c.identifier, :id => a.id @@ -1205,7 +1205,7 @@ class CmsControllerTest < ActionController::TestCase should 'allow user edit article if he is owner and has publish permission' do c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') u = create_user_with_permission('test_user', 'publish_content', c) - a = c.articles.create!(:name => 'test_article', :last_changed_by => u) + a = create(Article, :profile => c, :name => 'test_article', :last_changed_by => u) login_as :test_user @controller.stubs(:user).returns(u) diff --git a/test/functional/comment_controller_test.rb b/test/functional/comment_controller_test.rb index a5cdf8a..53e9425 100644 --- a/test/functional/comment_controller_test.rb +++ b/test/functional/comment_controller_test.rb @@ -266,7 +266,7 @@ class CommentControllerTest < ActionController::TestCase should 'not create ApproveComment task when the comment author is the same of article author' do login_as @profile.identifier community = Community.create!(:name => 'testcomm') - page = community.articles.create!(:name => 'myarticle', :moderate_comments => true, :last_changed_by => @profile) + page = create(Article, :profile => community, :name => 'myarticle', :moderate_comments => true, :last_changed_by => @profile) community.add_moderator(@profile) assert_no_difference 'ApproveComment.count' do @@ -381,7 +381,7 @@ class CommentControllerTest < ActionController::TestCase should 'touch article after adding a comment' do yesterday = Time.now.yesterday Article.record_timestamps = false - page = profile.articles.create(:name => 'myarticle', :body => 'the body of the text', :created_at => yesterday, :updated_at => yesterday) + page = create(Article, :profile => profile, :name => 'myarticle', :body => 'the body of the text', :created_at => yesterday, :updated_at => yesterday) Article.record_timestamps = true login_as @profile.identifier diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index d2eb03b..8e02a2f 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -122,7 +122,7 @@ class ContentViewerControllerTest < ActionController::TestCase should 'not display forbidden articles' do profile.articles.create!(:name => 'test') - profile.update_attributes!(:public_content => false) + profile.update_attributes!({:public_content => false}, :without_protection => true) Article.any_instance.expects(:display_to?).with(anything).returns(false) get :view_page, :profile => profile.identifier, :page => [ 'test' ] @@ -131,7 +131,7 @@ class ContentViewerControllerTest < ActionController::TestCase should 'display allowed articles' do profile.articles.create!(:name => 'test') - profile.update_attributes!(:public_content => false) + profile.update_attributes!({:public_content => false}, :without_protection => true) Article.any_instance.expects(:display_to?).with(anything).returns(true) get :view_page, :profile => profile.identifier, :page => [ 'test' ] @@ -384,7 +384,7 @@ class ContentViewerControllerTest < ActionController::TestCase end should 'not show a profile in an environment that is not its home environment' do - p = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment => Environment.default) + p = create(Profile, :identifier => 'mytestprofile', :name => 'My test profile', :environment => Environment.default) current = fast_create(Environment, :name => 'test environment') current.domains.create!(:name => 'example.com') @@ -458,7 +458,7 @@ class ContentViewerControllerTest < ActionController::TestCase blog = Blog.create!(:name => "blog", :profile => profile) profile.articles << blog - past_post = TextileArticle.create!(:name => "past post", :profile => profile, :parent => blog, :published_at => blog.created_at - 1.year) + past_post = create(TextileArticle, :name => "past post", :profile => profile, :parent => blog, :published_at => blog.created_at - 1.year) current_post = TextileArticle.create!(:name => "current post", :profile => profile, :parent => blog) blog.children << past_post blog.children << current_post @@ -726,7 +726,7 @@ class ContentViewerControllerTest < ActionController::TestCase c = Community.create!(:name => 'test_com') u = create_user_with_permission('test_user', 'publish_content', c) login_as u.identifier - a = c.articles.create!(:name => 'test-article', :last_changed_by => u, :published => false) + a = create(Article, :profile => c, :name => 'test-article', :last_changed_by => u, :published => false) get :view_page, :profile => c.identifier, :page => a.explode_path @@ -738,7 +738,7 @@ class ContentViewerControllerTest < ActionController::TestCase c = Community.create!(:name => 'test_com') u = create_user_with_permission('test_user', 'publish_content', c) login_as u.identifier - a = c.articles.create!(:name => 'test-article', :last_changed_by => profile, :published => true) + a = create(Article, :profile => c, :name => 'test-article', :last_changed_by => profile, :published => true) xhr :get, :view_page, :profile => c.identifier, :page => a.explode_path, :toolbar => true @@ -847,7 +847,7 @@ class ContentViewerControllerTest < ActionController::TestCase forum = Forum.create!(:name => "forum", :profile => profile) profile.articles << forum - past_post = TextileArticle.create!(:name => "past post", :profile => profile, :parent => forum, :published_at => forum.created_at - 1.year) + past_post = create(TextileArticle, :name => "past post", :profile => profile, :parent => forum, :published_at => forum.created_at - 1.year) current_post = TextileArticle.create!(:name => "current post", :profile => profile, :parent => forum) forum.children << past_post forum.children << current_post @@ -1051,7 +1051,7 @@ class ContentViewerControllerTest < ActionController::TestCase article = profile.articles.build(:name => 'test') article.save! Comment.destroy_all - comment = Comment.create!(:author => profile, :title => 'a comment', :body => 'lalala', :article => article) + comment = article.comments.create!(:author => profile, :title => 'a comment', :body => 'lalala') login_as 'testuser' get :view_page, :profile => 'testuser', :page => [ 'test' ] assert_tag :tag => 'a', :attributes => { :class => /comment-actions-reply/ } diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb index 99233ef..3f48d99 100644 --- a/test/functional/home_controller_test.rb +++ b/test/functional/home_controller_test.rb @@ -81,7 +81,7 @@ class HomeControllerTest < ActionController::TestCase should 'display block in index page if it\'s configured to display on homepage and its an environment block' do env = Environment.default - box = Box.create(:owner_type => 'Environment', :owner_id => env.id) + box = create(Box, :owner_type => 'Environment', :owner_id => env.id) block = Block.create(:title => "Index Block", :box_id => box.id, :display => 'home_page_only') env.save! diff --git a/test/functional/invite_controller_test.rb b/test/functional/invite_controller_test.rb index 6683079..161d013 100644 --- a/test/functional/invite_controller_test.rb +++ b/test/functional/invite_controller_test.rb @@ -185,7 +185,7 @@ class InviteControllerTest < ActionController::TestCase end should 'return hash as invitation data if contact list was fetched' do - contact_list = ContactList.create(:fetched => true) + contact_list = create(ContactList, :fetched => true) get :invitation_data, :profile => profile.identifier, :contact_list => contact_list.id hash = {'fetched' => true, 'contact_list' => contact_list.id, 'error' => nil} @@ -194,7 +194,7 @@ class InviteControllerTest < ActionController::TestCase end should 'render empty list of contacts' do - contact_list = ContactList.create(:fetched => true) + contact_list = create(ContactList, :fetched => true) get :add_contact_list, :profile => profile.identifier, :contact_list => contact_list.id assert_response :success @@ -203,7 +203,7 @@ class InviteControllerTest < ActionController::TestCase end should 'render list of contacts' do - contact_list = ContactList.create(:fetched => true, :list => ['email1@noosfero.org', 'email2@noosfero.org']) + contact_list = create(ContactList, :fetched => true, :list => ['email1@noosfero.org', 'email2@noosfero.org']) get :add_contact_list, :profile => profile.identifier, :contact_list => contact_list.id assert_response :success diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 035da79..7f91835 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -261,7 +261,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'link back to index from product show' do - enterprise = Enterprise.create!(:name => 'test_enterprise_1', :identifier => 'test_enterprise_1', :environment => Environment.default) + enterprise = create(Enterprise, :name => 'test_enterprise_1', :identifier => 'test_enterprise_1', :environment => Environment.default) prod = enterprise.products.create!(:name => 'Product test', :product_category => @product_category) get :show, :id => prod.id, :profile => enterprise.identifier assert_tag({ diff --git a/test/functional/map_balloon_controller_test.rb b/test/functional/map_balloon_controller_test.rb index 66a2b08..f058a55 100644 --- a/test/functional/map_balloon_controller_test.rb +++ b/test/functional/map_balloon_controller_test.rb @@ -17,14 +17,14 @@ class MapBalloonControllerTest < ActionController::TestCase end should 'find product to show' do - prod = Product.create!(:name => 'Product1', :product_category_id => fast_create(ProductCategory).id, + prod = create(Product, :name => 'Product1', :product_category_id => fast_create(ProductCategory).id, :enterprise_id => fast_create(Enterprise).id) get :product, :id => prod.id assert_equal prod, assigns(:product) end should 'find person to show' do - pers = Person.create!(:name => 'Person1', :user_id => fast_create(User).id, :identifier => 'pers1') + pers = create(Person, :name => 'Person1', :user_id => fast_create(User).id, :identifier => 'pers1') get :person, :id => pers.id assert_equal pers, assigns(:profile) end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index ef3ba2a..113f4aa 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -367,7 +367,7 @@ class ProfileControllerTest < ActionController::TestCase should 'display contact button for community if its enable in environment' do env = Environment.default - community = Community.create!(:name => 'my test community', :environment => env) + community = create(Community, :name => 'my test community', :environment => env) community.boxes.first.blocks << block = ProfileInfoBlock.create! env.disable('disable_contact_community') env.save! @@ -379,7 +379,7 @@ class ProfileControllerTest < ActionController::TestCase should 'not display contact button for community if its disable in environment' do env = Environment.default - community = Community.create!(:name => 'my test community', :environment => env) + community = create(Community, :name => 'my test community', :environment => env) community.boxes.first.blocks << block = ProfileInfoBlock.create! env.enable('disable_contact_community') env.save! @@ -499,7 +499,7 @@ class ProfileControllerTest < ActionController::TestCase end should 'show number of published posts in index' do - profile.articles << blog = Blog.create(:name => 'Blog', :profile_id => profile.id) + profile.articles << blog = create(Blog, :name => 'Blog', :profile_id => profile.id) fast_create(TextileArticle, :name => 'Published post', :parent_id => profile.blog.id, :profile_id => profile.id) fast_create(TextileArticle, :name => 'Other published post', :parent_id => profile.blog.id, :profile_id => profile.id) fast_create(TextileArticle, :name => 'Unpublished post', :parent_id => profile.blog.id, :profile_id => profile.id, :published => false) @@ -574,8 +574,8 @@ class ProfileControllerTest < ActionController::TestCase end should 'reverse the order of posts in tag feed' do - TextileArticle.create!(:name => 'First post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now) - TextileArticle.create!(:name => 'Second post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now + 1.day) + create(TextileArticle, :name => 'First post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now) + create(TextileArticle, :name => 'Second post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now + 1.day) get :tag_feed, :profile => profile.identifier, :id => 'tag1' assert_match(/Second.*First/, @response.body) @@ -583,11 +583,11 @@ class ProfileControllerTest < ActionController::TestCase should 'display the most recent posts in tag feed' do start = Time.now - 30.days - first = TextileArticle.create!(:name => 'First post', :profile => profile, :tag_list => 'tag1', :published_at => start) + first = create(TextileArticle, :name => 'First post', :profile => profile, :tag_list => 'tag1', :published_at => start) 20.times do |i| - TextileArticle.create!(:name => 'Post #' + i.to_s, :profile => profile, :tag_list => 'tag1', :published_at => start + i.days) + create(TextileArticle, :name => 'Post #' + i.to_s, :profile => profile, :tag_list => 'tag1', :published_at => start + i.days) end - last = TextileArticle.create!(:name => 'Last post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now) + last = create(TextileArticle, :name => 'Last post', :profile => profile, :tag_list => 'tag1', :published_at => Time.now) get :tag_feed, :profile => profile.identifier, :id => 'tag1' assert_no_match(/First post/, @response.body) # First post is older than other 20 posts already @@ -699,7 +699,7 @@ class ProfileControllerTest < ActionController::TestCase should "display a scrap sent" do another_person = fast_create(Person) - Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap')) + create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap')) login_as(profile.identifier) get :index, :profile => profile.identifier assert_tag :tag => 'p', :content => 'A scrap' @@ -707,7 +707,7 @@ class ProfileControllerTest < ActionController::TestCase should "not display a scrap sent by a removed user" do another_person = fast_create(Person) - Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap')) + create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap')) login_as(profile.identifier) another_person.destroy get :index, :profile => profile.identifier @@ -719,13 +719,13 @@ class ProfileControllerTest < ActionController::TestCase p2= fast_create(Person) UserStampSweeper.any_instance.stubs(:current_user).returns(p1) - scrap1 = Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p2)) + scrap1 = create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p2)) UserStampSweeper.any_instance.stubs(:current_user).returns(p2) - scrap2 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p1)) + scrap2 = create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p1)) UserStampSweeper.any_instance.stubs(:current_user).returns(p1) - TinyMceArticle.create!(:profile => p1, :name => 'An article about free software') + create(TinyMceArticle, :profile => p1, :name => 'An article about free software') a1 = ActionTracker::Record.last login_as(profile.identifier) @@ -736,7 +736,7 @@ class ProfileControllerTest < ActionController::TestCase should 'see the activities_items paginated' do p1 = create_user('some').person ActionTracker::Record.destroy_all - 40.times{Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1))} + 40.times{create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1))} login_as(p1.identifier) get :index, :profile => p1.identifier assert_equal 15, assigns(:activities).count @@ -750,8 +750,8 @@ class ProfileControllerTest < ActionController::TestCase assert p3.is_a_friend?(profile) ActionTracker::Record.destroy_all - scrap1 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) - scrap2 = Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => profile)) + scrap1 = create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3)) + scrap2 = create(Scrap, defaults_for_scrap(:sender => p2, :receiver => profile)) UserStampSweeper.any_instance.stubs(:current_user).returns(p3) article1 = TinyMceArticle.create!(:profile => p3, :name => 'An article about free software') @@ -773,13 +773,13 @@ class ProfileControllerTest < ActionController::TestCase p3.add_friend(p1) assert p3.is_a_friend?(p1) ActionTracker::Record.destroy_all - Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1)) + create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1)) a1 = ActionTracker::Record.last UserStampSweeper.any_instance.stubs(:current_user).returns(p2) - Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) + create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3)) a2 = ActionTracker::Record.last UserStampSweeper.any_instance.stubs(:current_user).returns(p3) - Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1)) + create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1)) a3 = ActionTracker::Record.last @@ -805,13 +805,13 @@ class ProfileControllerTest < ActionController::TestCase p3.add_friend(p1) assert p3.is_a_friend?(p1) ActionTracker::Record.destroy_all - Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1)) + create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1)) a1 = ActionTracker::Record.last UserStampSweeper.any_instance.stubs(:current_user).returns(p2) - Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) + create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3)) a2 = ActionTracker::Record.last UserStampSweeper.any_instance.stubs(:current_user).returns(p3) - Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1)) + create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1)) a3 = ActionTracker::Record.last @controller.stubs(:logged_in?).returns(true) @@ -854,13 +854,13 @@ class ProfileControllerTest < ActionController::TestCase p3.add_friend(p1) assert p3.is_a_friend?(p1) ActionTracker::Record.destroy_all - Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1)) + create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1)) a1 = ActionTracker::Record.last UserStampSweeper.any_instance.stubs(:current_user).returns(p2) - Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) + create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3)) a2 = ActionTracker::Record.last UserStampSweeper.any_instance.stubs(:current_user).returns(p3) - Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1)) + create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1)) a3 = ActionTracker::Record.last login_as(profile.identifier) @@ -889,10 +889,10 @@ class ProfileControllerTest < ActionController::TestCase community.add_member(p1) community.add_member(p2) ActionTracker::Record.destroy_all - Article.create! :name => 'a', :profile_id => community.id - Article.create! :name => 'b', :profile_id => community.id + create(Article, :name => 'a', :profile_id => community.id) + create(Article, :name => 'b', :profile_id => community.id) UserStampSweeper.any_instance.stubs(:current_user).returns(p2) - Article.create! :name => 'c', :profile_id => community.id + create(Article, :name => 'c', :profile_id => community.id) process_delayed_job_queue get :index, :profile => community.identifier @@ -916,13 +916,13 @@ class ProfileControllerTest < ActionController::TestCase p3.add_friend(p1) assert p3.is_a_friend?(p1) ActionTracker::Record.destroy_all - Scrap.create!(defaults_for_scrap(:sender => p1, :receiver => p1)) + create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1)) a1 = ActionTracker::Record.last UserStampSweeper.any_instance.stubs(:current_user).returns(p2) - Scrap.create!(defaults_for_scrap(:sender => p2, :receiver => p3)) + create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3)) a2 = ActionTracker::Record.last UserStampSweeper.any_instance.stubs(:current_user).returns(p3) - Scrap.create!(defaults_for_scrap(:sender => p3, :receiver => p1)) + create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1)) a3 = ActionTracker::Record.last get :index, :profile => p1.identifier @@ -1141,7 +1141,7 @@ class ProfileControllerTest < ActionController::TestCase login_as(profile.identifier) article = TinyMceArticle.create!(:profile => profile, :name => 'An Article about Free Software') ActionTracker::Record.destroy_all - 40.times{ ActionTracker::Record.create!(:user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image})} + 40.times{ create(ActionTracker::Record, :user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image})} assert_equal 40, profile.tracked_actions.count assert_equal 40, profile.activities.count get :view_more_activities, :profile => profile.identifier, :page => 2 @@ -1174,7 +1174,7 @@ class ProfileControllerTest < ActionController::TestCase login_as(profile.identifier) article = TinyMceArticle.create!(:profile => profile, :name => 'An Article about Free Software') ActionTracker::Record.destroy_all - activity = ActionTracker::Record.create!(:user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image}) + activity = create(ActionTracker::Record, :user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image}) 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} article.reload get :index, :profile => profile.identifier @@ -1185,7 +1185,7 @@ class ProfileControllerTest < ActionController::TestCase login_as(profile.identifier) article = TinyMceArticle.create!(:profile => profile, :name => 'An Article about Free Software') ActionTracker::Record.destroy_all - activity = ActionTracker::Record.create!(:user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image}) + activity = create(ActionTracker::Record, :user_id => profile.id, :user_type => 'Profile', :verb => 'create_article', :target_id => article.id, :target_type => 'Article', :params => {'name' => article.name, 'url' => article.url, 'lead' => article.lead, 'first_image' => article.first_image}) 20.times {comment = fast_create(Comment, :source_id => article, :title => 'a comment', :body => 'lalala', :created_at => Time.now)} article.reload assert_equal 20, article.comments.count @@ -1319,7 +1319,7 @@ class ProfileControllerTest < ActionController::TestCase should 'display activities and scraps together' do another_person = fast_create(Person) - Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap')) + create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap')) UserStampSweeper.any_instance.stubs(:current_user).returns(profile) ActionTracker::Record.destroy_all @@ -1334,7 +1334,7 @@ class ProfileControllerTest < ActionController::TestCase should 'have scraps and activities on activities' do another_person = fast_create(Person) - scrap = Scrap.create!(defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap')) + scrap = create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap')) UserStampSweeper.any_instance.stubs(:current_user).returns(profile) ActionTracker::Record.destroy_all @@ -1387,7 +1387,7 @@ class ProfileControllerTest < ActionController::TestCase UserStampSweeper.any_instance.stubs(:current_user).returns(profile) article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') to_be_removed = create_user('removed_user').person - comment = Comment.create!(:author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') + comment = create(Comment, :author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') to_be_removed.destroy login_as(profile.identifier) @@ -1399,7 +1399,7 @@ class ProfileControllerTest < ActionController::TestCase should 'not display spam comments in wall' do UserStampSweeper.any_instance.stubs(:current_user).returns(profile) article = TinyMceArticle.create!(:profile => profile, :name => 'An article about spam\'s nutritional attributes') - comment = Comment.create!(:author => profile, :title => 'Test Comment', :body => 'This article makes me hungry', :source_id => article.id, :source_type => 'Article') + comment = create(Comment, :author => profile, :title => 'Test Comment', :body => 'This article makes me hungry', :source_id => article.id, :source_type => 'Article') comment.spam! login_as(profile.identifier) get :index, :profile => profile.identifier @@ -1410,7 +1410,7 @@ class ProfileControllerTest < ActionController::TestCase should 'display comment in wall from non logged users' do UserStampSweeper.any_instance.stubs(:current_user).returns(profile) article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') - comment = Comment.create!(:name => 'outside user', :email => 'outside@localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') + comment = create(Comment, :name => 'outside user', :email => 'outside@localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') login_as(profile.identifier) get :index, :profile => profile.identifier diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index ccdb899..a9efb4f 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -68,7 +68,7 @@ class ProfileEditorControllerTest < ActionController::TestCase should 'display categories to choose to associate profile' do cat1 = Environment.default.categories.build(:display_in_menu => true, :name => 'top category'); cat1.save! - cat2 = Environment.default.categories.build(:display_in_menu => true, :name => 'sub category', :parent => cat1); cat2.save! + cat2 = Environment.default.categories.build(:display_in_menu => true, :name => 'sub category', :parent_id => cat1.id); cat2.save! person = profile get :edit, :profile => profile.identifier assert_response :success @@ -78,7 +78,7 @@ class ProfileEditorControllerTest < ActionController::TestCase should 'save categorization of profile' do cat1 = Environment.default.categories.build(:name => 'top category'); cat1.save! - cat2 = Environment.default.categories.build(:name => 'sub category', :parent => cat1); cat2.save! + cat2 = Environment.default.categories.build(:name => 'sub category', :parent_id => cat1.id); cat2.save! person = profile post :edit, :profile => profile.identifier, :profile_data => {:category_ids => [cat2.id]} assert_response :redirect @@ -233,7 +233,7 @@ class ProfileEditorControllerTest < ActionController::TestCase should 'show categories links on edit profile' do cat1 = Environment.default.categories.create!(:display_in_menu => true, :name => 'top category') - cat2 = Environment.default.categories.create!(:display_in_menu => true, :name => 'sub category', :parent => cat1) + cat2 = Environment.default.categories.create!(:display_in_menu => true, :name => 'sub category', :parent_id => cat1.id) person = create_user('testuser').person get :edit, :profile => 'testuser' assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'profile_data[category_ids][]', :value => cat2.id} diff --git a/test/functional/region_validators_controller_test.rb b/test/functional/region_validators_controller_test.rb index 2447fe2..1ea7114 100644 --- a/test/functional/region_validators_controller_test.rb +++ b/test/functional/region_validators_controller_test.rb @@ -51,7 +51,7 @@ class RegionValidatorsControllerTest < ActionController::TestCase region = Region.new(:name => 'my region') environment.regions << region assert !region.new_record? - org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id) + org = create(Organization, :name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id) @controller.expects(:environment).returns(environment).at_least_once @@ -67,7 +67,7 @@ class RegionValidatorsControllerTest < ActionController::TestCase region = Region.new(:name => 'my region') environment.regions << region assert !region.new_record? - org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id) + org = create(Organization, :name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id) @controller.expects(:environment).returns(environment).at_least_once @@ -84,7 +84,7 @@ class RegionValidatorsControllerTest < ActionController::TestCase region = Region.new(:name => 'my region') environment.regions << region assert !region.new_record? - org = Organization.create!(:name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id) + org = create(Organization, :name => "My frufru organization", :identifier => 'frufru', :environment_id => environment.id) region.validators << org @controller.expects(:environment).returns(environment).at_least_once diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index e4daaf0..cbe4371 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -13,7 +13,7 @@ class SearchControllerTest < ActionController::TestCase @request.stubs(:ssl?).returns(false) @response = ActionController::TestResponse.new - @category = Category.create!(:name => 'my category', :environment => Environment.default) + @category = create(Category, :name => 'my category', :environment => Environment.default) env = Environment.default domain = env.domains.first @@ -246,8 +246,8 @@ class SearchControllerTest < ActionController::TestCase end should 'search in category hierachy' do - parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) - child = Category.create!(:name => 'Child Category', :environment => Environment.default, :parent => parent) + parent = create(Category, :name => 'Parent Category', :environment => Environment.default) + child = create(Category, :name => 'Child Category', :environment => Environment.default, :parent => parent) p = create_profile_with_optional_category(Person, 'test_profile', child) @@ -277,10 +277,10 @@ class SearchControllerTest < ActionController::TestCase should 'search all enabled assets in general search' do ent1 = create_profile_with_optional_category(Enterprise, 'test enterprise') - prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) + prod_cat = create(ProductCategory, :name => 'pctest', :environment => Environment.default) prod = ent1.products.create!(:name => 'test product', :product_category => prod_cat) - art = Article.create!(:name => 'test article', :profile_id => fast_create(Person).id) - per = Person.create!(:name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) + art = create(Article, :name => 'test article', :profile_id => fast_create(Person).id) + per = create(Person, :name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) com = Community.create!(:name => 'test community') eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id) @@ -294,8 +294,8 @@ class SearchControllerTest < ActionController::TestCase end should 'display category image while in directory' do - parent = Category.create!(:name => 'category1', :environment => Environment.default) - cat = Category.create!(:name => 'category2', :environment => Environment.default, :parent => parent, + parent = create(Category, :name => 'category1', :environment => Environment.default) + cat = create(Category, :name => 'category2', :environment => Environment.default, :parent => parent, :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} ) @@ -379,10 +379,10 @@ class SearchControllerTest < ActionController::TestCase end should 'display only within a product category when specified' do - prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) + prod_cat = create(ProductCategory, :name => 'prod cat test', :environment => Environment.default) ent = create_profile_with_optional_category(Enterprise, 'test ent') - p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent) + p = create(Product, :product_category => prod_cat, :name => 'prod test 1', :enterprise => ent) get :products, :product_category => prod_cat.id @@ -390,12 +390,12 @@ class SearchControllerTest < ActionController::TestCase end should 'display properly in conjuntion with a category' do - cat = Category.create(:name => 'cat', :environment => Environment.default) - prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) - prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) + cat = create(Category, :name => 'cat', :environment => Environment.default) + prod_cat1 = create(ProductCategory, :name => 'prod cat test 1', :environment => Environment.default) + prod_cat2 = create(ProductCategory, :name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) ent = create_profile_with_optional_category(Enterprise, 'test ent', cat) - product = prod_cat2.products.create!(:name => 'prod test 1', :enterprise_id => ent.id) + product = create(Product, :product_category => prod_cat2, :name => 'prod test 1', :enterprise_id => ent.id) get :products, :category_path => cat.path.split('/'), :product_category => prod_cat1.id @@ -588,7 +588,7 @@ class SearchControllerTest < ActionController::TestCase should 'show tag cloud' do @controller.stubs(:is_cache_expired?).returns(true) - a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) + a = create(Article, :name => 'my article', :profile_id => fast_create(Person).id) a.tag_list = ['one', 'two'] a.save_tags @@ -600,8 +600,8 @@ class SearchControllerTest < ActionController::TestCase should 'show tagged content' do @controller.stubs(:is_cache_expired?).returns(true) - a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) - a2 = Article.create!(:name => 'my article 2', :profile_id => fast_create(Person).id) + a = Article.create!(:name => 'my article', :profile => fast_create(Person)) + a2 = Article.create!(:name => 'my article 2', :profile => fast_create(Person)) a.tag_list = ['one', 'two'] a2.tag_list = ['two', 'three'] a.save_tags @@ -630,9 +630,9 @@ class SearchControllerTest < ActionController::TestCase should 'order articles by more recent' do Article.destroy_all - art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days) - art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now) - art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days) + art1 = create(Article, :name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days) + art2 = create(Article, :name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now) + art3 = create(Article, :name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days) get :articles, :filter => :more_recent @@ -641,14 +641,14 @@ class SearchControllerTest < ActionController::TestCase should 'add highlighted CSS class around a highlighted product' do enterprise = fast_create(Enterprise) - product = Product.create!(:name => 'Enter Sandman', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => true) + product = create(Product, :name => 'Enter Sandman', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => true) get :products assert_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Enter Sandman/ end should 'do not add highlighted CSS class around an ordinary product' do enterprise = fast_create(Enterprise) - product = Product.create!(:name => 'Holier Than Thou', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => false) + product = create(Product, :name => 'Holier Than Thou', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => false) get :products assert_no_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Holier Than Thou/ end @@ -656,7 +656,7 @@ class SearchControllerTest < ActionController::TestCase protected def create_event(profile, options) - ev = Event.new({ :name => 'some event', :start_date => Date.new(2008,1,1) }.merge(options)) + ev = build(Event, { :name => 'some event', :start_date => Date.new(2008,1,1) }.merge(options)) ev.profile = profile ev.save! ev diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 145a5dc..60ee3a8 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -59,8 +59,8 @@ class TasksControllerTest < ActionController::TestCase should 'list processed tasks without spam' do requestor = fast_create(Person) - task_spam = Task.create!(:status => Task::Status::FINISHED, :requestor => requestor, :target => profile, :spam => true) - task_ham = Task.create!(:status => Task::Status::FINISHED, :requestor => requestor, :target => profile, :spam => false) + task_spam = create(Task, :status => Task::Status::FINISHED, :requestor => requestor, :target => profile, :spam => true) + task_ham = create(Task, :status => Task::Status::FINISHED, :requestor => requestor, :target => profile, :spam => false) get :processed assert_response :success @@ -197,7 +197,7 @@ class TasksControllerTest < ActionController::TestCase c = fast_create(Community) c.update_attributes(:moderated_articles => false) @controller.stubs(:profile).returns(c) - folder = c.articles.create!(:name => 'test folder', :type => 'Folder') + folder = create(Article, :profile => c, :name => 'test folder', :type => 'Folder') c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) @@ -210,7 +210,7 @@ class TasksControllerTest < ActionController::TestCase c = fast_create(Community) c.update_attributes(:moderated_articles => false) @controller.stubs(:profile).returns(c) - folder = c.articles.create!(:name => 'test folder', :type => 'Folder') + folder = create(Article, :profile => c, :name => 'test folder', :type => 'Folder') c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') t = ApproveArticle.create!(:article => article, :target => c, :requestor => profile) @@ -357,10 +357,10 @@ class TasksControllerTest < ActionController::TestCase should 'return tasks ordered accordingly and limited by pages' do time = Time.now person = fast_create(Person) - t1 = Task.create!(:status => Task::Status::ACTIVE, :target => profile, :requestor => person, :created_at => time) - t2 = Task.create!(:status => Task::Status::ACTIVE, :target => profile, :requestor => person, :created_at => time + 1.second) - t3 = Task.create!(:status => Task::Status::ACTIVE, :target => profile, :requestor => person, :created_at => time + 2.seconds) - t4 = Task.create!(:status => Task::Status::ACTIVE, :target => profile, :requestor => person, :created_at => time + 3.seconds) + t1 = create(Task, :status => Task::Status::ACTIVE, :target => profile, :requestor => person, :created_at => time) + t2 = create(Task, :status => Task::Status::ACTIVE, :target => profile, :requestor => person, :created_at => time + 1.second) + t3 = create(Task, :status => Task::Status::ACTIVE, :target => profile, :requestor => person, :created_at => time + 2.seconds) + t4 = create(Task, :status => Task::Status::ACTIVE, :target => profile, :requestor => person, :created_at => time + 3.seconds) Task.stubs(:per_page).returns(2) diff --git a/test/functional/themes_controller_test.rb b/test/functional/themes_controller_test.rb index 381a0a1..975db7d 100644 --- a/test/functional/themes_controller_test.rb +++ b/test/functional/themes_controller_test.rb @@ -254,7 +254,7 @@ class ThemesControllerTest < ActionController::TestCase end should 'display links to set template' do - profile.update_attributes!(:layout_template => 'rightbar') + profile.update_attributes!({:layout_template => 'rightbar'}, :without_protection => true) t1 = LayoutTemplate.find('default') t2 = LayoutTemplate.find('leftbar') LayoutTemplate.expects(:all).returns([t1, t2]) @@ -265,7 +265,7 @@ class ThemesControllerTest < ActionController::TestCase end should 'highlight current template' do - profile.update_attributes!(:layout_template => 'default') + profile.update_attributes!({:layout_template => 'default'}, :without_protection => true) t1 = LayoutTemplate.find('default') t2 = LayoutTemplate.find('leftbar') -- libgit2 0.21.2