Commit 196faf057f9b1e3187005cd4ec24e9339672ab4e

Authored by Braulio Bhavamitra
1 parent 3f7a7a8b

Add STI, serialized field and rename enterprise_id

app/models/enterprise.rb
@@ -10,7 +10,7 @@ class Enterprise < Organization @@ -10,7 +10,7 @@ class Enterprise < Organization
10 10
11 N_('Enterprise') 11 N_('Enterprise')
12 12
13 - has_many :products, :dependent => :destroy, :order => 'name ASC' 13 + has_many :products, :foreign_key => :profile_id, :dependent => :destroy, :order => 'name ASC'
14 has_many :inputs, :through => :products 14 has_many :inputs, :through => :products
15 has_many :production_costs, :as => :owner 15 has_many :production_costs, :as => :owner
16 16
app/models/environment.rb
@@ -792,7 +792,7 @@ class Environment < ActiveRecord::Base @@ -792,7 +792,7 @@ class Environment < ActiveRecord::Base
792 end 792 end
793 793
794 def highlighted_products_with_image(options = {}) 794 def highlighted_products_with_image(options = {})
795 - Product.find(:all, {:conditions => {:highlighted => true, :enterprise_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) 795 + Product.find(:all, {:conditions => {:highlighted => true, :profile_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options))
796 end 796 end
797 797
798 settings_items :home_cache_in_minutes, :type => :integer, :default => 5 798 settings_items :home_cache_in_minutes, :type => :integer, :default => 5
app/models/product.rb
@@ -15,7 +15,8 @@ class Product < ActiveRecord::Base @@ -15,7 +15,8 @@ class Product < ActiveRecord::Base
15 'full' 15 'full'
16 end 16 end
17 17
18 - belongs_to :enterprise 18 + belongs_to :enterprise, :foreign_key => :profile_id, :class_name => 'Profile'
  19 + belongs_to :profile
19 has_one :region, :through => :enterprise 20 has_one :region, :through => :enterprise
20 validates_presence_of :enterprise 21 validates_presence_of :enterprise
21 22
@@ -29,7 +30,9 @@ class Product < ActiveRecord::Base @@ -29,7 +30,9 @@ class Product < ActiveRecord::Base
29 has_many :qualifiers, :through => :product_qualifiers 30 has_many :qualifiers, :through => :product_qualifiers
30 has_many :certifiers, :through => :product_qualifiers 31 has_many :certifiers, :through => :product_qualifiers
31 32
32 - validates_uniqueness_of :name, :scope => :enterprise_id, :allow_nil => true 33 + acts_as_having_settings :field => :data
  34 +
  35 + validates_uniqueness_of :name, :scope => :profile_id, :allow_nil => true
33 validates_presence_of :product_category_id 36 validates_presence_of :product_category_id
34 validates_associated :product_category 37 validates_associated :product_category
35 38
db/migrate/20130702135550_add_sti_and_serialized_data_to_products.rb 0 → 100644
@@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
  1 +class AddStiAndSerializedDataToProducts < ActiveRecord::Migration
  2 + def self.up
  3 + add_column :products, :type, :string
  4 + add_column :products, :data, :text
  5 + rename_column :products, :enterprise_id, :profile_id
  6 + end
  7 +
  8 + def self.down
  9 + remove_column :products, :type
  10 + remove_column :products, :data
  11 + rename_column :products, :profile_id, :enterprise_id
  12 + end
  13 +end
plugins/bsc/controllers/bsc_plugin_myprofile_controller.rb
@@ -199,7 +199,7 @@ class BscPluginMyprofileController &lt; MyProfileController @@ -199,7 +199,7 @@ class BscPluginMyprofileController &lt; MyProfileController
199 enterprises = enterprises.blank? ? -1 : enterprises 199 enterprises = enterprises.blank? ? -1 : enterprises
200 added_products = (params[:added_products] || []).split(',') 200 added_products = (params[:added_products] || []).split(',')
201 added_products = added_products.blank? ? -1 : added_products 201 added_products = added_products.blank? ? -1 : added_products
202 - render :text => Product.find(:all, :conditions => ["LOWER(name) LIKE ? AND enterprise_id IN (?) AND id NOT IN (?)", "%#{query}%", enterprises, added_products]). 202 + render :text => Product.find(:all, :conditions => ["LOWER(name) LIKE ? AND profile_id IN (?) AND id NOT IN (?)", "%#{query}%", enterprises, added_products]).
203 map {|product| { :id => product.id, 203 map {|product| { :id => product.id,
204 :name => short_text(product_display_name(product), 60), 204 :name => short_text(product_display_name(product), 60),
205 :sale_id => params[:sale_id], 205 :sale_id => params[:sale_id],
plugins/bsc/lib/bsc_plugin/bsc.rb
@@ -2,7 +2,7 @@ class BscPlugin::Bsc &lt; Enterprise @@ -2,7 +2,7 @@ class BscPlugin::Bsc &lt; Enterprise
2 2
3 has_many :enterprises 3 has_many :enterprises
4 has_many :enterprise_requests, :class_name => 'BscPlugin::AssociateEnterprise' 4 has_many :enterprise_requests, :class_name => 'BscPlugin::AssociateEnterprise'
5 - has_many :products, :finder_sql => 'select * from products where enterprise_id in (#{enterprises.map(&:id).join(",")})' 5 + has_many :products, :finder_sql => 'select * from products where profile_id in (#{enterprises.map(&:id).join(",")})'
6 has_many :contracts, :class_name => 'BscPlugin::Contract' 6 has_many :contracts, :class_name => 'BscPlugin::Contract'
7 7
8 validates_presence_of :nickname 8 validates_presence_of :nickname
plugins/bsc/test/functional/bsc_plugin_myprofile_controller_test.rb
@@ -308,9 +308,9 @@ class BscPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -308,9 +308,9 @@ class BscPluginMyprofileControllerTest &lt; ActionController::TestCase
308 enterprise1 = fast_create(Enterprise) 308 enterprise1 = fast_create(Enterprise)
309 enterprise2 = fast_create(Enterprise) 309 enterprise2 = fast_create(Enterprise)
310 enterprise3 = fast_create(Enterprise) 310 enterprise3 = fast_create(Enterprise)
311 - product1 = fast_create(Product, :enterprise_id => enterprise1.id, :name => 'Black Bycicle')  
312 - product2 = fast_create(Product, :enterprise_id => enterprise2.id, :name => 'Black Guitar')  
313 - product3 = fast_create(Product, :enterprise_id => enterprise3.id, :name => 'Black Notebook') 311 + product1 = fast_create(Product, :profile_id => enterprise1.id, :name => 'Black Bycicle')
  312 + product2 = fast_create(Product, :profile_id => enterprise2.id, :name => 'Black Guitar')
  313 + product3 = fast_create(Product, :profile_id => enterprise3.id, :name => 'Black Notebook')
314 314
315 get :search_sale_product, :profile => bsc.identifier, :enterprises => [enterprise1.id,enterprise2.id].join(','), :added_products => [product2.id].join(','),:sales => {1 => {:product_id => 'black'}} 315 get :search_sale_product, :profile => bsc.identifier, :enterprises => [enterprise1.id,enterprise2.id].join(','), :added_products => [product2.id].join(','),:sales => {1 => {:product_id => 'black'}}
316 316
plugins/bsc/test/unit/ext/product_test.rb
@@ -6,7 +6,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -6,7 +6,7 @@ class ProductTest &lt; ActiveSupport::TestCase
6 should 'return have bsc' do 6 should 'return have bsc' do
7 bsc = BscPlugin::Bsc.create!({:business_name => 'Sample Bsc', :identifier => 'sample-bsc', :company_name => 'Sample Bsc Ltda.', :cnpj => VALID_CNPJ}) 7 bsc = BscPlugin::Bsc.create!({:business_name => 'Sample Bsc', :identifier => 'sample-bsc', :company_name => 'Sample Bsc Ltda.', :cnpj => VALID_CNPJ})
8 enterprise = fast_create(Enterprise, :bsc_id => bsc.id) 8 enterprise = fast_create(Enterprise, :bsc_id => bsc.id)
9 - product = fast_create(Product, :enterprise_id => enterprise.id) 9 + product = fast_create(Product, :profile_id => enterprise.id)
10 10
11 assert_equal bsc, product.bsc 11 assert_equal bsc, product.bsc
12 end 12 end
plugins/shopping_cart/controllers/shopping_cart_plugin_controller.rb
@@ -13,12 +13,12 @@ class ShoppingCartPluginController &lt; PublicController @@ -13,12 +13,12 @@ class ShoppingCartPluginController &lt; PublicController
13 def get 13 def get
14 config = 14 config =
15 if cart.nil? 15 if cart.nil?
16 - { :enterprise_id => nil, 16 + { :profile_id => nil,
17 :has_products => false, 17 :has_products => false,
18 :visible => false, 18 :visible => false,
19 :products => []} 19 :products => []}
20 else 20 else
21 - { :enterprise_id => cart[:enterprise_id], 21 + { :profile_id => cart[:profile_id],
22 :has_products => (cart[:items].keys.size > 0), 22 :has_products => (cart[:items].keys.size > 0),
23 :visible => visible?, 23 :visible => visible?,
24 :products => products} 24 :products => products}
@@ -29,7 +29,7 @@ class ShoppingCartPluginController &lt; PublicController @@ -29,7 +29,7 @@ class ShoppingCartPluginController &lt; PublicController
29 def add 29 def add
30 product = find_product(params[:id]) 30 product = find_product(params[:id])
31 if product && enterprise = validate_same_enterprise(product) 31 if product && enterprise = validate_same_enterprise(product)
32 - self.cart = { :enterprise_id => enterprise.id, :items => {} } if self.cart.nil? 32 + self.cart = { :profile_id => enterprise.id, :items => {} } if self.cart.nil?
33 self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil? 33 self.cart[:items][product.id] = 0 if self.cart[:items][product.id].nil?
34 self.cart[:items][product.id] += 1 34 self.cart[:items][product.id] += 1
35 render :text => { 35 render :text => {
@@ -95,7 +95,7 @@ class ShoppingCartPluginController &lt; PublicController @@ -95,7 +95,7 @@ class ShoppingCartPluginController &lt; PublicController
95 95
96 def buy 96 def buy
97 @cart = cart 97 @cart = cart
98 - @enterprise = environment.enterprises.find(cart[:enterprise_id]) 98 + @enterprise = environment.enterprises.find(cart[:profile_id])
99 @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin) 99 @settings = Noosfero::Plugin::Settings.new(@enterprise, ShoppingCartPlugin)
100 render :layout => false 100 render :layout => false
101 end 101 end
@@ -103,7 +103,7 @@ class ShoppingCartPluginController &lt; PublicController @@ -103,7 +103,7 @@ class ShoppingCartPluginController &lt; PublicController
103 def send_request 103 def send_request
104 register_order(params[:customer], self.cart[:items]) 104 register_order(params[:customer], self.cart[:items])
105 begin 105 begin
106 - enterprise = environment.enterprises.find(cart[:enterprise_id]) 106 + enterprise = environment.enterprises.find(cart[:profile_id])
107 ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) 107 ShoppingCartPlugin::Mailer.deliver_customer_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option])
108 ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option]) 108 ShoppingCartPlugin::Mailer.deliver_supplier_notification(params[:customer], enterprise, self.cart[:items], params[:delivery_option])
109 self.cart = nil 109 self.cart = nil
@@ -166,7 +166,7 @@ class ShoppingCartPluginController &lt; PublicController @@ -166,7 +166,7 @@ class ShoppingCartPluginController &lt; PublicController
166 end 166 end
167 167
168 def update_delivery_option 168 def update_delivery_option
169 - enterprise = environment.enterprises.find(cart[:enterprise_id]) 169 + enterprise = environment.enterprises.find(cart[:profile_id])
170 settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin) 170 settings = Noosfero::Plugin::Settings.new(enterprise, ShoppingCartPlugin)
171 delivery_price = settings.delivery_options[params[:delivery_option]] 171 delivery_price = settings.delivery_options[params[:delivery_option]]
172 delivery = Product.new(:name => params[:delivery_option], :price => delivery_price) 172 delivery = Product.new(:name => params[:delivery_option], :price => delivery_price)
@@ -187,7 +187,7 @@ class ShoppingCartPluginController &lt; PublicController @@ -187,7 +187,7 @@ class ShoppingCartPluginController &lt; PublicController
187 private 187 private
188 188
189 def validate_same_enterprise(product) 189 def validate_same_enterprise(product)
190 - if self.cart && self.cart[:enterprise_id] && product.enterprise_id != self.cart[:enterprise_id] 190 + if self.cart && self.cart[:profile_id] && product.profile_id != self.cart[:profile_id]
191 render :text => { 191 render :text => {
192 :ok => false, 192 :ok => false,
193 :error => { 193 :error => {
@@ -266,7 +266,7 @@ class ShoppingCartPluginController &lt; PublicController @@ -266,7 +266,7 @@ class ShoppingCartPluginController &lt; PublicController
266 new_items[id] = {:quantity => quantity, :price => price, :name => product.name} 266 new_items[id] = {:quantity => quantity, :price => price, :name => product.name}
267 end 267 end
268 ShoppingCartPlugin::PurchaseOrder.create!( 268 ShoppingCartPlugin::PurchaseOrder.create!(
269 - :seller => Enterprise.find(cart[:enterprise_id]), 269 + :seller => Enterprise.find(cart[:profile_id]),
270 :customer => user, 270 :customer => user,
271 :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED, 271 :status => ShoppingCartPlugin::PurchaseOrder::Status::OPENED,
272 :products_list => new_items, 272 :products_list => new_items,
plugins/shopping_cart/test/functional/shopping_cart_plugin_controller_test.rb
@@ -11,7 +11,7 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase @@ -11,7 +11,7 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase
11 @request = ActionController::TestRequest.new 11 @request = ActionController::TestRequest.new
12 @response = ActionController::TestResponse.new 12 @response = ActionController::TestResponse.new
13 @enterprise = fast_create(Enterprise) 13 @enterprise = fast_create(Enterprise)
14 - @product = fast_create(Product, :enterprise_id => @enterprise.id) 14 + @product = fast_create(Product, :profile_id => @enterprise.id)
15 end 15 end
16 attr_reader :enterprise 16 attr_reader :enterprise
17 attr_reader :product 17 attr_reader :product
@@ -62,7 +62,7 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase @@ -62,7 +62,7 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase
62 end 62 end
63 63
64 should 'just remove product if there are other products on cart' do 64 should 'just remove product if there are other products on cart' do
65 - another_product = fast_create(Product, :enterprise_id => enterprise.id) 65 + another_product = fast_create(Product, :profile_id => enterprise.id)
66 get :add, :id => product.id 66 get :add, :id => product.id
67 get :add, :id => another_product.id 67 get :add, :id => another_product.id
68 68
@@ -135,7 +135,7 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase @@ -135,7 +135,7 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase
135 end 135 end
136 136
137 should 'clean the cart' do 137 should 'clean the cart' do
138 - another_product = fast_create(Product, :enterprise_id => enterprise.id) 138 + another_product = fast_create(Product, :profile_id => enterprise.id)
139 get :add, :id => product.id 139 get :add, :id => product.id
140 get :add, :id => another_product.id 140 get :add, :id => another_product.id
141 141
@@ -150,9 +150,9 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase @@ -150,9 +150,9 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase
150 end 150 end
151 151
152 should 'register order on send request' do 152 should 'register order on send request' do
153 - product1 = fast_create(Product, :enterprise_id => enterprise.id, :price => 1.99)  
154 - product2 = fast_create(Product, :enterprise_id => enterprise.id, :price => 2.23)  
155 - @controller.stubs(:cart).returns({ :enterprise_id => enterprise.id, :items => {product1.id => 1, product2.id => 2}}) 153 + product1 = fast_create(Product, :profile_id => enterprise.id, :price => 1.99)
  154 + product2 = fast_create(Product, :profile_id => enterprise.id, :price => 2.23)
  155 + @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1, product2.id => 2}})
156 assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do 156 assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do
157 post :send_request, 157 post :send_request,
158 :customer => {:name => "Manuel", :email => "manuel@ceu.com"} 158 :customer => {:name => "Manuel", :email => "manuel@ceu.com"}
@@ -168,8 +168,8 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase @@ -168,8 +168,8 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase
168 end 168 end
169 169
170 should 'register order on send request and not crash if product is not defined' do 170 should 'register order on send request and not crash if product is not defined' do
171 - product1 = fast_create(Product, :enterprise_id => enterprise.id)  
172 - @controller.stubs(:cart).returns({ :enterprise_id => enterprise.id, :items => {product1.id => 1}}) 171 + product1 = fast_create(Product, :profile_id => enterprise.id)
  172 + @controller.stubs(:cart).returns({ :profile_id => enterprise.id, :items => {product1.id => 1}})
173 assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do 173 assert_difference ShoppingCartPlugin::PurchaseOrder, :count, 1 do
174 post :send_request, 174 post :send_request,
175 :customer => {:name => "Manuel", :email => "manuel@ceu.com"} 175 :customer => {:name => "Manuel", :email => "manuel@ceu.com"}
@@ -181,7 +181,7 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase @@ -181,7 +181,7 @@ class ShoppingCartPluginControllerTest &lt; ActionController::TestCase
181 end 181 end
182 182
183 should 'clean the cart after placing the order' do 183 should 'clean the cart after placing the order' do
184 - product1 = fast_create(Product, :enterprise_id => enterprise.id) 184 + product1 = fast_create(Product, :profile_id => enterprise.id)
185 post :add, :id => product1.id 185 post :add, :id => product1.id
186 post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" } 186 post :send_request, :customer => { :name => "Manuel", :email => "manuel@ceu.com" }
187 assert !cart?, "cart expected to be empty!" 187 assert !cart?, "cart expected to be empty!"
plugins/solr/features/.search_products.feature.swp
No preview for this file type
plugins/solr/lib/.solr_plugin.rb.swp
No preview for this file type
plugins/solr/lib/solr_plugin/.search_helper.rb.swp
No preview for this file type
plugins/solr/test/functional/.search_controller_test.rb.swp
No preview for this file type
plugins/solr/test/functional/search_controller_test.rb
@@ -81,7 +81,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -81,7 +81,7 @@ class SearchControllerTest &lt; ActionController::TestCase
81 state = fast_create(State, :name => 'Acre', :acronym => 'AC') 81 state = fast_create(State, :name => 'Acre', :acronym => 'AC')
82 city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id) 82 city = fast_create(City, :name => 'Rio Branco', :parent_id => state.id)
83 ent = fast_create(Enterprise, :region_id => city.id) 83 ent = fast_create(Enterprise, :region_id => city.id)
84 - prod = Product.create!(:name => 'Sound System', :enterprise_id => ent.id, :product_category_id => @product_category.id) 84 + prod = Product.create!(:name => 'Sound System', :profile_id => ent.id, :product_category_id => @product_category.id)
85 qualifier1 = fast_create(Qualifier) 85 qualifier1 = fast_create(Qualifier)
86 qualifier2 = fast_create(Qualifier) 86 qualifier2 = fast_create(Qualifier)
87 prod.qualifiers_list = [[qualifier1.id, 0], [qualifier2.id, 0]] 87 prod.qualifiers_list = [[qualifier1.id, 0], [qualifier2.id, 0]]
@@ -159,7 +159,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -159,7 +159,7 @@ class SearchControllerTest &lt; ActionController::TestCase
159 prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) 159 prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default)
160 ent = create_profile_with_optional_category(Enterprise, 'test enterprise') 160 ent = create_profile_with_optional_category(Enterprise, 'test enterprise')
161 (1..SearchController::LIST_SEARCH_LIMIT+5).each do |n| 161 (1..SearchController::LIST_SEARCH_LIMIT+5).each do |n|
162 - fast_create(Product, {:name => "produto #{n}", :enterprise_id => ent.id, :product_category_id => prod_cat.id}, :search => true) 162 + fast_create(Product, {:name => "produto #{n}", :profile_id => ent.id, :product_category_id => prod_cat.id}, :search => true)
163 end 163 end
164 164
165 get :products 165 get :products
@@ -183,13 +183,13 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -183,13 +183,13 @@ class SearchControllerTest &lt; ActionController::TestCase
183 183
184 cat = fast_create(ProductCategory) 184 cat = fast_create(ProductCategory)
185 ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '1.3', :lng => '1.3') 185 ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '1.3', :lng => '1.3')
186 - prod1 = Product.create!(:name => 'produto 1', :enterprise_id => ent1.id, :product_category_id => cat.id) 186 + prod1 = Product.create!(:name => 'produto 1', :profile_id => ent1.id, :product_category_id => cat.id)
187 ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') 187 ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0')
188 - prod2 = Product.create!(:name => 'produto 2', :enterprise_id => ent2.id, :product_category_id => cat.id) 188 + prod2 = Product.create!(:name => 'produto 2', :profile_id => ent2.id, :product_category_id => cat.id)
189 ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '1.6', :lng => '1.6') 189 ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '1.6', :lng => '1.6')
190 - prod3 = Product.create!(:name => 'produto 3', :enterprise_id => ent3.id, :product_category_id => cat.id) 190 + prod3 = Product.create!(:name => 'produto 3', :profile_id => ent3.id, :product_category_id => cat.id)
191 ent4 = Enterprise.create!(:name => 'ent4', :identifier => 'ent4', :lat => '10', :lng => '10') 191 ent4 = Enterprise.create!(:name => 'ent4', :identifier => 'ent4', :lat => '10', :lng => '10')
192 - prod4 = Product.create!(:name => 'produto 4', :enterprise_id => ent4.id, :product_category_id => cat.id) 192 + prod4 = Product.create!(:name => 'produto 4', :profile_id => ent4.id, :product_category_id => cat.id)
193 193
194 get :products 194 get :products
195 assert_equivalent [prod1, prod3, prod2], assigns(:searches)[:products][:results].docs 195 assert_equivalent [prod1, prod3, prod2], assigns(:searches)[:products][:results].docs
@@ -216,9 +216,9 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -216,9 +216,9 @@ class SearchControllerTest &lt; ActionController::TestCase
216 216
217 should 'order product results by more recent when requested' do 217 should 'order product results by more recent when requested' do
218 ent = fast_create(Enterprise) 218 ent = fast_create(Enterprise)
219 - prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id)  
220 - prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id)  
221 - prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) 219 + prod1 = Product.create!(:name => 'product 1', :profile_id => ent.id, :product_category_id => @product_category.id)
  220 + prod2 = Product.create!(:name => 'product 2', :profile_id => ent.id, :product_category_id => @product_category.id)
  221 + prod3 = Product.create!(:name => 'product 3', :profile_id => ent.id, :product_category_id => @product_category.id)
222 222
223 # change others attrs will make updated_at = Time.now for all 223 # change others attrs will make updated_at = Time.now for all
224 Product.record_timestamps = false 224 Product.record_timestamps = false
@@ -235,8 +235,8 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -235,8 +235,8 @@ class SearchControllerTest &lt; ActionController::TestCase
235 should 'only list products from enabled enterprises' do 235 should 'only list products from enabled enterprises' do
236 ent1 = fast_create(Enterprise, :enabled => true) 236 ent1 = fast_create(Enterprise, :enabled => true)
237 ent2 = fast_create(Enterprise, :enabled => false) 237 ent2 = fast_create(Enterprise, :enabled => false)
238 - prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => @product_category.id)  
239 - prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent2.id, :product_category_id => @product_category.id) 238 + prod1 = Product.create!(:name => 'product 1', :profile_id => ent1.id, :product_category_id => @product_category.id)
  239 + prod2 = Product.create!(:name => 'product 2', :profile_id => ent2.id, :product_category_id => @product_category.id)
240 240
241 get :products, :query => 'product' 241 get :products, :query => 'product'
242 242
@@ -246,9 +246,9 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -246,9 +246,9 @@ class SearchControllerTest &lt; ActionController::TestCase
246 246
247 should 'order product results by name when requested' do 247 should 'order product results by name when requested' do
248 ent = fast_create(Enterprise) 248 ent = fast_create(Enterprise)
249 - prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent.id, :product_category_id => @product_category.id)  
250 - prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent.id, :product_category_id => @product_category.id)  
251 - prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent.id, :product_category_id => @product_category.id) 249 + prod1 = Product.create!(:name => 'product 1', :profile_id => ent.id, :product_category_id => @product_category.id)
  250 + prod2 = Product.create!(:name => 'product 2', :profile_id => ent.id, :product_category_id => @product_category.id)
  251 + prod3 = Product.create!(:name => 'product 3', :profile_id => ent.id, :product_category_id => @product_category.id)
252 252
253 prod3.update_attribute :name, 'product A' 253 prod3.update_attribute :name, 'product A'
254 prod2.update_attribute :name, 'product B' 254 prod2.update_attribute :name, 'product B'
@@ -269,11 +269,11 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -269,11 +269,11 @@ class SearchControllerTest &lt; ActionController::TestCase
269 269
270 cat = fast_create(ProductCategory) 270 cat = fast_create(ProductCategory)
271 ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0') 271 ent1 = Enterprise.create!(:name => 'ent1', :identifier => 'ent1', :lat => '-5.0', :lng => '-5.0')
272 - prod1 = Product.create!(:name => 'product 1', :enterprise_id => ent1.id, :product_category_id => cat.id) 272 + prod1 = Product.create!(:name => 'product 1', :profile_id => ent1.id, :product_category_id => cat.id)
273 ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0') 273 ent2 = Enterprise.create!(:name => 'ent2', :identifier => 'ent2', :lat => '2.0', :lng => '2.0')
274 - prod2 = Product.create!(:name => 'product 2', :enterprise_id => ent2.id, :product_category_id => cat.id) 274 + prod2 = Product.create!(:name => 'product 2', :profile_id => ent2.id, :product_category_id => cat.id)
275 ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '10.0', :lng => '10.0') 275 ent3 = Enterprise.create!(:name => 'ent3', :identifier => 'ent3', :lat => '10.0', :lng => '10.0')
276 - prod3 = Product.create!(:name => 'product 3', :enterprise_id => ent3.id, :product_category_id => cat.id) 276 + prod3 = Product.create!(:name => 'product 3', :profile_id => ent3.id, :product_category_id => cat.id)
277 277
278 get :products, :query => 'product', :order_by => :closest 278 get :products, :query => 'product', :order_by => :closest
279 assert_equal [prod2, prod1, prod3], assigns(:searches)[:products][:results].docs 279 assert_equal [prod2, prod1, prod3], assigns(:searches)[:products][:results].docs
plugins/solr/test/unit/enterprise_test.rb
@@ -11,7 +11,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -11,7 +11,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
11 11
12 should 'reindex when products are changed' do 12 should 'reindex when products are changed' do
13 enterprise = fast_create(Enterprise) 13 enterprise = fast_create(Enterprise)
14 - product = fast_create(Product, :enterprise_id => enterprise.id, :product_category_id => product_category.id) 14 + product = fast_create(Product, :profile_id => enterprise.id, :product_category_id => product_category.id)
15 Product.expects(:solr_batch_add_association).with(product, :enterprise) 15 Product.expects(:solr_batch_add_association).with(product, :enterprise)
16 product.update_attribute :name, "novo nome" 16 product.update_attribute :name, "novo nome"
17 end 17 end
plugins/solr/test/unit/product_test.rb
@@ -13,7 +13,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -13,7 +13,7 @@ class ProductTest &lt; ActiveSupport::TestCase
13 should 'reindex enterprise after saving' do 13 should 'reindex enterprise after saving' do
14 ent = fast_create(Enterprise) 14 ent = fast_create(Enterprise)
15 cat = fast_create(ProductCategory) 15 cat = fast_create(ProductCategory)
16 - prod = Product.create!(:name => 'something', :enterprise_id => ent.id, :product_category_id => cat.id) 16 + prod = Product.create!(:name => 'something', :profile_id => ent.id, :product_category_id => cat.id)
17 Product.expects(:solr_batch_add).with([ent]) 17 Product.expects(:solr_batch_add).with([ent])
18 prod.save! 18 prod.save!
19 end 19 end
@@ -23,7 +23,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -23,7 +23,7 @@ class ProductTest &lt; ActiveSupport::TestCase
23 c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) 23 c = fast_create(City, :name => 'Tabajara', :parent_id => s.id)
24 ent = fast_create(Enterprise, :region_id => c.id) 24 ent = fast_create(Enterprise, :region_id => c.id)
25 cat = fast_create(ProductCategory, :name => 'hardcore') 25 cat = fast_create(ProductCategory, :name => 'hardcore')
26 - p = Product.create!(:name => 'black flag', :enterprise_id => ent.id, :product_category_id => cat.id) 26 + p = Product.create!(:name => 'black flag', :profile_id => ent.id, :product_category_id => cat.id)
27 pq = p.product_qualifiers.create!(:qualifier => fast_create(Qualifier, :name => 'qualifier'), 27 pq = p.product_qualifiers.create!(:qualifier => fast_create(Qualifier, :name => 'qualifier'),
28 :certifier => fast_create(Certifier, :name => 'certifier')) 28 :certifier => fast_create(Certifier, :name => 'certifier'))
29 assert_equal 'Related products', Product.facet_by_id(:solr_plugin_f_category)[:label] 29 assert_equal 'Related products', Product.facet_by_id(:solr_plugin_f_category)[:label]
@@ -39,7 +39,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -39,7 +39,7 @@ class ProductTest &lt; ActiveSupport::TestCase
39 c = fast_create(City, :name => 'Tabajara', :parent_id => s.id) 39 c = fast_create(City, :name => 'Tabajara', :parent_id => s.id)
40 ent = fast_create(Enterprise, :region_id => c.id, :name => "Black Sun") 40 ent = fast_create(Enterprise, :region_id => c.id, :name => "Black Sun")
41 category = fast_create(ProductCategory, :name => "homemade", :acronym => "hm", :abbreviation => "homey") 41 category = fast_create(ProductCategory, :name => "homemade", :acronym => "hm", :abbreviation => "homey")
42 - p = Product.create!(:name => 'bananas syrup', :description => 'surrounded by mosquitos', :enterprise_id => ent.id, 42 + p = Product.create!(:name => 'bananas syrup', :description => 'surrounded by mosquitos', :profile_id => ent.id,
43 :product_category_id => category.id) 43 :product_category_id => category.id)
44 qual = Qualifier.create!(:name => 'qualificador', :environment_id => Environment.default.id) 44 qual = Qualifier.create!(:name => 'qualificador', :environment_id => Environment.default.id)
45 cert = Certifier.create!(:name => 'certificador', :environment_id => Environment.default.id) 45 cert = Certifier.create!(:name => 'certificador', :environment_id => Environment.default.id)
@@ -70,28 +70,28 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -70,28 +70,28 @@ class ProductTest &lt; ActiveSupport::TestCase
70 TestSolr.enable 70 TestSolr.enable
71 ent = fast_create(Enterprise) 71 ent = fast_create(Enterprise)
72 cat = fast_create(ProductCategory) 72 cat = fast_create(ProductCategory)
73 - in_desc = Product.create!(:name => 'something', :enterprise_id => ent.id, :description => 'bananas in the description!', 73 + in_desc = Product.create!(:name => 'something', :profile_id => ent.id, :description => 'bananas in the description!',
74 :product_category_id => cat.id) 74 :product_category_id => cat.id)
75 - in_name = Product.create!(:name => 'bananas in the name!', :enterprise_id => ent.id, :product_category_id => cat.id) 75 + in_name = Product.create!(:name => 'bananas in the name!', :profile_id => ent.id, :product_category_id => cat.id)
76 assert_equal [in_name, in_desc], Product.find_by_contents('bananas')[:results].docs 76 assert_equal [in_name, in_desc], Product.find_by_contents('bananas')[:results].docs
77 end 77 end
78 78
79 should 'boost search results that include an image' do 79 should 'boost search results that include an image' do
80 TestSolr.enable 80 TestSolr.enable
81 product_without_image = Product.create!(:name => 'product without image', :product_category => product_category, 81 product_without_image = Product.create!(:name => 'product without image', :product_category => product_category,
82 - :enterprise_id => profile.id) 82 + :profile_id => profile.id)
83 product_with_image = Product.create!(:name => 'product with image', :product_category => product_category, 83 product_with_image = Product.create!(:name => 'product with image', :product_category => product_category,
84 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, 84 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')},
85 - :enterprise_id => profile.id) 85 + :profile_id => profile.id)
86 assert_equal [product_with_image, product_without_image], Product.find_by_contents('product image')[:results].docs 86 assert_equal [product_with_image, product_without_image], Product.find_by_contents('product image')[:results].docs
87 end 87 end
88 88
89 should 'boost search results that include qualifier' do 89 should 'boost search results that include qualifier' do
90 TestSolr.enable 90 TestSolr.enable
91 product_without_q = Product.create!(:name => 'product without qualifier', :product_category => product_category, 91 product_without_q = Product.create!(:name => 'product without qualifier', :product_category => product_category,
92 - :enterprise_id => profile.id) 92 + :profile_id => profile.id)
93 product_with_q = Product.create!(:name => 'product with qualifier', :product_category => product_category, 93 product_with_q = Product.create!(:name => 'product with qualifier', :product_category => product_category,
94 - :enterprise_id => profile.id) 94 + :profile_id => profile.id)
95 product_with_q.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) 95 product_with_q.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil)
96 product_with_q.save! 96 product_with_q.save!
97 97
@@ -100,8 +100,8 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -100,8 +100,8 @@ class ProductTest &lt; ActiveSupport::TestCase
100 100
101 should 'boost search results with open price' do 101 should 'boost search results with open price' do
102 TestSolr.enable 102 TestSolr.enable
103 - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id, :price => 100)  
104 - open_price = Product.new(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id, :price => 100) 103 + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id, :price => 100)
  104 + open_price = Product.new(:name => 'product 2', :product_category => product_category, :profile_id => profile.id, :price => 100)
105 open_price.inputs << Input.new(:product => open_price, :product_category_id => product_category.id, :amount_used => 10, :price_per_unit => 10) 105 open_price.inputs << Input.new(:product => open_price, :product_category_id => product_category.id, :amount_used => 10, :price_per_unit => 10)
106 open_price.save! 106 open_price.save!
107 107
@@ -110,14 +110,14 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -110,14 +110,14 @@ class ProductTest &lt; ActiveSupport::TestCase
110 110
111 should 'boost search results with solidarity inputs' do 111 should 'boost search results with solidarity inputs' do
112 TestSolr.enable 112 TestSolr.enable
113 - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id)  
114 - perc_50 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) 113 + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id)
  114 + perc_50 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id)
115 Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id, 115 Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id,
116 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) 116 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true)
117 Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id, 117 Input.create!(:product_id => perc_50.id, :product_category_id => product_category.id,
118 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) 118 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false)
119 perc_50.save! 119 perc_50.save!
120 - perc_75 = Product.create!(:name => 'product 3', :product_category => product_category, :enterprise_id => profile.id) 120 + perc_75 = Product.create!(:name => 'product 3', :product_category => product_category, :profile_id => profile.id)
121 Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, 121 Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id,
122 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) 122 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false)
123 Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id, 123 Input.create!(:product_id => perc_75.id, :product_category_id => product_category.id,
@@ -133,10 +133,10 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -133,10 +133,10 @@ class ProductTest &lt; ActiveSupport::TestCase
133 133
134 should 'boost available search results' do 134 should 'boost available search results' do
135 TestSolr.enable 135 TestSolr.enable
136 - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id) 136 + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id)
137 product.available = false 137 product.available = false
138 product.save! 138 product.save!
139 - product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) 139 + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id)
140 product2.available = true 140 product2.available = true
141 product2.save! 141 product2.save!
142 142
@@ -145,18 +145,18 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -145,18 +145,18 @@ class ProductTest &lt; ActiveSupport::TestCase
145 145
146 should 'boost search results created updated recently' do 146 should 'boost search results created updated recently' do
147 TestSolr.enable 147 TestSolr.enable
148 - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id) 148 + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id)
149 product.update_attribute :created_at, Time.now - 10.day 149 product.update_attribute :created_at, Time.now - 10.day
150 - product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) 150 + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id)
151 151
152 assert_equal [product2, product], Product.find_by_contents('product')[:results].docs 152 assert_equal [product2, product], Product.find_by_contents('product')[:results].docs
153 end 153 end
154 154
155 should 'boost search results with description' do 155 should 'boost search results with description' do
156 TestSolr.enable 156 TestSolr.enable
157 - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => profile.id, 157 + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => profile.id,
158 :description => '') 158 :description => '')
159 - product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id, 159 + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id,
160 :description => 'a small description') 160 :description => 'a small description')
161 161
162 assert_equal [product2, product], Product.find_by_contents('product')[:results].docs 162 assert_equal [product2, product], Product.find_by_contents('product')[:results].docs
@@ -165,23 +165,23 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -165,23 +165,23 @@ class ProductTest &lt; ActiveSupport::TestCase
165 should 'boost if enterprise is enabled' do 165 should 'boost if enterprise is enabled' do
166 TestSolr.enable 166 TestSolr.enable
167 ent = Enterprise.create!(:name => 'ent', :identifier => 'ent', :enabled => false) 167 ent = Enterprise.create!(:name => 'ent', :identifier => 'ent', :enabled => false)
168 - product = Product.create!(:name => 'product 1', :product_category => product_category, :enterprise_id => ent.id)  
169 - product2 = Product.create!(:name => 'product 2', :product_category => product_category, :enterprise_id => profile.id) 168 + product = Product.create!(:name => 'product 1', :product_category => product_category, :profile_id => ent.id)
  169 + product2 = Product.create!(:name => 'product 2', :product_category => product_category, :profile_id => profile.id)
170 170
171 assert_equal [product2, product], Product.find_by_contents('product')[:results].docs 171 assert_equal [product2, product], Product.find_by_contents('product')[:results].docs
172 end 172 end
173 173
174 should 'combine different boost types' do 174 should 'combine different boost types' do
175 TestSolr.enable 175 TestSolr.enable
176 - product = Product.create!(:name => 'product', :product_category => product_category, :enterprise_id => profile.id) 176 + product = Product.create!(:name => 'product', :product_category => product_category, :profile_id => profile.id)
177 image_only = Product.create!(:name => 'product with image', :product_category => product_category, 177 image_only = Product.create!(:name => 'product with image', :product_category => product_category,
178 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, 178 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')},
179 - :enterprise_id => profile.id) 179 + :profile_id => profile.id)
180 qual_only = Product.create!(:name => 'product with qualifier', :product_category => product_category, 180 qual_only = Product.create!(:name => 'product with qualifier', :product_category => product_category,
181 - :enterprise_id => profile.id) 181 + :profile_id => profile.id)
182 img_and_qual = Product.create!(:name => 'product with image and qualifier', :product_category => product_category, 182 img_and_qual = Product.create!(:name => 'product with image and qualifier', :product_category => product_category,
183 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')}, 183 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')},
184 - :enterprise_id => profile.id) 184 + :profile_id => profile.id)
185 qual_only.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) 185 qual_only.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil)
186 img_and_qual.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil) 186 img_and_qual.product_qualifiers.create(:qualifier => fast_create(Qualifier), :certifier => nil)
187 qual_only.save! 187 qual_only.save!
@@ -195,8 +195,8 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -195,8 +195,8 @@ class ProductTest &lt; ActiveSupport::TestCase
195 parent_cat = fast_create(ProductCategory, :name => 'Parent') 195 parent_cat = fast_create(ProductCategory, :name => 'Parent')
196 prod_cat = fast_create(ProductCategory, :name => 'Category1', :parent_id => parent_cat.id) 196 prod_cat = fast_create(ProductCategory, :name => 'Category1', :parent_id => parent_cat.id)
197 prod_cat2 = fast_create(ProductCategory, :name => 'Category2') 197 prod_cat2 = fast_create(ProductCategory, :name => 'Category2')
198 - p = Product.create(:name => 'a test', :product_category => prod_cat, :enterprise_id => @profile.id)  
199 - p2 = Product.create(:name => 'another test', :product_category => prod_cat2, :enterprise_id => @profile.id) 198 + p = Product.create(:name => 'a test', :product_category => prod_cat, :profile_id => @profile.id)
  199 + p2 = Product.create(:name => 'another test', :product_category => prod_cat2, :profile_id => @profile.id)
200 200
201 r = Product.find_by_contents('Parent')[:results].docs 201 r = Product.find_by_contents('Parent')[:results].docs
202 assert_includes r, p 202 assert_includes r, p
@@ -206,10 +206,10 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -206,10 +206,10 @@ class ProductTest &lt; ActiveSupport::TestCase
206 should 'index by schema name when database is postgresql' do 206 should 'index by schema name when database is postgresql' do
207 TestSolr.enable 207 TestSolr.enable
208 uses_postgresql 'schema_one' 208 uses_postgresql 'schema_one'
209 - p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) 209 + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :profile_id => @profile.id)
210 assert_equal [p1], Product.find_by_contents('thing')[:results].docs 210 assert_equal [p1], Product.find_by_contents('thing')[:results].docs
211 uses_postgresql 'schema_two' 211 uses_postgresql 'schema_two'
212 - p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) 212 + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :profile_id => @profile.id)
213 assert_not_includes Product.find_by_contents('thing')[:results], p1 213 assert_not_includes Product.find_by_contents('thing')[:results], p1
214 assert_includes Product.find_by_contents('thing')[:results], p2 214 assert_includes Product.find_by_contents('thing')[:results], p2
215 uses_postgresql 'schema_one' 215 uses_postgresql 'schema_one'
@@ -221,9 +221,9 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -221,9 +221,9 @@ class ProductTest &lt; ActiveSupport::TestCase
221 should 'not index by schema name when database is not postgresql' do 221 should 'not index by schema name when database is not postgresql' do
222 TestSolr.enable 222 TestSolr.enable
223 uses_sqlite 223 uses_sqlite
224 - p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :enterprise_id => @profile.id) 224 + p1 = Product.create!(:name => 'some thing', :product_category => @product_category, :profile_id => @profile.id)
225 assert_equal [p1], Product.find_by_contents('thing')[:results].docs 225 assert_equal [p1], Product.find_by_contents('thing')[:results].docs
226 - p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :enterprise_id => @profile.id) 226 + p2 = Product.create!(:name => 'another thing', :product_category => @product_category, :profile_id => @profile.id)
227 assert_includes Product.find_by_contents('thing')[:results], p1 227 assert_includes Product.find_by_contents('thing')[:results], p1
228 assert_includes Product.find_by_contents('thing')[:results], p2 228 assert_includes Product.find_by_contents('thing')[:results], p2
229 end 229 end
plugins/solr/views/search/.communities.rhtml.swp
No preview for this file type
plugins/solr/views/search/.people.rhtml.swp
No preview for this file type
script/sample-products
@@ -14,7 +14,7 @@ for thing in THINGS @@ -14,7 +14,7 @@ for thing in THINGS
14 rand(10).times do |i| 14 rand(10).times do |i|
15 save Product.new( 15 save Product.new(
16 :name => name, 16 :name => name,
17 - :enterprise_id => enterprises.rand.id, :price => (i * 13.7), 17 + :profile_id => enterprises.rand.id, :price => (i * 13.7),
18 :product_category_id => categories.rand.id 18 :product_category_id => categories.rand.id
19 ) 19 )
20 end 20 end
test/functional/catalog_controller_test.rb
@@ -18,7 +18,7 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -18,7 +18,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
18 def test_local_files_reference 18 def test_local_files_reference
19 assert_local_files_reference :get, :index, :profile => @enterprise.identifier 19 assert_local_files_reference :get, :index, :profile => @enterprise.identifier
20 end 20 end
21 - 21 +
22 def test_valid_xhtml 22 def test_valid_xhtml
23 assert_valid_xhtml 23 assert_valid_xhtml
24 end 24 end
@@ -33,7 +33,7 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -33,7 +33,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
33 get :index, :profile => 'testent' 33 get :index, :profile => 'testent'
34 assert_response :success 34 assert_response :success
35 end 35 end
36 - 36 +
37 should 'list products of enterprise' do 37 should 'list products of enterprise' do
38 get :index, :profile => @enterprise.identifier 38 get :index, :profile => @enterprise.identifier
39 assert_kind_of Array, assigns(:products) 39 assert_kind_of Array, assigns(:products)
@@ -41,7 +41,7 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -41,7 +41,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
41 41
42 should 'paginate enterprise products list' do 42 should 'paginate enterprise products list' do
43 1.upto(12).map do 43 1.upto(12).map do
44 - fast_create(Product, :enterprise_id => @enterprise.id) 44 + fast_create(Product, :profile_id => @enterprise.id)
45 end 45 end
46 46
47 assert_equal 12, @enterprise.products.count 47 assert_equal 12, @enterprise.products.count
@@ -91,7 +91,7 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -91,7 +91,7 @@ class CatalogControllerTest &lt; ActionController::TestCase
91 end 91 end
92 end 92 end
93 93
94 - product = fast_create(Product, :enterprise_id => @enterprise.id) 94 + product = fast_create(Product, :profile_id => @enterprise.id)
95 environment = Environment.default 95 environment = Environment.default
96 environment.enable_plugin(Plugin1.name) 96 environment.enable_plugin(Plugin1.name)
97 environment.enable_plugin(Plugin2.name) 97 environment.enable_plugin(Plugin2.name)
@@ -107,10 +107,10 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -107,10 +107,10 @@ class CatalogControllerTest &lt; ActionController::TestCase
107 pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) 107 pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id)
108 pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) 108 pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id)
109 pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) 109 pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id)
110 - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id)  
111 - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id)  
112 - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id)  
113 - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) 110 + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id)
  111 + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id)
  112 + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id)
  113 + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id)
114 114
115 get :index, :profile => @enterprise.identifier, :level => pc1.id 115 get :index, :profile => @enterprise.identifier, :level => pc1.id
116 116
@@ -125,10 +125,10 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -125,10 +125,10 @@ class CatalogControllerTest &lt; ActionController::TestCase
125 pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) 125 pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id)
126 pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) 126 pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id)
127 pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) 127 pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id)
128 - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id)  
129 - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id)  
130 - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id)  
131 - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) 128 + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id)
  129 + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id)
  130 + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id)
  131 + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id)
132 132
133 get :index, :profile => @enterprise.identifier, :level => pc2.id 133 get :index, :profile => @enterprise.identifier, :level => pc2.id
134 134
@@ -139,12 +139,12 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -139,12 +139,12 @@ class CatalogControllerTest &lt; ActionController::TestCase
139 end 139 end
140 140
141 should 'get products ordered by availability, highlighted and then name' do 141 should 'get products ordered by availability, highlighted and then name' do
142 - p1 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Zebra', :available => true, :highlighted => true)  
143 - p2 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Car', :available => true)  
144 - p3 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Panda', :available => true)  
145 - p4 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Pen', :available => false, :highlighted => true)  
146 - p5 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Ball', :available => false)  
147 - p6 = fast_create(Product, :enterprise_id => @enterprise.id, :name => 'Medal', :available => false) 142 + p1 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Zebra', :available => true, :highlighted => true)
  143 + p2 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Car', :available => true)
  144 + p3 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Panda', :available => true)
  145 + p4 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Pen', :available => false, :highlighted => true)
  146 + p5 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Ball', :available => false)
  147 + p6 = fast_create(Product, :profile_id => @enterprise.id, :name => 'Medal', :available => false)
148 148
149 get :index, :profile => @enterprise.identifier 149 get :index, :profile => @enterprise.identifier
150 150
@@ -174,10 +174,10 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -174,10 +174,10 @@ class CatalogControllerTest &lt; ActionController::TestCase
174 pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) 174 pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id)
175 pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) 175 pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id)
176 pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) 176 pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id)
177 - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id)  
178 - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id)  
179 - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id)  
180 - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) 177 + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id)
  178 + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id)
  179 + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id)
  180 + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id)
181 181
182 get :index, :profile => @enterprise.identifier 182 get :index, :profile => @enterprise.identifier
183 183
@@ -193,10 +193,10 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -193,10 +193,10 @@ class CatalogControllerTest &lt; ActionController::TestCase
193 pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id) 193 pc2 = ProductCategory.create!(:name => "PC2", :environment => @enterprise.environment, :parent_id => pc1.id)
194 pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id) 194 pc3 = ProductCategory.create!(:name => "PC3", :environment => @enterprise.environment, :parent_id => pc1.id)
195 pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id) 195 pc4 = ProductCategory.create!(:name => "PC4", :environment => @enterprise.environment, :parent_id => pc2.id)
196 - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id)  
197 - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id)  
198 - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id)  
199 - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) 196 + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id)
  197 + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id)
  198 + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id)
  199 + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id)
200 200
201 get :index, :profile => @enterprise.identifier, :level => pc4.id 201 get :index, :profile => @enterprise.identifier, :level => pc4.id
202 202
@@ -208,8 +208,8 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -208,8 +208,8 @@ class CatalogControllerTest &lt; ActionController::TestCase
208 208
209 should 'add product status on the class css' do 209 should 'add product status on the class css' do
210 category = ProductCategory.create!(:name => "Cateogry", :environment => @enterprise.environment) 210 category = ProductCategory.create!(:name => "Cateogry", :environment => @enterprise.environment)
211 - p1 = fast_create(Product, :product_category_id => category.id, :enterprise_id => @enterprise.id, :highlighted => true)  
212 - p2 = fast_create(Product, :product_category_id => category.id, :enterprise_id => @enterprise.id, :available => false) 211 + p1 = fast_create(Product, :product_category_id => category.id, :profile_id => @enterprise.id, :highlighted => true)
  212 + p2 = fast_create(Product, :product_category_id => category.id, :profile_id => @enterprise.id, :available => false)
213 213
214 get :index, :profile => @enterprise.identifier 214 get :index, :profile => @enterprise.identifier
215 215
@@ -224,10 +224,10 @@ class CatalogControllerTest &lt; ActionController::TestCase @@ -224,10 +224,10 @@ class CatalogControllerTest &lt; ActionController::TestCase
224 pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment) 224 pc2 = ProductCategory.create!(:name => "Bananas", :environment => environment)
225 pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment) 225 pc3 = ProductCategory.create!(:name => "Sodas", :environment => environment)
226 pc4 = ProductCategory.create!(:name => "Pies", :environment => environment) 226 pc4 = ProductCategory.create!(:name => "Pies", :environment => environment)
227 - p1 = fast_create(Product, :product_category_id => pc1.id, :enterprise_id => @enterprise.id)  
228 - p2 = fast_create(Product, :product_category_id => pc2.id, :enterprise_id => @enterprise.id)  
229 - p3 = fast_create(Product, :product_category_id => pc3.id, :enterprise_id => @enterprise.id)  
230 - p4 = fast_create(Product, :product_category_id => pc4.id, :enterprise_id => @enterprise.id) 227 + p1 = fast_create(Product, :product_category_id => pc1.id, :profile_id => @enterprise.id)
  228 + p2 = fast_create(Product, :product_category_id => pc2.id, :profile_id => @enterprise.id)
  229 + p3 = fast_create(Product, :product_category_id => pc3.id, :profile_id => @enterprise.id)
  230 + p4 = fast_create(Product, :product_category_id => pc4.id, :profile_id => @enterprise.id)
231 231
232 get :index, :profile => @enterprise.identifier 232 get :index, :profile => @enterprise.identifier
233 233
test/functional/manage_products_controller_test.rb
@@ -20,11 +20,11 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -20,11 +20,11 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
20 def test_local_files_reference 20 def test_local_files_reference
21 assert_local_files_reference :get, :index, :profile => @enterprise.identifier 21 assert_local_files_reference :get, :index, :profile => @enterprise.identifier
22 end 22 end
23 - 23 +
24 def test_valid_xhtml 24 def test_valid_xhtml
25 assert_valid_xhtml 25 assert_valid_xhtml
26 end 26 end
27 - 27 +
28 should "not have permission" do 28 should "not have permission" do
29 u = create_user('user_test') 29 u = create_user('user_test')
30 login_as :user_test 30 login_as :user_test
@@ -44,7 +44,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -44,7 +44,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
44 assert_response :success 44 assert_response :success
45 assert assigns(:product) 45 assert assigns(:product)
46 assert_template 'new' 46 assert_template 'new'
47 - assert_tag :tag => 'form', :attributes => { :action => /new/ } 47 + assert_tag :tag => 'form', :attributes => { :action => /new/ }
48 end 48 end
49 49
50 should "create new product" do 50 should "create new product" do
@@ -65,7 +65,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -65,7 +65,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
65 end 65 end
66 66
67 should "get edit name form" do 67 should "get edit name form" do
68 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 68 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
69 get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'name' 69 get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'name'
70 assert_response :success 70 assert_response :success
71 assert assigns(:product) 71 assert assigns(:product)
@@ -73,7 +73,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -73,7 +73,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
73 end 73 end
74 74
75 should "get edit info form" do 75 should "get edit info form" do
76 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 76 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
77 get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info' 77 get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info'
78 assert_response :success 78 assert_response :success
79 assert assigns(:product) 79 assert assigns(:product)
@@ -81,7 +81,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -81,7 +81,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
81 end 81 end
82 82
83 should "get edit image form" do 83 should "get edit image form" do
84 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 84 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
85 get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'image' 85 get 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'image'
86 assert_response :success 86 assert_response :success
87 assert assigns(:product) 87 assert assigns(:product)
@@ -89,7 +89,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -89,7 +89,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
89 end 89 end
90 90
91 should "edit product name" do 91 should "edit product name" do
92 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 92 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
93 post :edit, :profile => @enterprise.identifier, :product => {:name => 'new test product'}, :id => product.id, :field => 'name' 93 post :edit, :profile => @enterprise.identifier, :product => {:name => 'new test product'}, :id => product.id, :field => 'name'
94 assert_response :success 94 assert_response :success
95 assert assigns(:product) 95 assert assigns(:product)
@@ -98,7 +98,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -98,7 +98,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
98 end 98 end
99 99
100 should "edit product description" do 100 should "edit product description" do
101 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id, :description => 'My product is very good') 101 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id, :description => 'My product is very good')
102 post :edit, :profile => @enterprise.identifier, :product => {:description => 'A very good product!'}, :id => product.id, :field => 'info' 102 post :edit, :profile => @enterprise.identifier, :product => {:description => 'A very good product!'}, :id => product.id, :field => 'info'
103 assert_response :success 103 assert_response :success
104 assert assigns(:product) 104 assert assigns(:product)
@@ -107,7 +107,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -107,7 +107,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
107 end 107 end
108 108
109 should "edit product image" do 109 should "edit product image" do
110 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 110 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
111 post :edit, :profile => @enterprise.identifier, :product => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } }, :id => product.id, :field => 'image' 111 post :edit, :profile => @enterprise.identifier, :product => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } }, :id => product.id, :field => 'image'
112 assert_response :success 112 assert_response :success
113 assert assigns(:product) 113 assert assigns(:product)
@@ -116,32 +116,32 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -116,32 +116,32 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
116 end 116 end
117 117
118 should "not edit to invalid parameters" do 118 should "not edit to invalid parameters" do
119 - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 119 + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id)
120 post 'edit_category', :profile => @enterprise.identifier, :selected_category_id => nil, :id => product.id 120 post 'edit_category', :profile => @enterprise.identifier, :selected_category_id => nil, :id => product.id
121 assert_response :success 121 assert_response :success
122 assert_template 'shared/_dialog_error_messages' 122 assert_template 'shared/_dialog_error_messages'
123 end 123 end
124 124
125 should "not crash if product has no category" do 125 should "not crash if product has no category" do
126 - product = fast_create(Product, :enterprise_id => @enterprise.id) 126 + product = fast_create(Product, :profile_id => @enterprise.id)
127 assert_nothing_raised do 127 assert_nothing_raised do
128 post 'edit_category', :profile => @enterprise.identifier, :id => product.id 128 post 'edit_category', :profile => @enterprise.identifier, :id => product.id
129 end 129 end
130 end 130 end
131 131
132 should "destroy product" do 132 should "destroy product" do
133 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 133 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
134 assert_difference Product, :count, -1 do 134 assert_difference Product, :count, -1 do
135 post 'destroy', :profile => @enterprise.identifier, :id => product.id 135 post 'destroy', :profile => @enterprise.identifier, :id => product.id
136 assert_response :redirect 136 assert_response :redirect
137 assert_redirected_to :action => 'index' 137 assert_redirected_to :action => 'index'
138 assert assigns(:product) 138 assert assigns(:product)
139 assert ! Product.find_by_name('test product') 139 assert ! Product.find_by_name('test product')
140 - end 140 + end
141 end 141 end
142 142
143 should "fail to destroy product" do 143 should "fail to destroy product" do
144 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 144 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
145 Product.any_instance.stubs(:destroy).returns(false) 145 Product.any_instance.stubs(:destroy).returns(false)
146 assert_no_difference Product, :count do 146 assert_no_difference Product, :count do
147 post 'destroy', :profile => @enterprise.identifier, :id => product.id 147 post 'destroy', :profile => @enterprise.identifier, :id => product.id
@@ -184,11 +184,11 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -184,11 +184,11 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
184 end 184 end
185 185
186 should 'filter html with white list from description of product' do 186 should 'filter html with white list from description of product' do
187 - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 187 + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id)
188 post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "<b id='html_descr'>descr bold</b>" } 188 post 'edit', :profile => @enterprise.identifier, :id => product.id, :field => 'info', :product => { :name => 'name', :description => "<b id='html_descr'>descr bold</b>" }
189 assert_equal "<b>descr bold</b>", assigns(:product).description 189 assert_equal "<b>descr bold</b>", assigns(:product).description
190 end 190 end
191 - 191 +
192 should 'not let users in if environment do not let' do 192 should 'not let users in if environment do not let' do
193 env = Environment.default 193 env = Environment.default
194 env.enable('disable_products_for_enterprises') 194 env.enable('disable_products_for_enterprises')
@@ -279,14 +279,14 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -279,14 +279,14 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
279 end 279 end
280 280
281 should 'not show product price when showing product if not informed' do 281 should 'not show product price when showing product if not informed' do
282 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 282 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
283 get :show, :id => product.id, :profile => @enterprise.identifier 283 get :show, :id => product.id, :profile => @enterprise.identifier
284 284
285 assert_no_tag :tag => 'span', :attributes => { :class => 'product_price' }, :content => /Price:/ 285 assert_no_tag :tag => 'span', :attributes => { :class => 'product_price' }, :content => /Price:/
286 end 286 end
287 287
288 should 'show product price when showing product if unit was informed' do 288 should 'show product price when showing product if unit was informed' do
289 - 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) 289 + 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)
290 get :show, :id => product.id, :profile => @enterprise.identifier 290 get :show, :id => product.id, :profile => @enterprise.identifier
291 291
292 assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ 292 assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/
@@ -294,7 +294,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -294,7 +294,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
294 end 294 end
295 295
296 should 'show product price when showing product if discount was informed' do 296 should 'show product price when showing product if discount was informed' do
297 - 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) 297 + 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)
298 get :show, :id => product.id, :profile => @enterprise.identifier 298 get :show, :id => product.id, :profile => @enterprise.identifier
299 299
300 assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /List price:/ 300 assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /List price:/
@@ -304,7 +304,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -304,7 +304,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
304 end 304 end
305 305
306 should 'show product price when showing product if unit not informed' do 306 should 'show product price when showing product if unit not informed' do
307 - product = fast_create(Product, :name => 'test product', :price => 50.00, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 307 + product = fast_create(Product, :name => 'test product', :price => 50.00, :profile_id => @enterprise.id, :product_category_id => @product_category.id)
308 get :show, :id => product.id, :profile => @enterprise.identifier 308 get :show, :id => product.id, :profile => @enterprise.identifier
309 309
310 assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/ 310 assert_tag :tag => 'span', :attributes => { :class => 'field-name' }, :content => /Price:/
@@ -312,7 +312,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -312,7 +312,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
312 end 312 end
313 313
314 should 'display button to add input when product has no input' do 314 should 'display button to add input when product has no input' do
315 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 315 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
316 get :show, :id => product.id, :profile => @enterprise.identifier 316 get :show, :id => product.id, :profile => @enterprise.identifier
317 317
318 assert_tag :tag => 'div', :attributes => { :id => 'display-add-input-button'}, 318 assert_tag :tag => 'div', :attributes => { :id => 'display-add-input-button'},
@@ -320,13 +320,13 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -320,13 +320,13 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
320 end 320 end
321 321
322 should 'has instance of input list when showing product' do 322 should 'has instance of input list when showing product' do
323 - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 323 + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id)
324 get :show, :id => product.id, :profile => @enterprise.identifier 324 get :show, :id => product.id, :profile => @enterprise.identifier
325 assert_equal [], assigns(:inputs) 325 assert_equal [], assigns(:inputs)
326 end 326 end
327 327
328 should 'remove input of a product' do 328 should 'remove input of a product' do
329 - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 329 + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id)
330 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) 330 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id)
331 assert_equal [input], product.inputs 331 assert_equal [input], product.inputs
332 332
@@ -336,7 +336,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -336,7 +336,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
336 end 336 end
337 337
338 should 'save inputs order' do 338 should 'save inputs order' do
339 - product = fast_create(Product, :enterprise_id => @enterprise.id) 339 + product = fast_create(Product, :profile_id => @enterprise.id)
340 first = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) 340 first = Input.create!(:product => product, :product_category => fast_create(ProductCategory))
341 second = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) 341 second = Input.create!(:product => product, :product_category => fast_create(ProductCategory))
342 third = Input.create!(:product => product, :product_category => fast_create(ProductCategory)) 342 third = Input.create!(:product => product, :product_category => fast_create(ProductCategory))
@@ -357,7 +357,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -357,7 +357,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
357 should 'not list all the products of enterprise' do 357 should 'not list all the products of enterprise' do
358 @enterprise.products = [] 358 @enterprise.products = []
359 1.upto(12) do |n| 359 1.upto(12) do |n|
360 - fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 360 + fast_create(Product, :name => "test product_#{n}", :profile_id => @enterprise.id, :product_category_id => @product_category.id)
361 end 361 end
362 get :index, :profile => @enterprise.identifier 362 get :index, :profile => @enterprise.identifier
363 assert_equal 10, assigns(:products).count 363 assert_equal 10, assigns(:products).count
@@ -366,7 +366,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -366,7 +366,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
366 should 'paginate the manage products list of enterprise' do 366 should 'paginate the manage products list of enterprise' do
367 @enterprise.products = [] 367 @enterprise.products = []
368 1.upto(12) do |n| 368 1.upto(12) do |n|
369 - fast_create(Product, :name => "test product_#{n}", :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 369 + fast_create(Product, :name => "test product_#{n}", :profile_id => @enterprise.id, :product_category_id => @product_category.id)
370 end 370 end
371 get :index, :profile => @enterprise.identifier 371 get :index, :profile => @enterprise.identifier
372 assert_tag :tag => 'a', :attributes => { :rel => 'next', :href => "/myprofile/#{@enterprise.identifier}/manage_products?page=2" } 372 assert_tag :tag => 'a', :attributes => { :rel => 'next', :href => "/myprofile/#{@enterprise.identifier}/manage_products?page=2" }
@@ -376,7 +376,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -376,7 +376,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
376 end 376 end
377 377
378 should 'display tabs even if description and inputs are empty and user is allowed' do 378 should 'display tabs even if description and inputs are empty and user is allowed' do
379 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 379 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
380 get :show, :id => product.id, :profile => @enterprise.identifier 380 get :show, :id => product.id, :profile => @enterprise.identifier
381 381
382 assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } 382 assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }
@@ -387,7 +387,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -387,7 +387,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
387 387
388 login_as 'foo' 388 login_as 'foo'
389 389
390 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 390 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
391 get :show, :id => product.id, :profile => @enterprise.identifier 391 get :show, :id => product.id, :profile => @enterprise.identifier
392 392
393 assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } 393 assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }
@@ -396,7 +396,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -396,7 +396,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
396 should 'not display tabs if description and inputs are empty and user is not logged in' do 396 should 'not display tabs if description and inputs are empty and user is not logged in' do
397 logout 397 logout
398 398
399 - product = fast_create(Product, :name => 'test product', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 399 + product = fast_create(Product, :name => 'test product', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
400 get :show, :id => product.id, :profile => @enterprise.identifier 400 get :show, :id => product.id, :profile => @enterprise.identifier
401 401
402 assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" } 402 assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }
@@ -406,7 +406,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -406,7 +406,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
406 create_user('foo') 406 create_user('foo')
407 407
408 login_as 'foo' 408 login_as 'foo'
409 - product = fast_create(Product, :description => 'This product is very good', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 409 + product = fast_create(Product, :description => 'This product is very good', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
410 get :show, :id => product.id, :profile => @enterprise.identifier 410 get :show, :id => product.id, :profile => @enterprise.identifier
411 assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#product-description'}, :content => 'Description'} 411 assert_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#product-description'}, :content => 'Description'}
412 assert_no_tag :tag => 'div', :attributes => { :id => "product-#{product.id}-tabs" }, :descendant => {:tag => 'a', :attributes => {:href => '#inputs'}, :content => 'Inputs and raw material'} 412 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 &lt; ActionController::TestCase @@ -416,7 +416,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
416 create_user 'foo' 416 create_user 'foo'
417 417
418 login_as 'foo' 418 login_as 'foo'
419 - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 419 + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id)
420 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) 420 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id)
421 421
422 get :show, :id => product.id, :profile => @enterprise.identifier 422 get :show, :id => product.id, :profile => @enterprise.identifier
@@ -428,7 +428,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -428,7 +428,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
428 create_user('foo') 428 create_user('foo')
429 429
430 login_as 'foo' 430 login_as 'foo'
431 - product = fast_create(Product, :description => 'This product is very good', :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 431 + product = fast_create(Product, :description => 'This product is very good', :profile_id => @enterprise.id, :product_category_id => @product_category.id)
432 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) 432 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id)
433 433
434 get :show, :id => product.id, :profile => @enterprise.identifier 434 get :show, :id => product.id, :profile => @enterprise.identifier
@@ -448,7 +448,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -448,7 +448,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
448 end 448 end
449 end 449 end
450 450
451 - product = fast_create(Product, :enterprise_id => @enterprise.id) 451 + product = fast_create(Product, :profile_id => @enterprise.id)
452 452
453 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProductInfoExtras1Plugin.new, TestProductInfoExtras2Plugin.new]) 453 Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([TestProductInfoExtras1Plugin.new, TestProductInfoExtras2Plugin.new])
454 454
@@ -470,7 +470,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase @@ -470,7 +470,7 @@ class ManageProductsControllerTest &lt; ActionController::TestCase
470 end 470 end
471 471
472 should 'remove price detail of a product' do 472 should 'remove price detail of a product' do
473 - product = fast_create(Product, :enterprise_id => @enterprise.id, :product_category_id => @product_category.id) 473 + product = fast_create(Product, :profile_id => @enterprise.id, :product_category_id => @product_category.id)
474 cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'Environment') 474 cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'Environment')
475 detail = product.price_details.create(:production_cost_id => cost.id, :price => 10) 475 detail = product.price_details.create(:production_cost_id => cost.id, :price => 10)
476 476
test/functional/map_balloon_controller_test.rb
@@ -18,26 +18,26 @@ class MapBalloonControllerTest &lt; ActionController::TestCase @@ -18,26 +18,26 @@ class MapBalloonControllerTest &lt; ActionController::TestCase
18 18
19 should 'find product to show' do 19 should 'find product to show' do
20 prod = Product.create!(:name => 'Product1', :product_category_id => fast_create(ProductCategory).id, 20 prod = Product.create!(:name => 'Product1', :product_category_id => fast_create(ProductCategory).id,
21 - :enterprise_id => fast_create(Enterprise).id)  
22 - get :product, :id => prod.id 21 + :profile_id => fast_create(Enterprise).id)
  22 + get :product, :id => prod.id
23 assert_equal prod, assigns(:product) 23 assert_equal prod, assigns(:product)
24 end 24 end
25 25
26 should 'find person to show' do 26 should 'find person to show' do
27 pers = Person.create!(:name => 'Person1', :user_id => fast_create(User).id, :identifier => 'pers1') 27 pers = Person.create!(:name => 'Person1', :user_id => fast_create(User).id, :identifier => 'pers1')
28 - get :person, :id => pers.id 28 + get :person, :id => pers.id
29 assert_equal pers, assigns(:profile) 29 assert_equal pers, assigns(:profile)
30 end 30 end
31 31
32 should 'find enterprise to show' do 32 should 'find enterprise to show' do
33 ent = Enterprise.create!(:name => 'Enterprise1', :identifier => 'ent1') 33 ent = Enterprise.create!(:name => 'Enterprise1', :identifier => 'ent1')
34 - get :enterprise, :id => ent.id 34 + get :enterprise, :id => ent.id
35 assert_equal ent, assigns(:profile) 35 assert_equal ent, assigns(:profile)
36 end 36 end
37 37
38 should 'find community to show' do 38 should 'find community to show' do
39 comm = Community.create!(:name => 'Community1', :identifier => 'comm1') 39 comm = Community.create!(:name => 'Community1', :identifier => 'comm1')
40 - get :community, :id => comm.id 40 + get :community, :id => comm.id
41 assert_equal comm, assigns(:profile) 41 assert_equal comm, assigns(:profile)
42 end 42 end
43 end 43 end
test/functional/search_controller_test.rb
@@ -166,7 +166,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -166,7 +166,7 @@ class SearchControllerTest &lt; ActionController::TestCase
166 166
167 enterprise = fast_create(Enterprise) 167 enterprise = fast_create(Enterprise)
168 prod_cat = fast_create(ProductCategory) 168 prod_cat = fast_create(ProductCategory)
169 - product = fast_create(Product, {:enterprise_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true) 169 + product = fast_create(Product, {:profile_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true)
170 170
171 e = Environment.default 171 e = Environment.default
172 e.enable_plugin(Plugin1.name) 172 e.enable_plugin(Plugin1.name)
@@ -191,7 +191,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -191,7 +191,7 @@ class SearchControllerTest &lt; ActionController::TestCase
191 end 191 end
192 enterprise = fast_create(Enterprise) 192 enterprise = fast_create(Enterprise)
193 prod_cat = fast_create(ProductCategory) 193 prod_cat = fast_create(ProductCategory)
194 - product = fast_create(Product, {:enterprise_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true) 194 + product = fast_create(Product, {:profile_id => enterprise.id, :name => "produto1", :product_category_id => prod_cat.id}, :search => true)
195 195
196 environment = Environment.default 196 environment = Environment.default
197 environment.enable_plugin(Plugin1.name) 197 environment.enable_plugin(Plugin1.name)
@@ -348,15 +348,15 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -348,15 +348,15 @@ class SearchControllerTest &lt; ActionController::TestCase
348 should 'show events for current month by default' do 348 should 'show events for current month by default' do
349 person = create_user('someone').person 349 person = create_user('someone').person
350 350
351 - ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id], 351 + ev1 = create_event(person, :name => 'event 1', :category_ids => [@category.id],
352 :start_date => Date.today + 2.month) 352 :start_date => Date.today + 2.month)
353 - ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id], 353 + ev2 = create_event(person, :name => 'event 2', :category_ids => [@category.id],
354 :start_date => Date.today + 2.day) 354 :start_date => Date.today + 2.day)
355 355
356 get :events 356 get :events
357 357
358 assert_not_includes assigns(:searches)[:events][:results], ev1 358 assert_not_includes assigns(:searches)[:events][:results], ev1
359 - assert_includes assigns(:searches)[:events][:results], ev2 359 + assert_includes assigns(:searches)[:events][:results], ev2
360 end 360 end
361 361
362 should 'list events for a given month' do 362 should 'list events for a given month' do
@@ -394,7 +394,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -394,7 +394,7 @@ class SearchControllerTest &lt; ActionController::TestCase
394 prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) 394 prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1)
395 ent = create_profile_with_optional_category(Enterprise, 'test ent', cat) 395 ent = create_profile_with_optional_category(Enterprise, 'test ent', cat)
396 396
397 - product = prod_cat2.products.create!(:name => 'prod test 1', :enterprise_id => ent.id) 397 + product = prod_cat2.products.create!(:name => 'prod test 1', :profile_id => ent.id)
398 398
399 get :products, :category_path => cat.path.split('/'), :product_category => prod_cat1.id 399 get :products, :category_path => cat.path.split('/'), :product_category => prod_cat1.id
400 400
@@ -590,7 +590,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -590,7 +590,7 @@ class SearchControllerTest &lt; ActionController::TestCase
590 a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id) 590 a = Article.create!(:name => 'my article', :profile_id => fast_create(Person).id)
591 a.tag_list = ['one', 'two'] 591 a.tag_list = ['one', 'two']
592 a.save_tags 592 a.save_tags
593 - 593 +
594 get :tags 594 get :tags
595 595
596 assert assigns(:tags)["two"] = 1 596 assert assigns(:tags)["two"] = 1
@@ -605,7 +605,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -605,7 +605,7 @@ class SearchControllerTest &lt; ActionController::TestCase
605 a2.tag_list = ['two', 'three'] 605 a2.tag_list = ['two', 'three']
606 a.save_tags 606 a.save_tags
607 a2.save_tags 607 a2.save_tags
608 - 608 +
609 get :tag, :tag => 'two' 609 get :tag, :tag => 'two'
610 610
611 assert_equal [a, a2], assigns(:searches)[:tag][:results] 611 assert_equal [a, a2], assigns(:searches)[:tag][:results]
@@ -621,7 +621,7 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -621,7 +621,7 @@ class SearchControllerTest &lt; ActionController::TestCase
621 p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) 621 p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id)
622 art1 = Article.create!(:name => 'my article', :profile_id => p1.id) 622 art1 = Article.create!(:name => 'my article', :profile_id => p1.id)
623 art2 = Article.create!(:name => 'my article', :profile_id => p2.id) 623 art2 = Article.create!(:name => 'my article', :profile_id => p2.id)
624 - 624 +
625 get :articles, :query => 'my article' 625 get :articles, :query => 'my article'
626 626
627 assert_equal [art2], assigns(:searches)[:articles][:results] 627 assert_equal [art2], assigns(:searches)[:articles][:results]
@@ -632,22 +632,22 @@ class SearchControllerTest &lt; ActionController::TestCase @@ -632,22 +632,22 @@ class SearchControllerTest &lt; ActionController::TestCase
632 art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days) 632 art1 = Article.create!(:name => 'review C', :profile_id => fast_create(Person).id, :created_at => Time.now-1.days)
633 art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now) 633 art2 = Article.create!(:name => 'review A', :profile_id => fast_create(Person).id, :created_at => Time.now)
634 art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days) 634 art3 = Article.create!(:name => 'review B', :profile_id => fast_create(Person).id, :created_at => Time.now-2.days)
635 - 635 +
636 get :articles, :filter => :more_recent 636 get :articles, :filter => :more_recent
637 637
638 assert_equal [art2, art1, art3], assigns(:searches)[:articles][:results] 638 assert_equal [art2, art1, art3], assigns(:searches)[:articles][:results]
639 end 639 end
640 - 640 +
641 should 'add highlighted CSS class around a highlighted product' do 641 should 'add highlighted CSS class around a highlighted product' do
642 enterprise = fast_create(Enterprise) 642 enterprise = fast_create(Enterprise)
643 - product = Product.create!(:name => 'Enter Sandman', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => true) 643 + product = Product.create!(:name => 'Enter Sandman', :profile_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => true)
644 get :products 644 get :products
645 assert_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Enter Sandman/ 645 assert_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Enter Sandman/
646 end 646 end
647 647
648 should 'do not add highlighted CSS class around an ordinary product' do 648 should 'do not add highlighted CSS class around an ordinary product' do
649 enterprise = fast_create(Enterprise) 649 enterprise = fast_create(Enterprise)
650 - product = Product.create!(:name => 'Holier Than Thou', :enterprise_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => false) 650 + product = Product.create!(:name => 'Holier Than Thou', :profile_id => enterprise.id, :product_category_id => @product_category.id, :highlighted => false)
651 get :products 651 get :products
652 assert_no_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Holier Than Thou/ 652 assert_no_tag :tag => 'li', :attributes => { :class => 'search-product-item highlighted' }, :content => /Holier Than Thou/
653 end 653 end
test/unit/enterprise_test.rb
@@ -393,13 +393,13 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -393,13 +393,13 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
393 p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => @product_category.id) 393 p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => @product_category.id)
394 products = [] 394 products = []
395 3.times {|n| 395 3.times {|n|
396 - products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, 396 + products.push(Product.create!(:name => "product #{n}", :profile_id => e1.id,
397 :highlighted => true, :product_category_id => @product_category.id, 397 :highlighted => true, :product_category_id => @product_category.id,
398 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } 398 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }
399 )) 399 ))
400 } 400 }
401 - Product.create!(:name => "product 4", :enterprise_id => e1.id, :product_category_id => @product_category.id, :highlighted => true)  
402 - Product.create!(:name => "product 5", :enterprise_id => e1.id, :product_category_id => @product_category.id, :image_builder => { 401 + Product.create!(:name => "product 4", :profile_id => e1.id, :product_category_id => @product_category.id, :highlighted => true)
  402 + Product.create!(:name => "product 5", :profile_id => e1.id, :product_category_id => @product_category.id, :image_builder => {
403 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') 403 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
404 }) 404 })
405 assert_equal products, e1.highlighted_products_with_image 405 assert_equal products, e1.highlighted_products_with_image
@@ -407,7 +407,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase @@ -407,7 +407,7 @@ class EnterpriseTest &lt; ActiveSupport::TestCase
407 407
408 should 'has many inputs through products' do 408 should 'has many inputs through products' do
409 enterprise = fast_create(Enterprise) 409 enterprise = fast_create(Enterprise)
410 - product = fast_create(Product, :enterprise_id => enterprise.id, :product_category_id => @product_category.id) 410 + product = fast_create(Product, :profile_id => enterprise.id, :product_category_id => @product_category.id)
411 product.inputs << Input.new(:product_category => @product_category) 411 product.inputs << Input.new(:product_category => @product_category)
412 product.inputs << Input.new(:product_category => @product_category) 412 product.inputs << Input.new(:product_category => @product_category)
413 413
test/unit/environment_test.rb
@@ -399,13 +399,13 @@ class EnvironmentTest &lt; ActiveSupport::TestCase @@ -399,13 +399,13 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
399 p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => category.id) 399 p1 = e1.products.create!(:name => 'test_prod1', :product_category_id => category.id)
400 products = [] 400 products = []
401 3.times {|n| 401 3.times {|n|
402 - products.push(Product.create!(:name => "product #{n}", :enterprise_id => e1.id, 402 + products.push(Product.create!(:name => "product #{n}", :profile_id => e1.id,
403 :product_category_id => category.id, :highlighted => true, 403 :product_category_id => category.id, :highlighted => true,
404 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } 404 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }
405 )) 405 ))
406 } 406 }
407 - Product.create!(:name => "product 4", :enterprise_id => e1.id, :product_category_id => category.id, :highlighted => true)  
408 - Product.create!(:name => "product 5", :enterprise_id => e1.id, :product_category_id => category.id, :image_builder => { 407 + Product.create!(:name => "product 4", :profile_id => e1.id, :product_category_id => category.id, :highlighted => true)
  408 + Product.create!(:name => "product 5", :profile_id => e1.id, :product_category_id => category.id, :image_builder => {
409 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') 409 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
410 }) 410 })
411 assert_equal products, env.highlighted_products_with_image 411 assert_equal products, env.highlighted_products_with_image
@@ -733,7 +733,7 @@ class EnvironmentTest &lt; ActiveSupport::TestCase @@ -733,7 +733,7 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
733 assert_equal c, e.portal_community 733 assert_equal c, e.portal_community
734 e.unset_portal_community! 734 e.unset_portal_community!
735 e.reload 735 e.reload
736 - assert_nil e.portal_community 736 + assert_nil e.portal_community
737 assert_equal [], e.portal_folders 737 assert_equal [], e.portal_folders
738 assert_equal 0, e.news_amount_by_folder 738 assert_equal 0, e.news_amount_by_folder
739 assert_equal false, e.enabled?('use_portal_community') 739 assert_equal false, e.enabled?('use_portal_community')
test/unit/featured_products_block_test.rb
@@ -13,7 +13,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase @@ -13,7 +13,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase
13 profile = fast_create(Enterprise) 13 profile = fast_create(Enterprise)
14 products = [] 14 products = []
15 category = fast_create(ProductCategory) 15 category = fast_create(ProductCategory)
16 - 3.times {|n| products.push(Product.create!(:name => "product #{n}", :enterprise_id => profile.id, :product_category_id => category.id)) } 16 + 3.times {|n| products.push(Product.create!(:name => "product #{n}", :profile_id => profile.id, :product_category_id => category.id)) }
17 featured_products_block = FeaturedProductsBlock.create!(:product_ids => products.map(&:id)) 17 featured_products_block = FeaturedProductsBlock.create!(:product_ids => products.map(&:id))
18 assert_equal products, featured_products_block.products 18 assert_equal products, featured_products_block.products
19 end 19 end
@@ -66,7 +66,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase @@ -66,7 +66,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase
66 enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) 66 enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment)
67 category = fast_create(ProductCategory) 67 category = fast_create(ProductCategory)
68 3.times {|n| 68 3.times {|n|
69 - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, 69 + Product.create!(:name => "product #{n}", :profile_id => enterprise.id,
70 :highlighted => true, :product_category_id => category.id, 70 :highlighted => true, :product_category_id => category.id,
71 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } 71 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }
72 ) 72 )
@@ -82,7 +82,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase @@ -82,7 +82,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase
82 enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) 82 enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment)
83 category = fast_create(ProductCategory) 83 category = fast_create(ProductCategory)
84 3.times {|n| 84 3.times {|n|
85 - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :highlighted => true, :product_category_id => category.id) 85 + Product.create!(:name => "product #{n}", :profile_id => enterprise.id, :highlighted => true, :product_category_id => category.id)
86 } 86 }
87 @environment.boxes.first.blocks<< block 87 @environment.boxes.first.blocks<< block
88 88
@@ -95,7 +95,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase @@ -95,7 +95,7 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase
95 enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment) 95 enterprise = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise', :environment => @environment)
96 category = fast_create(ProductCategory) 96 category = fast_create(ProductCategory)
97 3.times {|n| 97 3.times {|n|
98 - Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { 98 + Product.create!(:name => "product #{n}", :profile_id => enterprise.id, :product_category_id => category.id, :image_builder => {
99 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') 99 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
100 }) 100 })
101 } 101 }
@@ -118,13 +118,13 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase @@ -118,13 +118,13 @@ class FeaturedProductsBlockTest &lt; ActiveSupport::TestCase
118 category = fast_create(ProductCategory) 118 category = fast_create(ProductCategory)
119 products = [] 119 products = []
120 3.times {|n| 120 3.times {|n|
121 - products.push(Product.create!(:name => "product #{n}", :enterprise_id => enterprise.id, 121 + products.push(Product.create!(:name => "product #{n}", :profile_id => enterprise.id,
122 :highlighted => true, :product_category_id => category.id, 122 :highlighted => true, :product_category_id => category.id,
123 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } 123 :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') }
124 )) 124 ))
125 } 125 }
126 - Product.create!(:name => "product 4", :enterprise_id => enterprise.id, :product_category_id => category.id, :highlighted => true)  
127 - Product.create!(:name => "product 5", :enterprise_id => enterprise.id, :product_category_id => category.id, :image_builder => { 126 + Product.create!(:name => "product 4", :profile_id => enterprise.id, :product_category_id => category.id, :highlighted => true)
  127 + Product.create!(:name => "product 5", :profile_id => enterprise.id, :product_category_id => category.id, :image_builder => {
128 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') 128 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
129 }) 129 })
130 @environment.boxes.first.blocks<< block 130 @environment.boxes.first.blocks<< block
test/unit/input_test.rb
@@ -115,7 +115,7 @@ class InputTest &lt; ActiveSupport::TestCase @@ -115,7 +115,7 @@ class InputTest &lt; ActiveSupport::TestCase
115 should 'display amount used' do 115 should 'display amount used' do
116 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') 116 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1')
117 product_category = fast_create(ProductCategory, :name => 'Products') 117 product_category = fast_create(ProductCategory, :name => 'Products')
118 - product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) 118 + product = fast_create(Product, :profile_id => ent.id, :product_category_id => product_category.id)
119 119
120 input = Input.new(:product => product) 120 input = Input.new(:product => product)
121 input.amount_used = 10.45 121 input.amount_used = 10.45
@@ -134,7 +134,7 @@ class InputTest &lt; ActiveSupport::TestCase @@ -134,7 +134,7 @@ class InputTest &lt; ActiveSupport::TestCase
134 should 'display only integer value if decimal value is 00' do 134 should 'display only integer value if decimal value is 00' do
135 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') 135 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1')
136 product_category = fast_create(ProductCategory, :name => 'Products') 136 product_category = fast_create(ProductCategory, :name => 'Products')
137 - product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) 137 + product = fast_create(Product, :profile_id => ent.id, :product_category_id => product_category.id)
138 138
139 input = Input.new(:product => product) 139 input = Input.new(:product => product)
140 input.amount_used = 10.00 140 input.amount_used = 10.00
@@ -144,7 +144,7 @@ class InputTest &lt; ActiveSupport::TestCase @@ -144,7 +144,7 @@ class InputTest &lt; ActiveSupport::TestCase
144 should 'display formatted value' do 144 should 'display formatted value' do
145 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') 145 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1')
146 product_category = fast_create(ProductCategory, :name => 'Products') 146 product_category = fast_create(ProductCategory, :name => 'Products')
147 - product = fast_create(Product, :enterprise_id => ent.id, :product_category_id => product_category.id) 147 + product = fast_create(Product, :profile_id => ent.id, :product_category_id => product_category.id)
148 148
149 input = Input.new(:product => product) 149 input = Input.new(:product => product)
150 input.price_per_unit = 1.45 150 input.price_per_unit = 1.45
test/unit/price_detail_test.rb
@@ -70,7 +70,7 @@ class PriceDetailTest &lt; ActiveSupport::TestCase @@ -70,7 +70,7 @@ class PriceDetailTest &lt; ActiveSupport::TestCase
70 70
71 should 'format values to float with 2 decimals' do 71 should 'format values to float with 2 decimals' do
72 enterprise = fast_create(Enterprise) 72 enterprise = fast_create(Enterprise)
73 - product = fast_create(Product, :enterprise_id => enterprise.id) 73 + product = fast_create(Product, :profile_id => enterprise.id)
74 cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'environment') 74 cost = fast_create(ProductionCost, :owner_id => Environment.default.id, :owner_type => 'environment')
75 75
76 price_detail = product.price_details.create(:production_cost_id => cost.id, :price => 10) 76 price_detail = product.price_details.create(:production_cost_id => cost.id, :price => 10)
test/unit/product_category_test.rb
@@ -7,12 +7,12 @@ class ProductCategoryTest &lt; ActiveSupport::TestCase @@ -7,12 +7,12 @@ class ProductCategoryTest &lt; ActiveSupport::TestCase
7 assert_equivalent [], c0.all_products 7 assert_equivalent [], c0.all_products
8 8
9 profile = fast_create(Enterprise) 9 profile = fast_create(Enterprise)
10 - p0 = Product.create(:name => 'product1', :product_category => c0, :enterprise_id => profile.id) 10 + p0 = Product.create(:name => 'product1', :product_category => c0, :profile_id => profile.id)
11 c0.reload 11 c0.reload
12 assert_equivalent [p0], c0.all_products 12 assert_equivalent [p0], c0.all_products
13 13
14 c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default) 14 c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default)
15 - p1 = Product.create(:name => 'product2', :product_category => c1, :enterprise_id => profile.id) 15 + p1 = Product.create(:name => 'product2', :product_category => c1, :profile_id => profile.id)
16 c0.reload; c1.reload 16 c0.reload; c1.reload
17 assert_equivalent [p0, p1], c0.all_products 17 assert_equivalent [p0, p1], c0.all_products
18 assert_equivalent [p1], c1.all_products 18 assert_equivalent [p1], c1.all_products
test/unit/product_test.rb
@@ -18,14 +18,14 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -18,14 +18,14 @@ class ProductTest &lt; ActiveSupport::TestCase
18 should 'return associated enterprise region' do 18 should 'return associated enterprise region' do
19 @profile.region = fast_create Region, :name => 'Salvador' 19 @profile.region = fast_create Region, :name => 'Salvador'
20 @profile.save! 20 @profile.save!
21 - p = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :enterprise_id => @profile.id) 21 + p = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :profile_id => @profile.id)
22 22
23 assert_equal @profile.region, p.region 23 assert_equal @profile.region, p.region
24 end 24 end
25 25
26 should 'create product' do 26 should 'create product' do
27 assert_difference Product, :count do 27 assert_difference Product, :count do
28 - p = Product.new(:name => 'test product1', :product_category => @product_category, :enterprise_id => @profile.id) 28 + p = Product.new(:name => 'test product1', :product_category => @product_category, :profile_id => @profile.id)
29 assert p.save 29 assert p.save
30 end 30 end
31 end 31 end
@@ -84,7 +84,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -84,7 +84,7 @@ class ProductTest &lt; ActiveSupport::TestCase
84 assert_difference Product, :count do 84 assert_difference Product, :count do
85 p = Product.create!(:name => 'test product1', :product_category => @product_category, :image_builder => { 85 p = Product.create!(:name => 'test product1', :product_category => @product_category, :image_builder => {
86 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') 86 :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')
87 - }, :enterprise_id => @profile.id) 87 + }, :profile_id => @profile.id)
88 assert_equal p.image(true).filename, 'rails.png' 88 assert_equal p.image(true).filename, 'rails.png'
89 end 89 end
90 end 90 end
@@ -138,7 +138,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -138,7 +138,7 @@ class ProductTest &lt; ActiveSupport::TestCase
138 138
139 should 'respond to public? as its enterprise public?' do 139 should 'respond to public? as its enterprise public?' do
140 e1 = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') 140 e1 = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1')
141 - p1 = fast_create(Product, :name => 'test product 1', :enterprise_id => e1.id, :product_category_id => @product_category.id) 141 + p1 = fast_create(Product, :name => 'test product 1', :profile_id => e1.id, :product_category_id => @product_category.id)
142 142
143 assert p1.public? 143 assert p1.public?
144 144
@@ -197,7 +197,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -197,7 +197,7 @@ class ProductTest &lt; ActiveSupport::TestCase
197 end 197 end
198 198
199 should 'use name of category when has no name yet' do 199 should 'use name of category when has no name yet' do
200 - product = Product.new(:product_category => @product_category, :enterprise_id => @profile.id) 200 + product = Product.new(:product_category => @product_category, :profile_id => @profile.id)
201 assert product.valid? 201 assert product.valid?
202 assert_equal product.name, @product_category.name 202 assert_equal product.name, @product_category.name
203 end 203 end
@@ -217,7 +217,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -217,7 +217,7 @@ class ProductTest &lt; ActiveSupport::TestCase
217 217
218 should 'format values to float with 2 decimals' do 218 should 'format values to float with 2 decimals' do
219 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') 219 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1')
220 - product = fast_create(Product, :enterprise_id => ent.id, :price => 12.994, :discount => 1.994) 220 + product = fast_create(Product, :profile_id => ent.id, :price => 12.994, :discount => 1.994)
221 221
222 assert_equal "12.99", product.formatted_value(:price) 222 assert_equal "12.99", product.formatted_value(:price)
223 assert_equal "1.99", product.formatted_value(:discount) 223 assert_equal "1.99", product.formatted_value(:discount)
@@ -225,14 +225,14 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -225,14 +225,14 @@ class ProductTest &lt; ActiveSupport::TestCase
225 225
226 should 'calculate price with discount' do 226 should 'calculate price with discount' do
227 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') 227 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1')
228 - product = fast_create(Product, :enterprise_id => ent.id, :price => 12.994, :discount => 1.994) 228 + product = fast_create(Product, :profile_id => ent.id, :price => 12.994, :discount => 1.994)
229 229
230 assert_equal 11.00, product.price_with_discount 230 assert_equal 11.00, product.price_with_discount
231 end 231 end
232 232
233 should 'calculate price without discount' do 233 should 'calculate price without discount' do
234 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1') 234 ent = fast_create(Enterprise, :name => 'test ent 1', :identifier => 'test_ent1')
235 - product = fast_create(Product, :enterprise_id => ent.id, :price => 12.994, :discount => 0) 235 + product = fast_create(Product, :profile_id => ent.id, :price => 12.994, :discount => 0)
236 236
237 assert_equal product.price, product.price_with_discount 237 assert_equal product.price, product.price_with_discount
238 end 238 end
@@ -254,7 +254,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -254,7 +254,7 @@ class ProductTest &lt; ActiveSupport::TestCase
254 254
255 should 'return product inputs' do 255 should 'return product inputs' do
256 ent = fast_create(Enterprise) 256 ent = fast_create(Enterprise)
257 - product = fast_create(Product, :enterprise_id => ent.id) 257 + product = fast_create(Product, :profile_id => ent.id)
258 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) 258 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id)
259 259
260 assert_equal [input], product.inputs 260 assert_equal [input], product.inputs
@@ -262,7 +262,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -262,7 +262,7 @@ class ProductTest &lt; ActiveSupport::TestCase
262 262
263 should 'destroy inputs when product is removed' do 263 should 'destroy inputs when product is removed' do
264 ent = fast_create(Enterprise) 264 ent = fast_create(Enterprise)
265 - product = fast_create(Product, :enterprise_id => ent.id) 265 + product = fast_create(Product, :profile_id => ent.id)
266 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id) 266 input = fast_create(Input, :product_id => product.id, :product_category_id => @product_category.id)
267 267
268 services_category = fast_create(ProductCategory, :name => 'Services') 268 services_category = fast_create(ProductCategory, :name => 'Services')
@@ -414,7 +414,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -414,7 +414,7 @@ class ProductTest &lt; ActiveSupport::TestCase
414 414
415 should 'return production costs from enterprise and environment' do 415 should 'return production costs from enterprise and environment' do
416 ent = fast_create(Enterprise) 416 ent = fast_create(Enterprise)
417 - product = fast_create(Product, :enterprise_id => ent.id) 417 + product = fast_create(Product, :profile_id => ent.id)
418 ent_production_cost = fast_create(ProductionCost, :owner_id => ent.id, :owner_type => 'Profile') 418 ent_production_cost = fast_create(ProductionCost, :owner_id => ent.id, :owner_type => 'Profile')
419 env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment') 419 env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment')
420 420
@@ -423,7 +423,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -423,7 +423,7 @@ class ProductTest &lt; ActiveSupport::TestCase
423 423
424 should 'return all production costs' do 424 should 'return all production costs' do
425 ent = fast_create(Enterprise) 425 ent = fast_create(Enterprise)
426 - product = fast_create(Product, :enterprise_id => ent.id) 426 + product = fast_create(Product, :profile_id => ent.id)
427 427
428 env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment') 428 env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment')
429 ent_production_cost = fast_create(ProductionCost, :owner_id => ent.id, :owner_type => 'Profile') 429 ent_production_cost = fast_create(ProductionCost, :owner_id => ent.id, :owner_type => 'Profile')
@@ -433,7 +433,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -433,7 +433,7 @@ class ProductTest &lt; ActiveSupport::TestCase
433 433
434 should 'return total value of production costs' do 434 should 'return total value of production costs' do
435 ent = fast_create(Enterprise) 435 ent = fast_create(Enterprise)
436 - product = fast_create(Product, :enterprise_id => ent.id) 436 + product = fast_create(Product, :profile_id => ent.id)
437 437
438 env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment') 438 env_production_cost = fast_create(ProductionCost, :owner_id => ent.environment.id, :owner_type => 'Environment')
439 price_detail = product.price_details.create(:production_cost => env_production_cost, :price => 10) 439 price_detail = product.price_details.create(:production_cost => env_production_cost, :price => 10)
@@ -445,7 +445,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -445,7 +445,7 @@ class ProductTest &lt; ActiveSupport::TestCase
445 445
446 should 'return inputs cost as total value of production costs if has no price details' do 446 should 'return inputs cost as total value of production costs if has no price details' do
447 ent = fast_create(Enterprise) 447 ent = fast_create(Enterprise)
448 - product = fast_create(Product, :enterprise_id => ent.id) 448 + product = fast_create(Product, :profile_id => ent.id)
449 449
450 input = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 20.0, :amount_used => 2) 450 input = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 20.0, :amount_used => 2)
451 451
@@ -460,7 +460,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -460,7 +460,7 @@ class ProductTest &lt; ActiveSupport::TestCase
460 460
461 should 'format inputs cost values to float with 2 decimals' do 461 should 'format inputs cost values to float with 2 decimals' do
462 ent = fast_create(Enterprise) 462 ent = fast_create(Enterprise)
463 - product = fast_create(Product, :enterprise_id => ent.id) 463 + product = fast_create(Product, :profile_id => ent.id)
464 first = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 20.0, :amount_used => 2) 464 first = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 20.0, :amount_used => 2)
465 second = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 10.0, :amount_used => 1) 465 second = fast_create(Input, :product_id => product.id, :product_category_id => fast_create(ProductCategory).id, :price_per_unit => 10.0, :amount_used => 1)
466 466
@@ -490,7 +490,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -490,7 +490,7 @@ class ProductTest &lt; ActiveSupport::TestCase
490 end 490 end
491 491
492 should 'return solidarity percentage from inputs' do 492 should 'return solidarity percentage from inputs' do
493 - prod = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :enterprise_id => @profile.id) 493 + prod = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :profile_id => @profile.id)
494 assert_equal 0, prod.percentage_from_solidarity_economy.first 494 assert_equal 0, prod.percentage_from_solidarity_economy.first
495 495
496 Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, 496 Input.create!(:product_id => prod.id, :product_category_id => @product_category.id,
@@ -505,7 +505,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -505,7 +505,7 @@ class ProductTest &lt; ActiveSupport::TestCase
505 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) 505 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false)
506 assert_equal 25, prod.percentage_from_solidarity_economy.first 506 assert_equal 25, prod.percentage_from_solidarity_economy.first
507 507
508 - prod = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :enterprise_id => @profile.id) 508 + prod = fast_create(Product, :name => 'test product1', :product_category_id => @product_category.id, :profile_id => @profile.id)
509 Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, 509 Input.create!(:product_id => prod.id, :product_category_id => @product_category.id,
510 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) 510 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true)
511 Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, 511 Input.create!(:product_id => prod.id, :product_category_id => @product_category.id,
@@ -516,7 +516,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -516,7 +516,7 @@ class ProductTest &lt; ActiveSupport::TestCase
516 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false) 516 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => false)
517 assert_equal 75, prod.percentage_from_solidarity_economy.first 517 assert_equal 75, prod.percentage_from_solidarity_economy.first
518 518
519 - prod = fast_create(Product, :name => 'test product', :product_category_id => @product_category.id, :enterprise_id => @profile.id) 519 + prod = fast_create(Product, :name => 'test product', :product_category_id => @product_category.id, :profile_id => @profile.id)
520 Input.create!(:product_id => prod.id, :product_category_id => @product_category.id, 520 Input.create!(:product_id => prod.id, :product_category_id => @product_category.id,
521 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true) 521 :amount_used => 10, :price_per_unit => 10, :is_from_solidarity_economy => true)
522 assert_equal 100, prod.percentage_from_solidarity_economy.first 522 assert_equal 100, prod.percentage_from_solidarity_economy.first
@@ -526,7 +526,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -526,7 +526,7 @@ class ProductTest &lt; ActiveSupport::TestCase
526 enterprise = fast_create(Enterprise) 526 enterprise = fast_create(Enterprise)
527 Enterprise.any_instance.expects(:region) 527 Enterprise.any_instance.expects(:region)
528 Enterprise.any_instance.expects(:region_id) 528 Enterprise.any_instance.expects(:region_id)
529 - product = fast_create(Product, :enterprise_id => enterprise.id) 529 + product = fast_create(Product, :profile_id => enterprise.id)
530 product.region 530 product.region
531 product.region_id 531 product.region_id
532 end 532 end
@@ -535,7 +535,7 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -535,7 +535,7 @@ class ProductTest &lt; ActiveSupport::TestCase
535 enterprise = fast_create(Enterprise) 535 enterprise = fast_create(Enterprise)
536 Enterprise.any_instance.expects(:environment) 536 Enterprise.any_instance.expects(:environment)
537 Enterprise.any_instance.expects(:environment_id) 537 Enterprise.any_instance.expects(:environment_id)
538 - product = fast_create(Product, :enterprise_id => enterprise.id) 538 + product = fast_create(Product, :profile_id => enterprise.id)
539 product.environment 539 product.environment
540 product.environment_id 540 product.environment_id
541 end 541 end
@@ -543,9 +543,9 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -543,9 +543,9 @@ class ProductTest &lt; ActiveSupport::TestCase
543 should 'return more recent products' do 543 should 'return more recent products' do
544 Product.destroy_all 544 Product.destroy_all
545 545
546 - prod1 = Product.create!(:name => 'Damaged LP', :enterprise_id => @profile.id, :product_category_id => @product_category.id)  
547 - prod2 = Product.create!(:name => 'Damaged CD', :enterprise_id => @profile.id, :product_category_id => @product_category.id)  
548 - prod3 = Product.create!(:name => 'Damaged DVD', :enterprise_id => @profile.id, :product_category_id => @product_category.id) 546 + prod1 = Product.create!(:name => 'Damaged LP', :profile_id => @profile.id, :product_category_id => @product_category.id)
  547 + prod2 = Product.create!(:name => 'Damaged CD', :profile_id => @profile.id, :product_category_id => @product_category.id)
  548 + prod3 = Product.create!(:name => 'Damaged DVD', :profile_id => @profile.id, :product_category_id => @product_category.id)
549 549
550 prod1.update_attribute :created_at, Time.now-2.days 550 prod1.update_attribute :created_at, Time.now-2.days
551 prod2.update_attribute :created_at, Time.now-1.days 551 prod2.update_attribute :created_at, Time.now-1.days
@@ -579,9 +579,9 @@ class ProductTest &lt; ActiveSupport::TestCase @@ -579,9 +579,9 @@ class ProductTest &lt; ActiveSupport::TestCase
579 579
580 should 'return from_category scope untouched if passed nil' do 580 should 'return from_category scope untouched if passed nil' do
581 enterprise = fast_create(Enterprise) 581 enterprise = fast_create(Enterprise)
582 - p1 = fast_create(Product, :enterprise_id => enterprise.id)  
583 - p2 = fast_create(Product, :enterprise_id => enterprise.id)  
584 - p3 = fast_create(Product, :enterprise_id => enterprise.id) 582 + p1 = fast_create(Product, :profile_id => enterprise.id)
  583 + p2 = fast_create(Product, :profile_id => enterprise.id)
  584 + p3 = fast_create(Product, :profile_id => enterprise.id)
585 585
586 products = enterprise.products.from_category(nil) 586 products = enterprise.products.from_category(nil)
587 587