From 196faf057f9b1e3187005cd4ec24e9339672ab4e Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Tue, 2 Jul 2013 11:09:30 -0300 Subject: [PATCH] Add STI, serialized field and rename enterprise_id --- app/models/enterprise.rb | 2 +- app/models/environment.rb | 2 +- app/models/product.rb | 7 +++++-- db/migrate/20130702135550_add_sti_and_serialized_data_to_products.rb | 13 +++++++++++++ plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb | 2 +- plugins/bsc/lib/bsc_plugin/bsc.rb | 2 +- plugins/bsc/test/functional/bsc_plugin_myprofile_controller_test.rb | 6 +++--- plugins/bsc/test/unit/ext/product_test.rb | 2 +- plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb | 16 ++++++++-------- plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb | 18 +++++++++--------- plugins/solr/features/.search_products.feature.swp | Bin 20480 -> 0 bytes plugins/solr/lib/.solr_plugin.rb.swp | Bin 12288 -> 0 bytes plugins/solr/lib/solr_plugin/.search_helper.rb.swp | Bin 24576 -> 0 bytes plugins/solr/test/functional/.search_controller_test.rb.swp | Bin 57344 -> 0 bytes plugins/solr/test/functional/search_controller_test.rb | 34 +++++++++++++++++----------------- plugins/solr/test/unit/enterprise_test.rb | 2 +- plugins/solr/test/unit/product_test.rb | 64 ++++++++++++++++++++++++++++++++-------------------------------- plugins/solr/views/search/.communities.rhtml.swp | Bin 12288 -> 0 bytes plugins/solr/views/search/.people.rhtml.swp | Bin 12288 -> 0 bytes script/sample-products | 2 +- test/functional/catalog_controller_test.rb | 64 ++++++++++++++++++++++++++++++++-------------------------------- test/functional/manage_products_controller_test.rb | 68 ++++++++++++++++++++++++++++++++++---------------------------------- test/functional/map_balloon_controller_test.rb | 10 +++++----- test/functional/search_controller_test.rb | 26 +++++++++++++------------- test/unit/enterprise_test.rb | 8 ++++---- test/unit/environment_test.rb | 8 ++++---- test/unit/featured_products_block_test.rb | 14 +++++++------- test/unit/input_test.rb | 6 +++--- test/unit/price_detail_test.rb | 2 +- test/unit/product_category_test.rb | 4 ++-- test/unit/product_test.rb | 52 ++++++++++++++++++++++++++-------------------------- 31 files changed, 225 insertions(+), 209 deletions(-) create mode 100644 db/migrate/20130702135550_add_sti_and_serialized_data_to_products.rb delete mode 100644 plugins/solr/features/.search_products.feature.swp delete mode 100644 plugins/solr/lib/.solr_plugin.rb.swp delete mode 100644 plugins/solr/lib/solr_plugin/.search_helper.rb.swp delete mode 100644 plugins/solr/test/functional/.search_controller_test.rb.swp delete mode 100644 plugins/solr/views/search/.communities.rhtml.swp delete mode 100644 plugins/solr/views/search/.people.rhtml.swp diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 89e3962..23e4221 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -10,7 +10,7 @@ class Enterprise < Organization N_('Enterprise') - has_many :products, :dependent => :destroy, :order => 'name ASC' + has_many :products, :foreign_key => :profile_id, :dependent => :destroy, :order => 'name ASC' has_many :inputs, :through => :products has_many :production_costs, :as => :owner diff --git a/app/models/environment.rb b/app/models/environment.rb index 129a831..609d562 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -792,7 +792,7 @@ class Environment < ActiveRecord::Base end def highlighted_products_with_image(options = {}) - Product.find(:all, {:conditions => {:highlighted => true, :enterprise_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) + Product.find(:all, {:conditions => {:highlighted => true, :profile_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) end settings_items :home_cache_in_minutes, :type => :integer, :default => 5 diff --git a/app/models/product.rb b/app/models/product.rb index 4c6bdee..9bc40d4 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -15,7 +15,8 @@ class Product < ActiveRecord::Base 'full' end - belongs_to :enterprise + belongs_to :enterprise, :foreign_key => :profile_id, :class_name => 'Profile' + belongs_to :profile has_one :region, :through => :enterprise validates_presence_of :enterprise @@ -29,7 +30,9 @@ class Product < ActiveRecord::Base has_many :qualifiers, :through => :product_qualifiers has_many :certifiers, :through => :product_qualifiers - validates_uniqueness_of :name, :scope => :enterprise_id, :allow_nil => true + acts_as_having_settings :field => :data + + validates_uniqueness_of :name, :scope => :profile_id, :allow_nil => true validates_presence_of :product_category_id validates_associated :product_category diff --git a/db/migrate/20130702135550_add_sti_and_serialized_data_to_products.rb b/db/migrate/20130702135550_add_sti_and_serialized_data_to_products.rb new file mode 100644 index 0000000..1d0c6f4 --- /dev/null +++ b/db/migrate/20130702135550_add_sti_and_serialized_data_to_products.rb @@ -0,0 +1,13 @@ +class AddStiAndSerializedDataToProducts < ActiveRecord::Migration + def self.up + add_column :products, :type, :string + add_column :products, :data, :text + rename_column :products, :enterprise_id, :profile_id + end + + def self.down + remove_column :products, :type + remove_column :products, :data + rename_column :products, :profile_id, :enterprise_id + end +end diff --git a/plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb b/plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb index 6697ddd..68d0bca 100644 --- a/plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb +++ b/plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb @@ -199,7 +199,7 @@ class BscPluginMyprofileController < MyProfileController enterprises = enterprises.blank? ? -1 : enterprises added_products = (params[:added_products] || []).split(',') added_products = added_products.blank? ? -1 : added_products - render :text => Product.find(:all, :conditions => ["LOWER(name) LIKE ? AND enterprise_id IN (?) AND id NOT IN (?)", "%#{query}%", enterprises, added_products]). + render :text => Product.find(:all, :conditions => ["LOWER(name) LIKE ? AND profile_id IN (?) AND id NOT IN (?)", "%#{query}%", enterprises, added_products]). map {|product| { :id => product.id, :name => short_text(product_display_name(product), 60), :sale_id => params[:sale_id], diff --git a/plugins/bsc/lib/bsc_plugin/bsc.rb b/plugins/bsc/lib/bsc_plugin/bsc.rb index 75a5aca..84f5366 100644 --- a/plugins/bsc/lib/bsc_plugin/bsc.rb +++ b/plugins/bsc/lib/bsc_plugin/bsc.rb @@ -2,7 +2,7 @@ class BscPlugin::Bsc < Enterprise has_many :enterprises has_many :enterprise_requests, :class_name => 'BscPlugin::AssociateEnterprise' - has_many :products, :finder_sql => 'select * from products where enterprise_id in (#{enterprises.map(&:id).join(",")})' + has_many :products, :finder_sql => 'select * from products where profile_id in (#{enterprises.map(&:id).join(",")})' has_many :contracts, :class_name => 'BscPlugin::Contract' validates_presence_of :nickname diff --git a/plugins/bsc/test/functional/bsc_plugin_myprofile_controller_test.rb b/plugins/bsc/test/functional/bsc_plugin_myprofile_controller_test.rb index 39d43fa..c99ee67 100644 --- a/plugins/bsc/test/functional/bsc_plugin_myprofile_controller_test.rb +++ b/plugins/bsc/test/functional/bsc_plugin_myprofile_controller_test.rb @@ -308,9 +308,9 @@ class BscPluginMyprofileControllerTest < ActionController::TestCase enterprise1 = fast_create(Enterprise) enterprise2 = fast_create(Enterprise) enterprise3 = fast_create(Enterprise) - product1 = fast_create(Product, :enterprise_id => enterprise1.id, :name => 'Black Bycicle') - product2 = fast_create(Product, :enterprise_id => enterprise2.id, :name => 'Black Guitar') - product3 = fast_create(Product, :enterprise_id => enterprise3.id, :name => 'Black Notebook') + product1 = fast_create(Product, :profile_id => enterprise1.id, :name => 'Black Bycicle') + product2 = fast_create(Product, :profile_id => enterprise2.id, :name => 'Black Guitar') + product3 = fast_create(Product, :profile_id => enterprise3.id, :name => 'Black Notebook') get :search_sale_product, :profile => bsc.identifier, :enterprises => [enterprise1.id,enterprise2.id].join(','), :added_products => [product2.id].join(','),:sales => {1 => {:product_id => 'black'}} diff --git a/plugins/bsc/test/unit/ext/product_test.rb b/plugins/bsc/test/unit/ext/product_test.rb index 9b00362..45fa033 100644 --- a/plugins/bsc/test/unit/ext/product_test.rb +++ b/plugins/bsc/test/unit/ext/product_test.rb @@ -6,7 +6,7 @@ class ProductTest < ActiveSupport::TestCase should 'return have bsc' do bsc = BscPlugin::Bsc.create!({:business_name => 'Sample Bsc', :identifier => 'sample-bsc', :company_name => 'Sample Bsc Ltda.', :cnpj => VALID_CNPJ}) enterprise = fast_create(Enterprise, :bsc_id => bsc.id) - product = fast_create(Product, :enterprise_id => enterprise.id) + product = fast_create(Product, :profile_id => enterprise.id) assert_equal bsc, product.bsc end diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb index 8eb1747..e8ad2e8 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb @@ -13,12 +13,12 @@ class ShoppingCartPluginController < PublicController def get config = if cart.nil? - { :enterprise_id => nil, + { :profile_id => nil, :has_products => false, :visible => false, :products => []} else - { :enterprise_id => cart[:enterprise_id], + { :profile_id => cart[:profile_id], :has_products => (cart[:items].keys.size > 0), :visible => visible?, :products => products} @@ -29,7 +29,7 @@ class ShoppingCartPluginController < PublicController def add product = find_product(params[:id]) if product && enterprise = validate_same_enterprise(product) - self.cart = { :enterprise_id => enterprise.id, :items => {} } if self.cart.nil? + self.cart = { :profile_id => enterprise.id, :items => {} } if self.cart.nil? self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil? self.cart[:items][product.id] += 1 render :text => { @@ -95,7 +95,7 @@ class ShoppingCartPluginController < PublicController def buy @cart = cart - @enterprise = environment.enterprises.find(cart[:enterprise_id]) + @enterprise = environment.enterprises.find(cart[:profile_id]) @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) render :layout => false end @@ -103,7 +103,7 @@ class ShoppingCartPluginController < PublicController def send_request register_order(params[:customer], self.cart[:items]) begin - enterprise = environment.enterprises.find(cart[:enterprise_id]) + enterprise = environment.enterprises.find(cart[:profile_id]) ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) self.cart = nil @@ -166,7 +166,7 @@ class ShoppingCartPluginController < PublicController end def update_delivery_option - enterprise = environment.enterprises.find(cart[:enterprise_id]) + enterprise = environment.enterprises.find(cart[:profile_id]) settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) delivery_price = settings.delivery_options[params[:delivery_option]] delivery = Product.new(:name => params[:delivery_option], :price => delivery_price) @@ -187,7 +187,7 @@ class ShoppingCartPluginController < PublicController private def validate_same_enterprise(product) - if self.cart && self.cart[:enterprise_id] && product.enterprise_id != self.cart[:enterprise_id] + if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id] render :text => { :ok => false, :error => { @@ -266,7 +266,7 @@ class ShoppingCartPluginController < PublicController new_items[id] = {:quantity => quantity, :price => price, :name => product.name} end ShoppingCartPlugin::PurchaseOrder.create!( - :seller => Enterprise.find(cart[:enterprise_id]), + :seller => Enterprise.find(cart[:profile_id]), :customer => user, :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, :products_list => new_items, diff --git a/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb b/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb index 618ac9f..de5fde7 100644 --- a/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb +++ b/plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb @@ -11,7 +11,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new @enterprise = fast_create(Enterprise) - @product = fast_create(Product, :enterprise_id => @enterprise.id) + @product = fast_create(Product, :profile_id => @enterprise.id) end attr_reader :enterprise attr_reader :product @@ -62,7 +62,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'just remove product if there are other products on cart' do - another_product = fast_create(Product, :enterprise_id => enterprise.id) + another_product = fast_create(Product, :profile_id => enterprise.id) get :add, :id => product.id get :add, :id => another_product.id @@ -135,7 +135,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'clean the cart' do - another_product = fast_create(Product, :enterprise_id => enterprise.id) + another_product = fast_create(Product, :profile_id => enterprise.id) get :add, :id => product.id get :add, :id => another_product.id @@ -150,9 +150,9 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'register order on send request' do - product1 = fast_create(Product, :enterprise_id => enterprise.id, :price => 1.99) - product2 = fast_create(Product, :enterprise_id => enterprise.id, :price => 2.23) - @controller.stubs(:cart).returns({ :enterprise_id => enterprise.id, :items => {product1.id => 1, product2.id => 2}}) + product1 = fast_create(Product, :profile_id => enterprise.id, :price => 1.99) + product2 = fast_create(Product, :profile_id => enterprise.id, :price => 2.23) + @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1, product2.id => 2}}) assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do post :send_request, :customer => {:name => "Manuel", :email => "manuel@ceu.com"} @@ -168,8 +168,8 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'register order on send request and not crash if product is not defined' do - product1 = fast_create(Product, :enterprise_id => enterprise.id) - @controller.stubs(:cart).returns({ :enterprise_id => enterprise.id, :items => {product1.id => 1}}) + product1 = fast_create(Product, :profile_id => enterprise.id) + @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1}}) assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do post :send_request, :customer => {:name => "Manuel", :email => "manuel@ceu.com"} @@ -181,7 +181,7 @@ class ShoppingCartPluginControllerTest < ActionController::TestCase end should 'clean the cart after placing the order' do - product1 = fast_create(Product, :enterprise_id => enterprise.id) + product1 = fast_create(Product, :profile_id => enterprise.id) post :add, :id => product1.id post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } assert !cart?, "cart expected to be empty!" diff --git a/plugins/solr/features/.search_products.feature.swp b/plugins/solr/features/.search_products.feature.swp deleted file mode 100644 index 93789c7..0000000 Binary files a/plugins/solr/features/.search_products.feature.swp and /dev/null differ diff --git a/plugins/solr/lib/.solr_plugin.rb.swp b/plugins/solr/lib/.solr_plugin.rb.swp deleted file mode 100644 index 9d54386..0000000 Binary files a/plugins/solr/lib/.solr_plugin.rb.swp and /dev/null differ diff --git a/plugins/solr/lib/solr_plugin/.search_helper.rb.swp b/plugins/solr/lib/solr_plugin/.search_helper.rb.swp deleted file mode 100644 index 44f5ba6..0000000 Binary files a/plugins/solr/lib/solr_plugin/.search_helper.rb.swp and /dev/null differ diff --git a/plugins/solr/test/functional/.search_controller_test.rb.swp b/plugins/solr/test/functional/.search_controller_test.rb.swp deleted file mode 100644 index 5a0c8a8..0000000 Binary files a/plugins/solr/test/functional/.search_controller_test.rb.swp and /dev/null differ diff --git a/plugins/solr/test/functional/search_controller_test.rb b/plugins/solr/test/functional/search_controller_test.rb index fe66031..cf1f12f 100644 --- a/plugins/solr/test/functional/search_controller_test.rb +++ b/plugins/solr/test/functional/search_controller_test.rb @@ -81,7 +81,7 @@ class SearchControllerTest < ActionController::TestCase state = fast_create(State, :name => 'Acre', :acronym => 'AC') city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id) ent = fast_create(Enterprise, :region_id => city.id) - prod = Product.create!(:name => 'Sound System', :enterprise_id => ent.id, :product_category_id => @product_category.id) + prod = Product.create!(:name => 'Sound System', :profile_id => ent.id, :product_category_id => @product_category.id) qualifier1 = fast_create(Qualifier) qualifier2 = fast_create(Qualifier) prod.qualifiers_list = [[qualifier1.id, 0], [qualifier2.id, 0]] @@ -159,7 +159,7 @@ class SearchControllerTest < ActionController::TestCase prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) ent = create_profile_with_optional_category(Enterprise, 'test enterprise') (1..SearchController::LIST_SEARCH_LIMIT+5).each do |n| - fast_create(Product, {:name => "produto #{n}", :enterprise_id => ent.id, :product_category_id => prod_cat.id}, :search => true) + fast_create(Product, {:name => "produto #{n}", :profile_id => ent.id, :product_category_id => prod_cat.id}, :search => true) end get :products @@ -183,13 +183,13 @@ class SearchControllerTest < ActionController::TestCase cat = fast_create(ProductCategory) ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '1.3', :lng => '1.3') - prod1 = Product.create!(:name => 'produto 1', :enterprise_id => ent1.id, :product_category_id => cat.id) + prod1 = Product.create!(:name => 'produto 1', :profile_id => ent1.id, :product_category_id => cat.id) ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') - prod2 = Product.create!(:name => 'produto 2', :enterprise_id => ent2.id, :product_category_id => cat.id) + prod2 = Product.create!(:name => 'produto 2', :profile_id => ent2.id, :product_category_id => cat.id) ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '1.6', :lng => '1.6') - prod3 = Product.create!(:name => 'produto 3', :enterprise_id => ent3.id, :product_category_id => cat.id) + prod3 = Product.create!(:name => 'produto 3', :profile_id => ent3.id, :product_category_id => cat.id) ent4 = Enterprise.create!(:name => 'ent4', :identifier => 'ent4', :lat => '10', :lng => '10') - prod4 = Product.create!(:name => 'produto 4', :enterprise_id => ent4.id, :product_category_id => cat.id) + prod4 = Product.create!(:name => 'produto 4', :profile_id => ent4.id, :product_category_id => cat.id) get :products assert_equivalent [prod1, prod3, prod2], assigns(:searches)[:products][:results].docs @@ -216,9 +216,9 @@ class SearchControllerTest < ActionController::TestCase should 'order product results by more recent when requested' do ent = fast_create(Enterprise) - prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id) - prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) - prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) + prod1 = Product.create!(:name => 'product 1', :profile_id => ent.id, :product_category_id => @product_category.id) + prod2 = Product.create!(:name => 'product 2', :profile_id => ent.id, :product_category_id => @product_category.id) + prod3 = Product.create!(:name => 'product 3', :profile_id => ent.id, :product_category_id => @product_category.id) # change others attrs will make updated_at = Time.now for all Product.record_timestamps = false @@ -235,8 +235,8 @@ class SearchControllerTest < ActionController::TestCase should 'only list products from enabled enterprises' do ent1 = fast_create(Enterprise, :enabled => true) ent2 = fast_create(Enterprise, :enabled => false) - prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => @product_category.id) - prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent2.id, :product_category_id => @product_category.id) + prod1 = Product.create!(:name => 'product 1', :profile_id => ent1.id, :product_category_id => @product_category.id) + prod2 = Product.create!(:name => 'product 2', :profile_id => ent2.id, :product_category_id => @product_category.id) get :products, :query => 'product' @@ -246,9 +246,9 @@ class SearchControllerTest < ActionController::TestCase should 'order product results by name when requested' do ent = fast_create(Enterprise) - prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id) - prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id) - prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) + prod1 = Product.create!(:name => 'product 1', :profile_id => ent.id, :product_category_id => @product_category.id) + prod2 = Product.create!(:name => 'product 2', :profile_id => ent.id, :product_category_id => @product_category.id) + prod3 = Product.create!(:name => 'product 3', :profile_id => ent.id, :product_category_id => @product_category.id) prod3.update_attribute :name, 'product A' prod2.update_attribute :name, 'product B' @@ -269,11 +269,11 @@ class SearchControllerTest < ActionController::TestCase cat = fast_create(ProductCategory) ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0') - prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => cat.id) + prod1 = Product.create!(:name => 'product 1', :profile_id => ent1.id, :product_category_id => cat.id) ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') - prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent2.id, :product_category_id => cat.id) + prod2 = Product.create!(:name => 'product 2', :profile_id => ent2.id, :product_category_id => cat.id) ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '10.0', :lng => '10.0') - prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent3.id, :product_category_id => cat.id) + prod3 = Product.create!(:name => 'product 3', :profile_id => ent3.id, :product_category_id => cat.id) get :products, :query => 'product', :order_by => :closest assert_equal [prod2, prod1, prod3], assigns(:searches)[:products][:results].docs diff --git a/plugins/solr/test/unit/enterprise_test.rb b/plugins/solr/test/unit/enterprise_test.rb index 7a6aeb8..9b36dc1 100644 --- a/plugins/solr/test/unit/enterprise_test.rb +++ b/plugins/solr/test/unit/enterprise_test.rb @@ -11,7 +11,7 @@ class EnterpriseTest < ActiveSupport::TestCase should 'reindex when products are changed' do enterprise = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => enterprise.id, :product_category_id => product_category.id) + product = fast_create(Product, :profile_id => enterprise.id, :product_category_id => product_category.id) Product.expects(:solr_batch_add_association).with(product, :enterprise) product.update_attribute :name, "novo nome" end diff --git a/plugins/solr/test/unit/product_test.rb b/plugins/solr/test/unit/product_test.rb index 23d96a3..d852102 100644 --- a/plugins/solr/test/unit/product_test.rb +++ b/plugins/solr/test/unit/product_test.rb @@ -13,7 +13,7 @@ class ProductTest < ActiveSupport::TestCase should 'reindex enterprise after saving' do ent = fast_create(Enterprise) cat = fast_create(ProductCategory) - prod = Product.create!(:name => 'something', :enterprise_id => ent.id, :product_category_id => cat.id) + prod = Product.create!(:name => 'something', :profile_id => ent.id, :product_category_id => cat.id) Product.expects(:solr_batch_add).with([ent]) prod.save! end @@ -23,7 +23,7 @@ class ProductTest < ActiveSupport::TestCase c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) ent = fast_create(Enterprise, :region_id => c.id) cat = fast_create(ProductCategory, :name => 'hardcore') - p = Product.create!(:name => 'black flag', :enterprise_id => ent.id, :product_category_id => cat.id) + p = Product.create!(:name => 'black flag', :profile_id => ent.id, :product_category_id => cat.id) pq = p.product_qualifiers.create!(:qualifier => fast_create(Qualifier, :name => 'qualifier'), :certifier => fast_create(Certifier, :name => 'certifier')) assert_equal 'Related products', Product.facet_by_id(:solr_plugin_f_category)[:label] @@ -39,7 +39,7 @@ class ProductTest < ActiveSupport::TestCase c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) ent = fast_create(Enterprise, :region_id => c.id, :name => "Black Sun") category = fast_create(ProductCategory, :name => "homemade", :acronym => "hm", :abbreviation => "homey") - p = Product.create!(:name => 'bananas syrup', :description => 'surrounded by mosquitos', :enterprise_id => ent.id, + p = Product.create!(:name => 'bananas syrup', :description => 'surrounded by mosquitos', :profile_id => ent.id, :product_category_id => category.id) qual = Qualifier.create!(:name => 'qualificador', :environment_id => Environment.default.id) cert = Certifier.create!(:name => 'certificador', :environment_id => Environment.default.id) @@ -70,28 +70,28 @@ class ProductTest < ActiveSupport::TestCase TestSolr.enable ent = fast_create(Enterprise) cat = fast_create(ProductCategory) - in_desc = Product.create!(:name => 'something', :enterprise_id => ent.id, :description => 'bananas in the description!', + in_desc = Product.create!(:name => 'something', :profile_id => ent.id, :description => 'bananas in the description!', :product_category_id => cat.id) - in_name = Product.create!(:name => 'bananas in the name!', :enterprise_id => ent.id, :product_category_id => cat.id) + in_name = Product.create!(:name => 'bananas in the name!', :profile_id => ent.id, :product_category_id => cat.id) assert_equal [in_name, in_desc], Product.find_by_contents('bananas')[:results].docs end should 'boost search results that include an image' do TestSolr.enable product_without_image = Product.create!(:name => 'product without image', :product_category => product_category, - :enterprise_id => profile.id) + :profile_id => profile.id) product_with_image = Product.create!(:name => 'product with image', :product_category => product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, - :enterprise_id => profile.id) + :profile_id => profile.id) assert_equal [product_with_image, product_without_image], Product.find_by_contents('product image')[:results].docs end should 'boost search results that include qualifier' do TestSolr.enable product_without_q = Product.create!(:name => 'product without qualifier', :product_category => product_category, - :enterprise_id => profile.id) + :profile_id => profile.id) product_with_q = Product.create!(:name => 'product with qualifier', :product_category => product_category, - :enterprise_id => profile.id) + :profile_id => profile.id) product_with_q.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) product_with_q.save! @@ -100,8 +100,8 @@ class ProductTest < ActiveSupport::TestCase should 'boost search results with open price' do TestSolr.enable - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id, :price => 100) - open_price = Product.new(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id, :price => 100) + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id, :price => 100) + open_price = Product.new(:name => 'product 2', :product_category => product_category, :profile_id => profile.id, :price => 100) open_price.inputs << Input.new(:product => open_price, :product_category_id => product_category.id, :amount_used => 10, :price_per_unit => 10) open_price.save! @@ -110,14 +110,14 @@ class ProductTest < ActiveSupport::TestCase should 'boost search results with solidarity inputs' do TestSolr.enable - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id) - perc_50 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id) + perc_50 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id) Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id, :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id, :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) perc_50.save! - perc_75 = Product.create!(:name => 'product 3', :product_category => product_category, :enterprise_id => profile.id) + perc_75 = Product.create!(:name => 'product 3', :product_category => product_category, :profile_id => profile.id) Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, @@ -133,10 +133,10 @@ class ProductTest < ActiveSupport::TestCase should 'boost available search results' do TestSolr.enable - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id) + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id) product.available = false product.save! - product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id) product2.available = true product2.save! @@ -145,18 +145,18 @@ class ProductTest < ActiveSupport::TestCase should 'boost search results created updated recently' do TestSolr.enable - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id) + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id) product.update_attribute :created_at, Time.now - 10.day - product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id) assert_equal [product2, product], Product.find_by_contents('product')[:results].docs end should 'boost search results with description' do TestSolr.enable - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id, + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id, :description => '') - product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id, + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id, :description => 'a small description') assert_equal [product2, product], Product.find_by_contents('product')[:results].docs @@ -165,23 +165,23 @@ class ProductTest < ActiveSupport::TestCase should 'boost if enterprise is enabled' do TestSolr.enable ent = Enterprise.create!(:name => 'ent', :identifier => 'ent', :enabled => false) - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => ent.id) - product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => ent.id) + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id) assert_equal [product2, product], Product.find_by_contents('product')[:results].docs end should 'combine different boost types' do TestSolr.enable - product = Product.create!(:name => 'product', :product_category => product_category, :enterprise_id => profile.id) + product = Product.create!(:name => 'product', :product_category => product_category, :profile_id => profile.id) image_only = Product.create!(:name => 'product with image', :product_category => product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, - :enterprise_id => profile.id) + :profile_id => profile.id) qual_only = Product.create!(:name => 'product with qualifier', :product_category => product_category, - :enterprise_id => profile.id) + :profile_id => profile.id) img_and_qual = Product.create!(:name => 'product with image and qualifier', :product_category => product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, - :enterprise_id => profile.id) + :profile_id => profile.id) qual_only.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) img_and_qual.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) qual_only.save! @@ -195,8 +195,8 @@ class ProductTest < ActiveSupport::TestCase parent_cat = fast_create(ProductCategory, :name => 'Parent') prod_cat = fast_create(ProductCategory, :name => 'Category1', :parent_id => parent_cat.id) prod_cat2 = fast_create(ProductCategory, :name => 'Category2') - p = Product.create(:name => 'a test', :product_category => prod_cat, :enterprise_id => @profile.id) - p2 = Product.create(:name => 'another test', :product_category => prod_cat2, :enterprise_id => @profile.id) + p = Product.create(:name => 'a test', :product_category => prod_cat, :profile_id => @profile.id) + p2 = Product.create(:name => 'another test', :product_category => prod_cat2, :profile_id => @profile.id) r = Product.find_by_contents('Parent')[:results].docs assert_includes r, p @@ -206,10 +206,10 @@ class ProductTest < ActiveSupport::TestCase should 'index by schema name when database is postgresql' do TestSolr.enable uses_postgresql 'schema_one' - p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :profile_id => @profile.id) assert_equal [p1], Product.find_by_contents('thing')[:results].docs uses_postgresql 'schema_two' - p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :profile_id => @profile.id) assert_not_includes Product.find_by_contents('thing')[:results], p1 assert_includes Product.find_by_contents('thing')[:results], p2 uses_postgresql 'schema_one' @@ -221,9 +221,9 @@ class ProductTest < ActiveSupport::TestCase should 'not index by schema name when database is not postgresql' do TestSolr.enable uses_sqlite - p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :profile_id => @profile.id) assert_equal [p1], Product.find_by_contents('thing')[:results].docs - p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :profile_id => @profile.id) assert_includes Product.find_by_contents('thing')[:results], p1 assert_includes Product.find_by_contents('thing')[:results], p2 end diff --git a/plugins/solr/views/search/.communities.rhtml.swp b/plugins/solr/views/search/.communities.rhtml.swp deleted file mode 100644 index ff23962..0000000 Binary files a/plugins/solr/views/search/.communities.rhtml.swp and /dev/null differ diff --git a/plugins/solr/views/search/.people.rhtml.swp b/plugins/solr/views/search/.people.rhtml.swp deleted file mode 100644 index 9add0ea..0000000 Binary files a/plugins/solr/views/search/.people.rhtml.swp and /dev/null differ diff --git a/script/sample-products b/script/sample-products index c4fecbc..daccd9d 100755 --- a/script/sample-products +++ b/script/sample-products @@ -14,7 +14,7 @@ for thing in THINGS rand(10).times do |i| save Product.new( :name => name, - :enterprise_id => enterprises.rand.id, :price => (i * 13.7), + :profile_id => enterprises.rand.id, :price => (i * 13.7), :product_category_id => categories.rand.id ) end diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb index 6456410..63ebc65 100644 --- a/test/functional/catalog_controller_test.rb +++ b/test/functional/catalog_controller_test.rb @@ -18,7 +18,7 @@ class CatalogControllerTest < ActionController::TestCase def test_local_files_reference assert_local_files_reference :get, :index, :profile => @enterprise.identifier end - + def test_valid_xhtml assert_valid_xhtml end @@ -33,7 +33,7 @@ class CatalogControllerTest < ActionController::TestCase get :index, :profile => 'testent' assert_response :success end - + should 'list products of enterprise' do get :index, :profile => @enterprise.identifier assert_kind_of Array, assigns(:products) @@ -41,7 +41,7 @@ class CatalogControllerTest < ActionController::TestCase should 'paginate enterprise products list' do 1.upto(12).map do - fast_create(Product, :enterprise_id => @enterprise.id) + fast_create(Product, :profile_id => @enterprise.id) end assert_equal 12, @enterprise.products.count @@ -91,7 +91,7 @@ class CatalogControllerTest < ActionController::TestCase end end - product = fast_create(Product, :enterprise_id => @enterprise.id) + product = fast_create(Product, :profile_id => @enterprise.id) environment = Environment.default environment.enable_plugin(Plugin1.name) environment.enable_plugin(Plugin2.name) @@ -107,10 +107,10 @@ class CatalogControllerTest < ActionController::TestCase 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) - 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) - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) get :index, :profile => @enterprise.identifier, :level => pc1.id @@ -125,10 +125,10 @@ class CatalogControllerTest < ActionController::TestCase 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) - 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) - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) get :index, :profile => @enterprise.identifier, :level => pc2.id @@ -139,12 +139,12 @@ class CatalogControllerTest < ActionController::TestCase end should 'get products ordered by availability, highlighted and then name' do - p1 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Zebra', :available => true, :highlighted => true) - p2 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Car', :available => true) - p3 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Panda', :available => true) - p4 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Pen', :available => false, :highlighted => true) - p5 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Ball', :available => false) - p6 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Medal', :available => false) + p1 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Zebra', :available => true, :highlighted => true) + p2 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Car', :available => true) + p3 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Panda', :available => true) + p4 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Pen', :available => false, :highlighted => true) + p5 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Ball', :available => false) + p6 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Medal', :available => false) get :index, :profile => @enterprise.identifier @@ -174,10 +174,10 @@ class CatalogControllerTest < ActionController::TestCase 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) - 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) - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) get :index, :profile => @enterprise.identifier @@ -193,10 +193,10 @@ class CatalogControllerTest < ActionController::TestCase 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) - 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) - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) get :index, :profile => @enterprise.identifier, :level => pc4.id @@ -208,8 +208,8 @@ class CatalogControllerTest < ActionController::TestCase should 'add product status on the class css' do category = ProductCategory.create!(: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) + p1 = fast_create(Product, :product_category_id => category.id, :profile_id => @enterprise.id, :highlighted => true) + p2 = fast_create(Product, :product_category_id => category.id, :profile_id => @enterprise.id, :available => false) get :index, :profile => @enterprise.identifier @@ -224,10 +224,10 @@ class CatalogControllerTest < ActionController::TestCase pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment) pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment) pc4 = ProductCategory.create!(: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) - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id) + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id) + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id) + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id) get :index, :profile => @enterprise.identifier diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 1395e4d..89c807e 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -20,11 +20,11 @@ class ManageProductsControllerTest < ActionController::TestCase def test_local_files_reference assert_local_files_reference :get, :index, :profile => @enterprise.identifier end - + def test_valid_xhtml assert_valid_xhtml end - + should "not have permission" do u = create_user('user_test') login_as :user_test @@ -44,7 +44,7 @@ class ManageProductsControllerTest < ActionController::TestCase assert_response :success assert assigns(:product) assert_template 'new' - assert_tag :tag => 'form', :attributes => { :action => /new/ } + assert_tag :tag => 'form', :attributes => { :action => /new/ } end should "create new product" do @@ -65,7 +65,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should "get edit name form" do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'name' assert_response :success assert assigns(:product) @@ -73,7 +73,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should "get edit info form" do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info' assert_response :success assert assigns(:product) @@ -81,7 +81,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should "get edit image form" do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'image' assert_response :success assert assigns(:product) @@ -89,7 +89,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should "edit product name" do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) post :edit, :profile => @enterprise.identifier, :product => {:name => 'new test product'}, :id => product.id, :field => 'name' assert_response :success assert assigns(:product) @@ -98,7 +98,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should "edit product description" do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id, :description => 'My product is very good') + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id, :description => 'My product is very good') post :edit, :profile => @enterprise.identifier, :product => {:description => 'A very good product!'}, :id => product.id, :field => 'info' assert_response :success assert assigns(:product) @@ -107,7 +107,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should "edit product image" do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) post :edit, :profile => @enterprise.identifier, :product => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } }, :id => product.id, :field => 'image' assert_response :success assert assigns(:product) @@ -116,32 +116,32 @@ class ManageProductsControllerTest < ActionController::TestCase end should "not edit to invalid parameters" do - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) post 'edit_category', :profile => @enterprise.identifier, :selected_category_id => nil, :id => product.id assert_response :success assert_template 'shared/_dialog_error_messages' end should "not crash if product has no category" do - product = fast_create(Product, :enterprise_id => @enterprise.id) + product = fast_create(Product, :profile_id => @enterprise.id) assert_nothing_raised do post 'edit_category', :profile => @enterprise.identifier, :id => product.id end end should "destroy product" do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) assert_difference Product, :count, -1 do post 'destroy', :profile => @enterprise.identifier, :id => product.id assert_response :redirect assert_redirected_to :action => 'index' assert assigns(:product) assert ! Product.find_by_name('test product') - end + end end should "fail to destroy product" do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) Product.any_instance.stubs(:destroy).returns(false) assert_no_difference Product, :count do post 'destroy', :profile => @enterprise.identifier, :id => product.id @@ -184,11 +184,11 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'filter html with white list from description of product' do - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "descr bold" } assert_equal "descr bold", assigns(:product).description end - + should 'not let users in if environment do not let' do env = Environment.default env.enable('disable_products_for_enterprises') @@ -279,14 +279,14 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'not show product price when showing product if not informed' do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_no_tag :tag => 'span', :attributes => { :class => 'product_price' }, :content => /Price:/ end should 'show product price when showing product if unit was informed' do - product = fast_create(Product, :name => 'test product', :price => 50.00, :unit_id => fast_create(Unit).id, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :price => 50.00, :unit_id => fast_create(Unit).id, :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ @@ -294,7 +294,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'show product price when showing product if discount was informed' do - product = fast_create(Product, :name => 'test product', :price => 50.00, :unit_id => fast_create(Unit).id, :discount => 3.50, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :price => 50.00, :unit_id => fast_create(Unit).id, :discount => 3.50, :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /List price:/ @@ -304,7 +304,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'show product price when showing product if unit not informed' do - product = fast_create(Product, :name => 'test product', :price => 50.00, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :price => 50.00, :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ @@ -312,7 +312,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'display button to add input when product has no input' do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_tag :tag => 'div', :attributes => { :id => 'display-add-input-button'}, @@ -320,13 +320,13 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'has instance of input list when showing product' do - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_equal [], assigns(:inputs) end should 'remove input of a product' do - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) assert_equal [input], product.inputs @@ -336,7 +336,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'save inputs order' do - product = fast_create(Product, :enterprise_id => @enterprise.id) + product = fast_create(Product, :profile_id => @enterprise.id) first = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) second = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) third = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) @@ -357,7 +357,7 @@ class ManageProductsControllerTest < ActionController::TestCase should 'not list all the products of enterprise' do @enterprise.products = [] 1.upto(12) do |n| - fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + fast_create(Product, :name => "test product_#{n}", :profile_id => @enterprise.id, :product_category_id => @product_category.id) end get :index, :profile => @enterprise.identifier assert_equal 10, assigns(:products).count @@ -366,7 +366,7 @@ class ManageProductsControllerTest < ActionController::TestCase should 'paginate the manage products list of enterprise' do @enterprise.products = [] 1.upto(12) do |n| - fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + fast_create(Product, :name => "test product_#{n}", :profile_id => @enterprise.id, :product_category_id => @product_category.id) end get :index, :profile => @enterprise.identifier assert_tag :tag => 'a', :attributes => { :rel => 'next', :href => "/myprofile/#{@enterprise.identifier}/manage_products?page=2" } @@ -376,7 +376,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'display tabs even if description and inputs are empty and user is allowed' do - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } @@ -387,7 +387,7 @@ class ManageProductsControllerTest < ActionController::TestCase login_as 'foo' - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } @@ -396,7 +396,7 @@ class ManageProductsControllerTest < ActionController::TestCase should 'not display tabs if description and inputs are empty and user is not logged in' do logout - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } @@ -406,7 +406,7 @@ class ManageProductsControllerTest < ActionController::TestCase create_user('foo') login_as 'foo' - product = fast_create(Product, :description => 'This product is very good', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :description => 'This product is very good', :profile_id => @enterprise.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#product-description'}, :content => 'Description'} assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#inputs'}, :content => 'Inputs and raw material'} @@ -416,7 +416,7 @@ class ManageProductsControllerTest < ActionController::TestCase create_user 'foo' login_as 'foo' - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier @@ -428,7 +428,7 @@ class ManageProductsControllerTest < ActionController::TestCase create_user('foo') login_as 'foo' - product = fast_create(Product, :description => 'This product is very good', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :description => 'This product is very good', :profile_id => @enterprise.id, :product_category_id => @product_category.id) input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) get :show, :id => product.id, :profile => @enterprise.identifier @@ -448,7 +448,7 @@ class ManageProductsControllerTest < ActionController::TestCase end end - product = fast_create(Product, :enterprise_id => @enterprise.id) + product = fast_create(Product, :profile_id => @enterprise.id) Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProductInfoExtras1Plugin.new, TestProductInfoExtras2Plugin.new]) @@ -470,7 +470,7 @@ class ManageProductsControllerTest < ActionController::TestCase end should 'remove price detail of a product' do - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id) cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'Environment') detail = product.price_details.create(:production_cost_id => cost.id, :price => 10) diff --git a/test/functional/map_balloon_controller_test.rb b/test/functional/map_balloon_controller_test.rb index 66a2b08..2ff3b6e 100644 --- a/test/functional/map_balloon_controller_test.rb +++ b/test/functional/map_balloon_controller_test.rb @@ -18,26 +18,26 @@ class MapBalloonControllerTest < ActionController::TestCase should 'find product to show' do prod = Product.create!(:name => 'Product1', :product_category_id => fast_create(ProductCategory).id, - :enterprise_id => fast_create(Enterprise).id) - get :product, :id => prod.id + :profile_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') - get :person, :id => pers.id + get :person, :id => pers.id assert_equal pers, assigns(:profile) end should 'find enterprise to show' do ent = Enterprise.create!(:name => 'Enterprise1', :identifier => 'ent1') - get :enterprise, :id => ent.id + get :enterprise, :id => ent.id assert_equal ent, assigns(:profile) end should 'find community to show' do comm = Community.create!(:name => 'Community1', :identifier => 'comm1') - get :community, :id => comm.id + get :community, :id => comm.id assert_equal comm, assigns(:profile) end end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index bb0bc17..965fbcd 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -166,7 +166,7 @@ class SearchControllerTest < ActionController::TestCase enterprise = fast_create(Enterprise) prod_cat = fast_create(ProductCategory) - product = fast_create(Product, {:enterprise_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true) + product = fast_create(Product, {:profile_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true) e = Environment.default e.enable_plugin(Plugin1.name) @@ -191,7 +191,7 @@ class SearchControllerTest < ActionController::TestCase end enterprise = fast_create(Enterprise) prod_cat = fast_create(ProductCategory) - product = fast_create(Product, {:enterprise_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true) + product = fast_create(Product, {:profile_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true) environment = Environment.default environment.enable_plugin(Plugin1.name) @@ -348,15 +348,15 @@ class SearchControllerTest < ActionController::TestCase should 'show events for current month by default' do person = create_user('someone').person - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], :start_date => Date.today + 2.month) - ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], :start_date => Date.today + 2.day) get :events assert_not_includes assigns(:searches)[:events][:results], ev1 - assert_includes assigns(:searches)[:events][:results], ev2 + assert_includes assigns(:searches)[:events][:results], ev2 end should 'list events for a given month' do @@ -394,7 +394,7 @@ class SearchControllerTest < ActionController::TestCase prod_cat2 = ProductCategory.create!(: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 = prod_cat2.products.create!(:name => 'prod test 1', :profile_id => ent.id) get :products, :category_path => cat.path.split('/'), :product_category => prod_cat1.id @@ -590,7 +590,7 @@ class SearchControllerTest < ActionController::TestCase a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) a.tag_list = ['one', 'two'] a.save_tags - + get :tags assert assigns(:tags)["two"] = 1 @@ -605,7 +605,7 @@ class SearchControllerTest < ActionController::TestCase a2.tag_list = ['two', 'three'] a.save_tags a2.save_tags - + get :tag, :tag => 'two' assert_equal [a, a2], assigns(:searches)[:tag][:results] @@ -621,7 +621,7 @@ class SearchControllerTest < ActionController::TestCase p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) art1 = Article.create!(:name => 'my article', :profile_id => p1.id) art2 = Article.create!(:name => 'my article', :profile_id => p2.id) - + get :articles, :query => 'my article' assert_equal [art2], assigns(:searches)[:articles][:results] @@ -632,22 +632,22 @@ class SearchControllerTest < ActionController::TestCase 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) - + get :articles, :filter => :more_recent assert_equal [art2, art1, art3], assigns(:searches)[:articles][:results] end - + 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 = Product.create!(:name => 'Enter Sandman', :profile_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 = Product.create!(:name => 'Holier Than Thou', :profile_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 diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index fd8694d..1af7f6f 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -393,13 +393,13 @@ class EnterpriseTest < ActiveSupport::TestCase p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => @product_category.id) products = [] 3.times {|n| - products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, + products.push(Product.create!(:name => "product #{n}", :profile_id => e1.id, :highlighted => true, :product_category_id => @product_category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } )) } - Product.create!(:name => "product 4", :enterprise_id => e1.id, :product_category_id => @product_category.id, :highlighted => true) - Product.create!(:name => "product 5", :enterprise_id => e1.id, :product_category_id => @product_category.id, :image_builder => { + Product.create!(:name => "product 4", :profile_id => e1.id, :product_category_id => @product_category.id, :highlighted => true) + Product.create!(:name => "product 5", :profile_id => e1.id, :product_category_id => @product_category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }) assert_equal products, e1.highlighted_products_with_image @@ -407,7 +407,7 @@ class EnterpriseTest < ActiveSupport::TestCase should 'has many inputs through products' do enterprise = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => enterprise.id, :product_category_id => @product_category.id) + product = fast_create(Product, :profile_id => enterprise.id, :product_category_id => @product_category.id) product.inputs << Input.new(:product_category => @product_category) product.inputs << Input.new(:product_category => @product_category) diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 1c510f4..05ae046 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -399,13 +399,13 @@ class EnvironmentTest < ActiveSupport::TestCase p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => category.id) products = [] 3.times {|n| - products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, + products.push(Product.create!(:name => "product #{n}", :profile_id => e1.id, :product_category_id => category.id, :highlighted => true, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } )) } - Product.create!(:name => "product 4", :enterprise_id => e1.id, :product_category_id => category.id, :highlighted => true) - Product.create!(:name => "product 5", :enterprise_id => e1.id, :product_category_id => category.id, :image_builder => { + Product.create!(:name => "product 4", :profile_id => e1.id, :product_category_id => category.id, :highlighted => true) + Product.create!(:name => "product 5", :profile_id => e1.id, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }) assert_equal products, env.highlighted_products_with_image @@ -733,7 +733,7 @@ class EnvironmentTest < ActiveSupport::TestCase assert_equal c, e.portal_community e.unset_portal_community! e.reload - assert_nil e.portal_community + assert_nil e.portal_community assert_equal [], e.portal_folders assert_equal 0, e.news_amount_by_folder assert_equal false, e.enabled?('use_portal_community') diff --git a/test/unit/featured_products_block_test.rb b/test/unit/featured_products_block_test.rb index 8aef8bf..dce0c5d 100644 --- a/test/unit/featured_products_block_test.rb +++ b/test/unit/featured_products_block_test.rb @@ -13,7 +13,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase profile = fast_create(Enterprise) products = [] category = fast_create(ProductCategory) - 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } + 3.times {|n| products.push(Product.create!(:name => "product #{n}", :profile_id => profile.id, :product_category_id => category.id)) } featured_products_block = FeaturedProductsBlock.create!(:product_ids => products.map(&:id)) assert_equal products, featured_products_block.products end @@ -66,7 +66,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) category = fast_create(ProductCategory) 3.times {|n| - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, + Product.create!(:name => "product #{n}", :profile_id => enterprise.id, :highlighted => true, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } ) @@ -82,7 +82,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) category = fast_create(ProductCategory) 3.times {|n| - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id) + Product.create!(:name => "product #{n}", :profile_id => enterprise.id, :highlighted => true, :product_category_id => category.id) } @environment.boxes.first.blocks<< block @@ -95,7 +95,7 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) category = fast_create(ProductCategory) 3.times {|n| - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { + Product.create!(:name => "product #{n}", :profile_id => enterprise.id, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }) } @@ -118,13 +118,13 @@ class FeaturedProductsBlockTest < ActiveSupport::TestCase category = fast_create(ProductCategory) products = [] 3.times {|n| - products.push(Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, + products.push(Product.create!(:name => "product #{n}", :profile_id => enterprise.id, :highlighted => true, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } )) } - Product.create!(:name => "product 4", :enterprise_id => enterprise.id, :product_category_id => category.id, :highlighted => true) - Product.create!(:name => "product 5", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { + Product.create!(:name => "product 4", :profile_id => enterprise.id, :product_category_id => category.id, :highlighted => true) + Product.create!(:name => "product 5", :profile_id => enterprise.id, :product_category_id => category.id, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }) @environment.boxes.first.blocks<< block diff --git a/test/unit/input_test.rb b/test/unit/input_test.rb index c136dab..4150b86 100644 --- a/test/unit/input_test.rb +++ b/test/unit/input_test.rb @@ -115,7 +115,7 @@ class InputTest < ActiveSupport::TestCase should 'display amount used' do ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') product_category = fast_create(ProductCategory, :name => 'Products') - product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) + product = fast_create(Product, :profile_id => ent.id, :product_category_id => product_category.id) input = Input.new(:product => product) input.amount_used = 10.45 @@ -134,7 +134,7 @@ class InputTest < ActiveSupport::TestCase should 'display only integer value if decimal value is 00' do ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') product_category = fast_create(ProductCategory, :name => 'Products') - product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) + product = fast_create(Product, :profile_id => ent.id, :product_category_id => product_category.id) input = Input.new(:product => product) input.amount_used = 10.00 @@ -144,7 +144,7 @@ class InputTest < ActiveSupport::TestCase should 'display formatted value' do ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') product_category = fast_create(ProductCategory, :name => 'Products') - product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) + product = fast_create(Product, :profile_id => ent.id, :product_category_id => product_category.id) input = Input.new(:product => product) input.price_per_unit = 1.45 diff --git a/test/unit/price_detail_test.rb b/test/unit/price_detail_test.rb index 81ee5d8..1a1a838 100644 --- a/test/unit/price_detail_test.rb +++ b/test/unit/price_detail_test.rb @@ -70,7 +70,7 @@ class PriceDetailTest < ActiveSupport::TestCase should 'format values to float with 2 decimals' do enterprise = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => enterprise.id) + product = fast_create(Product, :profile_id => enterprise.id) cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'environment') price_detail = product.price_details.create(:production_cost_id => cost.id, :price => 10) diff --git a/test/unit/product_category_test.rb b/test/unit/product_category_test.rb index 7c99072..d5f8557 100644 --- a/test/unit/product_category_test.rb +++ b/test/unit/product_category_test.rb @@ -7,12 +7,12 @@ class ProductCategoryTest < ActiveSupport::TestCase assert_equivalent [], c0.all_products profile = fast_create(Enterprise) - p0 = Product.create(:name => 'product1', :product_category => c0, :enterprise_id => profile.id) + p0 = Product.create(:name => 'product1', :product_category => c0, :profile_id => profile.id) c0.reload assert_equivalent [p0], c0.all_products c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default) - p1 = Product.create(:name => 'product2', :product_category => c1, :enterprise_id => profile.id) + p1 = Product.create(:name => 'product2', :product_category => c1, :profile_id => profile.id) c0.reload; c1.reload assert_equivalent [p0, p1], c0.all_products assert_equivalent [p1], c1.all_products diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb index 594ba52..838784e 100644 --- a/test/unit/product_test.rb +++ b/test/unit/product_test.rb @@ -18,14 +18,14 @@ class ProductTest < ActiveSupport::TestCase should 'return associated enterprise region' do @profile.region = fast_create Region, :name => 'Salvador' @profile.save! - p = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :enterprise_id => @profile.id) + p = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :profile_id => @profile.id) assert_equal @profile.region, p.region end should 'create product' do assert_difference Product, :count do - p = Product.new(:name => 'test product1', :product_category => @product_category, :enterprise_id => @profile.id) + p = Product.new(:name => 'test product1', :product_category => @product_category, :profile_id => @profile.id) assert p.save end end @@ -84,7 +84,7 @@ class ProductTest < ActiveSupport::TestCase assert_difference Product, :count do p = Product.create!(:name => 'test product1', :product_category => @product_category, :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') - }, :enterprise_id => @profile.id) + }, :profile_id => @profile.id) assert_equal p.image(true).filename, 'rails.png' end end @@ -138,7 +138,7 @@ class ProductTest < ActiveSupport::TestCase should 'respond to public? as its enterprise public?' do e1 = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') - p1 = fast_create(Product, :name => 'test product 1', :enterprise_id => e1.id, :product_category_id => @product_category.id) + p1 = fast_create(Product, :name => 'test product 1', :profile_id => e1.id, :product_category_id => @product_category.id) assert p1.public? @@ -197,7 +197,7 @@ class ProductTest < ActiveSupport::TestCase end should 'use name of category when has no name yet' do - product = Product.new(:product_category => @product_category, :enterprise_id => @profile.id) + product = Product.new(:product_category => @product_category, :profile_id => @profile.id) assert product.valid? assert_equal product.name, @product_category.name end @@ -217,7 +217,7 @@ class ProductTest < ActiveSupport::TestCase should 'format values to float with 2 decimals' do ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') - product = fast_create(Product, :enterprise_id => ent.id, :price => 12.994, :discount => 1.994) + product = fast_create(Product, :profile_id => ent.id, :price => 12.994, :discount => 1.994) assert_equal "12.99", product.formatted_value(:price) assert_equal "1.99", product.formatted_value(:discount) @@ -225,14 +225,14 @@ class ProductTest < ActiveSupport::TestCase should 'calculate price with discount' do ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') - product = fast_create(Product, :enterprise_id => ent.id, :price => 12.994, :discount => 1.994) + product = fast_create(Product, :profile_id => ent.id, :price => 12.994, :discount => 1.994) assert_equal 11.00, product.price_with_discount end should 'calculate price without discount' do ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') - product = fast_create(Product, :enterprise_id => ent.id, :price => 12.994, :discount => 0) + product = fast_create(Product, :profile_id => ent.id, :price => 12.994, :discount => 0) assert_equal product.price, product.price_with_discount end @@ -254,7 +254,7 @@ class ProductTest < ActiveSupport::TestCase should 'return product inputs' do ent = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => ent.id) + product = fast_create(Product, :profile_id => ent.id) input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) assert_equal [input], product.inputs @@ -262,7 +262,7 @@ class ProductTest < ActiveSupport::TestCase should 'destroy inputs when product is removed' do ent = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => ent.id) + product = fast_create(Product, :profile_id => ent.id) input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) services_category = fast_create(ProductCategory, :name => 'Services') @@ -414,7 +414,7 @@ class ProductTest < ActiveSupport::TestCase should 'return production costs from enterprise and environment' do ent = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => ent.id) + product = fast_create(Product, :profile_id => ent.id) ent_production_cost = fast_create(ProductionCost, :owner_id => ent.id, :owner_type => 'Profile') env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment') @@ -423,7 +423,7 @@ class ProductTest < ActiveSupport::TestCase should 'return all production costs' do ent = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => ent.id) + product = fast_create(Product, :profile_id => ent.id) env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment') ent_production_cost = fast_create(ProductionCost, :owner_id => ent.id, :owner_type => 'Profile') @@ -433,7 +433,7 @@ class ProductTest < ActiveSupport::TestCase should 'return total value of production costs' do ent = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => ent.id) + product = fast_create(Product, :profile_id => ent.id) env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment') price_detail = product.price_details.create(:production_cost => env_production_cost, :price => 10) @@ -445,7 +445,7 @@ class ProductTest < ActiveSupport::TestCase should 'return inputs cost as total value of production costs if has no price details' do ent = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => ent.id) + product = fast_create(Product, :profile_id => ent.id) input = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 20.0, :amount_used => 2) @@ -460,7 +460,7 @@ class ProductTest < ActiveSupport::TestCase should 'format inputs cost values to float with 2 decimals' do ent = fast_create(Enterprise) - product = fast_create(Product, :enterprise_id => ent.id) + product = fast_create(Product, :profile_id => ent.id) first = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 20.0, :amount_used => 2) second = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 10.0, :amount_used => 1) @@ -490,7 +490,7 @@ class ProductTest < ActiveSupport::TestCase end should 'return solidarity percentage from inputs' do - prod = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :enterprise_id => @profile.id) + prod = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :profile_id => @profile.id) assert_equal 0, prod.percentage_from_solidarity_economy.first Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, @@ -505,7 +505,7 @@ class ProductTest < ActiveSupport::TestCase :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) assert_equal 25, prod.percentage_from_solidarity_economy.first - prod = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :enterprise_id => @profile.id) + prod = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :profile_id => @profile.id) Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, @@ -516,7 +516,7 @@ class ProductTest < ActiveSupport::TestCase :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) assert_equal 75, prod.percentage_from_solidarity_economy.first - prod = fast_create(Product, :name => 'test product', :product_category_id => @product_category.id, :enterprise_id => @profile.id) + prod = fast_create(Product, :name => 'test product', :product_category_id => @product_category.id, :profile_id => @profile.id) Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) assert_equal 100, prod.percentage_from_solidarity_economy.first @@ -526,7 +526,7 @@ class ProductTest < ActiveSupport::TestCase enterprise = fast_create(Enterprise) Enterprise.any_instance.expects(:region) Enterprise.any_instance.expects(:region_id) - product = fast_create(Product, :enterprise_id => enterprise.id) + product = fast_create(Product, :profile_id => enterprise.id) product.region product.region_id end @@ -535,7 +535,7 @@ class ProductTest < ActiveSupport::TestCase enterprise = fast_create(Enterprise) Enterprise.any_instance.expects(:environment) Enterprise.any_instance.expects(:environment_id) - product = fast_create(Product, :enterprise_id => enterprise.id) + product = fast_create(Product, :profile_id => enterprise.id) product.environment product.environment_id end @@ -543,9 +543,9 @@ class ProductTest < ActiveSupport::TestCase should 'return more recent products' do Product.destroy_all - prod1 = Product.create!(:name => 'Damaged LP', :enterprise_id => @profile.id, :product_category_id => @product_category.id) - prod2 = Product.create!(:name => 'Damaged CD', :enterprise_id => @profile.id, :product_category_id => @product_category.id) - prod3 = Product.create!(:name => 'Damaged DVD', :enterprise_id => @profile.id, :product_category_id => @product_category.id) + prod1 = Product.create!(:name => 'Damaged LP', :profile_id => @profile.id, :product_category_id => @product_category.id) + prod2 = Product.create!(:name => 'Damaged CD', :profile_id => @profile.id, :product_category_id => @product_category.id) + prod3 = Product.create!(:name => 'Damaged DVD', :profile_id => @profile.id, :product_category_id => @product_category.id) prod1.update_attribute :created_at, Time.now-2.days prod2.update_attribute :created_at, Time.now-1.days @@ -579,9 +579,9 @@ class ProductTest < ActiveSupport::TestCase should 'return from_category scope untouched if passed nil' do enterprise = fast_create(Enterprise) - p1 = fast_create(Product, :enterprise_id => enterprise.id) - p2 = fast_create(Product, :enterprise_id => enterprise.id) - p3 = fast_create(Product, :enterprise_id => enterprise.id) + p1 = fast_create(Product, :profile_id => enterprise.id) + p2 = fast_create(Product, :profile_id => enterprise.id) + p3 = fast_create(Product, :profile_id => enterprise.id) products = enterprise.products.from_category(nil) -- libgit2 0.21.2